Merge pull request #34453 from xsellier/patch-3

[2.1] Fallback to the dummy audio driver if no other audio driver works
This commit is contained in:
Rémi Verschelde 2019-12-20 12:22:42 +01:00 committed by GitHub
commit 9c9aee12f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 53 additions and 83 deletions

View File

@ -181,7 +181,7 @@ Error AudioDriverRtAudio::init() {
} }
} }
return OK; return active ? OK : ERR_UNAVAILABLE;
} }
int AudioDriverRtAudio::get_mix_rate() const { int AudioDriverRtAudio::get_mix_rate() const {

View File

@ -143,12 +143,7 @@ void OS_Android::initialize(const VideoMode &p_desired, int p_video_driver, int
}; };
visual_server->init(); visual_server->init();
AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); AudioDriverManagerSW::initialize(p_audio_driver);
if (AudioDriverManagerSW::get_driver(p_audio_driver)->init() != OK) {
ERR_PRINT("Initializing audio failed.");
}
sample_manager = memnew(SampleManagerMallocSW); sample_manager = memnew(SampleManagerMallocSW);
audio_server = memnew(AudioServerSW(sample_manager)); audio_server = memnew(AudioServerSW(sample_manager));

View File

@ -136,11 +136,7 @@ void OS_Haiku::initialize(const VideoMode &p_desired, int p_video_driver, int p_
//physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>(); //physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>();
physics_2d_server->init(); physics_2d_server->init();
AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); AudioDriverManagerSW::initialize(p_audio_driver);
if (AudioDriverManagerSW::get_driver(p_audio_driver)->init() != OK) {
ERR_PRINT("Initializing audio failed.");
}
sample_manager = memnew(SampleManagerMallocSW); sample_manager = memnew(SampleManagerMallocSW);
audio_server = memnew(AudioServerSW(sample_manager)); audio_server = memnew(AudioServerSW(sample_manager));

View File

@ -440,12 +440,7 @@ void OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver, i
visual_server = memnew(VisualServerRaster(rasterizer)); visual_server = memnew(VisualServerRaster(rasterizer));
visual_server->init(); visual_server->init();
/*AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); // AudioDriverManagerSW::initialize(p_audio_driver);
if (AudioDriverManagerSW::get_driver(p_audio_driver)->init()!=OK) {
ERR_PRINT("Initializing audio failed.");
}*/
print_line("Init SM"); print_line("Init SM");

View File

@ -1029,12 +1029,7 @@ void OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
visual_server->init(); visual_server->init();
AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); AudioDriverManagerSW::initialize(p_audio_driver);
if (AudioDriverManagerSW::get_driver(p_audio_driver)->init() != OK) {
ERR_PRINT("Initializing audio failed.");
}
sample_manager = memnew(SampleManagerMallocSW); sample_manager = memnew(SampleManagerMallocSW);
audio_server = memnew(AudioServerSW(sample_manager)); audio_server = memnew(AudioServerSW(sample_manager));

View File

