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 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "media/audio/audio_parameters.h" | 38 #include "media/audio/audio_parameters.h" |
39 #include "media/base/channel_layout.h" | 39 #include "media/base/channel_layout.h" |
40 #include "media/base/media_switches.h" | 40 #include "media/base/media_switches.h" |
41 #include "media/video/capture/video_capture_device_factory.h" | 41 #include "media/video/capture/video_capture_device_factory.h" |
42 #include "url/gurl.h" | 42 #include "url/gurl.h" |
43 | 43 |
44 #if defined(OS_WIN) | 44 #if defined(OS_WIN) |
45 #include "base/win/scoped_com_initializer.h" | 45 #include "base/win/scoped_com_initializer.h" |
46 #endif | 46 #endif |
47 | 47 |
| 48 #if defined(OS_CHROMEOS) |
| 49 #include "chromeos/audio/cras_audio_handler.h" |
| 50 #endif |
| 51 |
48 namespace content { | 52 namespace content { |
49 | 53 |
50 // Forward declaration of DeviceMonitorMac and its only useable method. | 54 // Forward declaration of DeviceMonitorMac and its only useable method. |
51 class DeviceMonitorMac { | 55 class DeviceMonitorMac { |
52 public: | 56 public: |
53 void StartMonitoring( | 57 void StartMonitoring( |
54 const scoped_refptr<base::SingleThreadTaskRunner>& device_task_runner); | 58 const scoped_refptr<base::SingleThreadTaskRunner>& device_task_runner); |
55 }; | 59 }; |
56 | 60 |
57 namespace { | 61 namespace { |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 MediaStreamManager::EnumerationCache::EnumerationCache() | 355 MediaStreamManager::EnumerationCache::EnumerationCache() |
352 : valid(false) { | 356 : valid(false) { |
353 } | 357 } |
354 | 358 |
355 MediaStreamManager::EnumerationCache::~EnumerationCache() { | 359 MediaStreamManager::EnumerationCache::~EnumerationCache() { |
356 } | 360 } |
357 | 361 |
358 MediaStreamManager::MediaStreamManager() | 362 MediaStreamManager::MediaStreamManager() |
359 : audio_manager_(NULL), | 363 : audio_manager_(NULL), |
360 monitoring_started_(false), | 364 monitoring_started_(false), |
| 365 #if defined(OS_CHROMEOS) |
| 366 has_checked_keyboard_mic_(false), |
| 367 #endif |
361 io_loop_(NULL), | 368 io_loop_(NULL), |
362 use_fake_ui_(false) {} | 369 use_fake_ui_(false) {} |
363 | 370 |
364 MediaStreamManager::MediaStreamManager(media::AudioManager* audio_manager) | 371 MediaStreamManager::MediaStreamManager(media::AudioManager* audio_manager) |
365 : audio_manager_(audio_manager), | 372 : audio_manager_(audio_manager), |
366 monitoring_started_(false), | 373 monitoring_started_(false), |
| 374 #if defined(OS_CHROMEOS) |
| 375 has_checked_keyboard_mic_(false), |
| 376 #endif |
367 io_loop_(NULL), | 377 io_loop_(NULL), |
368 use_fake_ui_(false) { | 378 use_fake_ui_(false) { |
369 DCHECK(audio_manager_); | 379 DCHECK(audio_manager_); |
370 memset(active_enumeration_ref_count_, 0, | 380 memset(active_enumeration_ref_count_, 0, |
371 sizeof(active_enumeration_ref_count_)); | 381 sizeof(active_enumeration_ref_count_)); |
372 | 382 |
373 // Some unit tests create the MSM in the IO thread and assumes the | 383 // Some unit tests create the MSM in the IO thread and assumes the |
374 // initialization is done synchronously. | 384 // initialization is done synchronously. |
375 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 385 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
376 InitializeDeviceManagersOnIOThread(); | 386 InitializeDeviceManagersOnIOThread(); |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 // If the cache isn't valid, we need to start a full enumeration. | 1075 // If the cache isn't valid, we need to start a full enumeration. |
1066 return !cache->valid; | 1076 return !cache->valid; |
1067 } | 1077 } |
1068 | 1078 |
1069 void MediaStreamManager::StartEnumeration(DeviceRequest* request) { | 1079 void MediaStreamManager::StartEnumeration(DeviceRequest* request) { |
1070 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1080 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1071 | 1081 |
1072 // Start monitoring the devices when doing the first enumeration. | 1082 // Start monitoring the devices when doing the first enumeration. |
1073 StartMonitoring(); | 1083 StartMonitoring(); |
1074 | 1084 |
| 1085 #if defined(OS_CHROMEOS) |
| 1086 if (!has_checked_keyboard_mic_) { |
| 1087 has_checked_keyboard_mic_ = true; |
| 1088 BrowserThread::PostTask( |
| 1089 BrowserThread::UI, FROM_HERE, |
| 1090 base::Bind(&MediaStreamManager::CheckKeyboardMicOnUIThread, |
| 1091 base::Unretained(this))); |
| 1092 } |
| 1093 #endif |
| 1094 |
1075 // Start enumeration for devices of all requested device types. | 1095 // Start enumeration for devices of all requested device types. |
1076 const MediaStreamType streams[] = { request->audio_type(), | 1096 const MediaStreamType streams[] = { request->audio_type(), |
1077 request->video_type() }; | 1097 request->video_type() }; |
1078 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(streams); ++i) { | 1098 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(streams); ++i) { |
1079 if (streams[i] == MEDIA_NO_SERVICE) | 1099 if (streams[i] == MEDIA_NO_SERVICE) |
1080 continue; | 1100 continue; |
1081 request->SetState(streams[i], MEDIA_REQUEST_STATE_REQUESTED); | 1101 request->SetState(streams[i], MEDIA_REQUEST_STATE_REQUESTED); |
1082 DCHECK_GE(active_enumeration_ref_count_[streams[i]], 0); | 1102 DCHECK_GE(active_enumeration_ref_count_[streams[i]], 0); |
1083 if (active_enumeration_ref_count_[streams[i]] == 0) { | 1103 if (active_enumeration_ref_count_[streams[i]] == 0) { |
1084 ++active_enumeration_ref_count_[streams[i]]; | 1104 ++active_enumeration_ref_count_[streams[i]]; |
(...skipping 985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2070 ++it) { | 2090 ++it) { |
2071 if (it->device.type == MEDIA_DESKTOP_VIDEO_CAPTURE) { | 2091 if (it->device.type == MEDIA_DESKTOP_VIDEO_CAPTURE) { |
2072 video_capture_manager_->SetDesktopCaptureWindowId(it->session_id, | 2092 video_capture_manager_->SetDesktopCaptureWindowId(it->session_id, |
2073 window_id); | 2093 window_id); |
2074 break; | 2094 break; |
2075 } | 2095 } |
2076 } | 2096 } |
2077 } | 2097 } |
2078 } | 2098 } |
2079 | 2099 |
| 2100 #if defined(OS_CHROMEOS) |
| 2101 void MediaStreamManager::CheckKeyboardMicOnUIThread() { |
| 2102 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2103 |
| 2104 // We will post this on the device thread before the media media access |
| 2105 // request is posted on the UI thread, so setting the keyboard mic info will |
| 2106 // be done before any stream is created. |
| 2107 if (chromeos::CrasAudioHandler::Get()->HasKeyboardMic()) { |
| 2108 device_task_runner_->PostTask( |
| 2109 FROM_HERE, |
| 2110 base::Bind(&MediaStreamManager::SetKeyboardMicOnDeviceThread, |
| 2111 base::Unretained(this))); |
| 2112 } |
| 2113 } |
| 2114 |
| 2115 void MediaStreamManager::SetKeyboardMicOnDeviceThread() { |
| 2116 DCHECK(device_task_runner_->BelongsToCurrentThread()); |
| 2117 audio_manager_->SetHasKeyboardMic(); |
| 2118 } |
| 2119 #endif |
| 2120 |
2080 } // namespace content | 2121 } // namespace content |
OLD | NEW |