Re: [FFmpeg-devel] [PATCH] libavfilter/asrc_flite: fixes and improvements
On Tue, Dec 5, 2023 at 12:27 AM Stefano Sabatini wrote: > On date Sunday 2023-12-03 23:23:48 +0100, Paul B Mahol wrote: > > Attached. > > > From fe1ece70c0ecbe6fb24e0823fe46db57242396e4 Mon Sep 17 00:00:00 2001 > > From: Paul B Mahol > > Date: Sun, 3 Dec 2023 21:38:08 +0100 > > Subject: [PATCH 1/2] avfilter/asrc_flite: switch to activate > > > > Allows to set EOF timestamp. > > > > Signed-off-by: Paul B Mahol > > --- > > libavfilter/asrc_flite.c | 24 +--- > > 1 file changed, 13 insertions(+), 11 deletions(-) > > Cannot really comment, but should be good if tested. > > > From e8aad4411ee0f8bc4bd50d5e3a10b7f712687f60 Mon Sep 17 00:00:00 2001 > > From: Paul B Mahol > > Date: Sun, 3 Dec 2023 22:50:11 +0100 > > Subject: [PATCH 2/2] avfilter/asrc_flite: use streaming function > > > > Fix continuous accumulation of audio samples for big txt inputs. > > > > Signed-off-by: Paul B Mahol > > --- > > libavfilter/asrc_flite.c | 84 ++-- > > 1 file changed, 64 insertions(+), 20 deletions(-) > > > > diff --git a/libavfilter/asrc_flite.c b/libavfilter/asrc_flite.c > > index 74c8414b5c..70a2fd3e40 100644 > > --- a/libavfilter/asrc_flite.c > > +++ b/libavfilter/asrc_flite.c > > @@ -24,6 +24,8 @@ > > */ > > > > #include > > +#include "libavutil/audio_fifo.h" > > +#include "libavutil/avstring.h" > > #include "libavutil/channel_layout.h" > > #include "libavutil/file.h" > > #include "libavutil/opt.h" > > @@ -39,11 +41,14 @@ typedef struct FliteContext { > > char *voice_str; > > char *textfile; > > char *text; > > -cst_wave *wave; > > -int16_t *wave_samples; > > -int wave_nb_samples; > > +char *text_p; > > +char *text_saveptr; > > +int nb_channels; > > +int sample_rate; > > +AVAudioFifo *fifo; > > int list_voices; > > cst_voice *voice; > > +cst_audio_streaming_info *asi; > > struct voice_entry *voice_entry; > > int64_t pts; > > int frame_nb_samples; ///< number of samples per frame > > @@ -140,10 +145,30 @@ static int select_voice(struct voice_entry > **entry_ret, const char *voice_name, > > return AVERROR(EINVAL); > > } > > > > +static int audio_stream_chunk_by_word(const cst_wave *w, int start, int > size, > > nit+: w -> wave to simplify reading > > > + int last, > cst_audio_streaming_info *asi) > > +{ > > +FliteContext *flite = asi->userdata; > > +void *const ptr[8] = { >samples[start] }; > > + > > +flite->nb_channels = w->num_channels; > > +flite->sample_rate = w->sample_rate; > > > +if (!flite->fifo) { > > +flite->fifo = av_audio_fifo_alloc(AV_SAMPLE_FMT_S16, > flite->nb_channels, size); > > any reason to initialize it here rather than in init? > Mostly because number of channels is unknown at init point of filter. > > > +if (!flite->fifo) > > +return CST_AUDIO_STREAM_STOP; > > [...] > > LGTM otherwise, thanks. > Note that this patch expect flite >= 2.0 is used where thread safety was fixed (gonna retest again to confirm this). ___ > 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] libavfilter/asrc_flite: fixes and improvements
On date Sunday 2023-12-03 23:23:48 +0100, Paul B Mahol wrote: > Attached. > From fe1ece70c0ecbe6fb24e0823fe46db57242396e4 Mon Sep 17 00:00:00 2001 > From: Paul B Mahol > Date: Sun, 3 Dec 2023 21:38:08 +0100 > Subject: [PATCH 1/2] avfilter/asrc_flite: switch to activate > > Allows to set EOF timestamp. > > Signed-off-by: Paul B Mahol > --- > libavfilter/asrc_flite.c | 24 +--- > 1 file changed, 13 insertions(+), 11 deletions(-) Cannot really comment, but should be good if tested. > From e8aad4411ee0f8bc4bd50d5e3a10b7f712687f60 Mon Sep 17 00:00:00 2001 > From: Paul B Mahol > Date: Sun, 3 Dec 2023 22:50:11 +0100 > Subject: [PATCH 2/2] avfilter/asrc_flite: use streaming function > > Fix continuous accumulation of audio samples for big txt inputs. > > Signed-off-by: Paul B Mahol > --- > libavfilter/asrc_flite.c | 84 ++-- > 1 file changed, 64 insertions(+), 20 deletions(-) > > diff --git a/libavfilter/asrc_flite.c b/libavfilter/asrc_flite.c > index 74c8414b5c..70a2fd3e40 100644 > --- a/libavfilter/asrc_flite.c > +++ b/libavfilter/asrc_flite.c > @@ -24,6 +24,8 @@ > */ > > #include > +#include "libavutil/audio_fifo.h" > +#include "libavutil/avstring.h" > #include "libavutil/channel_layout.h" > #include "libavutil/file.h" > #include "libavutil/opt.h" > @@ -39,11 +41,14 @@ typedef struct FliteContext { > char *voice_str; > char *textfile; > char *text; > -cst_wave *wave; > -int16_t *wave_samples; > -int wave_nb_samples; > +char *text_p; > +char *text_saveptr; > +int nb_channels; > +int sample_rate; > +AVAudioFifo *fifo; > int list_voices; > cst_voice *voice; > +cst_audio_streaming_info *asi; > struct voice_entry *voice_entry; > int64_t pts; > int frame_nb_samples; ///< number of samples per frame > @@ -140,10 +145,30 @@ static int select_voice(struct voice_entry **entry_ret, > const char *voice_name, > return AVERROR(EINVAL); > } > > +static int audio_stream_chunk_by_word(const cst_wave *w, int start, int size, nit+: w -> wave to simplify reading > + int last, cst_audio_streaming_info > *asi) > +{ > +FliteContext *flite = asi->userdata; > +void *const ptr[8] = { >samples[start] }; > + > +flite->nb_channels = w->num_channels; > +flite->sample_rate = w->sample_rate; > +if (!flite->fifo) { > +flite->fifo = av_audio_fifo_alloc(AV_SAMPLE_FMT_S16, > flite->nb_channels, size); any reason to initialize it here rather than in init? > +if (!flite->fifo) > +return CST_AUDIO_STREAM_STOP; [...] LGTM otherwise, thanks. ___ 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] libavfilter/asrc_flite: fixes and improvements
Attached. From fe1ece70c0ecbe6fb24e0823fe46db57242396e4 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Sun, 3 Dec 2023 21:38:08 +0100 Subject: [PATCH 1/2] avfilter/asrc_flite: switch to activate Allows to set EOF timestamp. Signed-off-by: Paul B Mahol --- libavfilter/asrc_flite.c | 24 +--- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/libavfilter/asrc_flite.c b/libavfilter/asrc_flite.c index 1c3053aa39..74c8414b5c 100644 --- a/libavfilter/asrc_flite.c +++ b/libavfilter/asrc_flite.c @@ -29,6 +29,7 @@ #include "libavutil/opt.h" #include "libavutil/thread.h" #include "avfilter.h" +#include "filters.h" #include "audio.h" #include "formats.h" #include "internal.h" @@ -256,14 +257,20 @@ static int config_props(AVFilterLink *outlink) return 0; } -static int request_frame(AVFilterLink *outlink) +static int activate(AVFilterContext *ctx) { -AVFrame *samplesref; -FliteContext *flite = outlink->src->priv; +AVFilterLink *outlink = ctx->outputs[0]; +FliteContext *flite = ctx->priv; int nb_samples = FFMIN(flite->wave_nb_samples, flite->frame_nb_samples); +AVFrame *samplesref; -if (!nb_samples) -return AVERROR_EOF; +if (!ff_outlink_frame_wanted(outlink)) +return FFERROR_NOT_READY; + +if (!nb_samples) { +ff_outlink_set_status(outlink, AVERROR_EOF, flite->pts); +return 0; +} samplesref = ff_get_audio_buffer(outlink, nb_samples); if (!samplesref) @@ -272,11 +279,6 @@ static int request_frame(AVFilterLink *outlink) memcpy(samplesref->data[0], flite->wave_samples, nb_samples * flite->wave->num_channels * 2); samplesref->pts = flite->pts; -#if FF_API_FRAME_PKT -FF_DISABLE_DEPRECATION_WARNINGS -samplesref->pkt_pos = -1; -FF_ENABLE_DEPRECATION_WARNINGS -#endif samplesref->sample_rate = flite->wave->sample_rate; flite->pts += nb_samples; flite->wave_samples += nb_samples * flite->wave->num_channels; @@ -290,7 +292,6 @@ static const AVFilterPad flite_outputs[] = { .name = "default", .type = AVMEDIA_TYPE_AUDIO, .config_props = config_props, -.request_frame = request_frame, }, }; @@ -300,6 +301,7 @@ const AVFilter ff_asrc_flite = { .init = init, .uninit= uninit, .priv_size = sizeof(FliteContext), +.activate = activate, .inputs= NULL, FILTER_OUTPUTS(flite_outputs), FILTER_QUERY_FUNC(query_formats), -- 2.42.1 From e8aad4411ee0f8bc4bd50d5e3a10b7f712687f60 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Sun, 3 Dec 2023 22:50:11 +0100 Subject: [PATCH 2/2] avfilter/asrc_flite: use streaming function Fix continuous accumulation of audio samples for big txt inputs. Signed-off-by: Paul B Mahol --- libavfilter/asrc_flite.c | 84 ++-- 1 file changed, 64 insertions(+), 20 deletions(-) diff --git a/libavfilter/asrc_flite.c b/libavfilter/asrc_flite.c index 74c8414b5c..70a2fd3e40 100644 --- a/libavfilter/asrc_flite.c +++ b/libavfilter/asrc_flite.c @@ -24,6 +24,8 @@ */ #include +#include "libavutil/audio_fifo.h" +#include "libavutil/avstring.h" #include "libavutil/channel_layout.h" #include "libavutil/file.h" #include "libavutil/opt.h" @@ -39,11 +41,14 @@ typedef struct FliteContext { char *voice_str; char *textfile; char *text; -cst_wave *wave; -int16_t *wave_samples; -int wave_nb_samples; +char *text_p; +char *text_saveptr; +int nb_channels; +int sample_rate; +AVAudioFifo *fifo; int list_voices; cst_voice *voice; +cst_audio_streaming_info *asi; struct voice_entry *voice_entry; int64_t pts; int frame_nb_samples; ///< number of samples per frame @@ -140,10 +145,30 @@ static int select_voice(struct voice_entry **entry_ret, const char *voice_name, return AVERROR(EINVAL); } +static int audio_stream_chunk_by_word(const cst_wave *w, int start, int size, + int last, cst_audio_streaming_info *asi) +{ +FliteContext *flite = asi->userdata; +void *const ptr[8] = { >samples[start] }; + +flite->nb_channels = w->num_channels; +flite->sample_rate = w->sample_rate; +if (!flite->fifo) { +flite->fifo = av_audio_fifo_alloc(AV_SAMPLE_FMT_S16, flite->nb_channels, size); +if (!flite->fifo) +return CST_AUDIO_STREAM_STOP; +} + +av_audio_fifo_write(flite->fifo, ptr, size); + +return CST_AUDIO_STREAM_CONT; +} + static av_cold int init(AVFilterContext *ctx) { FliteContext *flite = ctx->priv; int ret = 0; +char *text; if (flite->list_voices) { list_voices(ctx, "\n"); @@ -197,10 +222,21 @@ static av_cold int init(AVFilterContext *ctx) return AVERROR(EINVAL); } -/* synth all the file data in block */ -flite->wave = flite_text_to_wave(flite->text, flite->voice); -