• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavutil/audioconvert.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
00003  *
00004  * This file is part of FFmpeg.
00005  *
00006  * FFmpeg is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * FFmpeg is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with FFmpeg; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00026 #include "avstring.h"
00027 #include "avutil.h"
00028 #include "audioconvert.h"
00029 
00030 static const char * const channel_names[] = {
00031     "FL", "FR", "FC", "LFE", "BL",  "BR",  "FLC", "FRC",
00032     "BC", "SL", "SR", "TC",  "TFL", "TFC", "TFR", "TBL",
00033     "TBC", "TBR",
00034     [29] = "DL",
00035     [30] = "DR",
00036 };
00037 
00038 static const char *get_channel_name(int channel_id)
00039 {
00040     if (channel_id < 0 || channel_id >= FF_ARRAY_ELEMS(channel_names))
00041         return NULL;
00042     return channel_names[channel_id];
00043 }
00044 
00045 static const struct {
00046     const char *name;
00047     int         nb_channels;
00048     int64_t     layout;
00049 } channel_layout_map[] = {
00050     { "mono",        1,  AV_CH_LAYOUT_MONO },
00051     { "stereo",      2,  AV_CH_LAYOUT_STEREO },
00052     { "4.0",         4,  AV_CH_LAYOUT_4POINT0 },
00053     { "quad",        4,  AV_CH_LAYOUT_QUAD },
00054     { "5.0",         5,  AV_CH_LAYOUT_5POINT0 },
00055     { "5.0",         5,  AV_CH_LAYOUT_5POINT0_BACK },
00056     { "5.1",         6,  AV_CH_LAYOUT_5POINT1 },
00057     { "5.1",         6,  AV_CH_LAYOUT_5POINT1_BACK },
00058     { "5.1+downmix", 8,  AV_CH_LAYOUT_5POINT1|AV_CH_LAYOUT_STEREO_DOWNMIX, },
00059     { "7.1",         8,  AV_CH_LAYOUT_7POINT1 },
00060     { "7.1(wide)",   8,  AV_CH_LAYOUT_7POINT1_WIDE },
00061     { "7.1+downmix", 10, AV_CH_LAYOUT_7POINT1|AV_CH_LAYOUT_STEREO_DOWNMIX, },
00062     { 0 }
00063 };
00064 
00065 int64_t av_get_channel_layout(const char *name)
00066 {
00067     int i = 0;
00068     do {
00069         if (!strcmp(channel_layout_map[i].name, name))
00070             return channel_layout_map[i].layout;
00071         i++;
00072     } while (channel_layout_map[i].name);
00073 
00074     return 0;
00075 }
00076 
00077 void av_get_channel_layout_string(char *buf, int buf_size,
00078                                   int nb_channels, int64_t channel_layout)
00079 {
00080     int i;
00081 
00082     if (nb_channels <= 0)
00083         nb_channels = av_get_channel_layout_nb_channels(channel_layout);
00084 
00085     for (i = 0; channel_layout_map[i].name; i++)
00086         if (nb_channels    == channel_layout_map[i].nb_channels &&
00087             channel_layout == channel_layout_map[i].layout) {
00088             av_strlcpy(buf, channel_layout_map[i].name, buf_size);
00089             return;
00090         }
00091 
00092     snprintf(buf, buf_size, "%d channels", nb_channels);
00093     if (channel_layout) {
00094         int i,ch;
00095         av_strlcat(buf, " (", buf_size);
00096         for(i=0,ch=0; i<64; i++) {
00097             if ((channel_layout & (1L<<i))) {
00098                 const char *name = get_channel_name(i);
00099                 if (name) {
00100                     if (ch>0) av_strlcat(buf, "|", buf_size);
00101                     av_strlcat(buf, name, buf_size);
00102                 }
00103                 ch++;
00104             }
00105         }
00106         av_strlcat(buf, ")", buf_size);
00107     }
00108 }
00109 
00110 int av_get_channel_layout_nb_channels(int64_t channel_layout)
00111 {
00112     int count;
00113     uint64_t x = channel_layout;
00114     for (count = 0; x; count++)
00115         x &= x-1; // unset lowest set bit
00116     return count;
00117 }

Generated on Fri Feb 22 2013 07:24:25 for FFmpeg by  doxygen 1.7.1