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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/audio/mac/scoped_audio_unit.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/mac/scoped_audio_unit.cc
diff --git a/media/audio/mac/scoped_audio_unit.cc b/media/audio/mac/scoped_audio_unit.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3f0cdb3c0ce5be6fb7205bb639dd35dadd500312
--- /dev/null
+++ b/media/audio/mac/scoped_audio_unit.cc
@@ -0,0 +1,53 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/audio/mac/scoped_audio_unit.h"
+
+#include "base/mac/mac_logging.h"
+
+namespace media {
+
+constexpr AudioComponentDescription desc = {kAudioUnitType_Output,
+ kAudioUnitSubType_HALOutput,
+ kAudioUnitManufacturer_Apple, 0, 0};
+
+static void DestroyAudioUnit(AudioUnit audio_unit) {
+ OSStatus result = AudioUnitUninitialize(audio_unit);
+ OSSTATUS_DLOG_IF(ERROR, result != noErr, result)
+ << "AudioUnitUninitialize() failed : " << audio_unit;
+ result = AudioComponentInstanceDispose(audio_unit);
+ OSSTATUS_DLOG_IF(ERROR, result != noErr, result)
+ << "AudioComponentInstanceDispose() failed : " << audio_unit;
+}
+
+ScopedAudioUnit::ScopedAudioUnit(AudioDeviceID device, AUElement element) {
+ AudioComponent comp = AudioComponentFindNext(0, &desc);
+ if (!comp)
+ return;
+
+ AudioUnit audio_unit;
+ OSStatus result = AudioComponentInstanceNew(comp, &audio_unit);
+ if (result != noErr) {
+ OSSTATUS_DLOG(ERROR, result) << "AudioComponentInstanceNew() failed.";
+ return;
+ }
+
+ result = AudioUnitSetProperty(
+ audio_unit, kAudioOutputUnitProperty_CurrentDevice,
+ kAudioUnitScope_Global, element, &device, sizeof(AudioDeviceID));
+ if (result == noErr) {
+ audio_unit_ = audio_unit;
+ return;
+ }
+ OSSTATUS_DLOG(ERROR, result)
+ << "Failed to set current device for audio unit.";
+ DestroyAudioUnit(audio_unit);
+}
+
+ScopedAudioUnit::~ScopedAudioUnit() {
+ if (audio_unit_)
+ DestroyAudioUnit(audio_unit_);
+}
+
+} // namespace media
« 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