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

Unified Diff: media/audio/mac/scoped_audio_unit.h

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/audio_manager_mac.cc ('k') | media/audio/mac/scoped_audio_unit.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/mac/scoped_audio_unit.h
diff --git a/media/audio/mac/scoped_audio_unit.h b/media/audio/mac/scoped_audio_unit.h
new file mode 100644
index 0000000000000000000000000000000000000000..cb6b85121d87946c9b97914a0e50bf6fe9dae6f0
--- /dev/null
+++ b/media/audio/mac/scoped_audio_unit.h
@@ -0,0 +1,40 @@
+// 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.
+
+#ifndef MEDIA_AUDIO_MAC_SCOPED_AUDIO_UNIT_H_
+#define MEDIA_AUDIO_MAC_SCOPED_AUDIO_UNIT_H_
+
+#include <AudioUnit/AudioUnit.h>
+#include <CoreAudio/CoreAudio.h>
+
+#include "base/macros.h"
+
+namespace media {
+
+// For whatever reason Apple doesn't have constants defined for these; per the
+// documentation, we use bus 0 for output and bus 1 for input:
+// http://developer.apple.com/library/mac/#technotes/tn2091/_index.html
+enum AUElement : AudioUnitElement { OUTPUT = 0, INPUT = 1 };
+
+// A helper class that ensures AudioUnits are properly disposed of.
+class ScopedAudioUnit {
+ public:
+ // Creates a new AudioUnit and sets its device for |element| to |device|. If
+ // the operation fails, is_valid() will return false and audio_unit() will
+ // return nullptr.
+ ScopedAudioUnit(AudioDeviceID device, AUElement element);
+ ~ScopedAudioUnit();
+
+ bool is_valid() const { return audio_unit_ != nullptr; }
+ AudioUnit audio_unit() const { return audio_unit_; }
+
+ private:
+ AudioUnit audio_unit_ = nullptr;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedAudioUnit);
+};
+
+} // namespace media
+
+#endif // MEDIA_AUDIO_MAC_SCOPED_AUDIO_UNIT_H_
« no previous file with comments | « media/audio/mac/audio_manager_mac.cc ('k') | media/audio/mac/scoped_audio_unit.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698