[FFmpeg-devel] [PATCH] avfilter/adelay: Add command support

David Lacko deiwo101 at gmail.com
Thu Jan 20 11:53:25 EET 2022


I would maybe even remove the av_freep(..) call, to keep the
original buffer and the original delay. The user would only
get an error code that the delay could not be changed.

st 19. 1. 2022 o 20:14 Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
napísal(a):

> David Lacko:
> > Adds command 'delays' to the adelay filter.
> > This command accepts same values as option with one difference, to apply
> > delay to all channels prefix 'all:' to the arguments is accepted.
> >
> > Signed-off-by: David Lacko <deiwo101 at gmail.com>
> > ---
> >  libavfilter/af_adelay.c | 183 ++++++++++++++++++++++++++++++++++------
> >  1 file changed, 157 insertions(+), 26 deletions(-)
> >
> > diff --git a/libavfilter/af_adelay.c b/libavfilter/af_adelay.c
> > index ed8a8ae739..1e13cf7fb0 100644
> > --- a/libavfilter/af_adelay.c
> > +++ b/libavfilter/af_adelay.c
> > @@ -31,6 +31,7 @@ typedef struct ChanDelay {
> >      int64_t delay;
> >      size_t delay_index;
> >      size_t index;
> > +    unsigned int samples_size;
> >      uint8_t *samples;
> >  } ChanDelay;
> >
> > @@ -48,13 +49,14 @@ typedef struct AudioDelayContext {
> >
> >      void (*delay_channel)(ChanDelay *d, int nb_samples,
> >                            const uint8_t *src, uint8_t *dst);
> > +    int (*resize_channel_samples)(ChanDelay *d, int64_t new_delay);
> >  } AudioDelayContext;
> >
> >  #define OFFSET(x) offsetof(AudioDelayContext, x)
> >  #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
> >
> >  static const AVOption adelay_options[] = {
> > -    { "delays", "set list of delays for each channel", OFFSET(delays),
> AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, A },
> > +    { "delays", "set list of delays for each channel", OFFSET(delays),
> AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, A | AV_OPT_FLAG_RUNTIME_PARAM },
> >      { "all",    "use last available delay for remained channels",
> OFFSET(all), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, A },
> >      { NULL }
> >  };
> > @@ -96,11 +98,92 @@ DELAY(s32, int32_t, 0)
> >  DELAY(flt, float,   0)
> >  DELAY(dbl, double,  0)
> >
> > +#define CHANGE_DELAY(name, type, fill)
>                                 \
> > +static int resize_samples_## name ##p(ChanDelay *d, int64_t new_delay)
>                                 \
> > +{
>                                  \
> > +    type *samples = (type *)d->samples;
>                                  \
> > +
>                                 \
> > +    if (new_delay == d->delay) {
>                                 \
> > +        return 0;
>                                  \
> > +    }
>                                  \
> > +
>                                 \
> > +    if (new_delay == 0) {
>                                  \
> > +        av_freep(&d->samples);
>                                 \
> > +        d->samples_size = 0;
>                                 \
> > +        d->delay = 0;
>                                  \
> > +        d->index = 0;
>                                  \
> > +        return 0;
>                                  \
> > +    }
>                                  \
> > +
>                                 \
> > +    d->samples = av_fast_realloc(d->samples, &d->samples_size,
> new_delay * sizeof(type));               \
> > +    if (!d->samples) {
>                                 \
> > +        av_freep(samples);
>                                 \
>
> av_free(samples) or av_freep(&samples), but not av_freep(samples).
> The typical way to write this is btw tmp = av_fast_realloc(buf,...) (in
> your case samples = av_fast_realloc(d->samples, ...) with
> av_freep(&d->samples); in the error branch and d->samples = samples in
> the non-error-case.
>
> > +        return AVERROR(ENOMEM);
>                                  \
> > +    }
>                                  \
>
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
>


More information about the ffmpeg-devel mailing list