调整代码细节
This commit is contained in:
parent
06023f1770
commit
936c6f7965
|
|
@ -647,45 +647,41 @@ void installWebApi() {
|
|||
//测试url http://127.0.0.1/index/api/addStreamPusherProxy?schema=rtmp&vhost=__defaultVhost__&app=proxy&stream=0&dst_url=rtmp://127.0.0.1/live/obs
|
||||
api_regist("/index/api/addStreamPusherProxy", [](API_ARGS_MAP_ASYNC) {
|
||||
CHECK_SECRET();
|
||||
CHECK_ARGS("schema","vhost","app","stream");
|
||||
CHECK_ARGS("schema", "vhost", "app", "stream", "dst_url");
|
||||
|
||||
InfoL << allArgs["schema"] << ", " << allArgs["vhost"] << ", " << allArgs["app"] << ", " << allArgs["stream"];
|
||||
|
||||
//查找源
|
||||
auto dst_url = allArgs["dst_url"];
|
||||
auto src_url = allArgs["schema"] + "/" + allArgs["vhost"] + "/" + allArgs["app"] + "/" + allArgs["stream"];
|
||||
auto src = MediaSource::find(allArgs["schema"],
|
||||
allArgs["vhost"],
|
||||
allArgs["app"],
|
||||
allArgs["stream"]);
|
||||
if (!src) {
|
||||
InfoL << "addStreamPusherProxy, canont find source stream!";
|
||||
const_cast<Value &>(val)["code"] = API::OtherFailed;
|
||||
const_cast<Value &>(val)["msg"] = "can not find the source stream";
|
||||
WarnL << "addStreamPusherProxy, can not find source stream:" << src_url;
|
||||
val["code"] = API::NotFound;
|
||||
val["msg"] = "can not find the source stream";
|
||||
invoker(200, headerOut, val.toStyledString());
|
||||
return;
|
||||
}
|
||||
|
||||
std::string srcUrl = allArgs["schema"] + "://" + "127.0.0.1" + "/" + allArgs["app"] + "/" + allArgs["stream"];
|
||||
std::string pushUrl = decodeBase64(allArgs["dst_url"]);
|
||||
InfoL << "addStreamPusherProxy, find stream: " << srcUrl << ", push dst url: " << pushUrl;
|
||||
InfoL << "addStreamPusherProxy, find stream: " << src_url << ", push dst url: " << dst_url;
|
||||
|
||||
addStreamPusherProxy(allArgs["schema"],
|
||||
allArgs["vhost"],
|
||||
allArgs["app"],
|
||||
allArgs["stream"],
|
||||
pushUrl,
|
||||
allArgs["dst_url"],
|
||||
allArgs["retry_count"],
|
||||
[invoker,val,headerOut, pushUrl](const SockException &ex, const string &key){
|
||||
[invoker, val, headerOut, dst_url](const SockException &ex, const string &key) mutable {
|
||||
if (ex) {
|
||||
const_cast<Value &>(val)["code"] = API::OtherFailed;
|
||||
const_cast<Value &>(val)["msg"] = ex.what();
|
||||
InfoL << "Publish error url: " << pushUrl;
|
||||
val["code"] = API::OtherFailed;
|
||||
val["msg"] = ex.what();
|
||||
WarnL << "Publish stream failed, dst url is: " << dst_url;
|
||||
} else {
|
||||
const_cast<Value &>(val)["data"]["key"] = key;
|
||||
InfoL << "Publish success, Please play with player:" << pushUrl;
|
||||
val["data"]["key"] = key;
|
||||
InfoL << "Publish success, please play with player:" << dst_url;
|
||||
}
|
||||
invoker(200, headerOut, val.toStyledString());
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
//关闭推流代理
|
||||
|
|
|
|||
Loading…
Reference in New Issue