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 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 // 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. |
1076 return !cache->valid; | 1076 return !cache->valid; |
1077 } | 1077 } |
1078 | 1078 |
1079 void MediaStreamManager::StartEnumeration(DeviceRequest* request) { | 1079 void MediaStreamManager::StartEnumeration(DeviceRequest* request) { |
1080 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1080 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1081 | 1081 |
1082 // Start monitoring the devices when doing the first enumeration. | 1082 // Start monitoring the devices when doing the first enumeration. |
1083 StartMonitoring(); | 1083 StartMonitoring(); |
1084 | 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 | |
1095 // Start enumeration for devices of all requested device types. | 1085 // Start enumeration for devices of all requested device types. |
1096 const MediaStreamType streams[] = { request->audio_type(), | 1086 const MediaStreamType streams[] = { request->audio_type(), |
1097 request->video_type() }; | 1087 request->video_type() }; |
1098 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(streams); ++i) { | 1088 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(streams); ++i) { |
1099 if (streams[i] == MEDIA_NO_SERVICE) | 1089 if (streams[i] == MEDIA_NO_SERVICE) |
1100 continue; | 1090 continue; |
1101 request->SetState(streams[i], MEDIA_REQUEST_STATE_REQUESTED); | 1091 request->SetState(streams[i], MEDIA_REQUEST_STATE_REQUESTED); |
1102 DCHECK_GE(active_enumeration_ref_count_[streams[i]], 0); | 1092 DCHECK_GE(active_enumeration_ref_count_[streams[i]], 0); |
1103 if (active_enumeration_ref_count_[streams[i]] == 0) { | 1093 if (active_enumeration_ref_count_[streams[i]] == 0) { |
1104 ++active_enumeration_ref_count_[streams[i]]; | 1094 ++active_enumeration_ref_count_[streams[i]]; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 | 1217 |
1228 bool is_screen_capture = | 1218 bool is_screen_capture = |
1229 video_type == MEDIA_DESKTOP_VIDEO_CAPTURE; | 1219 video_type == MEDIA_DESKTOP_VIDEO_CAPTURE; |
1230 if (is_screen_capture && !SetupScreenCaptureRequest(request)) { | 1220 if (is_screen_capture && !SetupScreenCaptureRequest(request)) { |
1231 FinalizeRequestFailed(label, | 1221 FinalizeRequestFailed(label, |
1232 request, | 1222 request, |
1233 MEDIA_DEVICE_SCREEN_CAPTURE_FAILURE); | 1223 MEDIA_DEVICE_SCREEN_CAPTURE_FAILURE); |
1234 return; | 1224 return; |
1235 } | 1225 } |
1236 | 1226 |
| 1227 #if defined(OS_CHROMEOS) |
| 1228 EnsureKeyboardMicChecked(); |
| 1229 #endif |
| 1230 |
1237 if (!is_web_contents_capture && !is_screen_capture) { | 1231 if (!is_web_contents_capture && !is_screen_capture) { |
1238 if (EnumerationRequired(&audio_enumeration_cache_, audio_type) || | 1232 if (EnumerationRequired(&audio_enumeration_cache_, audio_type) || |
1239 EnumerationRequired(&video_enumeration_cache_, video_type)) { | 1233 EnumerationRequired(&video_enumeration_cache_, video_type)) { |
1240 // Enumerate the devices if there is no valid device lists to be used. | 1234 // Enumerate the devices if there is no valid device lists to be used. |
1241 StartEnumeration(request); | 1235 StartEnumeration(request); |
1242 return; | 1236 return; |
1243 } else { | 1237 } else { |
1244 // Cache is valid, so log the cached devices for MediaStream requests. | 1238 // Cache is valid, so log the cached devices for MediaStream requests. |
1245 if (request->request_type == MEDIA_GENERATE_STREAM) { | 1239 if (request->request_type == MEDIA_GENERATE_STREAM) { |
1246 std::string log_message("Using cached devices for request.\n"); | 1240 std::string log_message("Using cached devices for request.\n"); |
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2091 if (it->device.type == MEDIA_DESKTOP_VIDEO_CAPTURE) { | 2085 if (it->device.type == MEDIA_DESKTOP_VIDEO_CAPTURE) { |
2092 video_capture_manager_->SetDesktopCaptureWindowId(it->session_id, | 2086 video_capture_manager_->SetDesktopCaptureWindowId(it->session_id, |
2093 window_id); | 2087 window_id); |
2094 break; | 2088 break; |
2095 } | 2089 } |
2096 } | 2090 } |
2097 } | 2091 } |
2098 } | 2092 } |
2099 | 2093 |
2100 #if defined(OS_CHROMEOS) | 2094 #if defined(OS_CHROMEOS) |
| 2095 void MediaStreamManager::EnsureKeyboardMicChecked() { |
| 2096 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 2097 if (!has_checked_keyboard_mic_) { |
| 2098 has_checked_keyboard_mic_ = true; |
| 2099 BrowserThread::PostTask( |
| 2100 BrowserThread::UI, FROM_HERE, |
| 2101 base::Bind(&MediaStreamManager::CheckKeyboardMicOnUIThread, |
| 2102 base::Unretained(this))); |
| 2103 } |
| 2104 } |
| 2105 |
2101 void MediaStreamManager::CheckKeyboardMicOnUIThread() { | 2106 void MediaStreamManager::CheckKeyboardMicOnUIThread() { |
2102 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 2107 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
2103 | 2108 |
2104 // We will post this on the device thread before the media media access | 2109 // 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 | 2110 // request is posted on the UI thread, so setting the keyboard mic info will |
2106 // be done before any stream is created. | 2111 // be done before any stream is created. |
2107 if (chromeos::CrasAudioHandler::Get()->HasKeyboardMic()) { | 2112 if (chromeos::CrasAudioHandler::Get()->HasKeyboardMic()) { |
2108 device_task_runner_->PostTask( | 2113 device_task_runner_->PostTask( |
2109 FROM_HERE, | 2114 FROM_HERE, |
2110 base::Bind(&MediaStreamManager::SetKeyboardMicOnDeviceThread, | 2115 base::Bind(&MediaStreamManager::SetKeyboardMicOnDeviceThread, |
2111 base::Unretained(this))); | 2116 base::Unretained(this))); |
2112 } | 2117 } |
2113 } | 2118 } |
2114 | 2119 |
2115 void MediaStreamManager::SetKeyboardMicOnDeviceThread() { | 2120 void MediaStreamManager::SetKeyboardMicOnDeviceThread() { |
2116 DCHECK(device_task_runner_->BelongsToCurrentThread()); | 2121 DCHECK(device_task_runner_->BelongsToCurrentThread()); |
2117 audio_manager_->SetHasKeyboardMic(); | 2122 audio_manager_->SetHasKeyboardMic(); |
2118 } | 2123 } |
2119 #endif | 2124 #endif |
2120 | 2125 |
2121 } // namespace content | 2126 } // namespace content |
OLD | NEW |