blob: e5155f0d6712d3fb2f957fe0646861783e6b7dc2 [file] [log] [blame]
Patrik Höglund3e113432017-12-15 14:40:10 +01001/*
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 12:03:01 +020015#include <stdint.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020016
Niels Möllerd57efc12019-03-22 14:02:11 +010017#include <string>
Patrik Höglund3e113432017-12-15 14:40:10 +010018
Johannes Kronad1d9f02018-11-09 11:12:36 +010019#include "absl/types/optional.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010020#include "api/array_view.h"
Sebastian Jansson3d61ab12019-06-14 13:35:51 +020021#include "api/units/timestamp.h"
Johannes Kron09d65882018-11-27 14:36:41 +010022#include "api/video/color_space.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010023#include "api/video/video_content_type.h"
Johnny Leee0c8b232018-09-11 16:50:49 -040024#include "api/video/video_frame_marking.h"
Patrik Höglund3e113432017-12-15 14:40:10 +010025#include "api/video/video_rotation.h"
26#include "api/video/video_timing.h"
Yves Gerey665174f2018-06-19 15:03:05 +020027#include "common_types.h" // NOLINT(build/include)
Patrik Höglund3e113432017-12-15 14:40:10 +010028
29namespace webrtc {
30
Johannes Kron075f6872019-02-14 14:41:05 +010031struct FeedbackRequest {
32 // Determines whether the recv delta as specified in
33 // https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01
34 // should be included.
35 bool include_timestamps;
36 // Include feedback of received packets in the range [sequence_number -
Johannes Kron0da25a12019-03-06 09:34:13 +010037 // sequence_count + 1, sequence_number]. That is, no feedback will be sent if
38 // sequence_count is zero.
Johannes Kron075f6872019-02-14 14:41:05 +010039 int sequence_count;
40};
41
Chen Xingcd8a6e22019-07-01 10:56:51 +020042// The Absolute Capture Time extension is used to stamp RTP packets with a NTP
43// timestamp showing when the first audio or video frame in a packet was
44// originally captured. The intent of this extension is to provide a way to
45// accomplish audio-to-video synchronization when RTCP-terminating intermediate
46// systems (e.g. mixers) are involved. See:
47// http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time
48struct AbsoluteCaptureTime {
49 // Absolute capture timestamp is the NTP timestamp of when the first frame in
50 // a packet was originally captured. This timestamp MUST be based on the same
51 // clock as the clock used to generate NTP timestamps for RTCP sender reports
52 // on the capture system.
53 //
54 // It’s not always possible to do an NTP clock readout at the exact moment of
55 // when a media frame is captured. A capture system MAY postpone the readout
56 // until a more convenient time. A capture system SHOULD have known delays
57 // (e.g. from hardware buffers) subtracted from the readout to make the final
58 // timestamp as close to the actual capture time as possible.
59 //
60 // This field is encoded as a 64-bit unsigned fixed-point number with the high
61 // 32 bits for the timestamp in seconds and low 32 bits for the fractional
62 // part. This is also known as the UQ32.32 format and is what the RTP
63 // specification defines as the canonical format to represent NTP timestamps.
64 uint64_t absolute_capture_timestamp;
65
66 // Estimated capture clock offset is the sender’s estimate of the offset
67 // between its own NTP clock and the capture system’s NTP clock. The sender is
68 // here defined as the system that owns the NTP clock used to generate the NTP
69 // timestamps for the RTCP sender reports on this stream. The sender system is
70 // typically either the capture system or a mixer.
71 //
72 // This field is encoded as a 64-bit two’s complement signed fixed-point
73 // number with the high 32 bits for the seconds and low 32 bits for the
74 // fractional part. It’s intended to make it easy for a receiver, that knows
75 // how to estimate the sender system’s NTP clock, to also estimate the capture
76 // system’s NTP clock:
77 //
78 // Capture NTP Clock = Sender NTP Clock + Capture Clock Offset
79 absl::optional<int64_t> estimated_capture_clock_offset;
80};
81
Patrik Höglund3e113432017-12-15 14:40:10 +010082struct RTPHeaderExtension {
83 RTPHeaderExtension();
84 RTPHeaderExtension(const RTPHeaderExtension& other);
85 RTPHeaderExtension& operator=(const RTPHeaderExtension& other);
86
Sebastian Jansson3d61ab12019-06-14 13:35:51 +020087 static constexpr int kAbsSendTimeFraction = 18;
88
89 Timestamp GetAbsoluteSendTimestamp() const {
90 RTC_DCHECK(hasAbsoluteSendTime);
91 RTC_DCHECK(absoluteSendTime < (1ul << 24));
92 return Timestamp::us((absoluteSendTime * 1000000L) /
93 (1 << kAbsSendTimeFraction));
94 }
95
Patrik Höglund3e113432017-12-15 14:40:10 +010096 bool hasTransmissionTimeOffset;
97 int32_t transmissionTimeOffset;
98 bool hasAbsoluteSendTime;
99 uint32_t absoluteSendTime;
Chen Xingcd8a6e22019-07-01 10:56:51 +0200100 absl::optional<AbsoluteCaptureTime> absolute_capture_time;
Patrik Höglund3e113432017-12-15 14:40:10 +0100101 bool hasTransportSequenceNumber;
102 uint16_t transportSequenceNumber;
Johannes Kron075f6872019-02-14 14:41:05 +0100103 absl::optional<FeedbackRequest> feedback_request;
Patrik Höglund3e113432017-12-15 14:40:10 +0100104
105 // Audio Level includes both level in dBov and voiced/unvoiced bit. See:
Chen Xingd2a66862019-06-03 14:53:42 +0200106 // https://tools.ietf.org/html/rfc6464#section-3
Patrik Höglund3e113432017-12-15 14:40:10 +0100107 bool hasAudioLevel;
108 bool voiceActivity;
109 uint8_t audioLevel;
110
111 // For Coordination of Video Orientation. See
112 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
113 // ts_126114v120700p.pdf
114 bool hasVideoRotation;
115 VideoRotation videoRotation;
116
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200117 // TODO(ilnik): Refactor this and one above to be absl::optional() and remove
Patrik Höglund3e113432017-12-15 14:40:10 +0100118 // a corresponding bool flag.
119 bool hasVideoContentType;
120 VideoContentType videoContentType;
121
122 bool has_video_timing;
123 VideoSendTiming video_timing;
124
Johnny Leee0c8b232018-09-11 16:50:49 -0400125 bool has_frame_marking;
126 FrameMarking frame_marking;
127
Patrik Höglund3e113432017-12-15 14:40:10 +0100128 PlayoutDelay playout_delay = {-1, -1};
129
130 // For identification of a stream when ssrc is not signaled. See
131 // https://tools.ietf.org/html/draft-ietf-avtext-rid-09
132 // TODO(danilchap): Update url from draft to release version.
Niels Möllerd57efc12019-03-22 14:02:11 +0100133 std::string stream_id;
134 std::string repaired_stream_id;
Patrik Höglund3e113432017-12-15 14:40:10 +0100135
136 // For identifying the media section used to interpret this RTP packet. See
137 // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-38
Niels Möllerd57efc12019-03-22 14:02:11 +0100138 std::string mid;
Johannes Kronad1d9f02018-11-09 11:12:36 +0100139
Johannes Kron09d65882018-11-27 14:36:41 +0100140 absl::optional<ColorSpace> color_space;
Patrik Höglund3e113432017-12-15 14:40:10 +0100141};
142
Niels Möller418f5802019-05-08 14:24:15 +0200143enum { kRtpCsrcSize = 15 }; // RFC 3550 page 13
144
Patrik Höglund3e113432017-12-15 14:40:10 +0100145struct RTPHeader {
146 RTPHeader();
147 RTPHeader(const RTPHeader& other);
148 RTPHeader& operator=(const RTPHeader& other);
149
150 bool markerBit;
151 uint8_t payloadType;
152 uint16_t sequenceNumber;
153 uint32_t timestamp;
154 uint32_t ssrc;
155 uint8_t numCSRCs;
156 uint32_t arrOfCSRCs[kRtpCsrcSize];
157 size_t paddingLength;
158 size_t headerLength;
159 int payload_type_frequency;
160 RTPHeaderExtension extension;
161};
162
163// RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
164// RTCP mode is described by RFC 5506.
165enum class RtcpMode { kOff, kCompound, kReducedSize };
166
167enum NetworkState {
168 kNetworkUp,
169 kNetworkDown,
170};
171
Patrik Höglund3e113432017-12-15 14:40:10 +0100172} // namespace webrtc
173
174#endif // API_RTP_HEADERS_H_