mirror of https://github.com/mpv-player/mpv
ao_coreaudio: handle latency change on hotplug
The device latency may change during hotplugging. This commit updates p->hw_latency_ns each time hotplug_cb is called so that it can reflect updated device latency.
This commit is contained in:
parent
1ed8607292
commit
276bbb8884
|
@ -137,6 +137,7 @@ static int control(struct ao *ao, enum aocontrol cmd, void *arg)
|
|||
|
||||
static bool init_audiounit(struct ao *ao, AudioStreamBasicDescription asbd);
|
||||
static void init_physical_format(struct ao *ao);
|
||||
static void reinit_latency(struct ao *ao);
|
||||
|
||||
static bool reinit_device(struct ao *ao) {
|
||||
struct priv *p = ao->priv;
|
||||
|
@ -175,6 +176,8 @@ static int init(struct ao *ao)
|
|||
if (!init_audiounit(ao, asbd))
|
||||
goto coreaudio_error;
|
||||
|
||||
reinit_latency(ao);
|
||||
|
||||
p->queue = dispatch_queue_create("io.mpv.coreaudio_stop_during_idle",
|
||||
DISPATCH_QUEUE_SERIAL);
|
||||
|
||||
|
@ -307,8 +310,6 @@ static bool init_audiounit(struct ao *ao, AudioStreamBasicDescription asbd)
|
|||
CHECK_CA_ERROR_L(coreaudio_error_audiounit,
|
||||
"can't link audio unit to selected device");
|
||||
|
||||
p->hw_latency_ns = ca_get_hardware_latency(ao);
|
||||
|
||||
AURenderCallbackStruct render_cb = (AURenderCallbackStruct) {
|
||||
.inputProc = render_cb_lpcm,
|
||||
.inputProcRefCon = ao,
|
||||
|
@ -332,6 +333,13 @@ coreaudio_error:
|
|||
return false;
|
||||
}
|
||||
|
||||
static void reinit_latency(struct ao *ao)
|
||||
{
|
||||
struct priv *p = ao->priv;
|
||||
|
||||
p->hw_latency_ns = ca_get_hardware_latency(ao);
|
||||
}
|
||||
|
||||
static void stop(struct ao *ao)
|
||||
{
|
||||
struct priv *p = ao->priv;
|
||||
|
@ -432,8 +440,11 @@ static OSStatus hotplug_cb(AudioObjectID id, UInt32 naddr,
|
|||
void *ctx)
|
||||
{
|
||||
struct ao *ao = ctx;
|
||||
struct priv *p = ao->priv;
|
||||
MP_VERBOSE(ao, "Handling potential hotplug event...\n");
|
||||
reinit_device(ao);
|
||||
if (p->audio_unit)
|
||||
reinit_latency(ao);
|
||||
ao_hotplug_event(ao);
|
||||
return noErr;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue