Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ao: proper end_time calulation & ao_read_frame() #14058

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

ruihe774
Copy link
Contributor

@ruihe774 ruihe774 commented May 4, 2024

This PR fixes the calculation of ao->buffer_state->end_time_ns when pad_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 if pad_silence == false giving the number of returned samples can vary. To fix this issue, this PR introduces an API change that ao_read_data() and ao_read_data_converted() now accepts start_time_ns, which is the the expected delay until the first sample reaches the speakers, instead of out_time_ns. ao_read_data() then updates ao->buffer_state->end_time_ns using start_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 get mp_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 in read_buffer(). A zero-copy ao_avfoundation that utilizes ao_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.

so that people can freely pass eof = NULL to read_buffer()
related functions.
The returned samples count can vary.
Use a pre-calculated end_time_ns is inaccurate.
This commit make ao_read_data() accept start_time_ns and calculate end_time_ns with:

end_time_ns = start_time_ns + MP_TIME_S_TO_NS(pad_silence ? samples : pos) / ao->samplerate
Copy link

github-actions bot commented May 4, 2024

Download the artifacts for this pull request:

Windows
macOS

to allow pull-based AO to directly get audio frames.
This also allows zero-copy AO.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant