Commit 51ae8d40 by xiongziliang

复用忽略协议查找流的相关代码

parent 599e8493
......@@ -810,19 +810,11 @@ void installWebApi() {
}
});
static auto getMediaSource = [](const string &vhost, const string &app, const string &stream_id){
auto src = MediaSource::find(RTMP_SCHEMA, vhost, app, stream_id);
if(src){
return src;
}
return MediaSource::find(RTSP_SCHEMA, vhost, app, stream_id);
};
api_regist2("/index/api/startSendRtp",[](API_ARGS2){
CHECK_SECRET();
CHECK_ARGS("vhost", "app", "stream", "ssrc", "dst_url", "dst_port", "is_udp");
auto src = getMediaSource(allArgs["vhost"], allArgs["app"], allArgs["stream"]);
auto src = MediaSource::find(allArgs["vhost"], allArgs["app"], allArgs["stream"]);
if (!src) {
throw ApiRetException("该媒体流不存在", API::OtherFailed);
}
......@@ -840,7 +832,7 @@ void installWebApi() {
CHECK_SECRET();
CHECK_ARGS("vhost", "app", "stream");
auto src = getMediaSource(allArgs["vhost"], allArgs["app"], allArgs["stream"]);
auto src = MediaSource::find(allArgs["vhost"], allArgs["app"], allArgs["stream"]);
if (!src) {
throw ApiRetException("该媒体流不存在", API::OtherFailed);
}
......
......@@ -307,6 +307,18 @@ MediaSource::Ptr MediaSource::find(const string &schema, const string &vhost, co
return find_l(schema, vhost, app, id, false);
}
MediaSource::Ptr MediaSource::find(const string &vhost, const string &app, const string &stream_id){
auto src = MediaSource::find(RTMP_SCHEMA, vhost, app, stream_id);
if (src) {
return src;
}
src = MediaSource::find(RTSP_SCHEMA, vhost, app, stream_id);
if (src) {
return src;
}
return MediaSource::find(HLS_SCHEMA, vhost, app, stream_id);
}
static string getTrackInfoStr(const TrackSource *track_src){
_StrPrinter codec_info;
auto tracks = track_src->getTracks(true);
......
......@@ -175,6 +175,10 @@ public:
// 同步查找流
static Ptr find(const string &schema, const string &vhost, const string &app, const string &id);
// 忽略类型,同步查找流,可能返回rtmp/rtsp/hls类型
static Ptr find(const string &vhost, const string &app, const string &stream_id);
// 异步查找流
static void findAsync(const MediaInfo &info, const std::shared_ptr<TcpSession> &session, const function<void(const Ptr &src)> &cb);
// 遍历所有流
......
......@@ -79,16 +79,8 @@ std::shared_ptr<MediaSinkInterface> Recorder::createRecorder(type type, const st
}
}
static MediaSource::Ptr getMediaSource(const string &vhost, const string &app, const string &stream_id){
auto src = MediaSource::find(RTMP_SCHEMA, vhost, app, stream_id);
if(src){
return src;
}
return MediaSource::find(RTSP_SCHEMA, vhost, app, stream_id);
}
bool Recorder::isRecording(type type, const string &vhost, const string &app, const string &stream_id){
auto src = getMediaSource(vhost, app, stream_id);
auto src = MediaSource::find(vhost, app, stream_id);
if(!src){
return false;
}
......@@ -96,7 +88,7 @@ bool Recorder::isRecording(type type, const string &vhost, const string &app, co
}
bool Recorder::startRecord(type type, const string &vhost, const string &app, const string &stream_id,const string &customized_path){
auto src = getMediaSource(vhost, app, stream_id);
auto src = MediaSource::find(vhost, app, stream_id);
if (!src) {
WarnL << "未找到相关的MediaSource,startRecord失败:" << vhost << "/" << app << "/" << stream_id;
return false;
......@@ -105,7 +97,7 @@ bool Recorder::startRecord(type type, const string &vhost, const string &app, co
}
bool Recorder::stopRecord(type type, const string &vhost, const string &app, const string &stream_id){
auto src = getMediaSource(vhost, app, stream_id);
auto src = MediaSource::find(vhost, app, stream_id);
if(!src){
return false;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论