OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/test/test_video_renderer.h" | 5 #include "remoting/test/test_video_renderer.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <cmath> | 9 #include <cmath> |
10 #include <utility> | 10 #include <utility> |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 int screen_height, | 133 int screen_height, |
134 double error_limit) { | 134 double error_limit) { |
135 DCHECK(encoder_); | 135 DCHECK(encoder_); |
136 DCHECK(test_video_renderer_); | 136 DCHECK(test_video_renderer_); |
137 | 137 |
138 // Generate a frame containing a gradient. | 138 // Generate a frame containing a gradient. |
139 std::unique_ptr<webrtc::DesktopFrame> original_frame = | 139 std::unique_ptr<webrtc::DesktopFrame> original_frame = |
140 CreateDesktopFrameWithGradient(screen_width, screen_height); | 140 CreateDesktopFrameWithGradient(screen_width, screen_height); |
141 EXPECT_TRUE(original_frame); | 141 EXPECT_TRUE(original_frame); |
142 | 142 |
143 std::unique_ptr<VideoPacket> packet = | 143 std::unique_ptr<VideoPacket> packet = encoder_->Encode(*original_frame.get()); |
144 encoder_->Encode(*original_frame.get(), 0); | |
145 | 144 |
146 DCHECK(!run_loop_ || !run_loop_->running()); | 145 DCHECK(!run_loop_ || !run_loop_->running()); |
147 DCHECK(!timer_->IsRunning()); | 146 DCHECK(!timer_->IsRunning()); |
148 run_loop_.reset(new base::RunLoop()); | 147 run_loop_.reset(new base::RunLoop()); |
149 | 148 |
150 // Set an extremely long time: 10 min to prevent bugs from hanging the system. | 149 // Set an extremely long time: 10 min to prevent bugs from hanging the system. |
151 // NOTE: We've seen cases which take up to 1 min to process a packet, so an | 150 // NOTE: We've seen cases which take up to 1 min to process a packet, so an |
152 // extremely long time as 10 min is chosen to avoid being variable/flaky. | 151 // extremely long time as 10 min is chosen to avoid being variable/flaky. |
153 timer_->Start(FROM_HERE, base::TimeDelta::FromMinutes(10), | 152 timer_->Start(FROM_HERE, base::TimeDelta::FromMinutes(10), |
154 run_loop_->QuitClosure()); | 153 run_loop_->QuitClosure()); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 int screen_height, | 225 int screen_height, |
227 const webrtc::DesktopRect& expected_rect, | 226 const webrtc::DesktopRect& expected_rect, |
228 bool expect_to_match) { | 227 bool expect_to_match) { |
229 DCHECK(encoder_); | 228 DCHECK(encoder_); |
230 DCHECK(test_video_renderer_); | 229 DCHECK(test_video_renderer_); |
231 | 230 |
232 std::unique_ptr<webrtc::DesktopFrame> frame = | 231 std::unique_ptr<webrtc::DesktopFrame> frame = |
233 CreateDesktopFrameWithGradient(screen_width, screen_height); | 232 CreateDesktopFrameWithGradient(screen_width, screen_height); |
234 RGBValue expected_average_color = | 233 RGBValue expected_average_color = |
235 CalculateAverageColorValueForFrame(frame.get(), expected_rect); | 234 CalculateAverageColorValueForFrame(frame.get(), expected_rect); |
236 std::unique_ptr<VideoPacket> packet = encoder_->Encode(*frame.get(), 0); | 235 std::unique_ptr<VideoPacket> packet = encoder_->Encode(*frame.get()); |
237 | 236 |
238 if (expect_to_match) { | 237 if (expect_to_match) { |
239 EXPECT_TRUE(SendPacketAndWaitForMatch(std::move(packet), expected_rect, | 238 EXPECT_TRUE(SendPacketAndWaitForMatch(std::move(packet), expected_rect, |
240 expected_average_color)); | 239 expected_average_color)); |
241 } else { | 240 } else { |
242 // Shift each channel by 128. | 241 // Shift each channel by 128. |
243 // e.g. (10, 127, 200) -> (138, 255, 73). | 242 // e.g. (10, 127, 200) -> (138, 255, 73). |
244 // In this way, the error between expected color and true value is always | 243 // In this way, the error between expected color and true value is always |
245 // around 0.5. | 244 // around 0.5. |
246 int red_shift = (expected_average_color.red + 128) % 255; | 245 int red_shift = (expected_average_color.red + 128) % 255; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 // Post multiple tasks to |test_video_renderer_|, and it should not crash. | 397 // Post multiple tasks to |test_video_renderer_|, and it should not crash. |
399 // 20 is chosen because it's large enough to make sure that there will be | 398 // 20 is chosen because it's large enough to make sure that there will be |
400 // more than one task on the video decode thread, while not too large to wait | 399 // more than one task on the video decode thread, while not too large to wait |
401 // for too long for the unit test to complete. | 400 // for too long for the unit test to complete. |
402 const int task_num = 20; | 401 const int task_num = 20; |
403 ScopedVector<VideoPacket> video_packets; | 402 ScopedVector<VideoPacket> video_packets; |
404 for (int i = 0; i < task_num; ++i) { | 403 for (int i = 0; i < task_num; ++i) { |
405 std::unique_ptr<webrtc::DesktopFrame> original_frame = | 404 std::unique_ptr<webrtc::DesktopFrame> original_frame = |
406 CreateDesktopFrameWithGradient(kDefaultScreenWidthPx, | 405 CreateDesktopFrameWithGradient(kDefaultScreenWidthPx, |
407 kDefaultScreenHeightPx); | 406 kDefaultScreenHeightPx); |
408 video_packets.push_back(encoder_->Encode(*original_frame.get(), 0)); | 407 video_packets.push_back(encoder_->Encode(*original_frame.get())); |
409 } | 408 } |
410 | 409 |
411 for (int i = 0; i < task_num; ++i) { | 410 for (int i = 0; i < task_num; ++i) { |
412 // Transfer ownership of video packet. | 411 // Transfer ownership of video packet. |
413 VideoPacket* packet = video_packets[i]; | 412 VideoPacket* packet = video_packets[i]; |
414 video_packets[i] = nullptr; | 413 video_packets[i] = nullptr; |
415 test_video_renderer_->ProcessVideoPacket(base::WrapUnique(packet), | 414 test_video_renderer_->ProcessVideoPacket(base::WrapUnique(packet), |
416 base::Bind(&base::DoNothing)); | 415 base::Bind(&base::DoNothing)); |
417 } | 416 } |
418 } | 417 } |
(...skipping 28 matching lines...) Expand all Loading... |
447 | 446 |
448 // Since we don't care whether expected image pattern is matched or not in | 447 // Since we don't care whether expected image pattern is matched or not in |
449 // this case, an expected color is chosen arbitrarily. | 448 // this case, an expected color is chosen arbitrarily. |
450 RGBValue black_color = RGBValue(); | 449 RGBValue black_color = RGBValue(); |
451 | 450 |
452 // Set expected image pattern. | 451 // Set expected image pattern. |
453 test_video_renderer_->ExpectAverageColorInRect( | 452 test_video_renderer_->ExpectAverageColorInRect( |
454 kDefaultExpectedRect, black_color, base::Bind(&base::DoNothing)); | 453 kDefaultExpectedRect, black_color, base::Bind(&base::DoNothing)); |
455 | 454 |
456 // Post test video packet. | 455 // Post test video packet. |
457 test_video_renderer_->ProcessVideoPacket(encoder_->Encode(*frame.get(), 0), | 456 test_video_renderer_->ProcessVideoPacket(encoder_->Encode(*frame.get()), |
458 base::Bind(&base::DoNothing)); | 457 base::Bind(&base::DoNothing)); |
459 } | 458 } |
460 | 459 |
461 // Verify correct image pattern can be matched for VP8. | 460 // Verify correct image pattern can be matched for VP8. |
462 TEST_F(TestVideoRendererTest, VerifyImagePatternMatchForVP8) { | 461 TEST_F(TestVideoRendererTest, VerifyImagePatternMatchForVP8) { |
463 encoder_ = VideoEncoderVpx::CreateForVP8(); | 462 encoder_ = VideoEncoderVpx::CreateForVP8(); |
464 test_video_renderer_->SetCodecForDecoding( | 463 test_video_renderer_->SetCodecForDecoding( |
465 protocol::ChannelConfig::Codec::CODEC_VP8); | 464 protocol::ChannelConfig::Codec::CODEC_VP8); |
466 TestImagePatternMatch(kDefaultScreenWidthPx, kDefaultScreenHeightPx, | 465 TestImagePatternMatch(kDefaultScreenWidthPx, kDefaultScreenHeightPx, |
467 kDefaultExpectedRect, true); | 466 kDefaultExpectedRect, true); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 TEST_F(TestVideoRendererTest, VerifyImagePatternNotMatchForVERBATIM) { | 506 TEST_F(TestVideoRendererTest, VerifyImagePatternNotMatchForVERBATIM) { |
508 encoder_.reset(new VideoEncoderVerbatim()); | 507 encoder_.reset(new VideoEncoderVerbatim()); |
509 test_video_renderer_->SetCodecForDecoding( | 508 test_video_renderer_->SetCodecForDecoding( |
510 protocol::ChannelConfig::Codec::CODEC_VERBATIM); | 509 protocol::ChannelConfig::Codec::CODEC_VERBATIM); |
511 TestImagePatternMatch(kDefaultScreenWidthPx, kDefaultScreenHeightPx, | 510 TestImagePatternMatch(kDefaultScreenWidthPx, kDefaultScreenHeightPx, |
512 kDefaultExpectedRect, false); | 511 kDefaultExpectedRect, false); |
513 } | 512 } |
514 | 513 |
515 } // namespace test | 514 } // namespace test |
516 } // namespace remoting | 515 } // namespace remoting |
OLD | NEW |