| OLD | NEW |
| 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> |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 for (uint64_t id : new_active_ids) { | 261 for (uint64_t id : new_active_ids) { |
| 262 const chromeos::AudioDevice* device = GetDeviceFromId(id); | 262 const chromeos::AudioDevice* device = GetDeviceFromId(id); |
| 263 if (!device) | 263 if (!device) |
| 264 continue; | 264 continue; |
| 265 if (device->is_input) | 265 if (device->is_input) |
| 266 input_devices.push_back(*device); | 266 input_devices.push_back(*device); |
| 267 else | 267 else |
| 268 output_devices.push_back(*device); | 268 output_devices.push_back(*device); |
| 269 } | 269 } |
| 270 if (!input_devices.empty()) | 270 if (!input_devices.empty()) |
| 271 SetActiveNodes(input_devices, true /* is_input */); | 271 SetActiveDevices(input_devices, true /* is_input */); |
| 272 if (!output_devices.empty()) | 272 if (!output_devices.empty()) |
| 273 SetActiveNodes(output_devices, false /* is_input */); | 273 SetActiveDevices(output_devices, false /* is_input */); |
| 274 } | 274 } |
| 275 | 275 |
| 276 void CrasAudioHandler::SetActiveNodes(const AudioDeviceList& devices, | 276 bool CrasAudioHandler::SetActiveInputNodes(const NodeIdList& node_ids) { |
| 277 return SetActiveNodes(node_ids, true /* is_input */); |
| 278 } |
| 279 |
| 280 bool CrasAudioHandler::SetActiveOutputNodes(const NodeIdList& node_ids) { |
| 281 return SetActiveNodes(node_ids, false /* is_input */); |
| 282 } |
| 283 |
| 284 bool CrasAudioHandler::SetActiveNodes(const NodeIdList& node_ids, |
| 277 bool is_input) { | 285 bool is_input) { |
| 286 chromeos::AudioDeviceList devices; |
| 287 for (uint64_t id : node_ids) { |
| 288 const chromeos::AudioDevice* device = GetDeviceFromId(id); |
| 289 if (!device || device->is_input != is_input) |
| 290 return false; |
| 291 |
| 292 devices.push_back(*device); |
| 293 } |
| 294 |
| 295 SetActiveDevices(devices, is_input); |
| 296 return true; |
| 297 } |
| 298 |
| 299 void CrasAudioHandler::SetActiveDevices(const AudioDeviceList& devices, |
| 300 bool is_input) { |
| 278 std::set<uint64_t> new_active_ids; | 301 std::set<uint64_t> new_active_ids; |
| 279 for (const auto& active_device : devices) { | 302 for (const auto& active_device : devices) { |
| 280 CHECK_EQ(is_input, active_device.is_input); | 303 CHECK_EQ(is_input, active_device.is_input); |
| 281 new_active_ids.insert(active_device.id); | 304 new_active_ids.insert(active_device.id); |
| 282 } | 305 } |
| 283 | 306 |
| 284 bool active_devices_changed = false; | 307 bool active_devices_changed = false; |
| 285 | 308 |
| 286 // If primary active node has to be switched, do that before adding or | 309 // If primary active node has to be switched, do that before adding or |
| 287 // removing any other active devices. Switching to a device can change | 310 // removing any other active devices. Switching to a device can change |
| (...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1386 hdmi_rediscover_grace_period_duration_in_ms_), | 1409 hdmi_rediscover_grace_period_duration_in_ms_), |
| 1387 this, &CrasAudioHandler::UpdateAudioAfterHDMIRediscoverGracePeriod); | 1410 this, &CrasAudioHandler::UpdateAudioAfterHDMIRediscoverGracePeriod); |
| 1388 } | 1411 } |
| 1389 | 1412 |
| 1390 void CrasAudioHandler::SetHDMIRediscoverGracePeriodForTesting( | 1413 void CrasAudioHandler::SetHDMIRediscoverGracePeriodForTesting( |
| 1391 int duration_in_ms) { | 1414 int duration_in_ms) { |
| 1392 hdmi_rediscover_grace_period_duration_in_ms_ = duration_in_ms; | 1415 hdmi_rediscover_grace_period_duration_in_ms_ = duration_in_ms; |
| 1393 } | 1416 } |
| 1394 | 1417 |
| 1395 } // namespace chromeos | 1418 } // namespace chromeos |
| OLD | NEW |