防止多个track时获取rtp推流丢包率失败

This commit is contained in:
xiongziliang 2022-09-03 16:47:37 +08:00
parent 5825f8b469
commit 00c9749b5d

View File

@ -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 : {