rtcp_fb.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. /*
  2. * Copyright (C) 2018 Teluu Inc. (http://www.teluu.com)
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #ifndef __PJMEDIA_RTCP_FB_H__
  19. #define __PJMEDIA_RTCP_FB_H__
  20. /**
  21. * @file rtcp_fb.h
  22. * @brief RTCP Feedback implementation.
  23. */
  24. #include <pjmedia/rtcp.h>
  25. #include <pjmedia/sdp.h>
  26. PJ_BEGIN_DECL
  27. /**
  28. * @defgroup PJMED_RTCP_FB RTCP Feedback - RFC 4585
  29. * @ingroup PJMEDIA_SESSION
  30. * @brief RTCP Feedback extension to RTCP session
  31. * @{
  32. *
  33. * PJMEDIA implements RTCP Feedback specification (RFC 4585) to enable
  34. * receivers to provide more immediate feedback to the senders.
  35. */
  36. /**
  37. * Enumeration of RTCP Feedback types. Each feedback type may have subtypes,
  38. * which should be specified in feedback parameters.
  39. */
  40. typedef enum pjmedia_rtcp_fb_type
  41. {
  42. /**
  43. * Positive acknowledgement feedbacks. Sample subtypes are Reference Picture
  44. * Selection Indication (RPSI) and application layer feedbacks.
  45. */
  46. PJMEDIA_RTCP_FB_ACK,
  47. /**
  48. * Negative acknowledgement feedbacks. Sample subtypes are generic NACK,
  49. * Picture Loss Indication (PLI), Slice Loss Indication (SLI), Reference
  50. * Picture Selection Indication (RPSI), and application layer feedbacks.
  51. */
  52. PJMEDIA_RTCP_FB_NACK,
  53. /**
  54. * Minimum interval between two regular RTCP packets.
  55. */
  56. PJMEDIA_RTCP_FB_TRR_INT,
  57. /**
  58. * Other feedback types.
  59. */
  60. PJMEDIA_RTCP_FB_OTHER
  61. } pjmedia_rtcp_fb_type;
  62. /**
  63. * This structure declare RTCP Feedback capability.
  64. */
  65. typedef struct pjmedia_rtcp_fb_cap
  66. {
  67. /**
  68. * Specify the codecs to which the capability is applicable. Codec ID is
  69. * using the same format as in pjmedia_codec_mgr_find_codecs_by_id() and
  70. * pjmedia_vid_codec_mgr_find_codecs_by_id(), e.g: "L16/8000/1", "PCMU",
  71. * "H264". This can also be an asterisk ("*") to represent all codecs.
  72. */
  73. pj_str_t codec_id;
  74. /**
  75. * Specify the RTCP Feedback type.
  76. */
  77. pjmedia_rtcp_fb_type type;
  78. /**
  79. * Specify the type name if RTCP Feedback type is PJMEDIA_RTCP_FB_OTHER.
  80. */
  81. pj_str_t type_name;
  82. /**
  83. * Specify the RTCP Feedback parameters. Feedback subtypes should be
  84. * specified in this field, e.g:
  85. * - 'pli' for Picture Loss Indication feedback,
  86. * - 'sli' for Slice Loss Indication feedback,
  87. * - 'rpsi' for Reference Picture Selection Indication feedback,
  88. * - 'app' for specific/proprietary application layer feedback.
  89. */
  90. pj_str_t param;
  91. } pjmedia_rtcp_fb_cap;
  92. /**
  93. * This structure declares RTCP Feedback information.
  94. */
  95. typedef struct pjmedia_rtcp_fb_info
  96. {
  97. /**
  98. * Number of RTCP Feedback capabilities.
  99. */
  100. unsigned cap_count;
  101. /**
  102. * The RTCP Feedback capabilities.
  103. */
  104. pjmedia_rtcp_fb_cap caps[PJMEDIA_RTCP_FB_MAX_CAP];
  105. } pjmedia_rtcp_fb_info;
  106. /**
  107. * This structure declares RTCP Feedback configuration settings.
  108. */
  109. typedef struct pjmedia_rtcp_fb_setting
  110. {
  111. /**
  112. * Specify whether transport protocol in SDP media description uses
  113. * RTP/AVP instead of RTP/AVPF. Note that RFC4585 mandates to signal
  114. * RTP/AVPF profile, but it may cause SDP negotiation failure when
  115. * negotiating with endpoints that does not support RTP/AVPF (including
  116. * older version of PJSIP), furthermore, there is RFC8643 that promotes
  117. * interoperability over the strictness of RTP profile specifications.
  118. *
  119. * Default: PJ_TRUE.
  120. */
  121. pj_bool_t dont_use_avpf;
  122. /**
  123. * Number of RTCP Feedback capabilities.
  124. */
  125. unsigned cap_count;
  126. /**
  127. * The RTCP Feedback capabilities.
  128. */
  129. pjmedia_rtcp_fb_cap caps[PJMEDIA_RTCP_FB_MAX_CAP];
  130. } pjmedia_rtcp_fb_setting;
  131. /**
  132. * This structure declares RTCP Feedback Generic NACK message.
  133. */
  134. typedef struct pjmedia_rtcp_fb_nack
  135. {
  136. pj_int32_t pid; /**< Packet ID (RTP seq) */
  137. pj_uint16_t blp; /**< Bitmask of following lost
  138. packets */
  139. } pjmedia_rtcp_fb_nack;
  140. /**
  141. * This structure declares RTCP Feedback Slice Loss Indication (SLI) message.
  142. */
  143. typedef struct pjmedia_rtcp_fb_sli
  144. {
  145. pj_uint16_t first; /**< First lost macroblock */
  146. pj_uint16_t number; /**< The number of lost macroblocks
  147. packets */
  148. pj_uint8_t pict_id; /**< Picture ID (temporal ref) */
  149. } pjmedia_rtcp_fb_sli;
  150. /**
  151. * This structure declares RTCP Feedback Reference Picture Selection
  152. * Indication (RPSI) message.
  153. */
  154. typedef struct pjmedia_rtcp_fb_rpsi
  155. {
  156. pj_uint8_t pt; /**< Payload Type */
  157. pj_str_t rpsi; /**< Native RPSI bit string */
  158. pj_size_t rpsi_bit_len; /**< Length of RPSI in bit */
  159. } pjmedia_rtcp_fb_rpsi;
  160. /**
  161. * Event data for incoming RTCP Feedback message event
  162. * (PJMEDIA_EVENT_RX_RTCP_FB).
  163. */
  164. typedef struct pjmedia_event_rx_rtcp_fb_data
  165. {
  166. pjmedia_rtcp_fb_cap cap;
  167. union {
  168. pjmedia_rtcp_fb_nack nack;
  169. pjmedia_rtcp_fb_sli sli;
  170. pjmedia_rtcp_fb_rpsi rpsi;
  171. } msg;
  172. } pjmedia_event_rx_rtcp_fb_data;
  173. /**
  174. * Initialize RTCP Feedback setting with default values.
  175. *
  176. * @param opt The RTCP Feedback setting to be initialized.
  177. *
  178. * @return PJ_SUCCESS on success.
  179. */
  180. PJ_DECL(pj_status_t) pjmedia_rtcp_fb_setting_default(
  181. pjmedia_rtcp_fb_setting *opt);
  182. /**
  183. * Duplicate RTCP Feedback setting.
  184. *
  185. * @param pool Pool to be used for duplicating the config.
  186. * @param dst Destination configuration.
  187. * @param src Source configuration.
  188. *
  189. */
  190. PJ_DECL(void) pjmedia_rtcp_fb_setting_dup(pj_pool_t *pool,
  191. pjmedia_rtcp_fb_setting *dst,
  192. const pjmedia_rtcp_fb_setting *src);
  193. /**
  194. * Duplicate RTCP Feedback info.
  195. *
  196. * @param pool Pool to be used for duplicating the info.
  197. * @param dst Destination info.
  198. * @param src Source info.
  199. *
  200. */
  201. PJ_DECL(void) pjmedia_rtcp_fb_info_dup(pj_pool_t *pool,
  202. pjmedia_rtcp_fb_info *dst,
  203. const pjmedia_rtcp_fb_info *src);
  204. /**
  205. * Encode RTCP Feedback specific information into local SDP according to
  206. * the provided RTCP Feedback setting. This is useful to signal remote
  207. * endpoint that local endpoint is capable and willing to receive RTCP
  208. * Feedback packets as described in the local SDP.
  209. *
  210. * @param pool Pool object to allocate memory in updating local SDP.
  211. * @param endpt The media endpoint.
  212. * @param opt RTCP Feedback setting.
  213. * @param sdp_local The local SDP to be filled in information from the
  214. * media transport.
  215. * @param med_idx The SDP media index.
  216. * @param sdp_remote Remote SDP or NULL if local is offerer.
  217. *
  218. * @return PJ_SUCCESS on success.
  219. */
  220. PJ_DECL(pj_status_t) pjmedia_rtcp_fb_encode_sdp(
  221. pj_pool_t *pool,
  222. pjmedia_endpt *endpt,
  223. const pjmedia_rtcp_fb_setting *opt,
  224. pjmedia_sdp_session *sdp_local,
  225. unsigned med_idx,
  226. const pjmedia_sdp_session *sdp_remote);
  227. /**
  228. * Decode RTCP Feedback specific information from SDP media.
  229. *
  230. * @param pool Pool object to allocate memory.
  231. * @param endpt The media endpoint.
  232. * @param opt Options, currently it must be NULL.
  233. * @param sdp The SDP.
  234. * @param med_idx The SDP media index.
  235. * @param info The RTCP-FB info fetched from SDP.
  236. *
  237. * @return PJ_SUCCESS on success.
  238. */
  239. PJ_DECL(pj_status_t) pjmedia_rtcp_fb_decode_sdp(
  240. pj_pool_t *pool,
  241. pjmedia_endpt *endpt,
  242. const void *opt,
  243. const pjmedia_sdp_session *sdp,
  244. unsigned med_idx,
  245. pjmedia_rtcp_fb_info *info);
  246. /**
  247. * Decode RTCP Feedback specific information from SDP media for the specified
  248. * payload type. If the payload type is set to negative value, it will decode
  249. * RTCP Feedback info for all payload types in the SDP media.
  250. *
  251. * @param pool Pool object to allocate memory.
  252. * @param endpt The media endpoint.
  253. * @param opt Options, currently it must be NULL.
  254. * @param sdp The SDP.
  255. * @param med_idx The SDP media index.
  256. * @param pt The payload type.
  257. * @param info The RTCP-FB info fetched from SDP.
  258. *
  259. * @return PJ_SUCCESS on success.
  260. */
  261. PJ_DECL(pj_status_t) pjmedia_rtcp_fb_decode_sdp2(
  262. pj_pool_t *pool,
  263. pjmedia_endpt *endpt,
  264. const void *opt,
  265. const pjmedia_sdp_session *sdp,
  266. unsigned med_idx,
  267. int pt,
  268. pjmedia_rtcp_fb_info *info);
  269. /**
  270. * Build an RTCP Feedback Generic NACK packet. This packet can be appended to
  271. * other RTCP packets, e.g: RTCP RR/SR, to compose a compound RTCP packet.
  272. * See also RFC 4585 Section 6.2.1 about Generic NACK message.
  273. *
  274. * @param session The RTCP session.
  275. * @param buf The buffer to receive RTCP Feedback packet.
  276. * @param length On input, it will contain the buffer length.
  277. * On output, it will contain the generated RTCP Feedback
  278. * packet length.
  279. * @param nack_cnt The number of RTCP Feedback Generic NACK messages.
  280. * @param nack The array of RTCP Feedback Generic NACK messages.
  281. *
  282. * @return PJ_SUCCESS on success.
  283. */
  284. PJ_DECL(pj_status_t) pjmedia_rtcp_fb_build_nack(
  285. pjmedia_rtcp_session *session,
  286. void *buf,
  287. pj_size_t *length,
  288. unsigned nack_cnt,
  289. const pjmedia_rtcp_fb_nack nack[]);
  290. /**
  291. * Build an RTCP Feedback Picture Loss Indication (PLI) packet. This packet
  292. * can be appended to other RTCP packets, e.g: RTCP RR/SR, to compose a
  293. * compound RTCP packet. See also RFC 4585 Section 6.3.1 about PLI FB message.
  294. *
  295. * @param session The RTCP session.
  296. * @param buf The buffer to receive RTCP Feedback packet.
  297. * @param length On input, it will contain the buffer length.
  298. * On output, it will contain the generated RTCP Feedback
  299. * packet length.
  300. *
  301. * @return PJ_SUCCESS on success.
  302. */
  303. PJ_DECL(pj_status_t) pjmedia_rtcp_fb_build_pli(
  304. pjmedia_rtcp_session *session,
  305. void *buf,
  306. pj_size_t *length);
  307. /**
  308. * Build an RTCP Feedback Slice Loss Indication (SLI) packet. This packet can
  309. * be appended to other RTCP packets, e.g: RTCP RR/SR, to compose a compound
  310. * RTCP packet. See also RFC 4585 Section 6.3.2 about SLI FB message.
  311. *
  312. * @param session The RTCP session.
  313. * @param buf The buffer to receive RTCP Feedback packet.
  314. * @param length On input, it will contain the buffer length.
  315. * On output, it will contain the generated RTCP Feedback
  316. * packet length.
  317. * @param sli_cnt The number of RTCP Feedback SLI messages.
  318. * @param sli The array of RTCP Feedback SLI messages.
  319. *
  320. * @return PJ_SUCCESS on success.
  321. */
  322. PJ_DECL(pj_status_t) pjmedia_rtcp_fb_build_sli(
  323. pjmedia_rtcp_session *session,
  324. void *buf,
  325. pj_size_t *length,
  326. unsigned sli_cnt,
  327. const pjmedia_rtcp_fb_sli sli[]);
  328. /**
  329. * Build an RTCP Feedback Reference Picture Selection Indication (RPSI)
  330. * packet. This packet can be appended to other RTCP packets, e.g: RTCP RR/SR,
  331. * to compose a compound RTCP packet. See also RFC 4585 Section 6.3.3 about
  332. * RPSI FB message.
  333. *
  334. * @param session The RTCP session.
  335. * @param buf The buffer to receive RTCP Feedback packet.
  336. * @param length On input, it will contain the buffer length.
  337. * On output, it will contain the generated RTCP Feedback
  338. * packet length.
  339. * @param rpsi The RTCP Feedback RPSI message.
  340. *
  341. * @return PJ_SUCCESS on success.
  342. */
  343. PJ_DECL(pj_status_t) pjmedia_rtcp_fb_build_rpsi(
  344. pjmedia_rtcp_session *session,
  345. void *buf,
  346. pj_size_t *length,
  347. const pjmedia_rtcp_fb_rpsi *rpsi);
  348. /**
  349. * Check whether the specified payload contains RTCP feedback generic NACK
  350. * message, and parse the payload if it does.
  351. *
  352. * @param buf The payload buffer.
  353. * @param length The payload length.
  354. * @param nack_cnt On input, it specifies the maximum number of generic NACK
  355. * messages.
  356. * On output, it specifies the number of parsed generic NACK
  357. * messages.
  358. * @param nack The array of RTCP Feedback Generic NACK messages.
  359. *
  360. * @return PJ_SUCCESS if the payload contains generic NACK message
  361. * and has been parsed successfully.
  362. */
  363. PJ_DECL(pj_status_t) pjmedia_rtcp_fb_parse_nack(
  364. const void *buf,
  365. pj_size_t length,
  366. unsigned *nack_cnt,
  367. pjmedia_rtcp_fb_nack nack[]);
  368. /**
  369. * Check whether the specified payload contains RTCP feedback Picture Loss
  370. * Indication (PLI) message.
  371. *
  372. * @param buf The payload buffer.
  373. * @param length The payload length.
  374. *
  375. * @return PJ_SUCCESS if the payload contains PLI message.
  376. */
  377. PJ_DECL(pj_status_t) pjmedia_rtcp_fb_parse_pli(
  378. const void *buf,
  379. pj_size_t length);
  380. /**
  381. * Check whether the specified payload contains RTCP feedback Slice Loss
  382. * Indication (SLI) message, and parse the payload if it does.
  383. *
  384. * @param buf The payload buffer.
  385. * @param length The payload length.
  386. * @param sli_cnt On input, it specifies the maximum number of SLI messages.
  387. * On output, it specifies the number of parsed SLI messages.
  388. * @param sli The array of RTCP Feedback SLI messages.
  389. *
  390. * @return PJ_SUCCESS if the payload contains SLI messages and
  391. * has been parsed successfully.
  392. */
  393. PJ_DECL(pj_status_t) pjmedia_rtcp_fb_parse_sli(
  394. const void *buf,
  395. pj_size_t length,
  396. unsigned *sli_cnt,
  397. pjmedia_rtcp_fb_sli sli[]);
  398. /**
  399. * Check whether the specified payload contains RTCP feedback Reference
  400. * Picture Selection Indication (RPSI) message, and parse the payload
  401. * if it does.
  402. *
  403. * @param buf The payload buffer.
  404. * @param length The payload length.
  405. * @param rpsi The parsed RTCP Feedback RPSI messages.
  406. *
  407. * @return PJ_SUCCESS if the payload contains SLI messages and
  408. * has been parsed successfully.
  409. */
  410. PJ_DECL(pj_status_t) pjmedia_rtcp_fb_parse_rpsi(
  411. const void *buf,
  412. pj_size_t length,
  413. pjmedia_rtcp_fb_rpsi *rpsi);
  414. /**
  415. * @}
  416. */
  417. PJ_END_DECL
  418. #endif /* __PJMEDIA_RTCP_FB_H__ */