diff options
author | wm4 <wm4@nowhere> | 2013-11-12 22:27:44 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-11-12 23:39:09 +0100 |
commit | 22b3f522cacfbdba76d311c86efd6091512eb089 (patch) | |
tree | 1105af44a9403bde554cd4b6041d05ceea4fb39a /mpvcore | |
parent | 5388a0cd4062ba24f5382f025552422fb6430906 (diff) | |
download | mpv-22b3f522cacfbdba76d311c86efd6091512eb089.tar.bz2 mpv-22b3f522cacfbdba76d311c86efd6091512eb089.tar.xz |
audio: add support for using non-interleaved audio from decoders directly
Most libavcodec decoders output non-interleaved audio. Add direct
support for this, and remove the hack that repacked non-interleaved
audio back to packed audio.
Remove the minlen argument from the decoder callback. Instead of
forcing every decoder to have its own decode loop to fill the buffer
until minlen is reached, leave this to the caller. So if a decoder
doesn't return enough data, it's simply called again. (In future, I
even want to change it so that decoders don't read packets directly,
but instead the caller has to pass packets to the decoders. This fits
well with this change, because now the decoder callback typically
decodes at most one packet.)
ad_mpg123.c receives some heavy refactoring. The main problem is that
it wanted to handle format changes when there was no data in the decode
output buffer yet. This sounds reasonable, but actually it would write
data into a buffer prepared for old data, since the caller doesn't know
about the format change yet. (I.e. the best place for a format change
would be _after_ writing the last sample to the output buffer.) It's
possible that this code was not perfectly sane before this commit,
and perhaps lost one frame of data after a format change, but I didn't
confirm this. Trying to fix this, I ended up rewriting the decoding
and also the probing.
Diffstat (limited to 'mpvcore')
-rw-r--r-- | mpvcore/player/audio.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/mpvcore/player/audio.c b/mpvcore/player/audio.c index 9bad5140ef..a13e8d9c07 100644 --- a/mpvcore/player/audio.c +++ b/mpvcore/player/audio.c @@ -180,12 +180,9 @@ no_audio: double written_audio_pts(struct MPContext *mpctx) { sh_audio_t *sh_audio = mpctx->sh_audio; - if (!sh_audio) + if (!sh_audio || !sh_audio->initialized) return MP_NOPTS_VALUE; - double bps = sh_audio->channels.num * sh_audio->samplerate * - (af_fmt2bits(sh_audio->sample_format) / 8); - // first calculate the end pts of audio that has been output by decoder double a_pts = sh_audio->pts; if (a_pts == MP_NOPTS_VALUE) @@ -194,13 +191,13 @@ double written_audio_pts(struct MPContext *mpctx) // sh_audio->pts is the timestamp of the latest input packet with // known pts that the decoder has decoded. sh_audio->pts_bytes is // the amount of bytes the decoder has written after that timestamp. - a_pts += sh_audio->pts_bytes / bps; + a_pts += sh_audio->pts_offset / (double)sh_audio->samplerate; // Now a_pts hopefully holds the pts for end of audio from decoder. // Subtract data in buffers between decoder and audio out. // Decoded but not filtered - a_pts -= sh_audio->a_buffer_len / bps; + a_pts -= mp_audio_buffer_seconds(sh_audio->decode_buffer); // Data buffered in audio filters, measured in seconds of "missing" output double buffered_output = af_calc_delay(sh_audio->afilter); @@ -446,6 +443,6 @@ void clear_audio_output_buffers(struct MPContext *mpctx) // Drop decoded data queued for filtering. void clear_audio_decode_buffers(struct MPContext *mpctx) { - if (mpctx->sh_audio) - mpctx->sh_audio->a_buffer_len = 0; + if (mpctx->sh_audio && mpctx->sh_audio->decode_buffer) + mp_audio_buffer_clear(mpctx->sh_audio->decode_buffer); } |