diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-31 18:56:27 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-31 18:56:27 +0100 |
commit | ea3566f2ed375143d5ee036e841540739c62ae40 (patch) | |
tree | c0a19bdd07b2db27208b9d26bb39c2e19f6f4999 /drivers | |
parent | 14a4408e025e9dfd2b02738975cc1b00d9361248 (diff) | |
parent | 5300daaff29b55d1d9ed55877f70644df3d3a434 (diff) |
Merge pull request #69120 from souplamp/audio-function-rename
Rename references to audio device, capture_device to output_device, input_device respectively
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/coreaudio/audio_driver_coreaudio.cpp | 54 | ||||
-rw-r--r-- | drivers/coreaudio/audio_driver_coreaudio.h | 18 | ||||
-rw-r--r-- | drivers/pulseaudio/audio_driver_pulseaudio.cpp | 138 | ||||
-rw-r--r-- | drivers/pulseaudio/audio_driver_pulseaudio.h | 36 | ||||
-rw-r--r-- | drivers/wasapi/audio_driver_wasapi.cpp | 162 | ||||
-rw-r--r-- | drivers/wasapi/audio_driver_wasapi.h | 36 |
6 files changed, 222 insertions, 222 deletions
diff --git a/drivers/coreaudio/audio_driver_coreaudio.cpp b/drivers/coreaudio/audio_driver_coreaudio.cpp index e9eb11e2e3..c454da8e23 100644 --- a/drivers/coreaudio/audio_driver_coreaudio.cpp +++ b/drivers/coreaudio/audio_driver_coreaudio.cpp @@ -44,10 +44,10 @@ OSStatus AudioDriverCoreAudio::input_device_address_cb(AudioObjectID inObjectID, void *inClientData) { AudioDriverCoreAudio *driver = static_cast<AudioDriverCoreAudio *>(inClientData); - // If our selected device is the Default call set_device to update the + // If our selected input device is the Default, call set_input_device to update the // kAudioOutputUnitProperty_CurrentDevice property - if (driver->capture_device_name == "Default") { - driver->capture_set_device("Default"); + if (driver->input_device_name == "Default") { + driver->set_input_device("Default"); } return noErr; @@ -58,10 +58,10 @@ OSStatus AudioDriverCoreAudio::output_device_address_cb(AudioObjectID inObjectID void *inClientData) { AudioDriverCoreAudio *driver = static_cast<AudioDriverCoreAudio *>(inClientData); - // If our selected device is the Default call set_device to update the + // If our selected output device is the Default call set_output_device to update the // kAudioOutputUnitProperty_CurrentDevice property - if (driver->device_name == "Default") { - driver->set_device("Default"); + if (driver->output_device_name == "Default") { + driver->set_output_device("Default"); } return noErr; @@ -495,7 +495,7 @@ Error AudioDriverCoreAudio::capture_stop() { #ifdef MACOS_ENABLED -PackedStringArray AudioDriverCoreAudio::_get_device_list(bool capture) { +PackedStringArray AudioDriverCoreAudio::_get_device_list(bool input) { PackedStringArray list; list.push_back("Default"); @@ -514,7 +514,7 @@ PackedStringArray AudioDriverCoreAudio::_get_device_list(bool capture) { UInt32 deviceCount = size / sizeof(AudioDeviceID); for (UInt32 i = 0; i < deviceCount; i++) { - prop.mScope = capture ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput; + prop.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput; prop.mSelector = kAudioDevicePropertyStreamConfiguration; AudioObjectGetPropertyDataSize(audioDevices[i], &prop, 0, nullptr, &size); @@ -555,10 +555,10 @@ PackedStringArray AudioDriverCoreAudio::_get_device_list(bool capture) { return list; } -void AudioDriverCoreAudio::_set_device(const String &device, bool capture) { +void AudioDriverCoreAudio::_set_device(const String &output_device, bool input) { AudioDeviceID deviceId; bool found = false; - if (device != "Default") { + if (output_device != "Default") { AudioObjectPropertyAddress prop; prop.mSelector = kAudioHardwarePropertyDevices; @@ -573,7 +573,7 @@ void AudioDriverCoreAudio::_set_device(const String &device, bool capture) { UInt32 deviceCount = size / sizeof(AudioDeviceID); for (UInt32 i = 0; i < deviceCount && !found; i++) { - prop.mScope = capture ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput; + prop.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput; prop.mSelector = kAudioDevicePropertyStreamConfiguration; AudioObjectGetPropertyDataSize(audioDevices[i], &prop, 0, nullptr, &size); @@ -602,7 +602,7 @@ void AudioDriverCoreAudio::_set_device(const String &device, bool capture) { ERR_FAIL_NULL_MSG(buffer, "Out of memory."); if (CFStringGetCString(cfname, buffer, maxSize, kCFStringEncodingUTF8)) { String name = String::utf8(buffer) + " (" + itos(audioDevices[i]) + ")"; - if (name == device) { + if (name == output_device) { deviceId = audioDevices[i]; found = true; } @@ -618,7 +618,7 @@ void AudioDriverCoreAudio::_set_device(const String &device, bool capture) { if (!found) { // If we haven't found the desired device get the system default one UInt32 size = sizeof(AudioDeviceID); - UInt32 elem = capture ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice; + UInt32 elem = input ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice; AudioObjectPropertyAddress property = { elem, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster }; OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject, &property, 0, nullptr, &size, &deviceId); @@ -628,10 +628,10 @@ void AudioDriverCoreAudio::_set_device(const String &device, bool capture) { } if (found) { - OSStatus result = AudioUnitSetProperty(capture ? input_unit : audio_unit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &deviceId, sizeof(AudioDeviceID)); + OSStatus result = AudioUnitSetProperty(input ? input_unit : audio_unit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &deviceId, sizeof(AudioDeviceID)); ERR_FAIL_COND(result != noErr); - if (capture) { + if (input) { // Reset audio input to keep synchronization. input_position = 0; input_size = 0; @@ -639,34 +639,34 @@ void AudioDriverCoreAudio::_set_device(const String &device, bool capture) { } } -PackedStringArray AudioDriverCoreAudio::get_device_list() { +PackedStringArray AudioDriverCoreAudio::get_output_device_list() { return _get_device_list(); } -String AudioDriverCoreAudio::get_device() { - return device_name; +String AudioDriverCoreAudio::get_output_device() { + return output_device_name; } -void AudioDriverCoreAudio::set_device(String device) { - device_name = device; +void AudioDriverCoreAudio::set_output_device(String output_device) { + output_device_name = output_device; if (active) { - _set_device(device_name); + _set_device(output_device_name); } } -void AudioDriverCoreAudio::capture_set_device(const String &p_name) { - capture_device_name = p_name; +void AudioDriverCoreAudio::set_input_device(const String &p_name) { + input_device_name = p_name; if (active) { - _set_device(capture_device_name, true); + _set_device(input_device_name, true); } } -PackedStringArray AudioDriverCoreAudio::capture_get_device_list() { +PackedStringArray AudioDriverCoreAudio::get_input_device_list() { return _get_device_list(true); } -String AudioDriverCoreAudio::capture_get_device() { - return capture_device_name; +String AudioDriverCoreAudio::get_input_device() { + return input_device_name; } #endif diff --git a/drivers/coreaudio/audio_driver_coreaudio.h b/drivers/coreaudio/audio_driver_coreaudio.h index 675265757b..2b192e630e 100644 --- a/drivers/coreaudio/audio_driver_coreaudio.h +++ b/drivers/coreaudio/audio_driver_coreaudio.h @@ -47,8 +47,8 @@ class AudioDriverCoreAudio : public AudioDriver { bool active = false; Mutex mutex; - String device_name = "Default"; - String capture_device_name = "Default"; + String output_device_name = "Default"; + String input_device_name = "Default"; int mix_rate = 0; unsigned int channels = 2; @@ -60,7 +60,7 @@ class AudioDriverCoreAudio : public AudioDriver { #ifdef MACOS_ENABLED PackedStringArray _get_device_list(bool capture = false); - void _set_device(const String &device, bool capture = false); + void _set_device(const String &output_device, bool capture = false); static OSStatus input_device_address_cb(AudioObjectID inObjectID, UInt32 inNumberAddresses, const AudioObjectPropertyAddress *inAddresses, @@ -107,13 +107,13 @@ public: void stop(); #ifdef MACOS_ENABLED - virtual PackedStringArray get_device_list(); - virtual String get_device(); - virtual void set_device(String device); + virtual PackedStringArray get_output_device_list(); + virtual String get_output_device(); + virtual void set_output_device(String output_device); - virtual PackedStringArray capture_get_device_list(); - virtual void capture_set_device(const String &p_name); - virtual String capture_get_device(); + virtual PackedStringArray get_input_device_list(); + virtual void set_input_device(const String &p_name); + virtual String get_input_device(); #endif AudioDriverCoreAudio(); diff --git a/drivers/pulseaudio/audio_driver_pulseaudio.cpp b/drivers/pulseaudio/audio_driver_pulseaudio.cpp index e14c3c7f7a..f96247a473 100644 --- a/drivers/pulseaudio/audio_driver_pulseaudio.cpp +++ b/drivers/pulseaudio/audio_driver_pulseaudio.cpp @@ -106,15 +106,15 @@ void AudioDriverPulseAudio::pa_server_info_cb(pa_context *c, const pa_server_inf ERR_FAIL_COND_MSG(!i, "PulseAudio server info is null."); AudioDriverPulseAudio *ad = static_cast<AudioDriverPulseAudio *>(userdata); - ad->capture_default_device = i->default_source_name; - ad->default_device = i->default_sink_name; + ad->default_input_device = i->default_source_name; + ad->default_output_device = i->default_sink_name; ad->pa_status++; } -Error AudioDriverPulseAudio::detect_channels(bool capture) { - pa_channel_map_init_stereo(capture ? &pa_rec_map : &pa_map); +Error AudioDriverPulseAudio::detect_channels(bool input) { + pa_channel_map_init_stereo(input ? &pa_rec_map : &pa_map); - String device = capture ? capture_device_name : device_name; + String device = input ? input_device_name : output_device_name; if (device == "Default") { // Get the default output device name pa_status = 0; @@ -136,7 +136,7 @@ Error AudioDriverPulseAudio::detect_channels(bool capture) { char dev[1024]; if (device == "Default") { - strcpy(dev, capture ? capture_default_device.utf8().get_data() : default_device.utf8().get_data()); + strcpy(dev, input ? default_input_device.utf8().get_data() : default_output_device.utf8().get_data()); } else { strcpy(dev, device.utf8().get_data()); } @@ -145,7 +145,7 @@ Error AudioDriverPulseAudio::detect_channels(bool capture) { // Now using the device name get the amount of channels pa_status = 0; pa_operation *pa_op; - if (capture) { + if (input) { pa_op = pa_context_get_source_info_by_name(pa_ctx, dev, &AudioDriverPulseAudio::pa_source_info_cb, (void *)this); } else { pa_op = pa_context_get_sink_info_by_name(pa_ctx, dev, &AudioDriverPulseAudio::pa_sink_info_cb, (void *)this); @@ -165,7 +165,7 @@ Error AudioDriverPulseAudio::detect_channels(bool capture) { return FAILED; } } else { - if (capture) { + if (input) { ERR_PRINT("pa_context_get_source_info_by_name error"); } else { ERR_PRINT("pa_context_get_sink_info_by_name error"); @@ -175,13 +175,13 @@ Error AudioDriverPulseAudio::detect_channels(bool capture) { return OK; } -Error AudioDriverPulseAudio::init_device() { - // If there is a specified device check that it is really present - if (device_name != "Default") { - PackedStringArray list = get_device_list(); - if (list.find(device_name) == -1) { - device_name = "Default"; - new_device = "Default"; +Error AudioDriverPulseAudio::init_output_device() { + // If there is a specified output device, check that it is really present + if (output_device_name != "Default") { + PackedStringArray list = get_output_device_list(); + if (list.find(output_device_name) == -1) { + output_device_name = "Default"; + new_output_device = "Default"; } } @@ -192,7 +192,7 @@ Error AudioDriverPulseAudio::init_device() { Error err = detect_channels(); if (err != OK) { // This most likely means there are no sinks. - ERR_PRINT("PulseAudio: init device failed to detect number of output channels"); + ERR_PRINT("PulseAudio: init_output_device failed to detect number of output channels"); return err; } @@ -256,7 +256,7 @@ Error AudioDriverPulseAudio::init_device() { attr.maxlength = (uint32_t)-1; attr.minreq = (uint32_t)-1; - const char *dev = device_name == "Default" ? nullptr : device_name.utf8().get_data(); + const char *dev = output_device_name == "Default" ? nullptr : output_device_name.utf8().get_data(); pa_stream_flags flags = pa_stream_flags(PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_ADJUST_LATENCY | PA_STREAM_AUTO_TIMING_UPDATE); int error_code = pa_stream_connect_playback(pa_str, dev, &attr, flags, nullptr, nullptr); ERR_FAIL_COND_V(error_code < 0, ERR_CANT_OPEN); @@ -346,7 +346,7 @@ Error AudioDriverPulseAudio::init() { return ERR_CANT_OPEN; } - init_device(); + init_output_device(); thread.start(AudioDriverPulseAudio::thread_func, this); return OK; @@ -448,18 +448,18 @@ void AudioDriverPulseAudio::thread_func(void *p_udata) { } } - // User selected a new device, finish the current one so we'll init the new device - if (ad->device_name != ad->new_device) { - ad->device_name = ad->new_device; - ad->finish_device(); + // User selected a new output device, finish the current one so we'll init the new output device + if (ad->output_device_name != ad->new_output_device) { + ad->output_device_name = ad->new_output_device; + ad->finish_output_device(); - Error err = ad->init_device(); + Error err = ad->init_output_device(); if (err != OK) { - ERR_PRINT("PulseAudio: init_device error"); - ad->device_name = "Default"; - ad->new_device = "Default"; + ERR_PRINT("PulseAudio: init_output_device error"); + ad->output_device_name = "Default"; + ad->new_output_device = "Default"; - err = ad->init_device(); + err = ad->init_output_device(); if (err != OK) { ad->active.clear(); ad->exit_thread.set(); @@ -471,11 +471,11 @@ void AudioDriverPulseAudio::thread_func(void *p_udata) { write_ofs = 0; } - // If we're using the default device check that the current device is still the default - if (ad->device_name == "Default") { + // If we're using the default output device, check that the current output device is still the default + if (ad->output_device_name == "Default") { uint64_t msec = OS::get_singleton()->get_ticks_msec(); if (msec > (default_device_msec + 1000)) { - String old_default_device = ad->default_device; + String old_default_device = ad->default_output_device; default_device_msec = msec; @@ -494,12 +494,12 @@ void AudioDriverPulseAudio::thread_func(void *p_udata) { ERR_PRINT("pa_context_get_server_info error: " + String(pa_strerror(pa_context_errno(ad->pa_ctx)))); } - if (old_default_device != ad->default_device) { - ad->finish_device(); + if (old_default_device != ad->default_output_device) { + ad->finish_output_device(); - Error err = ad->init_device(); + Error err = ad->init_output_device(); if (err != OK) { - ERR_PRINT("PulseAudio: init_device error"); + ERR_PRINT("PulseAudio: init_output_device error"); ad->active.clear(); ad->exit_thread.set(); break; @@ -541,18 +541,18 @@ void AudioDriverPulseAudio::thread_func(void *p_udata) { } } - // User selected a new device, finish the current one so we'll init the new device - if (ad->capture_device_name != ad->capture_new_device) { - ad->capture_device_name = ad->capture_new_device; - ad->capture_finish_device(); + // User selected a new input device, finish the current one so we'll init the new input device + if (ad->input_device_name != ad->new_input_device) { + ad->input_device_name = ad->new_input_device; + ad->finish_input_device(); - Error err = ad->capture_init_device(); + Error err = ad->init_input_device(); if (err != OK) { - ERR_PRINT("PulseAudio: capture_init_device error"); - ad->capture_device_name = "Default"; - ad->capture_new_device = "Default"; + ERR_PRINT("PulseAudio: init_input_device error"); + ad->input_device_name = "Default"; + ad->new_input_device = "Default"; - err = ad->capture_init_device(); + err = ad->init_input_device(); if (err != OK) { ad->active.clear(); ad->exit_thread.set(); @@ -596,7 +596,7 @@ void AudioDriverPulseAudio::pa_sinklist_cb(pa_context *c, const pa_sink_info *l, ad->pa_status++; } -PackedStringArray AudioDriverPulseAudio::get_device_list() { +PackedStringArray AudioDriverPulseAudio::get_output_device_list() { pa_devices.clear(); pa_devices.push_back("Default"); @@ -606,7 +606,7 @@ PackedStringArray AudioDriverPulseAudio::get_device_list() { lock(); - // Get the device list + // Get the output device list pa_status = 0; pa_operation *pa_op = pa_context_get_sink_info_list(pa_ctx, pa_sinklist_cb, (void *)this); if (pa_op) { @@ -627,13 +627,13 @@ PackedStringArray AudioDriverPulseAudio::get_device_list() { return pa_devices; } -String AudioDriverPulseAudio::get_device() { - return device_name; +String AudioDriverPulseAudio::get_output_device() { + return output_device_name; } -void AudioDriverPulseAudio::set_device(String device) { +void AudioDriverPulseAudio::set_output_device(String output_device) { lock(); - new_device = device; + new_output_device = output_device; unlock(); } @@ -645,7 +645,7 @@ void AudioDriverPulseAudio::unlock() { mutex.unlock(); } -void AudioDriverPulseAudio::finish_device() { +void AudioDriverPulseAudio::finish_output_device() { if (pa_str) { pa_stream_disconnect(pa_str); pa_stream_unref(pa_str); @@ -661,7 +661,7 @@ void AudioDriverPulseAudio::finish() { exit_thread.set(); thread.wait_to_finish(); - finish_device(); + finish_output_device(); if (pa_ctx) { pa_context_disconnect(pa_ctx); @@ -675,13 +675,13 @@ void AudioDriverPulseAudio::finish() { } } -Error AudioDriverPulseAudio::capture_init_device() { - // If there is a specified device check that it is really present - if (capture_device_name != "Default") { - PackedStringArray list = capture_get_device_list(); - if (list.find(capture_device_name) == -1) { - capture_device_name = "Default"; - capture_new_device = "Default"; +Error AudioDriverPulseAudio::init_input_device() { + // If there is a specified input device, check that it is really present + if (input_device_name != "Default") { + PackedStringArray list = get_input_device_list(); + if (list.find(input_device_name) == -1) { + input_device_name = "Default"; + new_input_device = "Default"; } } @@ -718,7 +718,7 @@ Error AudioDriverPulseAudio::capture_init_device() { ERR_FAIL_V(ERR_CANT_OPEN); } - const char *dev = capture_device_name == "Default" ? nullptr : capture_device_name.utf8().get_data(); + const char *dev = input_device_name == "Default" ? nullptr : input_device_name.utf8().get_data(); pa_stream_flags flags = pa_stream_flags(PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_ADJUST_LATENCY | PA_STREAM_AUTO_TIMING_UPDATE); int error_code = pa_stream_connect_record(pa_rec_str, dev, &attr, flags); if (error_code < 0) { @@ -734,7 +734,7 @@ Error AudioDriverPulseAudio::capture_init_device() { return OK; } -void AudioDriverPulseAudio::capture_finish_device() { +void AudioDriverPulseAudio::finish_input_device() { if (pa_rec_str) { int ret = pa_stream_disconnect(pa_rec_str); if (ret != 0) { @@ -745,25 +745,25 @@ void AudioDriverPulseAudio::capture_finish_device() { } } -Error AudioDriverPulseAudio::capture_start() { +Error AudioDriverPulseAudio::input_start() { lock(); - Error err = capture_init_device(); + Error err = init_input_device(); unlock(); return err; } -Error AudioDriverPulseAudio::capture_stop() { +Error AudioDriverPulseAudio::input_stop() { lock(); - capture_finish_device(); + finish_input_device(); unlock(); return OK; } -void AudioDriverPulseAudio::capture_set_device(const String &p_name) { +void AudioDriverPulseAudio::set_input_device(const String &p_name) { lock(); - capture_new_device = p_name; + new_input_device = p_name; unlock(); } @@ -782,7 +782,7 @@ void AudioDriverPulseAudio::pa_sourcelist_cb(pa_context *c, const pa_source_info ad->pa_status++; } -PackedStringArray AudioDriverPulseAudio::capture_get_device_list() { +PackedStringArray AudioDriverPulseAudio::get_input_device_list() { pa_rec_devices.clear(); pa_rec_devices.push_back("Default"); @@ -813,9 +813,9 @@ PackedStringArray AudioDriverPulseAudio::capture_get_device_list() { return pa_rec_devices; } -String AudioDriverPulseAudio::capture_get_device() { +String AudioDriverPulseAudio::get_input_device() { lock(); - String name = capture_device_name; + String name = input_device_name; unlock(); return name; diff --git a/drivers/pulseaudio/audio_driver_pulseaudio.h b/drivers/pulseaudio/audio_driver_pulseaudio.h index 16398e67eb..68df03cb60 100644 --- a/drivers/pulseaudio/audio_driver_pulseaudio.h +++ b/drivers/pulseaudio/audio_driver_pulseaudio.h @@ -51,13 +51,13 @@ class AudioDriverPulseAudio : public AudioDriver { pa_channel_map pa_map = {}; pa_channel_map pa_rec_map = {}; - String device_name = "Default"; - String new_device = "Default"; - String default_device; + String output_device_name = "Default"; + String new_output_device = "Default"; + String default_output_device; - String capture_device_name; - String capture_new_device; - String capture_default_device; + String input_device_name; + String new_input_device; + String default_input_device; Vector<int32_t> samples_in; Vector<int16_t> samples_out; @@ -83,11 +83,11 @@ class AudioDriverPulseAudio : public AudioDriver { static void pa_sinklist_cb(pa_context *c, const pa_sink_info *l, int eol, void *userdata); static void pa_sourcelist_cb(pa_context *c, const pa_source_info *l, int eol, void *userdata); - Error init_device(); - void finish_device(); + Error init_output_device(); + void finish_output_device(); - Error capture_init_device(); - void capture_finish_device(); + Error init_input_device(); + void finish_input_device(); Error detect_channels(bool capture = false); @@ -103,13 +103,13 @@ public: virtual int get_mix_rate() const; virtual SpeakerMode get_speaker_mode() const; - virtual PackedStringArray get_device_list(); - virtual String get_device(); - virtual void set_device(String device); + virtual PackedStringArray get_output_device_list(); + virtual String get_output_device(); + virtual void set_output_device(String output_device); - virtual PackedStringArray capture_get_device_list(); - virtual void capture_set_device(const String &p_name); - virtual String capture_get_device(); + virtual PackedStringArray get_input_device_list(); + virtual void set_input_device(const String &p_name); + virtual String get_input_device(); virtual void lock(); virtual void unlock(); @@ -117,8 +117,8 @@ public: virtual float get_latency(); - virtual Error capture_start(); - virtual Error capture_stop(); + virtual Error input_start(); + virtual Error input_stop(); AudioDriverPulseAudio(); ~AudioDriverPulseAudio() {} diff --git a/drivers/wasapi/audio_driver_wasapi.cpp b/drivers/wasapi/audio_driver_wasapi.cpp index b2745b1e86..42a2b85200 100644 --- a/drivers/wasapi/audio_driver_wasapi.cpp +++ b/drivers/wasapi/audio_driver_wasapi.cpp @@ -118,8 +118,8 @@ const IID IID_IAudioCaptureClient = __uuidof(IAudioCaptureClient); #define CAPTURE_BUFFER_CHANNELS 2 -static bool default_render_device_changed = false; -static bool default_capture_device_changed = false; +static bool default_output_device_changed = false; +static bool default_input_device_changed = false; // Silence warning due to a COM API weirdness (GH-35194). #if defined(__GNUC__) && !defined(__clang__) @@ -181,9 +181,9 @@ public: HRESULT STDMETHODCALLTYPE OnDefaultDeviceChanged(EDataFlow flow, ERole role, LPCWSTR pwstrDeviceId) { if (role == eConsole) { if (flow == eRender) { - default_render_device_changed = true; + default_output_device_changed = true; } else if (flow == eCapture) { - default_capture_device_changed = true; + default_input_device_changed = true; } } @@ -201,10 +201,10 @@ public: static CMMNotificationClient notif_client; -Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_capture, bool p_reinit, bool p_no_audio_client_3) { +Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_input, bool p_reinit, bool p_no_audio_client_3) { WAVEFORMATEX *pwfex; IMMDeviceEnumerator *enumerator = nullptr; - IMMDevice *device = nullptr; + IMMDevice *output_device = nullptr; CoInitialize(nullptr); @@ -212,11 +212,11 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_c ERR_FAIL_COND_V(hr != S_OK, ERR_CANT_OPEN); if (p_device->device_name == "Default") { - hr = enumerator->GetDefaultAudioEndpoint(p_capture ? eCapture : eRender, eConsole, &device); + hr = enumerator->GetDefaultAudioEndpoint(p_input ? eCapture : eRender, eConsole, &output_device); } else { IMMDeviceCollection *devices = nullptr; - hr = enumerator->EnumAudioEndpoints(p_capture ? eCapture : eRender, DEVICE_STATE_ACTIVE, &devices); + hr = enumerator->EnumAudioEndpoints(p_input ? eCapture : eRender, DEVICE_STATE_ACTIVE, &devices); ERR_FAIL_COND_V(hr != S_OK, ERR_CANT_OPEN); LPWSTR strId = nullptr; @@ -255,20 +255,20 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_c } if (found) { - hr = enumerator->GetDevice(strId, &device); + hr = enumerator->GetDevice(strId, &output_device); } if (strId) { CoTaskMemFree(strId); } - if (device == nullptr) { - hr = enumerator->GetDefaultAudioEndpoint(p_capture ? eCapture : eRender, eConsole, &device); + if (output_device == nullptr) { + hr = enumerator->GetDefaultAudioEndpoint(p_input ? eCapture : eRender, eConsole, &output_device); } } if (p_reinit) { - // In case we're trying to re-initialize the device prevent throwing this error on the console, + // In case we're trying to re-initialize the device, prevent throwing this error on the console, // otherwise if there is currently no device available this will spam the console. if (hr != S_OK) { return ERR_CANT_OPEN; @@ -284,28 +284,28 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_c ERR_PRINT("WASAPI: RegisterEndpointNotificationCallback error"); } - using_audio_client_3 = !p_capture; // IID_IAudioClient3 is only used for adjustable output latency (not input) + using_audio_client_3 = !p_input; // IID_IAudioClient3 is only used for adjustable output latency (not input) if (p_no_audio_client_3) { using_audio_client_3 = false; } if (using_audio_client_3) { - hr = device->Activate(IID_IAudioClient3, CLSCTX_ALL, nullptr, (void **)&p_device->audio_client); + hr = output_device->Activate(IID_IAudioClient3, CLSCTX_ALL, nullptr, (void **)&p_device->audio_client); if (hr != S_OK) { // IID_IAudioClient3 will never activate on OS versions before Windows 10. // Older Windows versions should fall back gracefully. using_audio_client_3 = false; - print_verbose("WASAPI: Couldn't activate device with IAudioClient3 interface, falling back to IAudioClient interface"); + print_verbose("WASAPI: Couldn't activate output_device with IAudioClient3 interface, falling back to IAudioClient interface"); } else { - print_verbose("WASAPI: Activated device using IAudioClient3 interface"); + print_verbose("WASAPI: Activated output_device using IAudioClient3 interface"); } } if (!using_audio_client_3) { - hr = device->Activate(IID_IAudioClient, CLSCTX_ALL, nullptr, (void **)&p_device->audio_client); + hr = output_device->Activate(IID_IAudioClient, CLSCTX_ALL, nullptr, (void **)&p_device->audio_client); } - SAFE_RELEASE(device) + SAFE_RELEASE(output_device) if (p_reinit) { if (hr != S_OK) { @@ -339,7 +339,7 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_c WAVEFORMATEX *closest = nullptr; hr = p_device->audio_client->IsFormatSupported(AUDCLNT_SHAREMODE_SHARED, pwfex, &closest); if (hr == S_FALSE) { - WARN_PRINT("WASAPI: Mix format is not supported by the Device"); + WARN_PRINT("WASAPI: Mix format is not supported by the output_device"); if (closest) { print_verbose("WASAPI: closest->wFormatTag = " + itos(closest->wFormatTag)); print_verbose("WASAPI: closest->nChannels = " + itos(closest->nChannels)); @@ -385,14 +385,14 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_c pwfex->nSamplesPerSec = mix_rate; pwfex->nAvgBytesPerSec = pwfex->nSamplesPerSec * pwfex->nChannels * (pwfex->wBitsPerSample / 8); } - hr = p_device->audio_client->Initialize(AUDCLNT_SHAREMODE_SHARED, streamflags, p_capture ? REFTIMES_PER_SEC : 0, 0, pwfex, nullptr); + hr = p_device->audio_client->Initialize(AUDCLNT_SHAREMODE_SHARED, streamflags, p_input ? REFTIMES_PER_SEC : 0, 0, pwfex, nullptr); ERR_FAIL_COND_V_MSG(hr != S_OK, ERR_CANT_OPEN, "WASAPI: Initialize failed with error 0x" + String::num_uint64(hr, 16) + "."); UINT32 max_frames; hr = p_device->audio_client->GetBufferSize(&max_frames); ERR_FAIL_COND_V(hr != S_OK, ERR_CANT_OPEN); // Due to WASAPI Shared Mode we have no control of the buffer size - if (!p_capture) { + if (!p_input) { buffer_frames = max_frames; int64_t latency = 0; @@ -421,8 +421,8 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_c if (hr != S_OK) { print_verbose("WASAPI: GetSharedModeEnginePeriod failed with error 0x" + String::num_uint64(hr, 16) + ", falling back to IAudioClient."); CoTaskMemFree(pwfex); - SAFE_RELEASE(device) - return audio_device_init(p_device, p_capture, p_reinit, true); + SAFE_RELEASE(output_device) + return audio_device_init(p_device, p_input, p_reinit, true); } // Period frames must be an integral multiple of fundamental_period_frames or IAudioClient3 initialization will fail, @@ -443,8 +443,8 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_c if (hr != S_OK) { print_verbose("WASAPI: InitializeSharedAudioStream failed with error 0x" + String::num_uint64(hr, 16) + ", falling back to IAudioClient."); CoTaskMemFree(pwfex); - SAFE_RELEASE(device); - return audio_device_init(p_device, p_capture, p_reinit, true); + SAFE_RELEASE(output_device); + return audio_device_init(p_device, p_input, p_reinit, true); } else { uint32_t output_latency_in_frames; WAVEFORMATEX *current_pwfex; @@ -455,13 +455,13 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_c } else { print_verbose("WASAPI: GetCurrentSharedModeEnginePeriod failed with error 0x" + String::num_uint64(hr, 16) + ", falling back to IAudioClient."); CoTaskMemFree(pwfex); - SAFE_RELEASE(device); - return audio_device_init(p_device, p_capture, p_reinit, true); + SAFE_RELEASE(output_device); + return audio_device_init(p_device, p_input, p_reinit, true); } } } - if (p_capture) { + if (p_input) { hr = p_device->audio_client->GetService(IID_IAudioCaptureClient, (void **)&p_device->capture_client); } else { hr = p_device->audio_client->GetService(IID_IAudioRenderClient, (void **)&p_device->render_client); @@ -470,12 +470,12 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_c // Free memory CoTaskMemFree(pwfex); - SAFE_RELEASE(device) + SAFE_RELEASE(output_device) return OK; } -Error AudioDriverWASAPI::init_render_device(bool p_reinit) { +Error AudioDriverWASAPI::init_output_device(bool p_reinit) { Error err = audio_device_init(&audio_output, false, p_reinit); if (err != OK) { return err; @@ -507,7 +507,7 @@ Error AudioDriverWASAPI::init_render_device(bool p_reinit) { return OK; } -Error AudioDriverWASAPI::init_capture_device(bool p_reinit) { +Error AudioDriverWASAPI::init_input_device(bool p_reinit) { Error err = audio_device_init(&audio_input, true, p_reinit); if (err != OK) { return err; @@ -538,11 +538,11 @@ Error AudioDriverWASAPI::audio_device_finish(AudioDeviceWASAPI *p_device) { return OK; } -Error AudioDriverWASAPI::finish_render_device() { +Error AudioDriverWASAPI::finish_output_device() { return audio_device_finish(&audio_output); } -Error AudioDriverWASAPI::finish_capture_device() { +Error AudioDriverWASAPI::finish_input_device() { return audio_device_finish(&audio_input); } @@ -551,9 +551,9 @@ Error AudioDriverWASAPI::init() { target_latency_ms = GLOBAL_GET("audio/driver/output_latency"); - Error err = init_render_device(); + Error err = init_output_device(); if (err != OK) { - ERR_PRINT("WASAPI: init_render_device error"); + ERR_PRINT("WASAPI: init_output_device error"); } exit_thread.clear(); @@ -575,7 +575,7 @@ AudioDriver::SpeakerMode AudioDriverWASAPI::get_speaker_mode() const { return get_speaker_mode_by_total_channels(channels); } -PackedStringArray AudioDriverWASAPI::audio_device_get_list(bool p_capture) { +PackedStringArray AudioDriverWASAPI::audio_device_get_list(bool p_input) { PackedStringArray list; IMMDeviceCollection *devices = nullptr; IMMDeviceEnumerator *enumerator = nullptr; @@ -587,7 +587,7 @@ PackedStringArray AudioDriverWASAPI::audio_device_get_list(bool p_capture) { HRESULT hr = CoCreateInstance(CLSID_MMDeviceEnumerator, nullptr, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void **)&enumerator); ERR_FAIL_COND_V(hr != S_OK, PackedStringArray()); - hr = enumerator->EnumAudioEndpoints(p_capture ? eCapture : eRender, DEVICE_STATE_ACTIVE, &devices); + hr = enumerator->EnumAudioEndpoints(p_input ? eCapture : eRender, DEVICE_STATE_ACTIVE, &devices); ERR_FAIL_COND_V(hr != S_OK, PackedStringArray()); UINT count = 0; @@ -595,13 +595,13 @@ PackedStringArray AudioDriverWASAPI::audio_device_get_list(bool p_capture) { ERR_FAIL_COND_V(hr != S_OK, PackedStringArray()); for (ULONG i = 0; i < count; i++) { - IMMDevice *device = nullptr; + IMMDevice *output_device = nullptr; - hr = devices->Item(i, &device); + hr = devices->Item(i, &output_device); ERR_BREAK(hr != S_OK); IPropertyStore *props = nullptr; - hr = device->OpenPropertyStore(STGM_READ, &props); + hr = output_device->OpenPropertyStore(STGM_READ, &props); ERR_BREAK(hr != S_OK); PROPVARIANT propvar; @@ -614,7 +614,7 @@ PackedStringArray AudioDriverWASAPI::audio_device_get_list(bool p_capture) { PropVariantClear(&propvar); props->Release(); - device->Release(); + output_device->Release(); } devices->Release(); @@ -622,11 +622,11 @@ PackedStringArray AudioDriverWASAPI::audio_device_get_list(bool p_capture) { return list; } -PackedStringArray AudioDriverWASAPI::get_device_list() { +PackedStringArray AudioDriverWASAPI::get_output_device_list() { return audio_device_get_list(false); } -String AudioDriverWASAPI::get_device() { +String AudioDriverWASAPI::get_output_device() { lock(); String name = audio_output.device_name; unlock(); @@ -634,9 +634,9 @@ String AudioDriverWASAPI::get_device() { return name; } -void AudioDriverWASAPI::set_device(String device) { +void AudioDriverWASAPI::set_output_device(String output_device) { lock(); - audio_output.new_device = device; + audio_output.new_device = output_device; unlock(); } @@ -769,13 +769,13 @@ void AudioDriverWASAPI::thread_func(void *p_udata) { avail_frames -= write_frames; written_frames += write_frames; } else if (hr == AUDCLNT_E_DEVICE_INVALIDATED) { - // Device is not valid anymore, reopen it + // output_device is not valid anymore, reopen it - Error err = ad->finish_render_device(); + Error err = ad->finish_output_device(); if (err != OK) { - ERR_PRINT("WASAPI: finish_render_device error"); + ERR_PRINT("WASAPI: finish_output_device error"); } else { - // We reopened the device and samples_in may have resized, so invalidate the current avail_frames + // We reopened the output device and samples_in may have resized, so invalidate the current avail_frames avail_frames = 0; } } else { @@ -790,37 +790,37 @@ void AudioDriverWASAPI::thread_func(void *p_udata) { } if (invalidated) { - // Device is not valid anymore - WARN_PRINT("WASAPI: Current device invalidated, closing device"); + // output_device is not valid anymore + WARN_PRINT("WASAPI: Current output_device invalidated, closing output_device"); - Error err = ad->finish_render_device(); + Error err = ad->finish_output_device(); if (err != OK) { - ERR_PRINT("WASAPI: finish_render_device error"); + ERR_PRINT("WASAPI: finish_output_device error"); } } } - // If we're using the Default device and it changed finish it so we'll re-init the device - if (ad->audio_output.device_name == "Default" && default_render_device_changed) { - Error err = ad->finish_render_device(); + // If we're using the Default output device and it changed finish it so we'll re-init the output device + if (ad->audio_output.device_name == "Default" && default_output_device_changed) { + Error err = ad->finish_output_device(); if (err != OK) { - ERR_PRINT("WASAPI: finish_render_device error"); + ERR_PRINT("WASAPI: finish_output_device error"); } - default_render_device_changed = false; + default_output_device_changed = false; } - // User selected a new device, finish the current one so we'll init the new device + // User selected a new output device, finish the current one so we'll init the new output device if (ad->audio_output.device_name != ad->audio_output.new_device) { ad->audio_output.device_name = ad->audio_output.new_device; - Error err = ad->finish_render_device(); + Error err = ad->finish_output_device(); if (err != OK) { - ERR_PRINT("WASAPI: finish_render_device error"); + ERR_PRINT("WASAPI: finish_output_device error"); } } if (!ad->audio_output.audio_client) { - Error err = ad->init_render_device(true); + Error err = ad->init_output_device(true); if (err == OK) { ad->start(); } @@ -873,29 +873,29 @@ void AudioDriverWASAPI::thread_func(void *p_udata) { } } - // If we're using the Default device and it changed finish it so we'll re-init the device - if (ad->audio_input.device_name == "Default" && default_capture_device_changed) { - Error err = ad->finish_capture_device(); + // If we're using the Default output device and it changed finish it so we'll re-init the output device + if (ad->audio_input.device_name == "Default" && default_input_device_changed) { + Error err = ad->finish_input_device(); if (err != OK) { - ERR_PRINT("WASAPI: finish_capture_device error"); + ERR_PRINT("WASAPI: finish_input_device error"); } - default_capture_device_changed = false; + default_input_device_changed = false; } - // User selected a new device, finish the current one so we'll init the new device + // User selected a new input device, finish the current one so we'll init the new input device if (ad->audio_input.device_name != ad->audio_input.new_device) { ad->audio_input.device_name = ad->audio_input.new_device; - Error err = ad->finish_capture_device(); + Error err = ad->finish_input_device(); if (err != OK) { - ERR_PRINT("WASAPI: finish_capture_device error"); + ERR_PRINT("WASAPI: finish_input_device error"); } } if (!ad->audio_input.audio_client) { - Error err = ad->init_capture_device(true); + Error err = ad->init_input_device(true); if (err == OK) { - ad->capture_start(); + ad->input_start(); } } } @@ -933,14 +933,14 @@ void AudioDriverWASAPI::finish() { exit_thread.set(); thread.wait_to_finish(); - finish_capture_device(); - finish_render_device(); + finish_input_device(); + finish_output_device(); } -Error AudioDriverWASAPI::capture_start() { - Error err = init_capture_device(); +Error AudioDriverWASAPI::input_start() { + Error err = init_input_device(); if (err != OK) { - ERR_PRINT("WASAPI: init_capture_device error"); + ERR_PRINT("WASAPI: init_input_device error"); return err; } @@ -953,7 +953,7 @@ Error AudioDriverWASAPI::capture_start() { return OK; } -Error AudioDriverWASAPI::capture_stop() { +Error AudioDriverWASAPI::input_stop() { if (audio_input.active.is_set()) { audio_input.audio_client->Stop(); audio_input.active.clear(); @@ -964,17 +964,17 @@ Error AudioDriverWASAPI::capture_stop() { return FAILED; } -void AudioDriverWASAPI::capture_set_device(const String &p_name) { +void AudioDriverWASAPI::set_input_device(const String &p_name) { lock(); audio_input.new_device = p_name; unlock(); } -PackedStringArray AudioDriverWASAPI::capture_get_device_list() { +PackedStringArray AudioDriverWASAPI::get_input_device_list() { return audio_device_get_list(true); } -String AudioDriverWASAPI::capture_get_device() { +String AudioDriverWASAPI::get_input_device() { lock(); String name = audio_input.device_name; unlock(); diff --git a/drivers/wasapi/audio_driver_wasapi.h b/drivers/wasapi/audio_driver_wasapi.h index 6eea24f78a..bf18ba8c99 100644 --- a/drivers/wasapi/audio_driver_wasapi.h +++ b/drivers/wasapi/audio_driver_wasapi.h @@ -47,8 +47,8 @@ class AudioDriverWASAPI : public AudioDriver { class AudioDeviceWASAPI { public: IAudioClient *audio_client = nullptr; - IAudioRenderClient *render_client = nullptr; - IAudioCaptureClient *capture_client = nullptr; + IAudioRenderClient *render_client = nullptr; // Output + IAudioCaptureClient *capture_client = nullptr; // Input SafeFlag active; WORD format_tag = 0; @@ -56,8 +56,8 @@ class AudioDriverWASAPI : public AudioDriver { unsigned int channels = 0; unsigned int frame_size = 0; - String device_name = "Default"; - String new_device = "Default"; + String device_name = "Default"; // Output OR Input + String new_device = "Default"; // Output OR Input AudioDeviceWASAPI() {} }; @@ -83,15 +83,15 @@ class AudioDriverWASAPI : public AudioDriver { static _FORCE_INLINE_ int32_t read_sample(WORD format_tag, int bits_per_sample, BYTE *buffer, int i); static void thread_func(void *p_udata); - Error init_render_device(bool p_reinit = false); - Error init_capture_device(bool p_reinit = false); + Error init_output_device(bool p_reinit = false); + Error init_input_device(bool p_reinit = false); - Error finish_render_device(); - Error finish_capture_device(); + Error finish_output_device(); + Error finish_input_device(); - Error audio_device_init(AudioDeviceWASAPI *p_device, bool p_capture, bool p_reinit, bool p_no_audio_client_3 = false); + Error audio_device_init(AudioDeviceWASAPI *p_device, bool p_input, bool p_reinit, bool p_no_audio_client_3 = false); Error audio_device_finish(AudioDeviceWASAPI *p_device); - PackedStringArray audio_device_get_list(bool p_capture); + PackedStringArray audio_device_get_list(bool p_input); public: virtual const char *get_name() const { @@ -103,18 +103,18 @@ public: virtual int get_mix_rate() const; virtual float get_latency(); virtual SpeakerMode get_speaker_mode() const; - virtual PackedStringArray get_device_list(); - virtual String get_device(); - virtual void set_device(String device); + virtual PackedStringArray get_output_device_list(); + virtual String get_output_device(); + virtual void set_output_device(String output_device); virtual void lock(); virtual void unlock(); virtual void finish(); - virtual Error capture_start(); - virtual Error capture_stop(); - virtual PackedStringArray capture_get_device_list(); - virtual void capture_set_device(const String &p_name); - virtual String capture_get_device(); + virtual Error input_start(); + virtual Error input_stop(); + virtual PackedStringArray get_input_device_list(); + virtual void set_input_device(const String &p_name); + virtual String get_input_device(); AudioDriverWASAPI(); }; |