@ -62,12 +62,7 @@ void OS_Server::initialize(const VideoMode &p_desired, int p_video_driver, int p
visual_server = memnew(VisualServerRaster(rasterizer)); visual_server = memnew(VisualServerRaster(rasterizer));
AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); AudioDriverManagerSW::initialize(p_audio_driver);
if (AudioDriverManagerSW::get_driver(p_audio_driver)->init() != OK) {
ERR_PRINT("Initializing audio failed.");
}
sample_manager = memnew(SampleManagerMallocSW); sample_manager = memnew(SampleManagerMallocSW);
audio_server = memnew(AudioServerSW(sample_manager)); audio_server = memnew(AudioServerSW(sample_manager));
@ -221,7 +216,6 @@ void OS_Server::run() {
OS_Server::OS_Server() { OS_Server::OS_Server() {
AudioDriverManagerSW::add_driver(&driver_dummy);
//adriver here //adriver here
grab = false; grab = false;
}; };

View File

@ -33,7 +33,6 @@
#include "drivers/rtaudio/audio_driver_rtaudio.h" #include "drivers/rtaudio/audio_driver_rtaudio.h"
#include "drivers/unix/os_unix.h" #include "drivers/unix/os_unix.h"
#include "main/input_default.h" #include "main/input_default.h"
#include "servers/audio/audio_driver_dummy.h"
#include "servers/audio/audio_server_sw.h" #include "servers/audio/audio_server_sw.h"
#include "servers/audio/sample_manager_sw.h" #include "servers/audio/sample_manager_sw.h"
#include "servers/physics_2d/physics_2d_server_sw.h" #include "servers/physics_2d/physics_2d_server_sw.h"
@ -57,7 +56,6 @@ class OS_Server : public OS_Unix {
List<String> args; List<String> args;
MainLoop *main_loop; MainLoop *main_loop;
AudioDriverDummy driver_dummy;
bool grab; bool grab;
PhysicsServer *physics_server; PhysicsServer *physics_server;

View File

@ -1126,12 +1126,7 @@ void OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
input = memnew(InputDefault); input = memnew(InputDefault);
joystick = memnew(joystick_windows(input, &hWnd)); joystick = memnew(joystick_windows(input, &hWnd));
AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); AudioDriverManagerSW::initialize(p_audio_driver);
if (AudioDriverManagerSW::get_driver(p_audio_driver)->init() != OK) {
ERR_PRINT("Initializing audio failed.");
}
sample_manager = memnew(SampleManagerMallocSW); sample_manager = memnew(SampleManagerMallocSW);
audio_server = memnew(AudioServerSW(sample_manager)); audio_server = memnew(AudioServerSW(sample_manager));

View File

@ -284,12 +284,7 @@ void OSWinrt::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
joystick = ref new JoystickWinrt(input); joystick = ref new JoystickWinrt(input);
joystick->register_events(); joystick->register_events();
AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); AudioDriverManagerSW::initialize(p_audio_driver);
if (AudioDriverManagerSW::get_driver(p_audio_driver)->init() != OK) {
ERR_PRINT("Initializing audio failed.");
}
sample_manager = memnew(SampleManagerMallocSW); sample_manager = memnew(SampleManagerMallocSW);
audio_server = memnew(AudioServerSW(sample_manager)); audio_server = memnew(AudioServerSW(sample_manager));

View File

