#ifndef _RTP_RECEIVER_H_ #define _RTP_RECEIVER_H_ #include #include #include using namespace std; typedef void(*CallBack_Stream)(void* userdata, uint8_t* buf, int buf_size, uint64_t pts); typedef void(*CallBack_VodFileEnd)(void* userdata); class RTPReceiver2 { public: RTPReceiver2(); virtual ~RTPReceiver2(); bool Open(string channel_id, bool isUdp); bool IsOpened(); void Close(); void SetVodEndCallback(CallBack_VodFileEnd cb, void* param); void SetOutputCallback(CallBack_Stream cb, void* param); void RequestStreamFailed(); int allocRtpPort(); public: int udp_server(); int tcp_server(); private: bool start_server(string channel_id, int port, bool isUdp); void parseTcpData(char* recvBuf, int recvBufSize); public: uint8_t* mRecvCache {nullptr}; uint64_t mRecvCacheSize {0}; uint8_t* mRecvRtpBuffer {nullptr}; // 从mRecvCache提取出来的rtp字节流 int16_t mRecvRtpBufferSize {0}; // 从mRecvCache提取出来的rtp字节流总长度 (rtpHeader+rtpBody) bool m_bRtpExit {false}; string m_SipChannelId; int m_rtp_port{-1}; std::atomic_bool m_bOpened; std::atomic_bool m_bAccepted; std::atomic_bool m_bClosing; std::thread* m_server_thread{nullptr}; void* m_bufferParam; CallBack_Stream m_buffer_cbk; // 视频流回调 void* m_finishParam; CallBack_VodFileEnd m_finish_cbk; // 录像流结束回调 }; #endif // _RTP_RECEIVER_H_