diff --git a/tests/test_bench_push.cpp b/tests/test_bench_push.cpp index ee07f0c2..a22d8879 100644 --- a/tests/test_bench_push.cpp +++ b/tests/test_bench_push.cpp @@ -20,7 +20,7 @@ #include "Thread/WorkThreadPool.h" #include "Pusher/MediaPusher.h" #include "Player/PlayerProxy.h" - +#include "Record/MP4Reader.h" using namespace std; using namespace toolkit; using namespace mediakit; @@ -52,7 +52,7 @@ public: Option::ArgRequired,/*该选项后面必须跟值*/ nullptr,/*该选项默认值*/ true,/*该选项是否必须赋值,如果没有默认值且为ArgRequired时用户必须提供该参数否则将抛异常*/ - "拉流url,支持rtsp/rtmp/hls",/*该选项说明文字*/ + "拉流url,支持rtsp/rtmp/hls/mp4文件",/*该选项说明文字*/ nullptr); (*_parser) << Option('o',/*该选项简称,如果是\x00则说明无简称*/ @@ -92,18 +92,16 @@ public: Option::ArgRequired,/*该选项后面必须跟值*/ to_string((int) (Rtsp::RTP_TCP)).data(),/*该选项默认值*/ true,/*该选项是否必须赋值,如果没有默认值且为ArgRequired时用户必须提供该参数否则将抛异常*/ - "rtsp拉流和推流方式,支持tcp/udp:0/1",/*该选项说明文字*/ - nullptr); + "rtsp拉流和推流方式,支持tcp/udp:0/1", /*该选项说明文字*/ + nullptr); } ~CMD_main() override {} - const char *description() const override { - return "主程序命令参数"; - } + const char *description() const override { return "主程序命令参数"; } }; -//此程序用于推流性能测试 +// 此程序用于推流性能测试 int main(int argc, char *argv[]) { CMD_main cmd_main; try { @@ -116,7 +114,7 @@ int main(int argc, char *argv[]) { } int threads = cmd_main["threads"]; - LogLevel logLevel = (LogLevel) cmd_main["level"].as(); + LogLevel logLevel = (LogLevel)cmd_main["level"].as(); logLevel = MIN(MAX(logLevel, LTrace), LError); auto in_url = cmd_main["in"]; auto out_url = cmd_main["out"]; @@ -129,6 +127,8 @@ int main(int argc, char *argv[]) { cout << "推流协议只支持rtsp或rtmp!" << endl; return -1; } + const std::string app = "app"; + const std::string stream = "test"; //设置日志 Logger::Instance().add(std::make_shared("ConsoleChannel", logLevel)); @@ -145,22 +145,39 @@ int main(int argc, char *argv[]) { ProtocolOption option; option.enable_hls = false; option.enable_mp4 = false; + MediaSource::Ptr src = nullptr; + PlayerProxy::Ptr proxy = nullptr;; - //添加拉流代理 - auto proxy = std::make_shared(DEFAULT_VHOST, "app", "test", option); - //rtsp拉流代理方式 - (*proxy)[Client::kRtpType] = rtp_type; - //开始拉流代理 - proxy->play(in_url); + if (end_with(in_url, ".mp4")) { + // create MediaSource from mp4file + auto reader = std::make_shared(DEFAULT_VHOST, app, stream, in_url); + //mp4 repeat + reader->startReadMP4(0, true, true); + src = MediaSource::find(schema, DEFAULT_VHOST, app, stream, false); + if (!src) { + // mp4文件不存在 + WarnL << "no such file or directory: " << in_url; + return -1; + } + } else { + //添加拉流代理 + proxy = std::make_shared(DEFAULT_VHOST, app, stream, option); + //rtsp拉流代理方式 + (*proxy)[Client::kRtpType] = rtp_type; + //开始拉流代理 + proxy->play(in_url); - auto get_src = [schema]() { - return MediaSource::find(schema, DEFAULT_VHOST, "app", "test", false); + } + + auto get_src = [schema,app,stream]() { + return MediaSource::find(schema, DEFAULT_VHOST, app, stream, false); }; //推流器map recursive_mutex mtx; unordered_map pusher_map; + auto add_pusher = [&](const MediaSource::Ptr &src, const string &rand_str, size_t index) { auto pusher = std::make_shared(src); auto tag = pusher.get();