MCPcopy Create free account
hub / github.com/PHZ76/RtspServer / main

Function main

example/rtsp_server.cpp:12–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10void SendFrameThread(xop::RtspServer* rtsp_server, xop::MediaSessionId session_id, int& clients);
11
12int main(int argc, char **argv)
13{
14 int clients = 0;
15 std::string ip = "0.0.0.0";
16 std::string rtsp_url = "rtsp://127.0.0.1:554/live";
17
18 std::shared_ptr<xop::EventLoop> event_loop(new xop::EventLoop());
19 std::shared_ptr<xop::RtspServer> server = xop::RtspServer::Create(event_loop.get());
20 if (!server->Start(ip, 554)) {
21 return -1;
22 }
23
24#ifdef AUTH_CONFIG
25 server->SetAuthConfig("-_-", "admin", "12345");
26#endif
27
28 xop::MediaSession *session = xop::MediaSession::CreateNew("live"); // url: rtsp://ip/live
29 session->AddSource(xop::channel_0, xop::H264Source::CreateNew());
30 session->AddSource(xop::channel_1, xop::AACSource::CreateNew(44100,2));
31 // session->startMulticast(); /* 开启组播(ip,端口随机生成), 默认使用 RTP_OVER_UDP, RTP_OVER_RTSP */
32
33 session->AddNotifyConnectedCallback([] (xop::MediaSessionId sessionId, std::string peer_ip, uint16_t peer_port){
34 printf("RTSP client connect, ip=%s, port=%hu \n", peer_ip.c_str(), peer_port);
35 });
36
37 session->AddNotifyDisconnectedCallback([](xop::MediaSessionId sessionId, std::string peer_ip, uint16_t peer_port) {
38 printf("RTSP client disconnect, ip=%s, port=%hu \n", peer_ip.c_str(), peer_port);
39 });
40
41 std::cout << "URL: " << rtsp_url << std::endl;
42
43 xop::MediaSessionId session_id = server->AddSession(session);
44 //server->removeMeidaSession(session_id); /* 取消会话, 接口线程安全 */
45
46 std::thread thread(SendFrameThread, server.get(), session_id, std::ref(clients));
47 thread.detach();
48
49 while(1) {
50 xop::Timer::Sleep(100);
51 }
52
53 getchar();
54 return 0;
55}
56
57void SendFrameThread(xop::RtspServer* rtsp_server, xop::MediaSessionId session_id, int& clients)
58{

Callers

nothing calls this directly

Calls 6

SetAuthConfigMethod · 0.80
AddSourceMethod · 0.80
StartMethod · 0.45
AddSessionMethod · 0.45

Tested by

no test coverage detected