Mercurial > libavcodec.hg
comparison aac.c @ 10308:28b0f87cfdf1 libavcodec
Refactor channel element configuration and mapping code into its own function
to allow reuse
author | superdump |
---|---|
date | Mon, 28 Sep 2009 15:37:18 +0000 |
parents | 4e1d3e37bba0 |
children | 98816e4d5522 |
comparison
equal
deleted
inserted
replaced
10307:4e1d3e37bba0 | 10308:28b0f87cfdf1 |
---|---|
151 return NULL; | 151 return NULL; |
152 } | 152 } |
153 } | 153 } |
154 | 154 |
155 /** | 155 /** |
156 * Check for the channel element in the current channel position configuration. | |
157 * If it exists, make sure the appropriate element is allocated and map the | |
158 * channel order to match the internal FFmpeg channel layout. | |
159 * | |
160 * @param che_pos current channel position configuration | |
161 * @param type channel element type | |
162 * @param id channel element id | |
163 * @param channels count of the number of channels in the configuration | |
164 * | |
165 * @return Returns error status. 0 - OK, !0 - error | |
166 */ | |
167 static int che_configure(AACContext *ac, | |
168 enum ChannelPosition che_pos[4][MAX_ELEM_ID], | |
169 int type, int id, | |
170 int *channels) | |
171 { | |
172 if (che_pos[type][id]) { | |
173 if (!ac->che[type][id] && !(ac->che[type][id] = av_mallocz(sizeof(ChannelElement)))) | |
174 return AVERROR(ENOMEM); | |
175 if (type != TYPE_CCE) { | |
176 ac->output_data[(*channels)++] = ac->che[type][id]->ch[0].ret; | |
177 if (type == TYPE_CPE) { | |
178 ac->output_data[(*channels)++] = ac->che[type][id]->ch[1].ret; | |
179 } | |
180 } | |
181 } else | |
182 av_freep(&ac->che[type][id]); | |
183 return 0; | |
184 } | |
185 | |
186 /** | |
156 * Configure output channel order based on the current program configuration element. | 187 * Configure output channel order based on the current program configuration element. |
157 * | 188 * |
158 * @param che_pos current channel position configuration | 189 * @param che_pos current channel position configuration |
159 * @param new_che_pos New channel position configuration - we only do something if it differs from the current one. | 190 * @param new_che_pos New channel position configuration - we only do something if it differs from the current one. |
160 * | 191 * |
164 enum ChannelPosition che_pos[4][MAX_ELEM_ID], | 195 enum ChannelPosition che_pos[4][MAX_ELEM_ID], |
165 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], | 196 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], |
166 int channel_config) | 197 int channel_config) |
167 { | 198 { |
168 AVCodecContext *avctx = ac->avccontext; | 199 AVCodecContext *avctx = ac->avccontext; |
169 int i, type, channels = 0; | 200 int i, type, channels = 0, ret; |
170 | 201 |
171 memcpy(che_pos, new_che_pos, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); | 202 memcpy(che_pos, new_che_pos, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); |
172 | 203 |
173 if (channel_config) { | 204 if (channel_config) { |
174 for (i = 0; i < tags_per_config[channel_config]; i++) { | 205 for (i = 0; i < tags_per_config[channel_config]; i++) { |
175 const int id = aac_channel_layout_map[channel_config - 1][i][1]; | 206 if ((ret = che_configure(ac, che_pos, |
176 type = aac_channel_layout_map[channel_config - 1][i][0]; | 207 aac_channel_layout_map[channel_config - 1][i][0], |
177 | 208 aac_channel_layout_map[channel_config - 1][i][1], |
178 if (!ac->che[type][id] && !(ac->che[type][id] = av_mallocz(sizeof(ChannelElement)))) | 209 &channels))) |
179 return AVERROR(ENOMEM); | 210 return ret; |
180 | |
181 if (type != TYPE_CCE) { | |
182 ac->output_data[channels++] = ac->che[type][id]->ch[0].ret; | |
183 if (type == TYPE_CPE) | |
184 ac->output_data[channels++] = ac->che[type][id]->ch[1].ret; | |
185 } | |
186 } | 211 } |
187 | 212 |
188 memset(ac->tag_che_map, 0, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0])); | 213 memset(ac->tag_che_map, 0, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0])); |
189 ac->tags_mapped = 0; | 214 ac->tags_mapped = 0; |
190 | 215 |
199 * [ Center ] [ Front Left ] [ Front Right ] [ LFE ] [ Surround Left ] [ Surround Right ] | 224 * [ Center ] [ Front Left ] [ Front Right ] [ LFE ] [ Surround Left ] [ Surround Right ] |
200 */ | 225 */ |
201 | 226 |
202 for (i = 0; i < MAX_ELEM_ID; i++) { | 227 for (i = 0; i < MAX_ELEM_ID; i++) { |
203 for (type = 0; type < 4; type++) { | 228 for (type = 0; type < 4; type++) { |
204 if (che_pos[type][i]) { | 229 if ((ret = che_configure(ac, che_pos, type, i, &channels))) |
205 if (!ac->che[type][i] && !(ac->che[type][i] = av_mallocz(sizeof(ChannelElement)))) | 230 return ret; |
206 return AVERROR(ENOMEM); | |
207 if (type != TYPE_CCE) { | |
208 ac->output_data[channels++] = ac->che[type][i]->ch[0].ret; | |
209 if (type == TYPE_CPE) { | |
210 ac->output_data[channels++] = ac->che[type][i]->ch[1].ret; | |
211 } | |
212 } | |
213 } else | |
214 av_freep(&ac->che[type][i]); | |
215 } | 231 } |
216 } | 232 } |
217 | 233 |
218 memcpy(ac->tag_che_map, ac->che, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0])); | 234 memcpy(ac->tag_che_map, ac->che, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0])); |
219 ac->tags_mapped = 4 * MAX_ELEM_ID; | 235 ac->tags_mapped = 4 * MAX_ELEM_ID; |