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

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

Issue 2361173002: Move classses VideoCaptureDeviceClient and VideoCaptureBufferPool to media/capture/video (Closed)
Patch Set: mcasas@ comments Created 4 years, 2 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 | « content/browser/BUILD.gn ('k') | content/browser/renderer_host/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/debug/debugger.h" 13 #include "base/debug/debugger.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/test/test_timeouts.h" 17 #include "base/test/test_timeouts.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "base/timer/timer.h" 19 #include "base/timer/timer.h"
20 #include "build/build_config.h" 20 #include "build/build_config.h"
21 #include "content/browser/browser_thread_impl.h" 21 #include "content/browser/browser_thread_impl.h"
22 #include "content/browser/frame_host/render_frame_host_impl.h" 22 #include "content/browser/frame_host/render_frame_host_impl.h"
23 #include "content/browser/renderer_host/media/video_capture_buffer_handle.h" 23 #include "content/browser/renderer_host/media/video_capture_buffer_tracker_facto ry_impl.h"
24 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h"
25 #include "content/browser/renderer_host/render_view_host_factory.h" 24 #include "content/browser/renderer_host/render_view_host_factory.h"
26 #include "content/browser/renderer_host/render_widget_host_impl.h" 25 #include "content/browser/renderer_host/render_widget_host_impl.h"
27 #include "content/browser/web_contents/web_contents_impl.h" 26 #include "content/browser/web_contents/web_contents_impl.h"
28 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" 27 #include "content/public/browser/render_widget_host_view_frame_subscriber.h"
29 #include "content/public/browser/web_contents_media_capture_id.h" 28 #include "content/public/browser/web_contents_media_capture_id.h"
30 #include "content/public/test/mock_render_process_host.h" 29 #include "content/public/test/mock_render_process_host.h"
31 #include "content/public/test/test_browser_context.h" 30 #include "content/public/test/test_browser_context.h"
32 #include "content/public/test/test_browser_thread_bundle.h" 31 #include "content/public/test/test_browser_thread_bundle.h"
33 #include "content/public/test/test_utils.h" 32 #include "content/public/test/test_utils.h"
34 #include "content/test/test_render_frame_host_factory.h" 33 #include "content/test/test_render_frame_host_factory.h"
35 #include "content/test/test_render_view_host.h" 34 #include "content/test/test_render_view_host.h"
36 #include "content/test/test_web_contents.h" 35 #include "content/test/test_web_contents.h"
37 #include "media/base/video_capture_types.h" 36 #include "media/base/video_capture_types.h"
38 #include "media/base/video_frame.h" 37 #include "media/base/video_frame.h"
39 #include "media/base/video_util.h" 38 #include "media/base/video_util.h"
40 #include "media/base/yuv_convert.h" 39 #include "media/base/yuv_convert.h"
40 #include "media/capture/video/video_capture_buffer_pool_impl.h"
41 #include "skia/ext/platform_canvas.h" 41 #include "skia/ext/platform_canvas.h"
42 #include "testing/gmock/include/gmock/gmock.h" 42 #include "testing/gmock/include/gmock/gmock.h"
43 #include "testing/gtest/include/gtest/gtest.h" 43 #include "testing/gtest/include/gtest/gtest.h"
44 #include "third_party/skia/include/core/SkColor.h" 44 #include "third_party/skia/include/core/SkColor.h"
45 #include "ui/base/layout.h" 45 #include "ui/base/layout.h"
46 #include "ui/display/display.h" 46 #include "ui/display/display.h"
47 #include "ui/display/screen.h" 47 #include "ui/display/screen.h"
48 #include "ui/display/test/test_screen.h" 48 #include "ui/display/test/test_screen.h"
49 #include "ui/gfx/geometry/dip_util.h" 49 #include "ui/gfx/geometry/dip_util.h"
50 #include "ui/gfx/geometry/size_conversions.h" 50 #include "ui/gfx/geometry/size_conversions.h"
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 326
327 // A stub consumer of captured video frames, which checks the output of 327 // A stub consumer of captured video frames, which checks the output of
328 // WebContentsVideoCaptureDevice. 328 // WebContentsVideoCaptureDevice.
329 class StubClient : public media::VideoCaptureDevice::Client { 329 class StubClient : public media::VideoCaptureDevice::Client {
330 public: 330 public:
331 StubClient( 331 StubClient(
332 const base::Callback<void(SkColor, const gfx::Size&)>& report_callback, 332 const base::Callback<void(SkColor, const gfx::Size&)>& report_callback,
333 const base::Closure& error_callback) 333 const base::Closure& error_callback)
334 : report_callback_(report_callback), 334 : report_callback_(report_callback),
335 error_callback_(error_callback) { 335 error_callback_(error_callback) {
336 buffer_pool_ = new VideoCaptureBufferPoolImpl(2); 336 buffer_pool_ = new media::VideoCaptureBufferPoolImpl(
337 base::MakeUnique<VideoCaptureBufferTrackerFactoryImpl>(), 2);
337 } 338 }
338 ~StubClient() override {} 339 ~StubClient() override {}
339 340
340 MOCK_METHOD6(OnIncomingCapturedData, 341 MOCK_METHOD6(OnIncomingCapturedData,
341 void(const uint8_t* data, 342 void(const uint8_t* data,
342 int length, 343 int length,
343 const media::VideoCaptureFormat& frame_format, 344 const media::VideoCaptureFormat& frame_format,
344 int rotation, 345 int rotation,
345 base::TimeTicks reference_time, 346 base::TimeTicks reference_time,
346 base::TimeDelta timestamp)); 347 base::TimeDelta timestamp));
347 348
348 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); 349 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void));
349 350
350 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> 351 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer>
351 ReserveOutputBuffer(const gfx::Size& dimensions, 352 ReserveOutputBuffer(const gfx::Size& dimensions,
352 media::VideoPixelFormat format, 353 media::VideoPixelFormat format,
353 media::VideoPixelStorage storage) override { 354 media::VideoPixelStorage storage) override {
354 CHECK_EQ(format, media::PIXEL_FORMAT_I420); 355 CHECK_EQ(format, media::PIXEL_FORMAT_I420);
355 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId; // Ignored. 356 int buffer_id_to_drop =
357 media::VideoCaptureBufferPool::kInvalidId; // Ignored.
356 const int buffer_id = buffer_pool_->ReserveForProducer( 358 const int buffer_id = buffer_pool_->ReserveForProducer(
357 dimensions, format, storage, &buffer_id_to_drop); 359 dimensions, format, storage, &buffer_id_to_drop);
358 if (buffer_id == VideoCaptureBufferPool::kInvalidId) 360 if (buffer_id == media::VideoCaptureBufferPool::kInvalidId)
359 return NULL; 361 return NULL;
360 362
361 return std::unique_ptr<media::VideoCaptureDevice::Client::Buffer>( 363 return std::unique_ptr<media::VideoCaptureDevice::Client::Buffer>(
362 new AutoReleaseBuffer( 364 new AutoReleaseBuffer(
363 buffer_pool_, buffer_pool_->GetBufferHandle(buffer_id), buffer_id)); 365 buffer_pool_, buffer_pool_->GetBufferHandle(buffer_id), buffer_id));
364 } 366 }
365 367
366 // Trampoline method to workaround GMOCK problems with std::unique_ptr<>. 368 // Trampoline method to workaround GMOCK problems with std::unique_ptr<>.
367 void OnIncomingCapturedBuffer(std::unique_ptr<Buffer> buffer, 369 void OnIncomingCapturedBuffer(std::unique_ptr<Buffer> buffer,
368 const media::VideoCaptureFormat& frame_format, 370 const media::VideoCaptureFormat& frame_format,
(...skipping 30 matching lines...) Expand all
399 frame->visible_rect().size()); 401 frame->visible_rect().size());
400 } 402 }
401 403
402 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> 404 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer>
403 ResurrectLastOutputBuffer(const gfx::Size& dimensions, 405 ResurrectLastOutputBuffer(const gfx::Size& dimensions,
404 media::VideoPixelFormat format, 406 media::VideoPixelFormat format,
405 media::VideoPixelStorage storage) override { 407 media::VideoPixelStorage storage) override {
406 CHECK_EQ(format, media::PIXEL_FORMAT_I420); 408 CHECK_EQ(format, media::PIXEL_FORMAT_I420);
407 const int buffer_id = 409 const int buffer_id =
408 buffer_pool_->ResurrectLastForProducer(dimensions, format, storage); 410 buffer_pool_->ResurrectLastForProducer(dimensions, format, storage);
409 if (buffer_id == VideoCaptureBufferPool::kInvalidId) 411 if (buffer_id == media::VideoCaptureBufferPool::kInvalidId)
410 return nullptr; 412 return nullptr;
411 return std::unique_ptr<media::VideoCaptureDevice::Client::Buffer>( 413 return std::unique_ptr<media::VideoCaptureDevice::Client::Buffer>(
412 new AutoReleaseBuffer( 414 new AutoReleaseBuffer(
413 buffer_pool_, buffer_pool_->GetBufferHandle(buffer_id), buffer_id)); 415 buffer_pool_, buffer_pool_->GetBufferHandle(buffer_id), buffer_id));
414 } 416 }
415 417
416 void OnError(const tracked_objects::Location& from_here, 418 void OnError(const tracked_objects::Location& from_here,
417 const std::string& reason) override { 419 const std::string& reason) override {
418 error_callback_.Run(); 420 error_callback_.Run();
419 } 421 }
420 422
421 double GetBufferPoolUtilization() const override { return 0.0; } 423 double GetBufferPoolUtilization() const override { return 0.0; }
422 424
423 private: 425 private:
424 class AutoReleaseBuffer : public media::VideoCaptureDevice::Client::Buffer { 426 class AutoReleaseBuffer : public media::VideoCaptureDevice::Client::Buffer {
425 public: 427 public:
426 AutoReleaseBuffer(const scoped_refptr<VideoCaptureBufferPool>& pool, 428 AutoReleaseBuffer(
427 std::unique_ptr<VideoCaptureBufferHandle> buffer_handle, 429 const scoped_refptr<media::VideoCaptureBufferPool>& pool,
428 int buffer_id) 430 std::unique_ptr<media::VideoCaptureBufferHandle> buffer_handle,
431 int buffer_id)
429 : id_(buffer_id), 432 : id_(buffer_id),
430 pool_(pool), 433 pool_(pool),
431 buffer_handle_(std::move(buffer_handle)) { 434 buffer_handle_(std::move(buffer_handle)) {
432 DCHECK(pool_); 435 DCHECK(pool_);
433 } 436 }
434 int id() const override { return id_; } 437 int id() const override { return id_; }
435 gfx::Size dimensions() const override { 438 gfx::Size dimensions() const override {
436 return buffer_handle_->dimensions(); 439 return buffer_handle_->dimensions();
437 } 440 }
438 size_t mapped_size() const override { 441 size_t mapped_size() const override {
439 return buffer_handle_->mapped_size(); 442 return buffer_handle_->mapped_size();
440 } 443 }
441 void* data(int plane) override { return buffer_handle_->data(plane); } 444 void* data(int plane) override { return buffer_handle_->data(plane); }
442 ClientBuffer AsClientBuffer(int plane) override { return nullptr; } 445 ClientBuffer AsClientBuffer(int plane) override { return nullptr; }
443 #if defined(OS_POSIX) && !defined(OS_MACOSX) 446 #if defined(OS_POSIX) && !defined(OS_MACOSX)
444 base::FileDescriptor AsPlatformFile() override { 447 base::FileDescriptor AsPlatformFile() override {
445 return base::FileDescriptor(); 448 return base::FileDescriptor();
446 } 449 }
447 #endif 450 #endif
448 451
449 private: 452 private:
450 ~AutoReleaseBuffer() override { pool_->RelinquishProducerReservation(id_); } 453 ~AutoReleaseBuffer() override { pool_->RelinquishProducerReservation(id_); }
451 454
452 const int id_; 455 const int id_;
453 const scoped_refptr<VideoCaptureBufferPool> pool_; 456 const scoped_refptr<media::VideoCaptureBufferPool> pool_;
454 const std::unique_ptr<VideoCaptureBufferHandle> buffer_handle_; 457 const std::unique_ptr<media::VideoCaptureBufferHandle> buffer_handle_;
455 }; 458 };
456 459
457 scoped_refptr<VideoCaptureBufferPool> buffer_pool_; 460 scoped_refptr<media::VideoCaptureBufferPool> buffer_pool_;
458 base::Callback<void(SkColor, const gfx::Size&)> report_callback_; 461 base::Callback<void(SkColor, const gfx::Size&)> report_callback_;
459 base::Closure error_callback_; 462 base::Closure error_callback_;
460 463
461 DISALLOW_COPY_AND_ASSIGN(StubClient); 464 DISALLOW_COPY_AND_ASSIGN(StubClient);
462 }; 465 };
463 466
464 class StubClientObserver { 467 class StubClientObserver {
465 public: 468 public:
466 StubClientObserver() 469 StubClientObserver()
467 : error_encountered_(false), 470 : error_encountered_(false),
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 for (int i = 0; i < 3; ++i) { 1212 for (int i = 0; i < 3; ++i) {
1210 SimulateRefreshFrameRequest(); 1213 SimulateRefreshFrameRequest();
1211 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); 1214 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN));
1212 } 1215 }
1213 1216
1214 device()->StopAndDeAllocate(); 1217 device()->StopAndDeAllocate();
1215 } 1218 }
1216 1219
1217 } // namespace 1220 } // namespace
1218 } // namespace content 1221 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/BUILD.gn ('k') | content/browser/renderer_host/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698