Thanks to visit codestin.com
Credit goes to webrtc.googlesource.com

blob: 6ba3292fca8d610ca1a665d11d95e2a207f69aa3 [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
Florent Castelli8037fc62024-08-29 13:00:4017#include <optional>
Niels Möllerd57efc12019-03-22 13:02:1118#include <string>
Patrik Höglund3e113432017-12-15 13:40:1019
Sebastian Jansson3d61ab12019-06-14 11:35:5120#include "api/units/timestamp.h"
Johannes Kron09d65882018-11-27 13:36:4121#include "api/video/color_space.h"
Patrik Höglund3e113432017-12-15 13:40:1022#include "api/video/video_content_type.h"
23#include "api/video/video_rotation.h"
24#include "api/video/video_timing.h"
Dor Henaefed552024-06-18 13:20:3525#include "rtc_base/checks.h"
26#include "rtc_base/system/rtc_export.h"
Patrik Höglund3e113432017-12-15 13:40:1027
28namespace webrtc {
29
Johannes Kron075f6872019-02-14 13:41:0530struct FeedbackRequest {
31 // Determines whether the recv delta as specified in
32 // https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01
33 // should be included.
34 bool include_timestamps;
35 // Include feedback of received packets in the range [sequence_number -
Johannes Kron0da25a12019-03-06 08:34:1336 // sequence_count + 1, sequence_number]. That is, no feedback will be sent if
37 // sequence_count is zero.
Johannes Kron075f6872019-02-14 13:41:0538 int sequence_count;
39};
40
Chen Xingcd8a6e22019-07-01 08:56:5141// The Absolute Capture Time extension is used to stamp RTP packets with a NTP
42// timestamp showing when the first audio or video frame in a packet was
43// originally captured. The intent of this extension is to provide a way to
44// accomplish audio-to-video synchronization when RTCP-terminating intermediate
45// systems (e.g. mixers) are involved. See:
46// http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time
47struct AbsoluteCaptureTime {
48 // Absolute capture timestamp is the NTP timestamp of when the first frame in
49 // a packet was originally captured. This timestamp MUST be based on the same
50 // clock as the clock used to generate NTP timestamps for RTCP sender reports
51 // on the capture system.
52 //
53 // It’s not always possible to do an NTP clock readout at the exact moment of
54 // when a media frame is captured. A capture system MAY postpone the readout
55 // until a more convenient time. A capture system SHOULD have known delays
56 // (e.g. from hardware buffers) subtracted from the readout to make the final
57 // timestamp as close to the actual capture time as possible.
58 //
59 // This field is encoded as a 64-bit unsigned fixed-point number with the high
60 // 32 bits for the timestamp in seconds and low 32 bits for the fractional
61 // part. This is also known as the UQ32.32 format and is what the RTP
62 // specification defines as the canonical format to represent NTP timestamps.
63 uint64_t absolute_capture_timestamp;
64
65 // Estimated capture clock offset is the sender’s estimate of the offset
66 // between its own NTP clock and the capture system’s NTP clock. The sender is
67 // here defined as the system that owns the NTP clock used to generate the NTP
68 // timestamps for the RTCP sender reports on this stream. The sender system is
69 // typically either the capture system or a mixer.
70 //
71 // This field is encoded as a 64-bit two’s complement signed fixed-point
72 // number with the high 32 bits for the seconds and low 32 bits for the
73 // fractional part. It’s intended to make it easy for a receiver, that knows
74 // how to estimate the sender system’s NTP clock, to also estimate the capture
75 // system’s NTP clock:
76 //
77 // Capture NTP Clock = Sender NTP Clock + Capture Clock Offset
Florent Castelli8037fc62024-08-29 13:00:4078 std::optional<int64_t> estimated_capture_clock_offset;
Chen Xingcd8a6e22019-07-01 08:56:5179};
80
Joachim Reiersen5075cb42024-03-22 01:08:5481// The audio level extension is used to indicate the voice activity and the
82// audio level of the payload in the RTP stream. See:
83// https://tools.ietf.org/html/rfc6464#section-3.
84class AudioLevel {
85 public:
86 AudioLevel();
87 AudioLevel(bool voice_activity, int audio_level);
88 AudioLevel(const AudioLevel& other) = default;
89 AudioLevel& operator=(const AudioLevel& other) = default;
90
91 // Flag indicating whether the encoder believes the audio packet contains
92 // voice activity.
93 bool voice_activity() const { return voice_activity_; }
94
95 // Audio level in -dBov. Values range from 0 to 127, representing 0 to -127
96 // dBov. 127 represents digital silence.
97 int level() const { return audio_level_; }
98
99 private:
100 bool voice_activity_;
101 int audio_level_;
102};
103
Chen Xinge08648d2019-08-05 14:29:13104inline bool operator==(const AbsoluteCaptureTime& lhs,
105 const AbsoluteCaptureTime& rhs) {
106 return (lhs.absolute_capture_timestamp == rhs.absolute_capture_timestamp) &&
107 (lhs.estimated_capture_clock_offset ==
108 rhs.estimated_capture_clock_offset);
109}
110
111inline bool operator!=(const AbsoluteCaptureTime& lhs,
112 const AbsoluteCaptureTime& rhs) {
113 return !(lhs == rhs);
114}
115
Patrik Höglund3e113432017-12-15 13:40:10116struct RTPHeaderExtension {
117 RTPHeaderExtension();
118 RTPHeaderExtension(const RTPHeaderExtension& other);
119 RTPHeaderExtension& operator=(const RTPHeaderExtension& other);
120
Sebastian Jansson3d61ab12019-06-14 11:35:51121 static constexpr int kAbsSendTimeFraction = 18;
122
123 Timestamp GetAbsoluteSendTimestamp() const {
124 RTC_DCHECK(hasAbsoluteSendTime);
125 RTC_DCHECK(absoluteSendTime < (1ul << 24));
Danil Chapovalov0c626af2020-02-10 10:16:00126 return Timestamp::Micros((absoluteSendTime * 1000000ll) /
127 (1 << kAbsSendTimeFraction));
Sebastian Jansson3d61ab12019-06-14 11:35:51128 }
129
Patrik Höglund3e113432017-12-15 13:40:10130 bool hasTransmissionTimeOffset;
131 int32_t transmissionTimeOffset;
132 bool hasAbsoluteSendTime;
133 uint32_t absoluteSendTime;
Florent Castelli8037fc62024-08-29 13:00:40134 std::optional<AbsoluteCaptureTime> absolute_capture_time;
Patrik Höglund3e113432017-12-15 13:40:10135 bool hasTransportSequenceNumber;
136 uint16_t transportSequenceNumber;
Florent Castelli8037fc62024-08-29 13:00:40137 std::optional<FeedbackRequest> feedback_request;
Patrik Höglund3e113432017-12-15 13:40:10138
139 // Audio Level includes both level in dBov and voiced/unvoiced bit. See:
Chen Xingd2a66862019-06-03 12:53:42140 // https://tools.ietf.org/html/rfc6464#section-3
Florent Castelli8037fc62024-08-29 13:00:40141 std::optional<AudioLevel> audio_level() const { return audio_level_; }
Joachim Reiersen5075cb42024-03-22 01:08:54142
Florent Castelli8037fc62024-08-29 13:00:40143 void set_audio_level(std::optional<AudioLevel> audio_level) {
Joachim Reiersena341fe32024-04-16 21:33:29144 audio_level_ = audio_level;
145 }
Patrik Höglund3e113432017-12-15 13:40:10146
147 // For Coordination of Video Orientation. See
148 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
149 // ts_126114v120700p.pdf
150 bool hasVideoRotation;
151 VideoRotation videoRotation;
152
Florent Castelli8037fc62024-08-29 13:00:40153 // TODO(ilnik): Refactor this and one above to be std::optional() and remove
Patrik Höglund3e113432017-12-15 13:40:10154 // a corresponding bool flag.
155 bool hasVideoContentType;
156 VideoContentType videoContentType;
157
158 bool has_video_timing;
159 VideoSendTiming video_timing;
160
Niels Möllerd381eed2020-09-02 13:34:40161 VideoPlayoutDelay playout_delay;
Patrik Höglund3e113432017-12-15 13:40:10162
163 // For identification of a stream when ssrc is not signaled. See
Danil Chapovaloveb282982021-03-20 18:43:11164 // https://tools.ietf.org/html/rfc8852
Niels Möllerd57efc12019-03-22 13:02:11165 std::string stream_id;
166 std::string repaired_stream_id;
Patrik Höglund3e113432017-12-15 13:40:10167
168 // For identifying the media section used to interpret this RTP packet. See
Danil Chapovaloveb282982021-03-20 18:43:11169 // https://tools.ietf.org/html/rfc8843
Niels Möllerd57efc12019-03-22 13:02:11170 std::string mid;
Johannes Kronad1d9f02018-11-09 10:12:36171
Florent Castelli8037fc62024-08-29 13:00:40172 std::optional<ColorSpace> color_space;
Joachim Reiersena341fe32024-04-16 21:33:29173
174 private:
Florent Castelli8037fc62024-08-29 13:00:40175 std::optional<AudioLevel> audio_level_;
Patrik Höglund3e113432017-12-15 13:40:10176};
177
Niels Möller418f5802019-05-08 12:24:15178enum { kRtpCsrcSize = 15 }; // RFC 3550 page 13
179
Philipp Hancke48936382023-01-20 14:23:50180struct RTC_EXPORT RTPHeader {
Patrik Höglund3e113432017-12-15 13:40:10181 RTPHeader();
182 RTPHeader(const RTPHeader& other);
183 RTPHeader& operator=(const RTPHeader& other);
184
185 bool markerBit;
186 uint8_t payloadType;
187 uint16_t sequenceNumber;
188 uint32_t timestamp;
189 uint32_t ssrc;
190 uint8_t numCSRCs;
191 uint32_t arrOfCSRCs[kRtpCsrcSize];
192 size_t paddingLength;
193 size_t headerLength;
Patrik Höglund3e113432017-12-15 13:40:10194 RTPHeaderExtension extension;
195};
196
197// RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
198// RTCP mode is described by RFC 5506.
199enum class RtcpMode { kOff, kCompound, kReducedSize };
200
201enum NetworkState {
202 kNetworkUp,
203 kNetworkDown,
204};
205
Patrik Höglund3e113432017-12-15 13:40:10206} // namespace webrtc
207
208#endif // API_RTP_HEADERS_H_