[FFmpeg-devel] [RFC] Channel layouts

Michael Niedermayer michaelni
Sun Sep 7 15:43:16 CEST 2008


On Sun, Sep 07, 2008 at 08:58:28PM +1000, Peter Ross wrote:
> On Sat, Aug 30, 2008 at 11:05:43AM +1000, Peter Ross wrote:
> > On Fri, Aug 29, 2008 at 04:28:00PM +1000, Peter Ross wrote:
> > > Hi.
> > > 
> > > This patch adds the notion of channel layouts to libavcodec.
> > 
> > Patch updated. Thanks for the feedback.
> 
> Patch updated.
[...]
> +static const struct {
> +    int      nb_channels;
> +    int64_t  layout;
> +    const char *string;

id place the small fields together to reduce the chance of wasted space from
padding


> +} channel_layout_map[] = {
> +    {  1, CHANNEL_LAYOUT_MONO                                 , "mono"        },
> +    {  2, CHANNEL_LAYOUT_STEREO                               , "stereo"      },
> +    {  3, CHANNEL_LAYOUT_SURROUND                             , "surround"    },
> +    {  4, CHANNEL_LAYOUT_QUAD                                 , "quad"        },
> +    {  5, CHANNEL_LAYOUT_5POINT0                              , "5.0"         },
> +    {  6, CHANNEL_LAYOUT_5POINT1                              , "5.1"         },
> +    {  8, CHANNEL_LAYOUT_5POINT1|CHANNEL_LAYOUT_STEREO_DOWNMIX, "5.1+downmix" },
> +    {  8, CHANNEL_LAYOUT_7POINT1                              , "7.1"         },
> +    {  8, CHANNEL_LAYOUT_7POINT1_WIDE                         , "7.1(wide)"   },
> +    { 10, CHANNEL_LAYOUT_7POINT1|CHANNEL_LAYOUT_STEREO_DOWNMIX, "7.1+downmix" },
> +    {  0 }
> +};
> +
> +void avcodec_get_channel_layout_string(char *buf, int buf_size, int nb_channels, int64_t channel_layout)
> +{
> +    int i;
> +
> +    if (channel_layout==0)
> +        channel_layout = avcodec_guess_channel_layout(nb_channels);
> +
> +    for (i=0; channel_layout_map[i].nb_channels; i++)
> +        if (nb_channels    == channel_layout_map[i].nb_channels &&
> +            channel_layout == channel_layout_map[i].layout) {
> +            snprintf(buf, buf_size, channel_layout_map[i].string);
> +            return;
> +        }
> +
> +    snprintf(buf, buf_size, "%d channels", nb_channels);
> +    if (channel_layout) {
> +        int i,ch;
> +        snprintf(buf + strlen(buf), buf_size - strlen(buf), "(");
> +        for(i=0,ch=0; i<64 && ch<nb_channels; i++) { 
> +            if ((channel_layout & (1<<i))) {
> +                const char *name = get_channel_name(i);
> +                if (name)
> +                    snprintf(buf + strlen(buf), buf_size - strlen(buf), 
> +                        ch==0 ? "%s" : "|%s", name);
> +                ch--;
> +            }
> +        }
> +        snprintf(buf + strlen(buf), buf_size - strlen(buf), ")");
> +    }
> +}

av_strlcat(f) may be usefull to simplify some of the snprintf() calls


[...]

> @@ -2260,6 +2305,13 @@
>       * - decoding: set by libavcodec.
>       */
>      int bits_per_raw_sample;
> +
> +    /**
> +     * Audio channel layout.
> +     * - encoding: set by user.
> +     * - decoding: set by user (if container describes layout) and/or set by libavcodec.

maybe there should be a request_channel_layout field and request_channels
could be deprecated (and removed with the next major version bump).



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

Good people do not need laws to tell them to act responsibly, while bad
people will find a way around the laws. -- Plato
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080907/45a1ae76/attachment.pgp>



More information about the ffmpeg-devel mailing list