Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: webrtc/media/engine/webrtcvideoengine2_unittest.cc

Issue 2698203003: Update sink wants with ranges for both pixel count and frame rate.
Patch Set: Slightly updated sink wants merging in videobroadcaster Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #include <algorithm> 11 #include <algorithm>
12 #include <map> 12 #include <map>
13 #include <memory> 13 #include <memory>
14 #include <vector> 14 #include <vector>
15 15
16 #include "webrtc/base/arraysize.h" 16 #include "webrtc/base/arraysize.h"
17 #include "webrtc/base/gunit.h"
18 #include "webrtc/base/stringutils.h" 17 #include "webrtc/base/stringutils.h"
19 #include "webrtc/call/flexfec_receive_stream.h" 18 #include "webrtc/call/flexfec_receive_stream.h"
20 #include "webrtc/common_video/h264/profile_level_id.h" 19 #include "webrtc/common_video/h264/profile_level_id.h"
21 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" 20 #include "webrtc/logging/rtc_event_log/rtc_event_log.h"
22 #include "webrtc/media/base/mediaconstants.h" 21 #include "webrtc/media/base/mediaconstants.h"
23 #include "webrtc/media/base/rtputils.h" 22 #include "webrtc/media/base/rtputils.h"
24 #include "webrtc/media/base/testutils.h" 23 #include "webrtc/media/base/testutils.h"
25 #include "webrtc/media/base/videoengine_unittest.h" 24 #include "webrtc/media/base/videoengine_unittest.h"
26 #include "webrtc/media/engine/constants.h" 25 #include "webrtc/media/engine/constants.h"
27 #include "webrtc/media/engine/fakewebrtccall.h" 26 #include "webrtc/media/engine/fakewebrtccall.h"
28 #include "webrtc/media/engine/fakewebrtcvideoengine.h" 27 #include "webrtc/media/engine/fakewebrtcvideoengine.h"
29 #include "webrtc/media/engine/simulcast.h" 28 #include "webrtc/media/engine/simulcast.h"
30 #include "webrtc/media/engine/webrtcvideoengine2.h" 29 #include "webrtc/media/engine/webrtcvideoengine2.h"
31 #include "webrtc/media/engine/webrtcvoiceengine.h" 30 #include "webrtc/media/engine/webrtcvoiceengine.h"
32 #include "webrtc/test/field_trial.h" 31 #include "webrtc/test/field_trial.h"
32 #include "webrtc/test/gtest.h"
33 #include "webrtc/video_encoder.h" 33 #include "webrtc/video_encoder.h"
34 34
35 using webrtc::RtpExtension; 35 using webrtc::RtpExtension;
36 36
37 namespace { 37 namespace {
38 static const int kDefaultQpMax = 56; 38 static const int kDefaultQpMax = 56;
39 39
40 static const uint8_t kRedRtxPayloadType = 125; 40 static const uint8_t kRedRtxPayloadType = 125;
41 41
42 static const uint32_t kSsrcs1[] = {1}; 42 static const uint32_t kSsrcs1[] = {1};
(...skipping 2053 matching lines...) Expand 10 before | Expand all | Expand 10 after
2096 ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); 2096 ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size());
2097 FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); 2097 FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front();
2098 2098
2099 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); 2099 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420));
2100 EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); 2100 EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames());
2101 EXPECT_EQ(1280, send_stream->GetLastWidth()); 2101 EXPECT_EQ(1280, send_stream->GetLastWidth());
2102 EXPECT_EQ(720, send_stream->GetLastHeight()); 2102 EXPECT_EQ(720, send_stream->GetLastHeight());
2103 2103
2104 // Trigger overuse. 2104 // Trigger overuse.
2105 rtc::VideoSinkWants wants; 2105 rtc::VideoSinkWants wants;
2106 wants.max_pixel_count = rtc::Optional<int>( 2106 wants.pixel_count.emplace(rtc::VideoSinkWants::Range(
2107 send_stream->GetLastWidth() * send_stream->GetLastHeight() - 1); 2107 0, (send_stream->GetLastWidth() * send_stream->GetLastHeight() * 3) / 5,
2108 send_stream->GetLastWidth() * send_stream->GetLastHeight() - 1));
2108 send_stream->InjectVideoSinkWants(wants); 2109 send_stream->InjectVideoSinkWants(wants);
2109 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); 2110 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420));
2110 EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames()); 2111 EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames());
2111 EXPECT_EQ(1280 * 3 / 4, send_stream->GetLastWidth()); 2112 EXPECT_EQ(1280 * 3 / 4, send_stream->GetLastWidth());
2112 EXPECT_EQ(720 * 3 / 4, send_stream->GetLastHeight()); 2113 EXPECT_EQ(720 * 3 / 4, send_stream->GetLastHeight());
2113 2114
2114 // Trigger overuse again. 2115 // Trigger overuse again.
2115 wants.max_pixel_count = rtc::Optional<int>( 2116 wants.pixel_count.emplace(rtc::VideoSinkWants::Range(
2116 send_stream->GetLastWidth() * send_stream->GetLastHeight() - 1); 2117 0, (send_stream->GetLastWidth() * send_stream->GetLastHeight() * 3) / 5,
2118 send_stream->GetLastWidth() * send_stream->GetLastHeight() - 1));
2117 send_stream->InjectVideoSinkWants(wants); 2119 send_stream->InjectVideoSinkWants(wants);
2118 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); 2120 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420));
2119 EXPECT_EQ(3, send_stream->GetNumberOfSwappedFrames()); 2121 EXPECT_EQ(3, send_stream->GetNumberOfSwappedFrames());
2120 EXPECT_EQ(1280 * 2 / 4, send_stream->GetLastWidth()); 2122 EXPECT_EQ(1280 * 2 / 4, send_stream->GetLastWidth());
2121 EXPECT_EQ(720 * 2 / 4, send_stream->GetLastHeight()); 2123 EXPECT_EQ(720 * 2 / 4, send_stream->GetLastHeight());
2122 2124
2123 // Change input resolution. 2125 // Change input resolution.
2124 EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724, cricket::FOURCC_I420)); 2126 EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724, cricket::FOURCC_I420));
2125 EXPECT_EQ(4, send_stream->GetNumberOfSwappedFrames()); 2127 EXPECT_EQ(4, send_stream->GetNumberOfSwappedFrames());
2126 EXPECT_EQ(1284 / 2, send_stream->GetLastWidth()); 2128 EXPECT_EQ(1284 / 2, send_stream->GetLastWidth());
2127 EXPECT_EQ(724 / 2, send_stream->GetLastHeight()); 2129 EXPECT_EQ(724 / 2, send_stream->GetLastHeight());
2128 2130
2129 // Trigger underuse which should go back up in resolution. 2131 // Trigger underuse which should go back up in resolution.
2130 int current_pixel_count = 2132 int current_pixel_count =
2131 send_stream->GetLastWidth() * send_stream->GetLastHeight(); 2133 send_stream->GetLastWidth() * send_stream->GetLastHeight();
2132 // Cap the max to 4x the pixel count (assuming max 1/2 x 1/2 scale downs) 2134 // Cap the max to 4x the pixel count (assuming max 1/2 x 1/2 scale downs)
2133 // of the current stream, so we don't take too large steps. 2135 // of the current stream, so we don't take too large steps.
2134 wants.max_pixel_count = rtc::Optional<int>(current_pixel_count * 4);
2135 // Default step down is 3/5 pixel count, so go up by 5/3. 2136 // Default step down is 3/5 pixel count, so go up by 5/3.
2136 wants.target_pixel_count = rtc::Optional<int>((current_pixel_count * 5) / 3); 2137 wants.pixel_count.emplace(rtc::VideoSinkWants::Range(
2138 0, (current_pixel_count * 5) / 3, current_pixel_count * 4));
2137 send_stream->InjectVideoSinkWants(wants); 2139 send_stream->InjectVideoSinkWants(wants);
2138 EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724, cricket::FOURCC_I420)); 2140 EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724, cricket::FOURCC_I420));
2139 EXPECT_EQ(5, send_stream->GetNumberOfSwappedFrames()); 2141 EXPECT_EQ(5, send_stream->GetNumberOfSwappedFrames());
2140 EXPECT_EQ(1284 * 3 / 4, send_stream->GetLastWidth()); 2142 EXPECT_EQ(1284 * 3 / 4, send_stream->GetLastWidth());
2141 EXPECT_EQ(724 * 3 / 4, send_stream->GetLastHeight()); 2143 EXPECT_EQ(724 * 3 / 4, send_stream->GetLastHeight());
2142 2144
2143 // Trigger underuse again, should go back up to full resolution. 2145 // Trigger underuse again, should go back up to full resolution.
2144 current_pixel_count = 2146 current_pixel_count =
2145 send_stream->GetLastWidth() * send_stream->GetLastHeight(); 2147 send_stream->GetLastWidth() * send_stream->GetLastHeight();
2146 wants.max_pixel_count = rtc::Optional<int>(current_pixel_count * 4); 2148 wants.pixel_count.emplace(rtc::VideoSinkWants::Range(
2147 wants.target_pixel_count = rtc::Optional<int>((current_pixel_count * 5) / 3); 2149 0, (current_pixel_count * 5) / 3, current_pixel_count * 4));
2148 send_stream->InjectVideoSinkWants(wants); 2150 send_stream->InjectVideoSinkWants(wants);
2149 EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724, cricket::FOURCC_I420)); 2151 EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724, cricket::FOURCC_I420));
2150 EXPECT_EQ(6, send_stream->GetNumberOfSwappedFrames()); 2152 EXPECT_EQ(6, send_stream->GetNumberOfSwappedFrames());
2151 EXPECT_EQ(1284, send_stream->GetLastWidth()); 2153 EXPECT_EQ(1284, send_stream->GetLastWidth());
2152 EXPECT_EQ(724, send_stream->GetLastHeight()); 2154 EXPECT_EQ(724, send_stream->GetLastHeight());
2153 2155
2154 EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); 2156 EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr));
2155 } 2157 }
2156 2158
2157 TEST_F(WebRtcVideoChannel2Test, PreviousAdaptationDoesNotApplyToScreenshare) { 2159 TEST_F(WebRtcVideoChannel2Test, PreviousAdaptationDoesNotApplyToScreenshare) {
(...skipping 22 matching lines...) Expand all
2180 ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); 2182 ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size());
2181 FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); 2183 FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front();
2182 2184
2183 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); 2185 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420));
2184 EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); 2186 EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames());
2185 EXPECT_EQ(1280, send_stream->GetLastWidth()); 2187 EXPECT_EQ(1280, send_stream->GetLastWidth());
2186 EXPECT_EQ(720, send_stream->GetLastHeight()); 2188 EXPECT_EQ(720, send_stream->GetLastHeight());
2187 2189
2188 // Trigger overuse. 2190 // Trigger overuse.
2189 rtc::VideoSinkWants wants; 2191 rtc::VideoSinkWants wants;
2190 wants.max_pixel_count = rtc::Optional<int>( 2192 wants.pixel_count.emplace(rtc::VideoSinkWants::Range(
2191 send_stream->GetLastWidth() * send_stream->GetLastHeight() - 1); 2193 0, (send_stream->GetLastWidth() * send_stream->GetLastHeight() * 3) / 5,
2194 send_stream->GetLastWidth() * send_stream->GetLastHeight() - 1));
2192 send_stream->InjectVideoSinkWants(wants); 2195 send_stream->InjectVideoSinkWants(wants);
2193 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); 2196 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420));
2194 EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames()); 2197 EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames());
2195 EXPECT_EQ(1280 * 3 / 4, send_stream->GetLastWidth()); 2198 EXPECT_EQ(1280 * 3 / 4, send_stream->GetLastWidth());
2196 EXPECT_EQ(720 * 3 / 4, send_stream->GetLastHeight()); 2199 EXPECT_EQ(720 * 3 / 4, send_stream->GetLastHeight());
2197 2200
2198 // Switch to screen share. Expect no CPU adaptation. 2201 // Switch to screen share. Expect no CPU adaptation.
2199 cricket::FakeVideoCapturer screen_share(true); 2202 cricket::FakeVideoCapturer screen_share(true);
2200 ASSERT_EQ(cricket::CS_RUNNING, 2203 ASSERT_EQ(cricket::CS_RUNNING,
2201 screen_share.Start(screen_share.GetSupportedFormats()->front())); 2204 screen_share.Start(screen_share.GetSupportedFormats()->front()));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2259 2262
2260 EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); 2263 EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr));
2261 return; 2264 return;
2262 } 2265 }
2263 2266
2264 EXPECT_TRUE(send_stream->resolution_scaling_enabled()); 2267 EXPECT_TRUE(send_stream->resolution_scaling_enabled());
2265 // Trigger overuse. 2268 // Trigger overuse.
2266 ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); 2269 ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size());
2267 2270
2268 rtc::VideoSinkWants wants; 2271 rtc::VideoSinkWants wants;
2269 wants.max_pixel_count = 2272 wants.pixel_count.emplace(rtc::VideoSinkWants::Range(
2270 rtc::Optional<int>(capture_format.width * capture_format.height - 1); 2273 0, (capture_format.width * capture_format.height * 3) / 5,
2274 capture_format.width * capture_format.height - 1));
2271 send_stream->InjectVideoSinkWants(wants); 2275 send_stream->InjectVideoSinkWants(wants);
2272 2276
2273 EXPECT_TRUE(capturer.CaptureFrame()); 2277 EXPECT_TRUE(capturer.CaptureFrame());
2274 EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); 2278 EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames());
2275 2279
2276 EXPECT_TRUE(capturer.CaptureFrame()); 2280 EXPECT_TRUE(capturer.CaptureFrame());
2277 EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames()); 2281 EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames());
2278 2282
2279 EXPECT_LT(send_stream->GetLastWidth(), capture_format.width); 2283 EXPECT_LT(send_stream->GetLastWidth(), capture_format.width);
2280 EXPECT_LT(send_stream->GetLastHeight(), capture_format.height); 2284 EXPECT_LT(send_stream->GetLastHeight(), capture_format.height);
2281 2285
2282 // Trigger underuse which should go back to normal resolution. 2286 // Trigger underuse which should go back to normal resolution.
2283 int last_pixel_count = 2287 int last_pixel_count =
2284 send_stream->GetLastWidth() * send_stream->GetLastHeight(); 2288 send_stream->GetLastWidth() * send_stream->GetLastHeight();
2285 wants.max_pixel_count = rtc::Optional<int>(last_pixel_count * 4); 2289 wants.pixel_count.emplace(rtc::VideoSinkWants::Range(
2286 wants.target_pixel_count = rtc::Optional<int>((last_pixel_count * 5) / 3); 2290 0, (last_pixel_count * 5) / 3, last_pixel_count * 4));
2287 send_stream->InjectVideoSinkWants(wants); 2291 send_stream->InjectVideoSinkWants(wants);
2288 2292
2289 EXPECT_TRUE(capturer.CaptureFrame()); 2293 EXPECT_TRUE(capturer.CaptureFrame());
2290 EXPECT_EQ(3, send_stream->GetNumberOfSwappedFrames()); 2294 EXPECT_EQ(3, send_stream->GetNumberOfSwappedFrames());
2291 2295
2292 EXPECT_EQ(capture_format.width, send_stream->GetLastWidth()); 2296 EXPECT_EQ(capture_format.width, send_stream->GetLastWidth());
2293 EXPECT_EQ(capture_format.height, send_stream->GetLastHeight()); 2297 EXPECT_EQ(capture_format.height, send_stream->GetLastHeight());
2294 2298
2295 EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); 2299 EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr));
2296 } 2300 }
(...skipping 2045 matching lines...) Expand 10 before | Expand all | Expand 10 after
4342 } 4346 }
4343 4347
4344 TEST_F(WebRtcVideoChannel2SimulcastTest, SetSendCodecsForSimulcastScreenshare) { 4348 TEST_F(WebRtcVideoChannel2SimulcastTest, SetSendCodecsForSimulcastScreenshare) {
4345 webrtc::test::ScopedFieldTrials override_field_trials_( 4349 webrtc::test::ScopedFieldTrials override_field_trials_(
4346 "WebRTC-SimulcastScreenshare/Enabled/"); 4350 "WebRTC-SimulcastScreenshare/Enabled/");
4347 VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 2, true, 4351 VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 2, true,
4348 true); 4352 true);
4349 } 4353 }
4350 4354
4351 } // namespace cricket 4355 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698