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 // MediaStreamManager is used to open/enumerate media capture devices (video | 5 // MediaStreamManager is used to open/enumerate media capture devices (video |
6 // supported now). Call flow: | 6 // supported now). Call flow: |
7 // 1. GenerateStream is called when a render process wants to use a capture | 7 // 1. GenerateStream is called when a render process wants to use a capture |
8 // device. | 8 // device. |
9 // 2. MediaStreamManager will ask MediaStreamDeviceSettings for permission to | 9 // 2. MediaStreamManager will ask MediaStreamDeviceSettings for permission to |
10 // use devices and for which device to use. | 10 // use devices and for which device to use. |
(...skipping 11 matching lines...) Expand all Loading... |
22 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ | 22 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ |
23 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ | 23 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ |
24 | 24 |
25 #include <map> | 25 #include <map> |
26 #include <string> | 26 #include <string> |
27 #include <vector> | 27 #include <vector> |
28 | 28 |
29 #include "base/basictypes.h" | 29 #include "base/basictypes.h" |
30 #include "base/memory/scoped_ptr.h" | 30 #include "base/memory/scoped_ptr.h" |
31 #include "base/memory/ref_counted.h" | 31 #include "base/memory/ref_counted.h" |
| 32 #include "base/message_loop.h" |
32 #include "base/threading/thread.h" | 33 #include "base/threading/thread.h" |
33 #include "content/browser/renderer_host/media/media_stream_provider.h" | 34 #include "content/browser/renderer_host/media/media_stream_provider.h" |
34 #include "content/browser/renderer_host/media/media_stream_settings_requester.h" | 35 #include "content/browser/renderer_host/media/media_stream_settings_requester.h" |
35 #include "content/common/media/media_stream_options.h" | 36 #include "content/common/media/media_stream_options.h" |
36 #include "content/common/content_export.h" | 37 #include "content/common/content_export.h" |
37 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
38 | 39 |
39 namespace base { | 40 namespace base { |
40 namespace win { | 41 namespace win { |
41 class ScopedCOMInitializer; | 42 class ScopedCOMInitializer; |
(...skipping 21 matching lines...) Expand all Loading... |
63 scoped_ptr<base::win::ScopedCOMInitializer> com_initializer_; | 64 scoped_ptr<base::win::ScopedCOMInitializer> com_initializer_; |
64 DISALLOW_COPY_AND_ASSIGN(DeviceThread); | 65 DISALLOW_COPY_AND_ASSIGN(DeviceThread); |
65 }; | 66 }; |
66 | 67 |
67 // MediaStreamManager is used to generate and close new media devices, not to | 68 // MediaStreamManager is used to generate and close new media devices, not to |
68 // start the media flow. | 69 // start the media flow. |
69 // The classes requesting new media streams are answered using | 70 // The classes requesting new media streams are answered using |
70 // MediaStreamManager::Listener. | 71 // MediaStreamManager::Listener. |
71 class CONTENT_EXPORT MediaStreamManager | 72 class CONTENT_EXPORT MediaStreamManager |
72 : public MediaStreamProviderListener, | 73 : public MediaStreamProviderListener, |
| 74 public MessageLoop::DestructionObserver, |
73 public SettingsRequester { | 75 public SettingsRequester { |
74 public: | 76 public: |
75 // This class takes the ownerships of the |audio_input_device_manager| | 77 // This class takes the ownerships of the |audio_input_device_manager| |
76 // and |video_capture_manager|. | 78 // and |video_capture_manager|. |
77 MediaStreamManager(AudioInputDeviceManager* audio_input_device_manager, | 79 MediaStreamManager(AudioInputDeviceManager* audio_input_device_manager, |
78 VideoCaptureManager* video_capture_manager); | 80 VideoCaptureManager* video_capture_manager); |
79 | 81 |
80 virtual ~MediaStreamManager(); | 82 virtual ~MediaStreamManager(); |
81 | 83 |
82 // Used to access VideoCaptureManager. | 84 // Used to access VideoCaptureManager. |
83 VideoCaptureManager* video_capture_manager(); | 85 VideoCaptureManager* video_capture_manager(); |
84 | 86 |
85 // Used to access AudioInputDeviceManager. | 87 // Used to access AudioInputDeviceManager. |
86 AudioInputDeviceManager* audio_input_device_manager(); | 88 AudioInputDeviceManager* audio_input_device_manager(); |
87 | 89 |
88 // GenerateStream opens new media devices according to |components|. The | 90 // GenerateStream opens new media devices according to |components|. It |
89 // request is identified using |label|, which is pointing to an already | 91 // creates a new request which is identified by a unique |label| that's |
90 // created std::string. | 92 // returned to the caller. |
91 void GenerateStream(MediaStreamRequester* requester, int render_process_id, | 93 void GenerateStream(MediaStreamRequester* requester, int render_process_id, |
92 int render_view_id, const StreamOptions& options, | 94 int render_view_id, const StreamOptions& options, |
93 const GURL& security_origin, std::string* label); | 95 const GURL& security_origin, std::string* label); |
94 | 96 |
95 // Cancels all non-finished GenerateStream request, i.e. request for which | 97 // Cancels all non-finished GenerateStream request, i.e. request for which |
96 // StreamGenerated hasn't been called. | 98 // StreamGenerated hasn't been called. |
97 void CancelRequests(MediaStreamRequester* requester); | 99 void CancelRequests(MediaStreamRequester* requester); |
98 | 100 |
99 // Cancel generate stream. | 101 // Cancel generate stream. |
100 void CancelGenerateStream(const std::string& label); | 102 void CancelGenerateStream(const std::string& label); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 virtual void DevicesAccepted(const std::string& label, | 140 virtual void DevicesAccepted(const std::string& label, |
139 const StreamDeviceInfoArray& devices) OVERRIDE; | 141 const StreamDeviceInfoArray& devices) OVERRIDE; |
140 virtual void SettingsError(const std::string& label) OVERRIDE; | 142 virtual void SettingsError(const std::string& label) OVERRIDE; |
141 | 143 |
142 // Used by unit test to make sure fake devices are used instead of a real | 144 // Used by unit test to make sure fake devices are used instead of a real |
143 // devices, which is needed for server based testing. | 145 // devices, which is needed for server based testing. |
144 // TODO(xians): Remove this hack since we can create our own | 146 // TODO(xians): Remove this hack since we can create our own |
145 // MediaStreamManager in our unit tests. | 147 // MediaStreamManager in our unit tests. |
146 void UseFakeDevice(); | 148 void UseFakeDevice(); |
147 | 149 |
| 150 // This object gets deleted on the UI thread after the IO thread has been |
| 151 // destroyed. So we need to know when IO thread is being destroyed so that |
| 152 // we can delete VideoCaptureManager and AudioInputDeviceManager. |
| 153 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; |
| 154 |
148 private: | 155 private: |
149 // Contains all data needed to keep track of requests. | 156 // Contains all data needed to keep track of requests. |
150 struct DeviceRequest; | 157 struct DeviceRequest; |
151 | 158 |
152 // Helpers for signaling the media observer that new capture devices are | 159 // Helpers for signaling the media observer that new capture devices are |
153 // opened/closed. | 160 // opened/closed. |
154 void NotifyObserverDevicesOpened(DeviceRequest* request); | 161 void NotifyObserverDevicesOpened(DeviceRequest* request); |
155 void NotifyObserverDevicesClosed(DeviceRequest* request); | 162 void NotifyObserverDevicesClosed(DeviceRequest* request); |
156 void DevicesFromRequest(DeviceRequest* request, | 163 void DevicesFromRequest(DeviceRequest* request, |
157 content::MediaStreamDevices* devices); | 164 content::MediaStreamDevices* devices); |
(...skipping 16 matching lines...) Expand all Loading... |
174 scoped_refptr<VideoCaptureManager> video_capture_manager_; | 181 scoped_refptr<VideoCaptureManager> video_capture_manager_; |
175 | 182 |
176 // Keeps track of device types currently being enumerated to not enumerate | 183 // Keeps track of device types currently being enumerated to not enumerate |
177 // when not necessary. | 184 // when not necessary. |
178 std::vector<bool> enumeration_in_progress_; | 185 std::vector<bool> enumeration_in_progress_; |
179 | 186 |
180 // All non-closed request. | 187 // All non-closed request. |
181 typedef std::map<std::string, DeviceRequest> DeviceRequests; | 188 typedef std::map<std::string, DeviceRequest> DeviceRequests; |
182 DeviceRequests requests_; | 189 DeviceRequests requests_; |
183 | 190 |
| 191 // Hold a pointer to the IO loop to check we delete the device thread and |
| 192 // managers on the right thread. |
| 193 MessageLoop* io_loop_; |
| 194 |
184 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); | 195 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); |
185 }; | 196 }; |
186 | 197 |
187 } // namespace media_stream | 198 } // namespace media_stream |
188 | 199 |
189 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ | 200 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ |
OLD | NEW |