Debian Codegraph @

drivers/coreaudio/audio_driver_coreaudio.h

raw symbols SCIP
1 /**************************************************************************/
2 /* audio_driver_coreaudio.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #ifdef COREAUDIO_ENABLED
34
35 #include "servers/audio/audio_server.h"
36
37 #import <AudioUnit/AudioUnit.h>
38 #ifdef MACOS_ENABLED
39 #import <CoreAudio/AudioHardware.h>
40 #else
41 #import <AVFoundation/AVFoundation.h>
42 #endif
43
44 class AudioDriverCoreAudio : public AudioDriver {
45 AudioComponentInstance audio_unit = nullptr;
46 AudioComponentInstance input_unit = nullptr;
47
48 bool active = false;
49 Mutex mutex;
50
51 String output_device_name = "Default";
52 String input_device_name = "Default";
53
54 int mix_rate = 0;
55 int capture_mix_rate = 0;
56 unsigned int channels = 2;
57 unsigned int capture_channels = 2;
58 unsigned int buffer_frames = 0;
59 unsigned int capture_buffer_frames = 0;
60
61 Vector<int32_t> samples_in;
62 unsigned int buffer_size = 0;
63
64 #ifdef MACOS_ENABLED
65 PackedStringArray _get_device_list(bool capture = false);
66 void _set_device(const String &output_device, bool capture = false);
67
68 static OSStatus input_device_address_cb(AudioObjectID inObjectID,
69 UInt32 inNumberAddresses, const AudioObjectPropertyAddress *inAddresses,
70 void *inClientData);
71
72 static OSStatus output_device_address_cb(AudioObjectID inObjectID,
73 UInt32 inNumberAddresses, const AudioObjectPropertyAddress *inAddresses,
74 void *inClientData);
75 #endif
76
77 static OSStatus output_callback(void *inRefCon,
78 AudioUnitRenderActionFlags *ioActionFlags,
79 const AudioTimeStamp *inTimeStamp,
80 UInt32 inBusNumber, UInt32 inNumberFrames,
81 AudioBufferList *ioData);
82
83 static OSStatus input_callback(void *inRefCon,
84 AudioUnitRenderActionFlags *ioActionFlags,
85 const AudioTimeStamp *inTimeStamp,
86 UInt32 inBusNumber, UInt32 inNumberFrames,
87 AudioBufferList *ioData);
88
89 Error init_input_device();
90 void finish_input_device();
91
92 public:
93 virtual const char *get_name() const override {
94 return "CoreAudio";
95 }
96
97 virtual Error init() override;
98 virtual void start() override;
99 virtual int get_mix_rate() const override;
100 virtual int get_input_mix_rate() const override;
101 virtual SpeakerMode get_speaker_mode() const override;
102
103 virtual void lock() override;
104 virtual void unlock() override;
105 virtual void finish() override;
106
107 #ifdef MACOS_ENABLED
108 virtual PackedStringArray get_output_device_list() override;
109 virtual String get_output_device() override;
110 virtual void set_output_device(const String &p_name) override;
111
112 virtual PackedStringArray get_input_device_list() override;
113 virtual String get_input_device() override;
114 virtual void set_input_device(const String &p_name) override;
115 #endif
116
117 virtual Error input_start() override;
118 virtual Error input_stop() override;
119
120 bool try_lock();
121 void stop();
122
123 AudioDriverCoreAudio();
124 ~AudioDriverCoreAudio() {}
125 };
126
127 #endif // COREAUDIO_ENABLED