00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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;
00116 return count;
00117 }