Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

129 строки
5.0KB

  1. #ifndef _rtsp_client_h_
  2. #define _rtsp_client_h_
  3. #include "rtsp-header-transport.h"
  4. #include <stdint.h>
  5. #include <stddef.h>
  6. #if defined(__cplusplus)
  7. extern "C" {
  8. #endif
  9. typedef struct rtsp_client_t rtsp_client_t;
  10. // seq=232433;rtptime=972948234
  11. struct rtsp_rtp_info_t
  12. {
  13. const char* uri;
  14. uint32_t seq; // uint16_t
  15. uint32_t time; // uint32_t
  16. };
  17. struct rtsp_client_handler_t
  18. {
  19. ///network implementation
  20. ///@return >0-sent bytes, <0-error
  21. int (*send)(void* param, const char* uri, const void* req, size_t bytes);
  22. ///create rtp/rtcp port
  23. /// @param[in] source media source address
  24. /// @param[in,out] port [INPUT] media port, [OUTPUT] udp: bind local port for rtp/rtcp(port[0] % 2 == 0), tcp: channel interleaved id
  25. /// @param[in,out] ip [INPUT] media address, [OUTPUT] udp bind local ip address, 224~239.x.x.x for multicast udp transport
  26. /// @param[in] len ip buffer length in byte
  27. /// @return <0-error, 0-ignore this media track, other-RTSP_TRANSPORT_XXX
  28. int (*rtpport)(void* param, int media, const char* source, unsigned short port[2], char* ip, int len);
  29. /// rtsp_client_announce callback only
  30. int (*onannounce)(void* param);
  31. /// call rtsp_client_setup
  32. int (*ondescribe)(void* param, const char* sdp, int len);
  33. /// @param[in] timeout session timeout in seconds
  34. /// @param[in] duration -1-unknown or live stream, other-rtsp stream duration in MS
  35. int (*onsetup)(void* param, int timeout, int64_t duration);
  36. int (*onplay)(void* param, int media, const uint64_t *nptbegin, const uint64_t *nptend, const double *scale, const struct rtsp_rtp_info_t* rtpinfo, int count); // play
  37. int (*onrecord)(void* param, int media, const uint64_t *nptbegin, const uint64_t *nptend, const double *scale, const struct rtsp_rtp_info_t* rtpinfo, int count); // record
  38. int (*onpause)(void* param);
  39. int (*onteardown)(void* param);
  40. void (*onrtp)(void* param, uint8_t channel, const void* data, uint16_t bytes);
  41. };
  42. /// @param[in] param user-defined parameter
  43. /// @param[in] usr RTSP auth username(optional)
  44. /// @param[in] pwd RTSP auth password(optional)
  45. rtsp_client_t* rtsp_client_create(const char* uri, const char* usr, const char* pwd, const struct rtsp_client_handler_t *handler, void* param);
  46. void rtsp_client_destroy(rtsp_client_t* rtsp);
  47. /// input server reply
  48. /// @param[in] data server response message
  49. /// @param[in] bytes data length in byte
  50. int rtsp_client_input(rtsp_client_t* rtsp, const void* data, size_t bytes);
  51. /// find RTSP response header
  52. /// @param[in] name header name
  53. /// @return header value, NULL if not found.
  54. /// NOTICE: call in rtsp_client_handler_t callback only
  55. const char* rtsp_client_get_header(rtsp_client_t* rtsp, const char* name);
  56. /// rtsp options (optional)
  57. /// @param[in] commands optional required command, NULL if none
  58. int rtsp_client_options(struct rtsp_client_t* rtsp, const char* commands);
  59. /// rtsp describe (optional)
  60. int rtsp_client_describe(struct rtsp_client_t* rtsp);
  61. /// rtsp setup
  62. /// @param[in] sdp resource info. it can be null, sdp will get by describe command
  63. /// @return 0-ok, -EACCESS-auth required, try again, other-error.
  64. int rtsp_client_setup(rtsp_client_t* rtsp, const char* sdp, int len);
  65. /// stop and close session(TearDown)
  66. /// call onclose on done
  67. /// @return 0-ok, other-error.
  68. int rtsp_client_teardown(rtsp_client_t* rtsp);
  69. /// play session(PLAY)
  70. /// call onplay on done
  71. /// @param[in] npt PLAY range parameter [optional, NULL is acceptable]
  72. /// @param[in] speed PLAY scale+speed parameter [optional, NULL is acceptable]
  73. /// @return 0-ok, other-error.
  74. /// Notice: if npt and speed is null, resume play only
  75. int rtsp_client_play(rtsp_client_t* rtsp, const uint64_t *npt, const float *speed);
  76. /// pause session(PAUSE)
  77. /// call onpause on done
  78. /// @return 0-ok, other-error.
  79. /// use rtsp_client_play(rtsp, NULL, NULL) to resume play
  80. int rtsp_client_pause(rtsp_client_t* rtsp);
  81. /// announce server sdp
  82. /// @return 0-ok, other-error.
  83. int rtsp_client_announce(rtsp_client_t* rtsp, const char* sdp);
  84. /// record session(publish)
  85. /// call onrecord on done
  86. /// @param[in] npt RECORD range parameter [optional, NULL is acceptable]
  87. /// @param[in] scale RECORD scale parameter [optional, NULL is acceptable]
  88. /// @return 0-ok, other-error.
  89. /// Notice: if npt and scale is null, resume record only
  90. int rtsp_client_record(struct rtsp_client_t *rtsp, const uint64_t *npt, const float *scale);
  91. /// SDP API
  92. int rtsp_client_media_count(rtsp_client_t* rtsp);
  93. const struct rtsp_header_transport_t* rtsp_client_get_media_transport(rtsp_client_t* rtsp, int media);
  94. const char* rtsp_client_get_media_encoding(rtsp_client_t* rtsp, int media);
  95. const char* rtsp_client_get_media_fmtp(rtsp_client_t* rtsp, int media);
  96. int rtsp_client_get_media_payload(rtsp_client_t* rtsp, int media);
  97. /// @return media sampling rate/frequency, 0 if unknown
  98. int rtsp_client_get_media_rate(rtsp_client_t* rtsp, int media);
  99. /// @return SDP_M_MEDIA_AUDIO/SDP_M_MEDIA_VIDEO/SDP_M_MEDIA_xxx, see more @sdp.h
  100. int rtsp_client_get_media_type(rtsp_client_t* rtsp, int media);
  101. #if defined(__cplusplus)
  102. }
  103. #endif
  104. #endif /* !_rtsp_client_h_ */