提炼ProtocolOption赋值相关逻辑

This commit is contained in:
xiongziliang 2022-09-16 23:30:55 +08:00
parent c094751f17
commit 12551be33c
3 changed files with 45 additions and 61 deletions

View File

@ -1011,20 +1011,7 @@ void installWebApi() {
CHECK_SECRET();
CHECK_ARGS("vhost","app","stream","url");
ProtocolOption option;
getArgsValue(allArgs, "enable_hls", option.enable_hls);
getArgsValue(allArgs, "enable_mp4", option.enable_mp4);
getArgsValue(allArgs, "mp4_as_player", option.mp4_as_player);
getArgsValue(allArgs, "enable_rtsp", option.enable_rtsp);
getArgsValue(allArgs, "enable_rtmp", option.enable_rtmp);
getArgsValue(allArgs, "enable_ts", option.enable_ts);
getArgsValue(allArgs, "enable_fmp4", option.enable_fmp4);
getArgsValue(allArgs, "enable_audio", option.enable_audio);
getArgsValue(allArgs, "add_mute_audio", option.add_mute_audio);
getArgsValue(allArgs, "mp4_save_path", option.mp4_save_path);
getArgsValue(allArgs, "mp4_max_second", option.mp4_max_second);
getArgsValue(allArgs, "hls_save_path", option.hls_save_path);
getArgsValue(allArgs, "modify_stamp", option.modify_stamp);
ProtocolOption option(allArgs);
addStreamProxy(allArgs["vhost"],
allArgs["app"],
@ -1629,9 +1616,9 @@ void installWebApi() {
api_regist("/index/hook/on_publish",[](API_ARGS_JSON){
//开始推流事件
//转换hls
val["enableHls"] = true;
val["enable_hls"] = true;
//不录制mp4
val["enableMP4"] = false;
val["enable_mp4"] = false;
});
api_regist("/index/hook/on_play",[](API_ARGS_JSON){

View File

@ -292,6 +292,16 @@ static void pullStreamFromOrigin(const vector<string>& urls, size_t index, size_
static void *web_hook_tag = nullptr;
static mINI jsonToMini(const Value &obj) {
mINI ret;
if (obj.isObject()) {
for (auto it = obj.begin(); it != obj.end(); ++it) {
ret[it.name()] = (*it).asString();
}
}
return ret;
}
void installWebHook(){
GET_CONFIG(bool,hook_enable,Hook::kEnable);
GET_CONFIG(string,hook_adminparams,Hook::kAdminParams);
@ -311,55 +321,12 @@ void installWebHook(){
body["originTypeStr"] = getOriginTypeString(type);
//执行hook
do_http_hook(hook_publish, body, [invoker](const Value &obj, const string &err) mutable {
ProtocolOption option;
if (err.empty()) {
//推流鉴权成功
if (obj.isMember("enable_hls")) {
option.enable_hls = obj["enable_hls"].asBool();
}
if (obj.isMember("enable_mp4")) {
option.enable_mp4 = obj["enable_mp4"].asBool();
}
if (obj.isMember("enable_audio")) {
option.enable_audio = obj["enable_audio"].asBool();
}
if (obj.isMember("add_mute_audio")) {
option.add_mute_audio = obj["add_mute_audio"].asBool();
}
if (obj.isMember("mp4_save_path")) {
option.mp4_save_path = obj["mp4_save_path"].asString();
}
if (obj.isMember("mp4_max_second")) {
option.mp4_max_second = obj["mp4_max_second"].asUInt();
}
if (obj.isMember("hls_save_path")) {
option.hls_save_path = obj["hls_save_path"].asString();
}
if (obj.isMember("enable_rtsp")) {
option.enable_rtsp = obj["enable_rtsp"].asBool();
}
if (obj.isMember("enable_rtmp")) {
option.enable_rtmp = obj["enable_rtmp"].asBool();
}
if (obj.isMember("enable_ts")) {
option.enable_ts = obj["enable_ts"].asBool();
}
if (obj.isMember("enable_fmp4")) {
option.enable_fmp4 = obj["enable_fmp4"].asBool();
}
if (obj.isMember("continue_push_ms")) {
option.continue_push_ms = obj["continue_push_ms"].asUInt();
}
if (obj.isMember("mp4_as_player")) {
option.mp4_as_player = obj["mp4_as_player"].asBool();
}
if (obj.isMember("modify_stamp")) {
option.modify_stamp = obj["modify_stamp"].asBool();
}
invoker(err, option);
invoker(err, ProtocolOption(jsonToMini(obj)));
} else {
//推流鉴权失败
invoker(err, option);
invoker(err, ProtocolOption());
}
});
});

View File

@ -60,6 +60,36 @@ public:
//时间戳修复这一路流标志位
bool modify_stamp;
template <typename MAP>
ProtocolOption(const MAP &allArgs) : ProtocolOption() {
#define GET_OPT_VALUE(key) getArgsValue(allArgs, #key, key)
GET_OPT_VALUE(enable_hls);
GET_OPT_VALUE(enable_mp4);
GET_OPT_VALUE(mp4_as_player);
GET_OPT_VALUE(enable_rtsp);
GET_OPT_VALUE(enable_rtmp);
GET_OPT_VALUE(enable_ts);
GET_OPT_VALUE(enable_fmp4);
GET_OPT_VALUE(enable_audio);
GET_OPT_VALUE(add_mute_audio);
GET_OPT_VALUE(mp4_save_path);
GET_OPT_VALUE(mp4_max_second);
GET_OPT_VALUE(hls_save_path);
GET_OPT_VALUE(continue_push_ms);
GET_OPT_VALUE(modify_stamp);
}
ProtocolOption(const ProtocolOption &) = default;
private:
template <typename MAP, typename KEY, typename TYPE>
static void getArgsValue(const MAP &allArgs, const KEY &key, TYPE &value) {
auto val = ((MAP &)allArgs)[key];
if (!val.empty()) {
value = (TYPE)val;
}
}
};
class MultiMediaSourceMuxer : public MediaSourceEventInterceptor, public MediaSink, public std::enable_shared_from_this<MultiMediaSourceMuxer>{