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 |
(...skipping 11 matching lines...) Expand all Loading... |
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 MockVideoCaptureManager; |
26 class VideoCaptureController; | 26 class VideoCaptureController; |
27 class VideoCaptureControllerEventHandler; | 27 class VideoCaptureControllerEventHandler; |
28 | 28 |
29 namespace media_stream { | 29 namespace media_stream { |
30 | 30 |
31 // VideoCaptureManager opens/closes and start/stops video capture devices. | 31 // VideoCaptureManager opens/closes and start/stops video capture devices. |
32 class CONTENT_EXPORT VideoCaptureManager | 32 class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider { |
33 : public base::RefCountedThreadSafe<VideoCaptureManager>, | |
34 public MediaStreamProvider { | |
35 public: | 33 public: |
36 // Calling |Start| of this id will open the first device, even though open has | 34 // Calling |Start| of this id will open the first device, even though open has |
37 // not been called. This is used to be able to use video capture devices | 35 // not been called. This is used to be able to use video capture devices |
38 // before MediaStream is implemented in Chrome and WebKit. | 36 // before MediaStream is implemented in Chrome and WebKit. |
39 enum { kStartOpenSessionId = 1 }; | 37 enum { kStartOpenSessionId = 1 }; |
40 | 38 |
41 VideoCaptureManager(); | 39 VideoCaptureManager(); |
42 | 40 |
43 // Implements MediaStreamProvider. | 41 // Implements MediaStreamProvider. |
44 virtual void Register(MediaStreamProviderListener* listener, | 42 virtual void Register(MediaStreamProviderListener* listener, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 const media::VideoCaptureParams& capture_params, | 78 const media::VideoCaptureParams& capture_params, |
81 VideoCaptureControllerEventHandler* handler, | 79 VideoCaptureControllerEventHandler* handler, |
82 base::Callback<void(VideoCaptureController*)> added_cb); | 80 base::Callback<void(VideoCaptureController*)> added_cb); |
83 // Called by VideoCaptureHost to remove the |controller|. | 81 // Called by VideoCaptureHost to remove the |controller|. |
84 void RemoveController( | 82 void RemoveController( |
85 VideoCaptureController* controller, | 83 VideoCaptureController* controller, |
86 VideoCaptureControllerEventHandler* handler); | 84 VideoCaptureControllerEventHandler* handler); |
87 | 85 |
88 private: | 86 private: |
89 friend class ::MockVideoCaptureManager; | 87 friend class ::MockVideoCaptureManager; |
90 friend class base::RefCountedThreadSafe<VideoCaptureManager>; | |
91 | 88 |
92 virtual ~VideoCaptureManager(); | 89 virtual ~VideoCaptureManager(); |
93 | 90 |
94 typedef std::list<VideoCaptureControllerEventHandler*> Handlers; | 91 typedef std::list<VideoCaptureControllerEventHandler*> Handlers; |
95 struct Controller; | 92 struct Controller; |
96 | 93 |
97 // Called by the public functions, executed on device thread. | 94 // Called by the public functions, executed on device thread. |
98 void OnEnumerateDevices(); | 95 void OnEnumerateDevices(); |
99 void OnOpen(int capture_session_id, const StreamDeviceInfo& device); | 96 void OnOpen(int capture_session_id, const StreamDeviceInfo& device); |
100 void OnClose(int capture_session_id); | 97 void OnClose(int capture_session_id); |
101 void OnStart(const media::VideoCaptureParams capture_params, | 98 void OnStart(const media::VideoCaptureParams capture_params, |
102 media::VideoCaptureDevice::EventHandler* video_capture_receiver); | 99 media::VideoCaptureDevice::EventHandler* video_capture_receiver); |
103 void OnStop(const media::VideoCaptureSessionId capture_session_id, | 100 void OnStop(const media::VideoCaptureSessionId capture_session_id, |
104 base::Closure stopped_cb); | 101 base::Closure stopped_cb); |
105 void DoAddControllerOnDeviceThread( | 102 void DoAddControllerOnDeviceThread( |
106 const media::VideoCaptureParams capture_params, | 103 const media::VideoCaptureParams capture_params, |
107 VideoCaptureControllerEventHandler* handler, | 104 VideoCaptureControllerEventHandler* handler, |
108 base::Callback<void(VideoCaptureController*)> added_cb); | 105 base::Callback<void(VideoCaptureController*)> added_cb); |
109 void DoRemoveControllerOnDeviceThread( | 106 void DoRemoveControllerOnDeviceThread( |
110 VideoCaptureController* controller, | 107 VideoCaptureController* controller, |
111 VideoCaptureControllerEventHandler* handler); | 108 VideoCaptureControllerEventHandler* handler); |
112 | 109 |
113 // Executed on Browser::IO thread to call Listener. | 110 // Executed on Browser::IO thread to call Listener. |
114 void OnOpened(int capture_session_id); | 111 void OnOpened(content::MediaStreamDeviceType type, int capture_session_id); |
115 void OnClosed(int capture_session_id); | 112 void OnClosed(content::MediaStreamDeviceType type, int capture_session_id); |
116 void OnDevicesEnumerated(const StreamDeviceInfoArray& devices); | 113 void OnDevicesEnumerated(const StreamDeviceInfoArray& devices); |
117 void OnError(int capture_session_id, MediaStreamProviderError error); | 114 void OnError(content::MediaStreamDeviceType type, int capture_session_id, |
| 115 MediaStreamProviderError error); |
118 | 116 |
119 // Executed on device thread to make sure Listener is called from | 117 // Executed on device thread to make sure Listener is called from |
120 // Browser::IO thread. | 118 // Browser::IO thread. |
121 void PostOnOpened(int capture_session_id); | 119 void PostOnOpened(content::MediaStreamDeviceType type, |
122 void PostOnClosed(int capture_session_id); | 120 int capture_session_id); |
| 121 void PostOnClosed(content::MediaStreamDeviceType type, |
| 122 int capture_session_id); |
123 void PostOnDevicesEnumerated(const StreamDeviceInfoArray& devices); | 123 void PostOnDevicesEnumerated(const StreamDeviceInfoArray& devices); |
124 void PostOnError(int capture_session_id, MediaStreamProviderError error); | 124 void PostOnError(int capture_session_id, MediaStreamProviderError error); |
125 | 125 |
126 // Helpers | 126 // Helpers |
127 void GetAvailableDevices(media::VideoCaptureDevice::Names* device_names); | 127 void GetAvailableDevices(media::VideoCaptureDevice::Names* device_names); |
128 bool DeviceOpened(const media::VideoCaptureDevice::Name& device_name); | 128 bool DeviceOpened(const media::VideoCaptureDevice::Name& device_name); |
129 bool DeviceInUse(const media::VideoCaptureDevice* video_capture_device); | 129 bool DeviceInUse(const media::VideoCaptureDevice* video_capture_device); |
130 media::VideoCaptureDevice* GetOpenedDevice( | 130 media::VideoCaptureDevice* GetOpenedDevice( |
131 const StreamDeviceInfo& device_info); | 131 const StreamDeviceInfo& device_info); |
132 bool IsOnDeviceThread() const; | 132 bool IsOnDeviceThread() const; |
133 media::VideoCaptureDevice* GetDeviceInternal(int capture_session_id); | 133 media::VideoCaptureDevice* GetDeviceInternal(int capture_session_id); |
134 | 134 |
135 // The message loop of media stream device thread that this object runs on. | 135 // The message loop of media stream device thread that this object runs on. |
136 scoped_refptr<base::MessageLoopProxy> device_loop_; | 136 scoped_refptr<base::MessageLoopProxy> device_loop_; |
137 | 137 |
138 // Only accessed on Browser::IO thread. | 138 // Only accessed on Browser::IO thread. |
139 MediaStreamProviderListener* listener_; | 139 MediaStreamProviderListener* listener_; |
140 int new_capture_session_id_; | 140 int new_capture_session_id_; |
141 | 141 |
142 // Only accessed from device thread. | 142 // Only accessed from device thread. |
143 // VideoCaptureManager owns all VideoCaptureDevices and is responsible for | 143 // VideoCaptureManager owns all VideoCaptureDevices and is responsible for |
144 // deleting the instances when they are not used any longer. | 144 // deleting the instances when they are not used any longer. |
145 typedef std::map<int, media::VideoCaptureDevice*> VideoCaptureDevices; | 145 struct DeviceEntry { |
146 VideoCaptureDevices devices_; | 146 content::MediaStreamDeviceType stream_type; |
| 147 media::VideoCaptureDevice* capture_device; // Maybe shared across sessions. |
| 148 }; |
| 149 typedef std::map<int, DeviceEntry> VideoCaptureDevices; |
| 150 VideoCaptureDevices devices_; // Maps capture_session_id to DeviceEntry. |
147 | 151 |
148 // Set to true if using fake devices for testing, false by default. | 152 // Set to true if using fake devices for testing, false by default. |
149 bool use_fake_device_; | 153 bool use_fake_device_; |
150 | 154 |
151 // Only accessed from device thread. | 155 // Only accessed from device thread. |
152 // VideoCaptureManager owns all VideoCaptureController's and is responsible | 156 // VideoCaptureManager owns all VideoCaptureController's and is responsible |
153 // for deleting the instances when they are not used any longer. | 157 // for deleting the instances when they are not used any longer. |
154 // VideoCaptureDevice is one-to-one mapped to VideoCaptureController. | 158 // VideoCaptureDevice is one-to-one mapped to VideoCaptureController. |
155 typedef std::map<media::VideoCaptureDevice*, Controller*> Controllers; | 159 typedef std::map<media::VideoCaptureDevice*, Controller*> Controllers; |
156 Controllers controllers_; | 160 Controllers controllers_; |
157 | 161 |
158 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); | 162 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); |
159 }; | 163 }; |
160 | 164 |
161 } // namespace media_stream | 165 } // namespace media_stream |
162 | 166 |
163 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 167 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
OLD | NEW |