mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
Push benchmark supports input from mp4 file (#3588)
This commit is contained in:
parent
8dad1983a0
commit
d6f166c1f4
@ -20,7 +20,7 @@
|
|||||||
#include "Thread/WorkThreadPool.h"
|
#include "Thread/WorkThreadPool.h"
|
||||||
#include "Pusher/MediaPusher.h"
|
#include "Pusher/MediaPusher.h"
|
||||||
#include "Player/PlayerProxy.h"
|
#include "Player/PlayerProxy.h"
|
||||||
|
#include "Record/MP4Reader.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
using namespace mediakit;
|
using namespace mediakit;
|
||||||
@ -52,7 +52,7 @@ public:
|
|||||||
Option::ArgRequired,/*该选项后面必须跟值*/
|
Option::ArgRequired,/*该选项后面必须跟值*/
|
||||||
nullptr,/*该选项默认值*/
|
nullptr,/*该选项默认值*/
|
||||||
true,/*该选项是否必须赋值,如果没有默认值且为ArgRequired时用户必须提供该参数否则将抛异常*/
|
true,/*该选项是否必须赋值,如果没有默认值且为ArgRequired时用户必须提供该参数否则将抛异常*/
|
||||||
"拉流url,支持rtsp/rtmp/hls",/*该选项说明文字*/
|
"拉流url,支持rtsp/rtmp/hls/mp4文件",/*该选项说明文字*/
|
||||||
nullptr);
|
nullptr);
|
||||||
|
|
||||||
(*_parser) << Option('o',/*该选项简称,如果是\x00则说明无简称*/
|
(*_parser) << Option('o',/*该选项简称,如果是\x00则说明无简称*/
|
||||||
@ -98,9 +98,7 @@ public:
|
|||||||
|
|
||||||
~CMD_main() override {}
|
~CMD_main() override {}
|
||||||
|
|
||||||
const char *description() const override {
|
const char *description() const override { return "主程序命令参数"; }
|
||||||
return "主程序命令参数";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 此程序用于推流性能测试
|
// 此程序用于推流性能测试
|
||||||
@ -129,6 +127,8 @@ int main(int argc, char *argv[]) {
|
|||||||
cout << "推流协议只支持rtsp或rtmp!" << endl;
|
cout << "推流协议只支持rtsp或rtmp!" << endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
const std::string app = "app";
|
||||||
|
const std::string stream = "test";
|
||||||
|
|
||||||
//设置日志
|
//设置日志
|
||||||
Logger::Instance().add(std::make_shared<ConsoleChannel>("ConsoleChannel", logLevel));
|
Logger::Instance().add(std::make_shared<ConsoleChannel>("ConsoleChannel", logLevel));
|
||||||
@ -145,22 +145,39 @@ int main(int argc, char *argv[]) {
|
|||||||
ProtocolOption option;
|
ProtocolOption option;
|
||||||
option.enable_hls = false;
|
option.enable_hls = false;
|
||||||
option.enable_mp4 = false;
|
option.enable_mp4 = false;
|
||||||
|
MediaSource::Ptr src = nullptr;
|
||||||
|
PlayerProxy::Ptr proxy = nullptr;;
|
||||||
|
|
||||||
|
if (end_with(in_url, ".mp4")) {
|
||||||
|
// create MediaSource from mp4file
|
||||||
|
auto reader = std::make_shared<MP4Reader>(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 {
|
||||||
//添加拉流代理
|
//添加拉流代理
|
||||||
auto proxy = std::make_shared<PlayerProxy>(DEFAULT_VHOST, "app", "test", option);
|
proxy = std::make_shared<PlayerProxy>(DEFAULT_VHOST, app, stream, option);
|
||||||
//rtsp拉流代理方式
|
//rtsp拉流代理方式
|
||||||
(*proxy)[Client::kRtpType] = rtp_type;
|
(*proxy)[Client::kRtpType] = rtp_type;
|
||||||
//开始拉流代理
|
//开始拉流代理
|
||||||
proxy->play(in_url);
|
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
|
//推流器map
|
||||||
recursive_mutex mtx;
|
recursive_mutex mtx;
|
||||||
unordered_map<void *, MediaPusher::Ptr> pusher_map;
|
unordered_map<void *, MediaPusher::Ptr> pusher_map;
|
||||||
|
|
||||||
|
|
||||||
auto add_pusher = [&](const MediaSource::Ptr &src, const string &rand_str, size_t index) {
|
auto add_pusher = [&](const MediaSource::Ptr &src, const string &rand_str, size_t index) {
|
||||||
auto pusher = std::make_shared<MediaPusher>(src);
|
auto pusher = std::make_shared<MediaPusher>(src);
|
||||||
auto tag = pusher.get();
|
auto tag = pusher.get();
|
||||||
|
Loading…
Reference in New Issue
Block a user