diff --git a/talk/media/webrtc/fakewebrtcvideoengine.h b/talk/media/webrtc/fakewebrtcvideoengine.h index 5e15aa8e33..ad8c046dec 100644 --- a/talk/media/webrtc/fakewebrtcvideoengine.h +++ b/talk/media/webrtc/fakewebrtcvideoengine.h @@ -596,12 +596,13 @@ class FakeWebRtcVideoEngine } void SetSendBandwidthEstimate(int channel, unsigned int send_bandwidth) { WEBRTC_ASSERT_CHANNEL(channel); - channels_[channel]->send_bandwidth_ = send_bandwidth; + channels_[GetOriginalChannelId(channel)]->send_bandwidth_ = send_bandwidth; } void SetReceiveBandwidthEstimate(int channel, unsigned int receive_bandwidth) { WEBRTC_ASSERT_CHANNEL(channel); - channels_[channel]->receive_bandwidth_ = receive_bandwidth; + channels_[GetOriginalChannelId(channel)]->receive_bandwidth_ = + receive_bandwidth; }; int GetRtxSendPayloadType(int channel) { WEBRTC_CHECK_CHANNEL(channel); @@ -636,7 +637,11 @@ class FakeWebRtcVideoEngine return -1; } Channel* ch = new Channel(); - channels_[++last_channel_] = ch; + ++last_channel_; + // The original channel of the first channel in a group refers to itself + // for code simplicity. + ch->original_channel_id_ = last_channel_; + channels_[last_channel_] = ch; channel = last_channel_; return 0; }; @@ -1121,6 +1126,7 @@ class FakeWebRtcVideoEngine std::map::const_iterator it = channels_.find(channel); // Assume the current video, fec and nack bitrate sums up to our estimate. if (it->second->send) { + it = channels_.find(GetOriginalChannelId(channel)); *send_bandwidth_estimate = it->second->send_bandwidth_; } else { *send_bandwidth_estimate = 0; @@ -1132,7 +1138,7 @@ class FakeWebRtcVideoEngine WEBRTC_CHECK_CHANNEL(channel); std::map::const_iterator it = channels_.find(channel); if (it->second->receive_) { - // For simplicity, assume all channels receive half of max send rate. + it = channels_.find(GetOriginalChannelId(channel)); *receive_bandwidth_estimate = it->second->receive_bandwidth_; } else { *receive_bandwidth_estimate = 0; diff --git a/talk/media/webrtc/webrtcvideoengine.cc b/talk/media/webrtc/webrtcvideoengine.cc index 29919d5d0f..7f70a3c25c 100644 --- a/talk/media/webrtc/webrtcvideoengine.cc +++ b/talk/media/webrtc/webrtcvideoengine.cc @@ -2483,13 +2483,6 @@ bool WebRtcVideoMediaChannel::GetStats(const StatsOptions& options, LOG_RTCERR1(GetBandwidthUsage, channel_id); } - unsigned int estimated_stream_send_bandwidth = 0; - if (engine_->vie()->rtp()->GetEstimatedSendBandwidth( - channel_id, &estimated_stream_send_bandwidth) == 0) { - estimated_send_bandwidth += estimated_stream_send_bandwidth; - } else { - LOG_RTCERR1(GetEstimatedSendBandwidth, channel_id); - } unsigned int target_enc_stream_bitrate = 0; if (engine_->vie()->codec()->GetCodecTargetBitrate( channel_id, &target_enc_stream_bitrate) == 0) { @@ -2498,12 +2491,22 @@ bool WebRtcVideoMediaChannel::GetStats(const StatsOptions& options, LOG_RTCERR1(GetCodecTargetBitrate, channel_id); } } + if (!send_channels_.empty()) { + // GetEstimatedSendBandwidth returns the estimated bandwidth for all video + // engine channels in a channel group. Any valid channel id will do as it + // is only used to access the right group of channels. + const int channel_id = send_channels_.begin()->second->channel_id(); + // Get the send bandwidth available for this MediaChannel. + if (engine_->vie()->rtp()->GetEstimatedSendBandwidth( + channel_id, &estimated_send_bandwidth) != 0) { + LOG_RTCERR1(GetEstimatedSendBandwidth, channel_id); + } + } } else { LOG(LS_WARNING) << "GetStats: sender information not ready."; } // Get the SSRC and stats for each receiver, based on our own calculations. - unsigned int estimated_recv_bandwidth = 0; for (RecvChannelMap::const_iterator it = recv_channels_.begin(); it != recv_channels_.end(); ++it) { WebRtcVideoChannelRecvInfo* channel = it->second; @@ -2564,15 +2567,20 @@ bool WebRtcVideoMediaChannel::GetStats(const StatsOptions& options, incoming_stream_rtcp_stats.fraction_lost) / (1 << 8); } info->receivers.push_back(rinfo); - - unsigned int estimated_recv_stream_bandwidth = 0; + } + unsigned int estimated_recv_bandwidth = 0; + if (!recv_channels_.empty()) { + // GetEstimatedReceiveBandwidth returns the estimated bandwidth for all + // video engine channels in a channel group. Any valid channel id will do as + // it is only used to access the right group of channels. + const int channel_id = recv_channels_.begin()->second->channel_id(); + // Gets the estimated receive bandwidth for the MediaChannel. if (engine_->vie()->rtp()->GetEstimatedReceiveBandwidth( - channel->channel_id(), &estimated_recv_stream_bandwidth) == 0) { - estimated_recv_bandwidth += estimated_recv_stream_bandwidth; - } else { - LOG_RTCERR1(GetEstimatedReceiveBandwidth, channel->channel_id()); + channel_id, &estimated_recv_bandwidth) != 0) { + LOG_RTCERR1(GetEstimatedReceiveBandwidth, channel_id); } } + // Build BandwidthEstimationInfo. // TODO(zhurunz): Add real unittest for this. BandwidthEstimationInfo bwe; diff --git a/talk/media/webrtc/webrtcvideoengine_unittest.cc b/talk/media/webrtc/webrtcvideoengine_unittest.cc index 4d88579540..8b60f23877 100644 --- a/talk/media/webrtc/webrtcvideoengine_unittest.cc +++ b/talk/media/webrtc/webrtcvideoengine_unittest.cc @@ -1529,26 +1529,28 @@ TEST_F(WebRtcVideoEngineTestFake, MultipleSendStreamsWithOneCapturer) { } -// Disabled since its flaky: b/11288120 -TEST_F(WebRtcVideoEngineTestFake, DISABLED_SendReceiveBitratesStats) { +TEST_F(WebRtcVideoEngineTestFake, SendReceiveBitratesStats) { EXPECT_TRUE(SetupEngine()); cricket::VideoOptions options; options.conference_mode.Set(true); EXPECT_TRUE(channel_->SetOptions(options)); EXPECT_TRUE(channel_->AddSendStream( cricket::StreamParams::CreateLegacy(1))); - int send_channel = vie_.GetLastChannel(); + int first_send_channel = vie_.GetLastChannel(); + EXPECT_TRUE(channel_->AddSendStream( + cricket::StreamParams::CreateLegacy(2))); + int second_send_channel = vie_.GetLastChannel(); cricket::VideoCodec codec(kVP8Codec720p); std::vector codec_list; codec_list.push_back(codec); EXPECT_TRUE(channel_->SetSendCodecs(codec_list)); - EXPECT_TRUE(channel_->AddRecvStream( - cricket::StreamParams::CreateLegacy(2))); - int first_receive_channel = vie_.GetLastChannel(); - EXPECT_NE(send_channel, first_receive_channel); EXPECT_TRUE(channel_->AddRecvStream( cricket::StreamParams::CreateLegacy(3))); + int first_receive_channel = vie_.GetLastChannel(); + EXPECT_NE(first_send_channel, first_receive_channel); + EXPECT_TRUE(channel_->AddRecvStream( + cricket::StreamParams::CreateLegacy(4))); int second_receive_channel = vie_.GetLastChannel(); EXPECT_NE(first_receive_channel, second_receive_channel); @@ -1563,21 +1565,20 @@ TEST_F(WebRtcVideoEngineTestFake, DISABLED_SendReceiveBitratesStats) { ASSERT_EQ(0, info.bw_estimations[0].target_enc_bitrate); // Start sending and receiving on one of the channels and verify bitrates. - EXPECT_EQ(0, vie_.StartSend(send_channel)); + EXPECT_EQ(0, vie_.StartSend(first_send_channel)); int send_video_bitrate = 800; int send_fec_bitrate = 100; int send_nack_bitrate = 20; int send_total_bitrate = send_video_bitrate + send_fec_bitrate + send_nack_bitrate; - int send_bandwidth = 950; - vie_.SetSendBitrates(send_channel, send_video_bitrate, send_fec_bitrate, + int send_bandwidth = 1900; + vie_.SetSendBitrates(first_send_channel, send_video_bitrate, send_fec_bitrate, send_nack_bitrate); - vie_.SetSendBandwidthEstimate(send_channel, send_bandwidth); + vie_.SetSendBandwidthEstimate(first_send_channel, send_bandwidth); EXPECT_EQ(0, vie_.StartReceive(first_receive_channel)); - int first_channel_receive_bandwidth = 600; - vie_.SetReceiveBandwidthEstimate(first_receive_channel, - first_channel_receive_bandwidth); + int receive_bandwidth = 600; + vie_.SetReceiveBandwidthEstimate(first_receive_channel, receive_bandwidth); info.Clear(); EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info)); @@ -1586,26 +1587,26 @@ TEST_F(WebRtcVideoEngineTestFake, DISABLED_SendReceiveBitratesStats) { ASSERT_EQ(send_total_bitrate, info.bw_estimations[0].transmit_bitrate); ASSERT_EQ(send_nack_bitrate, info.bw_estimations[0].retransmit_bitrate); ASSERT_EQ(send_bandwidth, info.bw_estimations[0].available_send_bandwidth); - ASSERT_EQ(first_channel_receive_bandwidth, - info.bw_estimations[0].available_recv_bandwidth); + ASSERT_EQ(receive_bandwidth, info.bw_estimations[0].available_recv_bandwidth); ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].target_enc_bitrate); // Start receiving on the second channel and verify received rate. + EXPECT_EQ(0, vie_.StartSend(second_send_channel)); + vie_.SetSendBitrates(second_send_channel, + send_video_bitrate, + send_fec_bitrate, + send_nack_bitrate); EXPECT_EQ(0, vie_.StartReceive(second_receive_channel)); - int second_channel_receive_bandwidth = 100; - vie_.SetReceiveBandwidthEstimate(second_receive_channel, - second_channel_receive_bandwidth); info.Clear(); EXPECT_TRUE(channel_->GetStats(cricket::StatsOptions(), &info)); ASSERT_EQ(1U, info.bw_estimations.size()); - ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].actual_enc_bitrate); - ASSERT_EQ(send_total_bitrate, info.bw_estimations[0].transmit_bitrate); - ASSERT_EQ(send_nack_bitrate, info.bw_estimations[0].retransmit_bitrate); + ASSERT_EQ(2 * send_video_bitrate, info.bw_estimations[0].actual_enc_bitrate); + ASSERT_EQ(2 * send_total_bitrate, info.bw_estimations[0].transmit_bitrate); + ASSERT_EQ(2 * send_nack_bitrate, info.bw_estimations[0].retransmit_bitrate); ASSERT_EQ(send_bandwidth, info.bw_estimations[0].available_send_bandwidth); - ASSERT_EQ(first_channel_receive_bandwidth + second_channel_receive_bandwidth, - info.bw_estimations[0].available_recv_bandwidth); - ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].target_enc_bitrate); + ASSERT_EQ(receive_bandwidth, info.bw_estimations[0].available_recv_bandwidth); + ASSERT_EQ(2 * send_video_bitrate, info.bw_estimations[0].target_enc_bitrate); } TEST_F(WebRtcVideoEngineTestFake, TestSetAdaptInputToCpuUsage) {