[FFmpeg-devel] [PATCH] Add af_resample - sample fmt and channel layout conversion filter

Stefano Sabatini stefano.sabatini-lala
Mon Sep 27 00:40:31 CEST 2010


On date Wednesday 2010-09-22 23:21:37 +0200, Michael Niedermayer encoded:
> On Sun, Sep 12, 2010 at 02:50:00PM -0700, S.N. Hemanth Meenakshisundaram wrote:
> > 
> > Now modified af_resample to wrap the channel mix functions in
> > lavc/resample.c the way Stefano wanted - exposing the channel mix
> > routines as ff_* functions.
> > 
> > With this af_resample has no duplicate code, calls lavc routines for
> > both sample format conversion and channel mixing.
> > 
> > This patch contains the extra resample_internal.h header and
> > audioconvert functions required to represent the channel conversion
> > required as a number.
> > 
> > The patch isn't well split now, but once any changes required to this
> > are done, I will split it properly. Please review and comment.
> > 
> > af_resample is required for ffmpeg.c integration and many other lavfi
> > audio filters to work.
> > 
> > Regards,
> > 
> > ---
> >  libavcodec/audioconvert.c      |   17 ++
> >  libavcodec/audioconvert.h      |   10 +
> >  libavcodec/resample.c          |   21 ++-
> >  libavcodec/resample_internal.h |   36 ++++
> >  libavfilter/Makefile           |    1 +
> >  libavfilter/af_resample.c      |  378 ++++++++++++++++++++++++++++++++++++++++
> >  libavfilter/allfilters.c       |    1 +
> >  7 files changed, 454 insertions(+), 10 deletions(-)
> >  create mode 100644 libavcodec/resample_internal.h
> >  create mode 100644 libavfilter/af_resample.c
> > 
> > 
> > 
> 
> >  libavcodec/audioconvert.c      |   17 +
> >  libavcodec/audioconvert.h      |   10 +
> >  libavcodec/resample.c          |   21 +-
> >  libavcodec/resample_internal.h |   36 +++
> >  libavfilter/Makefile           |    1 
> >  libavfilter/af_resample.c      |  378 +++++++++++++++++++++++++++++++++++++++++
> >  libavfilter/allfilters.c       |    1 
> >  7 files changed, 454 insertions(+), 10 deletions(-)
> > 331672e66f98cef708612cf26bbc18562a188c7f  0001-Add-af_resample-sample-fmt-and-channel-layout-conver.patch
> > diff --git a/libavcodec/audioconvert.c b/libavcodec/audioconvert.c
> > index c6dc1b1..17fa19a 100644
> > --- a/libavcodec/audioconvert.c
> > +++ b/libavcodec/audioconvert.c
> > @@ -121,6 +121,11 @@ static const struct {
> >      { 0 }
> >  };
> >  
> > +int avcodec_get_num_channel_layouts(void)
> > +{
> > +    return (sizeof(channel_layout_map)/sizeof(channel_layout_map[0]));
> > +}
> 
> the number is something close to 2^channels
> 
> 
> > +
> >  int64_t avcodec_get_channel_layout(const char *name)
> >  {
> >      int i = 0;
> > @@ -162,6 +167,18 @@ void avcodec_get_channel_layout_string(char *buf, int buf_size, int nb_channels,
> >      }
> >  }
> >  
> > +int avcodec_get_channel_layout_index(int64_t channel_layout)
> > +{
> > +    int i = 1;
> > +    do {
> > +        if (channel_layout_map[i].layout == channel_layout)
> > +            return i;
> > +        i++;
> > +    } while (channel_layout_map[i].name);
> > +
> > +    return 0;
> > +}
> 
> there are more layouts besides neither of these functions belong to public api
> 
> 
> [...]
> > @@ -53,7 +54,7 @@ struct ReSampleContext {
> >  };
> >  
> >  /* n1: number of samples */
> > -static void stereo_to_mono(short *output, short *input, int n1)
> > +void ff_stereo_to_mono(short *output, short *input, int n1)
> >  {
> >      short *p, *q;
> >      int n = n1;
> 
> the functions belong to libavfilter
> what is the plan to move them there?

Impossible as lavc uses that functions internally.  The plan was to
directly use them, and move to something better when we'll have a
revisited resampling/conversion API, a libavresample was mentioned.
Since this is not going to take small time, the idea was to use the
quickest solution and not stall audio lavfi development.

> maybe iam missing something but these added dependancies dont seem to make
> that easier

Currently lavfi depends on the audio conversion lavc functions (that's
also the only dependance, as video filtering now only relies on
lavu/lavcore).

[...]

Regards.
-- 
FFmpeg = Formidable Fancy Multimedia Portable Esoteric Genius



More information about the ffmpeg-devel mailing list