Further refactoring to AudioDriver implementations after #69120.
- Rename all instances of `capture_start()` and `capture_end()` to their new names. Fixes #72892. - More internal renames to match what was started in #69120. - Use `override` consistently so that such refactoring bugs can be caught. - Harmonize the order of definition of the overridden virtual methods in each audio driver. - Harmonize prototype for `set_output_device` and `set_input_device`. Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
This commit is contained in:
committed by
Rémi Verschelde
parent
d69809cab6
commit
c36460060e
@@ -43,17 +43,17 @@ extern int initialize_pulse(int verbose);
|
||||
}
|
||||
#endif
|
||||
|
||||
Error AudioDriverALSA::init_device() {
|
||||
Error AudioDriverALSA::init_output_device() {
|
||||
mix_rate = GLOBAL_GET("audio/driver/mix_rate");
|
||||
speaker_mode = SPEAKER_MODE_STEREO;
|
||||
channels = 2;
|
||||
|
||||
// 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";
|
||||
// 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";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,10 +75,10 @@ Error AudioDriverALSA::init_device() {
|
||||
//6 chans - "plug:surround51"
|
||||
//4 chans - "plug:surround40";
|
||||
|
||||
if (device_name == "Default") {
|
||||
if (output_device_name == "Default") {
|
||||
status = snd_pcm_open(&pcm_handle, "default", SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
|
||||
} else {
|
||||
String device = device_name;
|
||||
String device = output_device_name;
|
||||
int pos = device.find(";");
|
||||
if (pos != -1) {
|
||||
device = device.substr(0, pos);
|
||||
@@ -171,7 +171,7 @@ Error AudioDriverALSA::init() {
|
||||
active.clear();
|
||||
exit_thread.clear();
|
||||
|
||||
Error err = init_device();
|
||||
Error err = init_output_device();
|
||||
if (err == OK) {
|
||||
thread.start(AudioDriverALSA::thread_func, this);
|
||||
}
|
||||
@@ -227,18 +227,18 @@ void AudioDriverALSA::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 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("ALSA: init_device error");
|
||||
ad->device_name = "Default";
|
||||
ad->new_device = "Default";
|
||||
ERR_PRINT("ALSA: 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();
|
||||
@@ -263,7 +263,7 @@ AudioDriver::SpeakerMode AudioDriverALSA::get_speaker_mode() const {
|
||||
return speaker_mode;
|
||||
}
|
||||
|
||||
PackedStringArray AudioDriverALSA::get_device_list() {
|
||||
PackedStringArray AudioDriverALSA::get_output_device_list() {
|
||||
PackedStringArray list;
|
||||
|
||||
list.push_back("Default");
|
||||
@@ -298,13 +298,13 @@ PackedStringArray AudioDriverALSA::get_device_list() {
|
||||
return list;
|
||||
}
|
||||
|
||||
String AudioDriverALSA::get_device() {
|
||||
return device_name;
|
||||
String AudioDriverALSA::get_output_device() {
|
||||
return output_device_name;
|
||||
}
|
||||
|
||||
void AudioDriverALSA::set_device(String device) {
|
||||
void AudioDriverALSA::set_output_device(const String &p_name) {
|
||||
lock();
|
||||
new_device = device;
|
||||
new_output_device = p_name;
|
||||
unlock();
|
||||
}
|
||||
|
||||
@@ -316,7 +316,7 @@ void AudioDriverALSA::unlock() {
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
void AudioDriverALSA::finish_device() {
|
||||
void AudioDriverALSA::finish_output_device() {
|
||||
if (pcm_handle) {
|
||||
snd_pcm_close(pcm_handle);
|
||||
pcm_handle = nullptr;
|
||||
@@ -327,7 +327,7 @@ void AudioDriverALSA::finish() {
|
||||
exit_thread.set();
|
||||
thread.wait_to_finish();
|
||||
|
||||
finish_device();
|
||||
finish_output_device();
|
||||
}
|
||||
|
||||
#endif // ALSA_ENABLED
|
||||
|
||||
@@ -46,14 +46,14 @@ class AudioDriverALSA : public AudioDriver {
|
||||
|
||||
snd_pcm_t *pcm_handle = nullptr;
|
||||
|
||||
String device_name = "Default";
|
||||
String new_device = "Default";
|
||||
String output_device_name = "Default";
|
||||
String new_output_device = "Default";
|
||||
|
||||
Vector<int32_t> samples_in;
|
||||
Vector<int16_t> samples_out;
|
||||
|
||||
Error init_device();
|
||||
void finish_device();
|
||||
Error init_output_device();
|
||||
void finish_output_device();
|
||||
|
||||
static void thread_func(void *p_udata);
|
||||
|
||||
@@ -69,20 +69,22 @@ class AudioDriverALSA : public AudioDriver {
|
||||
SafeFlag exit_thread;
|
||||
|
||||
public:
|
||||
const char *get_name() const {
|
||||
virtual const char *get_name() const override {
|
||||
return "ALSA";
|
||||
};
|
||||
}
|
||||
|
||||
virtual Error init();
|
||||
virtual void start();
|
||||
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 void lock();
|
||||
virtual void unlock();
|
||||
virtual void finish();
|
||||
virtual Error init() override;
|
||||
virtual void start() override;
|
||||
virtual int get_mix_rate() const override;
|
||||
virtual SpeakerMode get_speaker_mode() const override;
|
||||
|
||||
virtual void lock() override;
|
||||
virtual void unlock() override;
|
||||
virtual void finish() override;
|
||||
|
||||
virtual PackedStringArray get_output_device_list() override;
|
||||
virtual String get_output_device() override;
|
||||
virtual void set_output_device(const String &p_name) override;
|
||||
|
||||
AudioDriverALSA() {}
|
||||
~AudioDriverALSA() {}
|
||||
|
||||
Reference in New Issue
Block a user