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