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.

79 lines
3.0KB

  1. #ifndef _rtmp_server_h_
  2. #define _rtmp_server_h_
  3. #include <stdint.h>
  4. #include <stddef.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. typedef struct rtmp_server_t rtmp_server_t;
  9. struct rtmp_server_handler_t
  10. {
  11. ///network implementation
  12. ///@param[in] payload rtmp payload, could be NULL
  13. ///@param[in] bytes rtmp payload size in byte, could be 0
  14. ///@return >0-sent bytes, <0-error
  15. int (*send)(void* param, const void* header, size_t len, const void* payload, size_t bytes);
  16. ///@return 0-ok, other-error
  17. //int (*oncreate_stream)(void* param, uint32_t* stream_id);
  18. //int (*ondelete_stream)(void* param, uint32_t stream_id);
  19. ///pull(server -> client)
  20. ///@return 0-ok, other-error
  21. int (*onplay)(void* param, const char* app, const char* stream, double start, double duration, uint8_t reset);
  22. int (*onpause)(void* param, int pause, uint32_t ms);
  23. int (*onseek)(void* param, uint32_t ms);
  24. ///push(client -> server)
  25. ///@param[in] type: live/record/append
  26. ///@return 0-ok, other-error
  27. int (*onpublish)(void* param, const char* app, const char* stream, const char* type);
  28. ///@param[in] data FLV VideoTagHeader + AVCVIDEOPACKET: AVCDecoderConfigurationRecord(ISO 14496-15) / One or more NALUs(four-bytes length + NALU)
  29. ///@return 0-ok, other-error
  30. int (*onvideo)(void* param, const void* data, size_t bytes, uint32_t timestamp);
  31. ///@param[in] data FLV AudioTagHeader + AACAUDIODATA: AudioSpecificConfig(14496-3) / Raw AAC frame data in UI8
  32. ///@return 0-ok, other-error
  33. int (*onaudio)(void* param, const void* data, size_t bytes, uint32_t timestamp);
  34. ///@param[in] data FLV onMetaData
  35. ///@return 0-ok, other-error
  36. int (*onscript)(void* param, const void* data, size_t bytes, uint32_t timestamp);
  37. ///@param[out] duration stream length in seconds
  38. ///@return 0-ok, other-error
  39. int (*ongetduration)(void* param, const char* app, const char* stream, double* duration);
  40. };
  41. rtmp_server_t* rtmp_server_create(void* param, const struct rtmp_server_handler_t* handler);
  42. void rtmp_server_destroy(rtmp_server_t* rtmp);
  43. int rtmp_server_getstate(rtmp_server_t* rtmp);
  44. /// @param[in] rtmp rtmp_server_create instance
  45. /// @param[in] data rtmp chunk stream data
  46. /// @param[in] bytes data length
  47. /// @return 0-ok, other-error
  48. int rtmp_server_input(rtmp_server_t* rtmp, const uint8_t* data, size_t bytes);
  49. /// send audio/video data(VOD only)
  50. /// @param[in] rtmp rtmp_server_create instance
  51. /// @return 0-ok, other-error
  52. int rtmp_server_send_audio(rtmp_server_t* rtmp, const void* data, size_t bytes, uint32_t timestamp);
  53. int rtmp_server_send_video(rtmp_server_t* rtmp, const void* data, size_t bytes, uint32_t timestamp);
  54. int rtmp_server_send_script(rtmp_server_t* rtmp, const void* data, size_t bytes, uint32_t timestamp);
  55. /// [OPTIONAL] call on between onplay and rtmp_server_send_audio/video/script
  56. /// @param[in] code 0-ok, other-error
  57. /// @param[in] msg error message
  58. /// @return 0-ok, other-error
  59. int rtmp_server_start(rtmp_server_t* rtmp, int code, const char* msg);
  60. #ifdef __cplusplus
  61. }
  62. #endif
  63. #endif /* !_rtmp_server_h_ */