| 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 // VideoCaptureManager is used to open/close, start/stop, enumerate available | 5 // VideoCaptureManager is used to open/close, start/stop, enumerate available |
| 6 // video capture devices, and manage VideoCaptureController's. | 6 // video capture devices, and manage VideoCaptureController's. |
| 7 // All functions are expected to be called from Browser::IO thread. | 7 // All functions are expected to be called from Browser::IO thread. |
| 8 // VideoCaptureManager will open OS dependent instances of VideoCaptureDevice. | 8 // VideoCaptureManager will open OS dependent instances of VideoCaptureDevice. |
| 9 // A device can only be opened once. | 9 // A device can only be opened once. |
| 10 | 10 |
| 11 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 11 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
| 12 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 12 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
| 13 | 13 |
| 14 #include <list> | 14 #include <list> |
| 15 #include <map> | 15 #include <map> |
| 16 | 16 |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
| 19 #include "content/browser/renderer_host/media/media_stream_provider.h" | 19 #include "content/browser/renderer_host/media/media_stream_provider.h" |
| 20 #include "content/common/content_export.h" | 20 #include "content/common/content_export.h" |
| 21 #include "content/common/media/media_stream_options.h" | 21 #include "content/common/media/media_stream_options.h" |
| 22 #include "media/video/capture/video_capture_device.h" | 22 #include "media/video/capture/video_capture_device.h" |
| 23 #include "media/video/capture/video_capture_types.h" | 23 #include "media/video/capture/video_capture_types.h" |
| 24 | 24 |
| 25 class MockVideoCaptureManager; |
| 25 class VideoCaptureController; | 26 class VideoCaptureController; |
| 26 class VideoCaptureControllerEventHandler; | 27 class VideoCaptureControllerEventHandler; |
| 27 | 28 |
| 28 namespace media_stream { | 29 namespace media_stream { |
| 29 | 30 |
| 30 // VideoCaptureManager opens/closes and start/stops video capture devices. | 31 // VideoCaptureManager opens/closes and start/stops video capture devices. |
| 31 class CONTENT_EXPORT VideoCaptureManager | 32 class CONTENT_EXPORT VideoCaptureManager |
| 32 : public base::RefCountedThreadSafe<VideoCaptureManager>, | 33 : public base::RefCountedThreadSafe<VideoCaptureManager>, |
| 33 public MediaStreamProvider { | 34 public MediaStreamProvider { |
| 34 public: | 35 public: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 47 virtual void EnumerateDevices() OVERRIDE; | 48 virtual void EnumerateDevices() OVERRIDE; |
| 48 | 49 |
| 49 virtual int Open(const StreamDeviceInfo& device) OVERRIDE; | 50 virtual int Open(const StreamDeviceInfo& device) OVERRIDE; |
| 50 | 51 |
| 51 virtual void Close(int capture_session_id) OVERRIDE; | 52 virtual void Close(int capture_session_id) OVERRIDE; |
| 52 | 53 |
| 53 // Functions used to start and stop media flow. | 54 // Functions used to start and stop media flow. |
| 54 // Start allocates the device and no other application can use the device | 55 // Start allocates the device and no other application can use the device |
| 55 // before Stop is called. Captured video frames will be delivered to | 56 // before Stop is called. Captured video frames will be delivered to |
| 56 // video_capture_receiver. | 57 // video_capture_receiver. |
| 57 void Start(const media::VideoCaptureParams& capture_params, | 58 virtual void Start(const media::VideoCaptureParams& capture_params, |
| 58 media::VideoCaptureDevice::EventHandler* video_capture_receiver); | 59 media::VideoCaptureDevice::EventHandler* video_capture_receiver); |
| 59 | 60 |
| 60 // Stops capture device referenced by |capture_session_id|. No more frames | 61 // Stops capture device referenced by |capture_session_id|. No more frames |
| 61 // will be delivered to the frame receiver, and |stopped_cb| will be called. | 62 // will be delivered to the frame receiver, and |stopped_cb| will be called. |
| 62 // |stopped_cb| can be NULL. | 63 // |stopped_cb| can be NULL. |
| 63 void Stop(const media::VideoCaptureSessionId& capture_session_id, | 64 virtual void Stop(const media::VideoCaptureSessionId& capture_session_id, |
| 64 base::Closure stopped_cb); | 65 base::Closure stopped_cb); |
| 65 | 66 |
| 66 // A capture device error has occurred for |capture_session_id|. The device | 67 // A capture device error has occurred for |capture_session_id|. The device |
| 67 // won't stream any more captured frames. | 68 // won't stream any more captured frames. |
| 68 void Error(const media::VideoCaptureSessionId& capture_session_id); | 69 virtual void Error(const media::VideoCaptureSessionId& capture_session_id); |
| 69 | 70 |
| 70 // Used by unit test to make sure a fake device is used instead of a real | 71 // Used by unit test to make sure a fake device is used instead of a real |
| 71 // video capture device. Due to timing requirements, the function must be | 72 // video capture device. Due to timing requirements, the function must be |
| 72 // called before EnumerateDevices and Open. | 73 // called before EnumerateDevices and Open. |
| 73 void UseFakeDevice(); | 74 void UseFakeDevice(); |
| 74 MessageLoop* GetMessageLoop(); | 75 MessageLoop* GetMessageLoop(); |
| 75 | 76 |
| 76 // Called by VideoCaptureHost to get a controller for |capture_params|. | 77 // Called by VideoCaptureHost to get a controller for |capture_params|. |
| 77 // The controller is returned via calling |added_cb|. | 78 // The controller is returned via calling |added_cb|. |
| 78 void AddController( | 79 void AddController( |
| 79 const media::VideoCaptureParams& capture_params, | 80 const media::VideoCaptureParams& capture_params, |
| 80 VideoCaptureControllerEventHandler* handler, | 81 VideoCaptureControllerEventHandler* handler, |
| 81 base::Callback<void(VideoCaptureController*)> added_cb); | 82 base::Callback<void(VideoCaptureController*)> added_cb); |
| 82 // Called by VideoCaptureHost to remove the |controller|. | 83 // Called by VideoCaptureHost to remove the |controller|. |
| 83 void RemoveController( | 84 void RemoveController( |
| 84 VideoCaptureController* controller, | 85 VideoCaptureController* controller, |
| 85 VideoCaptureControllerEventHandler* handler); | 86 VideoCaptureControllerEventHandler* handler); |
| 86 | 87 |
| 87 private: | 88 private: |
| 89 friend class ::MockVideoCaptureManager; |
| 88 friend class base::RefCountedThreadSafe<VideoCaptureManager>; | 90 friend class base::RefCountedThreadSafe<VideoCaptureManager>; |
| 89 virtual ~VideoCaptureManager(); | 91 virtual ~VideoCaptureManager(); |
| 90 | 92 |
| 91 typedef std::list<VideoCaptureControllerEventHandler*> Handlers; | 93 typedef std::list<VideoCaptureControllerEventHandler*> Handlers; |
| 92 struct Controller; | 94 struct Controller; |
| 93 | 95 |
| 94 // Called by the public functions, executed on vc_device_thread_. | 96 // Called by the public functions, executed on vc_device_thread_. |
| 95 void OnEnumerateDevices(); | 97 void OnEnumerateDevices(); |
| 96 void OnOpen(int capture_session_id, const StreamDeviceInfo& device); | 98 void OnOpen(int capture_session_id, const StreamDeviceInfo& device); |
| 97 void OnClose(int capture_session_id); | 99 void OnClose(int capture_session_id); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 // VideoCaptureDevice is one-to-one mapped to VideoCaptureController. | 153 // VideoCaptureDevice is one-to-one mapped to VideoCaptureController. |
| 152 typedef std::map<media::VideoCaptureDevice*, Controller*> Controllers; | 154 typedef std::map<media::VideoCaptureDevice*, Controller*> Controllers; |
| 153 Controllers controllers_; | 155 Controllers controllers_; |
| 154 | 156 |
| 155 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); | 157 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); |
| 156 }; | 158 }; |
| 157 | 159 |
| 158 } // namespace media_stream | 160 } // namespace media_stream |
| 159 | 161 |
| 160 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 162 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
| OLD | NEW |