Chromium Code Reviews| 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 <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/thread_task_runner_handle.h" | |
| 12 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 13 #include "media/base/video_frame.h" | 14 #include "media/base/video_frame.h" |
| 14 #include "remoting/codec/video_encoder.h" | 15 #include "remoting/codec/video_encoder.h" |
| 15 #include "remoting/codec/video_encoder_verbatim.h" | 16 #include "remoting/codec/video_encoder_verbatim.h" |
| 16 #include "remoting/codec/video_encoder_vpx.h" | 17 #include "remoting/codec/video_encoder_vpx.h" |
| 17 #include "remoting/proto/video.pb.h" | 18 #include "remoting/proto/video.pb.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 20 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| 20 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" | 21 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 const int kBytesPerPixel = 4; | 24 |
| 25 // Used to verify that image pattern is not matched. | |
| 26 void VideoPacketDoneHandler(const base::Closure& done_closure, | |
|
joedow
2015/07/10 23:39:16
'VideoPacketDoneHandler' isn't very descriptive, w
liaoyuke
2015/07/13 16:05:39
I have changed the mechanism: in both Match and No
| |
| 27 bool* image_pattern_is_matched) { | |
| 28 *image_pattern_is_matched = false; | |
| 29 done_closure.Run(); | |
| 30 } | |
| 31 | |
| 32 // Default screen size, measured in pixels. | |
| 24 const int kDefaultScreenWidth = 1024; | 33 const int kDefaultScreenWidth = 1024; |
| 25 const int kDefaultScreenHeight = 768; | 34 const int kDefaultScreenHeight = 768; |
|
joedow
2015/07/10 23:39:16
nit: You can remove the comment if you change the
liaoyuke
2015/07/13 16:05:39
Done.
| |
| 35 | |
| 36 // Default max error for encoding and decoding, measured in percent. | |
| 26 const double kDefaultErrorLimit = 0.02; | 37 const double kDefaultErrorLimit = 0.02; |
| 27 } | 38 |
| 39 // Default expected rect for image pattern, measured in pixels. | |
| 40 const webrtc::DesktopRect kDefaultExpectedRect = | |
| 41 webrtc::DesktopRect::MakeLTRB(100, 100, 200, 200); | |
| 42 } // namespace | |
| 28 | 43 |
| 29 namespace remoting { | 44 namespace remoting { |
| 30 namespace test { | 45 namespace test { |
| 31 | 46 |
| 32 // Provides basic functionality for for the TestVideoRenderer Tests below. | 47 // Provides basic functionality for for the TestVideoRenderer Tests below. |
| 33 // This fixture also creates an MessageLoop to test decoding video packets. | 48 // This fixture also creates an MessageLoop to test decoding video packets. |
| 34 class TestVideoRendererTest : public testing::Test { | 49 class TestVideoRendererTest : public testing::Test { |
| 35 public: | 50 public: |
| 36 TestVideoRendererTest(); | 51 TestVideoRendererTest(); |
| 37 ~TestVideoRendererTest() override; | 52 ~TestVideoRendererTest() override; |
| 38 | 53 |
| 39 // Generate a frame containing a gradient and test decoding of | 54 // Generate a frame containing a gradient and test decoding of |
| 40 // TestVideoRenderer. The original frame is compared to the one obtained from | 55 // TestVideoRenderer. |
| 41 // decoding the video packet, and the error at each pixel is the root mean | 56 // The original frame is compared to the one obtained from decoding the video |
| 42 // square of the errors in the R, G and B components, each normalized to | 57 // packet, and the error at each pixel is the root mean square of the errors |
| 43 // [0, 1]. This routine checks that the mean error over all pixels do not | 58 // in the R, G and B components, each normalized to [0, 1]. This routine |
| 44 // exceed a given limit. | 59 // checks that the mean error over all pixels do not exceed a given limit. |
| 45 void TestVideoPacketProcessing(int screen_width, int screen_height, | 60 void TestVideoPacketProcessing(int screen_width, int screen_height, |
| 46 double error_limit); | 61 double error_limit); |
| 47 | 62 |
| 63 // True positive case: checks correct image pattern will be matched. | |
| 64 // Generate a frame containing a gradient and an expected color is first | |
| 65 // obtained as the average value of pixels that fall within |expected_rect|, | |
| 66 // then set expected image pattern and encode the frame to send to | |
| 67 // TestVieoRenderer for processing. This routine expects that the expected | |
| 68 // image can be matched and corresponding callback can be fired. | |
|
joedow
2015/07/10 23:39:16
These comments are better suited for the definitio
liaoyuke
2015/07/13 16:05:38
Done.
| |
| 69 void TestImagePatternMatchAndCallback( | |
| 70 int screen_width, | |
| 71 int screen_height, | |
| 72 const webrtc::DesktopRect& expected_rect); | |
| 73 | |
| 74 // True negative case: checks incorrect image pattern will not be matched. | |
| 75 // Generate a frame containing a gradient and an expected color is first | |
| 76 // obtained as the average value of pixels that fall within |expected_rect|, | |
| 77 // then each channel of the expected color is shifted by 128 to make sure the | |
| 78 // difference between expected color and true value is large enough that | |
| 79 // expected image pattern should not match. Next, set expected image pattern | |
| 80 // and encode the frame to send to TestVideoRenderer for processing, lastly, | |
| 81 // an empty video packet with VideoPacketDoneHandler is sent to | |
| 82 // TestVideoRenderer to check whether callback has been fired or not. This | |
| 83 // routine checks that the expected image will not matched and callback will | |
| 84 // not be fired. | |
| 85 void TestImagePatternNotMatch(int screen_width, | |
| 86 int screen_height, | |
| 87 const webrtc::DesktopRect& expected_rect); | |
| 88 | |
| 48 // Generate a basic desktop frame containing a gradient. | 89 // Generate a basic desktop frame containing a gradient. |
| 49 scoped_ptr<webrtc::DesktopFrame> CreateDesktopFrameWithGradient( | 90 scoped_ptr<webrtc::DesktopFrame> CreateDesktopFrameWithGradient( |
| 50 int screen_width, int screen_height) const; | 91 int screen_width, int screen_height) const; |
| 51 | 92 |
| 52 protected: | 93 protected: |
| 53 // Used to post tasks to the message loop. | 94 // Used to post tasks to the message loop. |
| 54 scoped_ptr<base::RunLoop> run_loop_; | 95 scoped_ptr<base::RunLoop> run_loop_; |
| 55 | 96 |
| 56 // Used to set timeouts and delays. | 97 // Used to set timeouts and delays. |
| 57 scoped_ptr<base::Timer> timer_; | 98 scoped_ptr<base::Timer> timer_; |
| 58 | 99 |
| 59 // Manages the decoder and process generated video packets. | 100 // Manages the decoder and process generated video packets. |
| 60 scoped_ptr<TestVideoRenderer> test_video_renderer_; | 101 scoped_ptr<TestVideoRenderer> test_video_renderer_; |
| 61 | 102 |
| 62 // Used to encode desktop frames to generate video packets. | 103 // Used to encode desktop frames to generate video packets. |
| 63 scoped_ptr<VideoEncoder> encoder_; | 104 scoped_ptr<VideoEncoder> encoder_; |
| 64 | 105 |
| 65 private: | 106 private: |
| 66 // testing::Test interface. | 107 // testing::Test interface. |
| 67 void SetUp() override; | 108 void SetUp() override; |
| 68 | 109 |
| 110 // Returns the average color value of pixels fall within |rect|. | |
| 111 // NOTE: Callers should not release the objects. | |
| 112 RGBA32 CalculateAverageColorTripletsForFrame( | |
|
joedow
2015/07/10 23:39:16
CalculateAverageRgbColorForFrame
liaoyuke
2015/07/13 16:05:38
Done.
| |
| 113 const webrtc::DesktopFrame* frame, | |
| 114 const webrtc::DesktopRect& rect) const; | |
| 115 | |
| 69 // return the mean error of two frames. | 116 // return the mean error of two frames. |
| 70 double CalculateError(const webrtc::DesktopFrame* original_frame, | 117 double CalculateError(const webrtc::DesktopFrame* original_frame, |
| 71 const webrtc::DesktopFrame* decoded_frame) const; | 118 const webrtc::DesktopFrame* decoded_frame) const; |
| 72 | 119 |
| 73 // Fill a desktop frame with a gradient. | 120 // Fill a desktop frame with a gradient. |
| 74 void FillFrameWithGradient(webrtc::DesktopFrame* frame) const; | 121 void FillFrameWithGradient(webrtc::DesktopFrame* frame) const; |
| 75 | 122 |
| 76 // The thread's message loop. Valid only when the thread is alive. | 123 // The thread's message loop. Valid only when the thread is alive. |
| 77 scoped_ptr<base::MessageLoop> message_loop_; | 124 scoped_ptr<base::MessageLoop> message_loop_; |
| 78 | 125 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 102 scoped_ptr<webrtc::DesktopFrame> original_frame = | 149 scoped_ptr<webrtc::DesktopFrame> original_frame = |
| 103 CreateDesktopFrameWithGradient(screen_width, screen_height); | 150 CreateDesktopFrameWithGradient(screen_width, screen_height); |
| 104 EXPECT_TRUE(original_frame); | 151 EXPECT_TRUE(original_frame); |
| 105 scoped_ptr<VideoPacket> packet = encoder_->Encode(*original_frame.get()); | 152 scoped_ptr<VideoPacket> packet = encoder_->Encode(*original_frame.get()); |
| 106 DCHECK(!run_loop_ || !run_loop_->running()); | 153 DCHECK(!run_loop_ || !run_loop_->running()); |
| 107 run_loop_.reset(new base::RunLoop()); | 154 run_loop_.reset(new base::RunLoop()); |
| 108 | 155 |
| 109 // Wait for the video packet to be processed and rendered to buffer. | 156 // Wait for the video packet to be processed and rendered to buffer. |
| 110 test_video_renderer_->ProcessVideoPacket(packet.Pass(), | 157 test_video_renderer_->ProcessVideoPacket(packet.Pass(), |
| 111 run_loop_->QuitClosure()); | 158 run_loop_->QuitClosure()); |
| 159 | |
| 112 run_loop_->Run(); | 160 run_loop_->Run(); |
| 113 | 161 |
| 114 scoped_ptr<webrtc::DesktopFrame> buffer_copy = | 162 scoped_ptr<webrtc::DesktopFrame> buffer_copy = |
| 115 test_video_renderer_->GetBufferForTest(); | 163 test_video_renderer_->GetFrameForTest(); |
| 116 EXPECT_NE(buffer_copy, nullptr); | 164 EXPECT_NE(buffer_copy, nullptr); |
| 117 double error = CalculateError(original_frame.get(), buffer_copy.get()); | 165 double error = CalculateError(original_frame.get(), buffer_copy.get()); |
| 118 EXPECT_LT(error, error_limit); | 166 EXPECT_LT(error, error_limit); |
| 119 } | 167 } |
| 120 | 168 |
| 169 void TestVideoRendererTest::TestImagePatternMatchAndCallback( | |
| 170 int screen_width, | |
| 171 int screen_height, | |
| 172 const webrtc::DesktopRect& expected_rect) { | |
| 173 DCHECK(encoder_); | |
| 174 DCHECK(test_video_renderer_); | |
| 175 | |
| 176 scoped_ptr<webrtc::DesktopFrame> frame = | |
| 177 CreateDesktopFrameWithGradient(screen_width, screen_height); | |
| 178 EXPECT_TRUE(frame); | |
|
joedow
2015/07/10 23:39:16
I don't think you need EXPECT_TRUE since it is a h
liaoyuke
2015/07/13 16:05:39
Done.
| |
| 179 RGBA32 expected_color = | |
| 180 CalculateAverageColorTripletsForFrame(frame.get(), expected_rect); | |
| 181 DCHECK(!run_loop_ || !run_loop_->running()); | |
| 182 run_loop_.reset(new base::RunLoop()); | |
| 183 | |
| 184 // Set expected image pattern. | |
| 185 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 186 FROM_HERE, | |
| 187 base::Bind(&TestVideoRenderer::SetImagePatternAndMatchedCallback, | |
| 188 base::Unretained(test_video_renderer_.get()), expected_rect, | |
| 189 expected_color, run_loop_->QuitClosure())); | |
|
joedow
2015/07/10 23:39:16
Why are you posting a task here instead of just ca
liaoyuke
2015/07/13 16:05:39
Yes, you are right, they are basically doing the s
| |
| 190 | |
| 191 // Post test video packet, and this packet is expected to match the expected | |
| 192 // image pattern. | |
| 193 scoped_ptr<VideoPacket> packet = encoder_->Encode(*frame.get()); | |
| 194 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 195 FROM_HERE, | |
| 196 base::Bind(&TestVideoRenderer::ProcessVideoPacket, | |
| 197 base::Unretained(test_video_renderer_.get()), | |
| 198 base::Passed(&packet), base::Bind(&base::DoNothing))); | |
| 199 | |
| 200 // Wait for image pattern matched reply to be fired. | |
|
joedow
2015/07/10 23:39:16
If there is a product bug, then the MessageLoop co
liaoyuke
2015/07/13 16:05:39
the new mechanism send a copy packet to check if e
| |
| 201 run_loop_->Run(); | |
| 202 run_loop_.reset(); | |
| 203 } | |
| 204 | |
| 205 void TestVideoRendererTest::TestImagePatternNotMatch( | |
| 206 int screen_width, | |
| 207 int screen_height, | |
| 208 const webrtc::DesktopRect& expected_rect) { | |
| 209 DCHECK(encoder_); | |
| 210 DCHECK(test_video_renderer_); | |
| 211 | |
| 212 scoped_ptr<webrtc::DesktopFrame> frame = | |
| 213 CreateDesktopFrameWithGradient(screen_width, screen_height); | |
| 214 EXPECT_TRUE(frame); | |
| 215 RGBA32 expected_color = | |
| 216 CalculateAverageColorTripletsForFrame(frame.get(), expected_rect); | |
| 217 | |
| 218 // Shift each channel by 128. | |
| 219 // e.g. (10, 127, 200) -> (138, 255, 73). | |
| 220 // In this way, the error between expected color and true value is always | |
| 221 // around 0.5. | |
| 222 int red_shift = (((expected_color >> 16) & 0xFF) + 128) % 255; | |
| 223 int green_shift = (((expected_color >> 8) & 0xFF) + 128) % 255; | |
| 224 int blue_shift = ((expected_color & 0xFF) + 128) % 255; | |
| 225 | |
| 226 int expected_color_shift = | |
| 227 0xFF000000 | (red_shift << 16) | (green_shift << 8) | blue_shift; | |
| 228 | |
| 229 DCHECK(!run_loop_ || !run_loop_->running()); | |
| 230 run_loop_.reset(new base::RunLoop()); | |
| 231 | |
| 232 // Set expected image pattern. | |
| 233 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 234 FROM_HERE, | |
| 235 base::Bind(&TestVideoRenderer::SetImagePatternAndMatchedCallback, | |
| 236 base::Unretained(test_video_renderer_.get()), expected_rect, | |
| 237 expected_color_shift, run_loop_->QuitClosure())); | |
| 238 | |
| 239 // Post test video packet, and it is not expected to match the expected | |
| 240 // image pattern. | |
| 241 scoped_ptr<VideoPacket> packet = encoder_->Encode(*frame.get()); | |
| 242 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 243 FROM_HERE, | |
| 244 base::Bind(&TestVideoRenderer::ProcessVideoPacket, | |
| 245 base::Unretained(test_video_renderer_.get()), | |
| 246 base::Passed(&packet), base::Bind(&base::DoNothing))); | |
| 247 | |
| 248 // An empty packet with a VideoPacketDoneHandler is sent to check whether | |
| 249 // the callback has been fired or not. | |
|
joedow
2015/07/10 23:39:16
Posting an empty packet will just cause your done
liaoyuke
2015/07/13 16:05:38
You are right, there is a bug. The new mechanism i
| |
| 250 bool image_pattern_is_matched = true; | |
| 251 scoped_ptr<VideoPacket> empty_packet(new VideoPacket()); | |
| 252 base::Closure video_packet_done_callback = | |
| 253 base::Bind(&VideoPacketDoneHandler, run_loop_->QuitClosure(), | |
| 254 &image_pattern_is_matched); | |
| 255 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 256 FROM_HERE, | |
| 257 base::Bind(&TestVideoRenderer::ProcessVideoPacket, | |
| 258 base::Unretained(test_video_renderer_.get()), | |
| 259 base::Passed(&empty_packet), video_packet_done_callback)); | |
| 260 | |
| 261 run_loop_->Run(); | |
| 262 run_loop_.reset(); | |
| 263 | |
| 264 EXPECT_FALSE(image_pattern_is_matched); | |
| 265 } | |
| 266 | |
| 267 RGBA32 TestVideoRendererTest::CalculateAverageColorTripletsForFrame( | |
| 268 const webrtc::DesktopFrame* frame, | |
| 269 const webrtc::DesktopRect& rect) const { | |
| 270 int red_sum = 0; | |
| 271 int green_sum = 0; | |
| 272 int blue_sum = 0; | |
| 273 | |
| 274 // Loop through pixels that fall within |accumulating_rect_| to obtain the | |
| 275 // average color triplets. | |
| 276 for (int y = rect.top(); y < rect.bottom(); ++y) { | |
| 277 uint8_t* frame_pos = | |
| 278 frame->data() + (y * frame->stride() + | |
| 279 rect.left() * webrtc::DesktopFrame::kBytesPerPixel); | |
| 280 | |
| 281 // Pixels of decoded video frame are presented in ARGB format. | |
| 282 for (int x = 0; x < rect.width(); ++x) { | |
| 283 red_sum += frame_pos[2]; | |
| 284 green_sum += frame_pos[1]; | |
| 285 blue_sum += frame_pos[0]; | |
| 286 frame_pos += 4; | |
| 287 } | |
| 288 } | |
| 289 | |
| 290 int area = rect.width() * rect.height(); | |
| 291 return 0xFF000000 | ((red_sum / area) << 16) | ((green_sum / area) << 8) | | |
| 292 (blue_sum / area); | |
| 293 } | |
| 294 | |
| 121 double TestVideoRendererTest::CalculateError( | 295 double TestVideoRendererTest::CalculateError( |
| 122 const webrtc::DesktopFrame* original_frame, | 296 const webrtc::DesktopFrame* original_frame, |
| 123 const webrtc::DesktopFrame* decoded_frame) const { | 297 const webrtc::DesktopFrame* decoded_frame) const { |
| 124 DCHECK(original_frame); | 298 DCHECK(original_frame); |
| 125 DCHECK(decoded_frame); | 299 DCHECK(decoded_frame); |
| 126 | 300 |
| 127 // Check size remains the same after encoding and decoding. | 301 // Check size remains the same after encoding and decoding. |
| 128 EXPECT_EQ(original_frame->size().width(), decoded_frame->size().width()); | 302 EXPECT_EQ(original_frame->size().width(), decoded_frame->size().width()); |
| 129 EXPECT_EQ(original_frame->size().height(), decoded_frame->size().height()); | 303 EXPECT_EQ(original_frame->size().height(), decoded_frame->size().height()); |
| 130 EXPECT_EQ(original_frame->stride(), decoded_frame->stride()); | 304 EXPECT_EQ(original_frame->stride(), decoded_frame->stride()); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 149 // | 323 // |
| 150 for (int height = 0; height < screen_height; ++height) { | 324 for (int height = 0; height < screen_height; ++height) { |
| 151 uint8_t* original_ptr = original_frame->data() + | 325 uint8_t* original_ptr = original_frame->data() + |
| 152 height * original_frame->stride(); | 326 height * original_frame->stride(); |
| 153 uint8_t* decoded_ptr = decoded_frame->data() + | 327 uint8_t* decoded_ptr = decoded_frame->data() + |
| 154 height * decoded_frame->stride(); | 328 height * decoded_frame->stride(); |
| 155 | 329 |
| 156 for (int width = 0; width < screen_width; ++width) { | 330 for (int width = 0; width < screen_width; ++width) { |
| 157 // Errors are calculated in the R, G, B components. | 331 // Errors are calculated in the R, G, B components. |
| 158 for (int j = 0; j < 3; ++j) { | 332 for (int j = 0; j < 3; ++j) { |
| 159 int offset = kBytesPerPixel * width + j; | 333 int offset = webrtc::DesktopFrame::kBytesPerPixel * width + j; |
| 160 double original_value = static_cast<double>(*(original_ptr + offset)); | 334 double original_value = static_cast<double>(*(original_ptr + offset)); |
| 161 double decoded_value = static_cast<double>(*(decoded_ptr + offset)); | 335 double decoded_value = static_cast<double>(*(decoded_ptr + offset)); |
| 162 double error = original_value - decoded_value; | 336 double error = original_value - decoded_value; |
| 163 | 337 |
| 164 // Normalize the error to [0, 1]. | 338 // Normalize the error to [0, 1]. |
| 165 error /= 255.0; | 339 error /= 255.0; |
| 166 error_sum_squares += error * error; | 340 error_sum_squares += error * error; |
| 167 } | 341 } |
| 168 } | 342 } |
| 169 } | 343 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 TestVideoPacketProcessing(kDefaultScreenWidth, kDefaultScreenHeight, | 435 TestVideoPacketProcessing(kDefaultScreenWidth, kDefaultScreenHeight, |
| 262 kDefaultErrorLimit); | 436 kDefaultErrorLimit); |
| 263 | 437 |
| 264 TestVideoPacketProcessing(2 * kDefaultScreenWidth, 2 * kDefaultScreenHeight, | 438 TestVideoPacketProcessing(2 * kDefaultScreenWidth, 2 * kDefaultScreenHeight, |
| 265 kDefaultErrorLimit); | 439 kDefaultErrorLimit); |
| 266 | 440 |
| 267 TestVideoPacketProcessing(kDefaultScreenWidth / 2, kDefaultScreenHeight / 2, | 441 TestVideoPacketProcessing(kDefaultScreenWidth / 2, kDefaultScreenHeight / 2, |
| 268 kDefaultErrorLimit); | 442 kDefaultErrorLimit); |
| 269 } | 443 } |
| 270 | 444 |
| 445 // Verify setting expected image pattern doesn't break video packet processing. | |
| 446 TEST_F(TestVideoRendererTest, VerifySetExpectedImagePattern) { | |
| 447 encoder_ = VideoEncoderVpx::CreateForVP8(); | |
| 448 test_video_renderer_->SetCodecForDecoding( | |
| 449 protocol::ChannelConfig::Codec::CODEC_VP8); | |
| 450 | |
| 451 DCHECK(encoder_); | |
| 452 DCHECK(test_video_renderer_); | |
| 453 | |
| 454 scoped_ptr<webrtc::DesktopFrame> frame = | |
| 455 CreateDesktopFrameWithGradient(kDefaultScreenWidth, kDefaultScreenHeight); | |
| 456 EXPECT_TRUE(frame); | |
| 457 | |
| 458 // Since we don't care whether expected image pattern is matched or not in | |
| 459 // this case, an expected color is chosen arbitrarily. | |
| 460 RGBA32 expected_color = 0xFF000000; | |
|
joedow
2015/07/10 23:39:16
nit: I'd change the var name to reflect the color
liaoyuke
2015/07/13 16:05:39
Done.
| |
| 461 | |
| 462 // Set expected image pattern. | |
| 463 test_video_renderer_->SetImagePatternAndMatchedCallback( | |
| 464 kDefaultExpectedRect, expected_color, base::Bind(&base::DoNothing)); | |
| 465 | |
| 466 // Post test video packet. | |
| 467 scoped_ptr<VideoPacket> packet = encoder_->Encode(*frame.get()); | |
| 468 test_video_renderer_->ProcessVideoPacket(packet.Pass(), | |
| 469 base::Bind(&base::DoNothing)); | |
| 470 } | |
| 471 | |
| 472 // Verify correct image pattern can be matched for VP8. | |
| 473 TEST_F(TestVideoRendererTest, VerifyImagePatternMatchForVP8) { | |
| 474 encoder_ = VideoEncoderVpx::CreateForVP8(); | |
| 475 test_video_renderer_->SetCodecForDecoding( | |
| 476 protocol::ChannelConfig::Codec::CODEC_VP8); | |
| 477 TestImagePatternMatchAndCallback(kDefaultScreenWidth, kDefaultScreenHeight, | |
| 478 kDefaultExpectedRect); | |
| 479 } | |
| 480 | |
| 481 // Verify expected image pattern can be matched for VP9. | |
| 482 TEST_F(TestVideoRendererTest, VerifyImagePatternMatchForVP9) { | |
| 483 encoder_ = VideoEncoderVpx::CreateForVP9(); | |
| 484 test_video_renderer_->SetCodecForDecoding( | |
| 485 protocol::ChannelConfig::Codec::CODEC_VP9); | |
| 486 TestImagePatternMatchAndCallback(kDefaultScreenWidth, kDefaultScreenHeight, | |
| 487 kDefaultExpectedRect); | |
| 488 } | |
| 489 | |
| 490 // Verify expected image pattern can be matched for VERBATIM. | |
| 491 TEST_F(TestVideoRendererTest, VerifyImagePatternMatchForVERBATIM) { | |
| 492 encoder_.reset(new VideoEncoderVerbatim()); | |
| 493 test_video_renderer_->SetCodecForDecoding( | |
| 494 protocol::ChannelConfig::Codec::CODEC_VERBATIM); | |
| 495 TestImagePatternMatchAndCallback(kDefaultScreenWidth, kDefaultScreenHeight, | |
| 496 kDefaultExpectedRect); | |
| 497 } | |
| 498 | |
| 499 // Verify incorrect image pattern shouldn't be matched for VP8. | |
| 500 TEST_F(TestVideoRendererTest, VerifyImagePatternNotMatchForVP8) { | |
| 501 encoder_ = VideoEncoderVpx::CreateForVP8(); | |
| 502 test_video_renderer_->SetCodecForDecoding( | |
| 503 protocol::ChannelConfig::Codec::CODEC_VP8); | |
| 504 TestImagePatternNotMatch(kDefaultScreenWidth, kDefaultScreenHeight, | |
| 505 kDefaultExpectedRect); | |
| 506 } | |
| 507 | |
| 508 // Verify incorrect image pattern shouldn't be matched for VP9. | |
| 509 TEST_F(TestVideoRendererTest, VerifyImagePatternNotMatchForVP9) { | |
| 510 encoder_ = VideoEncoderVpx::CreateForVP9(); | |
| 511 test_video_renderer_->SetCodecForDecoding( | |
| 512 protocol::ChannelConfig::Codec::CODEC_VP9); | |
| 513 TestImagePatternNotMatch(kDefaultScreenWidth, kDefaultScreenWidth, | |
| 514 kDefaultExpectedRect); | |
| 515 } | |
| 516 | |
| 517 // Verify incorrect image pattern shouldn't be matched for VERBATIM. | |
| 518 TEST_F(TestVideoRendererTest, VerifyImagePatternNotMatchForVERBATIM) { | |
| 519 encoder_.reset(new VideoEncoderVerbatim()); | |
| 520 test_video_renderer_->SetCodecForDecoding( | |
| 521 protocol::ChannelConfig::Codec::CODEC_VERBATIM); | |
| 522 TestImagePatternNotMatch(kDefaultScreenWidth, kDefaultScreenHeight, | |
| 523 kDefaultExpectedRect); | |
| 524 } | |
| 525 | |
| 271 } // namespace test | 526 } // namespace test |
| 272 } // namespace remoting | 527 } // namespace remoting |
| OLD | NEW |