Index: content/renderer/media/video_capture_impl_manager.h |
diff --git a/content/renderer/media/video_capture_impl_manager.h b/content/renderer/media/video_capture_impl_manager.h |
index 6b02825a7aa9e549fc72da4c79075f962f988fc5..b7e19d8b23d44e74476da55db5f892bf61b260b6 100644 |
--- a/content/renderer/media/video_capture_impl_manager.h |
+++ b/content/renderer/media/video_capture_impl_manager.h |
@@ -2,17 +2,24 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-// VideoCaptureImplManager owns VideoCaptureImpl objects. Clients who |
-// want access to a video capture device call UseDevice() to get a handle |
-// to VideoCaptureImpl. |
+// TODO(hclam): This class should be renamed to VideoCaptureService. |
+ |
+// This class provides access to a video capture device in the browser |
+// process through IPC. The main function is to deliver video frames |
+// to a client. |
// |
// THREADING |
// |
// VideoCaptureImplManager lives only on the render thread. All methods |
// must be called on this thread. |
// |
-// The handle returned by UseDevice() is thread-safe. It ensures |
-// destruction is handled on the render thread. |
+// VideoFrames are delivered on the IO thread. Callbacks provided by |
+// a client are also called on the IO thread. |
+// |
+// LIFETIME |
+// |
+// This class is refcounted but not thread-safe. This allows cleanup of |
+// video capture resources after all clients are destroyed. |
Ami GONE FROM CHROMIUM
2014/04/21 23:42:53
Is it possible to use WeakPtrs to avoid letting cl
Alpha Left Google
2014/04/23 18:48:33
Good point. Done.
|
#ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ |
#define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ |
@@ -21,60 +28,65 @@ |
#include "base/callback.h" |
#include "base/memory/linked_ptr.h" |
+#include "base/memory/ref_counted.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/memory/weak_ptr.h" |
#include "base/message_loop/message_loop_proxy.h" |
#include "base/synchronization/lock.h" |
#include "base/threading/thread_checker.h" |
#include "content/common/content_export.h" |
-#include "media/video/capture/video_capture.h" |
+#include "content/common/media/video_capture.h" |
+#include "media/video/capture/video_capture_types.h" |
namespace content { |
class VideoCaptureImpl; |
-class VideoCaptureImplManager; |
class VideoCaptureMessageFilter; |
-// Thread-safe wrapper for a media::VideoCapture object. During |
-// destruction |destruction_cb| is called. This mechanism is used |
-// by VideoCaptureImplManager to ensure de-initialization and |
-// destruction of the media::VideoCapture object happens on the render |
-// thread. |
-class CONTENT_EXPORT VideoCaptureHandle : media::VideoCapture { |
+class CONTENT_EXPORT VideoCaptureImplManager : |
+ public base::RefCounted<VideoCaptureImplManager> { |
public: |
- virtual ~VideoCaptureHandle(); |
- |
- // media::VideoCapture implementations. |
- virtual void StartCapture( |
- EventHandler* handler, |
- const media::VideoCaptureParams& params) OVERRIDE; |
- virtual void StopCapture(EventHandler* handler) OVERRIDE; |
- virtual bool CaptureStarted() OVERRIDE; |
- virtual int CaptureFrameRate() OVERRIDE; |
- virtual void GetDeviceSupportedFormats( |
- const DeviceFormatsCallback& callback) OVERRIDE; |
- virtual void GetDeviceFormatsInUse( |
- const DeviceFormatsInUseCallback& callback) OVERRIDE; |
- |
- private: |
- friend class VideoCaptureImplManager; |
- |
- VideoCaptureHandle(media::VideoCapture* impl, |
- base::Closure destruction_cb); |
- |
- media::VideoCapture* impl_; |
- base::Closure destruction_cb_; |
+ VideoCaptureImplManager(); |
- DISALLOW_COPY_AND_ASSIGN(VideoCaptureHandle); |
-}; |
+ // Access a device associated with the session ID. |
Ami GONE FROM CHROMIUM
2014/04/21 23:42:53
s/Access/Open/
(or Use or something else more acti
Alpha Left Google
2014/04/23 18:48:33
Done.
|
+ // This method must be called before any methods with the same ID |
+ // is used. |
+ // Returns a callback that is used to release the acquired resources. |
Ami GONE FROM CHROMIUM
2014/04/21 23:42:53
s/is/should be/
Alpha Left Google
2014/04/23 18:48:33
Done.
|
+ base::Closure UseDevice(media::VideoCaptureSessionId id); |
+ |
+ // Start receiving video frames for the given session ID. |
+ // |
+ // |state_update_cb| will be called on the IO thread when capturing |
+ // state changes. |
+ // States will be one of the following four: |
+ // * VIDEO_CAPTURE_STATE_STARTED |
+ // * VIDEO_CAPTURE_STATE_STOPPED |
+ // * VIDEO_CAPTURE_STATE_PAUSED |
+ // * VIDEO_CAPTURE_STATE_ERROR |
+ // |
+ // |deliver_frame_cb| will be called on the IO thread when a video |
+ // frame is ready. |
+ // |
+ // Returns a callback that is used to stop capturing. Note that stopping |
+ // video capture is not synchronous. Client should handle the case where |
+ // callbacks are called after capturing is instructed to stop. |
Ami GONE FROM CHROMIUM
2014/04/21 23:42:53
s/./, typically by binding the passed callbacks on
Alpha Left Google
2014/04/23 18:48:33
Done.
|
+ base::Closure StartCapture( |
+ media::VideoCaptureSessionId id, |
+ const media::VideoCaptureParams& params, |
+ const VideoCaptureStateUpdateCB& state_update_cb, |
+ const VideoCaptureDeliverFrameCB& deliver_frame_cb); |
-class CONTENT_EXPORT VideoCaptureImplManager { |
- public: |
- VideoCaptureImplManager(); |
- virtual ~VideoCaptureImplManager(); |
+ // Get supported formats by the device for the given session ID. |
Ami GONE FROM CHROMIUM
2014/04/21 23:42:53
Get formats supported by the device...
Alpha Left Google
2014/04/23 18:48:33
Done.
|
+ // |callback| will be called on the IO thread. |
+ void GetDeviceSupportedFormats( |
+ media::VideoCaptureSessionId id, |
+ const VideoCaptureDeviceFormatsCB& callback); |
- // Returns a video capture device referenced by |id|. |
- scoped_ptr<VideoCaptureHandle> UseDevice(media::VideoCaptureSessionId id); |
+ // Get supported formats currently in use for the given session ID. |
+ // |callback| will be called on the IO thread. |
+ void GetDeviceFormatsInUse( |
+ media::VideoCaptureSessionId id, |
+ const VideoCaptureDeviceFormatsCB& callback); |
// Make all existing VideoCaptureImpl instances stop/resume delivering |
// video frames to their clients, depends on flag |suspend|. |
@@ -85,20 +97,29 @@ class CONTENT_EXPORT VideoCaptureImplManager { |
} |
protected: |
- // Used in tests to inject a mock VideoCaptureImpl. |
+ friend class base::RefCounted<VideoCaptureImplManager>; |
+ virtual ~VideoCaptureImplManager(); |
virtual VideoCaptureImpl* CreateVideoCaptureImpl( |
Ami GONE FROM CHROMIUM
2014/04/21 23:42:53
s/Impl(/ImplForTesting(/
Alpha Left Google
2014/04/23 18:48:33
Done.
|
media::VideoCaptureSessionId id, |
VideoCaptureMessageFilter* filter) const; |
private: |
+ void StopCapture(int client_id, media::VideoCaptureSessionId id); |
void UnrefDevice(media::VideoCaptureSessionId id); |
// The int is used to count clients of the corresponding VideoCaptureImpl. |
+ // VideoCaptureImpl objects are owned by this object. But they are |
+ // destroyed on the IO thread. These are raw pointers because we destroy |
+ // them manually. |
typedef std::map<media::VideoCaptureSessionId, |
- std::pair<int, linked_ptr<VideoCaptureImpl> > > |
+ std::pair<int, VideoCaptureImpl*> > |
VideoCaptureDeviceMap; |
VideoCaptureDeviceMap devices_; |
+ // This is an internal ID for identifying clients of VideoCaptureImpl. |
+ // The ID is global for the render process. |
+ int next_client_id_; |
+ |
scoped_refptr<VideoCaptureMessageFilter> filter_; |
// Bound to the render thread. |