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