From 22b3f522cacfbdba76d311c86efd6091512eb089 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 12 Nov 2013 22:27:44 +0100 Subject: 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. --- demux/demux.c | 1 - demux/stheader.h | 9 +++------ 2 files changed, 3 insertions(+), 7 deletions(-) (limited to 'demux') diff --git a/demux/demux.c b/demux/demux.c index b5934824dc..ded0dd895e 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -259,7 +259,6 @@ struct sh_stream *new_sh_stream(demuxer_t *demuxer, enum stream_type type) struct sh_audio *sht = talloc_zero(demuxer, struct sh_audio); sht->gsh = sh; sht->opts = sh->opts; - sht->sample_format = AF_FORMAT_S16_NE; sh->audio = sht; break; } diff --git a/demux/stheader.h b/demux/stheader.h index 5aa77ba693..c88ed0b0f7 100644 --- a/demux/stheader.h +++ b/demux/stheader.h @@ -92,11 +92,8 @@ typedef struct sh_audio { int samplerate; struct mp_chmap channels; int i_bps; // == bitrate (compressed bytes/sec) - // decoder buffers: - int audio_out_minsize; // minimal output from decoder may be this much - char *a_buffer; // buffer for decoder output - int a_buffer_len; - int a_buffer_size; + // decoder state: + struct mp_audio_buffer *decode_buffer; struct af_stream *afilter; // the audio filter stream const struct ad_functions *ad_driver; // win32-compatible codec parameters: @@ -104,7 +101,7 @@ typedef struct sh_audio { // note codec extradata may be either under "wf" or "codecdata" unsigned char *codecdata; int codecdata_len; - int pts_bytes; // bytes output by decoder after last known pts + int pts_offset; // number of samples output by decoder after last known pts } sh_audio_t; typedef struct sh_video { -- cgit v1.2.3