Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(895)

Side by Side Diff: chromeos/audio/cras_audio_handler.cc

Issue 2155503002: Fix dynamic plugging/unplugging audio devices may not update audio input source (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: check nullptr Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "chromeos/audio/cras_audio_handler.h" 5 #include "chromeos/audio/cras_audio_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <cmath> 11 #include <cmath>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/sys_info.h" 16 #include "base/sys_info.h"
17 #include "base/system_monitor/system_monitor.h"
17 #include "chromeos/audio/audio_devices_pref_handler_stub.h" 18 #include "chromeos/audio/audio_devices_pref_handler_stub.h"
18 #include "chromeos/dbus/dbus_thread_manager.h" 19 #include "chromeos/dbus/dbus_thread_manager.h"
19 20
20 using std::max; 21 using std::max;
21 using std::min; 22 using std::min;
22 23
23 namespace chromeos { 24 namespace chromeos {
24 25
25 namespace { 26 namespace {
26 27
(...skipping 1208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 if (!active_device || !active_device->active) 1236 if (!active_device || !active_device->active)
1236 active_node_id = 0; 1237 active_node_id = 0;
1237 1238
1238 if (!active_node_id || hotplug_nodes.empty() || hotplug_nodes.size() > 1) { 1239 if (!active_node_id || hotplug_nodes.empty() || hotplug_nodes.size() > 1) {
1239 HandleNonHotplugNodesChange(is_input, hotplug_nodes, has_device_change, 1240 HandleNonHotplugNodesChange(is_input, hotplug_nodes, has_device_change,
1240 has_device_removed, active_device_removed); 1241 has_device_removed, active_device_removed);
1241 } else { 1242 } else {
1242 // Typical user hotplug case. 1243 // Typical user hotplug case.
1243 HandleHotPlugDevice(hotplug_nodes.top(), devices_pq); 1244 HandleHotPlugDevice(hotplug_nodes.top(), devices_pq);
1244 } 1245 }
1246
1247 // content::MediaStreamManager listens to
1248 // base::SystemMonitor::DevicesChangedObserver for audio capture devices,
1249 // and updates EnumerateDevices when OnDevicesChanged is called.
1250 if (is_input) {
1251 base::SystemMonitor* monitor = base::SystemMonitor::Get();
1252 // In some unittest, |monitor| might be nullptr.
1253 if (!monitor)
1254 return;
1255 monitor->ProcessDevicesChanged(
1256 base::SystemMonitor::DeviceType::DEVTYPE_AUDIO_CAPTURE);
1257 }
1245 } 1258 }
1246 1259
1247 void CrasAudioHandler::HandleGetNodes(const chromeos::AudioNodeList& node_list, 1260 void CrasAudioHandler::HandleGetNodes(const chromeos::AudioNodeList& node_list,
1248 bool success) { 1261 bool success) {
1249 if (!success) { 1262 if (!success) {
1250 LOG_IF(ERROR, log_errors_) << "Failed to retrieve audio nodes data"; 1263 LOG_IF(ERROR, log_errors_) << "Failed to retrieve audio nodes data";
1251 return; 1264 return;
1252 } 1265 }
1253 1266
1254 UpdateDevicesAndSwitchActive(node_list); 1267 UpdateDevicesAndSwitchActive(node_list);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 hdmi_rediscover_grace_period_duration_in_ms_), 1359 hdmi_rediscover_grace_period_duration_in_ms_),
1347 this, &CrasAudioHandler::UpdateAudioAfterHDMIRediscoverGracePeriod); 1360 this, &CrasAudioHandler::UpdateAudioAfterHDMIRediscoverGracePeriod);
1348 } 1361 }
1349 1362
1350 void CrasAudioHandler::SetHDMIRediscoverGracePeriodForTesting( 1363 void CrasAudioHandler::SetHDMIRediscoverGracePeriodForTesting(
1351 int duration_in_ms) { 1364 int duration_in_ms) {
1352 hdmi_rediscover_grace_period_duration_in_ms_ = duration_in_ms; 1365 hdmi_rediscover_grace_period_duration_in_ms_ = duration_in_ms;
1353 } 1366 }
1354 1367
1355 } // namespace chromeos 1368 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698