This commit is contained in:
xiongziliang 2018-02-24 15:18:16 +08:00
parent 15f03476c3
commit fe4da29fb1
6 changed files with 54 additions and 50 deletions

View File

@ -43,35 +43,35 @@ using namespace ZL::Thread;
using namespace ZL::Network;
int main(int argc, char *argv[]){
int main(int argc, char *argv[]) {
//设置退出信号处理函数
signal(SIGINT, [](int){EventPoller::Instance().shutdown();});
signal(SIGINT, [](int) { EventPoller::Instance().shutdown(); });
//设置日志
Logger::Instance().add(std::make_shared<ConsoleChannel>("stdout", LTrace));
Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>());
if(argc != 5){
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"
<<endl;
<< endl;
Logger::Destory();
return 0;
}
{
list<MediaPlayer::Ptr> playerList;
auto playerCnt = atoi(argv[1]);//启动的播放器个数
atomic_int alivePlayerCnt(0);
//每隔若干毫秒启动一个播放器(如果一次性全部启动,服务器和客户端可能都承受不了)
AsyncTaskThread::Instance().DoTaskDelay(0, atoi(argv[2]), [&](){
AsyncTaskThread::Instance().DoTaskDelay(0, atoi(argv[2]), [&]() {
MediaPlayer::Ptr player(new MediaPlayer());
player->setOnPlayResult([&](const SockException &ex){
if(!ex){
player->setOnPlayResult([&](const SockException &ex) {
if (!ex) {
++alivePlayerCnt;
}
});
player->setOnShutdown([&](const SockException &ex){
player->setOnShutdown([&](const SockException &ex) {
--alivePlayerCnt;
});
(*player)[RtspPlayer::kRtpType] = atoi(argv[4]);
@ -80,18 +80,19 @@ int main(int argc, char *argv[]){
return playerCnt--;
});
AsyncTaskThread::Instance().DoTaskDelay(0, 1000, [&](){
AsyncTaskThread::Instance().DoTaskDelay(0, 1000, [&]() {
InfoL << "存活播放器个数:" << alivePlayerCnt.load();
return true;
});
EventPoller::Instance().runLoop();
playerList.clear();
AsyncTaskThread::Instance().CancelTask(0);
}
static onceToken token(nullptr, []() {
WorkThreadPool::Instance();
UDPServer::Destory();
AsyncTaskThread::Destory();
EventPoller::Destory();
AsyncTaskThread::Destory();
Logger::Destory();
});
return 0;

View File

@ -150,6 +150,7 @@ int main(int argc,char *argv[]){
requesterPost.reset();
//程序开始退出
EventPoller::Destory();
AsyncTaskThread::Destory();
Logger::Destory();
return 0;
}

View File

@ -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;

View File

@ -114,6 +114,7 @@ int domain(int argc, const char *argv[]) {
//清理程序
EventPoller::Destory();
AsyncTaskThread::Destory();
Logger::Destory();
return 0;
}

View File

@ -121,6 +121,7 @@ int domain(int argc,const char *argv[]){
//程序清理
EventPoller::Destory();
AsyncTaskThread::Destory();
Logger::Destory();
return 0;
}

View File

@ -250,8 +250,8 @@ int main(int argc,char *argv[]) {
UDPServer::Destory();
//TcpServer用到了WorkThreadPool
WorkThreadPool::Destory();
AsyncTaskThread::Destory();
EventPoller::Destory();
AsyncTaskThread::Destory();
Logger::Destory();
return 0;
}