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

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

Issue 1090273006: Revert of VideoCapture: add support for GpuMemoryBuffer allocation and lifetime mgmt in VideoCaptureBufferPool (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
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/media/capture/web_contents_video_capture_device.h" 5 #include "content/browser/media/capture/web_contents_video_capture_device.h"
6 6
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/debug/debugger.h" 8 #include "base/debug/debugger.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/test/test_timeouts.h" 10 #include "base/test/test_timeouts.h"
(...skipping 12 matching lines...) Expand all
23 #include "content/public/test/test_browser_context.h" 23 #include "content/public/test/test_browser_context.h"
24 #include "content/public/test/test_browser_thread_bundle.h" 24 #include "content/public/test/test_browser_thread_bundle.h"
25 #include "content/public/test/test_utils.h" 25 #include "content/public/test/test_utils.h"
26 #include "content/test/test_render_view_host.h" 26 #include "content/test/test_render_view_host.h"
27 #include "content/test/test_web_contents.h" 27 #include "content/test/test_web_contents.h"
28 #include "media/base/video_capture_types.h" 28 #include "media/base/video_capture_types.h"
29 #include "media/base/video_frame.h" 29 #include "media/base/video_frame.h"
30 #include "media/base/video_util.h" 30 #include "media/base/video_util.h"
31 #include "media/base/yuv_convert.h" 31 #include "media/base/yuv_convert.h"
32 #include "skia/ext/platform_canvas.h" 32 #include "skia/ext/platform_canvas.h"
33 #include "testing/gmock/include/gmock/gmock.h"
34 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
35 #include "third_party/skia/include/core/SkColor.h" 34 #include "third_party/skia/include/core/SkColor.h"
36 #include "ui/gfx/display.h" 35 #include "ui/gfx/display.h"
37 #include "ui/gfx/screen.h" 36 #include "ui/gfx/screen.h"
38 37
39 namespace content { 38 namespace content {
40 namespace { 39 namespace {
41 40
42 const int kTestWidth = 320; 41 const int kTestWidth = 320;
43 const int kTestHeight = 240; 42 const int kTestHeight = 240;
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 class StubClient : public media::VideoCaptureDevice::Client { 308 class StubClient : public media::VideoCaptureDevice::Client {
310 public: 309 public:
311 StubClient(const base::Callback<void(SkColor)>& color_callback, 310 StubClient(const base::Callback<void(SkColor)>& color_callback,
312 const base::Closure& error_callback) 311 const base::Closure& error_callback)
313 : color_callback_(color_callback), 312 : color_callback_(color_callback),
314 error_callback_(error_callback) { 313 error_callback_(error_callback) {
315 buffer_pool_ = new VideoCaptureBufferPool(2); 314 buffer_pool_ = new VideoCaptureBufferPool(2);
316 } 315 }
317 ~StubClient() override {} 316 ~StubClient() override {}
318 317
319 MOCK_METHOD5(OnIncomingCapturedData, 318 void OnIncomingCapturedData(const uint8* data,
320 void(const uint8* data, 319 int length,
321 int length, 320 const media::VideoCaptureFormat& frame_format,
322 const media::VideoCaptureFormat& frame_format, 321 int rotation,
323 int rotation, 322 const base::TimeTicks& timestamp) override {
324 const base::TimeTicks& timestamp)); 323 FAIL();
325 MOCK_METHOD9(OnIncomingCapturedYuvData, 324 }
326 void (const uint8* y_data,
327 const uint8* u_data,
328 const uint8* v_data,
329 size_t y_stride,
330 size_t u_stride,
331 size_t v_stride,
332 const media::VideoCaptureFormat& frame_format,
333 int clockwise_rotation,
334 const base::TimeTicks& timestamp));
335 325
336 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); 326 void OnIncomingCapturedYuvData(const uint8* y_data,
327 const uint8* u_data,
328 const uint8* v_data,
329 size_t y_stride,
330 size_t u_stride,
331 size_t v_stride,
332 const media::VideoCaptureFormat& frame_format,
333 int clockwise_rotation,
334 const base::TimeTicks& timestamp) override {
335 FAIL();
336 }
337 337
338 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> ReserveOutputBuffer( 338 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> ReserveOutputBuffer(
339 media::VideoPixelFormat format, 339 media::VideoPixelFormat format,
340 const gfx::Size& dimensions) override { 340 const gfx::Size& dimensions) override {
341 CHECK_EQ(format, media::PIXEL_FORMAT_I420); 341 CHECK_EQ(format, media::PIXEL_FORMAT_I420);
342 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId; // Ignored. 342 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId; // Ignored.
343 int buffer_id = buffer_pool_->ReserveForProducer(format, dimensions, 343 int buffer_id = buffer_pool_->ReserveForProducer(format, dimensions,
344 &buffer_id_to_drop); 344 &buffer_id_to_drop);
345 if (buffer_id == VideoCaptureBufferPool::kInvalidId) 345 if (buffer_id == VideoCaptureBufferPool::kInvalidId)
346 return NULL; 346 return NULL;
347 347 void* data;
348 return scoped_ptr<media::VideoCaptureDevice::Client::Buffer>( 348 size_t size;
349 new AutoReleaseBuffer( 349 buffer_pool_->GetBufferInfo(buffer_id, &data, &size);
350 buffer_pool_, buffer_pool_->GetBufferHandle(buffer_id), buffer_id)); 350 return scoped_refptr<media::VideoCaptureDevice::Client::Buffer>(
351 } 351 new AutoReleaseBuffer(buffer_pool_, buffer_id, data, size));
352 // Trampoline method to workaround GMOCK problems with scoped_ptr<>.
353 void OnIncomingCapturedBuffer(scoped_ptr<Buffer> buffer,
354 const media::VideoCaptureFormat& frame_format,
355 const base::TimeTicks& timestamp) override {
356 DoOnIncomingCapturedBuffer();
357 } 352 }
358 353
359 void OnIncomingCapturedVideoFrame( 354 void OnIncomingCapturedVideoFrame(
360 scoped_ptr<Buffer> buffer, 355 const scoped_refptr<Buffer>& buffer,
361 const scoped_refptr<media::VideoFrame>& frame, 356 const scoped_refptr<media::VideoFrame>& frame,
362 const base::TimeTicks& timestamp) override { 357 const base::TimeTicks& timestamp) override {
363 EXPECT_EQ(gfx::Size(kTestWidth, kTestHeight), frame->visible_rect().size()); 358 EXPECT_EQ(gfx::Size(kTestWidth, kTestHeight), frame->visible_rect().size());
364 EXPECT_EQ(media::VideoFrame::I420, frame->format()); 359 EXPECT_EQ(media::VideoFrame::I420, frame->format());
365 double frame_rate = 0; 360 double frame_rate = 0;
366 EXPECT_TRUE( 361 EXPECT_TRUE(
367 frame->metadata()->GetDouble(media::VideoFrameMetadata::FRAME_RATE, 362 frame->metadata()->GetDouble(media::VideoFrameMetadata::FRAME_RATE,
368 &frame_rate)); 363 &frame_rate));
369 EXPECT_EQ(kTestFramesPerSecond, frame_rate); 364 EXPECT_EQ(kTestFramesPerSecond, frame_rate);
370 uint8 yuv[3]; 365 uint8 yuv[3];
371 for (int plane = 0; plane < 3; ++plane) 366 for (int plane = 0; plane < 3; ++plane)
372 yuv[plane] = frame->visible_data(plane)[0]; 367 yuv[plane] = frame->visible_data(plane)[0];
373 // TODO(nick): We just look at the first pixel presently, because if 368 // TODO(nick): We just look at the first pixel presently, because if
374 // the analysis is too slow, the backlog of frames will grow without bound 369 // the analysis is too slow, the backlog of frames will grow without bound
375 // and trouble erupts. http://crbug.com/174519 370 // and trouble erupts. http://crbug.com/174519
376 color_callback_.Run((SkColorSetRGB(yuv[0], yuv[1], yuv[2]))); 371 color_callback_.Run((SkColorSetRGB(yuv[0], yuv[1], yuv[2])));
377 } 372 }
378 373
379 void OnError(const std::string& reason) override { error_callback_.Run(); } 374 void OnError(const std::string& reason) override { error_callback_.Run(); }
380 375
381 private: 376 private:
382 class AutoReleaseBuffer : public media::VideoCaptureDevice::Client::Buffer { 377 class AutoReleaseBuffer : public media::VideoCaptureDevice::Client::Buffer {
383 public: 378 public:
384 AutoReleaseBuffer( 379 AutoReleaseBuffer(const scoped_refptr<VideoCaptureBufferPool>& pool,
385 const scoped_refptr<VideoCaptureBufferPool>& pool, 380 int buffer_id,
386 scoped_ptr<VideoCaptureBufferPool::BufferHandle> buffer_handle, 381 void* data,
387 int buffer_id) 382 size_t size)
388 : id_(buffer_id), 383 : pool_(pool),
389 pool_(pool), 384 id_(buffer_id),
390 buffer_handle_(buffer_handle.Pass()) { 385 data_(data),
386 size_(size) {
391 DCHECK(pool_.get()); 387 DCHECK(pool_.get());
392 } 388 }
393 int id() const override { return id_; } 389 int id() const override { return id_; }
394 size_t size() const override { return buffer_handle_->size(); } 390 void* data() const override { return data_; }
395 void* data() override { return buffer_handle_->data(); } 391 size_t size() const override { return size_; }
396 ClientBuffer AsClientBuffer() override { return nullptr; }
397 392
398 private: 393 private:
399 ~AutoReleaseBuffer() override { pool_->RelinquishProducerReservation(id_); } 394 ~AutoReleaseBuffer() override { pool_->RelinquishProducerReservation(id_); }
400 395
396 const scoped_refptr<VideoCaptureBufferPool> pool_;
401 const int id_; 397 const int id_;
402 const scoped_refptr<VideoCaptureBufferPool> pool_; 398 void* const data_;
403 const scoped_ptr<VideoCaptureBufferPool::BufferHandle> buffer_handle_; 399 const size_t size_;
404 }; 400 };
405 401
406 scoped_refptr<VideoCaptureBufferPool> buffer_pool_; 402 scoped_refptr<VideoCaptureBufferPool> buffer_pool_;
407 base::Callback<void(SkColor)> color_callback_; 403 base::Callback<void(SkColor)> color_callback_;
408 base::Closure error_callback_; 404 base::Closure error_callback_;
409 405
410 DISALLOW_COPY_AND_ASSIGN(StubClient); 406 DISALLOW_COPY_AND_ASSIGN(StubClient);
411 }; 407 };
412 408
413 class StubClientObserver { 409 class StubClientObserver {
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 source()->SetSolidColor(SK_ColorGREEN); 867 source()->SetSolidColor(SK_ColorGREEN);
872 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); 868 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN));
873 source()->SetSolidColor(SK_ColorRED); 869 source()->SetSolidColor(SK_ColorRED);
874 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); 870 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED));
875 871
876 device()->StopAndDeAllocate(); 872 device()->StopAndDeAllocate();
877 } 873 }
878 874
879 } // namespace 875 } // namespace
880 } // namespace content 876 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698