Debian Codegraph @

drivers/wasapi/audio_driver_wasapi.h

raw symbols SCIP
1 /**************************************************************************/
2 /* audio_driver_wasapi.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 WASAPI_ENABLED
34
35 #include "core/os/mutex.h"
36 #include "core/os/thread.h"
37 #include "core/templates/safe_refcount.h"
38 #include "servers/audio/audio_server.h"
39
40 #include <audioclient.h>
41 #include <mmdeviceapi.h>
42 #define WIN32_LEAN_AND_MEAN
43 #include <windows.h>
44
45 class AudioDriverWASAPI : public AudioDriver {
46 class AudioDeviceWASAPI {
47 public:
48 IAudioClient *audio_client = nullptr;
49 IAudioRenderClient *render_client = nullptr; // Output
50 IAudioCaptureClient *capture_client = nullptr; // Input
51 SafeFlag active;
52
53 WORD format_tag = 0;
54 WORD bits_per_sample = 0;
55 unsigned int channels = 0;
56 unsigned int frame_size = 0;
57
58 String device_name = "Default"; // Output OR Input
59 String new_device = "Default"; // Output OR Input
60
61 AudioDeviceWASAPI() {}
62 };
63
64 AudioDeviceWASAPI audio_input;
65 AudioDeviceWASAPI audio_output;
66
67 Mutex mutex;
68 Thread thread;
69
70 Vector<int32_t> samples_in;
71
72 unsigned int channels = 0;
73 int mix_rate = 0;
74 int buffer_frames = 0;
75 int target_latency_ms = 0;
76 float real_latency = 0.0;
77 bool using_audio_client_3 = false;
78
79 SafeFlag exit_thread;
80
81 static _FORCE_INLINE_ void write_sample(WORD format_tag, int bits_per_sample, BYTE *buffer, int i, int32_t sample);
82 static _FORCE_INLINE_ int32_t read_sample(WORD format_tag, int bits_per_sample, BYTE *buffer, int i);
83 static void thread_func(void *p_udata);
84
85 Error init_output_device(bool p_reinit = false);
86 Error init_input_device(bool p_reinit = false);
87
88 Error finish_output_device();
89 Error finish_input_device();
90
91 Error audio_device_init(AudioDeviceWASAPI *p_device, bool p_input, bool p_reinit, bool p_no_audio_client_3 = false);
92 Error audio_device_finish(AudioDeviceWASAPI *p_device);
93 PackedStringArray audio_device_get_list(bool p_input);
94
95 public:
96 virtual const char *get_name() const override {
97 return "WASAPI";
98 }
99
100 virtual Error init() override;
101 virtual void start() override;
102 virtual int get_mix_rate() const override;
103 virtual SpeakerMode get_speaker_mode() const override;
104 virtual float get_latency() override;
105
106 virtual void lock() override;
107 virtual void unlock() override;
108 virtual void finish() override;
109
110 virtual PackedStringArray get_output_device_list() override;
111 virtual String get_output_device() override;
112 virtual void set_output_device(const String &p_name) override;
113
114 virtual Error input_start() override;
115 virtual Error input_stop() override;
116
117 virtual PackedStringArray get_input_device_list() override;
118 virtual String get_input_device() override;
119 virtual void set_input_device(const String &p_name) override;
120
121 AudioDriverWASAPI();
122 };
123
124 #endif // WASAPI_ENABLED