mirror of
https://github.com/mpv-player/mpv
synced 2024-12-30 11:02:10 +00:00
ao_coreaudio: remove device property listener on uninit
Also extract this functionality inside a function in coreaudio_common
This commit is contained in:
parent
7b2b292343
commit
a2d106cb31
@ -430,7 +430,6 @@ static int init_digital(struct ao *ao, AudioStreamBasicDescription asbd)
|
||||
struct priv *p = ao->priv;
|
||||
struct priv_d *d = p->digital;
|
||||
OSStatus err = noErr;
|
||||
AudioObjectPropertyAddress p_addr;
|
||||
uint32_t size;
|
||||
|
||||
uint32_t is_alive = 1;
|
||||
@ -524,17 +523,8 @@ static int init_digital(struct ao *ao, AudioStreamBasicDescription asbd)
|
||||
if (!AudioStreamChangeFormat(d->stream, d->stream_asbd))
|
||||
goto coreaudio_error;
|
||||
|
||||
p_addr = (AudioObjectPropertyAddress) {
|
||||
.mSelector = kAudioDevicePropertyDeviceHasChanged,
|
||||
.mScope = kAudioObjectPropertyScopeGlobal,
|
||||
.mElement = kAudioObjectPropertyElementMaster,
|
||||
};
|
||||
|
||||
const int *stream_asdb_changed = &(d->stream_asbd_changed);
|
||||
err = AudioObjectAddPropertyListener(p->device,
|
||||
&p_addr,
|
||||
ca_device_listener,
|
||||
(void *)stream_asdb_changed);
|
||||
void *changed = (void *) &(d->stream_asbd_changed);
|
||||
err = ca_enable_device_listener(p->device, changed);
|
||||
CHECK_CA_ERROR("cannot install format change listener during init");
|
||||
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
@ -634,6 +624,10 @@ static void uninit(struct ao *ao, bool immed)
|
||||
} else {
|
||||
struct priv_d *d = p->digital;
|
||||
|
||||
void *changed = (void *) &(d->stream_asbd_changed);
|
||||
err = ca_disable_device_listener(p->device, changed);
|
||||
CHECK_CA_WARN("can't remove device listener, this may cause a crash");
|
||||
|
||||
err = AudioDeviceStop(p->device, d->render_cb);
|
||||
CHECK_CA_WARN("failed to stop audio device");
|
||||
|
||||
|
@ -380,6 +380,32 @@ static OSStatus ca_enable_mixing(AudioDeviceID device, bool changed) {
|
||||
return noErr;
|
||||
}
|
||||
|
||||
static OSStatus ca_change_device_listening(AudioDeviceID device,
|
||||
void *flag, bool enabled)
|
||||
{
|
||||
AudioObjectPropertyAddress p_addr = (AudioObjectPropertyAddress) {
|
||||
.mSelector = kAudioDevicePropertyDeviceHasChanged,
|
||||
.mScope = kAudioObjectPropertyScopeGlobal,
|
||||
.mElement = kAudioObjectPropertyElementMaster,
|
||||
};
|
||||
|
||||
if (enabled) {
|
||||
return AudioObjectAddPropertyListener(
|
||||
device, &p_addr, ca_device_listener, flag);
|
||||
} else {
|
||||
return AudioObjectRemovePropertyListener(
|
||||
device, &p_addr, ca_device_listener, flag);
|
||||
}
|
||||
}
|
||||
|
||||
static OSStatus ca_enable_device_listener(AudioDeviceID device, void *flag) {
|
||||
return ca_change_device_listening(device, flag, true);
|
||||
}
|
||||
|
||||
static OSStatus ca_disable_device_listener(AudioDeviceID device, void *flag) {
|
||||
return ca_change_device_listening(device, flag, false);
|
||||
}
|
||||
|
||||
static int AudioStreamChangeFormat(AudioStreamID i_stream_id,
|
||||
AudioStreamBasicDescription change_format)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user