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 12 matching lines...) Expand all Loading... | |
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/supports_user_data.h" | 32 #include "base/supports_user_data.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" |
38 #include "content/public/browser/browser_thread.h" | |
39 | |
40 #if defined(OS_WIN) | |
41 #include <objbase.h> // For CoInitialize/CoUninitialize. | |
42 #endif | |
37 | 43 |
38 namespace content { | 44 namespace content { |
39 class ResourceContext; | 45 class ResourceContext; |
40 } | 46 } |
41 | 47 |
42 namespace media { | |
43 class AudioManager; | |
44 } | |
45 | |
46 namespace media_stream { | 48 namespace media_stream { |
47 | 49 |
48 class AudioInputDeviceManager; | 50 class AudioInputDeviceManager; |
49 class MediaStreamDeviceSettings; | 51 class MediaStreamDeviceSettings; |
50 class MediaStreamRequester; | 52 class MediaStreamRequester; |
51 class VideoCaptureManager; | 53 class VideoCaptureManager; |
52 | 54 |
55 // Thread that enters STA on windows, and is base::thread on linux and mac. | |
56 class DeviceThread : public base::Thread { | |
57 public: | |
58 explicit DeviceThread(const char *name) : base::Thread(name) {} | |
tommi (sloooow) - chröme
2012/07/02 13:36:36
const char* name
no longer working on chromium
2012/07/04 12:35:25
Done.
| |
59 | |
60 protected: | |
61 #if defined(OS_WIN) | |
62 // Called just prior to starting the message loop. | |
63 virtual void Init() { | |
64 CoInitialize(NULL); | |
tommi (sloooow) - chröme
2012/07/02 13:36:36
use the ScopedCOMInitializer class and remove the
no longer working on chromium
2012/07/04 12:35:25
Done.
| |
65 } | |
66 | |
67 // Called just after the message loop ends. | |
68 virtual void CleanUp() { | |
69 CoUninitialize(); | |
70 } | |
71 #endif | |
72 DISALLOW_COPY_AND_ASSIGN(DeviceThread); | |
73 }; | |
74 | |
53 // MediaStreamManager is used to generate and close new media devices, not to | 75 // MediaStreamManager is used to generate and close new media devices, not to |
54 // start the media flow. | 76 // start the media flow. |
55 // The classes requesting new media streams are answered using | 77 // The classes requesting new media streams are answered using |
56 // MediaStreamManager::Listener. | 78 // MediaStreamManager::Listener. |
57 class CONTENT_EXPORT MediaStreamManager | 79 class CONTENT_EXPORT MediaStreamManager |
58 : public MediaStreamProviderListener, | 80 : public MediaStreamProviderListener, |
59 public SettingsRequester, | 81 public SettingsRequester, |
60 public base::SupportsUserData::Data { | 82 public base::SupportsUserData::Data { |
61 public: | 83 public: |
62 // Returns the MediaStreamManager for the given ResourceContext. If it hasn't | 84 // Returns the MediaStreamManager for the given ResourceContext. If it hasn't |
63 // been created yet, it will be constructed with the given AudioManager. | 85 // been created yet, it will be constructed with the given AudioManager. |
64 static MediaStreamManager* GetForResourceContext( | 86 static MediaStreamManager* GetForResourceContext( |
65 content::ResourceContext* resource_context, | 87 content::ResourceContext* resource_context); |
66 media::AudioManager* audio_manager); | |
67 | 88 |
68 explicit MediaStreamManager(media::AudioManager* audio_manager); | 89 MediaStreamManager(); |
90 | |
69 virtual ~MediaStreamManager(); | 91 virtual ~MediaStreamManager(); |
70 | 92 |
71 // Used to access VideoCaptureManager. | 93 // Used to access VideoCaptureManager. |
72 VideoCaptureManager* video_capture_manager(); | 94 VideoCaptureManager* video_capture_manager(); |
73 | 95 |
74 // Used to access AudioInputDeviceManager. | 96 // Used to access AudioInputDeviceManager. |
75 AudioInputDeviceManager* audio_input_device_manager(); | 97 AudioInputDeviceManager* audio_input_device_manager(); |
76 | 98 |
77 // GenerateStream opens new media devices according to |components|. The | 99 // GenerateStream opens new media devices according to |components|. The |
78 // request is identified using |label|, which is pointing to an already | 100 // request is identified using |label|, which is pointing to an already |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 void NotifyObserverDevicesClosed(DeviceRequest* request); | 164 void NotifyObserverDevicesClosed(DeviceRequest* request); |
143 void DevicesFromRequest(DeviceRequest* request, | 165 void DevicesFromRequest(DeviceRequest* request, |
144 content::MediaStreamDevices* devices); | 166 content::MediaStreamDevices* devices); |
145 | 167 |
146 // Helpers. | 168 // Helpers. |
147 bool RequestDone(const MediaStreamManager::DeviceRequest& request) const; | 169 bool RequestDone(const MediaStreamManager::DeviceRequest& request) const; |
148 MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type); | 170 MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type); |
149 void StartEnumeration(DeviceRequest* new_request, | 171 void StartEnumeration(DeviceRequest* new_request, |
150 std::string* label); | 172 std::string* label); |
151 | 173 |
174 // Helper to ensure the device thread before passing to device managers. | |
175 void EnsureDeviceThread(); | |
176 | |
177 // Device thread shared by VideoCaptureManager and AudioInputDeviceManager. | |
178 scoped_ptr<base::Thread> device_thread_; | |
179 | |
152 scoped_ptr<MediaStreamDeviceSettings> device_settings_; | 180 scoped_ptr<MediaStreamDeviceSettings> device_settings_; |
153 scoped_refptr<VideoCaptureManager> video_capture_manager_; | 181 scoped_refptr<VideoCaptureManager> video_capture_manager_; |
154 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_; | 182 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_; |
155 | 183 |
156 // Keeps track of device types currently being enumerated to not enumerate | 184 // Keeps track of device types currently being enumerated to not enumerate |
157 // when not necessary. | 185 // when not necessary. |
158 std::vector<bool> enumeration_in_progress_; | 186 std::vector<bool> enumeration_in_progress_; |
159 | 187 |
160 // All non-closed request. | 188 // All non-closed request. |
161 typedef std::map<std::string, DeviceRequest> DeviceRequests; | 189 typedef std::map<std::string, DeviceRequest> DeviceRequests; |
162 DeviceRequests requests_; | 190 DeviceRequests requests_; |
163 media::AudioManager* audio_manager_; | |
164 | 191 |
165 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); | 192 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); |
166 }; | 193 }; |
167 | 194 |
168 } // namespace media_stream | 195 } // namespace media_stream |
169 | 196 |
170 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ | 197 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ |
OLD | NEW |