rtp_header_extension_defines.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #ifndef RTP_HEADER_EXTENSION_DEFINES_H_
  2. #define RTP_HEADER_EXTENSION_DEFINES_H_
  3. #include <stdint.h>
  4. #include <vector>
  5. #include <string>
  6. // This enum must not have any gaps, i.e., all integers between
  7. // kRtpExtensionNone and kRtpExtensionNumberOfExtensions must be valid enum
  8. // entries.
  9. enum RTPExtensionType {
  10. kRtpExtensionNone,
  11. kRtpExtensionTransmissionTimeOffset,
  12. kRtpExtensionAudioLevel,
  13. kRtpExtensionAbsoluteSendTime,
  14. kRtpExtensionVideoRotation,
  15. kRtpExtensionTransportSequenceNumber,
  16. kRtpExtensionPlayoutDelay,
  17. kRtpExtensionVideoContentType,
  18. kRtpExtensionRtpStreamId,
  19. kRtpExtensionRepairedRtpStreamId,
  20. kRtpExtensionMid,
  21. kRtpExtensionNumberOfExtensions // Must be the last entity in the enum.
  22. };
  23. // enum for clockwise rotation.
  24. enum VideoRotation {
  25. kVideoRotation_0 = 0,
  26. kVideoRotation_90 = 90,
  27. kVideoRotation_180 = 180,
  28. kVideoRotation_270 = 270
  29. };
  30. // Please refer to http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/
  31. // 12.07.00_60/ts_126114v120700p.pdf Section 7.4.5. The rotation of a frame is
  32. // the clockwise angle the frames must be rotated in order to display the frames
  33. // correctly if the display is rotated in its natural orientation.
  34. inline uint8_t ConvertVideoRotationToCVOByte(VideoRotation rotation) {
  35. switch (rotation) {
  36. case kVideoRotation_0:
  37. return 0;
  38. case kVideoRotation_90:
  39. return 1;
  40. case kVideoRotation_180:
  41. return 2;
  42. case kVideoRotation_270:
  43. return 3;
  44. }
  45. return 0;
  46. }
  47. inline VideoRotation ConvertCVOByteToVideoRotation(uint8_t cvo_byte) {
  48. // CVO byte: |0 0 0 0 C F R R|.
  49. const uint8_t rotation_bits = cvo_byte & 0x3;
  50. switch (rotation_bits) {
  51. case 0:
  52. return kVideoRotation_0;
  53. case 1:
  54. return kVideoRotation_90;
  55. case 2:
  56. return kVideoRotation_180;
  57. case 3:
  58. return kVideoRotation_270;
  59. default:
  60. return kVideoRotation_0;
  61. }
  62. }
  63. // Minimum and maximum playout delay values from capture to render.
  64. // These are best effort values.
  65. //
  66. // A value < 0 indicates no change from previous valid value.
  67. //
  68. // min = max = 0 indicates that the receiver should try and render
  69. // frame as soon as possible.
  70. //
  71. // min = x, max = y indicates that the receiver is free to adapt
  72. // in the range (x, y) based on network jitter.
  73. //
  74. // Note: Given that this gets embedded in a union, it is up-to the owner to
  75. // initialize these values.
  76. struct PlayoutDelay {
  77. int min_ms;
  78. int max_ms;
  79. };
  80. enum VideoContentType {
  81. UNSPECIFIED = 0,
  82. SCREENSHARE = 1,
  83. };
  84. struct RTPHeaderExtension {
  85. RTPHeaderExtension();
  86. bool hasTransmissionTimeOffset;
  87. int32_t transmissionTimeOffset;
  88. bool hasAbsoluteSendTime;
  89. uint32_t absoluteSendTime;
  90. bool hasTransportSequenceNumber;
  91. uint16_t transportSequenceNumber;
  92. // Audio Level includes both level in dBov and voiced/unvoiced bit. See:
  93. // https://datatracker.ietf.org/doc/draft-lennox-avt-rtp-audio-level-exthdr/
  94. bool hasAudioLevel;
  95. bool voiceActivity;
  96. uint8_t audioLevel;
  97. // For Coordination of Video Orientation. See
  98. // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
  99. // ts_126114v120700p.pdf
  100. bool hasVideoRotation;
  101. VideoRotation videoRotation;
  102. // TODO(ilnik): Refactor this and one above to be absl::optional() and remove
  103. // a corresponding bool flag.
  104. bool hasVideoContentType;
  105. VideoContentType videoContentType;
  106. PlayoutDelay playout_delay;
  107. // For identification of a stream when ssrc is not signaled. See
  108. // https://tools.ietf.org/html/draft-ietf-avtext-rid-09
  109. // TODO(danilchap): Update url from draft to release version.
  110. std::string stream_id;
  111. std::string repaired_stream_id;
  112. // For identifying the media section used to interpret this RTP packet. See
  113. // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-38
  114. std::string mid;
  115. };
  116. // RTP header extension, see RFC8285.
  117. struct RtpExtension {
  118. RtpExtension();
  119. RtpExtension(const std::string& uri, int id);
  120. RtpExtension(const std::string& uri, int id, bool encrypt);
  121. ~RtpExtension();
  122. bool operator==(const RtpExtension& rhs) const {
  123. return uri == rhs.uri && id == rhs.id && encrypt == rhs.encrypt;
  124. }
  125. static bool IsSupportedForAudio(const std::string& uri);
  126. static bool IsSupportedForVideo(const std::string& uri);
  127. // Return "true" if the given RTP header extension URI may be encrypted.
  128. static bool IsEncryptionSupported(const std::string& uri);
  129. // Returns the named header extension if found among all extensions,
  130. // nullptr otherwise.
  131. static const RtpExtension* FindHeaderExtensionByUri(
  132. const std::vector<RtpExtension>& extensions,
  133. const std::string& uri);
  134. // Header extension for audio levels, as defined in:
  135. // http://tools.ietf.org/html/draft-ietf-avtext-client-to-mixer-audio-level-03
  136. static const char kAudioLevelUri[];
  137. // Header extension for RTP timestamp offset, see RFC 5450 for details:
  138. // http://tools.ietf.org/html/rfc5450
  139. static const char kTimestampOffsetUri[];
  140. // Header extension for absolute send time, see url for details:
  141. // http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
  142. static const char kAbsSendTimeUri[];
  143. // Header extension for coordination of video orientation, see url for
  144. // details:
  145. // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf
  146. static const char kVideoRotationUri[];
  147. // Header extension for video content type. E.g. default or screenshare.
  148. static const char kVideoContentTypeUri[];
  149. // Header extension for transport sequence number, see url for details:
  150. // http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions
  151. static const char kTransportSequenceNumberUri[];
  152. static const char kPlayoutDelayUri[];
  153. // Header extension for identifying media section within a transport.
  154. // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-49#section-15
  155. static const char kMidUri[];
  156. // Encryption of Header Extensions, see RFC 6904 for details:
  157. // https://tools.ietf.org/html/rfc6904
  158. static const char kEncryptHeaderExtensionsUri[];
  159. // Header extension for RIDs and Repaired RIDs
  160. // https://tools.ietf.org/html/draft-ietf-avtext-rid-09
  161. // https://tools.ietf.org/html/draft-ietf-mmusic-rid-15
  162. static const char kRidUri[];
  163. static const char kRepairedRidUri[];
  164. // Inclusive min and max IDs for two-byte header extensions and one-byte
  165. // header extensions, per RFC8285 Section 4.2-4.3.
  166. static const int kMinId = 1;
  167. static const int kMaxId = 255;
  168. static const int kMaxValueSize = 255;
  169. static const int kOneByteHeaderExtensionMaxId = 10;//14;
  170. static const int kOneByteHeaderExtensionMaxValueSize = 16;
  171. std::string uri;
  172. int id;
  173. bool encrypt;
  174. };
  175. #endif // RTP_HEADER_EXTENSION_DEFINES_H_