[FFmpeg-devel] [PATCH] libavfilter/asrc_flite: fixes and improvements

Paul B Mahol onemda at gmail.com
Tue Dec 5 01:30:56 EET 2023


On Tue, Dec 5, 2023 at 12:27 AM Stefano Sabatini <stefasab at gmail.com> 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 <onemda at gmail.com>
> > 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 <onemda at gmail.com>
> > ---
> >  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 <onemda at gmail.com>
> > 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 <onemda at gmail.com>
> > ---
> >  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 <flite/flite.h>
> > +#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] = { &w->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 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