diff options
Diffstat (limited to 'drivers/pulseaudio/audio_driver_pulseaudio.cpp')
-rw-r--r-- | drivers/pulseaudio/audio_driver_pulseaudio.cpp | 98 |
1 files changed, 68 insertions, 30 deletions
diff --git a/drivers/pulseaudio/audio_driver_pulseaudio.cpp b/drivers/pulseaudio/audio_driver_pulseaudio.cpp index 010f7bdb0a..0d98b7fbc0 100644 --- a/drivers/pulseaudio/audio_driver_pulseaudio.cpp +++ b/drivers/pulseaudio/audio_driver_pulseaudio.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -316,6 +316,7 @@ void AudioDriverPulseAudio::thread_func(void *p_udata) { AudioDriverPulseAudio *ad = (AudioDriverPulseAudio *)p_udata; unsigned int write_ofs = 0; size_t avail_bytes = 0; + uint32_t default_device_msec = OS::get_singleton()->get_ticks_msec(); while (!ad->exit_thread) { @@ -374,7 +375,7 @@ void AudioDriverPulseAudio::thread_func(void *p_udata) { const void *ptr = ad->samples_out.ptr(); ret = pa_stream_write(ad->pa_str, (char *)ptr + write_ofs, bytes_to_write, NULL, 0LL, PA_SEEK_RELATIVE); if (ret != 0) { - ERR_PRINT("pa_stream_write error"); + ERR_PRINTS("PulseAudio: pa_stream_write error: " + String(pa_strerror(ret))); } else { avail_bytes -= bytes_to_write; write_ofs += bytes_to_write; @@ -401,6 +402,50 @@ void AudioDriverPulseAudio::thread_func(void *p_udata) { break; } } + + avail_bytes = 0; + write_ofs = 0; + } + + // If we're using the default device check that the current device is still the default + if (ad->device_name == "Default") { + + uint32_t msec = OS::get_singleton()->get_ticks_msec(); + if (msec > (default_device_msec + 1000)) { + String old_default_device = ad->default_device; + + default_device_msec = msec; + + ad->pa_status = 0; + pa_operation *pa_op = pa_context_get_server_info(ad->pa_ctx, &AudioDriverPulseAudio::pa_server_info_cb, (void *)ad); + if (pa_op) { + while (ad->pa_status == 0) { + int ret = pa_mainloop_iterate(ad->pa_ml, 1, NULL); + if (ret < 0) { + ERR_PRINT("pa_mainloop_iterate error"); + } + } + + pa_operation_unref(pa_op); + } else { + ERR_PRINT("pa_context_get_server_info error"); + } + + if (old_default_device != ad->default_device) { + ad->finish_device(); + + Error err = ad->init_device(); + if (err != OK) { + ERR_PRINT("PulseAudio: init_device error"); + ad->active = false; + ad->exit_thread = true; + break; + } + + avail_bytes = 0; + write_ofs = 0; + } + } } if (ad->pa_rec_str && pa_stream_get_state(ad->pa_rec_str) == PA_STREAM_READY) { @@ -740,35 +785,28 @@ String AudioDriverPulseAudio::capture_get_device() { return name; } -AudioDriverPulseAudio::AudioDriverPulseAudio() { - - pa_ml = NULL; - pa_ctx = NULL; - pa_str = NULL; - pa_rec_str = NULL; - - mutex = NULL; - thread = NULL; - - device_name = "Default"; - new_device = "Default"; - default_device = ""; - +AudioDriverPulseAudio::AudioDriverPulseAudio() : + thread(NULL), + mutex(NULL), + pa_ml(NULL), + pa_ctx(NULL), + pa_str(NULL), + pa_rec_str(NULL), + device_name("Default"), + new_device("Default"), + default_device(""), + mix_rate(0), + buffer_frames(0), + pa_buffer_size(0), + channels(0), + pa_ready(0), + pa_status(0), + active(false), + thread_exited(false), + exit_thread(false), + latency(0) { samples_in.clear(); samples_out.clear(); - - mix_rate = 0; - buffer_frames = 0; - pa_buffer_size = 0; - channels = 0; - pa_ready = 0; - pa_status = 0; - - active = false; - thread_exited = false; - exit_thread = false; - - latency = 0; } AudioDriverPulseAudio::~AudioDriverPulseAudio() { |