diff --git a/server/FFmpegSource.cpp b/server/FFmpegSource.cpp index 50492f22..b6a7ef7e 100644 --- a/server/FFmpegSource.cpp +++ b/server/FFmpegSource.cpp @@ -240,6 +240,15 @@ int FFmpegSource::totalReaderCount(MediaSource &sender) { return sender.readerCount(); } +void FFmpegSource::onNoneReader(MediaSource &sender){ + auto listener = _listener.lock(); + if(listener){ + listener->onNoneReader(sender); + return; + } + MediaSourceEvent::onNoneReader(sender); +} + void FFmpegSource::onGetMediaSource(const MediaSource::Ptr &src) { _listener = src->getListener(); src->setListener(shared_from_this()); diff --git a/server/FFmpegSource.h b/server/FFmpegSource.h index b32ec8f8..06bcf410 100644 --- a/server/FFmpegSource.h +++ b/server/FFmpegSource.h @@ -61,6 +61,8 @@ private: //MediaSourceEvent override bool close(MediaSource &sender,bool force) override; int totalReaderCount(MediaSource &sender) override; + void onNoneReader(MediaSource &sender) override; + private: Process _process; Timer::Ptr _timer; diff --git a/src/Common/MediaSource.h b/src/Common/MediaSource.h index 6c775934..28330166 100644 --- a/src/Common/MediaSource.h +++ b/src/Common/MediaSource.h @@ -53,9 +53,9 @@ public: virtual bool setupRecord(MediaSource &sender, Recorder::type type, bool start, const string &custom_path) { return false; }; // 获取录制状态 virtual bool isRecording(MediaSource &sender, Recorder::type type) { return false; }; -private: // 通知无人观看 - void onNoneReader(MediaSource &sender); + virtual void onNoneReader(MediaSource &sender); + private: Timer::Ptr _async_close_timer; }; diff --git a/src/Common/MultiMediaSourceMuxer.cpp b/src/Common/MultiMediaSourceMuxer.cpp index 70a20413..b5f10da8 100644 --- a/src/Common/MultiMediaSourceMuxer.cpp +++ b/src/Common/MultiMediaSourceMuxer.cpp @@ -278,6 +278,15 @@ int MultiMediaSourceMuxer::totalReaderCount(MediaSource &sender) { return listener->totalReaderCount(sender); } +void MultiMediaSourceMuxer::onNoneReader(MediaSource &sender){ + auto listener = _listener.lock(); + if (!listener) { + MediaSourceEvent::onNoneReader(sender); + return; + } + listener->onNoneReader(sender); +} + bool MultiMediaSourceMuxer::setupRecord(MediaSource &sender, Recorder::type type, bool start, const string &custom_path) { return _muxer->setupRecord(sender,type,start,custom_path); } diff --git a/src/Common/MultiMediaSourceMuxer.h b/src/Common/MultiMediaSourceMuxer.h index 2ba2aa99..679906ba 100644 --- a/src/Common/MultiMediaSourceMuxer.h +++ b/src/Common/MultiMediaSourceMuxer.h @@ -131,6 +131,12 @@ public: */ int totalReaderCount(MediaSource &sender) override; + /** + * 触发无人观看事件 + * @param sender 触发者 + */ + void onNoneReader(MediaSource &sender) override; + /** * 设置录制状态 * @param type 录制类型