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

Side by Side 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, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_PROXY_H_
6 #define MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_PROXY_H_
7
8 #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
9 #include "base/memory/ref_counted.h"
10 #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.
11 #include "base/task.h"
12 #include "media/video/capture/video_capture.h"
13
14 namespace base {
15 class MessageLoopProxy;
16 }
17
18 namespace media {
19
20 // This is a helper class to proxy a VideoCapture::EventHandler. In the renderer
21 // process, the VideoCaptureImpl calls its handler on a "Video Capture" thread,
22 // 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.
23 // would be the thread where the instance of this class is created. The
24 // "proxied" handler is then called on that thread.
25 // Since the VideoCapture is living on the "Video Capture" thread, querying its
26 // state from the "main thread" is fundamentally racy. Instead this class keeps
27 // track of the state every time it is called by the VideoCapture (on the VC
28 // thread), and forwards that information to the main thread.
29 class VideoCaptureHandlerProxy : public VideoCapture::EventHandler {
30 public:
31 struct VideoCaptureState {
32 VideoCaptureState() : started(false), width(0), height(0), frame_rate(0) {}
33 bool started;
34 int width;
35 int height;
36 int frame_rate;
37 };
38
39 // Called on main thread.
40 VideoCaptureHandlerProxy(VideoCapture::EventHandler* proxied);
41 virtual ~VideoCaptureHandlerProxy();
42
43 // Retrieves the state of the VideoCapture. Must be called on main thread.
44 const VideoCaptureState& state() const { return state_; }
45 VideoCapture::EventHandler* proxied() const { return proxied_; }
46
47 // VideoCapture::EventHandler implementation, called on VC thread.
48 virtual void OnStarted(VideoCapture* capture);
49 virtual void OnStopped(VideoCapture* capture);
50 virtual void OnPaused(VideoCapture* capture);
51 virtual void OnError(VideoCapture* capture, int error_code);
52 virtual void OnBufferReady(
53 VideoCapture* capture,
54 scoped_refptr<VideoCapture::VideoFrameBuffer> buffer);
55 virtual void OnDeviceInfoReceived(
56 VideoCapture* capture,
57 const VideoCaptureParams& device_info);
58
59 private:
60 // Called on main thread.
61 void OnStartedOnMainThread(
62 VideoCapture* capture,
63 const VideoCaptureState& state);
64 void OnStoppedOnMainThread(
65 VideoCapture* capture,
66 const VideoCaptureState& state);
67 void OnPausedOnMainThread(
68 VideoCapture* capture,
69 const VideoCaptureState& state);
70 void OnErrorOnMainThread(
71 VideoCapture* capture,
72 const VideoCaptureState& state,
73 int error_code);
74 void OnBufferReadyOnMainThread(
75 VideoCapture* capture,
76 const VideoCaptureState& state,
77 scoped_refptr<VideoCapture::VideoFrameBuffer> buffer);
78 void OnDeviceInfoReceivedOnMainThread(
79 VideoCapture* capture,
80 const VideoCaptureState& state,
81 const VideoCaptureParams& device_info);
82
83 // Only accessed from main thread.
84 VideoCapture::EventHandler* proxied_;
85 VideoCaptureState state_;
86
87 scoped_refptr<base::MessageLoopProxy> main_message_loop_;
88 };
89
90 } // namespace media
91 DISABLE_RUNNABLE_METHOD_REFCOUNT(media::VideoCaptureHandlerProxy);
92
93 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_PROXY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698