diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 3e2f3f90..51afc9e5 100644 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -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); } diff --git a/src/Common/MediaSource.cpp b/src/Common/MediaSource.cpp index f0eb493d..758f8ff3 100644 --- a/src/Common/MediaSource.cpp +++ b/src/Common/MediaSource.cpp @@ -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); diff --git a/src/Common/MediaSource.h b/src/Common/MediaSource.h index 6da20cb5..98a5ed1a 100644 --- a/src/Common/MediaSource.h +++ b/src/Common/MediaSource.h @@ -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 &session, const function &cb); // 遍历所有流 diff --git a/src/Record/Recorder.cpp b/src/Record/Recorder.cpp index 4e6f0186..100a2951 100644 --- a/src/Record/Recorder.cpp +++ b/src/Record/Recorder.cpp @@ -79,16 +79,8 @@ std::shared_ptr 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; }