ao: proper end_time calulation & ao_read_frame() #14058
Draft
+153
−71
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes the calculation of
ao->buffer_state->end_time_ns
whenpad_silence == false
and partial data is returned for pull-based AO. Previously,end_time_ns
was calculated by driver delay plus the duration of requested sample count. It was not accurate ifpad_silence == false
giving the number of returned samples can vary. To fix this issue, this PR introduces an API change thatao_read_data()
andao_read_data_converted()
now acceptsstart_time_ns
, which is the the expected delay until the first sample reaches the speakers, instead ofout_time_ns
.ao_read_data()
then updatesao->buffer_state->end_time_ns
usingstart_time_ns
and the actual sample count got from the buffer.This PR also introduces a new API
ao_read_frame()
for pull-based AO. Now pull-based AO can directly getmp_aframe
. For AO that can handle data with variable size, this new API bypass the copying of audio data from audio frames into data buffer inread_buffer()
. A zero-copyao_avfoundation
that utilizesao_read_frame()
is included in this PR.This PR depends on #13967. Before it is merged, I think I'd better keep this PR a draft, though my work is done already.