OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_PROXY_H_ | 5 #ifndef MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_PROXY_H_ |
6 #define MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_PROXY_H_ | 6 #define MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_PROXY_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "media/video/capture/video_capture.h" | 10 #include "media/video/capture/video_capture.h" |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 class MessageLoopProxy; | 13 class SingleThreadTaskRunner; |
14 } | 14 } |
15 | 15 |
16 namespace media { | 16 namespace media { |
17 | 17 |
18 // This is a helper class to proxy a VideoCapture::EventHandler. In the renderer | 18 // This is a helper class to proxy a VideoCapture::EventHandler. In the renderer |
19 // process, the VideoCaptureImpl calls its handler on a "Video Capture" thread, | 19 // process, the VideoCaptureImpl calls its handler on a "Video Capture" thread, |
20 // this class allows seamless proxying to another thread ("main thread"), which | 20 // this class allows seamless proxying to another thread ("main thread"), which |
21 // would be the thread where the instance of this class is created. The | 21 // would be the thread where the instance of this class is created. The |
22 // "proxied" handler is then called on that thread. | 22 // "proxied" handler is then called on that thread. |
23 // Since the VideoCapture is living on the "Video Capture" thread, querying its | 23 // Since the VideoCapture is living on the "Video Capture" thread, querying its |
24 // state from the "main thread" is fundamentally racy. Instead this class keeps | 24 // state from the "main thread" is fundamentally racy. Instead this class keeps |
25 // track of the state every time it is called by the VideoCapture (on the VC | 25 // track of the state every time it is called by the VideoCapture (on the VC |
26 // thread), and forwards that information to the main thread. | 26 // thread), and forwards that information to the main thread. |
27 class MEDIA_EXPORT VideoCaptureHandlerProxy | 27 class MEDIA_EXPORT VideoCaptureHandlerProxy |
28 : public VideoCapture::EventHandler { | 28 : public VideoCapture::EventHandler { |
29 public: | 29 public: |
30 struct VideoCaptureState { | 30 struct VideoCaptureState { |
31 VideoCaptureState() : started(false), frame_rate(0) {} | 31 VideoCaptureState() : started(false), frame_rate(0) {} |
32 bool started; | 32 bool started; |
33 int frame_rate; | 33 int frame_rate; |
34 }; | 34 }; |
35 | 35 |
36 // Called on main thread. | 36 // Called on main thread. |
37 VideoCaptureHandlerProxy( | 37 VideoCaptureHandlerProxy( |
38 VideoCapture::EventHandler* proxied, | 38 VideoCapture::EventHandler* proxied, |
39 scoped_refptr<base::MessageLoopProxy> main_message_loop); | 39 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner); |
40 virtual ~VideoCaptureHandlerProxy(); | 40 virtual ~VideoCaptureHandlerProxy(); |
41 | 41 |
42 // Retrieves the state of the VideoCapture. Must be called on main thread. | 42 // Retrieves the state of the VideoCapture. Must be called on main thread. |
43 const VideoCaptureState& state() const { return state_; } | 43 const VideoCaptureState& state() const { return state_; } |
44 | 44 |
45 // VideoCapture::EventHandler implementation, called on VC thread. | 45 // VideoCapture::EventHandler implementation, called on VC thread. |
46 virtual void OnStarted(VideoCapture* capture) OVERRIDE; | 46 virtual void OnStarted(VideoCapture* capture) OVERRIDE; |
47 virtual void OnStopped(VideoCapture* capture) OVERRIDE; | 47 virtual void OnStopped(VideoCapture* capture) OVERRIDE; |
48 virtual void OnPaused(VideoCapture* capture) OVERRIDE; | 48 virtual void OnPaused(VideoCapture* capture) OVERRIDE; |
49 virtual void OnError(VideoCapture* capture, int error_code) OVERRIDE; | 49 virtual void OnError(VideoCapture* capture, int error_code) OVERRIDE; |
(...skipping 20 matching lines...) Expand all Loading... |
70 VideoCapture* capture, | 70 VideoCapture* capture, |
71 const VideoCaptureState& state); | 71 const VideoCaptureState& state); |
72 void OnFrameReadyOnMainThread(VideoCapture* capture, | 72 void OnFrameReadyOnMainThread(VideoCapture* capture, |
73 const VideoCaptureState& state, | 73 const VideoCaptureState& state, |
74 const scoped_refptr<VideoFrame>& frame); | 74 const scoped_refptr<VideoFrame>& frame); |
75 | 75 |
76 // Only accessed from main thread. | 76 // Only accessed from main thread. |
77 VideoCapture::EventHandler* proxied_; | 77 VideoCapture::EventHandler* proxied_; |
78 VideoCaptureState state_; | 78 VideoCaptureState state_; |
79 | 79 |
80 scoped_refptr<base::MessageLoopProxy> main_message_loop_; | 80 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
81 }; | 81 }; |
82 | 82 |
83 } // namespace media | 83 } // namespace media |
84 | 84 |
85 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_PROXY_H_ | 85 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_PROXY_H_ |
OLD | NEW |