25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rtcp-header.h 11KB

5 달 전
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. #ifndef _rtcp_header_h_
  2. #define _rtcp_header_h_
  3. #include <stdint.h>
  4. #define RTCP_V(v) ((v >> 30) & 0x03) // rtcp version
  5. #define RTCP_P(v) ((v >> 29) & 0x01) // rtcp padding
  6. #define RTCP_RC(v) ((v >> 24) & 0x1F) // rtcp reception report count
  7. #define RTCP_PT(v) ((v >> 16) & 0xFF) // rtcp packet type
  8. #define RTCP_LEN(v) (v & 0xFFFF) // rtcp packet length
  9. // https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml
  10. enum rtcp_type_t
  11. {
  12. RTCP_FIR = 192, // RFC2032, Reserved (Historic-FIR)
  13. RTCP_NACK = 193, // RFC2032, Reserved (Historic-NACK)
  14. RTCP_SMPTETC= 194, // RFC5484
  15. RTCP_IJ = 195, // RFC5450
  16. RTCP_SR = 200,
  17. RTCP_RR = 201,
  18. RTCP_SDES = 202,
  19. RTCP_BYE = 203,
  20. RTCP_APP = 204,
  21. RTCP_RTPFB = 205, // RFC4585
  22. RTCP_PSFB = 206, // RFC4585
  23. RTCP_XR = 207, // RFC3611
  24. RTCP_AVB = 208,
  25. RTCP_RSI = 209, // RFC5760
  26. RTCP_TOKEN = 210, // RFC6284
  27. RTCP_IDMS = 211, // RFC7272
  28. RTCP_RGRS = 212, // RFC8861
  29. RTCP_LIMIT = 223, // RFC5761 RTCP packet types in the ranges 1-191 and 224-254 SHOULD only be used when other values have been exhausted.
  30. };
  31. // https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-5
  32. enum rtcp_sdes_type_t
  33. {
  34. RTCP_SDES_END = 0, // RFC3550
  35. RTCP_SDES_CNAME = 1, // RFC3550
  36. RTCP_SDES_NAME = 2, // RFC3550
  37. RTCP_SDES_EMAIL = 3, // RFC3550
  38. RTCP_SDES_PHONE = 4, // RFC3550
  39. RTCP_SDES_LOC = 5, // RFC3550
  40. RTCP_SDES_TOOL = 6, // RFC3550
  41. RTCP_SDES_NOTE = 7, // RFC3550
  42. RTCP_SDES_PRIVATE = 8, // RFC3550
  43. RTCP_SDES_CADDR = 9, // H.323 callable address
  44. RTCP_SDES_APSI = 10, // RFC6776
  45. RTCP_SDES_RGRP = 11, // RFC8861
  46. RTCP_SDES_RID = 12, // RFC8852
  47. RTCP_SDES_RRID = 13, // RFC8852
  48. RTCP_SDES_CCID = 14, // RFC8849
  49. RTCP_SDES_MID = 15, // RFC8843
  50. };
  51. // https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-8
  52. enum rtcp_rtpfb_type_t
  53. {
  54. RTCP_RTPFB_NACK = 1, // RFC4585, Generic NACK
  55. RTCP_RTPFB_TMMBR = 3, // RFC5104, Temporary Maximum Media Stream Bit Rate Request (TMMBR)
  56. RTCP_RTPFB_TMMBN = 4, // RFC5104, Temporary Maximum Media Stream Bit Rate Notification (TMMBN)
  57. RTCP_RTPFB_SRREQ = 5, // RFC6051, RTCP Rapid Resynchronisation Request(RTCP-SR-REQ)
  58. RTCP_RTPFB_RAMS = 6, // RFC6285, Rapid Acquisition of Multicast Sessions
  59. RTCP_RTPFB_TLLEI = 7, // RFC6642, Transport-Layer Third-Party Loss Early Indication
  60. RTCP_RTPFB_ECN = 8, // RFC6679, RTCP ECN Feedback
  61. RTCP_RTPFB_PS = 9, // RFC7728, Media Pause/Resume
  62. RTCP_RTPFB_DBI = 10, // 3GPP TS 26.114 v16.3.0, Delay Budget Information (DBI)
  63. RTCP_RTPFB_CCFB = 11, // RFC8888, RTP Congestion Control Feedback
  64. RTCP_RTPFB_TCC01 = 15, // draft-holmer-rmcat-transport-wide-cc-extensions-01
  65. RTCP_RTPFB_EXT = 31,
  66. };
  67. // https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-9
  68. enum rtcp_psfb_type_t
  69. {
  70. RTCP_PSFB_PLI = 1, // RFC4585, Picture Loss Indication (PLI)
  71. RTCP_PSFB_SLI = 2, // RFC4585, Slice Loss Indication (SLI)
  72. RTCP_PSFB_RPSI = 3, // RFC4585, Reference Picture Selection Indication (RPSI)
  73. RTCP_PSFB_FIR = 4, // RFC5104, Full Intra Request (FIR)
  74. RTCP_PSFB_TSTR = 5, // RFC5104, Temporal-Spatial Trade-off Request
  75. RTCP_PSFB_TSTN = 6, // RFC5104, Temporal-Spatial Trade-off Notification
  76. RTCP_PSFB_VBCM = 7, // RFC5104, Video Back Channel Message
  77. RTCP_PSFB_PSLEI = 8, // RFC6642, Payload-Specific Third-Party Loss Early Indication
  78. RTCP_PSFB_ROI = 9, // 3GPP TS 26.114 v16.3.0, Video region-of-interest (ROI)
  79. RTCP_PSFB_LRR = 10, // RFC-ietf-avtext-lrr-07, Layer Refresh Request Command
  80. RTCP_PSFB_AFB = 15, // RFC4585, Application layer FB (AFB) message
  81. RTCP_PSFB_REMB = 15, // https://datatracker.ietf.org/doc/html/draft-alvestrand-rmcat-remb-03#section-2.2
  82. RTCP_PSFB_EXT = 31,
  83. };
  84. // https://www.iana.org/assignments/rtcp-xr-block-types/rtcp-xr-block-types.xhtml
  85. enum rtcp_xr_type_t
  86. {
  87. RTCP_XR_LRLE = 1, // RFC3611, Loss RLE Report Block
  88. RTCP_XR_DRLE = 2, // RFC3611, Duplicate RLE Report Block
  89. RTCP_XR_PRT = 3, // RFC3611, Packet Receipt Times Report Block
  90. RTCP_XR_RRT = 4, // RFC3611, Receiver Reference Time Report Block
  91. RTCP_XR_DLRR = 5, // RFC3611, DLRR Report Block
  92. RTCP_XR_SS = 6, // RFC3611, Statistics Summary Report Block
  93. RTCP_XR_VM = 7, // RFC3611, VoIP Metrics Report Block
  94. RTCP_XR_RTCP = 8, // RFC5093, RTCP XR
  95. RTCP_XR_IDMS = 12, // RFC7272, IDMS Report Block
  96. RTCP_XR_ECN = 13, // RFC6679, ECN Summary Report
  97. RTCP_XR_DISRLE = 25, // RFC7097, DRLE (Discard RLE Report)
  98. RTCP_XR_BDR = 26, // RFC7243, BDR (Bytes Discarded Report)
  99. RTCP_XR_RFISD = 27, // RFC7244, RFISD (RTP Flows Initial Synchronization Delay)
  100. RTCP_XR_RFSO = 28, // RFC7244, RFSO (RTP Flows Synchronization Offset Metrics Block)
  101. };
  102. typedef struct _rtcp_header_t
  103. {
  104. uint32_t v:2; // version
  105. uint32_t p:1; // padding
  106. uint32_t rc:5; // reception report count
  107. uint32_t pt:8; // packet type
  108. uint32_t length:16; /* pkt len in words, w/o this word */
  109. } rtcp_header_t;
  110. typedef struct _rtcp_sr_t // sender report
  111. {
  112. uint32_t ssrc;
  113. uint32_t ntpmsw; // ntp timestamp MSW(in second)
  114. uint32_t ntplsw; // ntp timestamp LSW(in picosecond)
  115. uint32_t rtpts; // rtp timestamp
  116. uint32_t spc; // sender packet count
  117. uint32_t soc; // sender octet count
  118. } rtcp_sr_t;
  119. typedef struct _rtcp_rr_t // receiver report
  120. {
  121. uint32_t ssrc;
  122. } rtcp_rr_t;
  123. typedef struct _rtcp_rb_t // report block
  124. {
  125. uint32_t ssrc;
  126. uint32_t fraction:8; // fraction lost
  127. uint32_t cumulative:24; // cumulative number of packets lost
  128. uint32_t exthsn; // extended highest sequence number received
  129. uint32_t jitter; // interarrival jitter
  130. uint32_t lsr; // last SR
  131. uint32_t dlsr; // delay since last SR
  132. } rtcp_rb_t;
  133. // source description RTCP packet
  134. typedef struct _rtcp_sdes_item_t
  135. {
  136. uint8_t pt; // chunk type
  137. uint8_t len;
  138. uint8_t *data;
  139. } rtcp_sdes_item_t;
  140. typedef struct _rtcp_bye_t
  141. {
  142. const void* reason;
  143. int bytes; // reason length
  144. } rtcp_bye_t;
  145. typedef struct _rtcp_app_t
  146. {
  147. uint8_t subtype;
  148. char name[4];
  149. void* data;
  150. int bytes; // data length
  151. } rtcp_app_t;
  152. // Slice Loss Indication (SLI)
  153. typedef struct _rtcp_sli_t
  154. {
  155. uint32_t first : 13; // The macroblock (MB) address of the first lost macroblock.
  156. uint32_t number : 13; // The number of lost macroblocks, in scan order
  157. uint32_t picture_id : 6;
  158. } rtcp_sli_t;
  159. // Full Intra Request (FIR)
  160. typedef struct _rtcp_fir_t
  161. {
  162. uint32_t ssrc;
  163. uint32_t sn : 8; // Command sequence number
  164. uint32_t reserved : 19;
  165. uint32_t index : 5; // for TSTR
  166. } rtcp_fir_t;
  167. // Video Back Channel Message (VBCM)
  168. typedef struct _rtcp_vbcm_t
  169. {
  170. uint32_t ssrc;
  171. uint32_t sn : 8; // Command sequence number
  172. uint32_t reserved : 1;
  173. uint32_t pt : 7;
  174. uint32_t len: 16;
  175. void* payload;
  176. } rtcp_vbcm_t;
  177. // Layer Refresh Request
  178. typedef struct _rtcp_lrr_t
  179. {
  180. uint32_t ssrc;
  181. uint32_t sn : 8; // Command sequence number
  182. uint32_t c : 1;
  183. uint32_t payload : 7;
  184. uint32_t reserved : 16; // Reserved
  185. uint32_t res1 : 5; // reserved
  186. uint32_t ttid : 3; // Target Temporal Layer ID (TTID) (3 bits)
  187. uint32_t tlid : 8; // Target Layer ID (TLID) (8 bits)
  188. uint32_t res2 : 5; // reserved
  189. uint32_t ctid : 3; // Current Temporal Layer ID (CTID) (3 bits)
  190. uint32_t clid : 8; // Current Layer ID (CLID) (8 bits)
  191. } rtcp_lrr_t;
  192. // Generic NACK
  193. typedef struct _rtcp_nack_t
  194. {
  195. uint16_t pid; // Packet ID (PID)
  196. uint16_t blp; // bitmask of following lost packets (BLP)
  197. } rtcp_nack_t;
  198. // Temporary Maximum Media Stream Bit Rate Request (TMMBR)
  199. typedef struct _rtcp_tmmbr_t
  200. {
  201. uint32_t ssrc;
  202. uint32_t exp : 6; // MxTBR Exp (6 bits)
  203. uint32_t mantissa : 17; // MxTBR Mantissa (17 bits)
  204. uint32_t overhead : 9; // Measured Overhead (9 bits)
  205. // maximum total media bit rate(MxTBR)
  206. // MxTBR = mantissa * 2^exp
  207. } rtcp_tmmbr_t;
  208. // RTP/AVPF Transport-Layer ECN Feedback Packet(ECN)
  209. typedef struct _rtcp_ecn_t
  210. {
  211. uint32_t ext_highest_seq; // 32-bit extended highest sequence number received
  212. uint32_t ect[2]; // The 32-bit cumulative number of RTP packets received from this SSRC.
  213. uint16_t ect_ce_counter;
  214. uint16_t not_ect_counter;
  215. uint16_t lost_packets_counter;
  216. uint16_t duplication_counter;
  217. } rtcp_ecn_t;
  218. typedef struct _rtcp_remb_t
  219. {
  220. uint32_t ssrc;
  221. uint32_t exp : 6; // BR Exp (6 bits)
  222. uint32_t mantissa : 18; // BR Mantissa (18 bits) in bps
  223. // maximum total media bit rate(MxTBR)
  224. // MxTBR = mantissa * 2^exp
  225. } rtcp_remb_t;
  226. // RTP Congestion Control Feedback
  227. typedef struct _rtcp_ccfb_t
  228. {
  229. uint32_t seq : 16;
  230. uint32_t received : 1;
  231. uint32_t ecn : 2; // 00 if not received or if ECN is not used
  232. //uint32_t ato : 13;
  233. int16_t ato; // ms * 1024, Arrival time offset (ATO, 13 bits) & (TCC-01 16 bits)
  234. } rtcp_ccfb_t;
  235. // DLRR Report Block
  236. typedef struct _rtcp_dlrr_t
  237. {
  238. uint32_t ssrc;
  239. uint32_t lrr;
  240. uint32_t dlrr;
  241. } rtcp_dlrr_t;
  242. typedef struct _rtcp_rtpfb_t
  243. {
  244. uint32_t media; // media ssrc
  245. union
  246. {
  247. // RTCP_RTPFB | (RTCP_RTPFB_NACK << 8)
  248. // RTCP_RTPFB | (RTCP_RTPFB_TLLEI << 8)
  249. struct
  250. {
  251. rtcp_nack_t* nack;
  252. int count;
  253. } nack;
  254. // RTCP_RTPFB | (RTCP_RTPFB_TMMBR << 8)
  255. // RTCP_RTPFB | (RTCP_RTPFB_TMMBN << 8)
  256. struct
  257. {
  258. rtcp_tmmbr_t* tmmbr;
  259. int count;
  260. } tmmbr;
  261. // RTCP_RTPFB | (RTCP_RTPFB_CCFB << 8)
  262. // RTCP_RTPFB | (RTCP_RTPFB_TCC01 << 8)
  263. struct
  264. {
  265. rtcp_ccfb_t* ccfb;
  266. int count;
  267. int32_t timestamp;
  268. uint32_t begin : 16;
  269. uint32_t cc : 8; // TCC01 only
  270. uint32_t ssrc; // ccfb only
  271. } tcc01;
  272. // RTCP_RTPFB | (RTCP_RTPFB_PS << 8)
  273. struct
  274. {
  275. uint32_t target;
  276. uint32_t cmd : 8;
  277. uint32_t len : 8;
  278. uint32_t id : 16;
  279. void* payload;
  280. } ps;
  281. // RTCP_RTPFB | (RTCP_RTPFB_ECN << 8)
  282. rtcp_ecn_t ecn;
  283. // RTCP_RTPFB | (RTCP_RTPFB_DBI << 8)
  284. struct
  285. {
  286. uint32_t delay : 16;
  287. uint32_t s : 1;
  288. uint32_t q : 1;
  289. } dbi;
  290. } u;
  291. } rtcp_rtpfb_t;
  292. typedef struct _rtcp_psfb_t
  293. {
  294. uint32_t media; // media ssrc
  295. union
  296. {
  297. // RTCP_PSFB | (RTCP_PSFB_PLI << 8)
  298. // RTCP_PSFB | (RTCP_PSFB_SLI << 8)
  299. struct
  300. {
  301. rtcp_sli_t* sli;
  302. int count;
  303. } sli;
  304. // RTCP_PSFB | (RTCP_PSFB_FIR << 8)
  305. // RTCP_PSFB | (RTCP_PSFB_TSTR << 8)
  306. // RTCP_PSFB | (RTCP_PSFB_TSTN << 8)
  307. struct
  308. {
  309. rtcp_fir_t* fir;
  310. int count;
  311. } fir;
  312. // RTCP_PSFB | (RTCP_PSFB_VBCM << 8)
  313. struct
  314. {
  315. uint8_t pt;
  316. uint32_t len; // length in bit
  317. void* payload;
  318. } rpsi;
  319. // RTCP_PSFB | (RTCP_PSFB_VBCM << 8)
  320. rtcp_vbcm_t vbcm;
  321. // RTCP_PSFB | (RTCP_PSFB_PSLEI << 8)
  322. struct
  323. {
  324. uint32_t* ssrc;
  325. int count;
  326. } pslei;
  327. // RTCP_PSFB | (RTCP_PSFB_LRR << 8)
  328. struct
  329. {
  330. rtcp_lrr_t* lrr;
  331. int count;
  332. } lrr;
  333. // RTCP_PSFB | (RTCP_PSFB_AFB << 8)
  334. struct
  335. {
  336. rtcp_remb_t* remb;
  337. int count;
  338. } afb;
  339. } u;
  340. } rtcp_psfb_t;
  341. typedef struct _rtcp_xr_t
  342. {
  343. union
  344. {
  345. // RTCP_XR | (RTCP_XR_LRLE << 8)
  346. // RTCP_XR | (RTCP_XR_DRLE << 8)
  347. struct
  348. {
  349. uint32_t source; // SSRC of source
  350. uint32_t begin : 16; // begin_seq
  351. uint32_t end : 16; // end_seq
  352. uint8_t* chunk;
  353. int count;
  354. } rle; // lrle/drle
  355. // RTCP_XR | (RTCP_XR_PRT << 8)
  356. struct
  357. {
  358. uint32_t source; // SSRC of source
  359. uint32_t begin : 16; // begin_seq
  360. uint32_t end : 16; // end_seq
  361. uint32_t* timestamp;
  362. int count;
  363. } prt;
  364. // RTCP_XR | (RTCP_XR_RRT << 8)
  365. uint64_t rrt;
  366. // RTCP_XR | (RTCP_XR_DLRR << 8)
  367. struct
  368. {
  369. rtcp_dlrr_t* dlrr;
  370. int count;
  371. } dlrr;
  372. // RTCP_XR | (RTCP_XR_ECN << 8)
  373. rtcp_ecn_t ecn;
  374. } u;
  375. } rtcp_xr_t;
  376. #endif /* !_rtcp_header_h_ */