OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 as well as enumerate | 5 // VideoCaptureManager is used to open/close, start/stop, enumerate available |
6 // available video capture devices. All functions are expected to be called from | 6 // video capture devices, and manage VideoCaptureController's. |
7 // the Browser::IO thread. VideoCaptureManager will open OS dependent instances | 7 // All functions are expected to be called from Browser::IO thread. |
8 // of VideoCaptureDevice. A device can only be opened once. | 8 // VideoCaptureManager will open OS dependent instances of VideoCaptureDevice. |
| 9 // A device can only be opened once. |
9 | 10 |
10 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 11 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
11 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 12 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
12 | 13 |
| 14 #include <list> |
13 #include <map> | 15 #include <map> |
14 | 16 |
15 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
16 #include "content/browser/renderer_host/media/media_stream_provider.h" | 18 #include "content/browser/renderer_host/media/media_stream_provider.h" |
17 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
18 #include "content/common/media/media_stream_options.h" | 20 #include "content/common/media/media_stream_options.h" |
19 #include "media/video/capture/video_capture_device.h" | 21 #include "media/video/capture/video_capture_device.h" |
20 #include "media/video/capture/video_capture_types.h" | 22 #include "media/video/capture/video_capture_types.h" |
21 | 23 |
| 24 class VideoCaptureController; |
| 25 class VideoCaptureControllerEventHandler; |
| 26 |
22 namespace media_stream { | 27 namespace media_stream { |
23 | 28 |
24 // VideoCaptureManager opens/closes and start/stops video capture devices. | 29 // VideoCaptureManager opens/closes and start/stops video capture devices. |
25 class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider { | 30 class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider { |
26 public: | 31 public: |
27 // Calling |Start| of this id will open the first device, even though open has | 32 // Calling |Start| of this id will open the first device, even though open has |
28 // not been called. This is used to be able to use video capture devices | 33 // not been called. This is used to be able to use video capture devices |
29 // before MediaStream is implemented in Chrome and WebKit. | 34 // before MediaStream is implemented in Chrome and WebKit. |
30 enum { kStartOpenSessionId = 1 }; | 35 enum { kStartOpenSessionId = 1 }; |
31 | 36 |
(...skipping 27 matching lines...) Expand all Loading... |
59 // A capture device error has occurred for |capture_session_id|. The device | 64 // A capture device error has occurred for |capture_session_id|. The device |
60 // won't stream any more captured frames. | 65 // won't stream any more captured frames. |
61 void Error(const media::VideoCaptureSessionId& capture_session_id); | 66 void Error(const media::VideoCaptureSessionId& capture_session_id); |
62 | 67 |
63 // Used by unit test to make sure a fake device is used instead of a real | 68 // Used by unit test to make sure a fake device is used instead of a real |
64 // video capture device. Due to timing requirements, the function must be | 69 // video capture device. Due to timing requirements, the function must be |
65 // called before EnumerateDevices and Open. | 70 // called before EnumerateDevices and Open. |
66 void UseFakeDevice(); | 71 void UseFakeDevice(); |
67 MessageLoop* GetMessageLoop(); | 72 MessageLoop* GetMessageLoop(); |
68 | 73 |
| 74 // Called by VideoCaptureHost to get a controller for |capture_params|. |
| 75 // The controller is returned via calling |added_cb|. |
| 76 void AddController( |
| 77 const media::VideoCaptureParams& capture_params, |
| 78 VideoCaptureControllerEventHandler* handler, |
| 79 base::Callback<void(VideoCaptureController*)> added_cb); |
| 80 // Called by VideoCaptureHost to remove the |controller|. |
| 81 void RemoveController( |
| 82 VideoCaptureController* controller, |
| 83 VideoCaptureControllerEventHandler* handler); |
| 84 |
| 85 // Called by |controller| to signal it's in use or not. |
| 86 void DeviceStatusFromController(VideoCaptureController* controller, |
| 87 bool in_use); |
| 88 |
69 private: | 89 private: |
| 90 typedef std::list<VideoCaptureControllerEventHandler*> Handlers; |
| 91 struct Controller; |
| 92 |
70 // Called by the public functions, executed on vc_device_thread_. | 93 // Called by the public functions, executed on vc_device_thread_. |
71 void OnEnumerateDevices(); | 94 void OnEnumerateDevices(); |
72 void OnOpen(int capture_session_id, const StreamDeviceInfo& device); | 95 void OnOpen(int capture_session_id, const StreamDeviceInfo& device); |
73 void OnClose(int capture_session_id); | 96 void OnClose(int capture_session_id); |
74 void OnStart(const media::VideoCaptureParams capture_params, | 97 void OnStart(const media::VideoCaptureParams capture_params, |
75 media::VideoCaptureDevice::EventHandler* video_capture_receiver); | 98 media::VideoCaptureDevice::EventHandler* video_capture_receiver); |
76 void OnStop(const media::VideoCaptureSessionId capture_session_id, | 99 void OnStop(const media::VideoCaptureSessionId capture_session_id, |
77 base::Closure stopped_cb); | 100 base::Closure stopped_cb); |
| 101 void DoAddControllerOnDeviceThread( |
| 102 const media::VideoCaptureParams capture_params, |
| 103 VideoCaptureControllerEventHandler* handler, |
| 104 base::Callback<void(VideoCaptureController*)> added_cb); |
| 105 void DoRemoveControllerOnDeviceThread( |
| 106 VideoCaptureController* controller, |
| 107 VideoCaptureControllerEventHandler* handler); |
| 108 void DoDeviceStatusFromControllerOnDeviceThread( |
| 109 VideoCaptureController* controller, |
| 110 bool in_use); |
78 | 111 |
79 // Executed on Browser::IO thread to call Listener. | 112 // Executed on Browser::IO thread to call Listener. |
80 void OnOpened(int capture_session_id); | 113 void OnOpened(int capture_session_id); |
81 void OnClosed(int capture_session_id); | 114 void OnClosed(int capture_session_id); |
82 void OnDevicesEnumerated(const StreamDeviceInfoArray& devices); | 115 void OnDevicesEnumerated(const StreamDeviceInfoArray& devices); |
83 void OnError(int capture_session_id, MediaStreamProviderError error); | 116 void OnError(int capture_session_id, MediaStreamProviderError error); |
84 | 117 |
85 // Executed on vc_device_thread_ to make sure Listener is called from | 118 // Executed on vc_device_thread_ to make sure Listener is called from |
86 // Browser::IO thread. | 119 // Browser::IO thread. |
87 void PostOnOpened(int capture_session_id); | 120 void PostOnOpened(int capture_session_id); |
88 void PostOnClosed(int capture_session_id); | 121 void PostOnClosed(int capture_session_id); |
89 void PostOnDevicesEnumerated(const StreamDeviceInfoArray& devices); | 122 void PostOnDevicesEnumerated(const StreamDeviceInfoArray& devices); |
90 void PostOnError(int capture_session_id, MediaStreamProviderError error); | 123 void PostOnError(int capture_session_id, MediaStreamProviderError error); |
91 | 124 |
92 // Helpers | 125 // Helpers |
93 void GetAvailableDevices(media::VideoCaptureDevice::Names* device_names); | 126 void GetAvailableDevices(media::VideoCaptureDevice::Names* device_names); |
94 bool DeviceOpened(const media::VideoCaptureDevice::Name& device_name); | 127 bool DeviceOpened(const media::VideoCaptureDevice::Name& device_name); |
95 bool DeviceOpened(const StreamDeviceInfo& device_info); | 128 bool DeviceOpened(const StreamDeviceInfo& device_info); |
96 bool IsOnCaptureDeviceThread() const; | 129 bool IsOnCaptureDeviceThread() const; |
| 130 media::VideoCaptureDevice* GetDeviceInternal(int capture_session_id); |
97 | 131 |
98 // Thread for all calls to VideoCaptureDevice. | 132 // Thread for all calls to VideoCaptureDevice. |
99 base::Thread vc_device_thread_; | 133 base::Thread vc_device_thread_; |
100 | 134 |
101 // Only accessed on Browser::IO thread. | 135 // Only accessed on Browser::IO thread. |
102 MediaStreamProviderListener* listener_; | 136 MediaStreamProviderListener* listener_; |
103 int new_capture_session_id_; | 137 int new_capture_session_id_; |
104 | 138 |
105 // Only accessed from vc_device_thread_. | 139 // Only accessed from vc_device_thread_. |
106 // VideoCaptureManager owns all VideoCaptureDevices and is responsible for | 140 // VideoCaptureManager owns all VideoCaptureDevices and is responsible for |
107 // deleting the instances when they are not used any longer. | 141 // deleting the instances when they are not used any longer. |
108 typedef std::map<int, media::VideoCaptureDevice*> VideoCaptureDevices; | 142 typedef std::map<int, media::VideoCaptureDevice*> VideoCaptureDevices; |
109 VideoCaptureDevices devices_; | 143 VideoCaptureDevices devices_; |
110 | 144 |
111 // Set to true if using fake devices for testing, false by default. | 145 // Set to true if using fake devices for testing, false by default. |
112 bool use_fake_device_; | 146 bool use_fake_device_; |
113 | 147 |
| 148 // Only accessed from vc_device_thread_. |
| 149 // VideoCaptureManager owns all VideoCaptureController's and is responsible |
| 150 // for deleting the instances when they are not used any longer. |
| 151 // VideoCaptureDevice is one-to-one mapped to VideoCaptureController. |
| 152 typedef std::map<media::VideoCaptureDevice*, Controller*> Controllers; |
| 153 Controllers controllers_; |
| 154 |
114 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); | 155 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); |
115 }; | 156 }; |
116 | 157 |
117 } // namespace media_stream | 158 } // namespace media_stream |
118 | 159 |
119 DISABLE_RUNNABLE_METHOD_REFCOUNT(media_stream::VideoCaptureManager); | 160 DISABLE_RUNNABLE_METHOD_REFCOUNT(media_stream::VideoCaptureManager); |
120 | 161 |
121 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 162 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
OLD | NEW |