Wire up bandwidth limitation info to GetStats and adapt_reason.

The input resolution (output from video_adapter) can be further scaled down or higher video layer(s) can be dropped due to bitrate constraints.

BUG=webrtc:4112

Review URL: https://codereview.webrtc.org/1502173002

Cr-Commit-Position: refs/heads/master@{#11006}
This commit is contained in:
asapersson
2015-12-14 02:08:12 -08:00
committed by Commit bot
parent ac921d7365
commit 17821db197
4 changed files with 94 additions and 0 deletions

View File

@ -2117,6 +2117,14 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::GetVideoSenderInfo() {
}
}
}
// Get bandwidth limitation info from stream_->GetStats().
// Input resolution (output from video_adapter) can be further scaled down or
// higher video layer(s) can be dropped due to bitrate constraints.
// Note, adapt_changes only include changes from the video_adapter.
if (stats.bw_limited_resolution)
info.adapt_reason |= CoordinatedVideoAdapter::ADAPTREASON_BANDWIDTH;
info.ssrc_groups = ssrc_groups_;
info.framerate_input = stats.input_frame_rate;
info.framerate_sent = stats.encode_frame_rate;

View File

@ -2553,6 +2553,87 @@ TEST_F(WebRtcVideoChannel2Test, GetStatsTracksAdaptationStats) {
EXPECT_TRUE(channel_->SetCapturer(kSsrcs3[0], NULL));
}
TEST_F(WebRtcVideoChannel2Test, GetStatsTracksAdaptationAndBandwidthStats) {
AddSendStream(cricket::CreateSimStreamParams("cname", MAKE_VECTOR(kSsrcs3)));
// Capture format VGA.
cricket::FakeVideoCapturer video_capturer_vga;
const std::vector<cricket::VideoFormat>* formats =
video_capturer_vga.GetSupportedFormats();
cricket::VideoFormat capture_format_vga = (*formats)[1];
EXPECT_EQ(cricket::CS_RUNNING, video_capturer_vga.Start(capture_format_vga));
EXPECT_TRUE(channel_->SetCapturer(kSsrcs3[0], &video_capturer_vga));
EXPECT_TRUE(video_capturer_vga.CaptureFrame());
cricket::VideoCodec send_codec(100, "VP8", 640, 480, 30, 0);
cricket::VideoSendParameters parameters;
parameters.codecs.push_back(send_codec);
EXPECT_TRUE(channel_->SetSendParameters(parameters));
EXPECT_TRUE(channel_->SetSend(true));
// Verify that the CpuOveruseObserver is registered and trigger downgrade.
parameters.options.cpu_overuse_detection = rtc::Optional<bool>(true);
EXPECT_TRUE(channel_->SetSendParameters(parameters));
// Trigger overuse -> adapt CPU.
ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size());
webrtc::LoadObserver* overuse_callback =
fake_call_->GetVideoSendStreams().front()->GetConfig().overuse_callback;
ASSERT_TRUE(overuse_callback != NULL);
overuse_callback->OnLoadUpdate(webrtc::LoadObserver::kOveruse);
EXPECT_TRUE(video_capturer_vga.CaptureFrame());
cricket::VideoMediaInfo info;
EXPECT_TRUE(channel_->GetStats(&info));
ASSERT_EQ(1U, info.senders.size());
EXPECT_EQ(CoordinatedVideoAdapter::ADAPTREASON_CPU,
info.senders[0].adapt_reason);
// Set bandwidth limitation stats for the stream -> adapt CPU + BW.
webrtc::VideoSendStream::Stats stats;
stats.bw_limited_resolution = true;
fake_call_->GetVideoSendStreams().front()->SetStats(stats);
info.Clear();
EXPECT_TRUE(channel_->GetStats(&info));
ASSERT_EQ(1U, info.senders.size());
EXPECT_EQ(CoordinatedVideoAdapter::ADAPTREASON_CPU +
CoordinatedVideoAdapter::ADAPTREASON_BANDWIDTH,
info.senders[0].adapt_reason);
// Trigger upgrade -> adapt BW.
overuse_callback->OnLoadUpdate(webrtc::LoadObserver::kUnderuse);
EXPECT_TRUE(video_capturer_vga.CaptureFrame());
info.Clear();
EXPECT_TRUE(channel_->GetStats(&info));
ASSERT_EQ(1U, info.senders.size());
EXPECT_EQ(CoordinatedVideoAdapter::ADAPTREASON_BANDWIDTH,
info.senders[0].adapt_reason);
// Reset bandwidth limitation state -> adapt NONE.
stats.bw_limited_resolution = false;
fake_call_->GetVideoSendStreams().front()->SetStats(stats);
info.Clear();
EXPECT_TRUE(channel_->GetStats(&info));
ASSERT_EQ(1U, info.senders.size());
EXPECT_EQ(CoordinatedVideoAdapter::ADAPTREASON_NONE,
info.senders[0].adapt_reason);
EXPECT_TRUE(channel_->SetCapturer(kSsrcs3[0], NULL));
}
TEST_F(WebRtcVideoChannel2Test,
GetStatsTranslatesBandwidthLimitedResolutionCorrectly) {
FakeVideoSendStream* stream = AddSendStream();
webrtc::VideoSendStream::Stats stats;
stats.bw_limited_resolution = true;
stream->SetStats(stats);
cricket::VideoMediaInfo info;
EXPECT_TRUE(channel_->GetStats(&info));
ASSERT_EQ(1U, info.senders.size());
EXPECT_EQ(CoordinatedVideoAdapter::ADAPTREASON_BANDWIDTH,
info.senders[0].adapt_reason);
}
TEST_F(WebRtcVideoChannel2Test,
GetStatsTranslatesSendRtcpPacketTypesCorrectly) {
FakeVideoSendStream* stream = AddSendStream();

View File

@ -258,6 +258,10 @@ void SendStatisticsProxy::OnSendEncodedImage(
uma_container_->key_frame_counter_.Add(encoded_image._frameType ==
kVideoFrameKey);
stats_.bw_limited_resolution =
encoded_image.adapt_reason_.quality_resolution_downscales > 0 ||
encoded_image.adapt_reason_.bw_resolutions_disabled > 0;
if (encoded_image.adapt_reason_.quality_resolution_downscales != -1) {
bool downscaled =
encoded_image.adapt_reason_.quality_resolution_downscales > 0;

View File

@ -69,6 +69,7 @@ class VideoSendStream : public SendStream {
int target_media_bitrate_bps = 0;
int media_bitrate_bps = 0;
bool suspended = false;
bool bw_limited_resolution = false;
std::map<uint32_t, StreamStats> substreams;
};