From ee05ae159ad6ffa146ba2aeb15a65992342bbdeb Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Sun, 3 May 2026 19:47:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dmp4=5Fas=5Fplayer=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E4=B8=BA1=E6=97=B6=EF=BC=8Con=5Fstream=5Fnone=5Freade?= =?UTF-8?q?r=E5=9B=9E=E8=B0=83=E6=97=A0=E6=95=88=E6=B5=81=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E7=9A=84=E9=97=AE=E9=A2=98=20(#4725)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/MultiMediaSourceMuxer.cpp | 20 +++++++++++++++++++- src/Common/MultiMediaSourceMuxer.h | 2 ++ src/FMP4/FMP4MediaSourceMuxer.h | 4 ++++ src/Record/HlsRecorder.h | 4 ++++ src/Rtmp/RtmpMediaSourceMuxer.h | 4 ++++ src/Rtsp/RtspMediaSourceMuxer.h | 4 ++++ src/TS/TSMediaSourceMuxer.h | 4 ++++ 7 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/Common/MultiMediaSourceMuxer.cpp b/src/Common/MultiMediaSourceMuxer.cpp index c3985615..20be4f8d 100644 --- a/src/Common/MultiMediaSourceMuxer.cpp +++ b/src/Common/MultiMediaSourceMuxer.cpp @@ -319,7 +319,7 @@ bool MultiMediaSourceMuxer::setupRecord(Recorder::type type, bool start, const s if (_option.mp4_as_player && type == Recorder::type_mp4) { // 开启关闭mp4录制,触发观看人数变化相关事件 [AUTO-TRANSLATED:b63a8deb] // Turn on/off mp4 recording, trigger events related to changes in the number of viewers - onReaderChanged(MediaSource::NullMediaSource(), totalReaderCount()); + onReaderChanged(*getAnyMediaSource(), totalReaderCount()); } }); switch (type) { @@ -908,6 +908,24 @@ bool MultiMediaSourceMuxer::onTrackFrame_l(const Frame::Ptr &frame_in) { return ret; } +#define TRY_SRC(muxer) \ + if (muxer) { \ + auto src = muxer->getMediaSource(); \ + if (src) { \ + return src; \ + } \ + } + +MediaSource::Ptr MultiMediaSourceMuxer::getAnyMediaSource() const { + TRY_SRC(_fmp4) + TRY_SRC(_rtmp) + TRY_SRC(_rtsp) + TRY_SRC(_ts) + TRY_SRC(_hls) + TRY_SRC(_hls_fmp4) + return MediaSource::NullMediaSource().shared_from_this(); +} + bool MultiMediaSourceMuxer::isEnabled(){ GET_CONFIG(uint32_t, stream_none_reader_delay_ms, General::kStreamNoneReaderDelayMS); if (!_is_enable || _last_check.elapsedTime() > stream_none_reader_delay_ms) { diff --git a/src/Common/MultiMediaSourceMuxer.h b/src/Common/MultiMediaSourceMuxer.h index 7b91641a..501b068d 100644 --- a/src/Common/MultiMediaSourceMuxer.h +++ b/src/Common/MultiMediaSourceMuxer.h @@ -237,6 +237,8 @@ protected: bool onTrackFrame(const Frame::Ptr &frame) override; bool onTrackFrame_l(const Frame::Ptr &frame); + MediaSource::Ptr getAnyMediaSource() const; + private: void createGopCacheIfNeed(size_t gop_count); std::shared_ptr makeRecorder(Recorder::type type); diff --git a/src/FMP4/FMP4MediaSourceMuxer.h b/src/FMP4/FMP4MediaSourceMuxer.h index 4cb8906a..2a9f68ec 100644 --- a/src/FMP4/FMP4MediaSourceMuxer.h +++ b/src/FMP4/FMP4MediaSourceMuxer.h @@ -73,6 +73,10 @@ public: _media_src->setInitSegment(getInitSegment()); } + MediaSource::Ptr getMediaSource() const { + return _media_src; + } + protected: void onSegmentData(std::string string, uint64_t stamp, bool key_frame) override { if (string.empty()) { diff --git a/src/Record/HlsRecorder.h b/src/Record/HlsRecorder.h index 1810aec5..6ed4e78f 100644 --- a/src/Record/HlsRecorder.h +++ b/src/Record/HlsRecorder.h @@ -77,6 +77,10 @@ public: return _option.hls_demand ? (_clear_cache ? true : _enabled) : true; } + MediaSource::Ptr getMediaSource() const { + return _hls ? _hls->getMediaSource() : nullptr; + } + protected: bool _enabled = true; bool _clear_cache = false; diff --git a/src/Rtmp/RtmpMediaSourceMuxer.h b/src/Rtmp/RtmpMediaSourceMuxer.h index 88accf64..843ec821 100644 --- a/src/Rtmp/RtmpMediaSourceMuxer.h +++ b/src/Rtmp/RtmpMediaSourceMuxer.h @@ -81,6 +81,10 @@ public: return _option.rtmp_demand ? (_clear_cache ? true : _enabled) : true; } + MediaSource::Ptr getMediaSource() const { + return _media_src; + } + private: bool _enabled = true; bool _clear_cache = false; diff --git a/src/Rtsp/RtspMediaSourceMuxer.h b/src/Rtsp/RtspMediaSourceMuxer.h index 8e4d9b7a..eeca3647 100644 --- a/src/Rtsp/RtspMediaSourceMuxer.h +++ b/src/Rtsp/RtspMediaSourceMuxer.h @@ -80,6 +80,10 @@ public: return _option.rtsp_demand ? (_clear_cache ? true : _enabled) : true; } + MediaSource::Ptr getMediaSource() const { + return _media_src; + } + private: bool _enabled = true; bool _clear_cache = false; diff --git a/src/TS/TSMediaSourceMuxer.h b/src/TS/TSMediaSourceMuxer.h index fab961d6..2911da0a 100644 --- a/src/TS/TSMediaSourceMuxer.h +++ b/src/TS/TSMediaSourceMuxer.h @@ -68,6 +68,10 @@ public: return _option.ts_demand ? (_clear_cache ? true : _enabled) : true; } + MediaSource::Ptr getMediaSource() const { + return _media_src; + } + protected: void onWrite(std::shared_ptr buffer, uint64_t timestamp, bool key_pos) override { if (!buffer) {