1
mirror of https://github.com/mpv-player/mpv synced 2024-11-18 21:16:10 +01:00

ao_coreaudio: extract methods to lock/unlock device for digital output

This commit is contained in:
Stefano Pigozzi 2013-06-25 08:24:14 +02:00
parent e3ce0f0f8e
commit 40f6e2e041
2 changed files with 26 additions and 28 deletions

View File

@ -431,16 +431,8 @@ static int init_digital(struct ao *ao, AudioStreamBasicDescription asbd)
p->b_digital = 1;
d->i_hog_pid = getpid();
err = SetAudioProperty(p->i_selected_dev,
kAudioDevicePropertyHogMode,
sizeof(d->i_hog_pid), &d->i_hog_pid);
if (! CHECK_CA_WARN("faild to set hogmode")) {
d->i_hog_pid = -1;
goto coreaudio_error;
}
err = ca_lock_device(p->i_selected_dev, &d->i_hog_pid);
CHECK_CA_ERROR("faild to set hogmode");
p_addr = (AudioObjectPropertyAddress) {
.mSelector = kAudioDevicePropertySupportsMixing,
@ -586,15 +578,8 @@ static int init_digital(struct ao *ao, AudioStreamBasicDescription asbd)
return CONTROL_TRUE;
coreaudio_error:
if (d->i_hog_pid == getpid()) {
d->i_hog_pid = -1;
err = SetAudioProperty(p->i_selected_dev,
kAudioDevicePropertyHogMode,
sizeof(d->i_hog_pid), &d->i_hog_pid);
if (err != noErr)
ca_msg(MSGL_WARN, "Could not release hogmode: [%4.4s]\n",
(char *)&err);
}
err = ca_unlock_device(p->i_selected_dev, &d->i_hog_pid);
CHECK_CA_WARN("can't release hog mode");
return CONTROL_FALSE;
}
@ -793,15 +778,9 @@ static void uninit(struct ao *ao, bool immed)
ca_msg(MSGL_WARN, "failed to set mixmode: [%4.4s]\n",
(char *)&err);
}
if (d->i_hog_pid == getpid()) {
d->i_hog_pid = -1;
err = SetAudioProperty(p->i_selected_dev,
kAudioDevicePropertyHogMode,
sizeof(d->i_hog_pid), &d->i_hog_pid);
if (err != noErr)
ca_msg(MSGL_WARN,
"Could not release hogmode: [%4.4s]\n", (char *)&err);
}
err = ca_unlock_device(p->i_selected_dev, &d->i_hog_pid);
CHECK_CA_WARN("can't release hog mode");
}
}

View File

@ -310,3 +310,22 @@ static OSStatus ca_device_listener(AudioObjectID object, uint32_t n_addresses,
return ca_property_listener(kAudioDevicePropertyDeviceHasChanged,
object, n_addresses, addresses, data);
}
static OSStatus ca_lock_device(AudioDeviceID device, pid_t *pid) {
*pid = getpid();
OSStatus err = SetAudioProperty(device, kAudioDevicePropertyHogMode,
sizeof(*pid), pid);
if (err != noErr)
*pid = -1;
return err;
}
static OSStatus ca_unlock_device(AudioDeviceID device, pid_t *pid) {
if (*pid == getpid()) {
*pid = -1;
return SetAudioProperty(device, kAudioDevicePropertyHogMode,
sizeof(*pid), &pid);
}
return noErr;
}