blob: cf3d909499e79303224c0139b7af81ed2eab9998 [file] [log] [blame]
Patrik Höglund3e113432017-12-15 13:40:101/*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef API_RTP_HEADERS_H_
12#define API_RTP_HEADERS_H_
13
14#include <stddef.h>
Yves Gerey988cc082018-10-23 10:03:0115#include <stdint.h>
Jonas Olssona4d87372019-07-05 17:08:3316
Niels Möllerd57efc12019-03-22 13:02:1117#include <string>
Patrik Höglund3e113432017-12-15 13:40:1018
Johannes Kronad1d9f02018-11-09 10:12:3619#include "absl/types/optional.h"
Patrik Höglund3e113432017-12-15 13:40:1020#include "api/array_view.h"
Sebastian Jansson3d61ab12019-06-14 11:35:5121#include "api/units/timestamp.h"
Johannes Kron09d65882018-11-27 13:36:4122#include "api/video/color_space.h"
Patrik Höglund3e113432017-12-15 13:40:1023#include "api/video/video_content_type.h"
24#include "api/video/video_rotation.h"
25#include "api/video/video_timing.h"
Patrik Höglund3e113432017-12-15 13:40:1026
27namespace webrtc {
28
Johannes Kron075f6872019-02-14 13:41:0529struct FeedbackRequest {
30 // Determines whether the recv delta as specified in
31 // https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01
32 // should be included.
33 bool include_timestamps;
34 // Include feedback of received packets in the range [sequence_number -
Johannes Kron0da25a12019-03-06 08:34:1335 // sequence_count + 1, sequence_number]. That is, no feedback will be sent if
36 // sequence_count is zero.
Johannes Kron075f6872019-02-14 13:41:0537 int sequence_count;
38};
39
Chen Xingcd8a6e22019-07-01 08:56:5140// The Absolute Capture Time extension is used to stamp RTP packets with a NTP
41// timestamp showing when the first audio or video frame in a packet was
42// originally captured. The intent of this extension is to provide a way to
43// accomplish audio-to-video synchronization when RTCP-terminating intermediate
44// systems (e.g. mixers) are involved. See:
45// http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time
46struct AbsoluteCaptureTime {
47 // Absolute capture timestamp is the NTP timestamp of when the first frame in
48 // a packet was originally captured. This timestamp MUST be based on the same
49 // clock as the clock used to generate NTP timestamps for RTCP sender reports
50 // on the capture system.
51 //
52 // It’s not always possible to do an NTP clock readout at the exact moment of
53 // when a media frame is captured. A capture system MAY postpone the readout
54 // until a more convenient time. A capture system SHOULD have known delays
55 // (e.g. from hardware buffers) subtracted from the readout to make the final
56 // timestamp as close to the actual capture time as possible.
57 //
58 // This field is encoded as a 64-bit unsigned fixed-point number with the high
59 // 32 bits for the timestamp in seconds and low 32 bits for the fractional
60 // part. This is also known as the UQ32.32 format and is what the RTP
61 // specification defines as the canonical format to represent NTP timestamps.
62 uint64_t absolute_capture_timestamp;
63
64 // Estimated capture clock offset is the sender’s estimate of the offset
65 // between its own NTP clock and the capture system’s NTP clock. The sender is
66 // here defined as the system that owns the NTP clock used to generate the NTP
67 // timestamps for the RTCP sender reports on this stream. The sender system is
68 // typically either the capture system or a mixer.
69 //
70 // This field is encoded as a 64-bit two’s complement signed fixed-point
71 // number with the high 32 bits for the seconds and low 32 bits for the
72 // fractional part. It’s intended to make it easy for a receiver, that knows
73 // how to estimate the sender system’s NTP clock, to also estimate the capture
74 // system’s NTP clock:
75 //
76 // Capture NTP Clock = Sender NTP Clock + Capture Clock Offset
77 absl::optional<int64_t> estimated_capture_clock_offset;
78};
79
Chen Xinge08648d2019-08-05 14:29:1380inline bool operator==(const AbsoluteCaptureTime& lhs,
81 const AbsoluteCaptureTime& rhs) {
82 return (lhs.absolute_capture_timestamp == rhs.absolute_capture_timestamp) &&
83 (lhs.estimated_capture_clock_offset ==
84 rhs.estimated_capture_clock_offset);
85}
86
87inline bool operator!=(const AbsoluteCaptureTime& lhs,
88 const AbsoluteCaptureTime& rhs) {
89 return !(lhs == rhs);
90}
91
Patrik Höglund3e113432017-12-15 13:40:1092struct RTPHeaderExtension {
93 RTPHeaderExtension();
94 RTPHeaderExtension(const RTPHeaderExtension& other);
95 RTPHeaderExtension& operator=(const RTPHeaderExtension& other);
96
Sebastian Jansson3d61ab12019-06-14 11:35:5197 static constexpr int kAbsSendTimeFraction = 18;
98
99 Timestamp GetAbsoluteSendTimestamp() const {
100 RTC_DCHECK(hasAbsoluteSendTime);
101 RTC_DCHECK(absoluteSendTime < (1ul << 24));
Danil Chapovalov0c626af2020-02-10 10:16:00102 return Timestamp::Micros((absoluteSendTime * 1000000ll) /
103 (1 << kAbsSendTimeFraction));
Sebastian Jansson3d61ab12019-06-14 11:35:51104 }
105
Per Kjellander52f7ae72019-09-10 17:28:06106 TimeDelta GetAbsoluteSendTimeDelta(uint32_t previous_sendtime) const {
107 RTC_DCHECK(hasAbsoluteSendTime);
108 RTC_DCHECK(absoluteSendTime < (1ul << 24));
109 RTC_DCHECK(previous_sendtime < (1ul << 24));
110 int32_t delta =
111 static_cast<int32_t>((absoluteSendTime - previous_sendtime) << 8) >> 8;
Danil Chapovalov0c626af2020-02-10 10:16:00112 return TimeDelta::Micros((delta * 1000000ll) / (1 << kAbsSendTimeFraction));
Per Kjellander52f7ae72019-09-10 17:28:06113 }
114
Patrik Höglund3e113432017-12-15 13:40:10115 bool hasTransmissionTimeOffset;
116 int32_t transmissionTimeOffset;
117 bool hasAbsoluteSendTime;
118 uint32_t absoluteSendTime;
Chen Xingcd8a6e22019-07-01 08:56:51119 absl::optional<AbsoluteCaptureTime> absolute_capture_time;
Patrik Höglund3e113432017-12-15 13:40:10120 bool hasTransportSequenceNumber;
121 uint16_t transportSequenceNumber;
Johannes Kron075f6872019-02-14 13:41:05122 absl::optional<FeedbackRequest> feedback_request;
Patrik Höglund3e113432017-12-15 13:40:10123
124 // Audio Level includes both level in dBov and voiced/unvoiced bit. See:
Chen Xingd2a66862019-06-03 12:53:42125 // https://tools.ietf.org/html/rfc6464#section-3
Patrik Höglund3e113432017-12-15 13:40:10126 bool hasAudioLevel;
127 bool voiceActivity;
128 uint8_t audioLevel;
129
130 // For Coordination of Video Orientation. See
131 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
132 // ts_126114v120700p.pdf
133 bool hasVideoRotation;
134 VideoRotation videoRotation;
135
Danil Chapovalov0bc58cf2018-06-21 11:32:56136 // TODO(ilnik): Refactor this and one above to be absl::optional() and remove
Patrik Höglund3e113432017-12-15 13:40:10137 // a corresponding bool flag.
138 bool hasVideoContentType;
139 VideoContentType videoContentType;
140
141 bool has_video_timing;
142 VideoSendTiming video_timing;
143
Niels Möllerd381eed2020-09-02 13:34:40144 VideoPlayoutDelay playout_delay;
Patrik Höglund3e113432017-12-15 13:40:10145
146 // For identification of a stream when ssrc is not signaled. See
Danil Chapovaloveb282982021-03-20 18:43:11147 // https://tools.ietf.org/html/rfc8852
Niels Möllerd57efc12019-03-22 13:02:11148 std::string stream_id;
149 std::string repaired_stream_id;
Patrik Höglund3e113432017-12-15 13:40:10150
151 // For identifying the media section used to interpret this RTP packet. See
Danil Chapovaloveb282982021-03-20 18:43:11152 // https://tools.ietf.org/html/rfc8843
Niels Möllerd57efc12019-03-22 13:02:11153 std::string mid;
Johannes Kronad1d9f02018-11-09 10:12:36154
Johannes Kron09d65882018-11-27 13:36:41155 absl::optional<ColorSpace> color_space;
Patrik Höglund3e113432017-12-15 13:40:10156};
157
Niels Möller418f5802019-05-08 12:24:15158enum { kRtpCsrcSize = 15 }; // RFC 3550 page 13
159
Patrik Höglund3e113432017-12-15 13:40:10160struct RTPHeader {
161 RTPHeader();
162 RTPHeader(const RTPHeader& other);
163 RTPHeader& operator=(const RTPHeader& other);
164
165 bool markerBit;
166 uint8_t payloadType;
167 uint16_t sequenceNumber;
168 uint32_t timestamp;
169 uint32_t ssrc;
170 uint8_t numCSRCs;
171 uint32_t arrOfCSRCs[kRtpCsrcSize];
172 size_t paddingLength;
173 size_t headerLength;
174 int payload_type_frequency;
175 RTPHeaderExtension extension;
176};
177
178// RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
179// RTCP mode is described by RFC 5506.
180enum class RtcpMode { kOff, kCompound, kReducedSize };
181
182enum NetworkState {
183 kNetworkUp,
184 kNetworkDown,
185};
186
Patrik Höglund3e113432017-12-15 13:40:10187} // namespace webrtc
188
189#endif // API_RTP_HEADERS_H_