Chromium Code Reviews| Index: content/renderer/media/video_capture_impl.h |
| diff --git a/content/renderer/media/video_capture_impl.h b/content/renderer/media/video_capture_impl.h |
| index 2215cef4336456920329f98ab0c500decbee8f12..ba0e6521a07845ac8f82b2c449619c7a4f93854e 100644 |
| --- a/content/renderer/media/video_capture_impl.h |
| +++ b/content/renderer/media/video_capture_impl.h |
| @@ -12,20 +12,20 @@ |
| // The media::VideoCapture and VideoCaptureMessageFilter::Delegate are |
| // asynchronous interfaces, which means callers can call those interfaces |
|
Ami GONE FROM CHROMIUM
2014/01/08 01:43:58
"async interface" doesn't usually mean "call on an
|
| -// from any threads without worrying about thread safety. |
| -// The |capture_message_loop_proxy_| is the working thread of VideoCaptureImpl. |
| -// All non-const members are accessed only on that working thread. |
| +// from any threads without worrying about thread safety. Public methods of |
|
Ami GONE FROM CHROMIUM
2014/01/08 01:43:58
s/any threads/any thread/
Alpha Left Google
2014/01/08 22:30:50
Done.
|
| +// VideoCaptureImpl can be called on any threads. Internally it runs on |
|
Ami GONE FROM CHROMIUM
2014/01/08 01:43:58
ditto
Ami GONE FROM CHROMIUM
2014/01/08 01:43:58
s/it runs/they run/
Alpha Left Google
2014/01/08 22:30:50
Done.
|
| +// the IO thread. Client of this class implements interface |
|
Ami GONE FROM CHROMIUM
2014/01/08 01:43:58
Client...implements
->
Clients...implement
Alpha Left Google
2014/01/08 22:30:50
Done.
|
| +// media::VideoCapture::EventHandler which is called only on the IO thread. |
| // |
| -// Implementation note: tasks are posted bound to Unretained(this) to both the |
| -// I/O and Capture threads and this is safe (even though the I/O thread is |
| -// scoped to the renderer process and the capture_message_loop_proxy_ thread is |
| -// scoped to the VideoCaptureImplManager) because VideoCaptureImplManager only |
| -// triggers deletion of its VideoCaptureImpl's by calling DeInit which detours |
| -// through the capture & I/O threads, so as long as nobody posts tasks after the |
| -// DeInit() call is made, it is guaranteed none of these Unretained posted tasks |
| -// will dangle after the delete goes through. The "as long as" is guaranteed by |
| -// clients of VideoCaptureImplManager not using devices after they've |
| -// RemoveDevice'd them. |
| +// Implementation note: tasks are posted bound to Unretained(this) to the I/O |
| +// thread and this is safe (even though the I/O thread is scoped to the renderer |
| +// process) because VideoCaptureImplManager only triggers deletion of its |
| +// VideoCaptureImpl's by calling DeInit which detours through the I/O thread, so |
| +// as long as nobody posts tasks after the DeInit() call is made, it is |
| +// guaranteed none of these Unretained posted tasks will dangle after the delete |
| +// goes through. The "as long as" is guaranteed by clients of |
| +// VideoCaptureImplManager not using devices after they've released |
| +// VideoCaptureHandle, which is a wrapper of this object. |
| #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
| #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
| @@ -49,6 +49,19 @@ namespace content { |
| class CONTENT_EXPORT VideoCaptureImpl |
| : public media::VideoCapture, public VideoCaptureMessageFilter::Delegate { |
| public: |
| + VideoCaptureImpl(media::VideoCaptureSessionId session_id, |
| + VideoCaptureMessageFilter* filter); |
| + virtual ~VideoCaptureImpl(); |
| + |
| + // Start listening to IPC messages. |
| + void Init(); |
| + |
| + // Stop listening to IPC messages. Call |done_cb| when done. |
| + void DeInit(base::Closure done_cb); |
| + |
| + // Stop/resume delivering video frames to clients, based on flag |suspend|. |
| + void SuspendCapture(bool suspend); |
| + |
| // media::VideoCapture interface. |
| virtual void StartCapture( |
| media::VideoCapture::EventHandler* handler, |
| @@ -57,23 +70,9 @@ class CONTENT_EXPORT VideoCaptureImpl |
| virtual bool CaptureStarted() OVERRIDE; |
| virtual int CaptureFrameRate() OVERRIDE; |
| - // VideoCaptureMessageFilter::Delegate interface. |
| - virtual void OnBufferCreated(base::SharedMemoryHandle handle, |
| - int length, |
| - int buffer_id) OVERRIDE; |
| - virtual void OnBufferDestroyed(int buffer_id) OVERRIDE; |
| - virtual void OnBufferReceived( |
| - int buffer_id, |
| - base::Time timestamp, |
| - const media::VideoCaptureFormat& format) OVERRIDE; |
| - virtual void OnStateChanged(VideoCaptureState state) OVERRIDE; |
| - virtual void OnDelegateAdded(int32 device_id) OVERRIDE; |
| - |
| - // Stop/resume delivering video frames to clients, based on flag |suspend|. |
| - virtual void SuspendCapture(bool suspend); |
| + media::VideoCaptureSessionId session_id() const { return session_id_; } |
| private: |
| - friend class VideoCaptureImplManager; |
| friend class VideoCaptureImplTest; |
| friend class MockVideoCaptureImpl; |
| @@ -81,39 +80,35 @@ class CONTENT_EXPORT VideoCaptureImpl |
| typedef std::map<media::VideoCapture::EventHandler*, |
| media::VideoCaptureParams> ClientInfo; |
| - VideoCaptureImpl(media::VideoCaptureSessionId session_id, |
| - base::MessageLoopProxy* capture_message_loop_proxy, |
| - VideoCaptureMessageFilter* filter); |
| - virtual ~VideoCaptureImpl(); |
| - |
| - void DoStartCaptureOnCaptureThread( |
| + void InitOnIOThread(); |
| + void DeInitOnIOThread(base::Closure done_cb); |
| + void SuspendCaptureOnIOThread(bool suspend); |
| + void StartCaptureOnIOThread( |
| media::VideoCapture::EventHandler* handler, |
| const media::VideoCaptureParams& params); |
| - void DoStopCaptureOnCaptureThread(media::VideoCapture::EventHandler* handler); |
| - void DoBufferCreatedOnCaptureThread(base::SharedMemoryHandle handle, |
| - int length, |
| - int buffer_id); |
| - void DoBufferDestroyedOnCaptureThread(int buffer_id); |
| - void DoBufferReceivedOnCaptureThread( |
| + void StopCaptureOnIOThread(media::VideoCapture::EventHandler* handler); |
| + |
| + // VideoCaptureMessageFilter::Delegate interface. |
| + virtual void OnBufferCreated(base::SharedMemoryHandle handle, |
| + int length, |
| + int buffer_id) OVERRIDE; |
| + virtual void OnBufferDestroyed(int buffer_id) OVERRIDE; |
| + virtual void OnBufferReceived( |
| int buffer_id, |
| base::Time timestamp, |
| - const media::VideoCaptureFormat& format); |
| - void DoClientBufferFinishedOnCaptureThread( |
| + const media::VideoCaptureFormat& format) OVERRIDE; |
| + virtual void OnStateChanged(VideoCaptureState state) OVERRIDE; |
| + virtual void OnDelegateAdded(int32 device_id) OVERRIDE; |
| + |
| + // Sends an IPC message to browser process when all clients are done with the |
| + // buffer. |
| + void OnClientBufferFinished( |
| int buffer_id, |
| const scoped_refptr<ClientBuffer>& buffer); |
| - void DoStateChangedOnCaptureThread(VideoCaptureState state); |
| - void DoDelegateAddedOnCaptureThread(int32 device_id); |
| - void DoSuspendCaptureOnCaptureThread(bool suspend); |
| - |
| - void Init(); |
| - void DeInit(base::Closure task); |
| - void DoDeInitOnCaptureThread(base::Closure task); |
| void StopDevice(); |
| void RestartCapture(); |
| void StartCaptureInternal(); |
| - void AddDelegateOnIOThread(); |
| - void RemoveDelegateOnIOThread(base::Closure task); |
| virtual void Send(IPC::Message* message); |
| // Helpers. |
| @@ -121,7 +116,6 @@ class CONTENT_EXPORT VideoCaptureImpl |
| ClientInfo* clients); |
| const scoped_refptr<VideoCaptureMessageFilter> message_filter_; |
| - const scoped_refptr<base::MessageLoopProxy> capture_message_loop_proxy_; |
| const scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; |
| int device_id_; |
| const int session_id_; |
| @@ -135,7 +129,7 @@ class CONTENT_EXPORT VideoCaptureImpl |
| ClientInfo clients_pending_on_restart_; |
| // Member params_ represents the video format requested by the |
| - // client to this class via DoStartCaptureOnCaptureThread. |
| + // client to this class via StartCapture(). |
| media::VideoCaptureParams params_; |
| // The device's video capture format sent from browser process side. |