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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
7 #include "base/thread_task_runner_handle.h" | 7 #include "base/thread_task_runner_handle.h" |
8 #include "content/child/child_process.h" | 8 #include "content/child/child_process.h" |
9 #include "content/renderer/media/canvas_capture_handler.h" | 9 #include "content/renderer/media/canvas_capture_handler.h" |
10 #include "content/renderer/media/media_stream_video_capturer_source.h" | 10 #include "content/renderer/media/media_stream_video_capturer_source.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
26 namespace content { | 26 namespace content { |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 static const int kTestCanvasCaptureWidth = 320; | 30 static const int kTestCanvasCaptureWidth = 320; |
31 static const int kTestCanvasCaptureHeight = 240; | 31 static const int kTestCanvasCaptureHeight = 240; |
32 static const double kTestCanvasCaptureFramesPerSecond = 55.5; | 32 static const double kTestCanvasCaptureFramesPerSecond = 55.5; |
33 | 33 |
34 static const int kTestCanvasCaptureFrameWidth = 2; | 34 static const int kTestCanvasCaptureFrameWidth = 2; |
35 static const int kTestCanvasCaptureFrameHeight = 2; | 35 static const int kTestCanvasCaptureFrameHeight = 2; |
36 static const int kTestCanvasCaptureFrameErrorTolerance = 2; | 36 static const int kTestCanvasOddSizeOffset = 1; |
37 static const int kTestCanvasCaptureFrameColorErrorTolerance = 2; | |
37 static const int kTestAlphaValue = 175; | 38 static const int kTestAlphaValue = 175; |
38 | 39 |
39 ACTION_P(RunClosure, closure) { | 40 ACTION_P(RunClosure, closure) { |
40 closure.Run(); | 41 closure.Run(); |
41 } | 42 } |
42 | 43 |
43 } // namespace | 44 } // namespace |
44 | 45 |
45 class CanvasCaptureHandlerTest : public TestWithParam<bool> { | 46 class CanvasCaptureHandlerTest |
47 : public TestWithParam<testing::tuple<bool, bool>> { | |
46 public: | 48 public: |
47 CanvasCaptureHandlerTest() {} | 49 CanvasCaptureHandlerTest() {} |
48 | 50 |
49 void SetUp() override { | 51 void SetUp() override { |
50 canvas_capture_handler_.reset( | 52 canvas_capture_handler_.reset( |
51 CanvasCaptureHandler::CreateCanvasCaptureHandler( | 53 CanvasCaptureHandler::CreateCanvasCaptureHandler( |
52 blink::WebSize(kTestCanvasCaptureWidth, kTestCanvasCaptureHeight), | 54 blink::WebSize(kTestCanvasCaptureWidth, kTestCanvasCaptureHeight), |
53 kTestCanvasCaptureFramesPerSecond, message_loop_.task_runner(), | 55 kTestCanvasCaptureFramesPerSecond, message_loop_.task_runner(), |
54 &track_)); | 56 &track_)); |
55 } | 57 } |
(...skipping 18 matching lines...) Expand all Loading... | |
74 MOCK_METHOD1(DoOnVideoCaptureDeviceFormats, | 76 MOCK_METHOD1(DoOnVideoCaptureDeviceFormats, |
75 void(const media::VideoCaptureFormats&)); | 77 void(const media::VideoCaptureFormats&)); |
76 void OnVideoCaptureDeviceFormats(const media::VideoCaptureFormats& formats) { | 78 void OnVideoCaptureDeviceFormats(const media::VideoCaptureFormats& formats) { |
77 DoOnVideoCaptureDeviceFormats(formats); | 79 DoOnVideoCaptureDeviceFormats(formats); |
78 } | 80 } |
79 | 81 |
80 MOCK_METHOD1(DoOnRunning, void(bool)); | 82 MOCK_METHOD1(DoOnRunning, void(bool)); |
81 void OnRunning(bool state) { DoOnRunning(state); } | 83 void OnRunning(bool state) { DoOnRunning(state); } |
82 | 84 |
83 // Verify returned frames. | 85 // Verify returned frames. |
84 static sk_sp<SkImage> GenerateTestImage(bool opaque) { | 86 static sk_sp<SkImage> GenerateTestImage(bool opaque, bool odd_size) { |
85 | |
86 SkBitmap testBitmap; | 87 SkBitmap testBitmap; |
87 testBitmap.allocN32Pixels(kTestCanvasCaptureFrameWidth, | 88 const int offset = odd_size ? kTestCanvasOddSizeOffset : 0; |
mcasas
2016/04/26 00:07:14
I'd say: Just use an integer parameter for the tes
emircan
2016/04/26 19:47:07
Done.
| |
88 kTestCanvasCaptureFrameHeight, opaque); | 89 testBitmap.allocN32Pixels(kTestCanvasCaptureFrameWidth + offset, |
90 kTestCanvasCaptureFrameHeight + offset, opaque); | |
89 testBitmap.eraseARGB(kTestAlphaValue, 30, 60, 200); | 91 testBitmap.eraseARGB(kTestAlphaValue, 30, 60, 200); |
90 return SkImage::MakeFromBitmap(testBitmap); | 92 return SkImage::MakeFromBitmap(testBitmap); |
91 } | 93 } |
92 | 94 |
93 void OnVerifyDeliveredFrame( | 95 void OnVerifyDeliveredFrame( |
94 bool opaque, | 96 bool opaque, |
97 bool odd_size, | |
95 const scoped_refptr<media::VideoFrame>& video_frame, | 98 const scoped_refptr<media::VideoFrame>& video_frame, |
96 base::TimeTicks estimated_capture_time) { | 99 base::TimeTicks estimated_capture_time) { |
97 if (opaque) | 100 if (opaque) |
98 EXPECT_EQ(media::PIXEL_FORMAT_I420, video_frame->format()); | 101 EXPECT_EQ(media::PIXEL_FORMAT_I420, video_frame->format()); |
99 else | 102 else |
100 EXPECT_EQ(media::PIXEL_FORMAT_YV12A, video_frame->format()); | 103 EXPECT_EQ(media::PIXEL_FORMAT_YV12A, video_frame->format()); |
101 | 104 |
102 EXPECT_EQ(video_frame->timestamp().InMilliseconds(), | 105 EXPECT_EQ(video_frame->timestamp().InMilliseconds(), |
103 (estimated_capture_time - base::TimeTicks()).InMilliseconds()); | 106 (estimated_capture_time - base::TimeTicks()).InMilliseconds()); |
104 const gfx::Size& size = video_frame->coded_size(); | 107 const int offset = odd_size ? kTestCanvasOddSizeOffset : 0; |
105 EXPECT_EQ(kTestCanvasCaptureFrameWidth, size.width()); | 108 const gfx::Size& size = video_frame->visible_rect().size(); |
106 EXPECT_EQ(kTestCanvasCaptureFrameHeight, size.height()); | 109 EXPECT_EQ(kTestCanvasCaptureFrameWidth + offset, size.width()); |
107 const uint8_t* y_plane = video_frame->data(media::VideoFrame::kYPlane); | 110 EXPECT_EQ(kTestCanvasCaptureFrameHeight + offset, size.height()); |
108 EXPECT_NEAR(74, y_plane[0], kTestCanvasCaptureFrameErrorTolerance); | 111 const uint8_t* y_plane = |
109 const uint8_t* u_plane = video_frame->data(media::VideoFrame::kUPlane); | 112 video_frame->visible_data(media::VideoFrame::kYPlane); |
110 EXPECT_NEAR(193, u_plane[0], kTestCanvasCaptureFrameErrorTolerance); | 113 EXPECT_NEAR(74, y_plane[0], kTestCanvasCaptureFrameColorErrorTolerance); |
111 const uint8_t* v_plane = video_frame->data(media::VideoFrame::kVPlane); | 114 const uint8_t* u_plane = |
112 EXPECT_NEAR(105, v_plane[0], kTestCanvasCaptureFrameErrorTolerance); | 115 video_frame->visible_data(media::VideoFrame::kUPlane); |
116 EXPECT_NEAR(193, u_plane[0], kTestCanvasCaptureFrameColorErrorTolerance); | |
117 const uint8_t* v_plane = | |
118 video_frame->visible_data(media::VideoFrame::kVPlane); | |
119 EXPECT_NEAR(105, v_plane[0], kTestCanvasCaptureFrameColorErrorTolerance); | |
113 if (!opaque) { | 120 if (!opaque) { |
114 const uint8_t* a_plane = video_frame->data(media::VideoFrame::kAPlane); | 121 const uint8_t* a_plane = |
122 video_frame->visible_data(media::VideoFrame::kAPlane); | |
115 EXPECT_EQ(kTestAlphaValue, a_plane[0]); | 123 EXPECT_EQ(kTestAlphaValue, a_plane[0]); |
116 } | 124 } |
117 } | 125 } |
118 | 126 |
119 blink::WebMediaStreamTrack track_; | 127 blink::WebMediaStreamTrack track_; |
120 // The Class under test. Needs to be scoped_ptr to force its destruction. | 128 // The Class under test. Needs to be scoped_ptr to force its destruction. |
121 std::unique_ptr<CanvasCaptureHandler> canvas_capture_handler_; | 129 std::unique_ptr<CanvasCaptureHandler> canvas_capture_handler_; |
122 | 130 |
123 protected: | 131 protected: |
124 media::VideoCapturerSource* GetVideoCapturerSource( | 132 media::VideoCapturerSource* GetVideoCapturerSource( |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 base::RunLoop run_loop; | 194 base::RunLoop run_loop; |
187 base::Closure quit_closure = run_loop.QuitClosure(); | 195 base::Closure quit_closure = run_loop.QuitClosure(); |
188 EXPECT_CALL(*this, DoOnRunning(true)).Times(1); | 196 EXPECT_CALL(*this, DoOnRunning(true)).Times(1); |
189 EXPECT_CALL(*this, DoOnDeliverFrame(_, _)) | 197 EXPECT_CALL(*this, DoOnDeliverFrame(_, _)) |
190 .Times(1) | 198 .Times(1) |
191 .WillOnce(RunClosure(quit_closure)); | 199 .WillOnce(RunClosure(quit_closure)); |
192 source->StartCapture( | 200 source->StartCapture( |
193 params, base::Bind(&CanvasCaptureHandlerTest::OnDeliverFrame, | 201 params, base::Bind(&CanvasCaptureHandlerTest::OnDeliverFrame, |
194 base::Unretained(this)), | 202 base::Unretained(this)), |
195 base::Bind(&CanvasCaptureHandlerTest::OnRunning, base::Unretained(this))); | 203 base::Bind(&CanvasCaptureHandlerTest::OnRunning, base::Unretained(this))); |
196 canvas_capture_handler_->sendNewFrame(GenerateTestImage(GetParam()).get()); | 204 canvas_capture_handler_->sendNewFrame(GenerateTestImage( |
205 testing::get<0>(GetParam()), testing::get<1>(GetParam())).get()); | |
197 run_loop.Run(); | 206 run_loop.Run(); |
198 | 207 |
199 source->StopCapture(); | 208 source->StopCapture(); |
200 } | 209 } |
201 | 210 |
202 // Verifies that SkImage is processed and produces VideoFrame as expected. | 211 // Verifies that SkImage is processed and produces VideoFrame as expected. |
203 TEST_P(CanvasCaptureHandlerTest, VerifyOpaqueFrame) { | 212 TEST_P(CanvasCaptureHandlerTest, VerifyFrame) { |
204 const bool isOpaque = GetParam(); | 213 const bool opaque_frame = testing::get<0>(GetParam()); |
214 const bool odd_size_frame = testing::get<1>(GetParam()); | |
205 InSequence s; | 215 InSequence s; |
206 media::VideoCapturerSource* const source = | 216 media::VideoCapturerSource* const source = |
207 GetVideoCapturerSource(static_cast<MediaStreamVideoCapturerSource*>( | 217 GetVideoCapturerSource(static_cast<MediaStreamVideoCapturerSource*>( |
208 track_.source().getExtraData())); | 218 track_.source().getExtraData())); |
209 EXPECT_TRUE(source != nullptr); | 219 EXPECT_TRUE(source != nullptr); |
210 | 220 |
211 base::RunLoop run_loop; | 221 base::RunLoop run_loop; |
212 EXPECT_CALL(*this, DoOnRunning(true)).Times(1); | 222 EXPECT_CALL(*this, DoOnRunning(true)).Times(1); |
213 media::VideoCaptureParams params; | 223 media::VideoCaptureParams params; |
214 source->StartCapture( | 224 source->StartCapture( |
215 params, base::Bind(&CanvasCaptureHandlerTest::OnVerifyDeliveredFrame, | 225 params, base::Bind(&CanvasCaptureHandlerTest::OnVerifyDeliveredFrame, |
216 base::Unretained(this), isOpaque), | 226 base::Unretained(this), opaque_frame, odd_size_frame), |
217 base::Bind(&CanvasCaptureHandlerTest::OnRunning, base::Unretained(this))); | 227 base::Bind(&CanvasCaptureHandlerTest::OnRunning, base::Unretained(this))); |
218 canvas_capture_handler_->sendNewFrame(GenerateTestImage(isOpaque).get()); | 228 canvas_capture_handler_->sendNewFrame( |
229 GenerateTestImage(opaque_frame, odd_size_frame).get()); | |
219 run_loop.RunUntilIdle(); | 230 run_loop.RunUntilIdle(); |
220 } | 231 } |
221 | 232 |
222 // Checks that needsNewFrame() works as expected. | 233 // Checks that needsNewFrame() works as expected. |
223 TEST_F(CanvasCaptureHandlerTest, CheckNeedsNewFrame) { | 234 TEST_F(CanvasCaptureHandlerTest, CheckNeedsNewFrame) { |
224 InSequence s; | 235 InSequence s; |
225 media::VideoCapturerSource* source = | 236 media::VideoCapturerSource* source = |
226 GetVideoCapturerSource(static_cast<MediaStreamVideoCapturerSource*>( | 237 GetVideoCapturerSource(static_cast<MediaStreamVideoCapturerSource*>( |
227 track_.source().getExtraData())); | 238 track_.source().getExtraData())); |
228 EXPECT_TRUE(source != nullptr); | 239 EXPECT_TRUE(source != nullptr); |
229 EXPECT_TRUE(canvas_capture_handler_->needsNewFrame()); | 240 EXPECT_TRUE(canvas_capture_handler_->needsNewFrame()); |
230 source->StopCapture(); | 241 source->StopCapture(); |
231 EXPECT_FALSE(canvas_capture_handler_->needsNewFrame()); | 242 EXPECT_FALSE(canvas_capture_handler_->needsNewFrame()); |
232 } | 243 } |
233 | 244 |
234 INSTANTIATE_TEST_CASE_P(, CanvasCaptureHandlerTest, ::testing::Bool()); | 245 INSTANTIATE_TEST_CASE_P(, |
246 CanvasCaptureHandlerTest, | |
247 ::testing::Combine(::testing::Bool(), | |
248 ::testing::Bool())); | |
235 | 249 |
236 } // namespace content | 250 } // namespace content |
OLD | NEW |