[FFmpeg-devel] [PATCH 4/4] Move audio channel API from libavcodec to libavcore.

Michael Niedermayer michaelni
Sat Nov 20 04:02:50 CET 2010


On Sat, Nov 20, 2010 at 01:36:02AM +0100, Stefano Sabatini wrote:
> On date Monday 2010-11-01 14:51:20 +0100, Michael Niedermayer encoded:
> > On Fri, Oct 29, 2010 at 09:49:41PM -0700, Stefano Sabatini wrote:
> > > ---
> > >  libavcodec/audioconvert.c |   91 +++------------------------------
> > >  libavcodec/audioconvert.h |   21 ++++---
> > >  libavcodec/avcodec.h      |   80 +++++++++++++++-------------
> > >  libavcore/Makefile        |    6 ++-
> > >  libavcore/audioconvert.c  |  125 +++++++++++++++++++++++++++++++++++++++++++++
> > >  libavcore/audioconvert.h  |  108 ++++++++++++++++++++++++++++++++++++++
> > >  6 files changed, 299 insertions(+), 132 deletions(-)
> > >  create mode 100644 libavcore/audioconvert.c
> > >  create mode 100644 libavcore/audioconvert.h
> > > 
> > > diff --git a/libavcodec/audioconvert.c b/libavcodec/audioconvert.c
> > > index 4e4063f..f3d483c 100644
> > > --- a/libavcodec/audioconvert.c
> > > +++ b/libavcodec/audioconvert.c
> > > @@ -48,104 +48,27 @@ void avcodec_sample_fmt_string (char *buf, int buf_size, int sample_fmt)
> > >  }
> > >  #endif
> > >  
> > > -static const char* const channel_names[]={
> > > -    "FL", "FR", "FC", "LFE", "BL",  "BR",  "FLC", "FRC",
> > > -    "BC", "SL", "SR", "TC",  "TFL", "TFC", "TFR", "TBL",
> > > -    "TBC", "TBR",
> > > -    [29] = "DL",
> > > -    [30] = "DR",
> > > -};
> > > -
> > > -static const char *get_channel_name(int channel_id)
> > > -{
> > > -    if (channel_id<0 || channel_id>=FF_ARRAY_ELEMS(channel_names))
> > > -        return NULL;
> > > -    return channel_names[channel_id];
> > > -}
> > > -
> > 
> > > +#if FF_API_OLD_AUDIOCONVERT
> > >  int64_t avcodec_guess_channel_layout(int nb_channels, enum CodecID codec_id, const char *fmt_name)
> > >  {
> > > -    switch(nb_channels) {
> > > -    case 1: return CH_LAYOUT_MONO;
> > > -    case 2: return CH_LAYOUT_STEREO;
> > > -    case 3: return CH_LAYOUT_SURROUND;
> > > -    case 4: return CH_LAYOUT_QUAD;
> > > -    case 5: return CH_LAYOUT_5POINT0;
> > > -    case 6: return CH_LAYOUT_5POINT1;
> > > -    case 8: return CH_LAYOUT_7POINT1;
> > > -    default: return 0;
> > > -    }
> > > +    return av_guess_channel_layout(nb_channels);
> > 
> > This is not possible, codec and demuxer ids can be required for guessing
> 
> Left in libavcodec.
> 
> > [...]
> > > @@ -3,12 +3,14 @@ include $(SUBDIR)../config.mak
> > >  NAME = avcore
> > >  FFLIBS = avutil
> > >  
> > > -HEADERS = avcore.h                                                      \
> > > +HEADERS = audioconvert.h                                                \
> > > +          avcore.h                                                      \
> > 
> > if you leave HEADER= \
> > on its own line than future patches would a line smaller if they change the first
> > entry
> 
> Fixed. 
> 
> > >            imgutils.h                                                    \
> > >            parseutils.h                                                  \
> > >            samplefmt.h                                                   \
> > >  
> > > -OBJS = imgutils.o                                                       \
> > > +OBJS = audioconvert.o                                                   \
> > > +       imgutils.o                                                       \
> > >         parseutils.o                                                     \
> > >         samplefmt.o                                                      \
> > >         utils.o                                                          \
> > > diff --git a/libavcore/audioconvert.c b/libavcore/audioconvert.c
> > > new file mode 100644
> > > index 0000000..2b6e1a8
> > > --- /dev/null
> > > +++ b/libavcore/audioconvert.c
> > > @@ -0,0 +1,125 @@
> > > +/*
> > > + * Copyright (c) 2006 Michael Niedermayer <michaelni at gmx.at>
> > > + *
> > > + * This file is part of FFmpeg.
> > > + *
> > > + * FFmpeg is free software; you can redistribute it and/or
> > > + * modify it under the terms of the GNU Lesser General Public
> > > + * License as published by the Free Software Foundation; either
> > > + * version 2.1 of the License, or (at your option) any later version.
> > > + *
> > > + * FFmpeg is distributed in the hope that it will be useful,
> > > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> > > + * Lesser General Public License for more details.
> > > + *
> > > + * You should have received a copy of the GNU Lesser General Public
> > > + * License along with FFmpeg; if not, write to the Free Software
> > > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> > > + */
> > 
> > dont forget svn cp
> 
> I'll do when I'll commit.
> 
> > and a diff against the true ancestor might be usefull
> [...]
> -- 
> FFmpeg = Free and Fast Mysterious Portable Eretic Genius

>  libavcodec/audioconvert.c |   78 ++-----------------------------
>  libavcodec/audioconvert.h |   22 +++++---
>  libavcodec/avcodec.h      |   80 +++++++++++++++++---------------
>  libavcore/Makefile        |    8 ++-
>  libavcore/audioconvert.c  |  113 ++++++++++++++++++++++++++++++++++++++++++++++
>  libavcore/audioconvert.h  |  100 ++++++++++++++++++++++++++++++++++++++++
>  6 files changed, 281 insertions(+), 120 deletions(-)
> db5da3038437375e3c280bf72f618ddffa1e4ce4  0001-Move-audio-channel-API-from-libavcodec-to-libavcore.patch
> From 34aa659faf89f0803902ac4e4c5870b5ea3ecbaa Mon Sep 17 00:00:00 2001
> From: Stefano Sabatini <stefano.sabatini-lala at poste.it>
> Date: Fri, 29 Oct 2010 21:45:44 -0700
> Subject: [PATCH] Move audio channel API from libavcodec to libavcore.
> 
> ---
>  libavcodec/audioconvert.c |   78 ++-----------------------------
>  libavcodec/audioconvert.h |   22 ++++++---
>  libavcodec/avcodec.h      |   80 +++++++++++++++++---------------
>  libavcore/Makefile        |    8 ++-
>  libavcore/audioconvert.c  |  113 +++++++++++++++++++++++++++++++++++++++++++++
>  libavcore/audioconvert.h  |  100 +++++++++++++++++++++++++++++++++++++++
>  6 files changed, 281 insertions(+), 120 deletions(-)
>  create mode 100644 libavcore/audioconvert.c
>  create mode 100644 libavcore/audioconvert.h
> 
> diff --git a/libavcodec/audioconvert.c b/libavcodec/audioconvert.c
> index 3f1c819..609fd1c 100644
> --- a/libavcodec/audioconvert.c
> +++ b/libavcodec/audioconvert.c
> @@ -48,21 +48,6 @@ void avcodec_sample_fmt_string (char *buf, int buf_size, int sample_fmt)
>  }
>  #endif
>  
> -static const char* const channel_names[]={
> -    "FL", "FR", "FC", "LFE", "BL",  "BR",  "FLC", "FRC",
> -    "BC", "SL", "SR", "TC",  "TFL", "TFC", "TFR", "TBL",
> -    "TBC", "TBR",
> -    [29] = "DL",
> -    [30] = "DR",
> -};
> -
> -static const char *get_channel_name(int channel_id)
> -{
> -    if (channel_id<0 || channel_id>=FF_ARRAY_ELEMS(channel_names))
> -        return NULL;
> -    return channel_names[channel_id];
> -}
> -
>  int64_t avcodec_guess_channel_layout(int nb_channels, enum CodecID codec_id, const char *fmt_name)
>  {
>      switch(nb_channels) {
> @@ -77,75 +62,22 @@ int64_t avcodec_guess_channel_layout(int nb_channels, enum CodecID codec_id, con
>      }
>  }
>  
> -static const struct {
> -    const char *name;
> -    int         nb_channels;
> -    int64_t     layout;
> -} channel_layout_map[] = {
> -    { "mono",        1,  CH_LAYOUT_MONO },
> -    { "stereo",      2,  CH_LAYOUT_STEREO },
> -    { "4.0",         4,  CH_LAYOUT_4POINT0 },
> -    { "quad",        4,  CH_LAYOUT_QUAD },
> -    { "5.0",         5,  CH_LAYOUT_5POINT0 },
> -    { "5.0",         5,  CH_LAYOUT_5POINT0_BACK },
> -    { "5.1",         6,  CH_LAYOUT_5POINT1 },
> -    { "5.1",         6,  CH_LAYOUT_5POINT1_BACK },
> -    { "5.1+downmix", 8,  CH_LAYOUT_5POINT1|CH_LAYOUT_STEREO_DOWNMIX, },
> -    { "7.1",         8,  CH_LAYOUT_7POINT1 },
> -    { "7.1(wide)",   8,  CH_LAYOUT_7POINT1_WIDE },
> -    { "7.1+downmix", 10, CH_LAYOUT_7POINT1|CH_LAYOUT_STEREO_DOWNMIX, },
> -    { 0 }
> -};
> -
> +#if FF_API_OLD_AUDIOCONVERT
>  int64_t avcodec_get_channel_layout(const char *name)
>  {
> -    int i = 0;
> -    do {
> -        if (!strcmp(channel_layout_map[i].name, name))
> -            return channel_layout_map[i].layout;
> -        i++;
> -    } while (channel_layout_map[i].name);
> -
> -    return 0;
> +    return av_get_channel_layout(name);
>  }
>  
>  void avcodec_get_channel_layout_string(char *buf, int buf_size, int nb_channels, int64_t channel_layout)
>  {
> -    int i;
> -
> -    for (i=0; channel_layout_map[i].name; i++)
> -        if (nb_channels    == channel_layout_map[i].nb_channels &&
> -            channel_layout == channel_layout_map[i].layout) {
> -            av_strlcpy(buf, channel_layout_map[i].name, buf_size);
> -            return;
> -        }
> -
> -    snprintf(buf, buf_size, "%d channels", nb_channels);
> -    if (channel_layout) {
> -        int i,ch;
> -        av_strlcat(buf, " (", buf_size);
> -        for(i=0,ch=0; i<64; i++) {
> -            if ((channel_layout & (1L<<i))) {
> -                const char *name = get_channel_name(i);
> -                if (name) {
> -                    if (ch>0) av_strlcat(buf, "|", buf_size);
> -                    av_strlcat(buf, name, buf_size);
> -                }
> -                ch++;
> -            }
> -        }
> -        av_strlcat(buf, ")", buf_size);
> -    }
> +    av_get_channel_layout_string(buf, buf_size, nb_channels, channel_layout);
>  }
>  
>  int avcodec_channel_layout_num_channels(int64_t channel_layout)
>  {
> -    int count;
> -    uint64_t x = channel_layout;
> -    for (count = 0; x; count++)
> -        x &= x-1; // unset lowest set bit
> -    return count;
> +    return av_get_channel_layout_nb_channels(channel_layout);
>  }
> +#endif
>  
>  struct AVAudioConvert {
>      int in_channels, out_channels;
> diff --git a/libavcodec/audioconvert.h b/libavcodec/audioconvert.h
> index a1e61c2..66a12a6 100644
> --- a/libavcodec/audioconvert.h
> +++ b/libavcodec/audioconvert.h
> @@ -52,22 +52,33 @@ attribute_deprecated
>  enum AVSampleFormat avcodec_get_sample_fmt(const char* name);
>  #endif
>  
> +#if FF_API_OLD_AUDIOCONVERT
>  /**
> - * @return NULL on error
> + * @deprecated Use av_get_channel_name() instead.
>   */
> +attribute_deprecated
>  const char *avcodec_get_channel_name(int channel_id);
>  
>  /**
> - * @return channel layout that matches name, 0 if no match
> + * @deprecated Use av_get_channel_layout() instead.
>   */
> +attribute_deprecated
>  int64_t avcodec_get_channel_layout(const char *name);
>  
>  /**
> - * Return description of channel layout
> + * @deprecated Use av_get_channel_layout_string() instead.
>   */
> +attribute_deprecated
>  void avcodec_get_channel_layout_string(char *buf, int buf_size, int nb_channels, int64_t channel_layout);
>  
>  /**
> + * @deprecated Use av_get_channel_layout_nb_channels() instead.
> + */
> +attribute_deprecated
> +int avcodec_channel_layout_num_channels(int64_t channel_layout);
> +#endif
> +
> +/**
>   * Guess the channel layout
>   * @param nb_channels
>   * @param codec_id Codec identifier, or CODEC_ID_NONE if unknown
> @@ -76,11 +87,6 @@ void avcodec_get_channel_layout_string(char *buf, int buf_size, int nb_channels,
>   */
>  int64_t avcodec_guess_channel_layout(int nb_channels, enum CodecID codec_id, const char *fmt_name);
>  
> -/**
> - * @return the number of channels in the channel layout.
> - */
> -int avcodec_channel_layout_num_channels(int64_t channel_layout);
> -
>  struct AVAudioConvert;
>  typedef struct AVAudioConvert AVAudioConvert;
>  
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index bff9477..360fa3e 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -79,6 +79,9 @@
>  #ifndef FF_API_OLD_SAMPLE_FMT
>  #define FF_API_OLD_SAMPLE_FMT   (LIBAVCODEC_VERSION_MAJOR < 53)
>  #endif
> +#ifndef FF_API_OLD_AUDIOCONVERT
> +#define FF_API_OLD_AUDIOCONVERT (LIBAVCODEC_VERSION_MAJOR < 54)

why 54 and not 53 ?


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

When the tyrant has disposed of foreign enemies by conquest or treaty, and
there is nothing more to fear from them, then he is always stirring up
some war or other, in order that the people may require a leader. -- Plato
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20101120/b88f8629/attachment.pgp>



More information about the ffmpeg-devel mailing list