Patrik Höglund | 3e11343 | 2017-12-15 13:40:10 | [diff] [blame] | 1 | /* |
| 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 Gerey | 988cc08 | 2018-10-23 10:03:01 | [diff] [blame] | 15 | #include <stdint.h> |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 16 | |
Niels Möller | d57efc1 | 2019-03-22 13:02:11 | [diff] [blame] | 17 | #include <string> |
Patrik Höglund | 3e11343 | 2017-12-15 13:40:10 | [diff] [blame] | 18 | |
Johannes Kron | ad1d9f0 | 2018-11-09 10:12:36 | [diff] [blame] | 19 | #include "absl/types/optional.h" |
Patrik Höglund | 3e11343 | 2017-12-15 13:40:10 | [diff] [blame] | 20 | #include "api/array_view.h" |
Sebastian Jansson | 3d61ab1 | 2019-06-14 11:35:51 | [diff] [blame] | 21 | #include "api/units/timestamp.h" |
Johannes Kron | 09d6588 | 2018-11-27 13:36:41 | [diff] [blame] | 22 | #include "api/video/color_space.h" |
Patrik Höglund | 3e11343 | 2017-12-15 13:40:10 | [diff] [blame] | 23 | #include "api/video/video_content_type.h" |
Johnny Lee | e0c8b23 | 2018-09-11 20:50:49 | [diff] [blame] | 24 | #include "api/video/video_frame_marking.h" |
Patrik Höglund | 3e11343 | 2017-12-15 13:40:10 | [diff] [blame] | 25 | #include "api/video/video_rotation.h" |
| 26 | #include "api/video/video_timing.h" |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 27 | #include "common_types.h" // NOLINT(build/include) |
Patrik Höglund | 3e11343 | 2017-12-15 13:40:10 | [diff] [blame] | 28 | |
| 29 | namespace webrtc { |
| 30 | |
Johannes Kron | 075f687 | 2019-02-14 13:41:05 | [diff] [blame] | 31 | struct 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 Kron | 0da25a1 | 2019-03-06 08:34:13 | [diff] [blame] | 37 | // sequence_count + 1, sequence_number]. That is, no feedback will be sent if |
| 38 | // sequence_count is zero. |
Johannes Kron | 075f687 | 2019-02-14 13:41:05 | [diff] [blame] | 39 | int sequence_count; |
| 40 | }; |
| 41 | |
Chen Xing | cd8a6e2 | 2019-07-01 08:56:51 | [diff] [blame] | 42 | // 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 |
| 48 | struct 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 | |
Chen Xing | e08648d | 2019-08-05 14:29:13 | [diff] [blame] | 82 | inline bool operator==(const AbsoluteCaptureTime& lhs, |
| 83 | const AbsoluteCaptureTime& rhs) { |
| 84 | return (lhs.absolute_capture_timestamp == rhs.absolute_capture_timestamp) && |
| 85 | (lhs.estimated_capture_clock_offset == |
| 86 | rhs.estimated_capture_clock_offset); |
| 87 | } |
| 88 | |
| 89 | inline bool operator!=(const AbsoluteCaptureTime& lhs, |
| 90 | const AbsoluteCaptureTime& rhs) { |
| 91 | return !(lhs == rhs); |
| 92 | } |
| 93 | |
Patrik Höglund | 3e11343 | 2017-12-15 13:40:10 | [diff] [blame] | 94 | struct RTPHeaderExtension { |
| 95 | RTPHeaderExtension(); |
| 96 | RTPHeaderExtension(const RTPHeaderExtension& other); |
| 97 | RTPHeaderExtension& operator=(const RTPHeaderExtension& other); |
| 98 | |
Sebastian Jansson | 3d61ab1 | 2019-06-14 11:35:51 | [diff] [blame] | 99 | static constexpr int kAbsSendTimeFraction = 18; |
| 100 | |
| 101 | Timestamp GetAbsoluteSendTimestamp() const { |
| 102 | RTC_DCHECK(hasAbsoluteSendTime); |
| 103 | RTC_DCHECK(absoluteSendTime < (1ul << 24)); |
| 104 | return Timestamp::us((absoluteSendTime * 1000000L) / |
| 105 | (1 << kAbsSendTimeFraction)); |
| 106 | } |
| 107 | |
Patrik Höglund | 3e11343 | 2017-12-15 13:40:10 | [diff] [blame] | 108 | bool hasTransmissionTimeOffset; |
| 109 | int32_t transmissionTimeOffset; |
| 110 | bool hasAbsoluteSendTime; |
| 111 | uint32_t absoluteSendTime; |
Chen Xing | cd8a6e2 | 2019-07-01 08:56:51 | [diff] [blame] | 112 | absl::optional<AbsoluteCaptureTime> absolute_capture_time; |
Patrik Höglund | 3e11343 | 2017-12-15 13:40:10 | [diff] [blame] | 113 | bool hasTransportSequenceNumber; |
| 114 | uint16_t transportSequenceNumber; |
Johannes Kron | 075f687 | 2019-02-14 13:41:05 | [diff] [blame] | 115 | absl::optional<FeedbackRequest> feedback_request; |
Patrik Höglund | 3e11343 | 2017-12-15 13:40:10 | [diff] [blame] | 116 | |
| 117 | // Audio Level includes both level in dBov and voiced/unvoiced bit. See: |
Chen Xing | d2a6686 | 2019-06-03 12:53:42 | [diff] [blame] | 118 | // https://tools.ietf.org/html/rfc6464#section-3 |
Patrik Höglund | 3e11343 | 2017-12-15 13:40:10 | [diff] [blame] | 119 | bool hasAudioLevel; |
| 120 | bool voiceActivity; |
| 121 | uint8_t audioLevel; |
| 122 | |
| 123 | // For Coordination of Video Orientation. See |
| 124 | // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ |
| 125 | // ts_126114v120700p.pdf |
| 126 | bool hasVideoRotation; |
| 127 | VideoRotation videoRotation; |
| 128 | |
Danil Chapovalov | 0bc58cf | 2018-06-21 11:32:56 | [diff] [blame] | 129 | // TODO(ilnik): Refactor this and one above to be absl::optional() and remove |
Patrik Höglund | 3e11343 | 2017-12-15 13:40:10 | [diff] [blame] | 130 | // a corresponding bool flag. |
| 131 | bool hasVideoContentType; |
| 132 | VideoContentType videoContentType; |
| 133 | |
| 134 | bool has_video_timing; |
| 135 | VideoSendTiming video_timing; |
| 136 | |
Johnny Lee | e0c8b23 | 2018-09-11 20:50:49 | [diff] [blame] | 137 | bool has_frame_marking; |
| 138 | FrameMarking frame_marking; |
| 139 | |
Patrik Höglund | 3e11343 | 2017-12-15 13:40:10 | [diff] [blame] | 140 | PlayoutDelay playout_delay = {-1, -1}; |
| 141 | |
| 142 | // For identification of a stream when ssrc is not signaled. See |
| 143 | // https://tools.ietf.org/html/draft-ietf-avtext-rid-09 |
| 144 | // TODO(danilchap): Update url from draft to release version. |
Niels Möller | d57efc1 | 2019-03-22 13:02:11 | [diff] [blame] | 145 | std::string stream_id; |
| 146 | std::string repaired_stream_id; |
Patrik Höglund | 3e11343 | 2017-12-15 13:40:10 | [diff] [blame] | 147 | |
| 148 | // For identifying the media section used to interpret this RTP packet. See |
| 149 | // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-38 |
Niels Möller | d57efc1 | 2019-03-22 13:02:11 | [diff] [blame] | 150 | std::string mid; |
Johannes Kron | ad1d9f0 | 2018-11-09 10:12:36 | [diff] [blame] | 151 | |
Johannes Kron | 09d6588 | 2018-11-27 13:36:41 | [diff] [blame] | 152 | absl::optional<ColorSpace> color_space; |
Patrik Höglund | 3e11343 | 2017-12-15 13:40:10 | [diff] [blame] | 153 | }; |
| 154 | |
Niels Möller | 418f580 | 2019-05-08 12:24:15 | [diff] [blame] | 155 | enum { kRtpCsrcSize = 15 }; // RFC 3550 page 13 |
| 156 | |
Patrik Höglund | 3e11343 | 2017-12-15 13:40:10 | [diff] [blame] | 157 | struct RTPHeader { |
| 158 | RTPHeader(); |
| 159 | RTPHeader(const RTPHeader& other); |
| 160 | RTPHeader& operator=(const RTPHeader& other); |
| 161 | |
| 162 | bool markerBit; |
| 163 | uint8_t payloadType; |
| 164 | uint16_t sequenceNumber; |
| 165 | uint32_t timestamp; |
| 166 | uint32_t ssrc; |
| 167 | uint8_t numCSRCs; |
| 168 | uint32_t arrOfCSRCs[kRtpCsrcSize]; |
| 169 | size_t paddingLength; |
| 170 | size_t headerLength; |
| 171 | int payload_type_frequency; |
| 172 | RTPHeaderExtension extension; |
| 173 | }; |
| 174 | |
| 175 | // RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size |
| 176 | // RTCP mode is described by RFC 5506. |
| 177 | enum class RtcpMode { kOff, kCompound, kReducedSize }; |
| 178 | |
| 179 | enum NetworkState { |
| 180 | kNetworkUp, |
| 181 | kNetworkDown, |
| 182 | }; |
| 183 | |
Patrik Höglund | 3e11343 | 2017-12-15 13:40:10 | [diff] [blame] | 184 | } // namespace webrtc |
| 185 | |
| 186 | #endif // API_RTP_HEADERS_H_ |