| 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 MediaStreamUIController for permission to | 9 // 2. MediaStreamManager will ask MediaStreamUIController for permission to |
| 10 // use devices and for which device to use. | 10 // use devices and for which device to use. |
| 11 // 3. MediaStreamManager will request the corresponding media device manager(s) | 11 // 3. MediaStreamManager will request the corresponding media device manager(s) |
| 12 // to enumerate available devices. The result will be given to | 12 // to enumerate available devices. The result will be given to |
| 13 // MediaStreamUIController. | 13 // MediaStreamUIController. |
| 14 // 4. MediaStreamUIController will, by posting the request to UI, let the | 14 // 4. MediaStreamUIController will, by posting the request to UI, let the |
| 15 // users to select which devices to use and send callback to | 15 // users to select which devices to use and send callback to |
| 16 // MediaStreamManager with the result. | 16 // MediaStreamManager with the result. |
| 17 // 5. MediaStreamManager will call the proper media device manager to open the | 17 // 5. MediaStreamManager will call the proper media device manager to open the |
| 18 // device and let the MediaStreamRequester know it has been done. | 18 // device and let the MediaStreamRequester know it has been done. |
| 19 | 19 |
| 20 // When enumeration and open are done in separate operations, | 20 // When enumeration and open are done in separate operations, |
| 21 // MediaStreamUIController is not involved as in steps. | 21 // MediaStreamUIController is not involved as in steps. |
| 22 | 22 |
| 23 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ | 23 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ |
| 24 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ | 24 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ |
| 25 | 25 |
| 26 #include <map> | 26 #include <map> |
| 27 #include <set> |
| 27 #include <string> | 28 #include <string> |
| 28 | 29 |
| 29 #include "base/basictypes.h" | 30 #include "base/basictypes.h" |
| 30 #include "base/memory/ref_counted.h" | 31 #include "base/memory/ref_counted.h" |
| 31 #include "base/memory/scoped_ptr.h" | 32 #include "base/memory/scoped_ptr.h" |
| 32 #include "base/message_loop/message_loop.h" | 33 #include "base/message_loop/message_loop.h" |
| 33 #include "base/system_monitor/system_monitor.h" | 34 #include "base/system_monitor/system_monitor.h" |
| 34 #include "content/browser/renderer_host/media/media_stream_provider.h" | 35 #include "content/browser/renderer_host/media/media_stream_provider.h" |
| 35 #include "content/common/content_export.h" | 36 #include "content/common/content_export.h" |
| 36 #include "content/common/media/media_stream_options.h" | 37 #include "content/common/media/media_stream_options.h" |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 // This object gets deleted on the UI thread after the IO thread has been | 179 // This object gets deleted on the UI thread after the IO thread has been |
| 179 // destroyed. So we need to know when IO thread is being destroyed so that | 180 // destroyed. So we need to know when IO thread is being destroyed so that |
| 180 // we can delete VideoCaptureManager and AudioInputDeviceManager. Normally | 181 // we can delete VideoCaptureManager and AudioInputDeviceManager. Normally |
| 181 // this is handled by | 182 // this is handled by |
| 182 // base::MessageLoop::DestructionObserver::WillDestroyCurrentMessageLoop. | 183 // base::MessageLoop::DestructionObserver::WillDestroyCurrentMessageLoop. |
| 183 // But for some tests which use TestBrowserThreadBundle, we need to call | 184 // But for some tests which use TestBrowserThreadBundle, we need to call |
| 184 // WillDestroyCurrentMessageLoop explicitly because the notification happens | 185 // WillDestroyCurrentMessageLoop explicitly because the notification happens |
| 185 // too late. (see http://crbug.com/247525#c14). | 186 // too late. (see http://crbug.com/247525#c14). |
| 186 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; | 187 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; |
| 187 | 188 |
| 189 // Sends log messages to the render processes making device requests, to be |
| 190 // used by the webrtcLoggingPrivate API if requested. |
| 191 void AddLogMessageOnIOThread(const std::string& message); |
| 192 |
| 193 // Adds |message| to native logs for outstanding device requests, for use by |
| 194 // render processes requesting logging from webrtcLoggingPrivate API. Safe to |
| 195 // call from any thread. |
| 196 static void SendMessageToNativeLog(const std::string& message); |
| 197 |
| 188 protected: | 198 protected: |
| 189 // Used for testing. | 199 // Used for testing. |
| 190 MediaStreamManager(); | 200 MediaStreamManager(); |
| 191 | 201 |
| 192 private: | 202 private: |
| 193 // Contains all data needed to keep track of requests. | 203 // Contains all data needed to keep track of requests. |
| 194 class DeviceRequest; | 204 class DeviceRequest; |
| 195 | 205 |
| 196 // Cache enumerated device list. | 206 // Cache enumerated device list. |
| 197 struct EnumerationCache { | 207 struct EnumerationCache { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 | 313 |
| 304 // Finds the requested device id from constraints. The requested device type | 314 // Finds the requested device id from constraints. The requested device type |
| 305 // must be MEDIA_DEVICE_AUDIO_CAPTURE or MEDIA_DEVICE_VIDEO_CAPTURE. | 315 // must be MEDIA_DEVICE_AUDIO_CAPTURE or MEDIA_DEVICE_VIDEO_CAPTURE. |
| 306 bool GetRequestedDeviceCaptureId(const DeviceRequest* request, | 316 bool GetRequestedDeviceCaptureId(const DeviceRequest* request, |
| 307 MediaStreamType type, | 317 MediaStreamType type, |
| 308 std::string* device_id) const; | 318 std::string* device_id) const; |
| 309 | 319 |
| 310 void TranslateDeviceIdToSourceId(DeviceRequest* request, | 320 void TranslateDeviceIdToSourceId(DeviceRequest* request, |
| 311 MediaStreamDevice* device); | 321 MediaStreamDevice* device); |
| 312 | 322 |
| 323 // Helper method that sends log messages to the render processes in |
| 324 // |render_process_ids|, to be used by the webrtcLoggingPrivate API if |
| 325 // requested. |
| 326 void AddLogMessageOnUIThread(const std::set<int>& render_process_ids, |
| 327 const std::string& message); |
| 328 |
| 313 // Finds and returns the device id corresponding to the given | 329 // Finds and returns the device id corresponding to the given |
| 314 // |source_id|. Returns true if there was a raw device id that matched the | 330 // |source_id|. Returns true if there was a raw device id that matched the |
| 315 // given |source_id|, false if nothing matched it. | 331 // given |source_id|, false if nothing matched it. |
| 316 bool TranslateSourceIdToDeviceId( | 332 bool TranslateSourceIdToDeviceId( |
| 317 MediaStreamType stream_type, | 333 MediaStreamType stream_type, |
| 318 ResourceContext* rc, | 334 ResourceContext* rc, |
| 319 const GURL& security_origin, | 335 const GURL& security_origin, |
| 320 const std::string& source_id, | 336 const std::string& source_id, |
| 321 std::string* device_id) const; | 337 std::string* device_id) const; |
| 322 | 338 |
| 323 // Device thread shared by VideoCaptureManager and AudioInputDeviceManager. | 339 // Device thread shared by VideoCaptureManager and AudioInputDeviceManager. |
| 324 scoped_ptr<base::Thread> device_thread_; | 340 scoped_ptr<base::Thread> device_thread_; |
| 325 | 341 |
| 326 media::AudioManager* const audio_manager_; // not owned | 342 media::AudioManager* const audio_manager_; // not owned |
| 327 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_; | 343 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_; |
| 328 scoped_refptr<VideoCaptureManager> video_capture_manager_; | 344 scoped_refptr<VideoCaptureManager> video_capture_manager_; |
| 329 | 345 |
| 330 // Indicator of device monitoring state. | 346 // Indicator of device monitoring state. |
| 331 bool monitoring_started_; | 347 bool monitoring_started_; |
| 332 | 348 |
| 333 // Stores most recently enumerated device lists. The cache is cleared when | 349 // Stores most recently enumerated device lists. The cache is cleared when |
| 334 // monitoring is stopped or there is no request for that type of device. | 350 // monitoring is stopped or there is no request for that type of device. |
| 335 EnumerationCache audio_enumeration_cache_; | 351 EnumerationCache audio_enumeration_cache_; |
| 336 EnumerationCache video_enumeration_cache_; | 352 EnumerationCache video_enumeration_cache_; |
| 337 | 353 |
| 338 // Keeps track of live enumeration commands sent to VideoCaptureManager or | 354 // Keeps track of live enumeration commands sent to VideoCaptureManager or |
| 339 // AudioInputDeviceManager, in order to only enumerate when necessary. | 355 // AudioInputDeviceManager, in order to only enumerate when necessary. |
| 340 int active_enumeration_ref_count_[NUM_MEDIA_TYPES]; | 356 int active_enumeration_ref_count_[NUM_MEDIA_TYPES]; |
| 341 | 357 |
| 342 // All non-closed request. | 358 // All non-closed request. Must be accessed on IO thread. |
| 343 DeviceRequests requests_; | 359 DeviceRequests requests_; |
| 344 | 360 |
| 345 // Hold a pointer to the IO loop to check we delete the device thread and | 361 // Hold a pointer to the IO loop to check we delete the device thread and |
| 346 // managers on the right thread. | 362 // managers on the right thread. |
| 347 base::MessageLoop* io_loop_; | 363 base::MessageLoop* io_loop_; |
| 348 | 364 |
| 349 bool use_fake_ui_; | 365 bool use_fake_ui_; |
| 350 scoped_ptr<FakeMediaStreamUIProxy> fake_ui_; | 366 scoped_ptr<FakeMediaStreamUIProxy> fake_ui_; |
| 351 | 367 |
| 352 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); | 368 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); |
| 353 }; | 369 }; |
| 354 | 370 |
| 355 } // namespace content | 371 } // namespace content |
| 356 | 372 |
| 357 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ | 373 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ |
| OLD | NEW |