| 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 #include "content/browser/renderer_host/media/media_stream_manager.h" | 5 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "base/threading/com_thread.h" |
| 13 #include "content/browser/renderer_host/media/audio_input_device_manager.h" | 14 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
| 14 #include "content/browser/renderer_host/media/media_stream_device_settings.h" | 15 #include "content/browser/renderer_host/media/media_stream_device_settings.h" |
| 15 #include "content/browser/renderer_host/media/media_stream_requester.h" | 16 #include "content/browser/renderer_host/media/media_stream_requester.h" |
| 16 #include "content/browser/renderer_host/media/video_capture_manager.h" | 17 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 17 #include "content/common/media/media_stream_options.h" | 18 #include "content/common/media/media_stream_options.h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/content_browser_client.h" | 20 #include "content/public/browser/content_browser_client.h" |
| 20 #include "content/public/browser/media_observer.h" | 21 #include "content/public/browser/media_observer.h" |
| 21 #include "googleurl/src/gurl.h" | 22 #include "googleurl/src/gurl.h" |
| 22 | 23 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 47 return label; | 48 return label; |
| 48 } | 49 } |
| 49 | 50 |
| 50 // Helper to verify if a media stream type is part of options or not. | 51 // Helper to verify if a media stream type is part of options or not. |
| 51 static bool Requested(const StreamOptions& options, | 52 static bool Requested(const StreamOptions& options, |
| 52 MediaStreamType stream_type) { | 53 MediaStreamType stream_type) { |
| 53 return (options.audio_type == stream_type || | 54 return (options.audio_type == stream_type || |
| 54 options.video_type == stream_type); | 55 options.video_type == stream_type); |
| 55 } | 56 } |
| 56 | 57 |
| 57 #if defined(OS_WIN) | |
| 58 DeviceThread::DeviceThread(const char* name) : base::Thread(name) { | |
| 59 } | |
| 60 | |
| 61 DeviceThread::~DeviceThread() { | |
| 62 Stop(); | |
| 63 } | |
| 64 | |
| 65 void DeviceThread::Init() { | |
| 66 com_initializer_.reset(new base::win::ScopedCOMInitializer( | |
| 67 base::win::ScopedCOMInitializer::kMTA)); | |
| 68 } | |
| 69 | |
| 70 void DeviceThread::CleanUp() { | |
| 71 com_initializer_.reset(); | |
| 72 } | |
| 73 #endif | |
| 74 | |
| 75 // TODO(xians): Merge DeviceRequest with MediaStreamRequest. | 58 // TODO(xians): Merge DeviceRequest with MediaStreamRequest. |
| 76 struct MediaStreamManager::DeviceRequest { | 59 struct MediaStreamManager::DeviceRequest { |
| 77 enum RequestState { | 60 enum RequestState { |
| 78 STATE_NOT_REQUESTED = 0, | 61 STATE_NOT_REQUESTED = 0, |
| 79 STATE_REQUESTED, | 62 STATE_REQUESTED, |
| 80 STATE_PENDING_APPROVAL, | 63 STATE_PENDING_APPROVAL, |
| 81 STATE_OPENING, | 64 STATE_OPENING, |
| 82 STATE_DONE, | 65 STATE_DONE, |
| 83 STATE_ERROR | 66 STATE_ERROR |
| 84 }; | 67 }; |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 requests_.insert(std::make_pair(request_label, new_request)); | 432 requests_.insert(std::make_pair(request_label, new_request)); |
| 450 | 433 |
| 451 (*label) = request_label; | 434 (*label) = request_label; |
| 452 } | 435 } |
| 453 | 436 |
| 454 void MediaStreamManager::EnsureDeviceManagersStarted() { | 437 void MediaStreamManager::EnsureDeviceManagersStarted() { |
| 455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 456 if (device_thread_.get()) | 439 if (device_thread_.get()) |
| 457 return; | 440 return; |
| 458 | 441 |
| 459 device_thread_.reset(new DeviceThread("MediaStreamDeviceThread")); | 442 device_thread_.reset(new base::ComThread("MediaStreamDeviceThread", true)); |
| 460 CHECK(device_thread_->Start()); | 443 CHECK(device_thread_->Start()); |
| 461 | 444 |
| 462 audio_input_device_manager_ = | 445 audio_input_device_manager_ = |
| 463 new media_stream::AudioInputDeviceManager(audio_manager_); | 446 new media_stream::AudioInputDeviceManager(audio_manager_); |
| 464 audio_input_device_manager_->Register(this, | 447 audio_input_device_manager_->Register(this, |
| 465 device_thread_->message_loop_proxy()); | 448 device_thread_->message_loop_proxy()); |
| 466 | 449 |
| 467 video_capture_manager_ = new media_stream::VideoCaptureManager(); | 450 video_capture_manager_ = new media_stream::VideoCaptureManager(); |
| 468 video_capture_manager_->Register(this, | 451 video_capture_manager_->Register(this, |
| 469 device_thread_->message_loop_proxy()); | 452 device_thread_->message_loop_proxy()); |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 it != requests_.end(); ++it) { | 875 it != requests_.end(); ++it) { |
| 893 if (it->second.type == DeviceRequest::ENUMERATE_DEVICES && | 876 if (it->second.type == DeviceRequest::ENUMERATE_DEVICES && |
| 894 Requested(it->second.options, stream_type)) { | 877 Requested(it->second.options, stream_type)) { |
| 895 return true; | 878 return true; |
| 896 } | 879 } |
| 897 } | 880 } |
| 898 return false; | 881 return false; |
| 899 } | 882 } |
| 900 | 883 |
| 901 } // namespace media_stream | 884 } // namespace media_stream |
| OLD | NEW |