Re: [FFmpeg-devel] [PATCH v2] avfilter/adelay: Add command support
Yes, during development I tested it streaming to rtmp and to file with a python client sending zmq requests. I Also tried changing the delay multiple times while running a single ffmpeg instance. Seemed to be working fine. so 5. 2. 2022 o 15:05 Paul B Mahol napísal(a): > Have this been tested? > > For example changing delays multiple times per invocation? > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe". > ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v2] avfilter/adelay: Add command support
Is this being reviewed? št 20. 1. 2022 o 12:38 David Lacko napísal(a): > Adds command 'delays' to the adelay filter. > This command accepts same values as the option with one difference, to > apply > delay to all channels prefix 'all:' to the argument is accepted. > > Signed-off-by: David Lacko > --- > libavfilter/af_adelay.c | 182 ++-- > 1 file changed, 156 insertions(+), 26 deletions(-) > > diff --git a/libavfilter/af_adelay.c b/libavfilter/af_adelay.c > index ed8a8ae739..382be3dca2 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,93 @@ 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; > \ > + > \ > +if (new_delay == d->delay) { > \ > +return 0; >\ > +} >\ > + > \ > +if (new_delay == 0) { >\ > +av_freep(>samples); > \ > +d->samples_size = 0; > \ > +d->delay = 0; >\ > +d->index = 0; >\ > +d->delay_index = 0; >\ > +return 0; >\ > +} >\ > + > \ > +samples = (type *) av_fast_realloc(d->samples, >samples_size, > new_delay * sizeof(type)); \ > +if (!samples) { >\ > +return AVERROR(ENOMEM); >\ > +} >\ > + > \ > +if (new_delay < d->delay) { >\ > +if (d->index > new_delay) { >\ > +d->index -= new_delay; > \ > +memmove(samples, [new_delay], d->index * > sizeof(type)); \ > +d->delay_index = new_delay; >\ > +} else if (d->delay_index > d->index) { >\ > +memmove([d->index], > [d->index+(d->delay-new_delay)],\ > +(new_delay - d->index) * sizeof(type)); >\ > +d->delay_index -= d->delay - new_delay; >\ > +} >\ > +} else { > \ > +size_t block_size; > \ > +if (d->delay_index >= d->delay) { >\ > +block_size = (d->delay - d->index) * sizeof(type); > \ > +memmove([d->index+(new_delay - d->delay)], > [d->index], block_size); \ > +d->delay_index = new_delay; >\ > +} else { >
[FFmpeg-devel] [PATCH v2] avfilter/adelay: Add command support
Adds command 'delays' to the adelay filter. This command accepts same values as the option with one difference, to apply delay to all channels prefix 'all:' to the argument is accepted. Signed-off-by: David Lacko --- libavfilter/af_adelay.c | 182 ++-- 1 file changed, 156 insertions(+), 26 deletions(-) diff --git a/libavfilter/af_adelay.c b/libavfilter/af_adelay.c index ed8a8ae739..382be3dca2 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,93 @@ 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; \ + \ +if (new_delay == d->delay) { \ +return 0; \ +} \ + \ +if (new_delay == 0) { \ +av_freep(>samples); \ +d->samples_size = 0; \ +d->delay = 0; \ +d->index = 0; \ +d->delay_index = 0; \ +return 0; \ +} \ + \ +samples = (type *) av_fast_realloc(d->samples, >samples_size, new_delay * sizeof(type)); \ +if (!samples) { \ +return AVERROR(ENOMEM); \ +} \ + \ +if (new_delay < d->delay) { \ +if (d->index > new_delay) { \ +d->index -= new_delay; \ +memmove(samples, [new_delay], d->index * sizeof(type)); \ +d->delay_index = new_delay; \ +} else if (d->delay_index > d->index) { \ +memmove([d->index], [d->index+(d->delay-new_delay)],\ +(new_delay - d-
Re: [FFmpeg-devel] [PATCH] avfilter/adelay: Add command support
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 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 > > --- > > 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(>samples); > \ > > +d->samples_size = 0; > \ > > +d->delay = 0; > \ > > +d->index = 0; > \ > > +return 0; > \ > > +} > \ > > + > \ > > +d->samples = av_fast_realloc(d->samples, >samples_size, > new_delay * sizeof(type)); \ > > +if (!d->samples) { > \ > > +av_freep(samples); > \ > > av_free(samples) or av_freep(), 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(>samples); in the error branch and d->samples = samples in > the non-error-case. > > > +return AVERROR(ENOMEM); > \ > > +} > \ > > > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe". > ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] avfilter/adelay: Add command support
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 --- 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(>samples); \ +d->samples_size = 0; \ +d->delay = 0; \ +d->index = 0; \ +return 0; \ +} \ + \ +d->samples = av_fast_realloc(d->samples, >samples_size, new_delay * sizeof(type)); \ +if (!d->samples) { \ +av_freep(samples); \ +return AVERROR(ENOMEM); \ +} \ +samples = (type *)d->samples; \ +if (new_delay < d->delay) { \ +if (d->index > new_delay) { \ +d->index -= new_delay; \ +memmove(samples, [new_delay], d->index * sizeof(type)); \ +} else if (d->delay_index > d->index) { \ +memmove([d->index], [d->index+(d->delay-new_delay)],\ +(new_delay - d->index) * sizeof(type)); \ +}