1 // Copyright 2005-2019 The Mumble Developers. All rights reserved.
2 // Use of this source code is governed by a BSD-style license
3 // that can be found in the LICENSE file at the root of the
4 // Mumble source tree or at <https://www.mumble.info/LICENSE>.
5 
6 #ifndef MUMBLE_MUMBLE_COREAUDIO_H_
7 #define MUMBLE_MUMBLE_COREAUDIO_H_
8 
9 #include "AudioInput.h"
10 #include "AudioOutput.h"
11 
12 #include <AudioToolbox/AudioToolbox.h>
13 
14 class CoreAudioSystem : public QObject {
15 	private:
16 		Q_OBJECT
17 		Q_DISABLE_COPY(CoreAudioSystem)
18 	public:
19 		static CFStringRef QStringToCFString(const QString &str);
20 		static const QHash<QString, QString> getDevices(bool input);
21 		static const QList<audioDevice> getDeviceChoices(bool input);
22 };
23 
24 class CoreAudioInput : public AudioInput {
25 	private:
26 		Q_OBJECT
27 		Q_DISABLE_COPY(CoreAudioInput)
28 	protected:
29 		AudioUnit au;
30 		AUEventListenerRef el;
31 		AudioBufferList buflist;
32 		static void propertyChange(void *udata, AudioUnit au, AudioUnitPropertyID prop, AudioUnitScope scope, AudioUnitElement element);
33 		static OSStatus inputCallback(void *udata, AudioUnitRenderActionFlags *flags, const AudioTimeStamp *ts,
34 		                              UInt32 busnum, UInt32 npackets, AudioBufferList *buflist);
35 	public:
36 		CoreAudioInput();
37 		~CoreAudioInput() Q_DECL_OVERRIDE;
38 		void run() Q_DECL_OVERRIDE;
39 };
40 
41 class CoreAudioOutput : public AudioOutput {
42 	private:
43 		Q_OBJECT
44 		Q_DISABLE_COPY(CoreAudioOutput)
45 	protected:
46 		AudioUnit au;
47 		AUEventListenerRef el;
48 		static void propertyChange(void *udata, AudioUnit au, AudioUnitPropertyID prop, AudioUnitScope scope, AudioUnitElement element);
49 		static OSStatus outputCallback(void *udata, AudioUnitRenderActionFlags *flags, const AudioTimeStamp *ts,
50 		                               UInt32 busnum, UInt32 npackets, AudioBufferList *buflist);
51 	public:
52 		CoreAudioOutput();
53 		~CoreAudioOutput() Q_DECL_OVERRIDE;
54 		void run() Q_DECL_OVERRIDE;
55 };
56 
57 #else
58 class CoreAudioSystem;
59 class CoreAudioInput;
60 class CoreAudioOutput;
61 #endif
62