From f9f386bc23320e3af516d7a004acf8e160b1bb1d Mon Sep 17 00:00:00 2001 From: PioLing <964472638@qq.com> Date: Fri, 14 Jun 2024 12:59:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=8C=E5=96=84MediaSource?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E6=8B=A6=E6=88=AA=E5=99=A8=20(#3622)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/MediaSource.cpp | 71 ++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/src/Common/MediaSource.cpp b/src/Common/MediaSource.cpp index 1ed99e46..1504a1dc 100644 --- a/src/Common/MediaSource.cpp +++ b/src/Common/MediaSource.cpp @@ -711,7 +711,7 @@ string MediaSourceEvent::getOriginUrl(MediaSource &sender) const { MediaOriginType MediaSourceEventInterceptor::getOriginType(MediaSource &sender) const { auto listener = _listener.lock(); if (!listener) { - return MediaOriginType::unknown; + return MediaSourceEvent::getOriginType(sender); } return listener->getOriginType(sender); } @@ -731,7 +731,7 @@ string MediaSourceEventInterceptor::getOriginUrl(MediaSource &sender) const { std::shared_ptr MediaSourceEventInterceptor::getOriginSock(MediaSource &sender) const { auto listener = _listener.lock(); if (!listener) { - return nullptr; + return MediaSourceEvent::getOriginSock(sender); } return listener->getOriginSock(sender); } @@ -739,7 +739,7 @@ std::shared_ptr MediaSourceEventInterceptor::getOriginSock(MediaSource bool MediaSourceEventInterceptor::seekTo(MediaSource &sender, uint32_t stamp) { auto listener = _listener.lock(); if (!listener) { - return false; + return MediaSourceEvent::seekTo(sender, stamp); } return listener->seekTo(sender, stamp); } @@ -747,7 +747,7 @@ bool MediaSourceEventInterceptor::seekTo(MediaSource &sender, uint32_t stamp) { bool MediaSourceEventInterceptor::pause(MediaSource &sender, bool pause) { auto listener = _listener.lock(); if (!listener) { - return false; + return MediaSourceEvent::pause(sender, pause); } return listener->pause(sender, pause); } @@ -755,7 +755,7 @@ bool MediaSourceEventInterceptor::pause(MediaSource &sender, bool pause) { bool MediaSourceEventInterceptor::speed(MediaSource &sender, float speed) { auto listener = _listener.lock(); if (!listener) { - return false; + return MediaSourceEvent::speed(sender, speed); } return listener->speed(sender, speed); } @@ -763,7 +763,7 @@ bool MediaSourceEventInterceptor::speed(MediaSource &sender, float speed) { bool MediaSourceEventInterceptor::close(MediaSource &sender) { auto listener = _listener.lock(); if (!listener) { - return false; + return MediaSourceEvent::close(sender); } return listener->close(sender); } @@ -771,7 +771,7 @@ bool MediaSourceEventInterceptor::close(MediaSource &sender) { int MediaSourceEventInterceptor::totalReaderCount(MediaSource &sender) { auto listener = _listener.lock(); if (!listener) { - return sender.readerCount(); + return MediaSourceEvent::totalReaderCount(sender); } return listener->totalReaderCount(sender); } @@ -779,49 +779,55 @@ int MediaSourceEventInterceptor::totalReaderCount(MediaSource &sender) { void MediaSourceEventInterceptor::onReaderChanged(MediaSource &sender, int size) { auto listener = _listener.lock(); if (!listener) { - MediaSourceEvent::onReaderChanged(sender, size); - } else { - listener->onReaderChanged(sender, size); + return MediaSourceEvent::onReaderChanged(sender, size); } + listener->onReaderChanged(sender, size); } void MediaSourceEventInterceptor::onRegist(MediaSource &sender, bool regist) { auto listener = _listener.lock(); - if (listener) { - listener->onRegist(sender, regist); + if (!listener) { + return MediaSourceEvent::onRegist(sender, regist); } + listener->onRegist(sender, regist); } -float MediaSourceEventInterceptor::getLossRate(MediaSource &sender, TrackType type){ +float MediaSourceEventInterceptor::getLossRate(MediaSource &sender, TrackType type) { auto listener = _listener.lock(); - if (listener) { - return listener->getLossRate(sender, type); + if (!listener) { + return MediaSourceEvent::getLossRate(sender, type); } - return -1; //异常返回-1 + return listener->getLossRate(sender, type); } toolkit::EventPoller::Ptr MediaSourceEventInterceptor::getOwnerPoller(MediaSource &sender) { auto listener = _listener.lock(); - if (listener) { - return listener->getOwnerPoller(sender); + if (!listener) { + return MediaSourceEvent::getOwnerPoller(sender); } - throw std::runtime_error(toolkit::demangle(typeid(*this).name()) + "::getOwnerPoller failed"); + return listener->getOwnerPoller(sender); } std::shared_ptr MediaSourceEventInterceptor::getMuxer(MediaSource &sender) const { auto listener = _listener.lock(); - return listener ? listener->getMuxer(sender) : nullptr; + if (!listener) { + return MediaSourceEvent::getMuxer(sender); + } + return listener->getMuxer(sender); } std::shared_ptr MediaSourceEventInterceptor::getRtpProcess(MediaSource &sender) const { auto listener = _listener.lock(); - return listener ? listener->getRtpProcess(sender) : nullptr; + if (!listener) { + return MediaSourceEvent::getRtpProcess(sender); + } + return listener->getRtpProcess(sender); } bool MediaSourceEventInterceptor::setupRecord(MediaSource &sender, Recorder::type type, bool start, const string &custom_path, size_t max_second) { auto listener = _listener.lock(); if (!listener) { - return false; + return MediaSourceEvent::setupRecord(sender, type, start, custom_path, max_second); } return listener->setupRecord(sender, type, start, custom_path, max_second); } @@ -829,7 +835,7 @@ bool MediaSourceEventInterceptor::setupRecord(MediaSource &sender, Recorder::typ bool MediaSourceEventInterceptor::isRecording(MediaSource &sender, Recorder::type type) { auto listener = _listener.lock(); if (!listener) { - return false; + return MediaSourceEvent::isRecording(sender, type); } return listener->isRecording(sender, type); } @@ -837,26 +843,25 @@ bool MediaSourceEventInterceptor::isRecording(MediaSource &sender, Recorder::typ vector MediaSourceEventInterceptor::getMediaTracks(MediaSource &sender, bool trackReady) const { auto listener = _listener.lock(); if (!listener) { - return vector(); + return MediaSourceEvent::getMediaTracks(sender, trackReady); } return listener->getMediaTracks(sender, trackReady); } void MediaSourceEventInterceptor::startSendRtp(MediaSource &sender, const MediaSourceEvent::SendRtpArgs &args, const std::function cb) { auto listener = _listener.lock(); - if (listener) { - listener->startSendRtp(sender, args, cb); - } else { - MediaSourceEvent::startSendRtp(sender, args, cb); + if (!listener) { + return MediaSourceEvent::startSendRtp(sender, args, cb); } + listener->startSendRtp(sender, args, cb); } -bool MediaSourceEventInterceptor::stopSendRtp(MediaSource &sender, const string &ssrc){ +bool MediaSourceEventInterceptor::stopSendRtp(MediaSource &sender, const string &ssrc) { auto listener = _listener.lock(); - if (listener) { - return listener->stopSendRtp(sender, ssrc); + if (!listener) { + return MediaSourceEvent::stopSendRtp(sender, ssrc); } - return false; + return listener->stopSendRtp(sender, ssrc); } void MediaSourceEventInterceptor::setDelegate(const std::weak_ptr &listener) { @@ -866,7 +871,7 @@ void MediaSourceEventInterceptor::setDelegate(const std::weak_ptr MediaSourceEventInterceptor::getDelegate() const{ +std::shared_ptr MediaSourceEventInterceptor::getDelegate() const { return _listener.lock(); }