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.

355 line
20KB

  1. /*
  2. * Copyright (c) 2021 ireader <tao3@outlook.com>. All rights reserved.
  3. */
  4. #ifndef _rtp_ext_h_
  5. #define _rtp_ext_h_
  6. #include <stdint.h>
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. // https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml
  11. // https://www.iana.org/assignments/rtcp-xr-block-types/rtcp-xr-block-types.xhtml
  12. /*
  13. RTCP Control Packet Types (PT)
  14. Value Abbrev. Name Reference
  15. 0 Reserved
  16. 1-191 Unassigned
  17. 192 Reserved (Historic-FIR) [RFC2032]
  18. 193 Reserved (Historic-NACK) [RFC2032]
  19. 194 SMPTETC SMPTE time-code mapping [RFC5484]
  20. 195 IJ Extended inter-arrival jitter report [RFC5450]
  21. 196-199 Unassigned
  22. 200 SR sender report [RFC3550]
  23. 201 RR receiver report [RFC3550]
  24. 202 SDES source description [RFC3550]
  25. 203 BYE goodbye [RFC3550]
  26. 204 APP application-defined [RFC3550]
  27. 205 RTPFB Generic RTP Feedback [RFC4585]
  28. 206 PSFB Payload-specific [RFC4585]
  29. 207 XR extended report [RFC3611]
  30. 208 AVB AVB RTCP packet ["Standard for Layer 3 Transport Protocol for Time Sensitive Applications in Local Area
  31. Networks." Work in progress.]
  32. 209 RSI Receiver Summary Information [RFC5760]
  33. 210 TOKEN Port Mapping [RFC6284]
  34. 211 IDMS IDMS Settings [RFC7272]
  35. 212 RGRS Reporting Group Reporting Sources [RFC8861]
  36. 213 SNM Splicing Notification Message [RFC8286]
  37. 214-254 Unassigned
  38. 255 Reserved
  39. RTP SDES Item Types
  40. Value Abbrev. Name Reference
  41. 0 END end of SDES list [RFC3550]
  42. 1 CNAME canonical name [RFC3550]
  43. 2 NAME user name [RFC3550]
  44. 3 EMAIL user's electronic mail address [RFC3550]
  45. 4 PHONE user's phone number [RFC3550]
  46. 5 LOC geographic user location [RFC3550]
  47. 6 TOOL name of application or tool [RFC3550]
  48. 7 NOTE notice about the source [RFC3550]
  49. 8 PRIV private extensions [RFC3550]
  50. 9 H323-CADDR H.323 callable address [Vineet_Kumar]
  51. 10 APSI Application Specific Identifier [RFC6776]
  52. 11 RGRP Reporting Group Identifier [RFC8861]
  53. 12 RtpStreamId RTP Stream Identifier [RFC8852]
  54. 13 RepairedRtpStreamId Repaired RTP Stream Identifier [RFC8852]
  55. 14 CCID CLUE CaptId [RFC8849]
  56. 15 MID Media Identification [RFC-ietf-mmusic-rfc8843bis-05]
  57. 16-255 Unassigned
  58. FMT Values for RTPFB Payload Types
  59. Value Name Long Name Reference
  60. 1 Generic NACK Generic negative acknowledgement [RFC4585]
  61. 2 Reserved [RFC5104]
  62. 3 TMMBR Temporary Maximum Media Stream Bit Rate Request [RFC5104]
  63. 4 TMMBN Temporary Maximum Media Stream Bit Rate Notification [RFC5104]
  64. 5 RTCP-SR-REQ RTCP Rapid Resynchronisation Request [RFC6051]
  65. 6 RAMS Rapid Acquisition of Multicast Sessions [RFC6285]
  66. 7 TLLEI Transport-Layer Third-Party Loss Early Indication [RFC6642]
  67. 8 RTCP-ECN-FB RTCP ECN Feedback [RFC6679]
  68. 9 PAUSE-RESUME Media Pause/Resume [RFC7728]
  69. 10 DBI Delay Budget Information (DBI) [3GPP TS 26.114 v16.3.0][Ozgur_Oyman]
  70. 11 CCFB RTP Congestion Control Feedback [RFC8888]
  71. 12-30 Unassigned
  72. 31 Extension Reserved for future extensions [RFC4585]
  73. FMT Values for PSFB Payload Types
  74. Value Name Long Name Reference
  75. 1 PLI Picture Loss Indication [RFC4585]
  76. 2 SLI Slice Loss Indication [RFC4585]
  77. 3 RPSI Reference Picture Selection Indication [RFC4585]
  78. 4 FIR Full Intra Request Command [RFC5104]
  79. 5 TSTR Temporal-Spatial Trade-off Request [RFC5104]
  80. 6 TSTN Temporal-Spatial Trade-off Notification [RFC5104]
  81. 7 VBCM Video Back Channel Message [RFC5104]
  82. 8 PSLEI Payload-Specific Third-Party Loss Early Indication [RFC6642]
  83. 9 ROI Video region-of-interest (ROI) [3GPP TS 26.114 v16.3.0][Ozgur_Oyman]
  84. 10 LRR Layer Refresh Request Command [RFC-ietf-avtext-lrr-07]
  85. 11-14 Unassigned
  86. 15 AFB Application Layer Feedback [RFC4585]
  87. 16-30 Unassigned
  88. 31 Extension Reserved for future extensions [RFC4585]
  89. RTP Compact Header Extensions
  90. Extension URI Description Contact Reference
  91. urn:ietf:params:rtp-hdrext:toffset Transmission Time offsets [Singer] [RFC5450]
  92. urn:ietf:params:rtp-hdrext:smpte-tc SMPTE time-code mapping [Singer] [RFC5484]
  93. urn:ietf:params:rtp-hdrext:ntp-64 Synchronisation metadata: 64-bit [Thomas_Schierl] [IETF Audio/Video Transport
  94. timestamp format Working Group][RFC6051]
  95. urn:ietf:params:rtp-hdrext:ntp-56 Synchronisation metadata: 56-bit [Thomas_Schierl] [IETF Audio/Video Transport
  96. timestamp format Working Group][RFC6051]
  97. urn:ietf:params:rtp-hdrext:ssrc-audio-level Audio Level [Jonathan_Lennox] [RFC6464]
  98. urn:ietf:params:rtp-hdrext:csrc-audio-level Mixer-to-client audio level indicators [Emil_Ivov] [RFC6465]
  99. urn:ietf:params:rtp-hdrext:encrypt Encrypted extension header element [Jonathan_Lennox] [RFC6904]
  100. urn:3gpp:video-orientation Coordination of video orientation (CVO) [Specifications_Manager_3GPP] [3GPP TS 26.114, version
  101. feature, see clause 6.2.3 12.5.0]
  102. Higher granularity (6-bit) coordination [3GPP TS 26.114, version
  103. urn:3gpp:video-orientation:6 of video orientation (CVO) feature, see [Specifications_Manager_3GPP] 12.5.0]
  104. clause 6.2.3
  105. Signalling of the arbitrary [3GPP TS 26.114, version
  106. urn:3gpp:roi-sent region-of-interest (ROI) information for [Specifications_Manager_3GPP] 13.1.0]
  107. the sent video, see clause 6.2.3.4
  108. Signalling of the predefined [3GPP TS 26.114, version
  109. urn:3gpp:predefined-roi-sent region-of-interest (ROI) information for [Specifications_Manager_3GPP] 13.1.0]
  110. the sent video, see clause 6.2.3.4
  111. Reserved as base URN for RTCP SDES items
  112. urn:ietf:params:rtp-hdrext:sdes that are also defined as RTP compact Authors of [RFC7941] [RFC7941]
  113. header extensions.
  114. urn:ietf:params:rtp-hdrext:splicing-interval Splicing Interval [Jinwei_Xia] [RFC8286]
  115. RTP SDES Compact Header Extensions
  116. Extension URI Description Contact Reference
  117. urn:ietf:params:rtp-hdrext:sdes:cname Source Description: Canonical Authors of [RFC7941] [RFC7941]
  118. End-Point Identifier (SDES CNAME)
  119. urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id RTP Stream Identifier [Adam_Roach] [RFC8852]
  120. urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id RTP Repaired Stream Identifier [Adam_Roach] [RFC8852]
  121. urn:ietf:params:rtp-hdrext:sdes:CaptId CLUE CaptId [Roni_Even] [RFC8849]
  122. urn:ietf:params:rtp-hdrext:sdes:mid Media identification [IESG] [RFC-ietf-mmusic-rfc8843bis-05]
  123. */
  124. enum RTPExtensionType {
  125. RTP_HDREXT_PADDING = 0,
  126. RTP_HDREXT_SSRC_AUDIO_LEVEL_ID, // [rfc6464] urn:ietf:params:rtp-hdrext:ssrc-audio-level
  127. RTP_HDREXT_CSRC_AUDIO_LEVEL_ID, // [rfc6465] urn:ietf:params:rtp-hdrext:csrc-audio-level
  128. RTP_HDREXT_FRAME_MARKING_ID, // [rfc8852] urn:ietf:params:rtp-hdrext:framemarking
  129. RTP_HDREXT_SDES_MID_ID, // [rfc8852] urn:ietf:params:rtp-hdrext:sdes:mid
  130. RTP_HDREXT_SDES_RTP_STREAM_ID, // urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id
  131. RTP_HDREXT_SDES_REPAIRED_RTP_STREAM_ID, // urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id
  132. RTP_HDREXT_TOFFSET_ID, // [rfc5450] urn:ietf:params:rtp-hdrext:toffset
  133. RTP_HDREXT_VIDEO_ORIENTATION_ID, // urn:3gpp:video-orientation (http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf)
  134. RTP_HDREXT_ABSOLUTE_SEND_TIME_ID, // http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
  135. RTP_HDREXT_ABSOLUTE_CAPTURE_TIME_ID, // http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time
  136. RTP_HDREXT_TRANSPORT_WIDE_CC_ID_01, // http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
  137. RTP_HDREXT_TRANSPORT_WIDE_CC_ID, // http://www.webrtc.org/experiments/rtp-hdrext/transport-wide-cc-02
  138. RTP_HDREXT_VIDEO_TIMING_ID, // http://www.webrtc.org/experiments/rtp-hdrext/video-timing
  139. RTP_HDREXT_PLAYOUT_DELAY_ID, // http://www.webrtc.org/experiments/rtp-hdrext/playout-delay
  140. RTP_HDREXT_ONE_BYTE_RESERVED,
  141. RTP_HDREXT_COLOR_SPACE_ID, // http://www.webrtc.org/experiments/rtp-hdrext/color-space
  142. RTP_HDREXT_VIDEO_CONTENT_TYPE_ID, // http://www.webrtc.org/experiments/rtp-hdrext/video-content-type
  143. RTP_HDREXT_INBAND_CN_ID, // http://www.webrtc.org/experiments/rtp-hdrext/inband-cn
  144. RTP_HDREXT_VIDEO_FRAME_TRACKING_ID, // http://www.webrtc.org/experiments/rtp-hdrext/video-frame-tracking-id
  145. RTP_HDREXT_VIDEO_LAYERS_ALLOCATION_ID, // http://www.webrtc.org/experiments/rtp-hdrext/video-layers-allocation00
  146. //RTP_HDREXT_GENERIC_FRAME_DESCRIPTOR_00, // http://www.webrtc.org/experiments/rtp-hdrext/generic-frame-descriptor-00
  147. //RTP_HDREXT_GENERIC_FRAME_DESCRIPTOR_02, // http://www.webrtc.org/experiments/rtp-hdrext/generic-frame-descriptor-02
  148. //RTP_HDREXT_ENCRYPT, // [rfc6904] urn:ietf:params:rtp-hdrext:encrypt
  149. RTP_HDREXT_NUM
  150. };
  151. enum
  152. {
  153. RTP_HDREXT_PROFILE_ONE_BYTE = 0xBEDE,
  154. RTP_HDREXT_PROFILE_TWO_BYTE = 0x1000,
  155. RTP_HDREXT_PROFILE_TWO_BYTE_FILTER = 0xFFF0,
  156. };
  157. enum { RTP_VIDEO_CONTENT_TYPE_UNSPECIFIED = 0, RTP_VIDEO_CONTENT_TYPE_SCREENSHARE };
  158. struct rtp_ext_uri_t
  159. {
  160. uint8_t id;
  161. const char* uri;
  162. };
  163. struct rtp_ext_data_t
  164. {
  165. uint32_t id : 8;
  166. uint32_t len : 8; // bytes
  167. uint32_t off : 16; // offset
  168. };
  169. struct rtp_ext_absolute_capture_time_t
  170. {
  171. uint64_t timestamp; // absolute capture timestamp
  172. uint64_t offset; // estimated capture clock offset
  173. };
  174. struct rtp_ext_transport_wide_cc_t
  175. {
  176. uint32_t seq : 16;
  177. uint32_t t : 1;
  178. uint32_t count : 15;
  179. };
  180. struct rtp_ext_video_orientation_t
  181. {
  182. int camera; // 1-Back-facing camera, 0-Front-facing camera
  183. int flip; // 1-Horizontal flip operation
  184. int rotaion; // 0/90/180/270
  185. };
  186. struct rtp_ext_video_timing_t
  187. {
  188. int flags; // 0x01-extension is set due to timer, 0x02-extension is set because the frame is larger than usual
  189. uint16_t encode_start;
  190. uint16_t encode_finish;
  191. uint16_t packetization_complete;
  192. uint16_t last_packet_left_the_pacer;
  193. uint16_t network_timestamp;
  194. uint16_t network_timestamp2;
  195. };
  196. struct rtp_ext_playout_delay_t
  197. {
  198. uint16_t min_delay;
  199. uint16_t max_delay;
  200. };
  201. struct rtp_ext_color_space_t
  202. {
  203. uint8_t primaries; // Color primaries value according to ITU-T H.273 Table 2.
  204. uint8_t transfer; // Transfer characteristic value according to ITU-T H.273 Table 3.
  205. uint8_t matrix; // Matrix coefficients value according to ITU-T H.273 Table 4.
  206. uint8_t range_chroma_siting; // https://www.webmproject.org/docs/container/#colour
  207. // HDR metadata(tow-byte RTP header extension)
  208. uint16_t luminance_max; // Luminance max, specified in nits, where 1 nit = 1 cd/m2. (16-bit unsigned integer)
  209. uint16_t luminance_min; // Luminance min, scaled by a factor of 10000 and specified in the unit 1/10000 nits. (16-bit unsigned integer)
  210. uint32_t mastering_metadata_primary_red; // CIE 1931 xy chromaticity coordinates of the primary red, scaled by a factor of 50000. (2x 16-bit unsigned integers)
  211. uint32_t mastering_metadata_primary_green; // CIE 1931 xy chromaticity coordinates of the primary green, scaled by a factor of 50000. (2x 16-bit unsigned integers)
  212. uint32_t mastering_metadata_primary_blue; // CIE 1931 xy chromaticity coordinates of the primary blue, scaled by a factor of 50000. (2x 16-bit unsigned integers)
  213. uint32_t mastering_metadata_primary_white; // CIE 1931 xy chromaticity coordinates of the white point, scaled by a factor of 50000. (2x 16-bit unsigned integers)
  214. uint16_t max_content_light_level; // Max content light level, specified in nits. (16-bit unsigned integer)
  215. uint16_t max_frame_average_light_level; // Max frame average light level, specified in nits. (16-bit unsigned integer)
  216. };
  217. struct rtp_ext_frame_marking_t
  218. {
  219. uint32_t s : 1; /* Start of Frame */
  220. uint32_t e : 1; /* End of Frame */
  221. uint32_t i : 1; /* Independent Frame */
  222. uint32_t d : 1; /* Discardable Frame */
  223. uint32_t b : 1; /* Base Layer Sync */
  224. uint32_t tid : 3; // The temporal layer ID of current frame
  225. uint32_t lid : 8;
  226. uint32_t tl0_pic_idx : 8; // 8 bits temporal layer zero index
  227. };
  228. struct rtp_ext_video_layers_allocation_t
  229. {
  230. uint8_t rid;
  231. };
  232. /// count: RTP_HDREXT_NUM-1(skip padding)
  233. /// @return ext id/uri
  234. const struct rtp_ext_uri_t* rtp_ext_list();
  235. const struct rtp_ext_uri_t* rtp_ext_find_uri(const char* uri);
  236. /// @param[out] exts parsed rtpext header payload offset/bytes (MUST memset(exts, 0, sizeof(exts)));
  237. /// @return 0-ok, other-error
  238. int rtp_ext_read(uint16_t profile, const uint8_t* data, int bytes, struct rtp_ext_data_t exts[256]);
  239. /// @param[in] profile RTP_HDREXT_PROFILE_ONE_BYTE/RTP_HDREXT_PROFILE_TWO_BYTE, 0-auto(detect one/two byte by length)
  240. /// @param[in] count rtp hdrext item count(exts)
  241. /// @return >0-ok, other-error
  242. int rtp_ext_write(uint16_t profile, const uint8_t* extension, const struct rtp_ext_data_t *exts, int count, uint8_t* data, int bytes);
  243. /// @param[in] n should be at least bytes + 1
  244. /// @return 0-ok, other-error
  245. int rtp_ext_string_parse(const uint8_t* data, int bytes, char* v, int n);
  246. /// @return write bytes
  247. int rtp_ext_string_write(uint8_t* data, int bytes, const char* v, int n);
  248. /// @param[out] activity 0-inactivity, 1-activity
  249. /// @return 0-ok, other-error
  250. int rtp_ext_ssrc_audio_level_parse(const uint8_t* data, int bytes, uint8_t* activity, uint8_t* level);
  251. /// @return write bytes
  252. int rtp_ext_ssrc_audio_level_write(uint8_t* data, int bytes, uint8_t activity, uint8_t level);
  253. /// @return 0-ok, other-error
  254. int rtp_ext_csrc_audio_level_parse(const uint8_t* data, int bytes, uint8_t levels[], int num);
  255. /// @return write bytes
  256. int rtp_ext_csrc_audio_level_write(uint8_t* data, int bytes, const uint8_t levels[], int num);
  257. /// @return 0-ok, other-error
  258. int rtp_ext_frame_marking_parse(const uint8_t* data, int bytes, struct rtp_ext_frame_marking_t* ext);
  259. /// @return write bytes
  260. int rtp_ext_frame_marking_write(uint8_t* data, int bytes, const struct rtp_ext_frame_marking_t* ext);
  261. //int rtp_ext_sdes_mid(void* param, const uint8_t* data, int bytes);
  262. //int rtp_ext_sdes_rtp_stream_id(void* param, const uint8_t* data, int bytes);
  263. //int rtp_ext_sdes_repaired_rtp_stream_id(void* param, const uint8_t* data, int bytes);
  264. /// @param[out] timestamp rtp time
  265. /// @return 0-ok, other-error
  266. int rtp_ext_toffset_parse(const uint8_t* data, int bytes, uint32_t* timestamp);
  267. /// @return write bytes
  268. int rtp_ext_toffset_write(uint8_t* data, int bytes, uint32_t timestamp);
  269. /// @param[out] rotaion 0/90/180/270
  270. /// @return 0-ok, other-error
  271. int rtp_ext_video_orientation_parse(const uint8_t* data, int bytes, struct rtp_ext_video_orientation_t* ext);
  272. /// @return write bytes
  273. int rtp_ext_video_orientation_write(uint8_t* data, int bytes, const struct rtp_ext_video_orientation_t* ext);
  274. /// @param[out] timestamp in millisecond
  275. /// @return 0-ok, other-error
  276. int rtp_ext_abs_send_time_parse(const uint8_t* data, int bytes, uint64_t* timestamp);
  277. /// @return write bytes
  278. int rtp_ext_abs_send_time_write(uint8_t* data, int bytes, uint64_t timestamp);
  279. /// @return 0-ok, other-error
  280. int rtp_ext_absolute_capture_time_parse(const uint8_t* data, int bytes, struct rtp_ext_absolute_capture_time_t* ext);
  281. /// @return write bytes
  282. int rtp_ext_absolute_capture_time_write(uint8_t* data, int bytes, const struct rtp_ext_absolute_capture_time_t* ext);
  283. /// @return 0-ok, other-error
  284. int rtp_ext_transport_wide_cc_parse(const uint8_t* data, int bytes, struct rtp_ext_transport_wide_cc_t* ext);
  285. /// @return write bytes(2-v1, 4-v2)
  286. int rtp_ext_transport_wide_cc_write(uint8_t* data, int bytes, const struct rtp_ext_transport_wide_cc_t* ext);
  287. /// @return 0-ok, other-error
  288. int rtp_ext_video_timing_parse(const uint8_t* data, int bytes, struct rtp_ext_video_timing_t* ext);
  289. /// @return write bytes
  290. int rtp_ext_video_timing_write(uint8_t* data, int bytes, const struct rtp_ext_video_timing_t* ext);
  291. /// @return 0-ok, other-error
  292. int rtp_ext_playout_delay_parse(const uint8_t* data, int bytes, struct rtp_ext_playout_delay_t* ext);
  293. /// @return write bytes
  294. int rtp_ext_playout_delay_write(uint8_t* data, int bytes, const struct rtp_ext_playout_delay_t* ext);
  295. /// @return 0-ok, other-error
  296. int rtp_ext_color_space_parse(const uint8_t* data, int bytes, struct rtp_ext_color_space_t* ext);
  297. /// @return write bytes
  298. int rtp_ext_color_space_write(uint8_t* data, int bytes, const struct rtp_ext_color_space_t* ext);
  299. /// @return 0-ok, other-error
  300. int rtp_ext_video_content_type_parse(const uint8_t* data, int bytes, uint8_t* ext);
  301. /// @return write bytes
  302. int rtp_ext_video_content_type_write(uint8_t* data, int bytes, uint8_t ext);
  303. /// @return 0-ok, other-error
  304. int rtp_ext_inband_cn_parse(const uint8_t* data, int bytes, uint8_t* level);
  305. /// @return write bytes
  306. int rtp_ext_inband_cn_write(uint8_t* data, int bytes, uint8_t level);
  307. /// @return 0-ok, other-error
  308. int rtp_ext_video_frame_tracking_id_parse(const uint8_t* data, int bytes, uint16_t* id);
  309. /// @return write bytes
  310. int rtp_ext_video_frame_tracking_id_write(uint8_t* data, int bytes, uint16_t id);
  311. /// @return 0-ok, other-error
  312. int rtp_ext_video_layers_allocation_parse(const uint8_t* data, int bytes, struct rtp_ext_video_layers_allocation_t* ext);
  313. /// @return write bytes
  314. int rtp_ext_video_layers_allocation_write(uint8_t* data, int bytes, const struct rtp_ext_video_layers_allocation_t* ext);
  315. #ifdef __cplusplus
  316. }
  317. #endif
  318. #endif /* !_rtp_ext_h_ */