mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-09-01 12:49:18 +02:00
audio: guard ALC_SOFT_system_events behind #ifdef for OpenAL < 1.24
This commit is contained in:
@@ -272,7 +272,9 @@ openal_source::clear() {
|
|||||||
|
|
||||||
openal_renderer::~openal_renderer() {
|
openal_renderer::~openal_renderer() {
|
||||||
|
|
||||||
|
#ifdef ALC_SOFT_system_events
|
||||||
if( m_alcEventCallbackSOFT != nullptr ) { m_alcEventCallbackSOFT( nullptr, nullptr ); } // stop callbacks before teardown
|
if( m_alcEventCallbackSOFT != nullptr ) { m_alcEventCallbackSOFT( nullptr, nullptr ); } // stop callbacks before teardown
|
||||||
|
#endif
|
||||||
|
|
||||||
::alcMakeContextCurrent( nullptr );
|
::alcMakeContextCurrent( nullptr );
|
||||||
|
|
||||||
@@ -280,6 +282,7 @@ openal_renderer::~openal_renderer() {
|
|||||||
if( m_device != nullptr ) { ::alcCloseDevice( m_device ); }
|
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,
|
// 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()
|
// the actual reopen is done on the main thread in update()
|
||||||
void ALC_APIENTRY
|
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; }
|
&& eventtype != ALC_EVENT_TYPE_DEVICE_REMOVED_SOFT ) { return; }
|
||||||
static_cast<openal_renderer*>( userparam )->m_outputchanged.store( true );
|
static_cast<openal_renderer*>( userparam )->m_outputchanged.store( true );
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
audio::buffer_handle
|
audio::buffer_handle
|
||||||
openal_renderer::fetch_buffer( std::string const &Filename ) {
|
openal_renderer::fetch_buffer( std::string const &Filename ) {
|
||||||
@@ -642,6 +646,7 @@ openal_renderer::init_caps() {
|
|||||||
if( !m_alcReopenDeviceSOFT )
|
if( !m_alcReopenDeviceSOFT )
|
||||||
WriteLog( "sound: warning: extension ALC_SOFT_reopen_device not found; audio output device changes won't be followed" );
|
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
|
// 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
|
// catches both device removal and default-output changes, incl. re-plugging headphones
|
||||||
if( m_alcReopenDeviceSOFT != nullptr
|
if( m_alcReopenDeviceSOFT != nullptr
|
||||||
@@ -656,6 +661,7 @@ openal_renderer::init_caps() {
|
|||||||
WriteLog( "sound: following audio output device changes via ALC_SOFT_system_events" );
|
WriteLog( "sound: following audio output device changes via ALC_SOFT_system_events" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,14 +152,17 @@ private:
|
|||||||
ALCint m_contextattributes[3] { 0, 0, 0 };
|
ALCint m_contextattributes[3] { 0, 0, 0 };
|
||||||
double m_devicechecktime { 0.0 };
|
double m_devicechecktime { 0.0 };
|
||||||
|
|
||||||
|
bool m_usedeviceevents { false };
|
||||||
|
std::atomic<bool> 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.
|
// 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
|
// 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.
|
// (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 };
|
LPALCEVENTCONTROLSOFT m_alcEventControlSOFT { nullptr };
|
||||||
LPALCEVENTCALLBACKSOFT m_alcEventCallbackSOFT { nullptr };
|
LPALCEVENTCALLBACKSOFT m_alcEventCallbackSOFT { nullptr };
|
||||||
bool m_usedeviceevents { false };
|
|
||||||
std::atomic<bool> 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;
|
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;
|
extern openal_renderer renderer;
|
||||||
|
|||||||
Reference in New Issue
Block a user