forked from PHZ76/RtspServer
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathrtsp_pusher.cpp
More file actions
executable file
·75 lines (60 loc) · 2.25 KB
/
Copy pathrtsp_pusher.cpp
File metadata and controls
executable file
·75 lines (60 loc) · 2.25 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
65
66
67
68
69
70
71
72
73
74
75
// RTSP Pusher
#include "xop/RtspPusher.h"
#include "net/Timer.h"
#include <thread>
#include <memory>
#include <iostream>
#include <string>
#define PUSH_TEST "rtsp://10.11.165.203:554/test"
void snedFrameThread(xop::RtspPusher* rtspPusher);
int main(int argc, char **argv)
{
std::shared_ptr<xop::EventLoop> event_loop(new xop::EventLoop());
std::shared_ptr<xop::RtspPusher> rtsp_pusher = xop::RtspPusher::Create(event_loop.get());
xop::MediaSession *session = xop::MediaSession::CreateNew();
session->AddSource(xop::channel_0, xop::H264Source::CreateNew());
session->AddSource(xop::channel_1, xop::AACSource::CreateNew(44100, 2, false));
rtsp_pusher->AddSession(session);
if (rtsp_pusher->OpenUrl(PUSH_TEST, 3000) < 0) {
std::cout << "Open " << PUSH_TEST << " failed." << std::endl;
getchar();
return 0;
}
std::cout << "Push stream to " << PUSH_TEST << " ..." << std::endl;
std::thread thread(snedFrameThread, rtsp_pusher.get());
thread.detach();
while (1) {
xop::Timer::Sleep(100);
}
getchar();
return 0;
}
void snedFrameThread(xop::RtspPusher* rtsp_pusher)
{
while(rtsp_pusher->IsConnected())
{
{
/*
//获取一帧 H264, 打包
xop::AVFrame videoFrame = {0};
//videoFrame.size = video frame size; // 视频帧大小
videoFrame.timestamp = xop::H264Source::GetTimestamp(); // 时间戳, 建议使用编码器提供的时间戳
videoFrame.buffer.reset(new uint8_t[videoFrame.size]);
//memcpy(videoFrame.buffer.get(), video frame data, videoFrame.size);
rtsp_pusher->PushFrame(xop::channel_0, videoFrame); //推流到服务器, 接口线程安全
*/
}
{
/*
//获取一帧 AAC, 打包
xop::AVFrame audioFrame = {0};
//audioFrame.size = audio frame size; // 音频帧大小
audioFrame.timestamp = xop::AACSource::GetTimestamp(44100); // 时间戳
audioFrame.buffer.reset(new uint8_t[audioFrame.size]);
//memcpy(audioFrame.buffer.get(), audio frame data, audioFrame.size);
rtsp_pusher->PushFrame(xop::channel_1, audioFrame); //推流到服务器, 接口线程安全
*/
}
xop::Timer::Sleep(1);
}
}