RTPReceiver2.h
1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef _RTP_RECEIVER_H_
#define _RTP_RECEIVER_H_
#include <stdint.h>
#include <atomic>
#include <thread>
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);
void Close();
void SetVodEndCallback(CallBack_VodFileEnd cb, void* param);
void SetOutputCallback(CallBack_Stream cb, void* param);
void RequestStreamFailed();
int allocRtpPort(bool isUdp);
public:
int udp_server();
int tcp_server();
private:
bool start_server(string channel_id, int port, bool isUdp);
void parseTcpData(uint8_t* 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_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_