| 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/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 "content/public/browser/media_request_state.h" | 22 #include "content/public/browser/media_request_state.h" |
| 22 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 53 return label; | 54 return label; |
| 54 } | 55 } |
| 55 | 56 |
| 56 // Helper to verify if a media stream type is part of options or not. | 57 // Helper to verify if a media stream type is part of options or not. |
| 57 static bool Requested(const StreamOptions& options, | 58 static bool Requested(const StreamOptions& options, |
| 58 MediaStreamType stream_type) { | 59 MediaStreamType stream_type) { |
| 59 return (options.audio_type == stream_type || | 60 return (options.audio_type == stream_type || |
| 60 options.video_type == stream_type); | 61 options.video_type == stream_type); |
| 61 } | 62 } |
| 62 | 63 |
| 63 #if defined(OS_WIN) | |
| 64 DeviceThread::DeviceThread(const char* name) : base::Thread(name) { | |
| 65 } | |
| 66 | |
| 67 DeviceThread::~DeviceThread() { | |
| 68 Stop(); | |
| 69 } | |
| 70 | |
| 71 void DeviceThread::Init() { | |
| 72 com_initializer_.reset(new base::win::ScopedCOMInitializer( | |
| 73 base::win::ScopedCOMInitializer::kMTA)); | |
| 74 } | |
| 75 | |
| 76 void DeviceThread::CleanUp() { | |
| 77 com_initializer_.reset(); | |
| 78 } | |
| 79 #endif | |
| 80 | |
| 81 // TODO(xians): Merge DeviceRequest with MediaStreamRequest. | 64 // TODO(xians): Merge DeviceRequest with MediaStreamRequest. |
| 82 class MediaStreamManager::DeviceRequest { | 65 class MediaStreamManager::DeviceRequest { |
| 83 public: | 66 public: |
| 84 enum RequestType { | 67 enum RequestType { |
| 85 GENERATE_STREAM = 0, | 68 GENERATE_STREAM = 0, |
| 86 ENUMERATE_DEVICES, | 69 ENUMERATE_DEVICES, |
| 87 OPEN_DEVICE | 70 OPEN_DEVICE |
| 88 }; | 71 }; |
| 89 | 72 |
| 90 DeviceRequest() | 73 DeviceRequest() |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 requests_.insert(std::make_pair(request_label, new_request)); | 495 requests_.insert(std::make_pair(request_label, new_request)); |
| 513 | 496 |
| 514 (*label) = request_label; | 497 (*label) = request_label; |
| 515 } | 498 } |
| 516 | 499 |
| 517 void MediaStreamManager::EnsureDeviceManagersStarted() { | 500 void MediaStreamManager::EnsureDeviceManagersStarted() { |
| 518 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 501 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 519 if (device_thread_.get()) | 502 if (device_thread_.get()) |
| 520 return; | 503 return; |
| 521 | 504 |
| 522 device_thread_.reset(new DeviceThread("MediaStreamDeviceThread")); | 505 device_thread_.reset(new base::Thread("MediaStreamDeviceThread")); |
| 506 #if defined(OS_WIN) |
| 507 device_thread_->init_com_with_mta(true); |
| 508 #endif |
| 523 CHECK(device_thread_->Start()); | 509 CHECK(device_thread_->Start()); |
| 524 | 510 |
| 525 audio_input_device_manager_ = | 511 audio_input_device_manager_ = |
| 526 new media_stream::AudioInputDeviceManager(audio_manager_); | 512 new media_stream::AudioInputDeviceManager(audio_manager_); |
| 527 audio_input_device_manager_->Register(this, | 513 audio_input_device_manager_->Register(this, |
| 528 device_thread_->message_loop_proxy()); | 514 device_thread_->message_loop_proxy()); |
| 529 | 515 |
| 530 video_capture_manager_ = new media_stream::VideoCaptureManager(); | 516 video_capture_manager_ = new media_stream::VideoCaptureManager(); |
| 531 video_capture_manager_->Register(this, | 517 video_capture_manager_->Register(this, |
| 532 device_thread_->message_loop_proxy()); | 518 device_thread_->message_loop_proxy()); |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 969 it != requests_.end(); ++it) { | 955 it != requests_.end(); ++it) { |
| 970 if (it->second.type == DeviceRequest::ENUMERATE_DEVICES && | 956 if (it->second.type == DeviceRequest::ENUMERATE_DEVICES && |
| 971 Requested(it->second.options, stream_type)) { | 957 Requested(it->second.options, stream_type)) { |
| 972 return true; | 958 return true; |
| 973 } | 959 } |
| 974 } | 960 } |
| 975 return false; | 961 return false; |
| 976 } | 962 } |
| 977 | 963 |
| 978 } // namespace media_stream | 964 } // namespace media_stream |
| OLD | NEW |