From 974428d1e7bf704cdfd876dc57e3ee9322152498 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 11 Jun 2022 14:40:14 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A1=AE=E4=BF=9D=E8=8E=B7=E5=8F=96=E4=B8=A2?= =?UTF-8?q?=E5=8C=85=E7=8E=87=E6=97=B6=E7=BA=BF=E7=A8=8B=E5=AE=89=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/WebApi.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 6302bfdf..bbee730a 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -333,6 +333,8 @@ Value makeMediaSourceJson(MediaSource &media){ item["originSock"] = Json::nullValue; } + //getLossRate有线程安全问题;使用getMediaInfo接口才能获取丢包率;getMediaList接口将忽略丢包率 + auto current_thread = media.getOwnerPoller()->isCurrentThread(); for(auto &track : media.getTracks(false)){ Value obj; auto codec_type = track->getTrackType(); @@ -343,7 +345,9 @@ Value makeMediaSourceJson(MediaSource &media){ switch(codec_type){ case TrackAudio : { auto audio_track = dynamic_pointer_cast(track); - obj["loss"] = media.getLossRate(TrackAudio); + if (current_thread) { + obj["loss"] = media.getLossRate(TrackAudio); + } obj["sample_rate"] = audio_track->getAudioSampleRate(); obj["channels"] = audio_track->getAudioChannel(); obj["sample_bit"] = audio_track->getAudioSampleBit(); @@ -351,7 +355,9 @@ Value makeMediaSourceJson(MediaSource &media){ } case TrackVideo : { auto video_track = dynamic_pointer_cast(track); - obj["loss"] = media.getLossRate(TrackVideo); + if (current_thread) { + obj["loss"] = media.getLossRate(TrackVideo); + } obj["width"] = video_track->getVideoWidth(); obj["height"] = video_track->getVideoHeight(); obj["fps"] = round(video_track->getVideoFps());