summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-28 08:56:20 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-28 08:56:20 +0000
commitfac792746fd46e9b64aedf45e0094200b8aed9db (patch)
treea48a1a5a708c0eea3cf87c342240e304d8ae9a98 /media
parent15443b7fa4263b624816023e249814885f1a31ec (diff)
downloadchromium_src-fac792746fd46e9b64aedf45e0094200b8aed9db.zip
chromium_src-fac792746fd46e9b64aedf45e0094200b8aed9db.tar.gz
chromium_src-fac792746fd46e9b64aedf45e0094200b8aed9db.tar.bz2
Refactor video capturing code in the render process
This is a large refactoring to cleanup the code that handles video capturing in the render process. The goal of this change is to: * Simplify threading model for objects involved. * Clarify ownership model. * Remove extra complexity caused by media::VideoCapture. Summary of this change: * Interface media::VideoCapture is removed completely. This interface doesn't add much value. It fails to define threading model and ownership. Some of the methods are obsolete. * Pepper code that performs video capturing now do not inherit from media::VideoCapture. The inheritance is not necessary * VideoCaptureImpl is now a purely IO thread object. VideoCaptureImpl can only be accessed on the IO thread. It now becomes and inner object of VideoCaptureImplManager. Client is not allowed to access this object directly. This helps remove code that accepts call from the render thread and hopping to the IO thread. This also makes cleanup much simpler. * VideoCaptureHandle is removed. The function of VideoCaptureHandle, i.e. handle cleanup of video capture resource is now folded into VideoCaptureImplManager. It's function is now replaced by a closure. * VideoCaptureImplManager becomes the public interface for accessing video capture device and start/stop capture. It takes VideoCaptureImpl as an internal object and sheild it from clients. We can now perform cleanup to prevent leak. Also ensures VideoCaptureImpl objects are deleted on the IO thread. * VideoFrames delivery done using callback insteasd of an interface. Using callback to deliver VideoFrames and state changes make thread hopping much simpler. Clients no longer need to provide an EventHandler interface. * Net deleted 450 lines of code. Tested with apprtc.appspot.com and example pepper plugin. Additional test to verify there's no leakage of VideoCaptureImpl objects. BUG=335327, 362558 Review URL: https://codereview.chromium.org/242013002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266492 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/media.gyp5
-rw-r--r--media/video/capture/mock_video_capture_event_handler.cc15
-rw-r--r--media/video/capture/mock_video_capture_event_handler.h40
-rw-r--r--media/video/capture/video_capture.h95
-rw-r--r--media/video/capture/video_capture_proxy.cc135
-rw-r--r--media/video/capture/video_capture_proxy.h85
6 files changed, 0 insertions, 375 deletions
diff --git a/media/media.gyp b/media/media.gyp
index b8e5773..e82f146 100644
--- a/media/media.gyp
+++ b/media/media.gyp
@@ -479,13 +479,10 @@
'video/capture/mac/video_capture_device_mac.mm',
'video/capture/mac/video_capture_device_qtkit_mac.h',
'video/capture/mac/video_capture_device_qtkit_mac.mm',
- 'video/capture/video_capture.h',
'video/capture/video_capture_device.cc',
'video/capture/video_capture_device.h',
'video/capture/video_capture_device_factory.cc',
'video/capture/video_capture_device_factory.h',
- 'video/capture/video_capture_proxy.cc',
- 'video/capture/video_capture_proxy.h',
'video/capture/video_capture_types.cc',
'video/capture/video_capture_types.h',
'video/capture/win/capability_list_win.cc',
@@ -1269,8 +1266,6 @@
'base/test_helpers.h',
'filters/mock_gpu_video_accelerator_factories.cc',
'filters/mock_gpu_video_accelerator_factories.h',
- 'video/capture/mock_video_capture_event_handler.cc',
- 'video/capture/mock_video_capture_event_handler.h',
'video/mock_video_decode_accelerator.cc',
'video/mock_video_decode_accelerator.h',
],
diff --git a/media/video/capture/mock_video_capture_event_handler.cc b/media/video/capture/mock_video_capture_event_handler.cc
deleted file mode 100644
index efbbda6..0000000
--- a/media/video/capture/mock_video_capture_event_handler.cc
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "media/video/capture/mock_video_capture_event_handler.h"
-
-namespace media {
-
-MockVideoCaptureEventHandler::MockVideoCaptureEventHandler() {
-}
-
-MockVideoCaptureEventHandler::~MockVideoCaptureEventHandler() {
-}
-
-} // namespace media
diff --git a/media/video/capture/mock_video_capture_event_handler.h b/media/video/capture/mock_video_capture_event_handler.h
deleted file mode 100644
index e71e8dd..0000000
--- a/media/video/capture/mock_video_capture_event_handler.h
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_EVENT_HANDLER_H_
-#define MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_EVENT_HANDLER_H_
-
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "media/video/capture/video_capture.h"
-#include "testing/gmock/include/gmock/gmock.h"
-
-namespace media {
-
-class MockVideoCaptureEventHandler : public VideoCapture::EventHandler {
- public:
- MockVideoCaptureEventHandler();
- virtual ~MockVideoCaptureEventHandler();
-
- // EventHandler implementation.
- MOCK_METHOD1(OnStarted, void(VideoCapture* capture));
- MOCK_METHOD1(OnStopped, void(VideoCapture* capture));
- MOCK_METHOD1(OnPaused, void(VideoCapture* capture));
- MOCK_METHOD2(OnError, void(VideoCapture* capture, int error_code));
- MOCK_METHOD1(OnRemoved, void(VideoCapture* capture));
- MOCK_METHOD2(OnFrameReady,
- void(VideoCapture* capture,
- const scoped_refptr<VideoFrame>& frame));
- MOCK_METHOD2(OnDeviceInfoReceived,
- void(VideoCapture* capture,
- const VideoCaptureFormat& device_info));
- MOCK_METHOD1(OnDeviceSupportedFormatsEnumerated,
- void(const media::VideoCaptureFormats& supported_formats));
- MOCK_METHOD1(OnDeviceFormatsInUseReceived,
- void(const media::VideoCaptureFormats& formats_in_use));
-};
-
-} // namespace media
-
-#endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_EVENT_HANDLER_H_
diff --git a/media/video/capture/video_capture.h b/media/video/capture/video_capture.h
deleted file mode 100644
index 0dd7b04..0000000
--- a/media/video/capture/video_capture.h
+++ /dev/null
@@ -1,95 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-//
-// This file contains abstract classes used for media filter to handle video
-// capture devices.
-
-#ifndef MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_H_
-#define MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_H_
-
-#include "base/callback.h"
-#include "base/memory/ref_counted.h"
-#include "base/time/time.h"
-#include "media/base/media_export.h"
-#include "media/video/capture/video_capture_types.h"
-
-namespace media {
-
-class VideoFrame;
-
-class MEDIA_EXPORT VideoCapture {
- public:
- // TODO(wjia): add error codes.
- // TODO(wjia): support weak ptr.
- // Callbacks provided by client for notification of events.
- class MEDIA_EXPORT EventHandler {
- public:
- // Notify client that video capture has been started.
- virtual void OnStarted(VideoCapture* capture) = 0;
-
- // Notify client that video capture has been stopped.
- virtual void OnStopped(VideoCapture* capture) = 0;
-
- // Notify client that video capture has been paused.
- virtual void OnPaused(VideoCapture* capture) = 0;
-
- // Notify client that video capture has hit some error |error_code|.
- virtual void OnError(VideoCapture* capture, int error_code) = 0;
-
- // Notify client that the client has been removed and no more calls will be
- // received.
- virtual void OnRemoved(VideoCapture* capture) = 0;
-
- // Notify client that a buffer is available.
- virtual void OnFrameReady(
- VideoCapture* capture,
- const scoped_refptr<media::VideoFrame>& frame) = 0;
-
- protected:
- virtual ~EventHandler() {}
- };
-
- typedef base::Callback<void(const media::VideoCaptureFormats&)>
- DeviceFormatsCallback;
-
- typedef base::Callback<void(const media::VideoCaptureFormats&)>
- DeviceFormatsInUseCallback;
-
- VideoCapture() {}
-
- // Request video capture to start capturing with |params|.
- // Also register |handler| with video capture for event handling.
- // |handler| must remain valid until it has received |OnRemoved()|.
- virtual void StartCapture(EventHandler* handler,
- const VideoCaptureParams& params) = 0;
-
- // Request video capture to stop capturing for client |handler|.
- // |handler| must remain valid until it has received |OnRemoved()|.
- virtual void StopCapture(EventHandler* handler) = 0;
-
- virtual bool CaptureStarted() = 0;
- virtual int CaptureFrameRate() = 0;
-
- // Request the device capture supported formats. This method can be called
- // before startCapture() and/or after stopCapture() so a |callback| is used
- // instead of replying via EventHandler.
- virtual void GetDeviceSupportedFormats(
- const DeviceFormatsCallback& callback) = 0;
-
- // Request the device capture in-use format(s), possibly by other user(s) in
- // other renderer(s). If there is no format in use, the vector returned in
- // the callback will be empty.
- virtual void GetDeviceFormatsInUse(
- const DeviceFormatsInUseCallback& callback) = 0;
-
- protected:
- virtual ~VideoCapture() {}
-
- private:
- DISALLOW_COPY_AND_ASSIGN(VideoCapture);
-};
-
-} // namespace media
-
-#endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_H_
diff --git a/media/video/capture/video_capture_proxy.cc b/media/video/capture/video_capture_proxy.cc
deleted file mode 100644
index c552819..0000000
--- a/media/video/capture/video_capture_proxy.cc
+++ /dev/null
@@ -1,135 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "media/video/capture/video_capture_proxy.h"
-
-#include "base/bind.h"
-#include "base/location.h"
-#include "base/single_thread_task_runner.h"
-#include "media/base/video_frame.h"
-
-namespace {
-
-// Called on VC thread: extracts the state out of the VideoCapture, and
-// serialize it into a VideoCaptureState.
-media::VideoCaptureHandlerProxy::VideoCaptureState GetState(
- media::VideoCapture* capture) {
- media::VideoCaptureHandlerProxy::VideoCaptureState state;
- state.started = capture->CaptureStarted();
- state.frame_rate = capture->CaptureFrameRate();
- return state;
-}
-
-} // anonymous namespace
-
-namespace media {
-
-VideoCaptureHandlerProxy::VideoCaptureHandlerProxy(
- VideoCapture::EventHandler* proxied,
- const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner)
- : proxied_(proxied),
- main_task_runner_(main_task_runner) {
-}
-
-VideoCaptureHandlerProxy::~VideoCaptureHandlerProxy() {
-}
-
-void VideoCaptureHandlerProxy::OnStarted(VideoCapture* capture) {
- main_task_runner_->PostTask(FROM_HERE, base::Bind(
- &VideoCaptureHandlerProxy::OnStartedOnMainThread,
- base::Unretained(this),
- capture,
- GetState(capture)));
-}
-
-void VideoCaptureHandlerProxy::OnStopped(VideoCapture* capture) {
- main_task_runner_->PostTask(FROM_HERE, base::Bind(
- &VideoCaptureHandlerProxy::OnStoppedOnMainThread,
- base::Unretained(this),
- capture,
- GetState(capture)));
-}
-
-void VideoCaptureHandlerProxy::OnPaused(VideoCapture* capture) {
- main_task_runner_->PostTask(FROM_HERE, base::Bind(
- &VideoCaptureHandlerProxy::OnPausedOnMainThread,
- base::Unretained(this),
- capture,
- GetState(capture)));
-}
-
-void VideoCaptureHandlerProxy::OnError(VideoCapture* capture, int error_code) {
- main_task_runner_->PostTask(FROM_HERE, base::Bind(
- &VideoCaptureHandlerProxy::OnErrorOnMainThread,
- base::Unretained(this),
- capture,
- GetState(capture),
- error_code));
-}
-
-void VideoCaptureHandlerProxy::OnRemoved(VideoCapture* capture) {
- main_task_runner_->PostTask(FROM_HERE, base::Bind(
- &VideoCaptureHandlerProxy::OnRemovedOnMainThread,
- base::Unretained(this),
- capture,
- GetState(capture)));
-}
-
-void VideoCaptureHandlerProxy::OnFrameReady(
- VideoCapture* capture,
- const scoped_refptr<VideoFrame>& frame) {
- main_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&VideoCaptureHandlerProxy::OnFrameReadyOnMainThread,
- base::Unretained(this),
- capture,
- GetState(capture),
- frame));
-}
-
-void VideoCaptureHandlerProxy::OnStartedOnMainThread(
- VideoCapture* capture,
- const VideoCaptureState& state) {
- state_ = state;
- proxied_->OnStarted(capture);
-}
-
-void VideoCaptureHandlerProxy::OnStoppedOnMainThread(
- VideoCapture* capture,
- const VideoCaptureState& state) {
- state_ = state;
- proxied_->OnStopped(capture);
-}
-
-void VideoCaptureHandlerProxy::OnPausedOnMainThread(
- VideoCapture* capture,
- const VideoCaptureState& state) {
- state_ = state;
- proxied_->OnPaused(capture);
-}
-
-void VideoCaptureHandlerProxy::OnErrorOnMainThread(
- VideoCapture* capture,
- const VideoCaptureState& state,
- int error_code) {
- state_ = state;
- proxied_->OnError(capture, error_code);
-}
-
-void VideoCaptureHandlerProxy::OnRemovedOnMainThread(
- VideoCapture* capture,
- const VideoCaptureState& state) {
- state_ = state;
- proxied_->OnRemoved(capture);
-}
-
-void VideoCaptureHandlerProxy::OnFrameReadyOnMainThread(
- VideoCapture* capture,
- const VideoCaptureState& state,
- const scoped_refptr<VideoFrame>& frame) {
- state_ = state;
- proxied_->OnFrameReady(capture, frame);
-}
-
-} // namespace media
diff --git a/media/video/capture/video_capture_proxy.h b/media/video/capture/video_capture_proxy.h
deleted file mode 100644
index 80f019d..0000000
--- a/media/video/capture/video_capture_proxy.h
+++ /dev/null
@@ -1,85 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_PROXY_H_
-#define MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_PROXY_H_
-
-#include "base/compiler_specific.h"
-#include "base/memory/ref_counted.h"
-#include "media/video/capture/video_capture.h"
-
-namespace base {
-class SingleThreadTaskRunner;
-}
-
-namespace media {
-
-// This is a helper class to proxy a VideoCapture::EventHandler. In the renderer
-// process, the VideoCaptureImpl calls its handler on a "Video Capture" thread,
-// this class allows seamless proxying to another thread ("main thread"), which
-// would be the thread where the instance of this class is created. The
-// "proxied" handler is then called on that thread.
-// Since the VideoCapture is living on the "Video Capture" thread, querying its
-// state from the "main thread" is fundamentally racy. Instead this class keeps
-// track of the state every time it is called by the VideoCapture (on the VC
-// thread), and forwards that information to the main thread.
-class MEDIA_EXPORT VideoCaptureHandlerProxy
- : public VideoCapture::EventHandler {
- public:
- struct VideoCaptureState {
- VideoCaptureState() : started(false), frame_rate(0) {}
- bool started;
- int frame_rate;
- };
-
- // Called on main thread.
- VideoCaptureHandlerProxy(
- VideoCapture::EventHandler* proxied,
- const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner);
- virtual ~VideoCaptureHandlerProxy();
-
- // Retrieves the state of the VideoCapture. Must be called on main thread.
- const VideoCaptureState& state() const { return state_; }
-
- // VideoCapture::EventHandler implementation, called on VC thread.
- virtual void OnStarted(VideoCapture* capture) OVERRIDE;
- virtual void OnStopped(VideoCapture* capture) OVERRIDE;
- virtual void OnPaused(VideoCapture* capture) OVERRIDE;
- virtual void OnError(VideoCapture* capture, int error_code) OVERRIDE;
- virtual void OnRemoved(VideoCapture* capture) OVERRIDE;
- virtual void OnFrameReady(VideoCapture* capture,
- const scoped_refptr<VideoFrame>& frame) OVERRIDE;
-
- private:
- // Called on main thread.
- void OnStartedOnMainThread(
- VideoCapture* capture,
- const VideoCaptureState& state);
- void OnStoppedOnMainThread(
- VideoCapture* capture,
- const VideoCaptureState& state);
- void OnPausedOnMainThread(
- VideoCapture* capture,
- const VideoCaptureState& state);
- void OnErrorOnMainThread(
- VideoCapture* capture,
- const VideoCaptureState& state,
- int error_code);
- void OnRemovedOnMainThread(
- VideoCapture* capture,
- const VideoCaptureState& state);
- void OnFrameReadyOnMainThread(VideoCapture* capture,
- const VideoCaptureState& state,
- const scoped_refptr<VideoFrame>& frame);
-
- // Only accessed from main thread.
- VideoCapture::EventHandler* proxied_;
- VideoCaptureState state_;
-
- scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
-};
-
-} // namespace media
-
-#endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_PROXY_H_