From 2f2868fab3cbbe7d2ef9e8fb45691d88ad090c41 Mon Sep 17 00:00:00 2001 From: Leon <8544842+leon14631@user.noreply.gitee.com> Date: Wed, 8 Jun 2022 08:34:12 +0000 Subject: [PATCH 1/7] update server/WebApi.cpp. --- server/WebApi.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 9992cfa6..282c2fba 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved. * * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit). @@ -343,6 +343,7 @@ Value makeMediaSourceJson(MediaSource &media){ switch(codec_type){ case TrackAudio : { auto audio_track = dynamic_pointer_cast(track); + obj["loss"] = media.getLossRate(TrackAudio); obj["sample_rate"] = audio_track->getAudioSampleRate(); obj["channels"] = audio_track->getAudioChannel(); obj["sample_bit"] = audio_track->getAudioSampleBit(); @@ -350,6 +351,7 @@ Value makeMediaSourceJson(MediaSource &media){ } case TrackVideo : { auto video_track = dynamic_pointer_cast(track); + obj["loss"] = media.getLossRate(TrackVideo); obj["width"] = video_track->getVideoWidth(); obj["height"] = video_track->getVideoHeight(); obj["fps"] = round(video_track->getVideoFps()); From c0e225750659df1385efbca3454eb1990fe6ef2b Mon Sep 17 00:00:00 2001 From: Leon <8544842+leon14631@user.noreply.gitee.com> Date: Wed, 8 Jun 2022 08:48:14 +0000 Subject: [PATCH 2/7] update src/Common/MediaSource.cpp. --- src/Common/MediaSource.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Common/MediaSource.cpp b/src/Common/MediaSource.cpp index 6b395c18..d2de4b9a 100644 --- a/src/Common/MediaSource.cpp +++ b/src/Common/MediaSource.cpp @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved. * * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit). @@ -213,6 +213,14 @@ bool MediaSource::close(bool force) { return listener->close(*this,force); } +int MediaSource::getLossRate(mediakit::TrackType type) { + auto listener = _listener.lock(); + if (!listener) { + return -1; + } + return listener->getLossRate(*this, type); +} + void MediaSource::onReaderChanged(int size) { auto listener = _listener.lock(); if (listener) { @@ -690,6 +698,14 @@ void MediaSourceEventInterceptor::onRegist(MediaSource &sender, bool regist) { } } +int MediaSourceEventInterceptor::getLossRate(MediaSource &sender, TrackType type){ + auto listener = _listener.lock(); + if (listener) { + return listener->getLossRate(sender, type); + } + return -1; //异常返回-1 +} + bool MediaSourceEventInterceptor::setupRecord(MediaSource &sender, Recorder::type type, bool start, const string &custom_path, size_t max_second) { auto listener = _listener.lock(); if (!listener) { From e299832f617a5a0068776dfd4aa83b32c5aa4d7f Mon Sep 17 00:00:00 2001 From: Leon <8544842+leon14631@user.noreply.gitee.com> Date: Wed, 8 Jun 2022 08:51:37 +0000 Subject: [PATCH 3/7] update src/Common/MediaSource.h. --- src/Common/MediaSource.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Common/MediaSource.h b/src/Common/MediaSource.h index dd6d3572..d711b4dc 100644 --- a/src/Common/MediaSource.h +++ b/src/Common/MediaSource.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved. * * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit). @@ -78,6 +78,8 @@ public: //流注册或注销事件 virtual void onRegist(MediaSource &sender, bool regist) {}; + virtual int getLossRate(MediaSource &sender, TrackType type) {return -1;}; + ////////////////////////仅供MultiMediaSourceMuxer对象继承//////////////////////// // 开启或关闭录制 virtual bool setupRecord(MediaSource &sender, Recorder::type type, bool start, const std::string &custom_path, size_t max_second) { return false; }; @@ -142,7 +144,7 @@ public: std::vector getMediaTracks(MediaSource &sender, bool trackReady = true) const override; void startSendRtp(MediaSource &sender, const SendRtpArgs &args, const std::function cb) override; bool stopSendRtp(MediaSource &sender, const std::string &ssrc) override; - + int getLossRate(MediaSource &sender, TrackType type) override; private: std::weak_ptr _listener; }; From c5a69163789163970e136932c925263599918ba0 Mon Sep 17 00:00:00 2001 From: Leon <8544842+leon14631@user.noreply.gitee.com> Date: Wed, 8 Jun 2022 09:04:45 +0000 Subject: [PATCH 4/7] update webrtc/WebRtcTransport.cpp. --- webrtc/WebRtcTransport.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index 42e97e92..fa9840c9 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved. * * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit). @@ -612,6 +612,10 @@ public: } int getLossRate() { + if (!_rtcp_context.getExpectedPacketsInterval()) //_rtcp_context.getExpectedPacketsInterval()取值总为零? + { + return 0; + } return _rtcp_context.geLostInterval() * 100 / _rtcp_context.getExpectedPacketsInterval(); } @@ -655,6 +659,21 @@ std::shared_ptr MediaTrack::getRtpChannel(uint32_t ssrc) const{ return it_chn->second; } +int WebRtcTransportImp::getLossRate(mediakit::TrackType type){ + for(auto it : _ssrc_to_track){ + auto ssrc = it.first; + auto track = it.second; + auto rtp_chn = track->getRtpChannel(ssrc); + if(rtp_chn){ + InfoL << "-----------接收丢包率,ssrc------------- :" << ssrc << ",loss rate(%):" << rtp_chn->getLossRate() ; + if (track->media && type==track->media->type){ + return rtp_chn->getLossRate(); + } + } + } + return -1; +} + void WebRtcTransportImp::onRtcp(const char *buf, size_t len) { _bytes_usage += len; auto rtcps = RtcpHeader::loadFromBytes((char *) buf, len); From 24b532c2cac9bd6e9fed84d7846ff90c00be776c Mon Sep 17 00:00:00 2001 From: Leon <8544842+leon14631@user.noreply.gitee.com> Date: Wed, 8 Jun 2022 09:06:23 +0000 Subject: [PATCH 5/7] update webrtc/WebRtcTransport.h. --- webrtc/WebRtcTransport.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/webrtc/WebRtcTransport.h b/webrtc/WebRtcTransport.h index a5bd4147..7a1cc63e 100644 --- a/webrtc/WebRtcTransport.h +++ b/webrtc/WebRtcTransport.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved. * * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit). @@ -262,6 +262,7 @@ protected: void onShutdown(const SockException &ex) override; virtual void onRecvRtp(MediaTrack &track, const std::string &rid, mediakit::RtpPacket::Ptr rtp) = 0; void updateTicker(); + int getLossRate(mediakit::TrackType type); private: void onSortedRtp(MediaTrack &track, const std::string &rid, mediakit::RtpPacket::Ptr rtp); From 8bb41ebcb8707a4a1d39327ae8877dc4a06a1b33 Mon Sep 17 00:00:00 2001 From: Leon <8544842+leon14631@user.noreply.gitee.com> Date: Wed, 8 Jun 2022 09:07:46 +0000 Subject: [PATCH 6/7] update webrtc/WebRtcPusher.cpp. --- webrtc/WebRtcPusher.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/webrtc/WebRtcPusher.cpp b/webrtc/WebRtcPusher.cpp index 111cda38..9659e101 100644 --- a/webrtc/WebRtcPusher.cpp +++ b/webrtc/WebRtcPusher.cpp @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved. * * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit). @@ -146,4 +146,8 @@ void WebRtcPusher::onRtcConfigure(RtcConfigure &configure) const { WebRtcTransportImp::onRtcConfigure(configure); //这只是推流 configure.audio.direction = configure.video.direction = RtpDirection::recvonly; -} \ No newline at end of file +} + +int WebRtcPusher::getLossRate(MediaSource &sender,mediakit::TrackType type){ + return WebRtcTransportImp::getLossRate(type); +} \ No newline at end of file From ed14d9373bb58d4e42ea51c436a9f0a10c283665 Mon Sep 17 00:00:00 2001 From: Leon <8544842+leon14631@user.noreply.gitee.com> Date: Wed, 8 Jun 2022 09:09:02 +0000 Subject: [PATCH 7/7] update webrtc/WebRtcPusher.h. --- webrtc/WebRtcPusher.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/webrtc/WebRtcPusher.h b/webrtc/WebRtcPusher.h index 865c5672..4b92961b 100644 --- a/webrtc/WebRtcPusher.h +++ b/webrtc/WebRtcPusher.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved. * * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit). @@ -40,6 +40,8 @@ protected: // 获取媒体源客户端相关信息 std::shared_ptr getOriginSock(mediakit::MediaSource &sender) const override; + int getLossRate(mediakit::MediaSource &sender,mediakit::TrackType type) override; + private: WebRtcPusher(const EventPoller::Ptr &poller, const mediakit::RtspMediaSourceImp::Ptr &src, const std::shared_ptr &ownership, const mediakit::MediaInfo &info, const mediakit::ProtocolOption &option);