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.

75 lines
2.8KB

  1. #ifndef _rtp_payload_h_
  2. #define _rtp_payload_h_
  3. // https://en.wikipedia.org/wiki/RTP_audio_video_profile
  4. #include <stdint.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. /// RTP packet lost(miss packet before this frame)
  9. #define RTP_PAYLOAD_FLAG_PACKET_LOST 0x0100 // some packets lost before the packet
  10. #define RTP_PAYLOAD_FLAG_PACKET_CORRUPT 0x0200 // the packet data is corrupt
  11. struct rtp_payload_t
  12. {
  13. void* (*alloc)(void* param, int bytes);
  14. void (*free)(void* param, void *packet);
  15. /// @return 0-ok, other-error
  16. int (*packet)(void* param, const void *packet, int bytes, uint32_t timestamp, int flags);
  17. };
  18. /// Create RTP packet encoder
  19. /// @param[in] payload RTP payload type, value: [0, 127] (see more about rtp-profile.h)
  20. /// @param[in] name RTP payload name
  21. /// @param[in] seq RTP header sequence number filed
  22. /// @param[in] ssrc RTP header SSRC filed
  23. /// @param[in] handler user-defined callback functions
  24. /// @param[in] cbparam user-defined parameter
  25. /// @return NULL-error, other-ok
  26. void* rtp_payload_encode_create(int payload, const char* name, uint16_t seq, uint32_t ssrc, struct rtp_payload_t *handler, void* cbparam);
  27. void rtp_payload_encode_destroy(void* encoder);
  28. /// Get rtp last packet sequence number and timestamp
  29. /// @param[in] encoder RTP packet encoder(create by rtp_payload_encode_create)
  30. /// @param[in] seq RTP header sequence number
  31. /// @param[in] timestamp RTP header timestamp
  32. void rtp_payload_encode_getinfo(void* encoder, uint16_t* seq, uint32_t* timestamp);
  33. /// Encode RTP packet
  34. /// @param[in] encoder RTP packet encoder(create by rtp_payload_encode_create)
  35. /// @param[in] data stream data
  36. /// @param[in] bytes stream length in bytes
  37. /// @param[in] timestamp RTP header timestamp
  38. /// @return 0-ok, ENOMEM-alloc failed, <0-failed
  39. int rtp_payload_encode_input(void* encoder, const void* data, int bytes, uint32_t timestamp);
  40. /// Create RTP packet decoder
  41. /// @param[in] payload RTP payload type, value: [0, 127] (see more about rtp-profile.h)
  42. /// @param[in] name RTP payload name
  43. /// @param[in] handler user-defined callback functions
  44. /// @param[in] cbparam user-defined parameter
  45. /// @return NULL-error, other-ok
  46. void* rtp_payload_decode_create(int payload, const char* name, struct rtp_payload_t *handler, void* cbparam);
  47. void rtp_payload_decode_destroy(void* decoder);
  48. /// Decode RTP packet
  49. /// @param[in] decoder RTP packet decoder(create by rtp_payload_decode_create)
  50. /// @param[in] packet RTP packet, include rtp header(12 bytes)
  51. /// @param[in] bytes RTP packet length in bytes
  52. /// @return 1-packet handled, 0-packet discard, <0-failed
  53. int rtp_payload_decode_input(void* decoder, const void* packet, int bytes);
  54. /// Set/Get rtp encode packet size(include rtp header)
  55. void rtp_packet_setsize(int bytes);
  56. int rtp_packet_getsize(void);
  57. #ifdef __cplusplus
  58. }
  59. #endif
  60. #endif /* !_rtp_payload_h_ */