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

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

Issue 1545723002: Use std::move() instead of .Pass() in remoting/* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_not_pass_host
Patch Set: Created 4 years, 12 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/test_chromoting_client.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 11
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
13 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h" 15 #include "base/run_loop.h"
15 #include "base/thread_task_runner_handle.h" 16 #include "base/thread_task_runner_handle.h"
16 #include "base/timer/timer.h" 17 #include "base/timer/timer.h"
17 #include "remoting/codec/video_encoder.h" 18 #include "remoting/codec/video_encoder.h"
18 #include "remoting/codec/video_encoder_verbatim.h" 19 #include "remoting/codec/video_encoder_verbatim.h"
19 #include "remoting/codec/video_encoder_vpx.h" 20 #include "remoting/codec/video_encoder_vpx.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 DCHECK(!timer_->IsRunning()); 144 DCHECK(!timer_->IsRunning());
144 run_loop_.reset(new base::RunLoop()); 145 run_loop_.reset(new base::RunLoop());
145 146
146 // Set an extremely long time: 10 min to prevent bugs from hanging the system. 147 // Set an extremely long time: 10 min to prevent bugs from hanging the system.
147 // NOTE: We've seen cases which take up to 1 min to process a packet, so an 148 // NOTE: We've seen cases which take up to 1 min to process a packet, so an
148 // extremely long time as 10 min is chosen to avoid being variable/flaky. 149 // extremely long time as 10 min is chosen to avoid being variable/flaky.
149 timer_->Start(FROM_HERE, base::TimeDelta::FromMinutes(10), 150 timer_->Start(FROM_HERE, base::TimeDelta::FromMinutes(10),
150 run_loop_->QuitClosure()); 151 run_loop_->QuitClosure());
151 152
152 // Wait for the video packet to be processed and rendered to buffer. 153 // Wait for the video packet to be processed and rendered to buffer.
153 test_video_renderer_->ProcessVideoPacket(packet.Pass(), 154 test_video_renderer_->ProcessVideoPacket(std::move(packet),
154 run_loop_->QuitClosure()); 155 run_loop_->QuitClosure());
155 156
156 run_loop_->Run(); 157 run_loop_->Run();
157 EXPECT_TRUE(timer_->IsRunning()); 158 EXPECT_TRUE(timer_->IsRunning());
158 timer_->Stop(); 159 timer_->Stop();
159 run_loop_.reset(); 160 run_loop_.reset();
160 161
161 scoped_ptr<webrtc::DesktopFrame> buffer_copy = 162 scoped_ptr<webrtc::DesktopFrame> buffer_copy =
162 test_video_renderer_->GetCurrentFrameForTest(); 163 test_video_renderer_->GetCurrentFrameForTest();
163 EXPECT_NE(buffer_copy, nullptr); 164 EXPECT_NE(buffer_copy, nullptr);
(...skipping 19 matching lines...) Expand all
183 run_loop_->QuitClosure()); 184 run_loop_->QuitClosure());
184 185
185 // Set expected image pattern. 186 // Set expected image pattern.
186 test_video_renderer_->ExpectAverageColorInRect( 187 test_video_renderer_->ExpectAverageColorInRect(
187 expected_rect, expected_average_color, run_loop_->QuitClosure()); 188 expected_rect, expected_average_color, run_loop_->QuitClosure());
188 189
189 // Used to verify if the expected image pattern will be matched by |packet|. 190 // Used to verify if the expected image pattern will be matched by |packet|.
190 scoped_ptr<VideoPacket> packet_copy(new VideoPacket(*packet.get())); 191 scoped_ptr<VideoPacket> packet_copy(new VideoPacket(*packet.get()));
191 192
192 // Post first test packet: |packet|. 193 // Post first test packet: |packet|.
193 test_video_renderer_->ProcessVideoPacket(packet.Pass(), 194 test_video_renderer_->ProcessVideoPacket(std::move(packet),
194 base::Bind(&base::DoNothing)); 195 base::Bind(&base::DoNothing));
195 196
196 // Second packet: |packet_copy| is posted, and |second_packet_done_callback| 197 // Second packet: |packet_copy| is posted, and |second_packet_done_callback|
197 // will always be posted back to main thread, however, whether it will be 198 // will always be posted back to main thread, however, whether it will be
198 // called depends on whether the expected pattern is matched or not. 199 // called depends on whether the expected pattern is matched or not.
199 bool second_packet_done_is_called = false; 200 bool second_packet_done_is_called = false;
200 base::Closure second_packet_done_callback = 201 base::Closure second_packet_done_callback =
201 base::Bind(&ProcessPacketDoneHandler, run_loop_->QuitClosure(), 202 base::Bind(&ProcessPacketDoneHandler, run_loop_->QuitClosure(),
202 &second_packet_done_is_called); 203 &second_packet_done_is_called);
203 204
204 test_video_renderer_->ProcessVideoPacket(packet_copy.Pass(), 205 test_video_renderer_->ProcessVideoPacket(std::move(packet_copy),
205 second_packet_done_callback); 206 second_packet_done_callback);
206 207
207 run_loop_->Run(); 208 run_loop_->Run();
208 EXPECT_TRUE(timer_->IsRunning()); 209 EXPECT_TRUE(timer_->IsRunning());
209 timer_->Stop(); 210 timer_->Stop();
210 run_loop_.reset(); 211 run_loop_.reset();
211 212
212 // if expected image pattern is matched, the QuitClosure of |run_loop_| will 213 // if expected image pattern is matched, the QuitClosure of |run_loop_| will
213 // be called before |second_packet_done_callback|, which leaves 214 // be called before |second_packet_done_callback|, which leaves
214 // |second_packet_done_is_called| be false. 215 // |second_packet_done_is_called| be false.
(...skipping 10 matching lines...) Expand all
225 DCHECK(encoder_); 226 DCHECK(encoder_);
226 DCHECK(test_video_renderer_); 227 DCHECK(test_video_renderer_);
227 228
228 scoped_ptr<webrtc::DesktopFrame> frame = 229 scoped_ptr<webrtc::DesktopFrame> frame =
229 CreateDesktopFrameWithGradient(screen_width, screen_height); 230 CreateDesktopFrameWithGradient(screen_width, screen_height);
230 RGBValue expected_average_color = 231 RGBValue expected_average_color =
231 CalculateAverageColorValueForFrame(frame.get(), expected_rect); 232 CalculateAverageColorValueForFrame(frame.get(), expected_rect);
232 scoped_ptr<VideoPacket> packet = encoder_->Encode(*frame.get()); 233 scoped_ptr<VideoPacket> packet = encoder_->Encode(*frame.get());
233 234
234 if (expect_to_match) { 235 if (expect_to_match) {
235 EXPECT_TRUE(SendPacketAndWaitForMatch(packet.Pass(), expected_rect, 236 EXPECT_TRUE(SendPacketAndWaitForMatch(std::move(packet), expected_rect,
236 expected_average_color)); 237 expected_average_color));
237 } else { 238 } else {
238 // Shift each channel by 128. 239 // Shift each channel by 128.
239 // e.g. (10, 127, 200) -> (138, 255, 73). 240 // e.g. (10, 127, 200) -> (138, 255, 73).
240 // In this way, the error between expected color and true value is always 241 // In this way, the error between expected color and true value is always
241 // around 0.5. 242 // around 0.5.
242 int red_shift = (expected_average_color.red + 128) % 255; 243 int red_shift = (expected_average_color.red + 128) % 255;
243 int green_shift = (expected_average_color.green + 128) % 255; 244 int green_shift = (expected_average_color.green + 128) % 255;
244 int blue_shift = (expected_average_color.blue + 128) % 255; 245 int blue_shift = (expected_average_color.blue + 128) % 255;
245 246
246 RGBValue expected_average_color_shift = 247 RGBValue expected_average_color_shift =
247 RGBValue(red_shift, green_shift, blue_shift); 248 RGBValue(red_shift, green_shift, blue_shift);
248 249
249 EXPECT_FALSE(SendPacketAndWaitForMatch(packet.Pass(), expected_rect, 250 EXPECT_FALSE(SendPacketAndWaitForMatch(std::move(packet), expected_rect,
250 expected_average_color_shift)); 251 expected_average_color_shift));
251 } 252 }
252 } 253 }
253 254
254 RGBValue TestVideoRendererTest::CalculateAverageColorValueForFrame( 255 RGBValue TestVideoRendererTest::CalculateAverageColorValueForFrame(
255 const webrtc::DesktopFrame* frame, 256 const webrtc::DesktopFrame* frame,
256 const webrtc::DesktopRect& rect) const { 257 const webrtc::DesktopRect& rect) const {
257 int red_sum = 0; 258 int red_sum = 0;
258 int green_sum = 0; 259 int green_sum = 0;
259 int blue_sum = 0; 260 int blue_sum = 0;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 334
334 scoped_ptr<webrtc::DesktopFrame> 335 scoped_ptr<webrtc::DesktopFrame>
335 TestVideoRendererTest::CreateDesktopFrameWithGradient( 336 TestVideoRendererTest::CreateDesktopFrameWithGradient(
336 int screen_width, int screen_height) const { 337 int screen_width, int screen_height) const {
337 webrtc::DesktopSize screen_size(screen_width, screen_height); 338 webrtc::DesktopSize screen_size(screen_width, screen_height);
338 scoped_ptr<webrtc::DesktopFrame> frame( 339 scoped_ptr<webrtc::DesktopFrame> frame(
339 new webrtc::BasicDesktopFrame(screen_size)); 340 new webrtc::BasicDesktopFrame(screen_size));
340 frame->mutable_updated_region()->SetRect( 341 frame->mutable_updated_region()->SetRect(
341 webrtc::DesktopRect::MakeSize(screen_size)); 342 webrtc::DesktopRect::MakeSize(screen_size));
342 FillFrameWithGradient(frame.get()); 343 FillFrameWithGradient(frame.get());
343 return frame.Pass(); 344 return frame;
344 } 345 }
345 346
346 void TestVideoRendererTest::FillFrameWithGradient( 347 void TestVideoRendererTest::FillFrameWithGradient(
347 webrtc::DesktopFrame* frame) const { 348 webrtc::DesktopFrame* frame) const {
348 for (int y = 0; y < frame->size().height(); ++y) { 349 for (int y = 0; y < frame->size().height(); ++y) {
349 uint8_t* p = frame->data() + y * frame->stride(); 350 uint8_t* p = frame->data() + y * frame->stride();
350 for (int x = 0; x < frame->size().width(); ++x) { 351 for (int x = 0; x < frame->size().width(); ++x) {
351 *p++ = (255.0 * x) / frame->size().width(); 352 *p++ = (255.0 * x) / frame->size().width();
352 *p++ = (164.0 * y) / frame->size().height(); 353 *p++ = (164.0 * y) / frame->size().height();
353 *p++ = (82.0 * (x + y)) / 354 *p++ = (82.0 * (x + y)) /
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 444
444 // Since we don't care whether expected image pattern is matched or not in 445 // Since we don't care whether expected image pattern is matched or not in
445 // this case, an expected color is chosen arbitrarily. 446 // this case, an expected color is chosen arbitrarily.
446 RGBValue black_color = RGBValue(); 447 RGBValue black_color = RGBValue();
447 448
448 // Set expected image pattern. 449 // Set expected image pattern.
449 test_video_renderer_->ExpectAverageColorInRect( 450 test_video_renderer_->ExpectAverageColorInRect(
450 kDefaultExpectedRect, black_color, base::Bind(&base::DoNothing)); 451 kDefaultExpectedRect, black_color, base::Bind(&base::DoNothing));
451 452
452 // Post test video packet. 453 // Post test video packet.
453 scoped_ptr<VideoPacket> packet = encoder_->Encode(*frame.get()); 454 test_video_renderer_->ProcessVideoPacket(encoder_->Encode(*frame.get()),
454 test_video_renderer_->ProcessVideoPacket(packet.Pass(),
455 base::Bind(&base::DoNothing)); 455 base::Bind(&base::DoNothing));
456 } 456 }
457 457
458 // Verify correct image pattern can be matched for VP8. 458 // Verify correct image pattern can be matched for VP8.
459 TEST_F(TestVideoRendererTest, VerifyImagePatternMatchForVP8) { 459 TEST_F(TestVideoRendererTest, VerifyImagePatternMatchForVP8) {
460 encoder_ = VideoEncoderVpx::CreateForVP8(); 460 encoder_ = VideoEncoderVpx::CreateForVP8();
461 test_video_renderer_->SetCodecForDecoding( 461 test_video_renderer_->SetCodecForDecoding(
462 protocol::ChannelConfig::Codec::CODEC_VP8); 462 protocol::ChannelConfig::Codec::CODEC_VP8);
463 TestImagePatternMatch(kDefaultScreenWidthPx, kDefaultScreenHeightPx, 463 TestImagePatternMatch(kDefaultScreenWidthPx, kDefaultScreenHeightPx,
464 kDefaultExpectedRect, true); 464 kDefaultExpectedRect, true);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 TEST_F(TestVideoRendererTest, VerifyImagePatternNotMatchForVERBATIM) { 504 TEST_F(TestVideoRendererTest, VerifyImagePatternNotMatchForVERBATIM) {
505 encoder_.reset(new VideoEncoderVerbatim()); 505 encoder_.reset(new VideoEncoderVerbatim());
506 test_video_renderer_->SetCodecForDecoding( 506 test_video_renderer_->SetCodecForDecoding(
507 protocol::ChannelConfig::Codec::CODEC_VERBATIM); 507 protocol::ChannelConfig::Codec::CODEC_VERBATIM);
508 TestImagePatternMatch(kDefaultScreenWidthPx, kDefaultScreenHeightPx, 508 TestImagePatternMatch(kDefaultScreenWidthPx, kDefaultScreenHeightPx,
509 kDefaultExpectedRect, false); 509 kDefaultExpectedRect, false);
510 } 510 }
511 511
512 } // namespace test 512 } // namespace test
513 } // namespace remoting 513 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/test/test_chromoting_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698