| OLD | NEW |
| (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 |
| OLD | NEW |