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

Side by Side Diff: remoting/test/test_video_renderer_unittest.cc

Issue 1846893002: Interface with webrtc through encoded frames (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed sergey comment Created 4 years, 8 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
« no previous file with comments | « remoting/test/codec_perftest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 = encoder_->Encode(*original_frame.get()); 143 std::unique_ptr<VideoPacket> packet =
144 encoder_->Encode(*original_frame.get(), 0);
144 145
145 DCHECK(!run_loop_ || !run_loop_->running()); 146 DCHECK(!run_loop_ || !run_loop_->running());
146 DCHECK(!timer_->IsRunning()); 147 DCHECK(!timer_->IsRunning());
147 run_loop_.reset(new base::RunLoop()); 148 run_loop_.reset(new base::RunLoop());
148 149
149 // Set an extremely long time: 10 min to prevent bugs from hanging the system. 150 // Set an extremely long time: 10 min to prevent bugs from hanging the system.
150 // NOTE: We've seen cases which take up to 1 min to process a packet, so an 151 // NOTE: We've seen cases which take up to 1 min to process a packet, so an
151 // extremely long time as 10 min is chosen to avoid being variable/flaky. 152 // extremely long time as 10 min is chosen to avoid being variable/flaky.
152 timer_->Start(FROM_HERE, base::TimeDelta::FromMinutes(10), 153 timer_->Start(FROM_HERE, base::TimeDelta::FromMinutes(10),
153 run_loop_->QuitClosure()); 154 run_loop_->QuitClosure());
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 int screen_height, 226 int screen_height,
226 const webrtc::DesktopRect& expected_rect, 227 const webrtc::DesktopRect& expected_rect,
227 bool expect_to_match) { 228 bool expect_to_match) {
228 DCHECK(encoder_); 229 DCHECK(encoder_);
229 DCHECK(test_video_renderer_); 230 DCHECK(test_video_renderer_);
230 231
231 std::unique_ptr<webrtc::DesktopFrame> frame = 232 std::unique_ptr<webrtc::DesktopFrame> frame =
232 CreateDesktopFrameWithGradient(screen_width, screen_height); 233 CreateDesktopFrameWithGradient(screen_width, screen_height);
233 RGBValue expected_average_color = 234 RGBValue expected_average_color =
234 CalculateAverageColorValueForFrame(frame.get(), expected_rect); 235 CalculateAverageColorValueForFrame(frame.get(), expected_rect);
235 std::unique_ptr<VideoPacket> packet = encoder_->Encode(*frame.get()); 236 std::unique_ptr<VideoPacket> packet = encoder_->Encode(*frame.get(), 0);
236 237
237 if (expect_to_match) { 238 if (expect_to_match) {
238 EXPECT_TRUE(SendPacketAndWaitForMatch(std::move(packet), expected_rect, 239 EXPECT_TRUE(SendPacketAndWaitForMatch(std::move(packet), expected_rect,
239 expected_average_color)); 240 expected_average_color));
240 } else { 241 } else {
241 // Shift each channel by 128. 242 // Shift each channel by 128.
242 // e.g. (10, 127, 200) -> (138, 255, 73). 243 // e.g. (10, 127, 200) -> (138, 255, 73).
243 // In this way, the error between expected color and true value is always 244 // In this way, the error between expected color and true value is always
244 // around 0.5. 245 // around 0.5.
245 int red_shift = (expected_average_color.red + 128) % 255; 246 int red_shift = (expected_average_color.red + 128) % 255;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 // Post multiple tasks to |test_video_renderer_|, and it should not crash. 398 // Post multiple tasks to |test_video_renderer_|, and it should not crash.
398 // 20 is chosen because it's large enough to make sure that there will be 399 // 20 is chosen because it's large enough to make sure that there will be
399 // more than one task on the video decode thread, while not too large to wait 400 // more than one task on the video decode thread, while not too large to wait
400 // for too long for the unit test to complete. 401 // for too long for the unit test to complete.
401 const int task_num = 20; 402 const int task_num = 20;
402 ScopedVector<VideoPacket> video_packets; 403 ScopedVector<VideoPacket> video_packets;
403 for (int i = 0; i < task_num; ++i) { 404 for (int i = 0; i < task_num; ++i) {
404 std::unique_ptr<webrtc::DesktopFrame> original_frame = 405 std::unique_ptr<webrtc::DesktopFrame> original_frame =
405 CreateDesktopFrameWithGradient(kDefaultScreenWidthPx, 406 CreateDesktopFrameWithGradient(kDefaultScreenWidthPx,
406 kDefaultScreenHeightPx); 407 kDefaultScreenHeightPx);
407 video_packets.push_back(encoder_->Encode(*original_frame.get())); 408 video_packets.push_back(encoder_->Encode(*original_frame.get(), 0));
408 } 409 }
409 410
410 for (int i = 0; i < task_num; ++i) { 411 for (int i = 0; i < task_num; ++i) {
411 // Transfer ownership of video packet. 412 // Transfer ownership of video packet.
412 VideoPacket* packet = video_packets[i]; 413 VideoPacket* packet = video_packets[i];
413 video_packets[i] = nullptr; 414 video_packets[i] = nullptr;
414 test_video_renderer_->ProcessVideoPacket(base::WrapUnique(packet), 415 test_video_renderer_->ProcessVideoPacket(base::WrapUnique(packet),
415 base::Bind(&base::DoNothing)); 416 base::Bind(&base::DoNothing));
416 } 417 }
417 } 418 }
(...skipping 28 matching lines...) Expand all
446 447
447 // Since we don't care whether expected image pattern is matched or not in 448 // Since we don't care whether expected image pattern is matched or not in
448 // this case, an expected color is chosen arbitrarily. 449 // this case, an expected color is chosen arbitrarily.
449 RGBValue black_color = RGBValue(); 450 RGBValue black_color = RGBValue();
450 451
451 // Set expected image pattern. 452 // Set expected image pattern.
452 test_video_renderer_->ExpectAverageColorInRect( 453 test_video_renderer_->ExpectAverageColorInRect(
453 kDefaultExpectedRect, black_color, base::Bind(&base::DoNothing)); 454 kDefaultExpectedRect, black_color, base::Bind(&base::DoNothing));
454 455
455 // Post test video packet. 456 // Post test video packet.
456 test_video_renderer_->ProcessVideoPacket(encoder_->Encode(*frame.get()), 457 test_video_renderer_->ProcessVideoPacket(encoder_->Encode(*frame.get(), 0),
457 base::Bind(&base::DoNothing)); 458 base::Bind(&base::DoNothing));
458 } 459 }
459 460
460 // Verify correct image pattern can be matched for VP8. 461 // Verify correct image pattern can be matched for VP8.
461 TEST_F(TestVideoRendererTest, VerifyImagePatternMatchForVP8) { 462 TEST_F(TestVideoRendererTest, VerifyImagePatternMatchForVP8) {
462 encoder_ = VideoEncoderVpx::CreateForVP8(); 463 encoder_ = VideoEncoderVpx::CreateForVP8();
463 test_video_renderer_->SetCodecForDecoding( 464 test_video_renderer_->SetCodecForDecoding(
464 protocol::ChannelConfig::Codec::CODEC_VP8); 465 protocol::ChannelConfig::Codec::CODEC_VP8);
465 TestImagePatternMatch(kDefaultScreenWidthPx, kDefaultScreenHeightPx, 466 TestImagePatternMatch(kDefaultScreenWidthPx, kDefaultScreenHeightPx,
466 kDefaultExpectedRect, true); 467 kDefaultExpectedRect, true);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 TEST_F(TestVideoRendererTest, VerifyImagePatternNotMatchForVERBATIM) { 507 TEST_F(TestVideoRendererTest, VerifyImagePatternNotMatchForVERBATIM) {
507 encoder_.reset(new VideoEncoderVerbatim()); 508 encoder_.reset(new VideoEncoderVerbatim());
508 test_video_renderer_->SetCodecForDecoding( 509 test_video_renderer_->SetCodecForDecoding(
509 protocol::ChannelConfig::Codec::CODEC_VERBATIM); 510 protocol::ChannelConfig::Codec::CODEC_VERBATIM);
510 TestImagePatternMatch(kDefaultScreenWidthPx, kDefaultScreenHeightPx, 511 TestImagePatternMatch(kDefaultScreenWidthPx, kDefaultScreenHeightPx,
511 kDefaultExpectedRect, false); 512 kDefaultExpectedRect, false);
512 } 513 }
513 514
514 } // namespace test 515 } // namespace test
515 } // namespace remoting 516 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/test/codec_perftest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698