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

Side by Side Diff: media/audio/mac/audio_manager_mac.cc

Issue 2721633005: Fix zero channel count being returned for unknown macOS layouts. (Closed)
Patch Set: Zero intialize. Created 3 years, 9 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) 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 "media/audio/mac/audio_manager_mac.h" 5 #include "media/audio/mac/audio_manager_mac.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 AudioObjectPropertyScope scope, 440 AudioObjectPropertyScope scope,
441 int* channels) { 441 int* channels) {
442 DCHECK(AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); 442 DCHECK(AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread());
443 CHECK(channels); 443 CHECK(channels);
444 444
445 // If the device has more channels than possible for layouts to express, use 445 // If the device has more channels than possible for layouts to express, use
446 // the total count of channels on the device; as of this writing, macOS will 446 // the total count of channels on the device; as of this writing, macOS will
447 // only return up to 8 channels in any layout. To allow WebAudio to work with 447 // only return up to 8 channels in any layout. To allow WebAudio to work with
448 // > 8 channel devices, we must use the total channel count instead of the 448 // > 8 channel devices, we must use the total channel count instead of the
449 // channel count of the preferred layout. 449 // channel count of the preferred layout.
450 if (GetDeviceTotalChannelCount(device, scope, channels) && 450 int total_channel_count = 0;
451 *channels > kMaxConcurrentChannels) { 451 if (GetDeviceTotalChannelCount(device, scope, &total_channel_count) &&
452 total_channel_count > kMaxConcurrentChannels) {
453 *channels = total_channel_count;
452 return true; 454 return true;
453 } 455 }
454 456
455 AudioObjectPropertyAddress pa = {kAudioDevicePropertyPreferredChannelLayout, 457 AudioObjectPropertyAddress pa = {kAudioDevicePropertyPreferredChannelLayout,
456 scope, kAudioObjectPropertyElementMaster}; 458 scope, kAudioObjectPropertyElementMaster};
457 UInt32 size; 459 UInt32 size;
458 OSStatus result = AudioObjectGetPropertyDataSize(device, &pa, 0, 0, &size); 460 OSStatus result = AudioObjectGetPropertyDataSize(device, &pa, 0, 0, &size);
459 if (result != noErr || !size) 461 if (result != noErr || !size)
460 return false; 462 return false;
461 463
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 *channels = layout->mNumberChannelDescriptions; 505 *channels = layout->mNumberChannelDescriptions;
504 } else { 506 } else {
505 *channels = 0; 507 *channels = 0;
506 for (UInt32 i = 0; i < layout->mNumberChannelDescriptions; ++i) { 508 for (UInt32 i = 0; i < layout->mNumberChannelDescriptions; ++i) {
507 if (layout->mChannelDescriptions[i].mChannelLabel != 509 if (layout->mChannelDescriptions[i].mChannelLabel !=
508 kAudioChannelLabel_Unknown) 510 kAudioChannelLabel_Unknown)
509 (*channels)++; 511 (*channels)++;
510 } 512 }
511 } 513 }
512 514
515 // If we still don't have a channel count, fall back to total channel count.
516 if (*channels == 0) {
517 DLOG(WARNING) << "Unable to use channel layout for channel count.";
518 *channels = total_channel_count;
519 }
520
513 DVLOG(1) << (scope == kAudioDevicePropertyScopeInput ? "Input" : "Output") 521 DVLOG(1) << (scope == kAudioDevicePropertyScopeInput ? "Input" : "Output")
514 << " channels: " << *channels; 522 << " channels: " << *channels;
515 return true; 523 return true;
516 } 524 }
517 525
518 // static 526 // static
519 int AudioManagerMac::HardwareSampleRateForDevice(AudioDeviceID device_id) { 527 int AudioManagerMac::HardwareSampleRateForDevice(AudioDeviceID device_id) {
520 DCHECK(AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread()); 528 DCHECK(AudioManager::Get()->GetTaskRunner()->BelongsToCurrentThread());
521 Float64 nominal_sample_rate; 529 Float64 nominal_sample_rate;
522 UInt32 info_size = sizeof(nominal_sample_rate); 530 UInt32 info_size = sizeof(nominal_sample_rate);
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 ScopedAudioManagerPtr CreateAudioManager( 1168 ScopedAudioManagerPtr CreateAudioManager(
1161 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 1169 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
1162 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, 1170 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner,
1163 AudioLogFactory* audio_log_factory) { 1171 AudioLogFactory* audio_log_factory) {
1164 return ScopedAudioManagerPtr( 1172 return ScopedAudioManagerPtr(
1165 new AudioManagerMac(std::move(task_runner), std::move(worker_task_runner), 1173 new AudioManagerMac(std::move(task_runner), std::move(worker_task_runner),
1166 audio_log_factory)); 1174 audio_log_factory));
1167 } 1175 }
1168 1176
1169 } // namespace media 1177 } // namespace media
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