[Scummvm-git-logs] scummvm master -> cc64a58b68f65aec2cb6f6ff846ab2b8d40a47fe
sev-
noreply at scummvm.org
Tue Nov 7 01:45:53 UTC 2023
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
bd857272f4 BACKENDS: SDL: Use null mixer if audio initialization fails, and add a flag to forcibly disable it for testing. Add an
cc64a58b68 BASE: Don't expose disable-sdl-audio or disable-sdl-parachute options when not using SDL
Commit: bd857272f4c35907328fceabc07f02ba949dc383
https://github.com/scummvm/scummvm/commit/bd857272f4c35907328fceabc07f02ba949dc383
Author: elasota (ejlasota at gmail.com)
Date: 2023-11-07T02:45:49+01:00
Commit Message:
BACKENDS: SDL: Use null mixer if audio initialization fails, and add a flag to forcibly disable it for testing. Add an alternate call that returns true if the mixer manager is a null device.
SDL audio init will fail on Windows if all audio output devices are disabled.
Only about 10 engines are checking for this case and numerous pieces of common code (EmulatedOPL, VideoDecoder) fail as well, so this acts as a fallback to prevent instability.
Changed paths:
backends/mixer/mixer.h
backends/mixer/null/null-mixer.cpp
backends/mixer/null/null-mixer.h
backends/mixer/sdl/sdl-mixer.cpp
backends/mixer/sdl/sdl-mixer.h
backends/module.mk
backends/platform/sdl/sdl.cpp
base/commandLine.cpp
diff --git a/backends/mixer/mixer.h b/backends/mixer/mixer.h
index 93d3532363c..c435e0d93f2 100644
--- a/backends/mixer/mixer.h
+++ b/backends/mixer/mixer.h
@@ -55,6 +55,11 @@ public:
*/
virtual int resumeAudio() = 0;
+ /**
+ * Returns true if this is a null device and won't output any audio.
+ */
+ virtual bool isNullDevice() const { return false; }
+
protected:
/** The mixer implementation */
Audio::MixerImpl *_mixer;
diff --git a/backends/mixer/null/null-mixer.cpp b/backends/mixer/null/null-mixer.cpp
index e7f3f79455a..451ca3ead66 100644
--- a/backends/mixer/null/null-mixer.cpp
+++ b/backends/mixer/null/null-mixer.cpp
@@ -53,6 +53,10 @@ int NullMixerManager::resumeAudio() {
return 0;
}
+bool NullMixerManager::isNullDevice() const {
+ return true;
+}
+
void NullMixerManager::update(uint8 callbackPeriod) {
if (_audioSuspended) {
return;
diff --git a/backends/mixer/null/null-mixer.h b/backends/mixer/null/null-mixer.h
index 90e7799019a..6495e19a172 100644
--- a/backends/mixer/null/null-mixer.h
+++ b/backends/mixer/null/null-mixer.h
@@ -38,11 +38,13 @@ public:
NullMixerManager();
virtual ~NullMixerManager();
- virtual void init();
+ void init();
void update(uint8 callbackPeriod = 10);
- virtual void suspendAudio();
- virtual int resumeAudio();
+ void suspendAudio() override;
+ int resumeAudio() override;
+
+ bool isNullDevice() const override;
private:
uint32 _outputRate;
diff --git a/backends/mixer/sdl/sdl-mixer.cpp b/backends/mixer/sdl/sdl-mixer.cpp
index e7d773e6ad3..e902785a20d 100644
--- a/backends/mixer/sdl/sdl-mixer.cpp
+++ b/backends/mixer/sdl/sdl-mixer.cpp
@@ -39,20 +39,39 @@
#define SAMPLES_PER_SEC 44100
#endif
+SdlMixerManager::SdlMixerManager() : _isSubsystemInitialized(false), _isAudioOpen(false) {
+}
+
SdlMixerManager::~SdlMixerManager() {
- _mixer->setReady(false);
+ if (_mixer)
+ _mixer->setReady(false);
- SDL_CloseAudio();
+ if (_isAudioOpen)
+ SDL_CloseAudio();
- SDL_QuitSubSystem(SDL_INIT_AUDIO);
+ if (_isSubsystemInitialized)
+ SDL_QuitSubSystem(SDL_INIT_AUDIO);
}
void SdlMixerManager::init() {
+ bool isDisabled = ConfMan.hasKey("disable_sdl_audio") && ConfMan.getBool("disable_sdl_audio");
+
+ if (isDisabled) {
+ warning("SDL audio subsystem was forcibly disabled by disable_sdl_audio option");
+ return;
+ }
+
+ // Get the desired audio specs
+ SDL_AudioSpec desired = getAudioSpec(SAMPLES_PER_SEC);
+
// Start SDL Audio subsystem
if (SDL_InitSubSystem(SDL_INIT_AUDIO) == -1) {
- error("Could not initialize SDL: %s", SDL_GetError());
+ warning("Could not initialize SDL audio subsystem: %s", SDL_GetError());
+ return;
}
+ _isSubsystemInitialized = true;
+
#if SDL_VERSION_ATLEAST(2, 0, 0)
const char *sdlDriverName = SDL_GetCurrentAudioDriver();
#else
@@ -63,9 +82,6 @@ void SdlMixerManager::init() {
#endif
debug(1, "Using SDL Audio Driver \"%s\"", sdlDriverName);
- // Get the desired audio specs
- SDL_AudioSpec desired = getAudioSpec(SAMPLES_PER_SEC);
-
// Needed as SDL_OpenAudio as of SDL-1.2.14 mutates fields in
// "desired" if used directly.
SDL_AudioSpec fmt = desired;
@@ -73,12 +89,11 @@ void SdlMixerManager::init() {
// Start SDL audio with the desired specs
if (SDL_OpenAudio(&fmt, &_obtained) != 0) {
warning("Could not open audio device: %s", SDL_GetError());
-
- // The mixer is not marked as ready
- _mixer = new Audio::MixerImpl(desired.freq, desired.channels >= 2, desired.samples);
return;
}
+ _isAudioOpen = true;
+
// The obtained sample format is not supported by the mixer, call
// SDL_OpenAudio again with NULL as the second argument to force
// SDL to do resampling to the desired audio spec.
@@ -88,9 +103,6 @@ void SdlMixerManager::init() {
if (SDL_OpenAudio(&fmt, nullptr) != 0) {
warning("Could not open audio device: %s", SDL_GetError());
-
- // The mixer is not marked as ready
- _mixer = new Audio::MixerImpl(desired.freq, desired.channels >= 2, desired.samples);
return;
}
diff --git a/backends/mixer/sdl/sdl-mixer.h b/backends/mixer/sdl/sdl-mixer.h
index 3d4f98a98e8..b9b7f74df79 100644
--- a/backends/mixer/sdl/sdl-mixer.h
+++ b/backends/mixer/sdl/sdl-mixer.h
@@ -33,6 +33,7 @@
*/
class SdlMixerManager : public MixerManager {
public:
+ SdlMixerManager();
virtual ~SdlMixerManager();
/**
@@ -79,6 +80,9 @@ protected:
* by subclasses, so it invokes the non-static function callbackHandler()
*/
static void sdlCallback(void *this_, byte *samples, int len);
+
+ bool _isSubsystemInitialized;
+ bool _isAudioOpen;
};
#endif
diff --git a/backends/module.mk b/backends/module.mk
index 6b2367e4a66..d8bfa2d6eeb 100644
--- a/backends/module.mk
+++ b/backends/module.mk
@@ -190,6 +190,7 @@ MODULE_OBJS += \
graphics/sdl/sdl-graphics.o \
graphics/surfacesdl/surfacesdl-graphics.o \
mixer/sdl/sdl-mixer.o \
+ mixer/null/null-mixer.o \
mutex/sdl/sdl-mutex.o \
timer/sdl/sdl-timer.o
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 528359afb6a..8cd8bba06d2 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -41,6 +41,7 @@
#include "backends/audiocd/sdl/sdl-audiocd.h"
#endif
+#include "backends/mixer/null/null-mixer.h"
#include "backends/events/default/default-events.h"
#include "backends/events/sdl/legacy-sdl-events.h"
#include "backends/keymapper/hardware-input.h"
@@ -303,6 +304,13 @@ void OSystem_SDL::initBackend() {
_mixerManager = new SdlMixerManager();
// Setup and start mixer
_mixerManager->init();
+
+ if (_mixerManager->getMixer() == nullptr) {
+ // Audio was unavailable or disabled
+ delete _mixerManager;
+ _mixerManager = new NullMixerManager();
+ _mixerManager->init();
+ }
}
#ifdef ENABLE_EVENTRECORDER
diff --git a/base/commandLine.cpp b/base/commandLine.cpp
index d916b996416..fccdae24855 100644
--- a/base/commandLine.cpp
+++ b/base/commandLine.cpp
@@ -364,6 +364,7 @@ void registerDefaults() {
ConfMan.registerDefault("joystick_num", 0);
ConfMan.registerDefault("confirm_exit", false);
ConfMan.registerDefault("disable_sdl_parachute", false);
+ ConfMan.registerDefault("disable_sdl_audio", false);
ConfMan.registerDefault("disable_display", false);
ConfMan.registerDefault("record_mode", "none");
@@ -822,6 +823,9 @@ Common::String parseCommandLine(Common::StringMap &settings, int argc, const cha
DO_LONG_OPTION_BOOL("disable-sdl-parachute")
END_OPTION
+ DO_LONG_OPTION_BOOL("disable-sdl-audio")
+ END_OPTION
+
DO_LONG_OPTION_BOOL("multi-midi")
END_OPTION
Commit: cc64a58b68f65aec2cb6f6ff846ab2b8d40a47fe
https://github.com/scummvm/scummvm/commit/cc64a58b68f65aec2cb6f6ff846ab2b8d40a47fe
Author: elasota (ejlasota at gmail.com)
Date: 2023-11-07T02:45:49+01:00
Commit Message:
BASE: Don't expose disable-sdl-audio or disable-sdl-parachute options when not using SDL
Changed paths:
base/commandLine.cpp
diff --git a/base/commandLine.cpp b/base/commandLine.cpp
index fccdae24855..b7dec250951 100644
--- a/base/commandLine.cpp
+++ b/base/commandLine.cpp
@@ -820,11 +820,13 @@ Common::String parseCommandLine(Common::StringMap &settings, int argc, const cha
}
END_OPTION
+#ifdef SDL_BACKEND
DO_LONG_OPTION_BOOL("disable-sdl-parachute")
END_OPTION
DO_LONG_OPTION_BOOL("disable-sdl-audio")
END_OPTION
+#endif
DO_LONG_OPTION_BOOL("multi-midi")
END_OPTION
More information about the Scummvm-git-logs
mailing list