@ -293,29 +293,7 @@ void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
XFree(xsh); XFree(xsh);
} }
AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); AudioDriverManagerSW::initialize(p_audio_driver);
audio_driver_index = p_audio_driver;
if (AudioDriverManagerSW::get_driver(p_audio_driver)->init() != OK) {
bool success = false;
audio_driver_index = -1;
for (int i = 0; i < AudioDriverManagerSW::get_driver_count(); i++) {
if (i == p_audio_driver)
continue;
AudioDriverManagerSW::get_driver(i)->set_singleton();
if (AudioDriverManagerSW::get_driver(i)->init() == OK) {
success = true;
print_line("Audio Driver Failed: " + String(AudioDriverManagerSW::get_driver(p_audio_driver)->get_name()));
print_line("Using alternate audio driver: " + String(AudioDriverManagerSW::get_driver(i)->get_name()));
audio_driver_index = i;
break;
}
}
if (!success) {
ERR_PRINT("Initializing audio failed.");
}
}
sample_manager = memnew(SampleManagerMallocSW); sample_manager = memnew(SampleManagerMallocSW);
audio_server = memnew(AudioServerSW(sample_manager)); audio_server = memnew(AudioServerSW(sample_manager));
@ -2389,10 +2367,6 @@ OS::LatinKeyboardVariant OS_X11::get_latin_keyboard_variant() const {
OS_X11::OS_X11() { OS_X11::OS_X11() {
#ifdef RTAUDIO_ENABLED
AudioDriverManagerSW::add_driver(&driver_rtaudio);
#endif
#ifdef PULSEAUDIO_ENABLED #ifdef PULSEAUDIO_ENABLED
AudioDriverManagerSW::add_driver(&driver_pulseaudio); AudioDriverManagerSW::add_driver(&driver_pulseaudio);
#endif #endif
@ -2401,11 +2375,6 @@ OS_X11::OS_X11() {
AudioDriverManagerSW::add_driver(&driver_alsa); AudioDriverManagerSW::add_driver(&driver_alsa);
#endif #endif
if (AudioDriverManagerSW::get_driver_count() == 0) {
WARN_PRINT("No sound driver found... Defaulting to dummy driver");
AudioDriverManagerSW::add_driver(&driver_dummy);
}
minimized = false; minimized = false;
xim_style = 0L; xim_style = 0L;
mouse_mode = MOUSE_MODE_VISIBLE; mouse_mode = MOUSE_MODE_VISIBLE;

View File

@ -34,7 +34,6 @@
#include "crash_handler_x11.h" #include "crash_handler_x11.h"
#include "drivers/alsa/audio_driver_alsa.h" #include "drivers/alsa/audio_driver_alsa.h"
#include "drivers/pulseaudio/audio_driver_pulseaudio.h" #include "drivers/pulseaudio/audio_driver_pulseaudio.h"
#include "drivers/rtaudio/audio_driver_rtaudio.h"
#include "drivers/unix/os_unix.h" #include "drivers/unix/os_unix.h"
#include "joystick_linux.h" #include "joystick_linux.h"
#include "main/input_default.h" #include "main/input_default.h"
@ -173,10 +172,6 @@ class OS_X11 : public OS_Unix {
joystick_linux *joystick; joystick_linux *joystick;
#endif #endif
#ifdef RTAUDIO_ENABLED
AudioDriverRtAudio driver_rtaudio;
#endif
#ifdef ALSA_ENABLED #ifdef ALSA_ENABLED
AudioDriverALSA driver_alsa; AudioDriverALSA driver_alsa;
#endif #endif
@ -184,7 +179,6 @@ class OS_X11 : public OS_Unix {
#ifdef PULSEAUDIO_ENABLED #ifdef PULSEAUDIO_ENABLED
AudioDriverPulseAudio driver_pulseaudio; AudioDriverPulseAudio driver_pulseaudio;
#endif #endif
AudioDriverDummy driver_dummy;
Atom net_wm_icon; Atom net_wm_icon;

View File

@ -30,6 +30,7 @@
#include "audio_server_sw.h" #include "audio_server_sw.h"
#include "globals.h" #include "globals.h"
#include "os/os.h" #include "os/os.h"
#include "servers/audio/audio_driver_dummy.h"
struct _AudioDriverLock { struct _AudioDriverLock {
@ -945,6 +946,7 @@ AudioDriverSW::AudioDriverSW() {
AudioDriverSW *AudioDriverManagerSW::drivers[MAX_DRIVERS]; AudioDriverSW *AudioDriverManagerSW::drivers[MAX_DRIVERS];
int AudioDriverManagerSW::driver_count = 0; int AudioDriverManagerSW::driver_count = 0;
AudioDriverDummy AudioDriverManagerSW::dummy_driver;
void AudioDriverManagerSW::add_driver(AudioDriverSW *p_driver) { void AudioDriverManagerSW::add_driver(AudioDriverSW *p_driver) {
@ -956,6 +958,43 @@ int AudioDriverManagerSW::get_driver_count() {
return driver_count; return driver_count;
} }
void AudioDriverManagerSW::initialize(int p_driver) {
AudioDriverSW *driver;
int failed_driver = -1;
// Check if there is a selected driver
if (p_driver >= 0 && p_driver < driver_count) {
if (drivers[p_driver]->init() == OK) {
drivers[p_driver]->set_singleton();
return;
} else {
failed_driver = p_driver;
}
}
// No selected driver, try them all in order
for (int i = 0; i < driver_count; i++) {
// Don't re-init the driver if it failed above
if (i == failed_driver) {
continue;
}
if (drivers[i]->init() == OK) {
drivers[i]->set_singleton();
return;
}
}
// Fallback to our dummy driver
if (dummy_driver.init() == OK) {
ERR_PRINT("AudioDriverManager: all drivers failed, falling back to dummy driver");
dummy_driver.set_singleton();
} else {
ERR_PRINT("AudioDriverManager: dummy driver faild to init()");
}
}
AudioDriverSW *AudioDriverManagerSW::get_driver(int p_driver) { AudioDriverSW *AudioDriverManagerSW::get_driver(int p_driver) {
ERR_FAIL_INDEX_V(p_driver, driver_count, NULL); ERR_FAIL_INDEX_V(p_driver, driver_count, NULL);

View File

@ -36,6 +36,9 @@
#include "servers/audio/audio_mixer_sw.h" #include "servers/audio/audio_mixer_sw.h"
#include "servers/audio/voice_rb_sw.h" #include "servers/audio/voice_rb_sw.h"
#include "servers/audio_server.h" #include "servers/audio_server.h"
class AudioDriverDummy;
class AudioServerSW : public AudioServer { class AudioServerSW : public AudioServer {
OBJ_TYPE(AudioServerSW, AudioServer); OBJ_TYPE(AudioServerSW, AudioServer);
@ -265,9 +268,11 @@ class AudioDriverManagerSW {
static AudioDriverSW *drivers[MAX_DRIVERS]; static AudioDriverSW *drivers[MAX_DRIVERS];
static int driver_count; static int driver_count;
static AudioDriverDummy dummy_driver;
public: public:
static void add_driver(AudioDriverSW *p_driver); static void add_driver(AudioDriverSW *p_driver);
static void initialize(int p_driver);
static int get_driver_count(); static int get_driver_count();
static AudioDriverSW *get_driver(int p_driver); static AudioDriverSW *get_driver(int p_driver);
}; };