From 00c9749b5d6ca6e7eb048da5f415493bd94ad1bb Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 3 Sep 2022 16:47:37 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B2=E6=AD=A2=E5=A4=9A=E4=B8=AAtrack?= =?UTF-8?q?=E6=97=B6=E8=8E=B7=E5=8F=96rtp=E6=8E=A8=E6=B5=81=E4=B8=A2?= =?UTF-8?q?=E5=8C=85=E7=8E=87=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/WebApi.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/WebApi.cpp b/server/WebApi.cpp index b5ab143e..ad3b8a27 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -341,6 +341,7 @@ Value makeMediaSourceJson(MediaSource &media){ //getLossRate有线程安全问题;使用getMediaInfo接口才能获取丢包率;getMediaList接口将忽略丢包率 auto current_thread = media.getOwnerPoller()->isCurrentThread(); + float last_loss = -1; for(auto &track : media.getTracks(false)){ Value obj; auto codec_type = track->getTrackType(); @@ -349,7 +350,14 @@ Value makeMediaSourceJson(MediaSource &media){ obj["ready"] = track->ready(); obj["codec_type"] = codec_type; if (current_thread) { - obj["loss"] = media.getLossRate(codec_type); + //rtp推流只有一个统计器,但是可能有多个track,如果短时间多次获取间隔丢包率,第二次会获取为-1 + auto loss = media.getLossRate(codec_type); + if (loss == -1) { + loss = last_loss; + } else { + last_loss = loss; + } + obj["loss"] = loss; } switch(codec_type){ case TrackAudio : {