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

Unified Diff: media/video/capture/video_capture_proxy.h

Issue 7537037: Add a proxy for thread-hopping VideoCapture::EventHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 5 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: media/video/capture/video_capture_proxy.h
diff --git a/media/video/capture/video_capture_proxy.h b/media/video/capture/video_capture_proxy.h
new file mode 100644
index 0000000000000000000000000000000000000000..e7e95829b5200f4750894d1954672501c6b3b476
--- /dev/null
+++ b/media/video/capture/video_capture_proxy.h
@@ -0,0 +1,93 @@
+// 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.
+
+#ifndef MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_PROXY_H_
+#define MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_PROXY_H_
+
+#include "base/compiler_specific.h"
wjia(left Chromium) 2011/08/02 00:10:39 not used, I think.
piman 2011/08/02 01:08:55 It's needed for the OVERRIDE's. That I somehow mis
+#include "base/memory/ref_counted.h"
+#include "base/scoped_ptr.h"
wjia(left Chromium) 2011/08/02 00:10:39 this one is not used.
piman 2011/08/02 01:08:55 Done.
+#include "base/task.h"
+#include "media/video/capture/video_capture.h"
+
+namespace base {
+class MessageLoopProxy;
+}
+
+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 symless proxying to another thread ("main thread"), which
wjia(left Chromium) 2011/08/02 00:10:39 seamless?
piman 2011/08/02 01:08:55 Done.
+// 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 VideoCaptureHandlerProxy : public VideoCapture::EventHandler {
+ public:
+ struct VideoCaptureState {
+ VideoCaptureState() : started(false), width(0), height(0), frame_rate(0) {}
+ bool started;
+ int width;
+ int height;
+ int frame_rate;
+ };
+
+ // Called on main thread.
+ VideoCaptureHandlerProxy(VideoCapture::EventHandler* proxied);
+ virtual ~VideoCaptureHandlerProxy();
+
+ // Retrieves the state of the VideoCapture. Must be called on main thread.
+ const VideoCaptureState& state() const { return state_; }
+ VideoCapture::EventHandler* proxied() const { return proxied_; }
+
+ // VideoCapture::EventHandler implementation, called on VC thread.
+ virtual void OnStarted(VideoCapture* capture);
+ virtual void OnStopped(VideoCapture* capture);
+ virtual void OnPaused(VideoCapture* capture);
+ virtual void OnError(VideoCapture* capture, int error_code);
+ virtual void OnBufferReady(
+ VideoCapture* capture,
+ scoped_refptr<VideoCapture::VideoFrameBuffer> buffer);
+ virtual void OnDeviceInfoReceived(
+ VideoCapture* capture,
+ const VideoCaptureParams& device_info);
+
+ 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 OnBufferReadyOnMainThread(
+ VideoCapture* capture,
+ const VideoCaptureState& state,
+ scoped_refptr<VideoCapture::VideoFrameBuffer> buffer);
+ void OnDeviceInfoReceivedOnMainThread(
+ VideoCapture* capture,
+ const VideoCaptureState& state,
+ const VideoCaptureParams& device_info);
+
+ // Only accessed from main thread.
+ VideoCapture::EventHandler* proxied_;
+ VideoCaptureState state_;
+
+ scoped_refptr<base::MessageLoopProxy> main_message_loop_;
+};
+
+} // namespace media
+DISABLE_RUNNABLE_METHOD_REFCOUNT(media::VideoCaptureHandlerProxy);
+
+#endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_PROXY_H_

Powered by Google App Engine
This is Rietveld 408576698