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

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

Issue 2771093002: Use AudioUnit instead of AudioDevice properties to get channel count. (Closed)
Patch Set: Revert deletion of GetDeviceTotalChannelCount. 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 | « media/audio/mac/scoped_audio_unit.h ('k') | 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/audio/mac/scoped_audio_unit.h"
6
7 #include "base/mac/mac_logging.h"
8
9 namespace media {
10
11 constexpr AudioComponentDescription desc = {kAudioUnitType_Output,
12 kAudioUnitSubType_HALOutput,
13 kAudioUnitManufacturer_Apple, 0, 0};
14
15 static void DestroyAudioUnit(AudioUnit audio_unit) {
16 OSStatus result = AudioUnitUninitialize(audio_unit);
17 OSSTATUS_DLOG_IF(ERROR, result != noErr, result)
18 << "AudioUnitUninitialize() failed : " << audio_unit;
19 result = AudioComponentInstanceDispose(audio_unit);
20 OSSTATUS_DLOG_IF(ERROR, result != noErr, result)
21 << "AudioComponentInstanceDispose() failed : " << audio_unit;
22 }
23
24 ScopedAudioUnit::ScopedAudioUnit(AudioDeviceID device, AUElement element) {
25 AudioComponent comp = AudioComponentFindNext(0, &desc);
26 if (!comp)
27 return;
28
29 AudioUnit audio_unit;
30 OSStatus result = AudioComponentInstanceNew(comp, &audio_unit);
31 if (result != noErr) {
32 OSSTATUS_DLOG(ERROR, result) << "AudioComponentInstanceNew() failed.";
33 return;
34 }
35
36 result = AudioUnitSetProperty(
37 audio_unit, kAudioOutputUnitProperty_CurrentDevice,
38 kAudioUnitScope_Global, element, &device, sizeof(AudioDeviceID));
39 if (result == noErr) {
40 audio_unit_ = audio_unit;
41 return;
42 }
43 OSSTATUS_DLOG(ERROR, result)
44 << "Failed to set current device for audio unit.";
45 DestroyAudioUnit(audio_unit);
46 }
47
48 ScopedAudioUnit::~ScopedAudioUnit() {
49 if (audio_unit_)
50 DestroyAudioUnit(audio_unit_);
51 }
52
53 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/mac/scoped_audio_unit.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698