From fe4da29fb13e1e62cdd373712ae27d1e1d3ae4a6 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 24 Feb 2018 15:18:16 +0800 Subject: [PATCH] update --- tests/test_benchmark.cpp | 95 ++++++++++++++++++------------------ tests/test_httpClient.cpp | 1 + tests/test_player.cpp | 2 +- tests/test_rtmpPusher.cpp | 1 + tests/test_rtmpPusherMp4.cpp | 1 + tests/test_server.cpp | 4 +- 6 files changed, 54 insertions(+), 50 deletions(-) diff --git a/tests/test_benchmark.cpp b/tests/test_benchmark.cpp index ba16443e..e145d8cd 100644 --- a/tests/test_benchmark.cpp +++ b/tests/test_benchmark.cpp @@ -43,57 +43,58 @@ using namespace ZL::Thread; using namespace ZL::Network; -int main(int argc, char *argv[]){ - //设置退出信号处理函数 - signal(SIGINT, [](int){EventPoller::Instance().shutdown();}); - //设置日志 - Logger::Instance().add(std::make_shared("stdout", LTrace)); - Logger::Instance().setWriter(std::make_shared()); +int main(int argc, char *argv[]) { + //设置退出信号处理函数 + signal(SIGINT, [](int) { EventPoller::Instance().shutdown(); }); + //设置日志 + Logger::Instance().add(std::make_shared("stdout", LTrace)); + Logger::Instance().setWriter(std::make_shared()); - if(argc != 5){ - FatalL << "\r\n测试方法:./test_benchmark player_count play_interval rtxp_url rtp_type\r\n" - << "例如你想每隔50毫秒启动共计100个播放器(tcp方式播放rtsp://127.0.0.1/live/0 )可以输入以下命令:\r\n" - << "./test_benchmark 100 50 rtsp://127.0.0.1/live/0 0\r\n" - < playerList; + auto playerCnt = atoi(argv[1]);//启动的播放器个数 + atomic_int alivePlayerCnt(0); + //每隔若干毫秒启动一个播放器(如果一次性全部启动,服务器和客户端可能都承受不了) + AsyncTaskThread::Instance().DoTaskDelay(0, atoi(argv[2]), [&]() { + MediaPlayer::Ptr player(new MediaPlayer()); + player->setOnPlayResult([&](const SockException &ex) { + if (!ex) { + ++alivePlayerCnt; + } + }); + player->setOnShutdown([&](const SockException &ex) { + --alivePlayerCnt; + }); + (*player)[RtspPlayer::kRtpType] = atoi(argv[4]); + player->play(argv[3]); + playerList.push_back(player); + return playerCnt--; + }); - list playerList; - auto playerCnt = atoi(argv[1]);//启动的播放器个数 - atomic_int alivePlayerCnt(0); - //每隔若干毫秒启动一个播放器(如果一次性全部启动,服务器和客户端可能都承受不了) - AsyncTaskThread::Instance().DoTaskDelay(0, atoi(argv[2]), [&](){ - MediaPlayer::Ptr player(new MediaPlayer()); - player->setOnPlayResult([&](const SockException &ex){ - if(!ex){ - ++alivePlayerCnt; - } - }); - player->setOnShutdown([&](const SockException &ex){ - --alivePlayerCnt; - }); - (*player)[RtspPlayer::kRtpType] = atoi(argv[4]); - player->play(argv[3]); - playerList.push_back(player); - return playerCnt--; - }); + AsyncTaskThread::Instance().DoTaskDelay(0, 1000, [&]() { + InfoL << "存活播放器个数:" << alivePlayerCnt.load(); + return true; + }); + EventPoller::Instance().runLoop(); + AsyncTaskThread::Instance().CancelTask(0); + } - AsyncTaskThread::Instance().DoTaskDelay(0, 1000, [&](){ - InfoL << "存活播放器个数:" << alivePlayerCnt.load(); - return true; - }); - EventPoller::Instance().runLoop(); - playerList.clear(); - - static onceToken token(nullptr, []() { - WorkThreadPool::Instance(); - UDPServer::Destory(); + static onceToken token(nullptr, []() { + WorkThreadPool::Instance(); + UDPServer::Destory(); + EventPoller::Destory(); AsyncTaskThread::Destory(); - EventPoller::Destory(); - Logger::Destory(); - }); - return 0; + Logger::Destory(); + }); + return 0; } diff --git a/tests/test_httpClient.cpp b/tests/test_httpClient.cpp index 66bea834..19c929bb 100644 --- a/tests/test_httpClient.cpp +++ b/tests/test_httpClient.cpp @@ -150,6 +150,7 @@ int main(int argc,char *argv[]){ requesterPost.reset(); //程序开始退出 EventPoller::Destory(); + AsyncTaskThread::Destory(); Logger::Destory(); return 0; } diff --git a/tests/test_player.cpp b/tests/test_player.cpp index 5581a6bd..7af44be9 100644 --- a/tests/test_player.cpp +++ b/tests/test_player.cpp @@ -89,8 +89,8 @@ int main(int argc, char *argv[]){ static onceToken token(nullptr, []() { UDPServer::Destory(); - AsyncTaskThread::Destory(); EventPoller::Destory(); + AsyncTaskThread::Destory(); Logger::Destory(); }); return 0; diff --git a/tests/test_rtmpPusher.cpp b/tests/test_rtmpPusher.cpp index 496dad18..8a8eeb2b 100644 --- a/tests/test_rtmpPusher.cpp +++ b/tests/test_rtmpPusher.cpp @@ -114,6 +114,7 @@ int domain(int argc, const char *argv[]) { //清理程序 EventPoller::Destory(); + AsyncTaskThread::Destory(); Logger::Destory(); return 0; } diff --git a/tests/test_rtmpPusherMp4.cpp b/tests/test_rtmpPusherMp4.cpp index 13ce429b..d85b176a 100644 --- a/tests/test_rtmpPusherMp4.cpp +++ b/tests/test_rtmpPusherMp4.cpp @@ -121,6 +121,7 @@ int domain(int argc,const char *argv[]){ //程序清理 EventPoller::Destory(); + AsyncTaskThread::Destory(); Logger::Destory(); return 0; } diff --git a/tests/test_server.cpp b/tests/test_server.cpp index d0a57d23..2ca2d1cb 100644 --- a/tests/test_server.cpp +++ b/tests/test_server.cpp @@ -250,9 +250,9 @@ int main(int argc,char *argv[]) { UDPServer::Destory(); //TcpServer用到了WorkThreadPool WorkThreadPool::Destory(); - AsyncTaskThread::Destory(); EventPoller::Destory(); - Logger::Destory(); + AsyncTaskThread::Destory(); + Logger::Destory(); return 0; }