修改完善MediaSource事件拦截器 (#3622)

This commit is contained in:
PioLing 2024-06-14 12:59:02 +08:00 committed by GitHub
parent d34da06766
commit f9f386bc23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -711,7 +711,7 @@ string MediaSourceEvent::getOriginUrl(MediaSource &sender) const {
MediaOriginType MediaSourceEventInterceptor::getOriginType(MediaSource &sender) const { MediaOriginType MediaSourceEventInterceptor::getOriginType(MediaSource &sender) const {
auto listener = _listener.lock(); auto listener = _listener.lock();
if (!listener) { if (!listener) {
return MediaOriginType::unknown; return MediaSourceEvent::getOriginType(sender);
} }
return listener->getOriginType(sender); return listener->getOriginType(sender);
} }
@ -731,7 +731,7 @@ string MediaSourceEventInterceptor::getOriginUrl(MediaSource &sender) const {
std::shared_ptr<SockInfo> MediaSourceEventInterceptor::getOriginSock(MediaSource &sender) const { std::shared_ptr<SockInfo> MediaSourceEventInterceptor::getOriginSock(MediaSource &sender) const {
auto listener = _listener.lock(); auto listener = _listener.lock();
if (!listener) { if (!listener) {
return nullptr; return MediaSourceEvent::getOriginSock(sender);
} }
return listener->getOriginSock(sender); return listener->getOriginSock(sender);
} }
@ -739,7 +739,7 @@ std::shared_ptr<SockInfo> MediaSourceEventInterceptor::getOriginSock(MediaSource
bool MediaSourceEventInterceptor::seekTo(MediaSource &sender, uint32_t stamp) { bool MediaSourceEventInterceptor::seekTo(MediaSource &sender, uint32_t stamp) {
auto listener = _listener.lock(); auto listener = _listener.lock();
if (!listener) { if (!listener) {
return false; return MediaSourceEvent::seekTo(sender, stamp);
} }
return listener->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) { bool MediaSourceEventInterceptor::pause(MediaSource &sender, bool pause) {
auto listener = _listener.lock(); auto listener = _listener.lock();
if (!listener) { if (!listener) {
return false; return MediaSourceEvent::pause(sender, pause);
} }
return listener->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) { bool MediaSourceEventInterceptor::speed(MediaSource &sender, float speed) {
auto listener = _listener.lock(); auto listener = _listener.lock();
if (!listener) { if (!listener) {
return false; return MediaSourceEvent::speed(sender, speed);
} }
return listener->speed(sender, speed); return listener->speed(sender, speed);
} }
@ -763,7 +763,7 @@ bool MediaSourceEventInterceptor::speed(MediaSource &sender, float speed) {
bool MediaSourceEventInterceptor::close(MediaSource &sender) { bool MediaSourceEventInterceptor::close(MediaSource &sender) {
auto listener = _listener.lock(); auto listener = _listener.lock();
if (!listener) { if (!listener) {
return false; return MediaSourceEvent::close(sender);
} }
return listener->close(sender); return listener->close(sender);
} }
@ -771,7 +771,7 @@ bool MediaSourceEventInterceptor::close(MediaSource &sender) {
int MediaSourceEventInterceptor::totalReaderCount(MediaSource &sender) { int MediaSourceEventInterceptor::totalReaderCount(MediaSource &sender) {
auto listener = _listener.lock(); auto listener = _listener.lock();
if (!listener) { if (!listener) {
return sender.readerCount(); return MediaSourceEvent::totalReaderCount(sender);
} }
return listener->totalReaderCount(sender); return listener->totalReaderCount(sender);
} }
@ -779,49 +779,55 @@ int MediaSourceEventInterceptor::totalReaderCount(MediaSource &sender) {
void MediaSourceEventInterceptor::onReaderChanged(MediaSource &sender, int size) { void MediaSourceEventInterceptor::onReaderChanged(MediaSource &sender, int size) {
auto listener = _listener.lock(); auto listener = _listener.lock();
if (!listener) { if (!listener) {
MediaSourceEvent::onReaderChanged(sender, size); return MediaSourceEvent::onReaderChanged(sender, size);
} else {
listener->onReaderChanged(sender, size);
} }
listener->onReaderChanged(sender, size);
} }
void MediaSourceEventInterceptor::onRegist(MediaSource &sender, bool regist) { void MediaSourceEventInterceptor::onRegist(MediaSource &sender, bool regist) {
auto listener = _listener.lock(); auto listener = _listener.lock();
if (listener) { if (!listener) {
listener->onRegist(sender, regist); 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(); auto listener = _listener.lock();
if (listener) { if (!listener) {
return listener->getLossRate(sender, type); return MediaSourceEvent::getLossRate(sender, type);
} }
return -1; //异常返回-1 return listener->getLossRate(sender, type);
} }
toolkit::EventPoller::Ptr MediaSourceEventInterceptor::getOwnerPoller(MediaSource &sender) { toolkit::EventPoller::Ptr MediaSourceEventInterceptor::getOwnerPoller(MediaSource &sender) {
auto listener = _listener.lock(); auto listener = _listener.lock();
if (listener) { if (!listener) {
return listener->getOwnerPoller(sender); return MediaSourceEvent::getOwnerPoller(sender);
} }
throw std::runtime_error(toolkit::demangle(typeid(*this).name()) + "::getOwnerPoller failed"); return listener->getOwnerPoller(sender);
} }
std::shared_ptr<MultiMediaSourceMuxer> MediaSourceEventInterceptor::getMuxer(MediaSource &sender) const { std::shared_ptr<MultiMediaSourceMuxer> MediaSourceEventInterceptor::getMuxer(MediaSource &sender) const {
auto listener = _listener.lock(); auto listener = _listener.lock();
return listener ? listener->getMuxer(sender) : nullptr; if (!listener) {
return MediaSourceEvent::getMuxer(sender);
}
return listener->getMuxer(sender);
} }
std::shared_ptr<RtpProcess> MediaSourceEventInterceptor::getRtpProcess(MediaSource &sender) const { std::shared_ptr<RtpProcess> MediaSourceEventInterceptor::getRtpProcess(MediaSource &sender) const {
auto listener = _listener.lock(); 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) { bool MediaSourceEventInterceptor::setupRecord(MediaSource &sender, Recorder::type type, bool start, const string &custom_path, size_t max_second) {
auto listener = _listener.lock(); auto listener = _listener.lock();
if (!listener) { if (!listener) {
return false; return MediaSourceEvent::setupRecord(sender, type, start, custom_path, max_second);
} }
return listener->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) { bool MediaSourceEventInterceptor::isRecording(MediaSource &sender, Recorder::type type) {
auto listener = _listener.lock(); auto listener = _listener.lock();
if (!listener) { if (!listener) {
return false; return MediaSourceEvent::isRecording(sender, type);
} }
return listener->isRecording(sender, type); return listener->isRecording(sender, type);
} }
@ -837,26 +843,25 @@ bool MediaSourceEventInterceptor::isRecording(MediaSource &sender, Recorder::typ
vector<Track::Ptr> MediaSourceEventInterceptor::getMediaTracks(MediaSource &sender, bool trackReady) const { vector<Track::Ptr> MediaSourceEventInterceptor::getMediaTracks(MediaSource &sender, bool trackReady) const {
auto listener = _listener.lock(); auto listener = _listener.lock();
if (!listener) { if (!listener) {
return vector<Track::Ptr>(); return MediaSourceEvent::getMediaTracks(sender, trackReady);
} }
return listener->getMediaTracks(sender, trackReady); return listener->getMediaTracks(sender, trackReady);
} }
void MediaSourceEventInterceptor::startSendRtp(MediaSource &sender, const MediaSourceEvent::SendRtpArgs &args, const std::function<void(uint16_t, const toolkit::SockException &)> cb) { void MediaSourceEventInterceptor::startSendRtp(MediaSource &sender, const MediaSourceEvent::SendRtpArgs &args, const std::function<void(uint16_t, const toolkit::SockException &)> cb) {
auto listener = _listener.lock(); auto listener = _listener.lock();
if (listener) { if (!listener) {
listener->startSendRtp(sender, args, cb); return MediaSourceEvent::startSendRtp(sender, args, cb);
} else {
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(); auto listener = _listener.lock();
if (listener) { if (!listener) {
return listener->stopSendRtp(sender, ssrc); return MediaSourceEvent::stopSendRtp(sender, ssrc);
} }
return false; return listener->stopSendRtp(sender, ssrc);
} }
void MediaSourceEventInterceptor::setDelegate(const std::weak_ptr<MediaSourceEvent> &listener) { void MediaSourceEventInterceptor::setDelegate(const std::weak_ptr<MediaSourceEvent> &listener) {
@ -866,7 +871,7 @@ void MediaSourceEventInterceptor::setDelegate(const std::weak_ptr<MediaSourceEve
_listener = listener; _listener = listener;
} }
std::shared_ptr<MediaSourceEvent> MediaSourceEventInterceptor::getDelegate() const{ std::shared_ptr<MediaSourceEvent> MediaSourceEventInterceptor::getDelegate() const {
return _listener.lock(); return _listener.lock();
} }