summaryrefslogtreecommitdiff
path: root/servers
diff options
context:
space:
mode:
Diffstat (limited to 'servers')
-rw-r--r--servers/audio_server.cpp39
-rw-r--r--servers/audio_server.h5
2 files changed, 44 insertions, 0 deletions
diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp
index ed62e65846..a18ad327c5 100644
--- a/servers/audio_server.cpp
+++ b/servers/audio_server.cpp
@@ -32,6 +32,7 @@
#include "os/file_access.h"
#include "os/os.h"
#include "project_settings.h"
+#include "servers/audio/audio_driver_dummy.h"
#include "servers/audio/effects/audio_effect_compressor.h"
#ifdef TOOLS_ENABLED
@@ -107,6 +108,7 @@ AudioDriver::AudioDriver() {
AudioDriver *AudioDriverManager::drivers[MAX_DRIVERS];
int AudioDriverManager::driver_count = 0;
+AudioDriverDummy AudioDriverManager::dummy_driver;
void AudioDriverManager::add_driver(AudioDriver *p_driver) {
@@ -118,6 +120,43 @@ int AudioDriverManager::get_driver_count() {
return driver_count;
}
+
+void AudioDriverManager::initialize(int p_driver) {
+ AudioDriver *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()");
+ }
+}
+
AudioDriver *AudioDriverManager::get_driver(int p_driver) {
ERR_FAIL_INDEX_V(p_driver, driver_count, NULL);
diff --git a/servers/audio_server.h b/servers/audio_server.h
index c479d09a3c..55e9367308 100644
--- a/servers/audio_server.h
+++ b/servers/audio_server.h
@@ -35,6 +35,8 @@
#include "servers/audio/audio_effect.h"
#include "variant.h"
+class AudioDriverDummy;
+
class AudioDriver {
static AudioDriver *singleton;
@@ -90,8 +92,11 @@ class AudioDriverManager {
static AudioDriver *drivers[MAX_DRIVERS];
static int driver_count;
+ static AudioDriverDummy dummy_driver;
+
public:
static void add_driver(AudioDriver *p_driver);
+ static void initialize(int p_driver);
static int get_driver_count();
static AudioDriver *get_driver(int p_driver);
};