xref: /aosp_15_r20/external/webrtc/docs/native-code/rtp-hdrext/abs-capture-time/README.md (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker# Absolute Capture Time
2*d9f75844SAndroid Build Coastguard Worker
3*d9f75844SAndroid Build Coastguard WorkerThe Absolute Capture Time extension is used to stamp RTP packets with a NTP
4*d9f75844SAndroid Build Coastguard Workertimestamp showing when the first audio or video frame in a packet was originally
5*d9f75844SAndroid Build Coastguard Workercaptured. The intent of this extension is to provide a way to accomplish
6*d9f75844SAndroid Build Coastguard Workeraudio-to-video synchronization when RTCP-terminating intermediate systems (e.g.
7*d9f75844SAndroid Build Coastguard Workermixers) are involved.
8*d9f75844SAndroid Build Coastguard Worker
9*d9f75844SAndroid Build Coastguard Worker**Name:**
10*d9f75844SAndroid Build Coastguard Worker"Absolute Capture Time"; "RTP Header Extension for Absolute Capture Time"
11*d9f75844SAndroid Build Coastguard Worker
12*d9f75844SAndroid Build Coastguard Worker**Formal name:**
13*d9f75844SAndroid Build Coastguard Worker<http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time>
14*d9f75844SAndroid Build Coastguard Worker
15*d9f75844SAndroid Build Coastguard Worker**Status:**
16*d9f75844SAndroid Build Coastguard WorkerThis extension is defined here to allow for experimentation. Once experience has
17*d9f75844SAndroid Build Coastguard Workershown that it is useful, we intend to make a proposal based on it for
18*d9f75844SAndroid Build Coastguard Workerstandardization in the IETF.
19*d9f75844SAndroid Build Coastguard Worker
20*d9f75844SAndroid Build Coastguard WorkerContact <[email protected]> for more info.
21*d9f75844SAndroid Build Coastguard Worker
22*d9f75844SAndroid Build Coastguard Worker## RTP header extension format
23*d9f75844SAndroid Build Coastguard Worker
24*d9f75844SAndroid Build Coastguard Worker### Data layout overview
25*d9f75844SAndroid Build Coastguard WorkerData layout of the shortened version of `abs-capture-time` with a 1-byte header
26*d9f75844SAndroid Build Coastguard Worker\+ 8 bytes of data:
27*d9f75844SAndroid Build Coastguard Worker
28*d9f75844SAndroid Build Coastguard Worker      0                   1                   2                   3
29*d9f75844SAndroid Build Coastguard Worker      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
30*d9f75844SAndroid Build Coastguard Worker     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
31*d9f75844SAndroid Build Coastguard Worker     |  ID   | len=7 |     absolute capture timestamp (bit 0-23)     |
32*d9f75844SAndroid Build Coastguard Worker     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33*d9f75844SAndroid Build Coastguard Worker     |             absolute capture timestamp (bit 24-55)            |
34*d9f75844SAndroid Build Coastguard Worker     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35*d9f75844SAndroid Build Coastguard Worker     |  ... (56-63)  |
36*d9f75844SAndroid Build Coastguard Worker     +-+-+-+-+-+-+-+-+
37*d9f75844SAndroid Build Coastguard Worker
38*d9f75844SAndroid Build Coastguard WorkerData layout of the extended version of `abs-capture-time` with a 1-byte header +
39*d9f75844SAndroid Build Coastguard Worker16 bytes of data:
40*d9f75844SAndroid Build Coastguard Worker
41*d9f75844SAndroid Build Coastguard Worker      0                   1                   2                   3
42*d9f75844SAndroid Build Coastguard Worker      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
43*d9f75844SAndroid Build Coastguard Worker     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44*d9f75844SAndroid Build Coastguard Worker     |  ID   | len=15|     absolute capture timestamp (bit 0-23)     |
45*d9f75844SAndroid Build Coastguard Worker     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46*d9f75844SAndroid Build Coastguard Worker     |             absolute capture timestamp (bit 24-55)            |
47*d9f75844SAndroid Build Coastguard Worker     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48*d9f75844SAndroid Build Coastguard Worker     |  ... (56-63)  |   estimated capture clock offset (bit 0-23)   |
49*d9f75844SAndroid Build Coastguard Worker     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50*d9f75844SAndroid Build Coastguard Worker     |           estimated capture clock offset (bit 24-55)          |
51*d9f75844SAndroid Build Coastguard Worker     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
52*d9f75844SAndroid Build Coastguard Worker     |  ... (56-63)  |
53*d9f75844SAndroid Build Coastguard Worker     +-+-+-+-+-+-+-+-+
54*d9f75844SAndroid Build Coastguard Worker
55*d9f75844SAndroid Build Coastguard Worker### Data layout details
56*d9f75844SAndroid Build Coastguard Worker#### Absolute capture timestamp
57*d9f75844SAndroid Build Coastguard Worker
58*d9f75844SAndroid Build Coastguard WorkerAbsolute capture timestamp is the NTP timestamp of when the first frame in a
59*d9f75844SAndroid Build Coastguard Workerpacket was originally captured. This timestamp MUST be based on the same clock
60*d9f75844SAndroid Build Coastguard Workeras the clock used to generate NTP timestamps for RTCP sender reports on the
61*d9f75844SAndroid Build Coastguard Workercapture system.
62*d9f75844SAndroid Build Coastguard Worker
63*d9f75844SAndroid Build Coastguard WorkerIt's not always possible to do an NTP clock readout at the exact moment of when
64*d9f75844SAndroid Build Coastguard Workera media frame is captured. A capture system MAY postpone the readout until a
65*d9f75844SAndroid Build Coastguard Workermore convenient time. A capture system SHOULD have known delays (e.g. from
66*d9f75844SAndroid Build Coastguard Workerhardware buffers) subtracted from the readout to make the final timestamp as
67*d9f75844SAndroid Build Coastguard Workerclose to the actual capture time as possible.
68*d9f75844SAndroid Build Coastguard Worker
69*d9f75844SAndroid Build Coastguard WorkerThis field is encoded as a 64-bit unsigned fixed-point number with the high 32
70*d9f75844SAndroid Build Coastguard Workerbits for the timestamp in seconds and low 32 bits for the fractional part. This
71*d9f75844SAndroid Build Coastguard Workeris also known as the UQ32.32 format and is what the RTP specification defines as
72*d9f75844SAndroid Build Coastguard Workerthe canonical format to represent NTP timestamps.
73*d9f75844SAndroid Build Coastguard Worker
74*d9f75844SAndroid Build Coastguard Worker#### Estimated capture clock offset
75*d9f75844SAndroid Build Coastguard Worker
76*d9f75844SAndroid Build Coastguard WorkerEstimated capture clock offset is the sender's estimate of the offset between
77*d9f75844SAndroid Build Coastguard Workerits own NTP clock and the capture system's NTP clock. The sender is here defined
78*d9f75844SAndroid Build Coastguard Workeras the system that owns the NTP clock used to generate the NTP timestamps for
79*d9f75844SAndroid Build Coastguard Workerthe RTCP sender reports on this stream. The sender system is typically either
80*d9f75844SAndroid Build Coastguard Workerthe capture system or a mixer.
81*d9f75844SAndroid Build Coastguard Worker
82*d9f75844SAndroid Build Coastguard WorkerThis field is encoded as a 64-bit two’s complement **signed** fixed-point number
83*d9f75844SAndroid Build Coastguard Workerwith the high 32 bits for the seconds and low 32 bits for the fractional part.
84*d9f75844SAndroid Build Coastguard WorkerIt’s intended to make it easy for a receiver, that knows how to estimate the
85*d9f75844SAndroid Build Coastguard Workersender system’s NTP clock, to also estimate the capture system’s NTP clock:
86*d9f75844SAndroid Build Coastguard Worker
87*d9f75844SAndroid Build Coastguard Worker     Capture NTP Clock = Sender NTP Clock + Capture Clock Offset
88*d9f75844SAndroid Build Coastguard Worker
89*d9f75844SAndroid Build Coastguard Worker### Further details
90*d9f75844SAndroid Build Coastguard Worker
91*d9f75844SAndroid Build Coastguard Worker#### Capture system
92*d9f75844SAndroid Build Coastguard Worker
93*d9f75844SAndroid Build Coastguard WorkerA receiver MUST treat the first CSRC in the CSRC list of a received packet as if
94*d9f75844SAndroid Build Coastguard Workerit belongs to the capture system. If the CSRC list is empty, then the receiver
95*d9f75844SAndroid Build Coastguard WorkerMUST treat the SSRC as if it belongs to the capture system. Mixers SHOULD put
96*d9f75844SAndroid Build Coastguard Workerthe most prominent CSRC as the first CSRC in a packet’s CSRC list.
97*d9f75844SAndroid Build Coastguard Worker
98*d9f75844SAndroid Build Coastguard Worker#### Intermediate systems
99*d9f75844SAndroid Build Coastguard Worker
100*d9f75844SAndroid Build Coastguard WorkerAn intermediate system (e.g. mixer) MAY adjust these timestamps as needed. It
101*d9f75844SAndroid Build Coastguard WorkerMAY also choose to rewrite the timestamps completely, using its own NTP clock as
102*d9f75844SAndroid Build Coastguard Workerreference clock, if it wants to present itself as a capture system for A/V-sync
103*d9f75844SAndroid Build Coastguard Workerpurposes.
104*d9f75844SAndroid Build Coastguard Worker
105*d9f75844SAndroid Build Coastguard Worker#### Timestamp interpolation
106*d9f75844SAndroid Build Coastguard Worker
107*d9f75844SAndroid Build Coastguard WorkerA sender SHOULD save bandwidth by not sending `abs-capture-time` with every
108*d9f75844SAndroid Build Coastguard WorkerRTP packet. It SHOULD still send them at regular intervals (e.g. every second)
109*d9f75844SAndroid Build Coastguard Workerto help mitigate the impact of clock drift and packet loss. Mixers SHOULD always
110*d9f75844SAndroid Build Coastguard Workersend `abs-capture-time` with the first RTP packet after changing capture system.
111*d9f75844SAndroid Build Coastguard Worker
112*d9f75844SAndroid Build Coastguard WorkerA receiver SHOULD memorize the capture system (i.e. CSRC/SSRC), capture
113*d9f75844SAndroid Build Coastguard Workertimestamp, and RTP timestamp of the most recently received `abs-capture-time`
114*d9f75844SAndroid Build Coastguard Workerpacket on each received stream. It can then use that information, in combination
115*d9f75844SAndroid Build Coastguard Workerwith RTP timestamps of packets without `abs-capture-time`, to extrapolate
116*d9f75844SAndroid Build Coastguard Workermissing capture timestamps.
117*d9f75844SAndroid Build Coastguard Worker
118*d9f75844SAndroid Build Coastguard WorkerTimestamp interpolation works fine as long as there’s reasonably low NTP/RTP
119*d9f75844SAndroid Build Coastguard Workerclock drift. This is not always true. Senders that detect "jumps" between its
120*d9f75844SAndroid Build Coastguard WorkerNTP and RTP clock mappings SHOULD send `abs-capture-time` with the first RTP
121*d9f75844SAndroid Build Coastguard Workerpacket after such a thing happening.
122