[FFmpeg-devel] [PATCH 4/5] lavc: skip initial silence when requested

Michael Niedermayer michaelni at gmx.at
Thu Jul 12 22:20:39 CEST 2012


On Thu, Jul 05, 2012 at 06:11:36PM +0200, Nicolas George wrote:
> Le septidi 17 messidor, an CCXX, Michael Niedermayer a écrit :
> > Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> > ---
> >  libavcodec/internal.h |    5 +++++
> >  libavcodec/utils.c    |   18 ++++++++++++++++++
> >  2 files changed, 23 insertions(+)
> > 
> > diff --git a/libavcodec/internal.h b/libavcodec/internal.h
> > index 49c1a18..063aeca 100644
> > --- a/libavcodec/internal.h
> > +++ b/libavcodec/internal.h
> > @@ -84,6 +84,11 @@ typedef struct AVCodecInternal {
> >      unsigned int byte_buffer_size;
> >  
> >      void *frame_thread_encoder;
> > +
> > +    /**
> > +     * Number of audio samples to skip at in the decoder
> 
> I can not parse this phrase. "Number of audio samples to skip at the start
> of the next decoded frame"?

yes, changed


> 
> > +     */
> > +    int skip_samples;
> >  } AVCodecInternal;
> >  
> >  struct AVCodecDefault {
> > diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> > index b3af77d..86fa3a8 100644
> > --- a/libavcodec/utils.c
> > +++ b/libavcodec/utils.c
> > @@ -1611,6 +1611,8 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,
> >      }
> >  
> >      if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size) {
> > +        uint8_t *side;
> > +        int side_size;
> >          // copy to ensure we do not change avpkt
> >          AVPacket tmp = *avpkt;
> >          int did_split = av_packet_split_side_data(&tmp);
> > @@ -1629,6 +1631,22 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,
> >                  frame->sample_rate = avctx->sample_rate;
> >          }
> >  
> > +        side= av_packet_get_side_data(avctx->pkt, AV_PKT_DATA_SKIP_SAMPLES, &side_size);
> > +        if(side && side_size>=10) {
> > +            avctx->internal->skip_samples = AV_RL32(side);
> > +        }
> > +        if (avctx->internal->skip_samples) {
> 
> Correct me if I am wrong: you designed the API so that
> internal->skip_samples can also be set by another component, codec->decode
> for example?

no but it would be possible if that makes sense


> 
> > +            if(frame->nb_samples <= avctx->internal->skip_samples){
> > +                *got_frame_ptr = 0;
> > +                avctx->internal->skip_samples -= frame->nb_samples;
> > +            } else {
> > +                av_samples_copy(frame->extended_data, frame->extended_data, 0, avctx->internal->skip_samples,
> > +                                frame->nb_samples - avctx->internal->skip_samples, avctx->channels, frame->format);
> 
> av_samples_copy uses memcpy, not memmove. If skip_samples < nb_samples/2,
> the source and destination will overlap.

fixed


> 
> > +                frame->nb_samples -= avctx->internal->skip_samples;
> > +                avctx->internal->skip_samples = 0;
> 
> What about timestamps? If skip_samples is set by the decoder rather than the
> demuxer (possibly for convergence reasons after a call to flush),
> frame->pkt_pts will be the time of the first discarded sample.

ill post a new patchset

[...]


-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Frequently ignored awnser#1 FFmpeg bugs should be sent to our bugtracker. User
questions about the command line tools should be sent to the ffmpeg-user ML.
And questions about how to use libav* should be sent to the libav-user ML.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120712/44dd419b/attachment.asc>


More information about the ffmpeg-devel mailing list