Skip to content

Commit

Permalink
coreaudio: fix timing instability
Browse files Browse the repository at this point in the history
Only report the timing when all the data has been processed. Indeed, the
timing includes the length of the buffer to write. Reporting the timing
in the middle could cause a difference of [0; IOBufferDuration] (between
0 and 23ms generally).
  • Loading branch information
tguillem committed Jan 2, 2023
1 parent 7eaa685 commit 31ac778
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions modules/audio_output/coreaudio_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ ca_Render(audio_output_t *p_aout, uint64_t host_time,
}
}

size_t bytes_copied = 0;
while (bytes > 0)
{
vlc_frame_t *f = p_sys->p_out_chain;
Expand All @@ -228,17 +229,6 @@ ca_Render(audio_output_t *p_aout, uint64_t host_time,
p_sys->i_out_size -= tocopy;
p_sys->i_total_bytes += tocopy;

if (!p_sys->started
|| (p_sys->timing_report_last_written_bytes >=
p_sys->timing_report_delay_bytes))
{
p_sys->timing_report_last_written_bytes = 0;
vlc_tick_t pos_ticks = BytesToTicks(p_sys, p_sys->i_total_bytes);
aout_TimingReport(p_aout, end_ticks + GetLatency(p_aout), pos_ticks);
}
else
p_sys->timing_report_last_written_bytes += tocopy;

p_sys->started = true;

memcpy(data, f->p_buffer, tocopy);
Expand All @@ -247,6 +237,7 @@ ca_Render(audio_output_t *p_aout, uint64_t host_time,
bytes -= tocopy;
f->i_buffer -= tocopy;
f->p_buffer += tocopy;
bytes_copied += tocopy;

if (f->i_buffer == 0)
{
Expand All @@ -258,6 +249,16 @@ ca_Render(audio_output_t *p_aout, uint64_t host_time,
}
}

if (p_sys->timing_report_last_written_bytes >=
p_sys->timing_report_delay_bytes)
{
p_sys->timing_report_last_written_bytes = 0;
vlc_tick_t pos_ticks = BytesToTicks(p_sys, p_sys->i_total_bytes);
aout_TimingReport(p_aout, end_ticks + GetLatency(p_aout), pos_ticks);
}
else
p_sys->timing_report_last_written_bytes += bytes_copied;

lock_unlock(p_sys);
}

Expand Down

0 comments on commit 31ac778

Please sign in to comment.