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

Unified Diff: trunk/src/content/renderer/media/video_capture_impl.h

Issue 135683002: Revert 244074 "Eliminate video capture thread in renderer" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: trunk/src/content/renderer/media/video_capture_impl.h
===================================================================
--- trunk/src/content/renderer/media/video_capture_impl.h (revision 244357)
+++ trunk/src/content/renderer/media/video_capture_impl.h (working copy)
@@ -9,21 +9,23 @@
// VideoCaptureImpl is also a delegate of VideoCaptureMessageFilter which relays
// operation of a capture device to the browser process and receives responses
// from browser process.
+
+// The media::VideoCapture and VideoCaptureMessageFilter::Delegate are
+// asynchronous interfaces, which means callers can call those interfaces
+// 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.
//
-// All public methods of VideoCaptureImpl can be called on any thread.
-// Internally it runs on the IO thread. Clients of this class implement
-// interface media::VideoCapture::EventHandler which is called only on the IO
-// thread.
-//
-// 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.
+// 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.
#ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_
#define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_
@@ -47,19 +49,6 @@
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,
@@ -68,9 +57,23 @@
virtual bool CaptureStarted() OVERRIDE;
virtual int CaptureFrameRate() OVERRIDE;
- media::VideoCaptureSessionId session_id() const { return session_id_; }
+ // 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::TimeTicks 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);
+
private:
+ friend class VideoCaptureImplManager;
friend class VideoCaptureImplTest;
friend class MockVideoCaptureImpl;
@@ -78,35 +81,38 @@
typedef std::map<media::VideoCapture::EventHandler*,
media::VideoCaptureParams> ClientInfo;
- void InitOnIOThread();
- void DeInitOnIOThread(base::Closure done_cb);
- void SuspendCaptureOnIOThread(bool suspend);
- void StartCaptureOnIOThread(
+ VideoCaptureImpl(media::VideoCaptureSessionId session_id,
+ base::MessageLoopProxy* capture_message_loop_proxy,
+ VideoCaptureMessageFilter* filter);
+ virtual ~VideoCaptureImpl();
+
+ void DoStartCaptureOnCaptureThread(
media::VideoCapture::EventHandler* handler,
const media::VideoCaptureParams& params);
- 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(
+ void DoStopCaptureOnCaptureThread(media::VideoCapture::EventHandler* handler);
+ void DoBufferCreatedOnCaptureThread(base::SharedMemoryHandle handle,
+ int length,
+ int buffer_id);
+ void DoBufferDestroyedOnCaptureThread(int buffer_id);
+ void DoBufferReceivedOnCaptureThread(int buffer_id,
+ base::TimeTicks timestamp,
+ const media::VideoCaptureFormat& format);
+ void DoClientBufferFinishedOnCaptureThread(
int buffer_id,
- base::TimeTicks timestamp,
- 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.
@@ -114,6 +120,7 @@
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_;
@@ -127,7 +134,7 @@
ClientInfo clients_pending_on_restart_;
// Member params_ represents the video format requested by the
- // client to this class via StartCapture().
+ // client to this class via DoStartCaptureOnCaptureThread.
media::VideoCaptureParams params_;
// The device's video capture format sent from browser process side.
« no previous file with comments | « trunk/src/content/renderer/media/rtc_video_capturer.cc ('k') | trunk/src/content/renderer/media/video_capture_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698