From 86a7204baba28b9844d6ed17ffb55e4ef66ebf43 Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Thu, 21 May 2026 16:39:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3mp4=5Fas=5Fplayer=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E4=B8=BA1=E6=97=B6=E7=9B=B8=E5=85=B3bug=20(#4725)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/MediaSource.cpp | 7 ++++++- src/Common/MediaSource.h | 6 ------ src/Common/MultiMediaSourceMuxer.cpp | 5 ++--- src/Common/MultiMediaSourceMuxer.h | 3 +-- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/Common/MediaSource.cpp b/src/Common/MediaSource.cpp index 46cc95c7..659c157c 100644 --- a/src/Common/MediaSource.cpp +++ b/src/Common/MediaSource.cpp @@ -66,6 +66,11 @@ ProtocolOption::ProtocolOption() { ////////////////////////////////////////////////////////////////////////////////////////////////////////////// +struct MediaSourceNull : public MediaSource { + MediaSourceNull() : MediaSource("schema", MediaTuple{"vhost", "app", "stream", ""}) {}; + int readerCount() override { return 0; } +}; + MediaSource &MediaSource::NullMediaSource() { static std::shared_ptr s_null = std::make_shared(); return *s_null; @@ -272,7 +277,7 @@ bool MediaSource::setupRecord(Recorder::type type, bool start, const string &cus WarnL << "未设置MediaSource的事件监听者,setupRecord失败:" << getUrl(); return false; } - return listener->getMuxer(const_cast(*this))->setupRecord(type, start, custom_path, max_second); + return listener->getMuxer(const_cast(*this))->setupRecord(*this, type, start, custom_path, max_second); } bool MediaSource::isRecording(Recorder::type type){ diff --git a/src/Common/MediaSource.h b/src/Common/MediaSource.h index 91ae4802..fc7f77d2 100644 --- a/src/Common/MediaSource.h +++ b/src/Common/MediaSource.h @@ -573,11 +573,5 @@ private: toolkit::ObjectStatistic _statistic; }; -struct MediaSourceNull : public MediaSource { - MediaSourceNull(const MediaTuple &tuple = { "vhost", "app", "stream", "" }) - : MediaSource("schema", tuple) { }; - int readerCount() override { return 0; } -}; - } /* namespace mediakit */ #endif //ZLMEDIAKIT_MEDIASOURCE_H diff --git a/src/Common/MultiMediaSourceMuxer.cpp b/src/Common/MultiMediaSourceMuxer.cpp index ce5d9074..10479645 100644 --- a/src/Common/MultiMediaSourceMuxer.cpp +++ b/src/Common/MultiMediaSourceMuxer.cpp @@ -206,7 +206,6 @@ void MultiMediaSourceMuxer::forEachRtpSender(const std::function(tuple); if (!option.stream_replace.empty()) { // 支持在on_publish hook中替换stream_id [AUTO-TRANSLATED:375eb2ff] // Support replacing stream_id in on_publish hook @@ -314,13 +313,13 @@ int MultiMediaSourceMuxer::totalReaderCount(MediaSource &sender) { // 此函数可能跨线程调用 [AUTO-TRANSLATED:e8c5f74d] // This function may be called across threads -bool MultiMediaSourceMuxer::setupRecord(Recorder::type type, bool start, const string &custom_path, size_t max_second) { +bool MultiMediaSourceMuxer::setupRecord(MediaSource &sender, Recorder::type type, bool start, const string &custom_path, size_t max_second) { CHECK(getOwnerPoller(MediaSource::NullMediaSource())->isCurrentThread(), "Can only call setupRecord in it's owner poller"); onceToken token(nullptr, [&]() { 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(*_null_src, totalReaderCount()); + onReaderChanged(sender, totalReaderCount()); } }); switch (type) { diff --git a/src/Common/MultiMediaSourceMuxer.h b/src/Common/MultiMediaSourceMuxer.h index 1ff7abb9..ea656156 100644 --- a/src/Common/MultiMediaSourceMuxer.h +++ b/src/Common/MultiMediaSourceMuxer.h @@ -133,7 +133,7 @@ public: * [AUTO-TRANSLATED:cb1fd8a9] */ - bool setupRecord(Recorder::type type, bool start, const std::string &custom_path, size_t max_second); + bool setupRecord(MediaSource &sender, Recorder::type type, bool start, const std::string &custom_path, size_t max_second); /** * 开始录制mp4 @@ -266,7 +266,6 @@ private: toolkit::EventPoller::Ptr _poller; RingType::Ptr _ring; MediaSinkInterface::Ptr _delegate; - MediaSourceNull::Ptr _null_src; // 对象个数统计 [AUTO-TRANSLATED:3b43e8c2] // Object count statistics toolkit::ObjectStatistic _statistic;