From 51ae8d40834cfa775263022d012e47a955bab98f Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sun, 6 Sep 2020 18:19:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=8D=E7=94=A8=E5=BF=BD=E7=95=A5=E5=8D=8F?= =?UTF-8?q?=E8=AE=AE=E6=9F=A5=E6=89=BE=E6=B5=81=E7=9A=84=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/WebApi.cpp | 12 ++---------- src/Common/MediaSource.cpp | 12 ++++++++++++ src/Common/MediaSource.h | 4 ++++ src/Record/Recorder.cpp | 14 +++----------- 4 files changed, 21 insertions(+), 21 deletions(-) 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; }