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

Side by Side Diff: content/browser/renderer_host/media/web_contents_video_capture_device_unittest.cc

Issue 12090109: Tab Capture: Backing store readbacks to YV12 VideoFrames. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Style fix per wjia Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/renderer_host/media/web_contents_video_capture_device. h" 5 #include "content/browser/renderer_host/media/web_contents_video_capture_device. h"
6 6
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/synchronization/condition_variable.h" 8 #include "base/synchronization/condition_variable.h"
9 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "base/time.h" 10 #include "base/time.h"
11 #include "content/browser/browser_thread_impl.h" 11 #include "content/browser/browser_thread_impl.h"
12 #include "content/browser/renderer_host/render_widget_host_delegate.h" 12 #include "content/browser/renderer_host/render_widget_host_delegate.h"
13 #include "content/browser/renderer_host/render_widget_host_impl.h" 13 #include "content/browser/renderer_host/render_widget_host_impl.h"
14 #include "content/public/test/mock_render_process_host.h" 14 #include "content/public/test/mock_render_process_host.h"
15 #include "content/public/test/test_browser_context.h" 15 #include "content/public/test/test_browser_context.h"
16 #include "media/base/video_util.h"
16 #include "media/video/capture/video_capture_types.h" 17 #include "media/video/capture/video_capture_types.h"
17 #include "skia/ext/platform_canvas.h" 18 #include "skia/ext/platform_canvas.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/skia/include/core/SkColor.h" 20 #include "third_party/skia/include/core/SkColor.h"
20 21
21 namespace content { 22 namespace content {
22 namespace { 23 namespace {
23 const int kTestWidth = 1280; 24 const int kTestWidth = 1280;
24 const int kTestHeight = 720; 25 const int kTestHeight = 720;
25 const int kBytesPerPixel = 4; 26 const int kBytesPerPixel = 4;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 146
146 { 147 {
147 base::AutoLock guard(lock_); 148 base::AutoLock guard(lock_);
148 if (color != picture_color_) { 149 if (color != picture_color_) {
149 picture_color_ = color; 150 picture_color_ = color;
150 output_changed_.Signal(); 151 output_changed_.Signal();
151 } 152 }
152 } 153 }
153 } 154 }
154 155
156 virtual void OnIncomingCapturedVideoFrame(media::VideoFrame* frame,
157 base::Time timestamp) OVERRIDE {
158 EXPECT_EQ(gfx::Size(kTestWidth, kTestHeight), frame->coded_size());
159 EXPECT_EQ(media::VideoFrame::YV12, frame->format());
160 bool all_pixels_are_the_same_color = true;
161 uint8 yuv[3] = {0};
162 for (int plane = 0; plane < 3; ++plane) {
163 yuv[plane] = frame->data(plane)[0];
164 for (int y = 0; y < frame->rows(plane); ++y) {
165 for (int x = 0; x < frame->row_bytes(plane); ++x) {
166 if (yuv[plane] != frame->data(plane)[x + y * frame->stride(plane)]) {
167 all_pixels_are_the_same_color = false;
168 break;
169 }
170 }
171 }
172 }
173 EXPECT_TRUE(all_pixels_are_the_same_color);
174 const SkColor color = SkColorSetRGB(yuv[0], yuv[1], yuv[2]);
175
176 {
177 base::AutoLock guard(lock_);
178 if (color != picture_color_) {
179 picture_color_ = color;
180 output_changed_.Signal();
181 }
182 }
183 }
184
155 virtual void OnError() OVERRIDE { 185 virtual void OnError() OVERRIDE {
156 base::AutoLock guard(lock_); 186 base::AutoLock guard(lock_);
157 error_encountered_ = true; 187 error_encountered_ = true;
158 output_changed_.Signal(); 188 output_changed_.Signal();
159 } 189 }
160 190
161 virtual void OnFrameInfo(const media::VideoCaptureCapability& info) OVERRIDE { 191 virtual void OnFrameInfo(const media::VideoCaptureCapability& info) OVERRIDE {
162 EXPECT_EQ(kTestWidth, info.width); 192 EXPECT_EQ(kTestWidth, info.width);
163 EXPECT_EQ(kTestHeight, info.height); 193 EXPECT_EQ(kTestHeight, info.height);
164 EXPECT_EQ(kTestFramesPerSecond, info.frame_rate); 194 EXPECT_EQ(kTestFramesPerSecond, info.frame_rate);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 scoped_ptr<StubRenderWidgetHost> source_; 259 scoped_ptr<StubRenderWidgetHost> source_;
230 scoped_ptr<base::WaitableEvent> destroyed_; 260 scoped_ptr<base::WaitableEvent> destroyed_;
231 scoped_ptr<media::VideoCaptureDevice> device_; 261 scoped_ptr<media::VideoCaptureDevice> device_;
232 scoped_ptr<StubConsumer> consumer_; 262 scoped_ptr<StubConsumer> consumer_;
233 263
234 DISALLOW_COPY_AND_ASSIGN(WebContentsVideoCaptureDeviceTest); 264 DISALLOW_COPY_AND_ASSIGN(WebContentsVideoCaptureDeviceTest);
235 }; 265 };
236 266
237 // The "happy case" test. No scaling is needed, so we should be able to change 267 // The "happy case" test. No scaling is needed, so we should be able to change
238 // the picture emitted from the source and expect to see each delivered to the 268 // the picture emitted from the source and expect to see each delivered to the
239 // consumer. 269 // consumer. The test will alternate between the SkBitmap and the VideoFrame
270 // paths, just as RenderWidgetHost might if the content falls in and out of
271 // accelerated compositing.
240 TEST_F(WebContentsVideoCaptureDeviceTest, GoesThroughAllTheMotions) { 272 TEST_F(WebContentsVideoCaptureDeviceTest, GoesThroughAllTheMotions) {
241 device()->Allocate(kTestWidth, kTestHeight, kTestFramesPerSecond, 273 device()->Allocate(kTestWidth, kTestHeight, kTestFramesPerSecond,
242 consumer()); 274 consumer());
243 275
244 device()->Start(); 276 device()->Start();
245 source()->SetSolidColor(SK_ColorRED); 277
246 EXPECT_TRUE(consumer()->WaitForNextColorOrError(SK_ColorRED)); 278 bool use_video_frames = false;
247 source()->SetSolidColor(SK_ColorGREEN); 279 for (int i = 0; i < 4; i++, use_video_frames = !use_video_frames) {
248 EXPECT_TRUE(consumer()->WaitForNextColorOrError(SK_ColorGREEN)); 280 SCOPED_TRACE(
249 source()->SetSolidColor(SK_ColorBLUE); 281 testing::Message() << "Using "
250 EXPECT_TRUE(consumer()->WaitForNextColorOrError(SK_ColorBLUE)); 282 << (use_video_frames ? "VideoFrame" : "SkBitmap")
251 source()->SetSolidColor(SK_ColorBLACK); 283 << " path, iteration #" << i);
252 EXPECT_TRUE(consumer()->WaitForNextColorOrError(SK_ColorBLACK)); 284 // TODO(nick): Implement this.
285 // source()->SetUseVideoFrames(use_video_frames);
286 source()->SetSolidColor(SK_ColorRED);
287 source()->WaitForNextBackingStoreCopy();
288 ASSERT_TRUE(consumer()->WaitForNextColorOrError(SK_ColorRED));
289 source()->SetSolidColor(SK_ColorGREEN);
290 ASSERT_TRUE(consumer()->WaitForNextColorOrError(SK_ColorGREEN));
291 source()->SetSolidColor(SK_ColorBLUE);
292 ASSERT_TRUE(consumer()->WaitForNextColorOrError(SK_ColorBLUE));
293 source()->SetSolidColor(SK_ColorBLACK);
294 ASSERT_TRUE(consumer()->WaitForNextColorOrError(SK_ColorBLACK));
295 }
253 296
254 device()->DeAllocate(); 297 device()->DeAllocate();
255 } 298 }
256 299
257 TEST_F(WebContentsVideoCaptureDeviceTest, RejectsInvalidAllocateParams) { 300 TEST_F(WebContentsVideoCaptureDeviceTest, RejectsInvalidAllocateParams) {
258 device()->Allocate(1280, 720, -2, consumer()); 301 device()->Allocate(1280, 720, -2, consumer());
259 EXPECT_FALSE(consumer()->WaitForNextColorOrError(kNotInterested)); 302 EXPECT_FALSE(consumer()->WaitForNextColorOrError(kNotInterested));
260 } 303 }
261 304
262 TEST_F(WebContentsVideoCaptureDeviceTest, BadFramesGoodFrames) { 305 TEST_F(WebContentsVideoCaptureDeviceTest, BadFramesGoodFrames) {
(...skipping 17 matching lines...) Expand all
280 // Now push some good frames through; they should be processed normally. 323 // Now push some good frames through; they should be processed normally.
281 source()->SetCopyResultSize(kTestWidth, kTestHeight); 324 source()->SetCopyResultSize(kTestWidth, kTestHeight);
282 source()->SetSolidColor(SK_ColorGREEN); 325 source()->SetSolidColor(SK_ColorGREEN);
283 EXPECT_TRUE(consumer()->WaitForNextColorOrError(SK_ColorGREEN)); 326 EXPECT_TRUE(consumer()->WaitForNextColorOrError(SK_ColorGREEN));
284 source()->SetSolidColor(SK_ColorRED); 327 source()->SetSolidColor(SK_ColorRED);
285 EXPECT_TRUE(consumer()->WaitForNextColorOrError(SK_ColorRED)); 328 EXPECT_TRUE(consumer()->WaitForNextColorOrError(SK_ColorRED));
286 device()->DeAllocate(); 329 device()->DeAllocate();
287 } 330 }
288 331
289 } // namespace content 332 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698