Commit 1702e77a authored by David Fuhrmann's avatar David Fuhrmann

auhal: use audio device latency for better a/v synchronization and airplay support

refs #7127
parent 591efc80
...@@ -117,6 +117,8 @@ struct aout_sys_t ...@@ -117,6 +117,8 @@ struct aout_sys_t
vlc_cond_t cond; vlc_cond_t cond;
bool b_ignore_streams_changed_callback; bool b_ignore_streams_changed_callback;
UInt32 i_device_latency; /* The time the device needs to process the data. In samples. */
}; };
#pragma mark - #pragma mark -
...@@ -314,6 +316,7 @@ static int Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt) ...@@ -314,6 +316,7 @@ static int Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt)
p_sys->b_changed_mixing = false; p_sys->b_changed_mixing = false;
p_sys->i_bytes_per_sample = 0; p_sys->i_bytes_per_sample = 0;
p_sys->b_paused = false; p_sys->b_paused = false;
p_sys->i_device_latency = 0;
vlc_mutex_lock(&p_sys->var_lock); vlc_mutex_lock(&p_sys->var_lock);
p_sys->i_selected_dev = p_sys->i_new_selected_dev; p_sys->i_selected_dev = p_sys->i_new_selected_dev;
...@@ -409,6 +412,22 @@ static int Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt) ...@@ -409,6 +412,22 @@ static int Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt)
goto error; goto error;
} }
/* get device latency */
AudioObjectPropertyAddress latencyAddress = { kAudioDevicePropertyLatency, kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementMaster };
i_param_size = sizeof(p_sys->i_device_latency);
err = AudioObjectGetPropertyData(p_sys->i_selected_dev,
&latencyAddress,
0,
NULL,
&i_param_size,
&p_sys->i_device_latency);
if (err != noErr) {
msg_Warn(p_aout, "Cannot get device latency [%4.4s]",
(char *)&err);
}
msg_Dbg(p_aout, "Current device has a latency of %u frames", p_sys->i_device_latency);
bool b_success = false; bool b_success = false;
/* Check for Digital mode or Analog output mode */ /* Check for Digital mode or Analog output mode */
...@@ -1424,7 +1443,7 @@ static int TimeGet(audio_output_t *p_aout, mtime_t *delay) ...@@ -1424,7 +1443,7 @@ static int TimeGet(audio_output_t *p_aout, mtime_t *delay)
int32_t availableBytes; int32_t availableBytes;
TPCircularBufferTail(&p_sys->circular_buffer, &availableBytes); TPCircularBufferTail(&p_sys->circular_buffer, &availableBytes);
*delay = (availableBytes / p_sys->i_bytes_per_sample) * CLOCK_FREQ / p_sys->i_rate; *delay = ((availableBytes / p_sys->i_bytes_per_sample) + p_sys->i_device_latency) * CLOCK_FREQ / p_sys->i_rate;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment