diff --git a/server/FFmpegSource.cpp b/server/FFmpegSource.cpp index ec9e918d..95f079c7 100644 --- a/server/FFmpegSource.cpp +++ b/server/FFmpegSource.cpp @@ -118,8 +118,7 @@ void FFmpegSource::findAsync(int maxWaitMS, const function &session, bool retry, - const function &cb){ - auto src = MediaSource::find(info._schema, info._vhost, info._app, info._streamid, true); +void MediaSource::findAsync_l(const MediaInfo &info, const std::shared_ptr &session, bool retry, const function &cb){ + auto src = MediaSource::find_l(info._schema, info._vhost, info._app, info._streamid, true); if(src || !retry){ cb(src); return; @@ -248,7 +247,11 @@ void MediaSource::findAsync(const MediaInfo &info, const std::shared_ptr weakSender = sender.shared_from_this(); - _async_close_timer = std::make_shared(close_delay, [weakSender,is_mp4_vod]() { + _async_close_timer = std::make_shared(stream_none_reader_delay / 1000.0, [weakSender,is_mp4_vod]() { auto strongSender = weakSender.lock(); if (!strongSender) { //对象已经销毁 @@ -467,7 +468,7 @@ MediaSource::Ptr MediaSource::createFromMP4(const string &schema, const string & try { MP4Reader::Ptr pReader(new MP4Reader(vhost, app, stream, filePath)); pReader->startReadMP4(); - return MediaSource::find(schema, vhost, app, stream, false); + return MediaSource::find(schema, vhost, app, stream); } catch (std::exception &ex) { WarnL << ex.what(); return nullptr; diff --git a/src/Common/MediaSource.h b/src/Common/MediaSource.h index ab0a0cfa..299cf709 100644 --- a/src/Common/MediaSource.h +++ b/src/Common/MediaSource.h @@ -134,7 +134,7 @@ public: virtual bool isRecording(Recorder::type type); // 同步查找流 - static Ptr find(const string &schema, const string &vhost, const string &app, const string &id, bool bMake = true) ; + static Ptr find(const string &schema, const string &vhost, const string &app, const string &id); // 异步查找流 static void findAsync(const MediaInfo &info, const std::shared_ptr &session, const function &cb); // 遍历所有流 @@ -142,9 +142,14 @@ public: // 从mp4文件生成MediaSource static MediaSource::Ptr createFromMP4(const string &schema, const string &vhost, const string &app, const string &stream, const string &filePath = "", bool checkApp = true); + protected: void regist() ; - bool unregist() ; + bool unregist(); + +private: + static Ptr find_l(const string &schema, const string &vhost, const string &app, const string &id, bool bMake); + static void findAsync_l(const MediaInfo &info, const std::shared_ptr &session, bool retry, const function &cb); private: string _strSchema; string _strVhost; diff --git a/src/Record/Recorder.cpp b/src/Record/Recorder.cpp index 2ab341b7..2f0314cb 100644 --- a/src/Record/Recorder.cpp +++ b/src/Record/Recorder.cpp @@ -80,11 +80,11 @@ 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, false); + auto src = MediaSource::find(RTMP_SCHEMA, vhost, app, stream_id); if(src){ return src; } - return MediaSource::find(RTSP_SCHEMA, vhost, app, stream_id, false); + return MediaSource::find(RTSP_SCHEMA, vhost, app, stream_id); } bool Recorder::isRecording(type type, const string &vhost, const string &app, const string &stream_id){ diff --git a/src/Rtmp/FlvMuxer.cpp b/src/Rtmp/FlvMuxer.cpp index bc29cf31..35564867 100644 --- a/src/Rtmp/FlvMuxer.cpp +++ b/src/Rtmp/FlvMuxer.cpp @@ -167,7 +167,7 @@ void FlvMuxer::stop() { ///////////////////////////////////////////////////////FlvRecorder///////////////////////////////////////////////////// void FlvRecorder::startRecord(const EventPoller::Ptr &poller,const string &vhost, const string &app, const string &stream,const string &file_path) { - startRecord(poller,dynamic_pointer_cast(MediaSource::find(RTMP_SCHEMA,vhost,app,stream,false)),file_path); + startRecord(poller,dynamic_pointer_cast(MediaSource::find(RTMP_SCHEMA,vhost,app,stream)),file_path); } void FlvRecorder::startRecord(const EventPoller::Ptr &poller,const RtmpMediaSource::Ptr &media, const string &file_path) { diff --git a/src/Rtmp/RtmpSession.cpp b/src/Rtmp/RtmpSession.cpp index d30eafaf..95076682 100644 --- a/src/Rtmp/RtmpSession.cpp +++ b/src/Rtmp/RtmpSession.cpp @@ -130,8 +130,7 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) { auto src = dynamic_pointer_cast(MediaSource::find(RTMP_SCHEMA, _mediaInfo._vhost, _mediaInfo._app, - _mediaInfo._streamid, - false)); + _mediaInfo._streamid)); bool authSuccess = err.empty(); bool ok = (!src && !_pPublisherSrc && authSuccess); AMFValue status(AMF_OBJECT); diff --git a/src/Rtsp/RtpMultiCaster.cpp b/src/Rtsp/RtpMultiCaster.cpp index b341a0fb..cf3a12b0 100644 --- a/src/Rtsp/RtpMultiCaster.cpp +++ b/src/Rtsp/RtpMultiCaster.cpp @@ -81,6 +81,7 @@ RtpMultiCaster::~RtpMultiCaster() { _pReader->setDetachCB(nullptr); DebugL; } + RtpMultiCaster::RtpMultiCaster(const EventPoller::Ptr &poller,const string &strLocalIp,const string &strVhost,const string &strApp,const string &strStream) { auto src = dynamic_pointer_cast(MediaSource::find(RTSP_SCHEMA,strVhost,strApp, strStream)); if(!src){ diff --git a/src/Rtsp/RtspSession.cpp b/src/Rtsp/RtspSession.cpp index 45308943..d73b11f1 100644 --- a/src/Rtsp/RtspSession.cpp +++ b/src/Rtsp/RtspSession.cpp @@ -221,8 +221,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) { auto src = dynamic_pointer_cast(MediaSource::find(RTSP_SCHEMA, _mediaInfo._vhost, _mediaInfo._app, - _mediaInfo._streamid, - false)); + _mediaInfo._streamid)); if(src){ sendRtspResponse("406 Not Acceptable", {"Content-Type", "text/plain"}, "Already publishing."); string err = StrPrinter << "ANNOUNCE:"