OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 1970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1981 AddSendStream(); | 1981 AddSendStream(); |
1982 | 1982 |
1983 cricket::FakeVideoCapturer capturer; | 1983 cricket::FakeVideoCapturer capturer; |
1984 ASSERT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, &capturer)); | 1984 ASSERT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, &capturer)); |
1985 ASSERT_EQ(cricket::CS_RUNNING, | 1985 ASSERT_EQ(cricket::CS_RUNNING, |
1986 capturer.Start(capturer.GetSupportedFormats()->front())); | 1986 capturer.Start(capturer.GetSupportedFormats()->front())); |
1987 ASSERT_TRUE(channel_->SetSend(true)); | 1987 ASSERT_TRUE(channel_->SetSend(true)); |
1988 | 1988 |
1989 ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); | 1989 ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
1990 FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); | 1990 FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
1991 webrtc::LoadObserver* overuse_callback = | |
1992 send_stream->GetConfig().overuse_callback; | |
1993 ASSERT_TRUE(overuse_callback != NULL); | |
1994 | 1991 |
1995 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); | 1992 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); |
1996 EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); | 1993 EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
1997 EXPECT_EQ(1280, send_stream->GetLastWidth()); | 1994 EXPECT_EQ(1280, send_stream->GetLastWidth()); |
1998 EXPECT_EQ(720, send_stream->GetLastHeight()); | 1995 EXPECT_EQ(720, send_stream->GetLastHeight()); |
1999 | 1996 |
2000 // Trigger overuse. | 1997 // Trigger overuse. |
2001 overuse_callback->OnLoadUpdate(webrtc::LoadObserver::kOveruse); | 1998 rtc::VideoSinkWants wants; |
| 1999 wants.max_pixel_count = rtc::Optional<int>( |
| 2000 send_stream->GetLastWidth() * send_stream->GetLastHeight() - 1); |
| 2001 send_stream->InjectVideoSinkWants(wants); |
2002 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); | 2002 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); |
2003 EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames()); | 2003 EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames()); |
2004 EXPECT_EQ(1280 * 3 / 4, send_stream->GetLastWidth()); | 2004 EXPECT_EQ(1280 * 3 / 4, send_stream->GetLastWidth()); |
2005 EXPECT_EQ(720 * 3 / 4, send_stream->GetLastHeight()); | 2005 EXPECT_EQ(720 * 3 / 4, send_stream->GetLastHeight()); |
2006 | 2006 |
2007 // Trigger overuse again. | 2007 // Trigger overuse again. |
2008 overuse_callback->OnLoadUpdate(webrtc::LoadObserver::kOveruse); | 2008 wants.max_pixel_count = rtc::Optional<int>( |
| 2009 send_stream->GetLastWidth() * send_stream->GetLastHeight() - 1); |
| 2010 send_stream->InjectVideoSinkWants(wants); |
2009 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); | 2011 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); |
2010 EXPECT_EQ(3, send_stream->GetNumberOfSwappedFrames()); | 2012 EXPECT_EQ(3, send_stream->GetNumberOfSwappedFrames()); |
2011 EXPECT_EQ(1280 * 2 / 4, send_stream->GetLastWidth()); | 2013 EXPECT_EQ(1280 * 2 / 4, send_stream->GetLastWidth()); |
2012 EXPECT_EQ(720 * 2 / 4, send_stream->GetLastHeight()); | 2014 EXPECT_EQ(720 * 2 / 4, send_stream->GetLastHeight()); |
2013 | 2015 |
2014 // Trigger overuse again. This should not decrease the resolution since we | |
2015 // should only adapt the resolution down max two steps. | |
2016 overuse_callback->OnLoadUpdate(webrtc::LoadObserver::kOveruse); | |
2017 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); | |
2018 EXPECT_EQ(4, send_stream->GetNumberOfSwappedFrames()); | |
2019 EXPECT_EQ(1280 * 2 / 4, send_stream->GetLastWidth()); | |
2020 EXPECT_EQ(720 * 2 / 4, send_stream->GetLastHeight()); | |
2021 | |
2022 // Change input resolution. | 2016 // Change input resolution. |
2023 EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724, cricket::FOURCC_I420)); | 2017 EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724, cricket::FOURCC_I420)); |
2024 EXPECT_EQ(5, send_stream->GetNumberOfSwappedFrames()); | 2018 EXPECT_EQ(4, send_stream->GetNumberOfSwappedFrames()); |
2025 EXPECT_EQ(1284 / 2, send_stream->GetLastWidth()); | 2019 EXPECT_EQ(1284 / 2, send_stream->GetLastWidth()); |
2026 EXPECT_EQ(724 / 2, send_stream->GetLastHeight()); | 2020 EXPECT_EQ(724 / 2, send_stream->GetLastHeight()); |
2027 | 2021 |
2028 // Trigger underuse which should go back up in resolution. | 2022 // Trigger underuse which should go back up in resolution. |
2029 overuse_callback->OnLoadUpdate(webrtc::LoadObserver::kUnderuse); | 2023 wants.max_pixel_count = rtc::Optional<int>(); |
| 2024 wants.max_pixel_count_step_up = rtc::Optional<int>( |
| 2025 send_stream->GetLastWidth() * send_stream->GetLastHeight()); |
| 2026 send_stream->InjectVideoSinkWants(wants); |
2030 EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724, cricket::FOURCC_I420)); | 2027 EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724, cricket::FOURCC_I420)); |
2031 EXPECT_EQ(6, send_stream->GetNumberOfSwappedFrames()); | 2028 EXPECT_EQ(5, send_stream->GetNumberOfSwappedFrames()); |
2032 EXPECT_EQ(1284 * 3 / 4, send_stream->GetLastWidth()); | 2029 EXPECT_EQ(1284 * 3 / 4, send_stream->GetLastWidth()); |
2033 EXPECT_EQ(724 * 3 / 4, send_stream->GetLastHeight()); | 2030 EXPECT_EQ(724 * 3 / 4, send_stream->GetLastHeight()); |
2034 | 2031 |
2035 // Trigger underuse which should go back up in resolution. | 2032 // Trigger underuse which should go back up in resolution. |
2036 overuse_callback->OnLoadUpdate(webrtc::LoadObserver::kUnderuse); | 2033 wants.max_pixel_count = rtc::Optional<int>(); |
| 2034 wants.max_pixel_count_step_up = rtc::Optional<int>( |
| 2035 send_stream->GetLastWidth() * send_stream->GetLastHeight()); |
| 2036 send_stream->InjectVideoSinkWants(wants); |
2037 EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724, cricket::FOURCC_I420)); | 2037 EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724, cricket::FOURCC_I420)); |
2038 EXPECT_EQ(7, send_stream->GetNumberOfSwappedFrames()); | 2038 EXPECT_EQ(6, send_stream->GetNumberOfSwappedFrames()); |
2039 EXPECT_EQ(1284, send_stream->GetLastWidth()); | 2039 EXPECT_EQ(1284, send_stream->GetLastWidth()); |
2040 EXPECT_EQ(724, send_stream->GetLastHeight()); | 2040 EXPECT_EQ(724, send_stream->GetLastHeight()); |
2041 | 2041 |
2042 EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); | 2042 EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); |
2043 } | 2043 } |
2044 | 2044 |
2045 TEST_F(WebRtcVideoChannel2Test, PreviousAdaptationDoesNotApplyToScreenshare) { | 2045 TEST_F(WebRtcVideoChannel2Test, PreviousAdaptationDoesNotApplyToScreenshare) { |
2046 cricket::VideoCodec codec = kVp8Codec; | 2046 cricket::VideoCodec codec = kVp8Codec; |
2047 cricket::VideoSendParameters parameters; | 2047 cricket::VideoSendParameters parameters; |
2048 parameters.codecs.push_back(codec); | 2048 parameters.codecs.push_back(codec); |
2049 | 2049 |
2050 MediaConfig media_config = MediaConfig(); | 2050 MediaConfig media_config = MediaConfig(); |
2051 channel_.reset( | 2051 channel_.reset( |
2052 engine_.CreateChannel(fake_call_.get(), media_config, VideoOptions())); | 2052 engine_.CreateChannel(fake_call_.get(), media_config, VideoOptions())); |
2053 ASSERT_TRUE(channel_->SetSendParameters(parameters)); | 2053 ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
2054 | 2054 |
2055 AddSendStream(); | 2055 AddSendStream(); |
2056 | 2056 |
2057 cricket::FakeVideoCapturer capturer; | 2057 cricket::FakeVideoCapturer capturer; |
2058 ASSERT_EQ(cricket::CS_RUNNING, | 2058 ASSERT_EQ(cricket::CS_RUNNING, |
2059 capturer.Start(capturer.GetSupportedFormats()->front())); | 2059 capturer.Start(capturer.GetSupportedFormats()->front())); |
2060 ASSERT_TRUE(channel_->SetSend(true)); | 2060 ASSERT_TRUE(channel_->SetSend(true)); |
2061 cricket::VideoOptions camera_options; | 2061 cricket::VideoOptions camera_options; |
| 2062 camera_options.is_screencast = rtc::Optional<bool>(false); |
2062 channel_->SetVideoSend(last_ssrc_, true /* enable */, &camera_options, | 2063 channel_->SetVideoSend(last_ssrc_, true /* enable */, &camera_options, |
2063 &capturer); | 2064 &capturer); |
2064 | 2065 |
2065 ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); | 2066 ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
2066 FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); | 2067 FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
2067 webrtc::LoadObserver* overuse_callback = | |
2068 send_stream->GetConfig().overuse_callback; | |
2069 ASSERT_TRUE(overuse_callback != NULL); | |
2070 | 2068 |
2071 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); | 2069 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); |
2072 EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); | 2070 EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
2073 EXPECT_EQ(1280, send_stream->GetLastWidth()); | 2071 EXPECT_EQ(1280, send_stream->GetLastWidth()); |
2074 EXPECT_EQ(720, send_stream->GetLastHeight()); | 2072 EXPECT_EQ(720, send_stream->GetLastHeight()); |
2075 | 2073 |
2076 // Trigger overuse. | 2074 // Trigger overuse. |
2077 overuse_callback->OnLoadUpdate(webrtc::LoadObserver::kOveruse); | 2075 rtc::VideoSinkWants wants; |
| 2076 wants.max_pixel_count = rtc::Optional<int>( |
| 2077 send_stream->GetLastWidth() * send_stream->GetLastHeight() - 1); |
| 2078 send_stream->InjectVideoSinkWants(wants); |
2078 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); | 2079 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); |
2079 EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames()); | 2080 EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames()); |
2080 EXPECT_EQ(1280 * 3 / 4, send_stream->GetLastWidth()); | 2081 EXPECT_EQ(1280 * 3 / 4, send_stream->GetLastWidth()); |
2081 EXPECT_EQ(720 * 3 / 4, send_stream->GetLastHeight()); | 2082 EXPECT_EQ(720 * 3 / 4, send_stream->GetLastHeight()); |
2082 | 2083 |
2083 // Switch to screen share. Expect no CPU adaptation. | 2084 // Switch to screen share. Expect no CPU adaptation. |
2084 cricket::FakeVideoCapturer screen_share(true); | 2085 cricket::FakeVideoCapturer screen_share(true); |
2085 ASSERT_EQ(cricket::CS_RUNNING, | 2086 ASSERT_EQ(cricket::CS_RUNNING, |
2086 screen_share.Start(screen_share.GetSupportedFormats()->front())); | 2087 screen_share.Start(screen_share.GetSupportedFormats()->front())); |
2087 cricket::VideoOptions screenshare_options; | 2088 cricket::VideoOptions screenshare_options; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2123 | 2124 |
2124 cricket::FakeVideoCapturer capturer; | 2125 cricket::FakeVideoCapturer capturer; |
2125 VideoOptions options; | 2126 VideoOptions options; |
2126 options.is_screencast = rtc::Optional<bool>(is_screenshare); | 2127 options.is_screencast = rtc::Optional<bool>(is_screenshare); |
2127 EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, &options, &capturer)); | 2128 EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, &options, &capturer)); |
2128 cricket::VideoFormat capture_format = capturer.GetSupportedFormats()->front(); | 2129 cricket::VideoFormat capture_format = capturer.GetSupportedFormats()->front(); |
2129 EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format)); | 2130 EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format)); |
2130 | 2131 |
2131 EXPECT_TRUE(channel_->SetSend(true)); | 2132 EXPECT_TRUE(channel_->SetSend(true)); |
2132 | 2133 |
2133 // Trigger overuse. | |
2134 ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); | |
2135 FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); | 2134 FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
2136 webrtc::LoadObserver* overuse_callback = | |
2137 send_stream->GetConfig().overuse_callback; | |
2138 | 2135 |
2139 if (!enable_overuse) { | 2136 if (!enable_overuse || is_screenshare) { |
2140 ASSERT_TRUE(overuse_callback == NULL); | 2137 EXPECT_FALSE(send_stream->resolution_scaling_enabled()); |
2141 | 2138 |
2142 EXPECT_TRUE(capturer.CaptureFrame()); | 2139 EXPECT_TRUE(capturer.CaptureFrame()); |
2143 EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); | 2140 EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
2144 | 2141 |
2145 EXPECT_EQ(capture_format.width, send_stream->GetLastWidth()); | 2142 EXPECT_EQ(capture_format.width, send_stream->GetLastWidth()); |
2146 EXPECT_EQ(capture_format.height, send_stream->GetLastHeight()); | 2143 EXPECT_EQ(capture_format.height, send_stream->GetLastHeight()); |
2147 | 2144 |
2148 EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); | 2145 EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); |
2149 return; | 2146 return; |
2150 } | 2147 } |
2151 | 2148 |
2152 ASSERT_TRUE(overuse_callback != NULL); | 2149 EXPECT_TRUE(send_stream->resolution_scaling_enabled()); |
| 2150 // Trigger overuse. |
| 2151 ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
| 2152 |
| 2153 rtc::VideoSinkWants wants; |
| 2154 wants.max_pixel_count = |
| 2155 rtc::Optional<int>(capture_format.width * capture_format.height - 1); |
| 2156 send_stream->InjectVideoSinkWants(wants); |
| 2157 |
2153 EXPECT_TRUE(capturer.CaptureFrame()); | 2158 EXPECT_TRUE(capturer.CaptureFrame()); |
2154 EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); | 2159 EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
2155 overuse_callback->OnLoadUpdate(webrtc::LoadObserver::kOveruse); | |
2156 | 2160 |
2157 EXPECT_TRUE(capturer.CaptureFrame()); | 2161 EXPECT_TRUE(capturer.CaptureFrame()); |
2158 EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames()); | 2162 EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames()); |
2159 | 2163 |
2160 if (is_screenshare) { | 2164 EXPECT_LT(send_stream->GetLastWidth(), capture_format.width); |
2161 // Do not adapt screen share. | 2165 EXPECT_LT(send_stream->GetLastHeight(), capture_format.height); |
2162 EXPECT_EQ(capture_format.width, send_stream->GetLastWidth()); | |
2163 EXPECT_EQ(capture_format.height, send_stream->GetLastHeight()); | |
2164 } else { | |
2165 EXPECT_LT(send_stream->GetLastWidth(), capture_format.width); | |
2166 EXPECT_LT(send_stream->GetLastHeight(), capture_format.height); | |
2167 } | |
2168 | 2166 |
2169 // Trigger underuse which should go back to normal resolution. | 2167 // Trigger underuse which should go back to normal resolution. |
2170 overuse_callback->OnLoadUpdate(webrtc::LoadObserver::kUnderuse); | 2168 wants.max_pixel_count = rtc::Optional<int>(); |
| 2169 wants.max_pixel_count_step_up = rtc::Optional<int>( |
| 2170 send_stream->GetLastWidth() * send_stream->GetLastHeight()); |
| 2171 send_stream->InjectVideoSinkWants(wants); |
| 2172 |
2171 EXPECT_TRUE(capturer.CaptureFrame()); | 2173 EXPECT_TRUE(capturer.CaptureFrame()); |
2172 EXPECT_EQ(3, send_stream->GetNumberOfSwappedFrames()); | 2174 EXPECT_EQ(3, send_stream->GetNumberOfSwappedFrames()); |
2173 | 2175 |
2174 EXPECT_EQ(capture_format.width, send_stream->GetLastWidth()); | 2176 EXPECT_EQ(capture_format.width, send_stream->GetLastWidth()); |
2175 EXPECT_EQ(capture_format.height, send_stream->GetLastHeight()); | 2177 EXPECT_EQ(capture_format.height, send_stream->GetLastHeight()); |
2176 | 2178 |
2177 EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); | 2179 EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); |
2178 } | 2180 } |
2179 | 2181 |
2180 TEST_F(WebRtcVideoChannel2Test, EstimatesNtpStartTimeCorrectly) { | 2182 TEST_F(WebRtcVideoChannel2Test, EstimatesNtpStartTimeCorrectly) { |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2909 webrtc::VideoSendStream::Stats stats; | 2911 webrtc::VideoSendStream::Stats stats; |
2910 stats.preferred_media_bitrate_bps = 5; | 2912 stats.preferred_media_bitrate_bps = 5; |
2911 stream->SetStats(stats); | 2913 stream->SetStats(stats); |
2912 | 2914 |
2913 cricket::VideoMediaInfo info; | 2915 cricket::VideoMediaInfo info; |
2914 ASSERT_TRUE(channel_->GetStats(&info)); | 2916 ASSERT_TRUE(channel_->GetStats(&info)); |
2915 ASSERT_EQ(1u, info.senders.size()); | 2917 ASSERT_EQ(1u, info.senders.size()); |
2916 EXPECT_EQ(5, info.senders[0].preferred_bitrate); | 2918 EXPECT_EQ(5, info.senders[0].preferred_bitrate); |
2917 } | 2919 } |
2918 | 2920 |
2919 TEST_F(WebRtcVideoChannel2Test, GetStatsTracksAdaptationStats) { | 2921 TEST_F(WebRtcVideoChannel2Test, GetStatsReportsCpuAdaptationStats) { |
2920 AddSendStream(cricket::CreateSimStreamParams("cname", MAKE_VECTOR(kSsrcs3))); | 2922 FakeVideoSendStream* stream = AddSendStream(); |
| 2923 webrtc::VideoSendStream::Stats stats; |
| 2924 stats.number_of_cpu_adapt_changes = 2; |
| 2925 stats.cpu_limited_resolution = true; |
| 2926 stream->SetStats(stats); |
2921 | 2927 |
2922 // Capture format VGA. | |
2923 cricket::FakeVideoCapturer video_capturer_vga; | |
2924 const std::vector<cricket::VideoFormat>* formats = | |
2925 video_capturer_vga.GetSupportedFormats(); | |
2926 cricket::VideoFormat capture_format_vga = (*formats)[1]; | |
2927 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_vga.Start(capture_format_vga)); | |
2928 EXPECT_TRUE( | |
2929 channel_->SetVideoSend(kSsrcs3[0], true, nullptr, &video_capturer_vga)); | |
2930 EXPECT_TRUE(video_capturer_vga.CaptureFrame()); | |
2931 | |
2932 cricket::VideoCodec send_codec(100, "VP8"); | |
2933 cricket::VideoSendParameters parameters; | |
2934 parameters.codecs.push_back(send_codec); | |
2935 EXPECT_TRUE(channel_->SetSendParameters(parameters)); | |
2936 EXPECT_TRUE(channel_->SetSend(true)); | |
2937 | |
2938 // Verify that the CpuOveruseObserver is registered and trigger downgrade. | |
2939 | |
2940 // Trigger overuse. | |
2941 ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); | |
2942 webrtc::LoadObserver* overuse_callback = | |
2943 fake_call_->GetVideoSendStreams().front()->GetConfig().overuse_callback; | |
2944 ASSERT_TRUE(overuse_callback != NULL); | |
2945 overuse_callback->OnLoadUpdate(webrtc::LoadObserver::kOveruse); | |
2946 | |
2947 // Capture format VGA -> adapt (OnCpuResolutionRequest downgrade) -> VGA/2. | |
2948 EXPECT_TRUE(video_capturer_vga.CaptureFrame()); | |
2949 cricket::VideoMediaInfo info; | |
2950 EXPECT_TRUE(channel_->GetStats(&info)); | |
2951 ASSERT_EQ(1U, info.senders.size()); | |
2952 EXPECT_EQ(1, info.senders[0].adapt_changes); | |
2953 EXPECT_EQ(WebRtcVideoChannel2::ADAPTREASON_CPU, info.senders[0].adapt_reason); | |
2954 | |
2955 // Trigger upgrade and verify that we adapt back up to VGA. | |
2956 overuse_callback->OnLoadUpdate(webrtc::LoadObserver::kUnderuse); | |
2957 EXPECT_TRUE(video_capturer_vga.CaptureFrame()); | |
2958 info.Clear(); | |
2959 EXPECT_TRUE(channel_->GetStats(&info)); | |
2960 ASSERT_EQ(1U, info.senders.size()); | |
2961 EXPECT_EQ(2, info.senders[0].adapt_changes); | |
2962 EXPECT_EQ(WebRtcVideoChannel2::ADAPTREASON_NONE, | |
2963 info.senders[0].adapt_reason); | |
2964 | |
2965 // No capturer (no adapter). Adapt changes from old adapter should be kept. | |
2966 EXPECT_TRUE(channel_->SetVideoSend(kSsrcs3[0], true, nullptr, nullptr)); | |
2967 info.Clear(); | |
2968 EXPECT_TRUE(channel_->GetStats(&info)); | |
2969 ASSERT_EQ(1U, info.senders.size()); | |
2970 EXPECT_EQ(2, info.senders[0].adapt_changes); | |
2971 EXPECT_EQ(WebRtcVideoChannel2::ADAPTREASON_NONE, | |
2972 info.senders[0].adapt_reason); | |
2973 | |
2974 // Set new capturer, capture format HD. | |
2975 cricket::FakeVideoCapturer video_capturer_hd; | |
2976 cricket::VideoFormat capture_format_hd = (*formats)[0]; | |
2977 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_hd.Start(capture_format_hd)); | |
2978 EXPECT_TRUE( | |
2979 channel_->SetVideoSend(kSsrcs3[0], true, nullptr, &video_capturer_hd)); | |
2980 EXPECT_TRUE(video_capturer_hd.CaptureFrame()); | |
2981 | |
2982 // Trigger overuse, HD -> adapt (OnCpuResolutionRequest downgrade) -> HD/2. | |
2983 overuse_callback->OnLoadUpdate(webrtc::LoadObserver::kOveruse); | |
2984 EXPECT_TRUE(video_capturer_hd.CaptureFrame()); | |
2985 info.Clear(); | |
2986 EXPECT_TRUE(channel_->GetStats(&info)); | |
2987 ASSERT_EQ(1U, info.senders.size()); | |
2988 EXPECT_EQ(3, info.senders[0].adapt_changes); | |
2989 EXPECT_EQ(WebRtcVideoChannel2::ADAPTREASON_CPU, info.senders[0].adapt_reason); | |
2990 | |
2991 EXPECT_TRUE(channel_->SetVideoSend(kSsrcs3[0], true, nullptr, nullptr)); | |
2992 } | |
2993 | |
2994 TEST_F(WebRtcVideoChannel2Test, GetStatsTracksAdaptationAndBandwidthStats) { | |
2995 AddSendStream(cricket::CreateSimStreamParams("cname", MAKE_VECTOR(kSsrcs3))); | |
2996 | |
2997 // Capture format VGA. | |
2998 cricket::FakeVideoCapturer video_capturer_vga; | |
2999 const std::vector<cricket::VideoFormat>* formats = | |
3000 video_capturer_vga.GetSupportedFormats(); | |
3001 cricket::VideoFormat capture_format_vga = (*formats)[1]; | |
3002 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_vga.Start(capture_format_vga)); | |
3003 EXPECT_TRUE( | |
3004 channel_->SetVideoSend(kSsrcs3[0], true, nullptr, &video_capturer_vga)); | |
3005 EXPECT_TRUE(video_capturer_vga.CaptureFrame()); | |
3006 | |
3007 cricket::VideoCodec send_codec(100, "VP8"); | |
3008 cricket::VideoSendParameters parameters; | |
3009 parameters.codecs.push_back(send_codec); | |
3010 EXPECT_TRUE(channel_->SetSendParameters(parameters)); | |
3011 EXPECT_TRUE(channel_->SetSend(true)); | |
3012 | |
3013 // Verify that the CpuOveruseObserver is registered and trigger downgrade. | |
3014 | |
3015 // Trigger overuse -> adapt CPU. | |
3016 ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); | |
3017 webrtc::LoadObserver* overuse_callback = | |
3018 fake_call_->GetVideoSendStreams().front()->GetConfig().overuse_callback; | |
3019 ASSERT_TRUE(overuse_callback != NULL); | |
3020 overuse_callback->OnLoadUpdate(webrtc::LoadObserver::kOveruse); | |
3021 EXPECT_TRUE(video_capturer_vga.CaptureFrame()); | |
3022 cricket::VideoMediaInfo info; | 2928 cricket::VideoMediaInfo info; |
3023 EXPECT_TRUE(channel_->GetStats(&info)); | 2929 EXPECT_TRUE(channel_->GetStats(&info)); |
3024 ASSERT_EQ(1U, info.senders.size()); | 2930 ASSERT_EQ(1U, info.senders.size()); |
3025 EXPECT_EQ(WebRtcVideoChannel2::ADAPTREASON_CPU, info.senders[0].adapt_reason); | 2931 EXPECT_EQ(WebRtcVideoChannel2::ADAPTREASON_CPU, info.senders[0].adapt_reason); |
| 2932 EXPECT_EQ(stats.number_of_cpu_adapt_changes, info.senders[0].adapt_changes); |
| 2933 } |
3026 | 2934 |
3027 // Set bandwidth limitation stats for the stream -> adapt CPU + BW. | 2935 TEST_F(WebRtcVideoChannel2Test, GetStatsReportsAdaptationAndBandwidthStats) { |
| 2936 FakeVideoSendStream* stream = AddSendStream(); |
3028 webrtc::VideoSendStream::Stats stats; | 2937 webrtc::VideoSendStream::Stats stats; |
| 2938 stats.number_of_cpu_adapt_changes = 2; |
| 2939 stats.cpu_limited_resolution = true; |
3029 stats.bw_limited_resolution = true; | 2940 stats.bw_limited_resolution = true; |
3030 fake_call_->GetVideoSendStreams().front()->SetStats(stats); | 2941 stream->SetStats(stats); |
3031 info.Clear(); | 2942 |
| 2943 cricket::VideoMediaInfo info; |
3032 EXPECT_TRUE(channel_->GetStats(&info)); | 2944 EXPECT_TRUE(channel_->GetStats(&info)); |
3033 ASSERT_EQ(1U, info.senders.size()); | 2945 ASSERT_EQ(1U, info.senders.size()); |
3034 EXPECT_EQ(WebRtcVideoChannel2::ADAPTREASON_CPU | | 2946 EXPECT_EQ(WebRtcVideoChannel2::ADAPTREASON_CPU | |
3035 WebRtcVideoChannel2::ADAPTREASON_BANDWIDTH, | 2947 WebRtcVideoChannel2::ADAPTREASON_BANDWIDTH, |
3036 info.senders[0].adapt_reason); | 2948 info.senders[0].adapt_reason); |
3037 | 2949 EXPECT_EQ(stats.number_of_cpu_adapt_changes, info.senders[0].adapt_changes); |
3038 // Trigger upgrade -> adapt BW. | |
3039 overuse_callback->OnLoadUpdate(webrtc::LoadObserver::kUnderuse); | |
3040 EXPECT_TRUE(video_capturer_vga.CaptureFrame()); | |
3041 info.Clear(); | |
3042 EXPECT_TRUE(channel_->GetStats(&info)); | |
3043 ASSERT_EQ(1U, info.senders.size()); | |
3044 EXPECT_EQ(WebRtcVideoChannel2::ADAPTREASON_BANDWIDTH, | |
3045 info.senders[0].adapt_reason); | |
3046 | |
3047 // Reset bandwidth limitation state -> adapt NONE. | |
3048 stats.bw_limited_resolution = false; | |
3049 fake_call_->GetVideoSendStreams().front()->SetStats(stats); | |
3050 info.Clear(); | |
3051 EXPECT_TRUE(channel_->GetStats(&info)); | |
3052 ASSERT_EQ(1U, info.senders.size()); | |
3053 EXPECT_EQ(WebRtcVideoChannel2::ADAPTREASON_NONE, | |
3054 info.senders[0].adapt_reason); | |
3055 | |
3056 EXPECT_TRUE(channel_->SetVideoSend(kSsrcs3[0], true, nullptr, nullptr)); | |
3057 } | 2950 } |
3058 | 2951 |
3059 TEST_F(WebRtcVideoChannel2Test, | 2952 TEST_F(WebRtcVideoChannel2Test, |
3060 GetStatsTranslatesBandwidthLimitedResolutionCorrectly) { | 2953 GetStatsTranslatesBandwidthLimitedResolutionCorrectly) { |
3061 FakeVideoSendStream* stream = AddSendStream(); | 2954 FakeVideoSendStream* stream = AddSendStream(); |
3062 webrtc::VideoSendStream::Stats stats; | 2955 webrtc::VideoSendStream::Stats stats; |
3063 stats.bw_limited_resolution = true; | 2956 stats.bw_limited_resolution = true; |
3064 stream->SetStats(stats); | 2957 stream->SetStats(stats); |
3065 | 2958 |
3066 cricket::VideoMediaInfo info; | 2959 cricket::VideoMediaInfo info; |
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3850 TEST_F(WebRtcVideoChannel2SimulcastTest, SetSendCodecsWith3SimulcastStreams) { | 3743 TEST_F(WebRtcVideoChannel2SimulcastTest, SetSendCodecsWith3SimulcastStreams) { |
3851 VerifySimulcastSettings(kVp8Codec, 1280, 720, 3, 3); | 3744 VerifySimulcastSettings(kVp8Codec, 1280, 720, 3, 3); |
3852 } | 3745 } |
3853 | 3746 |
3854 // Test that we normalize send codec format size in simulcast. | 3747 // Test that we normalize send codec format size in simulcast. |
3855 TEST_F(WebRtcVideoChannel2SimulcastTest, SetSendCodecsWithOddSizeInSimulcast) { | 3748 TEST_F(WebRtcVideoChannel2SimulcastTest, SetSendCodecsWithOddSizeInSimulcast) { |
3856 cricket::VideoCodec codec(kVp8Codec); | 3749 cricket::VideoCodec codec(kVp8Codec); |
3857 VerifySimulcastSettings(codec, 541, 271, 2, 2); | 3750 VerifySimulcastSettings(codec, 541, 271, 2, 2); |
3858 } | 3751 } |
3859 } // namespace cricket | 3752 } // namespace cricket |
OLD | NEW |