Mercurial > libavcodec.hg
comparison audioconvert.c @ 8098:c2ab7a8958ed libavcodec
Add audio channel layout API to libavcodec.
author | pross |
---|---|
date | Sat, 01 Nov 2008 05:03:42 +0000 |
parents | 24f2b8cc7918 |
children | 04295cbc0e9b |
comparison
equal
deleted
inserted
replaced
8097:7818ed859f66 | 8098:c2ab7a8958ed |
---|---|
25 * @author Michael Niedermayer <michaelni@gmx.at> | 25 * @author Michael Niedermayer <michaelni@gmx.at> |
26 */ | 26 */ |
27 | 27 |
28 #include "avcodec.h" | 28 #include "avcodec.h" |
29 #include "audioconvert.h" | 29 #include "audioconvert.h" |
30 #include <libavutil/avstring.h> | |
30 | 31 |
31 typedef struct SampleFmtInfo { | 32 typedef struct SampleFmtInfo { |
32 const char *name; | 33 const char *name; |
33 int bits; | 34 int bits; |
34 } SampleFmtInfo; | 35 } SampleFmtInfo; |
65 if (sample_fmt < 0) | 66 if (sample_fmt < 0) |
66 snprintf (buf, buf_size, "name " " depth"); | 67 snprintf (buf, buf_size, "name " " depth"); |
67 else if (sample_fmt < SAMPLE_FMT_NB) { | 68 else if (sample_fmt < SAMPLE_FMT_NB) { |
68 SampleFmtInfo info= sample_fmt_info[sample_fmt]; | 69 SampleFmtInfo info= sample_fmt_info[sample_fmt]; |
69 snprintf (buf, buf_size, "%-6s" " %2d ", info.name, info.bits); | 70 snprintf (buf, buf_size, "%-6s" " %2d ", info.name, info.bits); |
71 } | |
72 } | |
73 | |
74 static const char* const channel_names[]={ | |
75 "FL", "FR", "FC", "LFE", "BL", "BR", "FLC", "FRC", | |
76 "BC", "SL", "SR", "TC", "TFL", "TFC", "TFR", "TBL", | |
77 "TBC", "TBR", | |
78 [29] = "DL", | |
79 [30] = "DR", | |
80 }; | |
81 | |
82 const char *get_channel_name(int channel_id) | |
83 { | |
84 if (channel_id<0 || channel_id>=FF_ARRAY_ELEMS(channel_names)) | |
85 return NULL; | |
86 return channel_names[channel_id]; | |
87 } | |
88 | |
89 int64_t avcodec_guess_channel_layout(int nb_channels, enum CodecID codec_id, const char *fmt_name) | |
90 { | |
91 switch(nb_channels) { | |
92 case 1: return CHANNEL_LAYOUT_MONO; | |
93 case 2: return CHANNEL_LAYOUT_STEREO; | |
94 case 3: return CHANNEL_LAYOUT_SURROUND; | |
95 case 4: return CHANNEL_LAYOUT_QUAD; | |
96 case 5: return CHANNEL_LAYOUT_5POINT0; | |
97 case 6: return CHANNEL_LAYOUT_5POINT1; | |
98 case 8: return CHANNEL_LAYOUT_7POINT1; | |
99 default: return 0; | |
100 } | |
101 } | |
102 | |
103 static const struct { | |
104 const char *name; | |
105 int nb_channels; | |
106 int64_t layout; | |
107 } const channel_layout_map[] = { | |
108 { "mono", 1, CHANNEL_LAYOUT_MONO }, | |
109 { "stereo", 2, CHANNEL_LAYOUT_STEREO }, | |
110 { "surround", 3, CHANNEL_LAYOUT_SURROUND }, | |
111 { "quad", 4, CHANNEL_LAYOUT_QUAD }, | |
112 { "5.0", 5, CHANNEL_LAYOUT_5POINT0 }, | |
113 { "5.1", 6, CHANNEL_LAYOUT_5POINT1 }, | |
114 { "5.1+downmix", 8, CHANNEL_LAYOUT_5POINT1|CHANNEL_LAYOUT_STEREO_DOWNMIX, }, | |
115 { "7.1", 8, CHANNEL_LAYOUT_7POINT1 }, | |
116 { "7.1(wide)", 8, CHANNEL_LAYOUT_7POINT1_WIDE }, | |
117 { "7.1+downmix", 10, CHANNEL_LAYOUT_7POINT1|CHANNEL_LAYOUT_STEREO_DOWNMIX, }, | |
118 { 0 } | |
119 }; | |
120 | |
121 void avcodec_get_channel_layout_string(char *buf, int buf_size, int nb_channels, int64_t channel_layout) | |
122 { | |
123 int i; | |
124 | |
125 if (channel_layout==0) | |
126 channel_layout = avcodec_guess_channel_layout(nb_channels, CODEC_ID_NONE, NULL); | |
127 | |
128 for (i=0; channel_layout_map[i].name; i++) | |
129 if (nb_channels == channel_layout_map[i].nb_channels && | |
130 channel_layout == channel_layout_map[i].layout) { | |
131 snprintf(buf, buf_size, channel_layout_map[i].name); | |
132 return; | |
133 } | |
134 | |
135 snprintf(buf, buf_size, "%d channels", nb_channels); | |
136 if (channel_layout) { | |
137 int i,ch; | |
138 av_strlcat(buf, " (", buf_size); | |
139 for(i=0,ch=0; i<64; i++) { | |
140 if ((channel_layout & (1L<<i))) { | |
141 const char *name = get_channel_name(i); | |
142 if (name) { | |
143 if (ch>0) av_strlcat(buf, "|", buf_size); | |
144 av_strlcat(buf, name, buf_size); | |
145 } | |
146 ch++; | |
147 } | |
148 } | |
149 av_strlcat(buf, ")", buf_size); | |
70 } | 150 } |
71 } | 151 } |
72 | 152 |
73 struct AVAudioConvert { | 153 struct AVAudioConvert { |
74 int in_channels, out_channels; | 154 int in_channels, out_channels; |