Edge Storage Retrieval and RTSP/RTP timestamps

In order for XProtect to place correctly the received Video/Audio/Metadata data on the timeline, the ONVIF driver needs to receive exact wall-clock time for every frame. There a couple mechanisms with which this can be accomplished.

One way is for the device to send a “Range” parameter with a “clock” value in the response to the RTSP PLAY command. This value is specifying the wall-clock time of the first frame in the stream. Then based on that time and the RTP timestamps the ONVIF driver can calculate the wall-clock times of every frame.

The second and preferred way is to follow the ONVIF Streaming specification and use the 0xABAC extension for the RTP packets. Every first RTP packet of every frame should have the 0xABAC extension as specified in the ONVIF Streaming specification, Section 6.3 “RTP header extension”.

If both methods are used the ONVIF driver will respect the 0xABAC extension with higher priority.

RTSP PLAY command “Range” parameter

When initiating playback of a recording from the device, the ONVIF Driver adds a “Range” parameter with the needed start time of the stream. Below is an example of the command with the parameters.

PLAY rtsp://10.5.2.49:554/rtsp_tunnel RTSP/1.0

Session: 12342512568a5f8

CSeq: 4

User-Agent: CmRtspClient Unknown

Range: clock=20200227T081350.000Z-

Require: onvif-replay

Rate-Control: no

Authorization: Digest username="service", realm="Please log in with a valid username", nonce="7daf7249134b343866e87d085b967491", algorithm="MD5", uri="rtsp://10.5.2.49:554/rtsp_tunnel", response="ff558f784bb8f35f204e2a18c93442e6"

The start time of the requested recording is given with the parameter: Range: clock=20200227T081350.123Z format as defined in RFC2326 and is absolute time.

The ONVIF driver also requests the device to not do any rate control of the stream with the parameter Rate-Control: no . This means that the device can stream the recording as fast as possible.

RTP timestamps and 0xABAC extension

In order to provide accurate recorded frames (Video/Audio/Metadata), the device must set absolute wall-clock timestamp for each packet with the same RTP timestamp. This is achieved using an RTP header extension 0xABAC containing a NTP timestamp. This timestamp shall increase monotonically over successive packets within a single RTP stream.

The replay mechanism uses the extension ID 0xABAC for the replay extension.

NTP timestamps are represented as a 64-bit fixed-point number, in

   seconds relative to 0000 UT on 1 January 1900.  The integer part is

   in the first 32 bits and the fraction part in the last 32 bits, as

   shown in the following diagram.

       0                   1                   2                   3

       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1

      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

      |                         Integer Part                          |

      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

      |                         Fraction Part                         |

      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

See section 4 in https://tools.ietf.org/html/rfc958

And section 2 in https://www.eecis.udel.edu/~mills/time.html