You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
7.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #ifndef API_RTP_HEADERS_H_
  11. #define API_RTP_HEADERS_H_
  12. #include <stddef.h>
  13. #include <stdint.h>
  14. #include <string>
  15. #include "absl/types/optional.h"
  16. #include "api/array_view.h"
  17. #include "api/units/timestamp.h"
  18. #include "api/video/color_space.h"
  19. #include "api/video/video_content_type.h"
  20. #include "api/video/video_frame_marking.h"
  21. #include "api/video/video_rotation.h"
  22. #include "api/video/video_timing.h"
  23. #include "common_types.h" // NOLINT(build/include)
  24. namespace webrtc {
  25. struct FeedbackRequest {
  26. // Determines whether the recv delta as specified in
  27. // https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01
  28. // should be included.
  29. bool include_timestamps;
  30. // Include feedback of received packets in the range [sequence_number -
  31. // sequence_count + 1, sequence_number]. That is, no feedback will be sent if
  32. // sequence_count is zero.
  33. int sequence_count;
  34. };
  35. // The Absolute Capture Time extension is used to stamp RTP packets with a NTP
  36. // timestamp showing when the first audio or video frame in a packet was
  37. // originally captured. The intent of this extension is to provide a way to
  38. // accomplish audio-to-video synchronization when RTCP-terminating intermediate
  39. // systems (e.g. mixers) are involved. See:
  40. // http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time
  41. struct AbsoluteCaptureTime {
  42. // Absolute capture timestamp is the NTP timestamp of when the first frame in
  43. // a packet was originally captured. This timestamp MUST be based on the same
  44. // clock as the clock used to generate NTP timestamps for RTCP sender reports
  45. // on the capture system.
  46. //
  47. // It’s not always possible to do an NTP clock readout at the exact moment of
  48. // when a media frame is captured. A capture system MAY postpone the readout
  49. // until a more convenient time. A capture system SHOULD have known delays
  50. // (e.g. from hardware buffers) subtracted from the readout to make the final
  51. // timestamp as close to the actual capture time as possible.
  52. //
  53. // This field is encoded as a 64-bit unsigned fixed-point number with the high
  54. // 32 bits for the timestamp in seconds and low 32 bits for the fractional
  55. // part. This is also known as the UQ32.32 format and is what the RTP
  56. // specification defines as the canonical format to represent NTP timestamps.
  57. uint64_t absolute_capture_timestamp;
  58. // Estimated capture clock offset is the sender’s estimate of the offset
  59. // between its own NTP clock and the capture system’s NTP clock. The sender is
  60. // here defined as the system that owns the NTP clock used to generate the NTP
  61. // timestamps for the RTCP sender reports on this stream. The sender system is
  62. // typically either the capture system or a mixer.
  63. //
  64. // This field is encoded as a 64-bit two’s complement signed fixed-point
  65. // number with the high 32 bits for the seconds and low 32 bits for the
  66. // fractional part. It’s intended to make it easy for a receiver, that knows
  67. // how to estimate the sender system’s NTP clock, to also estimate the capture
  68. // system’s NTP clock:
  69. //
  70. // Capture NTP Clock = Sender NTP Clock + Capture Clock Offset
  71. absl::optional<int64_t> estimated_capture_clock_offset;
  72. };
  73. inline bool operator==(const AbsoluteCaptureTime& lhs,
  74. const AbsoluteCaptureTime& rhs) {
  75. return (lhs.absolute_capture_timestamp == rhs.absolute_capture_timestamp) &&
  76. (lhs.estimated_capture_clock_offset ==
  77. rhs.estimated_capture_clock_offset);
  78. }
  79. inline bool operator!=(const AbsoluteCaptureTime& lhs,
  80. const AbsoluteCaptureTime& rhs) {
  81. return !(lhs == rhs);
  82. }
  83. struct RTPHeaderExtension {
  84. RTPHeaderExtension();
  85. RTPHeaderExtension(const RTPHeaderExtension& other);
  86. RTPHeaderExtension& operator=(const RTPHeaderExtension& other);
  87. static constexpr int kAbsSendTimeFraction = 18;
  88. Timestamp GetAbsoluteSendTimestamp() const {
  89. RTC_DCHECK(hasAbsoluteSendTime);
  90. RTC_DCHECK(absoluteSendTime < (1ul << 24));
  91. return Timestamp::us((absoluteSendTime * 1000000ll) /
  92. (1 << kAbsSendTimeFraction));
  93. }
  94. TimeDelta GetAbsoluteSendTimeDelta(uint32_t previous_sendtime) const {
  95. RTC_DCHECK(hasAbsoluteSendTime);
  96. RTC_DCHECK(absoluteSendTime < (1ul << 24));
  97. RTC_DCHECK(previous_sendtime < (1ul << 24));
  98. int32_t delta =
  99. static_cast<int32_t>((absoluteSendTime - previous_sendtime) << 8) >> 8;
  100. return TimeDelta::us((delta * 1000000ll) / (1 << kAbsSendTimeFraction));
  101. }
  102. bool hasTransmissionTimeOffset;
  103. int32_t transmissionTimeOffset;
  104. bool hasAbsoluteSendTime;
  105. uint32_t absoluteSendTime;
  106. absl::optional<AbsoluteCaptureTime> absolute_capture_time;
  107. bool hasTransportSequenceNumber;
  108. uint16_t transportSequenceNumber;
  109. absl::optional<FeedbackRequest> feedback_request;
  110. // Audio Level includes both level in dBov and voiced/unvoiced bit. See:
  111. // https://tools.ietf.org/html/rfc6464#section-3
  112. bool hasAudioLevel;
  113. bool voiceActivity;
  114. uint8_t audioLevel;
  115. // For Coordination of Video Orientation. See
  116. // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
  117. // ts_126114v120700p.pdf
  118. bool hasVideoRotation;
  119. VideoRotation videoRotation;
  120. // TODO(ilnik): Refactor this and one above to be absl::optional() and remove
  121. // a corresponding bool flag.
  122. bool hasVideoContentType;
  123. VideoContentType videoContentType;
  124. bool has_video_timing;
  125. VideoSendTiming video_timing;
  126. bool has_frame_marking;
  127. FrameMarking frame_marking;
  128. PlayoutDelay playout_delay = {-1, -1};
  129. // For identification of a stream when ssrc is not signaled. See
  130. // https://tools.ietf.org/html/draft-ietf-avtext-rid-09
  131. // TODO(danilchap): Update url from draft to release version.
  132. std::string stream_id;
  133. std::string repaired_stream_id;
  134. // For identifying the media section used to interpret this RTP packet. See
  135. // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-38
  136. std::string mid;
  137. absl::optional<ColorSpace> color_space;
  138. };
  139. enum { kRtpCsrcSize = 15 }; // RFC 3550 page 13
  140. struct RTPHeader {
  141. RTPHeader();
  142. RTPHeader(const RTPHeader& other);
  143. RTPHeader& operator=(const RTPHeader& other);
  144. bool markerBit;
  145. uint8_t payloadType;
  146. uint16_t sequenceNumber;
  147. uint32_t timestamp;
  148. uint32_t ssrc;
  149. uint8_t numCSRCs;
  150. uint32_t arrOfCSRCs[kRtpCsrcSize];
  151. size_t paddingLength;
  152. size_t headerLength;
  153. int payload_type_frequency;
  154. RTPHeaderExtension extension;
  155. };
  156. // RTCP mode to use. Compound mode is described by RFC 4585 and reduced-size
  157. // RTCP mode is described by RFC 5506.
  158. enum class RtcpMode { kOff, kCompound, kReducedSize };
  159. enum NetworkState {
  160. kNetworkUp,
  161. kNetworkDown,
  162. };
  163. } // namespace webrtc
  164. #endif // API_RTP_HEADERS_H_