From a5224836293ac02bd13f688cfc848aae6818e963 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 11 Jul 2013 19:10:33 +0200 Subject: demux: remove facility for partial packet reads Partial packet reads were needed because the video/audio parsers were working on top of them. So it could happen that a parser read a part of a packet, and returned that to the decoder. With libavformat/libavcodec, packets are already parsed, and everything is much simpler. Most of the simplifications in ad_spdif could have been done earlier. Remove some other stuff as well, like the questionable slave mode start time reporting (could be replaced by proper code, but we don't bother). Remove the unused skip_audio_frame() functionality as well (it was used by old demuxers). Some functions become private to demux.c, like demux_fill_buffer(). Introduce new packet read functions, which have simpler semantics. Packets returned from them are owned by the caller, and all packets in the demux.c packet queue are considered unread. Remove special code that dropped subtitle packets with size 0. This used to be needed because it caused special cases in the old code. --- audio/decode/ad.h | 3 --- audio/decode/ad_lavc.c | 7 ++++-- audio/decode/ad_mpg123.c | 16 ++++++------- audio/decode/ad_spdif.c | 59 +++++++++--------------------------------------- audio/decode/dec_audio.c | 11 --------- 5 files changed, 23 insertions(+), 73 deletions(-) (limited to 'audio') diff --git a/audio/decode/ad.h b/audio/decode/ad.h index 1f45e88f98..1c8a211f5b 100644 --- a/audio/decode/ad.h +++ b/audio/decode/ad.h @@ -44,7 +44,4 @@ extern const ad_functions_t * const mpcodecs_ad_drivers[]; #define ADCTRL_RESYNC_STREAM 1 // resync, called after seeking -// fallback if ADCTRL_SKIP not implemented: ds_fill_buffer(sh_audio->ds); -#define ADCTRL_SKIP_FRAME 2 // skip block/frame, called while seeking - #endif /* MPLAYER_AD_H */ diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c index c311bc2cb8..d197bed072 100644 --- a/audio/decode/ad_lavc.c +++ b/audio/decode/ad_lavc.c @@ -372,10 +372,12 @@ static int decode_new_packet(struct sh_audio *sh) { struct priv *priv = sh->context; AVCodecContext *avctx = priv->avctx; - struct demux_packet *mpkt = ds_get_packet2(sh->ds, false); + struct demux_packet *mpkt = demux_read_packet(sh->gsh); if (!mpkt) return -1; // error or EOF + int in_len = mpkt->len; + AVPacket pkt; mp_set_av_packet(&pkt, mpkt); @@ -385,6 +387,7 @@ static int decode_new_packet(struct sh_audio *sh) } int got_frame = 0; int ret = avcodec_decode_audio4(avctx, priv->avframe, &got_frame, &pkt); + talloc_free(mpkt); // LATM may need many packets to find mux info if (ret == AVERROR(EAGAIN)) return 0; @@ -408,7 +411,7 @@ static int decode_new_packet(struct sh_audio *sh) } else { priv->output = priv->avframe->data[0]; } - mp_dbg(MSGT_DECAUDIO, MSGL_DBG2, "Decoded %d -> %d \n", mpkt->len, + mp_dbg(MSGT_DECAUDIO, MSGL_DBG2, "Decoded %d -> %d \n", in_len, priv->output_left); return 0; } diff --git a/audio/decode/ad_mpg123.c b/audio/decode/ad_mpg123.c index 08739b7f4b..8d97468e06 100644 --- a/audio/decode/ad_mpg123.c +++ b/audio/decode/ad_mpg123.c @@ -217,27 +217,25 @@ static int decode_a_bit(sh_audio_t *sh, unsigned char *buf, int count) /* Feed the decoder. This will only fire from the second round on. */ if (ret == MPG123_NEED_MORE) { - int incount; - double pts; - unsigned char *inbuf; /* Feed more input data. */ - incount = ds_get_packet_pts(sh->ds, &inbuf, &pts); - if (incount <= 0) + struct demux_packet *pkt = demux_read_packet(sh->gsh); + if (!pkt) break; /* Apparently that's it. EOF. */ /* Next bytes from that presentation time. */ - if (pts != MP_NOPTS_VALUE) { - sh->pts = pts; + if (pkt->pts != MP_NOPTS_VALUE) { + sh->pts = pkt->pts; sh->pts_bytes = 0; } #ifdef AD_MPG123_FRAMEWISE /* Have to use mpg123_feed() to avoid decoding here. */ - ret = mpg123_feed(con->handle, inbuf, incount); + ret = mpg123_feed(con->handle, pkt->buffer, pkt->len); #else /* Do not use mpg123_feed(), added in later libmpg123 versions. */ - ret = mpg123_decode(con->handle, inbuf, incount, NULL, 0, NULL); + ret = mpg123_decode(con->handle, pkt->buffer, pkt->len, NULL, 0, NULL); #endif + talloc_free(pkt); if (ret == MPG123_ERR) break; } diff --git a/audio/decode/ad_spdif.c b/audio/decode/ad_spdif.c index 49b7d9a0d8..f4fc430208 100644 --- a/audio/decode/ad_spdif.c +++ b/audio/decode/ad_spdif.c @@ -84,9 +84,7 @@ static int codecs[] = { static int init(sh_audio_t *sh, const char *decoder) { - int x, in_size, srate, bps, *dtshd_rate; - unsigned char *start; - double pts; + int srate, bps, *dtshd_rate; AVFormatContext *lavf_ctx = NULL; AVStream *stream = NULL; const AVOption *opt = NULL; @@ -125,16 +123,8 @@ static int init(sh_audio_t *sh, const char *decoder) goto fail; } - // get sample_rate & bitrate from parser - x = ds_get_packet_pts(sh->ds, &start, &pts); - in_size = x; - if (x <= 0) { - pts = MP_NOPTS_VALUE; - x = 0; - } srate = 48000; //fake value bps = 768000/8; //fake value - sh->ds->buffer_pos -= in_size; int num_channels = 0; switch (lavf_ctx->streams[0]->codec->codec_id) { @@ -214,42 +204,24 @@ static int decode_audio(sh_audio_t *sh, unsigned char *buf, struct spdifContext *spdif_ctx = sh->context; AVFormatContext *lavf_ctx = spdif_ctx->lavf_ctx; AVPacket pkt; - double pts; - int ret, in_size, consumed, x; - unsigned char *start = NULL; - consumed = spdif_ctx->out_buffer_len = 0; + spdif_ctx->out_buffer_len = 0; spdif_ctx->out_buffer_size = maxlen; spdif_ctx->out_buffer = buf; while (spdif_ctx->out_buffer_len + spdif_ctx->iec61937_packet_size < maxlen && spdif_ctx->out_buffer_len < minlen) { - if (sh->ds->eof) + struct demux_packet *mpkt = demux_read_packet(sh->gsh); + if (!mpkt) break; - x = ds_get_packet_pts(sh->ds, &start, &pts); - if (x <= 0) { - continue; // END_NOT_FOUND - } else { - in_size = x; - consumed = x; - if (x == 0) { - mp_msg(MSGT_DECAUDIO,MSGL_V, - "start[%p] in_size[%d] consumed[%d] x[%d].\n", - start, in_size, consumed, x); - continue; // END_NOT_FOUND - } - sh->ds->buffer_pos -= in_size - consumed; - } - av_init_packet(&pkt); - pkt.data = start; - pkt.size = x; - mp_msg(MSGT_DECAUDIO,MSGL_V, - "start[%p] pkt.size[%d] in_size[%d] consumed[%d] x[%d].\n", - start, pkt.size, in_size, consumed, x); - if (pts != MP_NOPTS_VALUE) { - sh->pts = pts; + mp_set_av_packet(&pkt, mpkt); + mp_msg(MSGT_DECAUDIO,MSGL_V, "pkt.data[%p] pkt.size[%d]\n", + pkt.data, pkt.size); + if (mpkt->pts != MP_NOPTS_VALUE) { + sh->pts = mpkt->pts; sh->pts_bytes = 0; } - ret = lavf_ctx->oformat->write_packet(lavf_ctx, &pkt); + int ret = lavf_ctx->oformat->write_packet(lavf_ctx, &pkt); + talloc_free(mpkt); if (ret < 0) break; } @@ -259,15 +231,6 @@ static int decode_audio(sh_audio_t *sh, unsigned char *buf, static int control(sh_audio_t *sh, int cmd, void *arg) { - unsigned char *start; - double pts; - - switch (cmd) { - case ADCTRL_RESYNC_STREAM: - case ADCTRL_SKIP_FRAME: - ds_get_packet_pts(sh->ds, &start, &pts); - return CONTROL_TRUE; - } return CONTROL_UNKNOWN; } diff --git a/audio/decode/dec_audio.c b/audio/decode/dec_audio.c index 1bf217de80..8c80a0b119 100644 --- a/audio/decode/dec_audio.c +++ b/audio/decode/dec_audio.c @@ -365,14 +365,3 @@ void resync_audio_stream(sh_audio_t *sh_audio) return; sh_audio->ad_driver->control(sh_audio, ADCTRL_RESYNC_STREAM, NULL); } - -void skip_audio_frame(sh_audio_t *sh_audio) -{ - if (!sh_audio->initialized) - return; - if (sh_audio->ad_driver->control(sh_audio, ADCTRL_SKIP_FRAME, NULL) - == CONTROL_TRUE) - return; - // default skip code: - ds_fill_buffer(sh_audio->ds); // skip block -} -- cgit v1.2.3