mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-14 20:15:58 +08:00
AI automatically translates all comments in the code into English (#3917)
This commit is contained in:
@@ -101,7 +101,8 @@ public:
|
||||
const char *description() const override { return "主程序命令参数"; }
|
||||
};
|
||||
|
||||
// 此程序用于推流性能测试
|
||||
// 此程序用于推流性能测试 [AUTO-TRANSLATED:45b48457]
|
||||
// This program is used for streaming performance testing
|
||||
int main(int argc, char *argv[]) {
|
||||
CMD_main cmd_main;
|
||||
try {
|
||||
@@ -130,16 +131,20 @@ int main(int argc, char *argv[]) {
|
||||
const std::string app = "app";
|
||||
const std::string stream = "test";
|
||||
|
||||
//设置日志
|
||||
// 设置日志 [AUTO-TRANSLATED:50372045]
|
||||
// Set log
|
||||
Logger::Instance().add(std::make_shared<ConsoleChannel>("ConsoleChannel", logLevel));
|
||||
//启动异步日志线程
|
||||
// 启动异步日志线程 [AUTO-TRANSLATED:c93cc6f4]
|
||||
// Start asynchronous log thread
|
||||
Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>());
|
||||
|
||||
//设置线程数
|
||||
// 设置线程数 [AUTO-TRANSLATED:22ec5cc9]
|
||||
// Set the number of threads
|
||||
EventPollerPool::setPoolSize(threads);
|
||||
WorkThreadPool::setPoolSize(threads);
|
||||
|
||||
//设置合并写
|
||||
// 设置合并写 [AUTO-TRANSLATED:7bf3456d]
|
||||
// Set merge write
|
||||
mINI::Instance()[General::kMergeWriteMS] = merge_ms;
|
||||
|
||||
ProtocolOption option;
|
||||
@@ -156,16 +161,20 @@ int main(int argc, char *argv[]) {
|
||||
reader->startReadMP4(0, true, true);
|
||||
src = MediaSource::find(schema, DEFAULT_VHOST, app, stream, false);
|
||||
if (!src) {
|
||||
// mp4文件不存在
|
||||
// mp4文件不存在 [AUTO-TRANSLATED:80188fb8]
|
||||
// mp4 file does not exist
|
||||
WarnL << "no such file or directory: " << in_url;
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
//添加拉流代理
|
||||
// 添加拉流代理 [AUTO-TRANSLATED:aa516f44]
|
||||
// Add pull stream proxy
|
||||
proxy = std::make_shared<PlayerProxy>(tuple, option);
|
||||
//rtsp拉流代理方式
|
||||
// rtsp拉流代理方式 [AUTO-TRANSLATED:065d328d]
|
||||
// rtsp pull stream proxy method
|
||||
(*proxy)[Client::kRtpType] = rtp_type;
|
||||
//开始拉流代理
|
||||
// 开始拉流代理 [AUTO-TRANSLATED:6937338d]
|
||||
// Start pull stream proxy
|
||||
proxy->play(in_url);
|
||||
|
||||
}
|
||||
@@ -174,7 +183,8 @@ int main(int argc, char *argv[]) {
|
||||
return MediaSource::find(schema, DEFAULT_VHOST, app, stream, false);
|
||||
};
|
||||
|
||||
//推流器map
|
||||
// 推流器map [AUTO-TRANSLATED:279fcfb0]
|
||||
// Streamer map
|
||||
recursive_mutex mtx;
|
||||
unordered_map<void *, MediaPusher::Ptr> pusher_map;
|
||||
|
||||
@@ -183,44 +193,55 @@ int main(int argc, char *argv[]) {
|
||||
auto pusher = std::make_shared<MediaPusher>(src);
|
||||
auto tag = pusher.get();
|
||||
pusher->setOnCreateSocket([](const EventPoller::Ptr &poller) {
|
||||
//socket关闭互斥锁,提高性能
|
||||
// socket关闭互斥锁,提高性能 [AUTO-TRANSLATED:471fc644]
|
||||
// Socket close mutex, improve performance
|
||||
return Socket::createSocket(poller, false);
|
||||
});
|
||||
//设置推流失败监听
|
||||
// 设置推流失败监听 [AUTO-TRANSLATED:4ad49de9]
|
||||
// Set push stream failure listener
|
||||
pusher->setOnPublished([&mtx, &pusher_map, tag](const SockException &ex) {
|
||||
if (ex) {
|
||||
//推流失败,移除之
|
||||
// 推流失败,移除之 [AUTO-TRANSLATED:97a29246]
|
||||
// Push stream failed, remove it
|
||||
lock_guard<recursive_mutex> lck(mtx);
|
||||
pusher_map.erase(tag);
|
||||
}
|
||||
});
|
||||
//设置推流中途断开监听
|
||||
// 设置推流中途断开监听 [AUTO-TRANSLATED:228076ef]
|
||||
// Set push stream disconnection listener
|
||||
pusher->setOnShutdown([&mtx, &pusher_map, tag](const SockException &ex) {
|
||||
//推流中途失败,移除之
|
||||
// 推流中途失败,移除之 [AUTO-TRANSLATED:00e0928a]
|
||||
// Push stream failed halfway, remove it
|
||||
lock_guard<recursive_mutex> lck(mtx);
|
||||
pusher_map.erase(tag);
|
||||
});
|
||||
//设置rtsp推流方式(在rtsp推流时有效)
|
||||
// 设置rtsp推流方式(在rtsp推流时有效) [AUTO-TRANSLATED:2dc733df]
|
||||
// Set rtsp push stream method (effective when rtsp push stream)
|
||||
(*pusher)[Client::kRtpType] = rtp_type;
|
||||
//发起推流请求,每个推流端的stream_id都不一样
|
||||
// 发起推流请求,每个推流端的stream_id都不一样 [AUTO-TRANSLATED:8b356fcb]
|
||||
// Initiate push stream request, each push stream end has a different stream_id
|
||||
string url = StrPrinter << out_url << "_" << rand_str << "_" << index;
|
||||
pusher->publish(url);
|
||||
|
||||
//保持对象不销毁
|
||||
// 保持对象不销毁 [AUTO-TRANSLATED:650977d0]
|
||||
// Keep the object from being destroyed
|
||||
lock_guard<recursive_mutex> lck(mtx);
|
||||
pusher_map.emplace(tag, std::move(pusher));
|
||||
|
||||
//休眠后再启动下一个推流,防止短时间海量链接
|
||||
// 休眠后再启动下一个推流,防止短时间海量链接 [AUTO-TRANSLATED:df224fc9]
|
||||
// Sleep and then start the next push stream to prevent massive connections in a short time
|
||||
if (delay_ms > 0) {
|
||||
usleep(1000 * delay_ms);
|
||||
}
|
||||
};
|
||||
|
||||
// 设置退出信号
|
||||
// 设置退出信号 [AUTO-TRANSLATED:02c7fa30]
|
||||
// Set exit signal
|
||||
static bool exit_flag = false;
|
||||
signal(SIGINT, [](int) { exit_flag = true; });
|
||||
while (!exit_flag) {
|
||||
//休眠一秒打印
|
||||
// 休眠一秒打印 [AUTO-TRANSLATED:239dc996]
|
||||
// Sleep for one second and print
|
||||
sleep(1);
|
||||
|
||||
size_t alive_pusher = 0;
|
||||
@@ -231,7 +252,8 @@ int main(int argc, char *argv[]) {
|
||||
InfoL << "在线推流器个数:" << alive_pusher;
|
||||
auto src = get_src();
|
||||
for(size_t i = 0; i < pusher_count - alive_pusher && src && !exit_flag; ++i){
|
||||
//有些推流器失败了,那么我们重试添加
|
||||
// 有些推流器失败了,那么我们重试添加 [AUTO-TRANSLATED:d01fb300]
|
||||
// Some push streamers failed, so we retry adding
|
||||
add_pusher(get_src(), makeRandStr(8), i);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user