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 e9422015b026bda6d3d41abc4398fed0aee1a34a..7367b9e9887d06bfd14a119a27efb795b0e6d816 100644 |
--- a/content/renderer/media/video_capture_impl_manager.h |
+++ b/content/renderer/media/video_capture_impl_manager.h |
@@ -2,77 +2,92 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-// VideoCaptureImplManager manages video capture devices in renderer process. |
-// The video capture clients use AddDevice() to get a pointer to |
-// video capture device. VideoCaputreImplManager supports multiple clients |
-// accessing same device. |
+// VideoCaptureImplManager owns VideoCaptureImpl objects. Clients who |
+// want access to a video capture device calls UseDevice() to get a handle |
Ami GONE FROM CHROMIUM
2014/01/06 23:37:14
s/calls/call/
Alpha Left Google
2014/01/08 00:23:36
Done.
|
+// to VideoCaptureImpl. |
+// |
+// THREADING |
+// |
+// This object lives only on the render thread. All methods must be called |
Ami GONE FROM CHROMIUM
2014/01/06 23:37:14
"This object" is unclear. I believe you refer to
Alpha Left Google
2014/01/08 00:23:36
Done.
|
+// on this thread. |
+// |
+// The handle returned by UseDevice() is thread-safe. It ensures |
+// destruction is handled on the render thread. |
#ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ |
#define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_ |
-#include <list> |
#include <map> |
+#include "base/callback.h" |
+#include "base/memory/linked_ptr.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
#include "base/message_loop/message_loop_proxy.h" |
-#include "base/threading/thread.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" |
namespace content { |
class VideoCaptureImpl; |
+class VideoCaptureImplManager; |
class VideoCaptureMessageFilter; |
-class CONTENT_EXPORT VideoCaptureImplManager |
- : public base::RefCountedThreadSafe<VideoCaptureImplManager> { |
+// Thread-safe wrapper for a media::VideoCapture object. This class |
Ami GONE FROM CHROMIUM
2014/01/06 23:37:14
Can you drop VCH entirely in favor of RefCountedDe
Alpha Left Google
2014/01/08 00:23:36
I don't think we can do away without an extra clas
|
+// ensures refcounting is done on the render thread. |
Ami GONE FROM CHROMIUM
2014/01/06 23:37:14
This sentence (and the corresponding one in the CL
Alpha Left Google
2014/01/08 00:23:36
Done.
|
+class CONTENT_EXPORT VideoCaptureHandle : media::VideoCapture { |
Ami GONE FROM CHROMIUM
2014/01/06 23:37:14
Is it easy to see why this class belongs in this f
Alpha Left Google
2014/01/08 00:23:36
The reason I put this class in this file is becaus
|
public: |
- VideoCaptureImplManager(); |
+ 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; |
+ |
+ private: |
+ friend class VideoCaptureImplManager; |
- // Called by video capture client |handler| to add device referenced |
- // by |id| to VideoCaptureImplManager's list of opened device list. |
- // A pointer to VideoCapture is returned to client so that client can |
- // operate on that pointer, such as StartCaptrue, StopCapture. |
- virtual media::VideoCapture* AddDevice( |
- media::VideoCaptureSessionId id, |
- media::VideoCapture::EventHandler* handler); |
+ VideoCaptureHandle(media::VideoCapture* impl, |
+ base::Closure destruction_cb); |
- // Called by video capture client |handler| to remove device referenced |
- // by |id| from VideoCaptureImplManager's list of opened device list. |
- virtual void RemoveDevice(media::VideoCaptureSessionId id, |
- media::VideoCapture::EventHandler* handler); |
+ media::VideoCapture* impl_; |
+ base::Closure destruction_cb_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(VideoCaptureHandle); |
+}; |
+ |
+class CONTENT_EXPORT VideoCaptureImplManager { |
+ public: |
+ VideoCaptureImplManager(); |
+ virtual ~VideoCaptureImplManager(); |
+ |
+ // Returns a video capture device referenced by |id|. |
+ scoped_ptr<VideoCaptureHandle> UseDevice(media::VideoCaptureSessionId id); |
// Make all existing VideoCaptureImpl instances stop/resume delivering |
// video frames to their clients, depends on flag |suspend|. |
- virtual void SuspendDevices(bool suspend); |
+ void SuspendDevices(bool suspend); |
VideoCaptureMessageFilter* video_capture_message_filter() const { |
return filter_.get(); |
} |
- protected: |
- virtual ~VideoCaptureImplManager(); |
- |
private: |
- friend class base::RefCountedThreadSafe<VideoCaptureImplManager>; |
- |
- struct Device { |
- Device(VideoCaptureImpl* device, |
- media::VideoCapture::EventHandler* handler); |
- ~Device(); |
- |
- VideoCaptureImpl* vc; |
- std::list<media::VideoCapture::EventHandler*> clients; |
- }; |
+ void UnrefDevice(media::VideoCaptureSessionId id); |
- void FreeDevice(VideoCaptureImpl* vc); |
+ typedef std::map<media::VideoCaptureSessionId, |
+ linked_ptr<VideoCaptureImpl> > VideoCaptureDeviceMap; |
Ami GONE FROM CHROMIUM
2014/01/06 23:37:14
FWIW if you made VideoCaptureDeviceMap be a
std::
Alpha Left Google
2014/01/08 00:23:36
Took your advice and used std::pair<> and removed
|
+ VideoCaptureDeviceMap devices_; |
+ std::map<media::VideoCaptureSessionId, int> use_count_; |
- typedef std::map<media::VideoCaptureSessionId, Device*> Devices; |
- Devices devices_; |
- base::Lock lock_; |
scoped_refptr<VideoCaptureMessageFilter> filter_; |
- base::Thread thread_; |
- scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
+ base::WeakPtrFactory<VideoCaptureImplManager> weak_factory_; |
Ami GONE FROM CHROMIUM
2014/01/06 23:37:14
IWBN to comment for both this and the next member
Alpha Left Google
2014/01/08 00:23:36
Done.
|
+ base::ThreadChecker thread_checker_; |
DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManager); |
}; |