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.

139 lines
4.2KB

  1. #ifndef _rtp_h_
  2. #define _rtp_h_
  3. #include <stdint.h>
  4. #include "rtcp-header.h"
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. struct rtcp_msg_t
  9. {
  10. int type;
  11. uint32_t ssrc; // rtcp message sender
  12. union rtcp_msg_u
  13. {
  14. // type = RTCP_SR
  15. rtcp_rb_t sr;
  16. // type = RTCP_SR
  17. rtcp_rb_t rr;
  18. // type = RTCP_SDES
  19. rtcp_sdes_item_t sdes;
  20. // type = RTCP_BYE
  21. rtcp_bye_t bye;
  22. // type = RTCP_APP
  23. rtcp_app_t app;
  24. // type = RTCP_RTPFB | (RTCP_RTPFB_NACK << 8)
  25. rtcp_rtpfb_t rtpfb;
  26. // type = RTCP_PSFB | (RTCP_PSFB_PLI << 8)
  27. rtcp_psfb_t psfb;
  28. // type = RTCP_XR | (RTCP_XR_DLRR << 8)
  29. rtcp_xr_t xr;
  30. } u;
  31. };
  32. struct rtp_event_t
  33. {
  34. void (*on_rtcp)(void* param, const struct rtcp_msg_t* msg);
  35. };
  36. /// @param[in] ssrc RTP SSRC
  37. /// @param[in] timestamp base timestamp
  38. /// @param[in] frequence RTP frequence
  39. /// @param[in] bandwidth in byte
  40. /// @param[in] sender 1-rtp sender(SR), 0-rtp receiver(RR)
  41. void* rtp_create(struct rtp_event_t *handler, void* param, uint32_t ssrc, uint32_t timestamp, int frequence, int bandwidth, int sender);
  42. int rtp_destroy(void* rtp);
  43. /// RTP send notify
  44. /// @param[in] rtp RTP object
  45. /// @param[in] data RTP packet(include RTP Header)
  46. /// @param[in] bytes RTP packet size in byte
  47. /// @return 0-ok, <0-error
  48. int rtp_onsend(void* rtp, const void* data, int bytes);
  49. /// RTP receive notify
  50. /// @param[in] rtp RTP object
  51. /// @param[in] data RTP packet(include RTP Header)
  52. /// @param[in] bytes RTP packet size in byte
  53. /// @return 1-ok, 0-rtp packet ok, seq disorder, <0-error
  54. int rtp_onreceived(void* rtp, const void* data, int bytes);
  55. /// received RTCP packet
  56. /// @param[in] rtp RTP object
  57. /// @param[in] rtcp RTCP packet(include RTCP Header)
  58. /// @param[in] bytes RTCP packet size in byte
  59. /// @return 0-ok, <0-error
  60. int rtp_onreceived_rtcp(void* rtp, const void* rtcp, int bytes);
  61. /// create RTCP Report(SR/RR) packet
  62. /// @param[in] rtp RTP object
  63. /// @param[out] rtcp RTCP packet(include RTCP Header)
  64. /// @param[in] bytes RTCP packet size in byte
  65. /// @return 0-error, >0-rtcp package size(maybe need call more times)
  66. int rtp_rtcp_report(void* rtp, void* rtcp, int bytes);
  67. /// create RTCP BYE packet
  68. /// @param[in] rtp RTP object
  69. /// @param[out] rtcp RTCP packet(include RTCP Header)
  70. /// @param[in] bytes RTCP packet size in byte
  71. /// @return 0-error, >0-rtcp package size(maybe need call more times)
  72. int rtp_rtcp_bye(void* rtp, void* rtcp, int bytes);
  73. /// create RTCP APP packet
  74. /// @param[in] rtp RTP object
  75. /// @param[out] rtcp RTCP packet(include RTCP Header)
  76. /// @param[in] bytes RTCP packet size in byte
  77. /// @return 0-error, >0-rtcp package size(maybe need call more times)
  78. int rtp_rtcp_app(void* rtp, void* rtcp, int bytes, const char name[4], const void* app, int len);
  79. /// create RTCP RTPFB packet
  80. /// @param[in] rtp RTP object
  81. /// @param[out] data RTCP packet(include RTCP Header)
  82. /// @param[in] bytes RTCP packet size in byte
  83. /// @param[in] id FMT Values for RTPFB Payload Types
  84. /// @param[in] rtpfb RTPFB info
  85. /// @return 0-error, >0-rtcp package size(maybe need call more times)
  86. int rtp_rtcp_rtpfb(void* rtp, void* data, int bytes, enum rtcp_rtpfb_type_t id, const rtcp_rtpfb_t *rtpfb);
  87. /// create RTCP PSFB packet
  88. /// @param[in] rtp RTP object
  89. /// @param[out] rtcp RTCP packet(include RTCP Header)
  90. /// @param[in] bytes RTCP packet size in byte
  91. /// @param[in] id FMT Values for PSFB Payload Types
  92. /// @param[in] psfb PSFB info
  93. /// @return 0-error, >0-rtcp package size(maybe need call more times)
  94. int rtp_rtcp_psfb(void* rtp, void* data, int bytes, enum rtcp_psfb_type_t id, const rtcp_psfb_t* psfb);
  95. /// create RTCP XR packet
  96. /// @param[in] rtp RTP object
  97. /// @param[out] data RTCP packet(include RTCP Header)
  98. /// @param[in] bytes RTCP packet size in byte
  99. /// @param[in] id FMT Values for XR Payload Types
  100. /// @param[in] xr XR info
  101. /// @return 0-error, >0-rtcp package size(maybe need call more times)
  102. int rtp_rtcp_xr(void* rtp, void* data, int bytes, enum rtcp_xr_type_t id, const rtcp_xr_t* xr);
  103. /// get RTCP interval
  104. /// @param[in] rtp RTP object
  105. /// 0-ok, <0-error
  106. int rtp_rtcp_interval(void* rtp);
  107. const char* rtp_get_cname(void* rtp, uint32_t ssrc);
  108. const char* rtp_get_name(void* rtp, uint32_t ssrc);
  109. int rtp_set_info(void* rtp, const char* cname, const char* name);
  110. #ifdef __cplusplus
  111. }
  112. #endif
  113. #endif /* !_rtp_h_ */