Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
PHZ76 committed May 24, 2020
1 parent 0a350e3 commit 293187e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions example/rtmp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "xop/HttpFlvServer.h"
#include "xop/RtmpPublisher.h"
#include "xop/RtmpClient.h"
#include "xop/HttpFlvServer.h"
#include "xop/H264Parser.h"
#include "net/EventLoop.h"

Expand All @@ -16,7 +17,7 @@
#define PUSH_FILE "./test.h264"
#define HTTP_URL "http://127.0.0.1:8080/live/01.flv"

int test_rtmp_publisher(xop::EventLoop *event_loop);
int TestRtmpPublisher(xop::EventLoop *event_loop);

int main(int argc, char **argv)
{
Expand All @@ -30,12 +31,15 @@ int main(int argc, char **argv)
auto rtmp_server = xop::RtmpServer::Create(&event_loop);
rtmp_server->SetChunkSize(60000);
//rtmp_server->SetGopCache(); /* enable gop cache */
rtmp_server->SetEventCallback([](std::string type, std::string stream_path) {
printf("[Event] %s, stream path: %s\n\n", type.c_str(), stream_path.c_str());
});
if (!rtmp_server->Start("0.0.0.0", 1935)) {
printf("RTMP Server listen on 1935 failed.\n");
}

/* http-flv server example */
xop::HttpFlvServer http_flv_server(&event_loop);
xop::HttpFlvServer http_flv_server;
http_flv_server.Attach(rtmp_server);
if (!http_flv_server.Start("0.0.0.0", 8080)) {
printf("HTTP FLV Server listen on 8080 failed.\n");
Expand All @@ -44,15 +48,15 @@ int main(int argc, char **argv)
#if TEST_RTMP_PUSHER
/* rtmp pusher example */
std::thread t([&event_loop] () {
test_rtmp_publisher(&event_loop);
TestRtmpPublisher(&event_loop);
});
t.detach();
#endif

#if TEST_RTMP_CLIENT
auto rtmp_client = xop::RtmpClient::Create(&event_loop);
rtmp_client->SetFrameCB([](uint8_t* payload, uint32_t length, uint8_t codecId, uint32_t timestamp) {
// handle frame ...
printf("recv frame, type:%u, size:%u,\n", codecId, length);
});

std::string status;
Expand All @@ -66,7 +70,7 @@ int main(int argc, char **argv)
}

rtmp_server->Stop();
http_flv_server.Stop();
//http_flv_server.Stop();
return 0;
}

Expand Down Expand Up @@ -233,7 +237,7 @@ int H264File::readFrame(char *inBuf, int inBufSize, bool *bEndOfFrame)
return size;
}

int test_rtmp_publisher(xop::EventLoop *event_loop)
int TestRtmpPublisher(xop::EventLoop *event_loop)
{
H264File h264_file;
if (!h264_file.open(PUSH_FILE)) {
Expand Down

0 comments on commit 293187e

Please sign in to comment.