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 |
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/testutils.h" | 22 #include "webrtc/media/base/testutils.h" |
24 #include "webrtc/media/base/videoengine_unittest.h" | 23 #include "webrtc/media/base/videoengine_unittest.h" |
25 #include "webrtc/media/engine/constants.h" | 24 #include "webrtc/media/engine/constants.h" |
26 #include "webrtc/media/engine/fakewebrtccall.h" | 25 #include "webrtc/media/engine/fakewebrtccall.h" |
27 #include "webrtc/media/engine/fakewebrtcvideoengine.h" | 26 #include "webrtc/media/engine/fakewebrtcvideoengine.h" |
28 #include "webrtc/media/engine/simulcast.h" | 27 #include "webrtc/media/engine/simulcast.h" |
29 #include "webrtc/media/engine/webrtcvideoengine2.h" | 28 #include "webrtc/media/engine/webrtcvideoengine2.h" |
30 #include "webrtc/media/engine/webrtcvoiceengine.h" | 29 #include "webrtc/media/engine/webrtcvoiceengine.h" |
31 #include "webrtc/test/field_trial.h" | 30 #include "webrtc/test/field_trial.h" |
| 31 #include "webrtc/test/gtest.h" |
32 #include "webrtc/video_encoder.h" | 32 #include "webrtc/video_encoder.h" |
33 | 33 |
34 using webrtc::RtpExtension; | 34 using webrtc::RtpExtension; |
35 | 35 |
36 namespace { | 36 namespace { |
37 static const int kDefaultQpMax = 56; | 37 static const int kDefaultQpMax = 56; |
38 | 38 |
39 static const uint8_t kRedRtxPayloadType = 125; | 39 static const uint8_t kRedRtxPayloadType = 125; |
40 | 40 |
41 static const uint32_t kSsrcs1[] = {1}; | 41 static const uint32_t kSsrcs1[] = {1}; |
(...skipping 2051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2093 ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); | 2093 ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
2094 FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); | 2094 FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
2095 | 2095 |
2096 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); | 2096 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); |
2097 EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); | 2097 EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
2098 EXPECT_EQ(1280, send_stream->GetLastWidth()); | 2098 EXPECT_EQ(1280, send_stream->GetLastWidth()); |
2099 EXPECT_EQ(720, send_stream->GetLastHeight()); | 2099 EXPECT_EQ(720, send_stream->GetLastHeight()); |
2100 | 2100 |
2101 // Trigger overuse. | 2101 // Trigger overuse. |
2102 rtc::VideoSinkWants wants; | 2102 rtc::VideoSinkWants wants; |
2103 wants.max_pixel_count = rtc::Optional<int>( | 2103 wants.pixel_count.emplace(rtc::VideoSinkWants::ValueRange( |
2104 send_stream->GetLastWidth() * send_stream->GetLastHeight() - 1); | 2104 0, (send_stream->GetLastWidth() * send_stream->GetLastHeight() * 3) / 5, |
| 2105 send_stream->GetLastWidth() * send_stream->GetLastHeight() - 1)); |
2105 send_stream->InjectVideoSinkWants(wants); | 2106 send_stream->InjectVideoSinkWants(wants); |
2106 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); | 2107 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); |
2107 EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames()); | 2108 EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames()); |
2108 EXPECT_EQ(1280 * 3 / 4, send_stream->GetLastWidth()); | 2109 EXPECT_EQ(1280 * 3 / 4, send_stream->GetLastWidth()); |
2109 EXPECT_EQ(720 * 3 / 4, send_stream->GetLastHeight()); | 2110 EXPECT_EQ(720 * 3 / 4, send_stream->GetLastHeight()); |
2110 | 2111 |
2111 // Trigger overuse again. | 2112 // Trigger overuse again. |
2112 wants.max_pixel_count = rtc::Optional<int>( | 2113 wants.pixel_count.emplace(rtc::VideoSinkWants::ValueRange( |
2113 send_stream->GetLastWidth() * send_stream->GetLastHeight() - 1); | 2114 0, (send_stream->GetLastWidth() * send_stream->GetLastHeight() * 3) / 5, |
| 2115 send_stream->GetLastWidth() * send_stream->GetLastHeight() - 1)); |
2114 send_stream->InjectVideoSinkWants(wants); | 2116 send_stream->InjectVideoSinkWants(wants); |
2115 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); | 2117 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); |
2116 EXPECT_EQ(3, send_stream->GetNumberOfSwappedFrames()); | 2118 EXPECT_EQ(3, send_stream->GetNumberOfSwappedFrames()); |
2117 EXPECT_EQ(1280 * 2 / 4, send_stream->GetLastWidth()); | 2119 EXPECT_EQ(1280 * 2 / 4, send_stream->GetLastWidth()); |
2118 EXPECT_EQ(720 * 2 / 4, send_stream->GetLastHeight()); | 2120 EXPECT_EQ(720 * 2 / 4, send_stream->GetLastHeight()); |
2119 | 2121 |
2120 // Change input resolution. | 2122 // Change input resolution. |
2121 EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724, cricket::FOURCC_I420)); | 2123 EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724, cricket::FOURCC_I420)); |
2122 EXPECT_EQ(4, send_stream->GetNumberOfSwappedFrames()); | 2124 EXPECT_EQ(4, send_stream->GetNumberOfSwappedFrames()); |
2123 EXPECT_EQ(1284 / 2, send_stream->GetLastWidth()); | 2125 EXPECT_EQ(1284 / 2, send_stream->GetLastWidth()); |
2124 EXPECT_EQ(724 / 2, send_stream->GetLastHeight()); | 2126 EXPECT_EQ(724 / 2, send_stream->GetLastHeight()); |
2125 | 2127 |
2126 // Trigger underuse which should go back up in resolution. | 2128 // Trigger underuse which should go back up in resolution. |
2127 int current_pixel_count = | 2129 int current_pixel_count = |
2128 send_stream->GetLastWidth() * send_stream->GetLastHeight(); | 2130 send_stream->GetLastWidth() * send_stream->GetLastHeight(); |
2129 // Cap the max to 4x the pixel count (assuming max 1/2 x 1/2 scale downs) | 2131 // Cap the max to 4x the pixel count (assuming max 1/2 x 1/2 scale downs) |
2130 // of the current stream, so we don't take too large steps. | 2132 // of the current stream, so we don't take too large steps. |
2131 wants.max_pixel_count = rtc::Optional<int>(current_pixel_count * 4); | |
2132 // Default step down is 3/5 pixel count, so go up by 5/3. | 2133 // Default step down is 3/5 pixel count, so go up by 5/3. |
2133 wants.target_pixel_count = rtc::Optional<int>((current_pixel_count * 5) / 3); | 2134 wants.pixel_count.emplace(rtc::VideoSinkWants::ValueRange( |
| 2135 0, (current_pixel_count * 5) / 3, current_pixel_count * 4)); |
2134 send_stream->InjectVideoSinkWants(wants); | 2136 send_stream->InjectVideoSinkWants(wants); |
2135 EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724, cricket::FOURCC_I420)); | 2137 EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724, cricket::FOURCC_I420)); |
2136 EXPECT_EQ(5, send_stream->GetNumberOfSwappedFrames()); | 2138 EXPECT_EQ(5, send_stream->GetNumberOfSwappedFrames()); |
2137 EXPECT_EQ(1284 * 3 / 4, send_stream->GetLastWidth()); | 2139 EXPECT_EQ(1284 * 3 / 4, send_stream->GetLastWidth()); |
2138 EXPECT_EQ(724 * 3 / 4, send_stream->GetLastHeight()); | 2140 EXPECT_EQ(724 * 3 / 4, send_stream->GetLastHeight()); |
2139 | 2141 |
2140 // Trigger underuse again, should go back up to full resolution. | 2142 // Trigger underuse again, should go back up to full resolution. |
2141 current_pixel_count = | 2143 current_pixel_count = |
2142 send_stream->GetLastWidth() * send_stream->GetLastHeight(); | 2144 send_stream->GetLastWidth() * send_stream->GetLastHeight(); |
2143 wants.max_pixel_count = rtc::Optional<int>(current_pixel_count * 4); | 2145 wants.pixel_count.emplace(rtc::VideoSinkWants::ValueRange( |
2144 wants.target_pixel_count = rtc::Optional<int>((current_pixel_count * 5) / 3); | 2146 0, (current_pixel_count * 5) / 3, current_pixel_count * 4)); |
2145 send_stream->InjectVideoSinkWants(wants); | 2147 send_stream->InjectVideoSinkWants(wants); |
2146 EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724, cricket::FOURCC_I420)); | 2148 EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724, cricket::FOURCC_I420)); |
2147 EXPECT_EQ(6, send_stream->GetNumberOfSwappedFrames()); | 2149 EXPECT_EQ(6, send_stream->GetNumberOfSwappedFrames()); |
2148 EXPECT_EQ(1284, send_stream->GetLastWidth()); | 2150 EXPECT_EQ(1284, send_stream->GetLastWidth()); |
2149 EXPECT_EQ(724, send_stream->GetLastHeight()); | 2151 EXPECT_EQ(724, send_stream->GetLastHeight()); |
2150 | 2152 |
2151 EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); | 2153 EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); |
2152 } | 2154 } |
2153 | 2155 |
2154 TEST_F(WebRtcVideoChannel2Test, PreviousAdaptationDoesNotApplyToScreenshare) { | 2156 TEST_F(WebRtcVideoChannel2Test, PreviousAdaptationDoesNotApplyToScreenshare) { |
(...skipping 22 matching lines...) Expand all Loading... |
2177 ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); | 2179 ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
2178 FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); | 2180 FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
2179 | 2181 |
2180 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); | 2182 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); |
2181 EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); | 2183 EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
2182 EXPECT_EQ(1280, send_stream->GetLastWidth()); | 2184 EXPECT_EQ(1280, send_stream->GetLastWidth()); |
2183 EXPECT_EQ(720, send_stream->GetLastHeight()); | 2185 EXPECT_EQ(720, send_stream->GetLastHeight()); |
2184 | 2186 |
2185 // Trigger overuse. | 2187 // Trigger overuse. |
2186 rtc::VideoSinkWants wants; | 2188 rtc::VideoSinkWants wants; |
2187 wants.max_pixel_count = rtc::Optional<int>( | 2189 wants.pixel_count.emplace(rtc::VideoSinkWants::ValueRange( |
2188 send_stream->GetLastWidth() * send_stream->GetLastHeight() - 1); | 2190 0, (send_stream->GetLastWidth() * send_stream->GetLastHeight() * 3) / 5, |
| 2191 send_stream->GetLastWidth() * send_stream->GetLastHeight() - 1)); |
2189 send_stream->InjectVideoSinkWants(wants); | 2192 send_stream->InjectVideoSinkWants(wants); |
2190 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); | 2193 EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); |
2191 EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames()); | 2194 EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames()); |
2192 EXPECT_EQ(1280 * 3 / 4, send_stream->GetLastWidth()); | 2195 EXPECT_EQ(1280 * 3 / 4, send_stream->GetLastWidth()); |
2193 EXPECT_EQ(720 * 3 / 4, send_stream->GetLastHeight()); | 2196 EXPECT_EQ(720 * 3 / 4, send_stream->GetLastHeight()); |
2194 | 2197 |
2195 // Switch to screen share. Expect no CPU adaptation. | 2198 // Switch to screen share. Expect no CPU adaptation. |
2196 cricket::FakeVideoCapturer screen_share(true); | 2199 cricket::FakeVideoCapturer screen_share(true); |
2197 ASSERT_EQ(cricket::CS_RUNNING, | 2200 ASSERT_EQ(cricket::CS_RUNNING, |
2198 screen_share.Start(screen_share.GetSupportedFormats()->front())); | 2201 screen_share.Start(screen_share.GetSupportedFormats()->front())); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2256 | 2259 |
2257 EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); | 2260 EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); |
2258 return; | 2261 return; |
2259 } | 2262 } |
2260 | 2263 |
2261 EXPECT_TRUE(send_stream->resolution_scaling_enabled()); | 2264 EXPECT_TRUE(send_stream->resolution_scaling_enabled()); |
2262 // Trigger overuse. | 2265 // Trigger overuse. |
2263 ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); | 2266 ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
2264 | 2267 |
2265 rtc::VideoSinkWants wants; | 2268 rtc::VideoSinkWants wants; |
2266 wants.max_pixel_count = | 2269 wants.pixel_count.emplace(rtc::VideoSinkWants::ValueRange( |
2267 rtc::Optional<int>(capture_format.width * capture_format.height - 1); | 2270 0, (capture_format.width * capture_format.height * 3) / 5, |
| 2271 capture_format.width * capture_format.height - 1)); |
2268 send_stream->InjectVideoSinkWants(wants); | 2272 send_stream->InjectVideoSinkWants(wants); |
2269 | 2273 |
2270 EXPECT_TRUE(capturer.CaptureFrame()); | 2274 EXPECT_TRUE(capturer.CaptureFrame()); |
2271 EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); | 2275 EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
2272 | 2276 |
2273 EXPECT_TRUE(capturer.CaptureFrame()); | 2277 EXPECT_TRUE(capturer.CaptureFrame()); |
2274 EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames()); | 2278 EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames()); |
2275 | 2279 |
2276 EXPECT_LT(send_stream->GetLastWidth(), capture_format.width); | 2280 EXPECT_LT(send_stream->GetLastWidth(), capture_format.width); |
2277 EXPECT_LT(send_stream->GetLastHeight(), capture_format.height); | 2281 EXPECT_LT(send_stream->GetLastHeight(), capture_format.height); |
2278 | 2282 |
2279 // Trigger underuse which should go back to normal resolution. | 2283 // Trigger underuse which should go back to normal resolution. |
2280 int last_pixel_count = | 2284 int last_pixel_count = |
2281 send_stream->GetLastWidth() * send_stream->GetLastHeight(); | 2285 send_stream->GetLastWidth() * send_stream->GetLastHeight(); |
2282 wants.max_pixel_count = rtc::Optional<int>(last_pixel_count * 4); | 2286 wants.pixel_count.emplace(rtc::VideoSinkWants::ValueRange( |
2283 wants.target_pixel_count = rtc::Optional<int>((last_pixel_count * 5) / 3); | 2287 0, (last_pixel_count * 5) / 3, last_pixel_count * 4)); |
2284 send_stream->InjectVideoSinkWants(wants); | 2288 send_stream->InjectVideoSinkWants(wants); |
2285 | 2289 |
2286 EXPECT_TRUE(capturer.CaptureFrame()); | 2290 EXPECT_TRUE(capturer.CaptureFrame()); |
2287 EXPECT_EQ(3, send_stream->GetNumberOfSwappedFrames()); | 2291 EXPECT_EQ(3, send_stream->GetNumberOfSwappedFrames()); |
2288 | 2292 |
2289 EXPECT_EQ(capture_format.width, send_stream->GetLastWidth()); | 2293 EXPECT_EQ(capture_format.width, send_stream->GetLastWidth()); |
2290 EXPECT_EQ(capture_format.height, send_stream->GetLastHeight()); | 2294 EXPECT_EQ(capture_format.height, send_stream->GetLastHeight()); |
2291 | 2295 |
2292 EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); | 2296 EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); |
2293 } | 2297 } |
(...skipping 1961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4255 } | 4259 } |
4256 | 4260 |
4257 TEST_F(WebRtcVideoChannel2SimulcastTest, SetSendCodecsForSimulcastScreenshare) { | 4261 TEST_F(WebRtcVideoChannel2SimulcastTest, SetSendCodecsForSimulcastScreenshare) { |
4258 webrtc::test::ScopedFieldTrials override_field_trials_( | 4262 webrtc::test::ScopedFieldTrials override_field_trials_( |
4259 "WebRTC-SimulcastScreenshare/Enabled/"); | 4263 "WebRTC-SimulcastScreenshare/Enabled/"); |
4260 VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 2, true, | 4264 VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 2, true, |
4261 true); | 4265 true); |
4262 } | 4266 } |
4263 | 4267 |
4264 } // namespace cricket | 4268 } // namespace cricket |
OLD | NEW |