[FFmpeg-devel] [PATCH] avcodec/mpegaudiodec_template: skip first frame after seeking

Michael Niedermayer michaelni at gmx.at
Sat Apr 25 18:42:27 CEST 2015


On Fri, Apr 17, 2015 at 08:05:06PM +0200, wm4 wrote:
> On Fri, 17 Apr 2015 19:47:50 +0200
> Michael Niedermayer <michaelni at gmx.at> wrote:
> 
> > On Fri, Apr 17, 2015 at 07:21:23PM +0200, wm4 wrote:
> > > On Fri, 17 Apr 2015 19:04:02 +0200
> > > Michael Niedermayer <michaelni at gmx.at> wrote:
> > > 
> > > > This could be made optional if preferred
> > > > ---
> > > >  libavcodec/mpegaudiodec_template.c |    7 +++++++
> > > >  1 file changed, 7 insertions(+)
> > > > 
> > > > diff --git a/libavcodec/mpegaudiodec_template.c b/libavcodec/mpegaudiodec_template.c
> > > > index 2326a90..70c17a1 100644
> > > > --- a/libavcodec/mpegaudiodec_template.c
> > > > +++ b/libavcodec/mpegaudiodec_template.c
> > > > @@ -87,6 +87,7 @@ typedef struct MPADecodeContext {
> > > >      MPADSPContext mpadsp;
> > > >      AVFloatDSPContext *fdsp;
> > > >      AVFrame *frame;
> > > > +    int flushed;
> > > >  } MPADecodeContext;
> > > >  
> > > >  #define HEADER_SIZE 4
> > > > @@ -1645,6 +1646,11 @@ static int mp_decode_frame(MPADecodeContext *s, OUT_INT **samples,
> > > >          }
> > > >      }
> > > >  
> > > > +    if (s->flushed) {
> > > > +        s->avctx->internal->skip_samples = FFMAX(s->avctx->internal->skip_samples, s->frame->nb_samples);
> > > > +        s->flushed = 0;
> > > > +    }
> > > > +
> > > >      return nb_frames * 32 * sizeof(OUT_INT) * s->nb_channels;
> > > >  }
> > > >  
> > > > @@ -1723,6 +1729,7 @@ static void mp_flush(MPADecodeContext *ctx)
> > > >      memset(ctx->mdct_buf, 0, sizeof(ctx->mdct_buf));
> > > >      ctx->last_buf_size = 0;
> > > >      ctx->dither_state = 0;
> > > > +    ctx->flushed = 1;
> > > >  }
> > > >  
> > > >  static void flush(AVCodecContext *avctx)
> > > 
> > > Would this not break gapless audio if you seek back to the first frame
> > > after being done decoding? (Consider usecases like infinite looping.)
> > 
> > i did not test it but the skip value from AVPacket should override
> > this if its set
> > the first packet should contain skip sidedata or the mp3 would start
> > with a "half" empty output frame
> > 
> > [...]
> 
> I wonder if it would be safer and generally less disruptive if the
> demuxer added the skip value to the first AVPacket after every seek?

i dont really know, but if people prefer, that probably can be done
as well (would need to be tested to ensure nothing unexpected happens)
question is what do (lib) users prefer ?

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Observe your enemies, for they first find out your faults. -- Antisthenes
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150425/47153792/attachment.asc>


More information about the ffmpeg-devel mailing list