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