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 { | |
scherkus (not reviewing)
2011/10/19 18:02:21
nit: this can be forward declared and the impl mov
wjia(left Chromium)
2011/10/21 00:56:13
Done.
| |
92 Controller(VideoCaptureController* ctrller, | |
93 VideoCaptureControllerEventHandler* handler); | |
94 ~Controller(); | |
95 | |
96 scoped_refptr<VideoCaptureController> controller; | |
97 bool ready_to_delete; | |
98 Handlers handlers; | |
99 }; | |
100 | |
70 // Called by the public functions, executed on vc_device_thread_. | 101 // Called by the public functions, executed on vc_device_thread_. |
71 void OnEnumerateDevices(); | 102 void OnEnumerateDevices(); |
72 void OnOpen(int capture_session_id, const StreamDeviceInfo& device); | 103 void OnOpen(int capture_session_id, const StreamDeviceInfo& device); |
73 void OnClose(int capture_session_id); | 104 void OnClose(int capture_session_id); |
74 void OnStart(const media::VideoCaptureParams capture_params, | 105 void OnStart(const media::VideoCaptureParams capture_params, |
75 media::VideoCaptureDevice::EventHandler* video_capture_receiver); | 106 media::VideoCaptureDevice::EventHandler* video_capture_receiver); |
76 void OnStop(const media::VideoCaptureSessionId capture_session_id, | 107 void OnStop(const media::VideoCaptureSessionId capture_session_id, |
77 base::Closure stopped_cb); | 108 base::Closure stopped_cb); |
109 void DoAddControllerOnDeviceThread( | |
110 const media::VideoCaptureParams capture_params, | |
111 VideoCaptureControllerEventHandler* handler, | |
112 base::Callback<void(VideoCaptureController*)> added_cb); | |
113 void DoRemoveControllerOnDeviceThread( | |
114 VideoCaptureController* controller, | |
115 VideoCaptureControllerEventHandler* handler); | |
116 void DoDeviceStatusFromControllerOnDeviceThread( | |
117 VideoCaptureController* controller, | |
118 bool in_use); | |
78 | 119 |
79 // Executed on Browser::IO thread to call Listener. | 120 // Executed on Browser::IO thread to call Listener. |
80 void OnOpened(int capture_session_id); | 121 void OnOpened(int capture_session_id); |
81 void OnClosed(int capture_session_id); | 122 void OnClosed(int capture_session_id); |
82 void OnDevicesEnumerated(const StreamDeviceInfoArray& devices); | 123 void OnDevicesEnumerated(const StreamDeviceInfoArray& devices); |
83 void OnError(int capture_session_id, MediaStreamProviderError error); | 124 void OnError(int capture_session_id, MediaStreamProviderError error); |
84 | 125 |
85 // Executed on vc_device_thread_ to make sure Listener is called from | 126 // Executed on vc_device_thread_ to make sure Listener is called from |
86 // Browser::IO thread. | 127 // Browser::IO thread. |
87 void PostOnOpened(int capture_session_id); | 128 void PostOnOpened(int capture_session_id); |
88 void PostOnClosed(int capture_session_id); | 129 void PostOnClosed(int capture_session_id); |
89 void PostOnDevicesEnumerated(const StreamDeviceInfoArray& devices); | 130 void PostOnDevicesEnumerated(const StreamDeviceInfoArray& devices); |
90 void PostOnError(int capture_session_id, MediaStreamProviderError error); | 131 void PostOnError(int capture_session_id, MediaStreamProviderError error); |
91 | 132 |
92 // Helpers | 133 // Helpers |
93 void GetAvailableDevices(media::VideoCaptureDevice::Names* device_names); | 134 void GetAvailableDevices(media::VideoCaptureDevice::Names* device_names); |
94 bool DeviceOpened(const media::VideoCaptureDevice::Name& device_name); | 135 bool DeviceOpened(const media::VideoCaptureDevice::Name& device_name); |
95 bool DeviceOpened(const StreamDeviceInfo& device_info); | 136 bool DeviceOpened(const StreamDeviceInfo& device_info); |
96 bool IsOnCaptureDeviceThread() const; | 137 bool IsOnCaptureDeviceThread() const; |
138 media::VideoCaptureDevice* GetDeviceInternal(int capture_session_id); | |
97 | 139 |
98 // Thread for all calls to VideoCaptureDevice. | 140 // Thread for all calls to VideoCaptureDevice. |
99 base::Thread vc_device_thread_; | 141 base::Thread vc_device_thread_; |
100 | 142 |
101 // Only accessed on Browser::IO thread. | 143 // Only accessed on Browser::IO thread. |
102 MediaStreamProviderListener* listener_; | 144 MediaStreamProviderListener* listener_; |
103 int new_capture_session_id_; | 145 int new_capture_session_id_; |
104 | 146 |
105 // Only accessed from vc_device_thread_. | 147 // Only accessed from vc_device_thread_. |
106 // VideoCaptureManager owns all VideoCaptureDevices and is responsible for | 148 // VideoCaptureManager owns all VideoCaptureDevices and is responsible for |
107 // deleting the instances when they are not used any longer. | 149 // deleting the instances when they are not used any longer. |
108 typedef std::map<int, media::VideoCaptureDevice*> VideoCaptureDevices; | 150 typedef std::map<int, media::VideoCaptureDevice*> VideoCaptureDevices; |
109 VideoCaptureDevices devices_; | 151 VideoCaptureDevices devices_; |
110 | 152 |
111 // Set to true if using fake devices for testing, false by default. | 153 // Set to true if using fake devices for testing, false by default. |
112 bool use_fake_device_; | 154 bool use_fake_device_; |
113 | 155 |
156 // Only accessed from vc_device_thread_. | |
157 // VideoCaptureManager owns all VideoCaptureController's and is responsible | |
158 // for deleting the instances when they are not used any longer. | |
159 // VideoCaptureDevice is one-to-one mapped to VideoCaptureController. | |
160 typedef std::map<media::VideoCaptureDevice*, Controller*> Controllers; | |
161 Controllers controllers_; | |
162 | |
114 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); | 163 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); |
115 }; | 164 }; |
116 | 165 |
117 } // namespace media_stream | 166 } // namespace media_stream |
118 | 167 |
119 DISABLE_RUNNABLE_METHOD_REFCOUNT(media_stream::VideoCaptureManager); | 168 DISABLE_RUNNABLE_METHOD_REFCOUNT(media_stream::VideoCaptureManager); |
120 | 169 |
121 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 170 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
OLD | NEW |