2017-10-09 22:11:01 +08:00
|
|
|
|
/*
|
2017-09-27 16:20:30 +08:00
|
|
|
|
* MIT License
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2016 xiongziliang <771730766@qq.com>
|
|
|
|
|
*
|
|
|
|
|
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
|
|
|
|
*/
|
2017-05-09 10:45:55 +08:00
|
|
|
|
#include <signal.h>
|
|
|
|
|
#include <atomic>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <list>
|
|
|
|
|
#include "Util/logger.h"
|
|
|
|
|
#include "Util/onceToken.h"
|
|
|
|
|
#include "Rtsp/UDPServer.h"
|
|
|
|
|
#include "Network/sockutil.h"
|
|
|
|
|
#include "Poller/EventPoller.h"
|
2018-10-29 09:54:35 +08:00
|
|
|
|
#include "Player/PlayerProxy.h"
|
2017-05-09 10:45:55 +08:00
|
|
|
|
|
|
|
|
|
using namespace std;
|
2018-10-24 17:17:55 +08:00
|
|
|
|
using namespace toolkit;
|
|
|
|
|
using namespace mediakit;
|
2017-05-09 10:45:55 +08:00
|
|
|
|
|
2018-02-24 15:18:16 +08:00
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
|
//设置退出信号处理函数
|
2019-01-18 10:16:36 +08:00
|
|
|
|
static semaphore sem;
|
|
|
|
|
signal(SIGINT, [](int) { sem.post(); });// 设置退出信号
|
2018-12-28 16:47:50 +08:00
|
|
|
|
|
2018-02-24 15:18:16 +08:00
|
|
|
|
//设置日志
|
2018-12-28 16:47:50 +08:00
|
|
|
|
Logger::Instance().add(std::make_shared<ConsoleChannel>());
|
2018-02-24 15:18:16 +08:00
|
|
|
|
Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>());
|
2017-05-09 10:45:55 +08:00
|
|
|
|
|
2018-02-24 15:18:16 +08:00
|
|
|
|
if (argc != 5) {
|
2018-04-09 11:33:19 +08:00
|
|
|
|
ErrorL << "\r\n测试方法:./test_benchmark player_count play_interval rtxp_url rtp_type\r\n"
|
2018-02-24 15:18:16 +08:00
|
|
|
|
<< "例如你想每隔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;
|
|
|
|
|
return 0;
|
2017-05-09 10:45:55 +08:00
|
|
|
|
|
2018-02-24 15:18:16 +08:00
|
|
|
|
}
|
2018-12-28 16:47:50 +08:00
|
|
|
|
list<MediaPlayer::Ptr> 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;
|
|
|
|
|
}
|
2018-02-24 15:18:16 +08:00
|
|
|
|
});
|
2018-12-28 16:47:50 +08:00
|
|
|
|
player->setOnShutdown([&](const SockException &ex) {
|
|
|
|
|
--alivePlayerCnt;
|
2018-02-24 15:18:16 +08:00
|
|
|
|
});
|
2018-12-28 16:47:50 +08:00
|
|
|
|
(*player)[RtspPlayer::kRtpType] = atoi(argv[4]);
|
|
|
|
|
player->play(argv[3]);
|
|
|
|
|
playerList.push_back(player);
|
|
|
|
|
return playerCnt--;
|
|
|
|
|
});
|
2017-05-09 10:45:55 +08:00
|
|
|
|
|
2018-12-28 16:47:50 +08:00
|
|
|
|
AsyncTaskThread::Instance().DoTaskDelay(0, 1000, [&]() {
|
|
|
|
|
InfoL << "存活播放器个数:" << alivePlayerCnt.load();
|
|
|
|
|
return true;
|
2018-02-24 15:18:16 +08:00
|
|
|
|
});
|
2018-12-28 16:47:50 +08:00
|
|
|
|
|
2019-01-18 10:16:36 +08:00
|
|
|
|
sem.wait();
|
2018-02-24 15:18:16 +08:00
|
|
|
|
return 0;
|
2017-05-09 10:45:55 +08:00
|
|
|
|
}
|
|
|
|
|
|