diff --git a/audio/audiorenderer.cpp b/audio/audiorenderer.cpp index 81f81570..cc87ed48 100644 --- a/audio/audiorenderer.cpp +++ b/audio/audiorenderer.cpp @@ -272,7 +272,9 @@ openal_source::clear() { openal_renderer::~openal_renderer() { +#ifdef ALC_SOFT_system_events if( m_alcEventCallbackSOFT != nullptr ) { m_alcEventCallbackSOFT( nullptr, nullptr ); } // stop callbacks before teardown +#endif ::alcMakeContextCurrent( nullptr ); @@ -280,6 +282,7 @@ openal_renderer::~openal_renderer() { if( m_device != nullptr ) { ::alcCloseDevice( m_device ); } } +#ifdef ALC_SOFT_system_events // invoked by OpenAL (possibly on an internal thread) on device events; only flags the change, // the actual reopen is done on the main thread in update() void ALC_APIENTRY @@ -291,6 +294,7 @@ openal_renderer::device_event_callback( ALCenum eventtype, ALCenum devicetype, A && eventtype != ALC_EVENT_TYPE_DEVICE_REMOVED_SOFT ) { return; } static_cast( userparam )->m_outputchanged.store( true ); } +#endif audio::buffer_handle openal_renderer::fetch_buffer( std::string const &Filename ) { @@ -642,6 +646,7 @@ openal_renderer::init_caps() { if( !m_alcReopenDeviceSOFT ) WriteLog( "sound: warning: extension ALC_SOFT_reopen_device not found; audio output device changes won't be followed" ); +#ifdef ALC_SOFT_system_events // prefer event-driven output following (ALC_SOFT_system_events) over polling: it reliably // catches both device removal and default-output changes, incl. re-plugging headphones if( m_alcReopenDeviceSOFT != nullptr @@ -656,6 +661,7 @@ openal_renderer::init_caps() { WriteLog( "sound: following audio output device changes via ALC_SOFT_system_events" ); } } +#endif return true; } diff --git a/audio/audiorenderer.h b/audio/audiorenderer.h index ec26ec82..81cc3a2b 100644 --- a/audio/audiorenderer.h +++ b/audio/audiorenderer.h @@ -152,14 +152,17 @@ private: ALCint m_contextattributes[3] { 0, 0, 0 }; double m_devicechecktime { 0.0 }; + bool m_usedeviceevents { false }; + std::atomic m_outputchanged { false }; // set from the (possibly off-thread) event callback +#ifdef ALC_SOFT_system_events // ALC_SOFT_system_events: event-driven following of output-device / default-output changes. // Preferred over polling because it reliably catches both device removal and default changes // (e.g. re-plugging headphones), which alcGetString(DEFAULT_ALL_DEVICES) does not report live. + // Requires OpenAL Soft >= 1.24; on older headers this is compiled out and we poll instead. LPALCEVENTCONTROLSOFT m_alcEventControlSOFT { nullptr }; LPALCEVENTCALLBACKSOFT m_alcEventCallbackSOFT { nullptr }; - bool m_usedeviceevents { false }; - std::atomic m_outputchanged { false }; // set from the (possibly off-thread) event callback static void ALC_APIENTRY device_event_callback( ALCenum eventtype, ALCenum devicetype, ALCdevice *device, ALCsizei length, ALCchar const *message, void *userparam ) noexcept; +#endif }; extern openal_renderer renderer;