Commit 754ff9a7 authored by Robert Swain's avatar Robert Swain

Refactor channel element configuration and mapping code into its own function

to allow reuse

Originally committed as revision 20069 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 2309923c
...@@ -152,6 +152,37 @@ static ChannelElement *get_che(AACContext *ac, int type, int elem_id) ...@@ -152,6 +152,37 @@ static ChannelElement *get_che(AACContext *ac, int type, int elem_id)
} }
} }
/**
* Check for the channel element in the current channel position configuration.
* If it exists, make sure the appropriate element is allocated and map the
* channel order to match the internal FFmpeg channel layout.
*
* @param che_pos current channel position configuration
* @param type channel element type
* @param id channel element id
* @param channels count of the number of channels in the configuration
*
* @return Returns error status. 0 - OK, !0 - error
*/
static int che_configure(AACContext *ac,
enum ChannelPosition che_pos[4][MAX_ELEM_ID],
int type, int id,
int *channels)
{
if (che_pos[type][id]) {
if (!ac->che[type][id] && !(ac->che[type][id] = av_mallocz(sizeof(ChannelElement))))
return AVERROR(ENOMEM);
if (type != TYPE_CCE) {
ac->output_data[(*channels)++] = ac->che[type][id]->ch[0].ret;
if (type == TYPE_CPE) {
ac->output_data[(*channels)++] = ac->che[type][id]->ch[1].ret;
}
}
} else
av_freep(&ac->che[type][id]);
return 0;
}
/** /**
* Configure output channel order based on the current program configuration element. * Configure output channel order based on the current program configuration element.
* *
...@@ -166,23 +197,17 @@ static int output_configure(AACContext *ac, ...@@ -166,23 +197,17 @@ static int output_configure(AACContext *ac,
int channel_config) int channel_config)
{ {
AVCodecContext *avctx = ac->avccontext; AVCodecContext *avctx = ac->avccontext;
int i, type, channels = 0; int i, type, channels = 0, ret;
memcpy(che_pos, new_che_pos, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); memcpy(che_pos, new_che_pos, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));
if (channel_config) { if (channel_config) {
for (i = 0; i < tags_per_config[channel_config]; i++) { for (i = 0; i < tags_per_config[channel_config]; i++) {
const int id = aac_channel_layout_map[channel_config - 1][i][1]; if ((ret = che_configure(ac, che_pos,
type = aac_channel_layout_map[channel_config - 1][i][0]; aac_channel_layout_map[channel_config - 1][i][0],
aac_channel_layout_map[channel_config - 1][i][1],
if (!ac->che[type][id] && !(ac->che[type][id] = av_mallocz(sizeof(ChannelElement)))) &channels)))
return AVERROR(ENOMEM); return ret;
if (type != TYPE_CCE) {
ac->output_data[channels++] = ac->che[type][id]->ch[0].ret;
if (type == TYPE_CPE)
ac->output_data[channels++] = ac->che[type][id]->ch[1].ret;
}
} }
memset(ac->tag_che_map, 0, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0])); memset(ac->tag_che_map, 0, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0]));
...@@ -201,17 +226,8 @@ static int output_configure(AACContext *ac, ...@@ -201,17 +226,8 @@ static int output_configure(AACContext *ac,
for (i = 0; i < MAX_ELEM_ID; i++) { for (i = 0; i < MAX_ELEM_ID; i++) {
for (type = 0; type < 4; type++) { for (type = 0; type < 4; type++) {
if (che_pos[type][i]) { if ((ret = che_configure(ac, che_pos, type, i, &channels)))
if (!ac->che[type][i] && !(ac->che[type][i] = av_mallocz(sizeof(ChannelElement)))) return ret;
return AVERROR(ENOMEM);
if (type != TYPE_CCE) {
ac->output_data[channels++] = ac->che[type][i]->ch[0].ret;
if (type == TYPE_CPE) {
ac->output_data[channels++] = ac->che[type][i]->ch[1].ret;
}
}
} else
av_freep(&ac->che[type][i]);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment