From e7d4a2a721ae863488f6a3814f9dcdbc6e8f5166 Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Wed, 8 Feb 2012 15:01:13 +0200 Subject: libavcodec: Don't do av_free(av_malloc(0)) for bitstream filters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes crashes on exit when closing a bitstream filter that hasn't allocated any private data, on OS X. Signed-off-by: Martin Storsjö --- libavcodec/bitstream_filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libavcodec') diff --git a/libavcodec/bitstream_filter.c b/libavcodec/bitstream_filter.c index b803ca4ef9..ee56174b2c 100644 --- a/libavcodec/bitstream_filter.c +++ b/libavcodec/bitstream_filter.c @@ -39,7 +39,7 @@ AVBitStreamFilterContext *av_bitstream_filter_init(const char *name){ if(!strcmp(name, bsf->name)){ AVBitStreamFilterContext *bsfc= av_mallocz(sizeof(AVBitStreamFilterContext)); bsfc->filter= bsf; - bsfc->priv_data= av_mallocz(bsf->priv_data_size); + bsfc->priv_data = bsf->priv_data_size ? av_mallocz(bsf->priv_data_size) : NULL; return bsfc; } bsf= bsf->next; -- cgit v1.2.3 From 37bed6ff3f7f48e25d1e0c3efdf8cbb90bcf9514 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Tue, 31 Jan 2012 15:54:21 -0800 Subject: aacdec: Try to sniff a reasonable channel layout for PCE based configurations. This changes the output order of multichannel PCE based streams. --- libavcodec/aac.h | 5 +- libavcodec/aacdec.c | 368 +++++++++++++++++++++++++++++++++++++------------ libavcodec/aacdectab.h | 16 +-- tests/fate/aac.mak | 10 +- 4 files changed, 297 insertions(+), 102 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/aac.h b/libavcodec/aac.h index a36080cb6f..49def78979 100644 --- a/libavcodec/aac.h +++ b/libavcodec/aac.h @@ -263,9 +263,8 @@ typedef struct { * @name Channel element related data * @{ */ - enum ChannelPosition che_pos[4][MAX_ELEM_ID]; /**< channel element channel mapping with the - * first index as the first 4 raw data block types - */ + uint8_t layout_map[MAX_ELEM_ID*4][3]; + int layout_map_tags; ChannelElement *che[4][MAX_ELEM_ID]; ChannelElement *tag_che_map[4][MAX_ELEM_ID]; int tags_mapped; diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c index b1de5a571e..bef17ab68d 100644 --- a/libavcodec/aacdec.c +++ b/libavcodec/aacdec.c @@ -163,15 +163,14 @@ static ChannelElement *get_che(AACContext *ac, int type, int elem_id) } } -static int count_channels(enum ChannelPosition che_pos[4][MAX_ELEM_ID]) +static int count_channels(uint8_t (*layout)[3], int tags) { - int i, type, sum = 0; - for (i = 0; i < MAX_ELEM_ID; i++) { - for (type = 0; type < 4; type++) { - sum += (1 + (type == TYPE_CPE)) * - (che_pos[type][i] != AAC_CHANNEL_OFF && - che_pos[type][i] != AAC_CHANNEL_CC); - } + int i, sum = 0; + for (i = 0; i < tags; i++) { + int syn_ele = layout[i][0]; + int pos = layout[i][2]; + sum += (1 + (syn_ele == TYPE_CPE)) * + (pos != AAC_CHANNEL_OFF && pos != AAC_CHANNEL_CC); } return sum; } @@ -213,30 +212,217 @@ static av_cold int che_configure(AACContext *ac, return 0; } +struct elem_to_channel { + uint64_t av_position; + uint8_t syn_ele; + uint8_t elem_id; + uint8_t aac_position; +}; + +static int assign_pair(struct elem_to_channel e2c_vec[MAX_ELEM_ID], + uint8_t (*layout_map)[3], int offset, int tags, uint64_t left, + uint64_t right, int pos) +{ + if (layout_map[offset][0] == TYPE_CPE) { + e2c_vec[offset] = (struct elem_to_channel) { + .av_position = left | right, .syn_ele = TYPE_CPE, + .elem_id = layout_map[offset ][1], .aac_position = pos }; + return 1; + } else { + e2c_vec[offset] = (struct elem_to_channel) { + .av_position = left, .syn_ele = TYPE_SCE, + .elem_id = layout_map[offset ][1], .aac_position = pos }; + e2c_vec[offset + 1] = (struct elem_to_channel) { + .av_position = right, .syn_ele = TYPE_SCE, + .elem_id = layout_map[offset + 1][1], .aac_position = pos }; + return 2; + } +} + +static int count_paired_channels(uint8_t (*layout_map)[3], int tags, int pos, int *current) { + int num_pos_channels = 0; + int first_cpe = 0; + int sce_parity = 0; + int i; + for (i = *current; i < tags; i++) { + if (layout_map[i][2] != pos) + break; + if (layout_map[i][0] == TYPE_CPE) { + if (sce_parity) { + if (pos == AAC_CHANNEL_FRONT || !first_cpe) { + sce_parity = 0; + } else { + return -1; + } + } + num_pos_channels += 2; + first_cpe = 1; + } else { + num_pos_channels++; + sce_parity ^= 1; + } + } + if (sce_parity && + ((pos == AAC_CHANNEL_FRONT && first_cpe) || pos == AAC_CHANNEL_SIDE)) + return -1; + *current = i; + return num_pos_channels; +} + +static uint64_t sniff_channel_order(uint8_t (*layout_map)[3], int tags) +{ + int i, n, total_non_cc_elements; + struct elem_to_channel e2c_vec[MAX_ELEM_ID] = {{ 0 }}; + int num_front_channels, num_side_channels, num_back_channels; + uint64_t layout; + + i = 0; + num_front_channels = + count_paired_channels(layout_map, tags, AAC_CHANNEL_FRONT, &i); + if (num_front_channels < 0) + return 0; + num_side_channels = + count_paired_channels(layout_map, tags, AAC_CHANNEL_SIDE, &i); + if (num_side_channels < 0) + return 0; + num_back_channels = + count_paired_channels(layout_map, tags, AAC_CHANNEL_BACK, &i); + if (num_back_channels < 0) + return 0; + + i = 0; + if (num_front_channels & 1) { + e2c_vec[i] = (struct elem_to_channel) { + .av_position = AV_CH_FRONT_CENTER, .syn_ele = TYPE_SCE, + .elem_id = layout_map[i][1], .aac_position = AAC_CHANNEL_FRONT }; + i++; + num_front_channels--; + } + if (num_front_channels >= 4) { + i += assign_pair(e2c_vec, layout_map, i, tags, + AV_CH_FRONT_LEFT_OF_CENTER, + AV_CH_FRONT_RIGHT_OF_CENTER, + AAC_CHANNEL_FRONT); + num_front_channels -= 2; + } + if (num_front_channels >= 2) { + i += assign_pair(e2c_vec, layout_map, i, tags, + AV_CH_FRONT_LEFT, + AV_CH_FRONT_RIGHT, + AAC_CHANNEL_FRONT); + num_front_channels -= 2; + } + while (num_front_channels >= 2) { + i += assign_pair(e2c_vec, layout_map, i, tags, + UINT64_MAX, + UINT64_MAX, + AAC_CHANNEL_FRONT); + num_front_channels -= 2; + } + + if (num_side_channels >= 2) { + i += assign_pair(e2c_vec, layout_map, i, tags, + AV_CH_SIDE_LEFT, + AV_CH_SIDE_RIGHT, + AAC_CHANNEL_FRONT); + num_side_channels -= 2; + } + while (num_side_channels >= 2) { + i += assign_pair(e2c_vec, layout_map, i, tags, + UINT64_MAX, + UINT64_MAX, + AAC_CHANNEL_SIDE); + num_side_channels -= 2; + } + + while (num_back_channels >= 4) { + i += assign_pair(e2c_vec, layout_map, i, tags, + UINT64_MAX, + UINT64_MAX, + AAC_CHANNEL_BACK); + num_back_channels -= 2; + } + if (num_back_channels >= 2) { + i += assign_pair(e2c_vec, layout_map, i, tags, + AV_CH_BACK_LEFT, + AV_CH_BACK_RIGHT, + AAC_CHANNEL_BACK); + num_back_channels -= 2; + } + if (num_back_channels) { + e2c_vec[i] = (struct elem_to_channel) { + .av_position = AV_CH_BACK_CENTER, .syn_ele = TYPE_SCE, + .elem_id = layout_map[i][1], .aac_position = AAC_CHANNEL_BACK }; + i++; + num_back_channels--; + } + + if (i < tags && layout_map[i][2] == AAC_CHANNEL_LFE) { + e2c_vec[i] = (struct elem_to_channel) { + .av_position = AV_CH_LOW_FREQUENCY, .syn_ele = TYPE_LFE, + .elem_id = layout_map[i][1], .aac_position = AAC_CHANNEL_LFE }; + i++; + } + while (i < tags && layout_map[i][2] == AAC_CHANNEL_LFE) { + e2c_vec[i] = (struct elem_to_channel) { + .av_position = UINT64_MAX, .syn_ele = TYPE_LFE, + .elem_id = layout_map[i][1], .aac_position = AAC_CHANNEL_LFE }; + i++; + } + + // Must choose a stable sort + total_non_cc_elements = n = i; + do { + int next_n = 0; + for (i = 1; i < n; i++) { + if (e2c_vec[i-1].av_position > e2c_vec[i].av_position) { + FFSWAP(struct elem_to_channel, e2c_vec[i-1], e2c_vec[i]); + next_n = i; + } + } + n = next_n; + } while (n > 0); + + layout = 0; + for (i = 0; i < total_non_cc_elements; i++) { + layout_map[i][0] = e2c_vec[i].syn_ele; + layout_map[i][1] = e2c_vec[i].elem_id; + layout_map[i][2] = e2c_vec[i].aac_position; + if (e2c_vec[i].av_position != UINT64_MAX) { + layout |= e2c_vec[i].av_position; + } + } + + return layout; +} + /** * Configure output channel order based on the current program configuration element. * * @param che_pos current channel position configuration - * @param new_che_pos New channel position configuration - we only do something if it differs from the current one. * * @return Returns error status. 0 - OK, !0 - error */ static av_cold int output_configure(AACContext *ac, - enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], + uint8_t layout_map[MAX_ELEM_ID*4][3], int tags, int channel_config, enum OCStatus oc_type) { AVCodecContext *avctx = ac->avctx; - int i, type, channels = 0, ret; + int i, channels = 0, ret; - if (new_che_pos) - memcpy(ac->che_pos, new_che_pos, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); + if (ac->layout_map != layout_map) { + memcpy(ac->layout_map, layout_map, tags * sizeof(layout_map[0])); + ac->layout_map_tags = tags; + } if (channel_config) { for (i = 0; i < tags_per_config[channel_config]; i++) { - int id = aac_channel_layout_map[channel_config - 1][i][1]; - type = aac_channel_layout_map[channel_config - 1][i][0]; - if ((ret = che_configure(ac, ac->che_pos[type][id], - type, id, &channels))) + int type = aac_channel_layout_map[channel_config - 1][i][0]; + int id = aac_channel_layout_map[channel_config - 1][i][1]; + int positon = aac_channel_layout_map[channel_config - 1][i][2]; + if ((ret = che_configure(ac, positon, + type, id, + &channels))) return ret; } @@ -247,20 +433,24 @@ static av_cold int output_configure(AACContext *ac, /* Allocate or free elements depending on if they are in the * current program configuration. * - * Set up default 1:1 output mapping. + * Try to sniff a reasonable channel order, otherwise output the + * channels in the order the PCE declared them. */ - for (i = 0; i < MAX_ELEM_ID; i++) { - for (type = 0; type < 4; type++) { - if ((ret = che_configure(ac, ac->che_pos[type][i], - type, i, &channels))) - return ret; - } + uint64_t layout = sniff_channel_order(layout_map, tags); + for (i = 0; i < tags; i++) { + int type = layout_map[i][0]; + int id = layout_map[i][1]; + int position = layout_map[i][2]; + if ((ret = che_configure(ac, position, + type, id, + &channels))) + return ret; } memcpy(ac->tag_che_map, ac->che, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0])); - avctx->channel_layout = 0; + avctx->channel_layout = layout; } avctx->channels = channels; @@ -277,30 +467,45 @@ static av_cold int output_configure(AACContext *ac, * @param sce_map mono (Single Channel Element) map * @param type speaker type/position for these channels */ -static void decode_channel_map(enum ChannelPosition *cpe_map, - enum ChannelPosition *sce_map, +static void decode_channel_map(uint8_t layout_map[][3], enum ChannelPosition type, GetBitContext *gb, int n) { while (n--) { - enum ChannelPosition *map = cpe_map && get_bits1(gb) ? cpe_map : sce_map; // stereo or mono map - map[get_bits(gb, 4)] = type; + enum RawDataBlockType syn_ele; + switch (type) { + case AAC_CHANNEL_FRONT: + case AAC_CHANNEL_BACK: + case AAC_CHANNEL_SIDE: + syn_ele = get_bits1(gb); + break; + case AAC_CHANNEL_CC: + skip_bits1(gb); + syn_ele = TYPE_CCE; + break; + case AAC_CHANNEL_LFE: + syn_ele = TYPE_LFE; + break; + } + layout_map[0][0] = syn_ele; + layout_map[0][1] = get_bits(gb, 4); + layout_map[0][2] = type; + layout_map++; } } /** * Decode program configuration element; reference: table 4.2. * - * @param new_che_pos New channel position configuration - we only do something if it differs from the current one. - * * @return Returns error status. 0 - OK, !0 - error */ static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac, - enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], + uint8_t (*layout_map)[3], GetBitContext *gb) { int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc, sampling_index; int comment_len; + int tags; skip_bits(gb, 2); // object_type @@ -323,14 +528,19 @@ static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac, if (get_bits1(gb)) skip_bits(gb, 3); // mixdown_coeff_index and pseudo_surround - decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_FRONT, gb, num_front); - decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_SIDE, gb, num_side ); - decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_BACK, gb, num_back ); - decode_channel_map(NULL, new_che_pos[TYPE_LFE], AAC_CHANNEL_LFE, gb, num_lfe ); + decode_channel_map(layout_map , AAC_CHANNEL_FRONT, gb, num_front); + tags = num_front; + decode_channel_map(layout_map + tags, AAC_CHANNEL_SIDE, gb, num_side); + tags += num_side; + decode_channel_map(layout_map + tags, AAC_CHANNEL_BACK, gb, num_back); + tags += num_back; + decode_channel_map(layout_map + tags, AAC_CHANNEL_LFE, gb, num_lfe); + tags += num_lfe; skip_bits_long(gb, 4 * num_assoc_data); - decode_channel_map(new_che_pos[TYPE_CCE], new_che_pos[TYPE_CCE], AAC_CHANNEL_CC, gb, num_cc ); + decode_channel_map(layout_map + tags, AAC_CHANNEL_CC, gb, num_cc); + tags += num_cc; align_get_bits(gb); @@ -341,19 +551,18 @@ static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac, return -1; } skip_bits_long(gb, comment_len); - return 0; + return tags; } /** * Set up channel positions based on a default channel configuration * as specified in table 1.17. * - * @param new_che_pos New channel position configuration - we only do something if it differs from the current one. - * * @return Returns error status. 0 - OK, !0 - error */ static av_cold int set_default_channel_config(AVCodecContext *avctx, - enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], + uint8_t (*layout_map)[3], + int *tags, int channel_config) { if (channel_config < 1 || channel_config > 7) { @@ -361,32 +570,8 @@ static av_cold int set_default_channel_config(AVCodecContext *avctx, channel_config); return -1; } - - /* default channel configurations: - * - * 1ch : front center (mono) - * 2ch : L + R (stereo) - * 3ch : front center + L + R - * 4ch : front center + L + R + back center - * 5ch : front center + L + R + back stereo - * 6ch : front center + L + R + back stereo + LFE - * 7ch : front center + L + R + outer front left + outer front right + back stereo + LFE - */ - - if (channel_config != 2) - new_che_pos[TYPE_SCE][0] = AAC_CHANNEL_FRONT; // front center (or mono) - if (channel_config > 1) - new_che_pos[TYPE_CPE][0] = AAC_CHANNEL_FRONT; // L + R (or stereo) - if (channel_config == 4) - new_che_pos[TYPE_SCE][1] = AAC_CHANNEL_BACK; // back center - if (channel_config > 4) - new_che_pos[TYPE_CPE][(channel_config == 7) + 1] - = AAC_CHANNEL_BACK; // back stereo - if (channel_config > 5) - new_che_pos[TYPE_LFE][0] = AAC_CHANNEL_LFE; // LFE - if (channel_config == 7) - new_che_pos[TYPE_CPE][1] = AAC_CHANNEL_FRONT; // outer front left + outer front right - + *tags = tags_per_config[channel_config]; + memcpy(layout_map, aac_channel_layout_map[channel_config-1], *tags * sizeof(*layout_map)); return 0; } @@ -403,8 +588,9 @@ static int decode_ga_specific_config(AACContext *ac, AVCodecContext *avctx, MPEG4AudioConfig *m4ac, int channel_config) { - enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]; int extension_flag, ret; + uint8_t layout_map[MAX_ELEM_ID*4][3]; + int tags = 0; if (get_bits1(gb)) { // frameLengthFlag av_log_missing_feature(avctx, "960/120 MDCT window is", 1); @@ -419,22 +605,23 @@ static int decode_ga_specific_config(AACContext *ac, AVCodecContext *avctx, m4ac->object_type == AOT_ER_AAC_SCALABLE) skip_bits(gb, 3); // layerNr - memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); if (channel_config == 0) { skip_bits(gb, 4); // element_instance_tag - if ((ret = decode_pce(avctx, m4ac, new_che_pos, gb))) - return ret; + tags = decode_pce(avctx, m4ac, layout_map, gb); + if (tags < 0) + return tags; } else { - if ((ret = set_default_channel_config(avctx, new_che_pos, channel_config))) + if ((ret = set_default_channel_config(avctx, layout_map, &tags, channel_config))) return ret; } - if (count_channels(new_che_pos) > 1) { + if (count_channels(layout_map, tags) > 1) { m4ac->ps = 0; } else if (m4ac->sbr == 1 && m4ac->ps == -1) m4ac->ps = 1; - if (ac && (ret = output_configure(ac, new_che_pos, channel_config, OC_GLOBAL_HDR))) + if (ac && (ret = output_configure(ac, layout_map, tags, + channel_config, OC_GLOBAL_HDR))) return ret; if (extension_flag) { @@ -588,7 +775,8 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) return -1; } else { int sr, i; - enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]; + uint8_t layout_map[MAX_ELEM_ID*4][3]; + int layout_map_tags; sr = sample_rate_idx(avctx->sample_rate); ac->m4ac.sampling_index = sr; @@ -605,9 +793,11 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) ac->m4ac.chan_config = i; if (ac->m4ac.chan_config) { - int ret = set_default_channel_config(avctx, new_che_pos, ac->m4ac.chan_config); + int ret = set_default_channel_config(avctx, layout_map, + &layout_map_tags, ac->m4ac.chan_config); if (!ret) - output_configure(ac, new_che_pos, ac->m4ac.chan_config, OC_GLOBAL_HDR); + output_configure(ac, layout_map, layout_map_tags, + ac->m4ac.chan_config, OC_GLOBAL_HDR); else if (avctx->err_recognition & AV_EF_EXPLODE) return AVERROR_INVALIDDATA; } @@ -1711,7 +1901,8 @@ static int decode_extension_payload(AACContext *ac, GetBitContext *gb, int cnt, } else if (ac->m4ac.ps == -1 && ac->output_configured < OC_LOCKED && ac->avctx->channels == 1) { ac->m4ac.sbr = 1; ac->m4ac.ps = 1; - output_configure(ac, NULL, ac->m4ac.chan_config, ac->output_configured); + output_configure(ac, ac->layout_map, ac->layout_map_tags, + ac->m4ac.chan_config, ac->output_configured); } else { ac->m4ac.sbr = 1; } @@ -2085,16 +2276,18 @@ static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb) { int size; AACADTSHeaderInfo hdr_info; + uint8_t layout_map[MAX_ELEM_ID*4][3]; + int layout_map_tags; size = avpriv_aac_parse_header(gb, &hdr_info); if (size > 0) { if (hdr_info.chan_config) { - enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]; - memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); ac->m4ac.chan_config = hdr_info.chan_config; - if (set_default_channel_config(ac->avctx, new_che_pos, hdr_info.chan_config)) + if (set_default_channel_config(ac->avctx, layout_map, + &layout_map_tags, hdr_info.chan_config)) return -7; - if (output_configure(ac, new_che_pos, hdr_info.chan_config, + if (output_configure(ac, layout_map, layout_map_tags, + hdr_info.chan_config, FFMAX(ac->output_configured, OC_TRIAL_FRAME))) return -7; } else if (ac->output_configured != OC_LOCKED) { @@ -2181,15 +2374,18 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data, break; case TYPE_PCE: { - enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]; - memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); - if ((err = decode_pce(avctx, &ac->m4ac, new_che_pos, gb))) + uint8_t layout_map[MAX_ELEM_ID*4][3]; + int tags; + tags = decode_pce(avctx, &ac->m4ac, layout_map, gb); + if (tags < 0) { + err = tags; break; + } if (ac->output_configured > OC_TRIAL_PCE) av_log(avctx, AV_LOG_ERROR, "Not evaluating a further program_config_element as this construct is dubious at best.\n"); else - err = output_configure(ac, new_che_pos, 0, OC_TRIAL_PCE); + err = output_configure(ac, layout_map, tags, 0, OC_TRIAL_PCE); break; } diff --git a/libavcodec/aacdectab.h b/libavcodec/aacdectab.h index 70372adf97..bd09b59b50 100644 --- a/libavcodec/aacdectab.h +++ b/libavcodec/aacdectab.h @@ -80,14 +80,14 @@ static const float * const tns_tmp2_map[4] = { static const int8_t tags_per_config[16] = { 0, 1, 1, 2, 3, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0 }; -static const uint8_t aac_channel_layout_map[7][5][2] = { - { { TYPE_SCE, 0 }, }, - { { TYPE_CPE, 0 }, }, - { { TYPE_CPE, 0 }, { TYPE_SCE, 0 }, }, - { { TYPE_CPE, 0 }, { TYPE_SCE, 0 }, { TYPE_SCE, 1 }, }, - { { TYPE_CPE, 0 }, { TYPE_SCE, 0 }, { TYPE_CPE, 1 }, }, - { { TYPE_CPE, 0 }, { TYPE_SCE, 0 }, { TYPE_LFE, 0 }, { TYPE_CPE, 1 }, }, - { { TYPE_CPE, 1 }, { TYPE_SCE, 0 }, { TYPE_LFE, 0 }, { TYPE_CPE, 2 }, { TYPE_CPE, 0 }, }, +static const uint8_t aac_channel_layout_map[7][5][3] = { + { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, }, + { { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, }, + { { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, }, + { { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_SCE, 1, AAC_CHANNEL_BACK }, }, + { { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_BACK }, }, + { { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_LFE, 0, AAC_CHANNEL_LFE }, { TYPE_CPE, 1, AAC_CHANNEL_BACK }, }, + { { TYPE_CPE, 1, AAC_CHANNEL_FRONT }, { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_LFE, 0, AAC_CHANNEL_LFE }, { TYPE_CPE, 2, AAC_CHANNEL_BACK }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, }, }; static const uint64_t aac_channel_layout[8] = { diff --git a/tests/fate/aac.mak b/tests/fate/aac.mak index ea87436698..0d4aa4a4fb 100644 --- a/tests/fate/aac.mak +++ b/tests/fate/aac.mak @@ -8,15 +8,15 @@ fate-aac-al05_44: REF = $(SAMPLES)/aac/al05_44.s16 FATE_AAC += fate-aac-al06_44 fate-aac-al06_44: CMD = pcm -i $(SAMPLES)/aac/al06_44.mp4 -fate-aac-al06_44: REF = $(SAMPLES)/aac/al06_44.s16 +fate-aac-al06_44: REF = $(SAMPLES)/aac/al06_44_reorder.s16 FATE_AAC += fate-aac-al07_96 fate-aac-al07_96: CMD = pcm -i $(SAMPLES)/aac/al07_96.mp4 -fate-aac-al07_96: REF = $(SAMPLES)/aac/al07_96.s16 +fate-aac-al07_96: REF = $(SAMPLES)/aac/al07_96_reorder.s16 FATE_AAC += fate-aac-al15_44 fate-aac-al15_44: CMD = pcm -i $(SAMPLES)/aac/al15_44.mp4 -fate-aac-al15_44: REF = $(SAMPLES)/aac/al15_44.s16 +fate-aac-al15_44: REF = $(SAMPLES)/aac/al15_44_reorder.s16 FATE_AAC += fate-aac-al17_44 fate-aac-al17_44: CMD = pcm -i $(SAMPLES)/aac/al17_44.mp4 @@ -32,7 +32,7 @@ fate-aac-am00_88: REF = $(SAMPLES)/aac/am00_88.s16 FATE_AAC += fate-aac-am05_44 fate-aac-am05_44: CMD = pcm -i $(SAMPLES)/aac/am05_44.mp4 -fate-aac-am05_44: REF = $(SAMPLES)/aac/am05_44.s16 +fate-aac-am05_44: REF = $(SAMPLES)/aac/am05_44_reorder.s16 FATE_AAC += fate-aac-al_sbr_hq_cm_48_2 fate-aac-al_sbr_hq_cm_48_2: CMD = pcm -i $(SAMPLES)/aac/al_sbr_cm_48_2.mp4 @@ -40,7 +40,7 @@ fate-aac-al_sbr_hq_cm_48_2: REF = $(SAMPLES)/aac/al_sbr_hq_cm_48_2.s16 FATE_AAC += fate-aac-al_sbr_hq_cm_48_5.1 fate-aac-al_sbr_hq_cm_48_5.1: CMD = pcm -i $(SAMPLES)/aac/al_sbr_cm_48_5.1.mp4 -fate-aac-al_sbr_hq_cm_48_5.1: REF = $(SAMPLES)/aac/al_sbr_hq_cm_48_5.1.s16 +fate-aac-al_sbr_hq_cm_48_5.1: REF = $(SAMPLES)/aac/al_sbr_hq_cm_48_5.1_reorder.s16 FATE_AAC += fate-aac-al_sbr_ps_06_ur fate-aac-al_sbr_ps_06_ur: CMD = pcm -i $(SAMPLES)/aac/al_sbr_ps_06_new.mp4 -- cgit v1.2.3 From f1ecd0802d5e81f9f8fac482bc0cd5ceb6b7755a Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Thu, 2 Feb 2012 18:59:15 -0800 Subject: aacdec: Support native channel layout when requested. --- libavcodec/aacdec.c | 14 +++++++++----- libavcodec/aacdectab.h | 10 +++++----- 2 files changed, 14 insertions(+), 10 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c index bef17ab68d..b3bbc4b162 100644 --- a/libavcodec/aacdec.c +++ b/libavcodec/aacdec.c @@ -416,11 +416,13 @@ static av_cold int output_configure(AACContext *ac, } if (channel_config) { + if (avctx->request_channel_layout != AV_CH_LAYOUT_NATIVE) + sniff_channel_order(layout_map, tags); for (i = 0; i < tags_per_config[channel_config]; i++) { - int type = aac_channel_layout_map[channel_config - 1][i][0]; - int id = aac_channel_layout_map[channel_config - 1][i][1]; - int positon = aac_channel_layout_map[channel_config - 1][i][2]; - if ((ret = che_configure(ac, positon, + int type = layout_map[i][0]; + int id = layout_map[i][1]; + int position = layout_map[i][2]; + if ((ret = che_configure(ac, position, type, id, &channels))) return ret; @@ -437,7 +439,9 @@ static av_cold int output_configure(AACContext *ac, * channels in the order the PCE declared them. */ - uint64_t layout = sniff_channel_order(layout_map, tags); + uint64_t layout = 0; + if (avctx->request_channel_layout != AV_CH_LAYOUT_NATIVE) + layout = sniff_channel_order(layout_map, tags); for (i = 0; i < tags; i++) { int type = layout_map[i][0]; int id = layout_map[i][1]; diff --git a/libavcodec/aacdectab.h b/libavcodec/aacdectab.h index bd09b59b50..844579fdee 100644 --- a/libavcodec/aacdectab.h +++ b/libavcodec/aacdectab.h @@ -83,11 +83,11 @@ static const int8_t tags_per_config[16] = { 0, 1, 1, 2, 3, 3, 4, 5, 0, 0, 0, 0, static const uint8_t aac_channel_layout_map[7][5][3] = { { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, }, { { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, }, - { { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, }, - { { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_SCE, 1, AAC_CHANNEL_BACK }, }, - { { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_BACK }, }, - { { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_LFE, 0, AAC_CHANNEL_LFE }, { TYPE_CPE, 1, AAC_CHANNEL_BACK }, }, - { { TYPE_CPE, 1, AAC_CHANNEL_FRONT }, { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_LFE, 0, AAC_CHANNEL_LFE }, { TYPE_CPE, 2, AAC_CHANNEL_BACK }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, }, + { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, }, + { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_SCE, 1, AAC_CHANNEL_BACK }, }, + { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_BACK }, }, + { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_BACK }, { TYPE_LFE, 0, AAC_CHANNEL_LFE }, }, + { { TYPE_SCE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 0, AAC_CHANNEL_FRONT }, { TYPE_CPE, 1, AAC_CHANNEL_FRONT }, { TYPE_CPE, 2, AAC_CHANNEL_BACK }, { TYPE_LFE, 0, AAC_CHANNEL_LFE }, }, }; static const uint64_t aac_channel_layout[8] = { -- cgit v1.2.3 From 7b05025856706ccc5da2e43f4f05c319907b3b16 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Wed, 8 Feb 2012 10:10:34 -0800 Subject: aacdec: Unify preconfigured layout and PCE layout. --- libavcodec/aacdec.c | 57 +++++++++++++++-------------------------------------- 1 file changed, 16 insertions(+), 41 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c index b3bbc4b162..1100a61d3e 100644 --- a/libavcodec/aacdec.c +++ b/libavcodec/aacdec.c @@ -409,56 +409,31 @@ static av_cold int output_configure(AACContext *ac, { AVCodecContext *avctx = ac->avctx; int i, channels = 0, ret; + uint64_t layout = 0; if (ac->layout_map != layout_map) { memcpy(ac->layout_map, layout_map, tags * sizeof(layout_map[0])); ac->layout_map_tags = tags; } - if (channel_config) { - if (avctx->request_channel_layout != AV_CH_LAYOUT_NATIVE) - sniff_channel_order(layout_map, tags); - for (i = 0; i < tags_per_config[channel_config]; i++) { - int type = layout_map[i][0]; - int id = layout_map[i][1]; - int position = layout_map[i][2]; - if ((ret = che_configure(ac, position, - type, id, - &channels))) - return ret; - } - - memset(ac->tag_che_map, 0, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0])); - - avctx->channel_layout = aac_channel_layout[channel_config - 1]; - } else { - /* Allocate or free elements depending on if they are in the - * current program configuration. - * - * Try to sniff a reasonable channel order, otherwise output the - * channels in the order the PCE declared them. - */ - - uint64_t layout = 0; - if (avctx->request_channel_layout != AV_CH_LAYOUT_NATIVE) - layout = sniff_channel_order(layout_map, tags); - for (i = 0; i < tags; i++) { - int type = layout_map[i][0]; - int id = layout_map[i][1]; - int position = layout_map[i][2]; - if ((ret = che_configure(ac, position, - type, id, - &channels))) - return ret; - } - - memcpy(ac->tag_che_map, ac->che, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0])); - - avctx->channel_layout = layout; + // Try to sniff a reasonable channel order, otherwise output the + // channels in the order the PCE declared them. + if (avctx->request_channel_layout != AV_CH_LAYOUT_NATIVE) + layout = sniff_channel_order(layout_map, tags); + for (i = 0; i < tags; i++) { + int type = layout_map[i][0]; + int id = layout_map[i][1]; + int position = layout_map[i][2]; + // Allocate or free elements depending on if they are in the + // current program configuration. + ret = che_configure(ac, position, type, id, &channels); + if (ret < 0) + return ret; } + memcpy(ac->tag_che_map, ac->che, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0])); + avctx->channel_layout = layout; avctx->channels = channels; - ac->output_configured = oc_type; return 0; -- cgit v1.2.3 From e6d9fa66f12cf5a3024c9bc7c4c608f7fc59207e Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Thu, 2 Feb 2012 22:27:27 -0500 Subject: ac3dec: Move center and surround mix level tables to the parser. That way all mix levels as exported by avpriv_ac3_parse_header() will have the same meaning. Previously the 3-bit center mix level for E-AC-3 was used to index in a 4-entry table, leading to out-of-array reads. Signed-off-by: Michael Niedermayer Signed-off-by: Justin Ruggles Signed-off-by: Alex Converse --- libavcodec/ac3_parser.c | 20 ++++++++++++++++---- libavcodec/ac3dec.c | 16 ++-------------- 2 files changed, 18 insertions(+), 18 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/ac3_parser.c b/libavcodec/ac3_parser.c index e3c46fd332..067b4f9879 100644 --- a/libavcodec/ac3_parser.c +++ b/libavcodec/ac3_parser.c @@ -34,6 +34,18 @@ static const uint8_t eac3_blocks[4] = { 1, 2, 3, 6 }; +/** + * Table for center mix levels + * reference: Section 5.4.2.4 cmixlev + */ +static const uint8_t center_levels[4] = { 4, 5, 6, 5 }; + +/** + * Table for surround mix levels + * reference: Section 5.4.2.5 surmixlev + */ +static const uint8_t surround_levels[4] = { 4, 6, 7, 6 }; + int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr) { @@ -53,8 +65,8 @@ int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr) hdr->num_blocks = 6; /* set default mix levels */ - hdr->center_mix_level = 1; // -4.5dB - hdr->surround_mix_level = 1; // -6.0dB + hdr->center_mix_level = 5; // -4.5dB + hdr->surround_mix_level = 6; // -6.0dB if(hdr->bitstream_id <= 10) { /* Normal AC-3 */ @@ -76,9 +88,9 @@ int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr) skip_bits(gbc, 2); // skip dsurmod } else { if((hdr->channel_mode & 1) && hdr->channel_mode != AC3_CHMODE_MONO) - hdr->center_mix_level = get_bits(gbc, 2); + hdr-> center_mix_level = center_levels[get_bits(gbc, 2)]; if(hdr->channel_mode & 4) - hdr->surround_mix_level = get_bits(gbc, 2); + hdr->surround_mix_level = surround_levels[get_bits(gbc, 2)]; } hdr->lfe_on = get_bits1(gbc); diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c index b50ec2abe6..66a9ea6299 100644 --- a/libavcodec/ac3dec.c +++ b/libavcodec/ac3dec.c @@ -76,18 +76,6 @@ static const float gain_levels[9] = { LEVEL_MINUS_9DB }; -/** - * Table for center mix levels - * reference: Section 5.4.2.4 cmixlev - */ -static const uint8_t center_levels[4] = { 4, 5, 6, 5 }; - -/** - * Table for surround mix levels - * reference: Section 5.4.2.5 surmixlev - */ -static const uint8_t surround_levels[4] = { 4, 6, 7, 6 }; - /** * Table for default stereo downmixing coefficients * reference: Section 7.8.2 Downmixing Into Two Channels @@ -315,8 +303,8 @@ static int parse_frame_header(AC3DecodeContext *s) static void set_downmix_coeffs(AC3DecodeContext *s) { int i; - float cmix = gain_levels[center_levels[s->center_mix_level]]; - float smix = gain_levels[surround_levels[s->surround_mix_level]]; + float cmix = gain_levels[s-> center_mix_level]; + float smix = gain_levels[s->surround_mix_level]; float norm0, norm1; for (i = 0; i < s->fbw_channels; i++) { -- cgit v1.2.3 From d483bb58c318b0a6152709cf28263d72200b98f9 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 9 Feb 2012 13:00:30 -0500 Subject: ac3dsp: do not use pshufb in ac3_extract_exponents_ssse3() We need to do unsigned saturation in order to cover the corner case when the absolute coefficient value is 16777215 (the maximum value). Fixes Bug #216 --- libavcodec/x86/ac3dsp.asm | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/x86/ac3dsp.asm b/libavcodec/x86/ac3dsp.asm index e1761fa806..746fd83a67 100644 --- a/libavcodec/x86/ac3dsp.asm +++ b/libavcodec/x86/ac3dsp.asm @@ -35,7 +35,6 @@ pw_bap_mul2: dw 5, 7, 0, 7, 5, 7, 0, 7 ; used in ff_ac3_extract_exponents() pd_1: times 4 dd 1 pd_151: times 4 dd 151 -pb_shuf_4dwb: db 0, 4, 8, 12 SECTION .text @@ -404,15 +403,12 @@ cglobal ac3_extract_exponents_3dnow, 3,3,0, exp, coef, len %endif %macro AC3_EXTRACT_EXPONENTS 1 -cglobal ac3_extract_exponents_%1, 3,3,5, exp, coef, len +cglobal ac3_extract_exponents_%1, 3,3,4, exp, coef, len add expq, lenq lea coefq, [coefq+4*lenq] neg lenq mova m2, [pd_1] mova m3, [pd_151] -%ifidn %1, ssse3 ; - movd m4, [pb_shuf_4dwb] -%endif .loop: ; move 4 32-bit coefs to xmm0 mova m0, [coefq+4*lenq] @@ -426,12 +422,11 @@ cglobal ac3_extract_exponents_%1, 3,3,5, exp, coef, len mova m0, m3 psubd m0, m1 ; move the lowest byte in each of 4 dwords to the low dword -%ifidn %1, ssse3 - pshufb m0, m4 -%else + ; NOTE: We cannot just extract the low bytes with pshufb because the dword + ; result for 16777215 is -1 due to float inaccuracy. Using packuswb + ; clips this to 0, which is the correct exponent. packssdw m0, m0 packuswb m0, m0 -%endif movd [expq+lenq], m0 add lenq, 4 -- cgit v1.2.3 From a75bc764ec89d800fa8d70662f16f89cdec17b49 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Mon, 6 Feb 2012 19:08:32 -0500 Subject: avcodec: for audio encoding, set packet dts to packet pts. There are no audio encoders which do frame reordering. --- avconv.c | 2 ++ libavcodec/utils.c | 16 +++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'libavcodec') diff --git a/avconv.c b/avconv.c index 57a4c926f3..418e1fde8b 100644 --- a/avconv.c +++ b/avconv.c @@ -991,6 +991,8 @@ static int encode_audio_frame(AVFormatContext *s, OutputStream *ost, if (got_packet) { if (pkt.pts != AV_NOPTS_VALUE) pkt.pts = av_rescale_q(pkt.pts, enc->time_base, ost->st->time_base); + if (pkt.dts != AV_NOPTS_VALUE) + pkt.dts = av_rescale_q(pkt.dts, enc->time_base, ost->st->time_base); if (pkt.duration > 0) pkt.duration = av_rescale_q(pkt.duration, enc->time_base, ost->st->time_base); diff --git a/libavcodec/utils.c b/libavcodec/utils.c index c890cf96e9..9dded6ae05 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -873,12 +873,14 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, if (avctx->codec->encode2) { *got_packet_ptr = 0; ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr); - if (!ret && *got_packet_ptr && - !(avctx->codec->capabilities & CODEC_CAP_DELAY)) { - avpkt->pts = frame->pts; - avpkt->duration = av_rescale_q(frame->nb_samples, - (AVRational){ 1, avctx->sample_rate }, - avctx->time_base); + if (!ret && *got_packet_ptr) { + if (!(avctx->codec->capabilities & CODEC_CAP_DELAY)) { + avpkt->pts = frame->pts; + avpkt->duration = av_rescale_q(frame->nb_samples, + (AVRational){ 1, avctx->sample_rate }, + avctx->time_base); + } + avpkt->dts = avpkt->pts; } } else { /* for compatibility with encoders not supporting encode2(), we need to @@ -925,7 +927,7 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, av_freep(&avpkt->data); } else { if (avctx->coded_frame) - avpkt->pts = avctx->coded_frame->pts; + avpkt->pts = avpkt->dts = avctx->coded_frame->pts; /* Set duration for final small packet. This can be removed once all encoders supporting CODEC_CAP_SMALL_LAST_FRAME use encode2() */ -- cgit v1.2.3 From b758cf7343d169afaa79a62b8a47af9ced04be27 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Tue, 7 Feb 2012 14:31:49 -0500 Subject: avcodec: set avpkt->size to 0 if encode2() did not output a packet --- libavcodec/utils.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libavcodec') diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 9dded6ae05..de3816b27f 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -881,6 +881,8 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, avctx->time_base); } avpkt->dts = avpkt->pts; + } else { + avpkt->size = 0; } } else { /* for compatibility with encoders not supporting encode2(), we need to -- cgit v1.2.3 From 37460727124df4110bc6ed392f996f0ca352f6d6 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Thu, 9 Feb 2012 17:44:47 -0800 Subject: dv: Split dvdata.h into dvdata.h and dvquant.h --- libavcodec/dv.c | 1 + libavcodec/dvdata.h | 125 ---------------------------------------- libavcodec/dvquant.h | 157 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+), 125 deletions(-) create mode 100644 libavcodec/dvquant.h (limited to 'libavcodec') diff --git a/libavcodec/dv.c b/libavcodec/dv.c index 74cbffb672..def0bef8c0 100644 --- a/libavcodec/dv.c +++ b/libavcodec/dv.c @@ -45,6 +45,7 @@ #include "put_bits.h" #include "simple_idct.h" #include "dvdata.h" +#include "dvquant.h" #include "dv_tablegen.h" //#undef NDEBUG diff --git a/libavcodec/dvdata.h b/libavcodec/dvdata.h index b2fb127ae6..21e15767bf 100644 --- a/libavcodec/dvdata.h +++ b/libavcodec/dvdata.h @@ -65,131 +65,6 @@ typedef struct DVprofile { const uint8_t (*audio_shuffle)[9]; /* PCM shuffling table */ } DVprofile; -/* unquant tables (not used directly) */ -static const uint8_t dv_quant_shifts[22][4] = { - { 3,3,4,4 }, - { 3,3,4,4 }, - { 2,3,3,4 }, - { 2,3,3,4 }, - { 2,2,3,3 }, - { 2,2,3,3 }, - { 1,2,2,3 }, - { 1,2,2,3 }, - { 1,1,2,2 }, - { 1,1,2,2 }, - { 0,1,1,2 }, - { 0,1,1,2 }, - { 0,0,1,1 }, - { 0,0,1,1 }, - { 0,0,0,1 }, - { 0,0,0,0 }, - { 0,0,0,0 }, - { 0,0,0,0 }, - { 0,0,0,0 }, - { 0,0,0,0 }, - { 0,0,0,0 }, - { 0,0,0,0 }, -}; - -static const uint8_t dv_quant_offset[4] = { 6, 3, 0, 1 }; -static const uint8_t dv_quant_areas[4] = { 6, 21, 43, 64 }; - -/* quantization quanta by QNO for DV100 */ -static const uint8_t dv100_qstep[16] = { - 1, /* QNO = 0 and 1 both have no quantization */ - 1, - 2, 3, 4, 5, 6, 7, 8, 16, 18, 20, 22, 24, 28, 52 -}; - -/* DV25/50 DCT coefficient weights and inverse weights */ -/* created by dvtables.py */ -static const int dv_weight_bits = 18; -static const int dv_weight_88[64] = { - 131072, 257107, 257107, 242189, 252167, 242189, 235923, 237536, - 237536, 235923, 229376, 231390, 223754, 231390, 229376, 222935, - 224969, 217965, 217965, 224969, 222935, 200636, 218652, 211916, - 212325, 211916, 218652, 200636, 188995, 196781, 205965, 206433, - 206433, 205965, 196781, 188995, 185364, 185364, 200636, 200704, - 200636, 185364, 185364, 174609, 180568, 195068, 195068, 180568, - 174609, 170091, 175557, 189591, 175557, 170091, 165371, 170627, - 170627, 165371, 160727, 153560, 160727, 144651, 144651, 136258, -}; -static const int dv_weight_248[64] = { - 131072, 242189, 257107, 237536, 229376, 200636, 242189, 223754, - 224969, 196781, 262144, 242189, 229376, 200636, 257107, 237536, - 211916, 185364, 235923, 217965, 229376, 211916, 206433, 180568, - 242189, 223754, 224969, 196781, 211916, 185364, 235923, 217965, - 200704, 175557, 222935, 205965, 200636, 185364, 195068, 170627, - 229376, 211916, 206433, 180568, 200704, 175557, 222935, 205965, - 175557, 153560, 188995, 174609, 165371, 144651, 200636, 185364, - 195068, 170627, 175557, 153560, 188995, 174609, 165371, 144651, -}; -static const int dv_iweight_bits = 14; -static const int dv_iweight_88[64] = { - 32768, 16710, 16710, 17735, 17015, 17735, 18197, 18079, - 18079, 18197, 18725, 18559, 19196, 18559, 18725, 19284, - 19108, 19692, 19692, 19108, 19284, 21400, 19645, 20262, - 20214, 20262, 19645, 21400, 22733, 21845, 20867, 20815, - 20815, 20867, 21845, 22733, 23173, 23173, 21400, 21400, - 21400, 23173, 23173, 24600, 23764, 22017, 22017, 23764, - 24600, 25267, 24457, 22672, 24457, 25267, 25971, 25191, - 25191, 25971, 26715, 27962, 26715, 29642, 29642, 31536, -}; -static const int dv_iweight_248[64] = { - 32768, 17735, 16710, 18079, 18725, 21400, 17735, 19196, - 19108, 21845, 16384, 17735, 18725, 21400, 16710, 18079, - 20262, 23173, 18197, 19692, 18725, 20262, 20815, 23764, - 17735, 19196, 19108, 21845, 20262, 23173, 18197, 19692, - 21400, 24457, 19284, 20867, 21400, 23173, 22017, 25191, - 18725, 20262, 20815, 23764, 21400, 24457, 19284, 20867, - 24457, 27962, 22733, 24600, 25971, 29642, 21400, 23173, - 22017, 25191, 24457, 27962, 22733, 24600, 25971, 29642, -}; - -/** - * The "inverse" DV100 weights are actually just the spec weights (zig-zagged). - */ -static const int dv_iweight_1080_y[64] = { - 128, 16, 16, 17, 17, 17, 18, 18, - 18, 18, 18, 18, 19, 18, 18, 19, - 19, 19, 19, 19, 19, 42, 38, 40, - 40, 40, 38, 42, 44, 43, 41, 41, - 41, 41, 43, 44, 45, 45, 42, 42, - 42, 45, 45, 48, 46, 43, 43, 46, - 48, 49, 48, 44, 48, 49, 101, 98, - 98, 101, 104, 109, 104, 116, 116, 123, -}; -static const int dv_iweight_1080_c[64] = { - 128, 16, 16, 17, 17, 17, 25, 25, - 25, 25, 26, 25, 26, 25, 26, 26, - 26, 27, 27, 26, 26, 42, 38, 40, - 40, 40, 38, 42, 44, 43, 41, 41, - 41, 41, 43, 44, 91, 91, 84, 84, - 84, 91, 91, 96, 93, 86, 86, 93, - 96, 197, 191, 177, 191, 197, 203, 197, - 197, 203, 209, 219, 209, 232, 232, 246, -}; -static const int dv_iweight_720_y[64] = { - 128, 16, 16, 17, 17, 17, 18, 18, - 18, 18, 18, 18, 19, 18, 18, 19, - 19, 19, 19, 19, 19, 42, 38, 40, - 40, 40, 38, 42, 44, 43, 41, 41, - 41, 41, 43, 44, 68, 68, 63, 63, - 63, 68, 68, 96, 92, 86, 86, 92, - 96, 98, 96, 88, 96, 98, 202, 196, - 196, 202, 208, 218, 208, 232, 232, 246, -}; -static const int dv_iweight_720_c[64] = { - 128, 24, 24, 26, 26, 26, 36, 36, - 36, 36, 36, 36, 38, 36, 36, 38, - 38, 38, 38, 38, 38, 84, 76, 80, - 80, 80, 76, 84, 88, 86, 82, 82, - 82, 82, 86, 88, 182, 182, 168, 168, - 168, 182, 182, 192, 186, 192, 172, 186, - 192, 394, 382, 354, 382, 394, 406, 394, - 394, 406, 418, 438, 418, 464, 464, 492, -}; - static const uint8_t dv_audio_shuffle525[10][9] = { { 0, 30, 60, 20, 50, 80, 10, 40, 70 }, /* 1st channel */ { 6, 36, 66, 26, 56, 86, 16, 46, 76 }, diff --git a/libavcodec/dvquant.h b/libavcodec/dvquant.h new file mode 100644 index 0000000000..7bd0cdc01a --- /dev/null +++ b/libavcodec/dvquant.h @@ -0,0 +1,157 @@ +/* + * Quant and Weight for DV codec + * Copyright (c) 2002 Fabrice Bellard + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * Constants for DV codec. + */ + +#ifndef AVCODEC_DVQUANT_H +#define AVCODEC_DVQUANT_H + +#include + +/* unquant tables (not used directly) */ +static const uint8_t dv_quant_shifts[22][4] = { + { 3,3,4,4 }, + { 3,3,4,4 }, + { 2,3,3,4 }, + { 2,3,3,4 }, + { 2,2,3,3 }, + { 2,2,3,3 }, + { 1,2,2,3 }, + { 1,2,2,3 }, + { 1,1,2,2 }, + { 1,1,2,2 }, + { 0,1,1,2 }, + { 0,1,1,2 }, + { 0,0,1,1 }, + { 0,0,1,1 }, + { 0,0,0,1 }, + { 0,0,0,0 }, + { 0,0,0,0 }, + { 0,0,0,0 }, + { 0,0,0,0 }, + { 0,0,0,0 }, + { 0,0,0,0 }, + { 0,0,0,0 }, +}; + +static const uint8_t dv_quant_offset[4] = { 6, 3, 0, 1 }; +static const uint8_t dv_quant_areas[4] = { 6, 21, 43, 64 }; + +/* quantization quanta by QNO for DV100 */ +static const uint8_t dv100_qstep[16] = { + 1, /* QNO = 0 and 1 both have no quantization */ + 1, + 2, 3, 4, 5, 6, 7, 8, 16, 18, 20, 22, 24, 28, 52 +}; + +/* DV25/50 DCT coefficient weights and inverse weights */ +/* created by dvtables.py */ +static const int dv_weight_bits = 18; +static const int dv_weight_88[64] = { + 131072, 257107, 257107, 242189, 252167, 242189, 235923, 237536, + 237536, 235923, 229376, 231390, 223754, 231390, 229376, 222935, + 224969, 217965, 217965, 224969, 222935, 200636, 218652, 211916, + 212325, 211916, 218652, 200636, 188995, 196781, 205965, 206433, + 206433, 205965, 196781, 188995, 185364, 185364, 200636, 200704, + 200636, 185364, 185364, 174609, 180568, 195068, 195068, 180568, + 174609, 170091, 175557, 189591, 175557, 170091, 165371, 170627, + 170627, 165371, 160727, 153560, 160727, 144651, 144651, 136258, +}; +static const int dv_weight_248[64] = { + 131072, 242189, 257107, 237536, 229376, 200636, 242189, 223754, + 224969, 196781, 262144, 242189, 229376, 200636, 257107, 237536, + 211916, 185364, 235923, 217965, 229376, 211916, 206433, 180568, + 242189, 223754, 224969, 196781, 211916, 185364, 235923, 217965, + 200704, 175557, 222935, 205965, 200636, 185364, 195068, 170627, + 229376, 211916, 206433, 180568, 200704, 175557, 222935, 205965, + 175557, 153560, 188995, 174609, 165371, 144651, 200636, 185364, + 195068, 170627, 175557, 153560, 188995, 174609, 165371, 144651, +}; +static const int dv_iweight_bits = 14; +static const int dv_iweight_88[64] = { + 32768, 16710, 16710, 17735, 17015, 17735, 18197, 18079, + 18079, 18197, 18725, 18559, 19196, 18559, 18725, 19284, + 19108, 19692, 19692, 19108, 19284, 21400, 19645, 20262, + 20214, 20262, 19645, 21400, 22733, 21845, 20867, 20815, + 20815, 20867, 21845, 22733, 23173, 23173, 21400, 21400, + 21400, 23173, 23173, 24600, 23764, 22017, 22017, 23764, + 24600, 25267, 24457, 22672, 24457, 25267, 25971, 25191, + 25191, 25971, 26715, 27962, 26715, 29642, 29642, 31536, +}; +static const int dv_iweight_248[64] = { + 32768, 17735, 16710, 18079, 18725, 21400, 17735, 19196, + 19108, 21845, 16384, 17735, 18725, 21400, 16710, 18079, + 20262, 23173, 18197, 19692, 18725, 20262, 20815, 23764, + 17735, 19196, 19108, 21845, 20262, 23173, 18197, 19692, + 21400, 24457, 19284, 20867, 21400, 23173, 22017, 25191, + 18725, 20262, 20815, 23764, 21400, 24457, 19284, 20867, + 24457, 27962, 22733, 24600, 25971, 29642, 21400, 23173, + 22017, 25191, 24457, 27962, 22733, 24600, 25971, 29642, +}; + +/** + * The "inverse" DV100 weights are actually just the spec weights (zig-zagged). + */ +static const int dv_iweight_1080_y[64] = { + 128, 16, 16, 17, 17, 17, 18, 18, + 18, 18, 18, 18, 19, 18, 18, 19, + 19, 19, 19, 19, 19, 42, 38, 40, + 40, 40, 38, 42, 44, 43, 41, 41, + 41, 41, 43, 44, 45, 45, 42, 42, + 42, 45, 45, 48, 46, 43, 43, 46, + 48, 49, 48, 44, 48, 49, 101, 98, + 98, 101, 104, 109, 104, 116, 116, 123, +}; +static const int dv_iweight_1080_c[64] = { + 128, 16, 16, 17, 17, 17, 25, 25, + 25, 25, 26, 25, 26, 25, 26, 26, + 26, 27, 27, 26, 26, 42, 38, 40, + 40, 40, 38, 42, 44, 43, 41, 41, + 41, 41, 43, 44, 91, 91, 84, 84, + 84, 91, 91, 96, 93, 86, 86, 93, + 96, 197, 191, 177, 191, 197, 203, 197, + 197, 203, 209, 219, 209, 232, 232, 246, +}; +static const int dv_iweight_720_y[64] = { + 128, 16, 16, 17, 17, 17, 18, 18, + 18, 18, 18, 18, 19, 18, 18, 19, + 19, 19, 19, 19, 19, 42, 38, 40, + 40, 40, 38, 42, 44, 43, 41, 41, + 41, 41, 43, 44, 68, 68, 63, 63, + 63, 68, 68, 96, 92, 86, 86, 92, + 96, 98, 96, 88, 96, 98, 202, 196, + 196, 202, 208, 218, 208, 232, 232, 246, +}; +static const int dv_iweight_720_c[64] = { + 128, 24, 24, 26, 26, 26, 36, 36, + 36, 36, 36, 36, 38, 36, 36, 38, + 38, 38, 38, 38, 38, 84, 76, 80, + 80, 80, 76, 84, 88, 86, 82, 82, + 82, 82, 86, 88, 182, 182, 168, 168, + 168, 182, 182, 192, 186, 192, 172, 186, + 192, 394, 382, 354, 382, 394, 406, 394, + 394, 406, 418, 438, 418, 464, 464, 492, +}; + +#endif /* AVCODEC_DVQUANT_H */ -- cgit v1.2.3 From 89c9a8d3fdaef610f276e28f02cc46c581d05ef0 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Thu, 9 Feb 2012 17:49:57 -0800 Subject: dv: Move functions used only by the encoder out of a shared header. --- libavcodec/dv.c | 35 +++++++++++++++++++++++++++++++++++ libavcodec/dvdata.h | 35 ----------------------------------- 2 files changed, 35 insertions(+), 35 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/dv.c b/libavcodec/dv.c index def0bef8c0..db231fb2bb 100644 --- a/libavcodec/dv.c +++ b/libavcodec/dv.c @@ -1190,6 +1190,41 @@ static inline int dv_write_pack(enum dv_pack_type pack_id, DVVideoContext *c, } #if CONFIG_DVVIDEO_ENCODER +static inline int dv_write_dif_id(enum dv_section_type t, uint8_t chan_num, + uint8_t seq_num, uint8_t dif_num, + uint8_t* buf) +{ + buf[0] = (uint8_t)t; /* Section type */ + buf[1] = (seq_num << 4) | /* DIF seq number 0-9 for 525/60; 0-11 for 625/50 */ + (chan_num << 3) | /* FSC: for 50Mb/s 0 - first channel; 1 - second */ + 7; /* reserved -- always 1 */ + buf[2] = dif_num; /* DIF block number Video: 0-134, Audio: 0-8 */ + return 3; +} + + +static inline int dv_write_ssyb_id(uint8_t syb_num, uint8_t fr, uint8_t* buf) +{ + if (syb_num == 0 || syb_num == 6) { + buf[0] = (fr << 7) | /* FR ID 1 - first half of each channel; 0 - second */ + (0 << 4) | /* AP3 (Subcode application ID) */ + 0x0f; /* reserved -- always 1 */ + } + else if (syb_num == 11) { + buf[0] = (fr << 7) | /* FR ID 1 - first half of each channel; 0 - second */ + 0x7f; /* reserved -- always 1 */ + } + else { + buf[0] = (fr << 7) | /* FR ID 1 - first half of each channel; 0 - second */ + (0 << 4) | /* APT (Track application ID) */ + 0x0f; /* reserved -- always 1 */ + } + buf[1] = 0xf0 | /* reserved -- always 1 */ + (syb_num & 0x0f); /* SSYB number 0 - 11 */ + buf[2] = 0xff; /* reserved -- always 1 */ + return 3; +} + static void dv_format_frame(DVVideoContext* c, uint8_t* buf) { int chan, i, j, k; diff --git a/libavcodec/dvdata.h b/libavcodec/dvdata.h index 21e15767bf..90ef7ed1df 100644 --- a/libavcodec/dvdata.h +++ b/libavcodec/dvdata.h @@ -153,39 +153,4 @@ const DVprofile* avpriv_dv_frame_profile(const DVprofile *sys, const uint8_t* frame, unsigned buf_size); const DVprofile* avpriv_dv_codec_profile(AVCodecContext* codec); -static inline int dv_write_dif_id(enum dv_section_type t, uint8_t chan_num, - uint8_t seq_num, uint8_t dif_num, - uint8_t* buf) -{ - buf[0] = (uint8_t)t; /* Section type */ - buf[1] = (seq_num << 4) | /* DIF seq number 0-9 for 525/60; 0-11 for 625/50 */ - (chan_num << 3) | /* FSC: for 50Mb/s 0 - first channel; 1 - second */ - 7; /* reserved -- always 1 */ - buf[2] = dif_num; /* DIF block number Video: 0-134, Audio: 0-8 */ - return 3; -} - - -static inline int dv_write_ssyb_id(uint8_t syb_num, uint8_t fr, uint8_t* buf) -{ - if (syb_num == 0 || syb_num == 6) { - buf[0] = (fr << 7) | /* FR ID 1 - first half of each channel; 0 - second */ - (0 << 4) | /* AP3 (Subcode application ID) */ - 0x0f; /* reserved -- always 1 */ - } - else if (syb_num == 11) { - buf[0] = (fr << 7) | /* FR ID 1 - first half of each channel; 0 - second */ - 0x7f; /* reserved -- always 1 */ - } - else { - buf[0] = (fr << 7) | /* FR ID 1 - first half of each channel; 0 - second */ - (0 << 4) | /* APT (Track application ID) */ - 0x0f; /* reserved -- always 1 */ - } - buf[1] = 0xf0 | /* reserved -- always 1 */ - (syb_num & 0x0f); /* SSYB number 0 - 11 */ - buf[2] = 0xff; /* reserved -- always 1 */ - return 3; -} - #endif /* AVCODEC_DVDATA_H */ -- cgit v1.2.3 From 8dbdc2d8407e8e3f4ca0e75b8684b8fc81fd4bcd Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Thu, 9 Feb 2012 17:53:05 -0800 Subject: dv: Move a table used only by the demuxer out of a shared header. --- libavcodec/dvdata.h | 4 ---- libavformat/dv.c | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/dvdata.h b/libavcodec/dvdata.h index 90ef7ed1df..46976f954a 100644 --- a/libavcodec/dvdata.h +++ b/libavcodec/dvdata.h @@ -95,10 +95,6 @@ static const uint8_t dv_audio_shuffle625[12][9] = { { 31, 67, 103, 21, 57, 93, 11, 47, 83}, }; -static const av_unused int dv_audio_frequency[3] = { - 48000, 44100, 32000, -}; - /* macroblock bit budgets */ static const uint8_t block_sizes_dv2550[8] = { 112, 112, 112, 112, 80, 80, 0, 0, diff --git a/libavformat/dv.c b/libavformat/dv.c index 0201a80b31..769f6b74f4 100644 --- a/libavformat/dv.c +++ b/libavformat/dv.c @@ -94,6 +94,10 @@ static const uint8_t* dv_extract_pack(uint8_t* frame, enum dv_pack_type t) return frame[offs] == t ? &frame[offs] : NULL; } +static const int dv_audio_frequency[3] = { + 48000, 44100, 32000, +}; + /* * There's a couple of assumptions being made here: * 1. By default we silence erroneous (0x8000/16bit 0x800/12bit) audio samples. -- cgit v1.2.3 From 81749f30cd84b35f774d7d1bbe6bf3f96e2362c8 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Thu, 9 Feb 2012 17:56:29 -0800 Subject: dv: Move tables from dvdata.h to dvdata.c --- libavcodec/dvdata.c | 38 ++++++++++++++++++++++++++++++++++++++ libavcodec/dvdata.h | 39 --------------------------------------- 2 files changed, 38 insertions(+), 39 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/dvdata.c b/libavcodec/dvdata.c index a2d89399f5..e9929d0997 100644 --- a/libavcodec/dvdata.c +++ b/libavcodec/dvdata.c @@ -42,6 +42,44 @@ static uint32_t dv_idct_factor_sd [2*2*22*64]; static uint32_t dv_idct_factor_hd1080[2*4*16*64]; static uint32_t dv_idct_factor_hd720 [2*4*16*64]; +static const uint8_t dv_audio_shuffle525[10][9] = { + { 0, 30, 60, 20, 50, 80, 10, 40, 70 }, /* 1st channel */ + { 6, 36, 66, 26, 56, 86, 16, 46, 76 }, + { 12, 42, 72, 2, 32, 62, 22, 52, 82 }, + { 18, 48, 78, 8, 38, 68, 28, 58, 88 }, + { 24, 54, 84, 14, 44, 74, 4, 34, 64 }, + + { 1, 31, 61, 21, 51, 81, 11, 41, 71 }, /* 2nd channel */ + { 7, 37, 67, 27, 57, 87, 17, 47, 77 }, + { 13, 43, 73, 3, 33, 63, 23, 53, 83 }, + { 19, 49, 79, 9, 39, 69, 29, 59, 89 }, + { 25, 55, 85, 15, 45, 75, 5, 35, 65 }, +}; + +static const uint8_t dv_audio_shuffle625[12][9] = { + { 0, 36, 72, 26, 62, 98, 16, 52, 88}, /* 1st channel */ + { 6, 42, 78, 32, 68, 104, 22, 58, 94}, + { 12, 48, 84, 2, 38, 74, 28, 64, 100}, + { 18, 54, 90, 8, 44, 80, 34, 70, 106}, + { 24, 60, 96, 14, 50, 86, 4, 40, 76}, + { 30, 66, 102, 20, 56, 92, 10, 46, 82}, + + { 1, 37, 73, 27, 63, 99, 17, 53, 89}, /* 2nd channel */ + { 7, 43, 79, 33, 69, 105, 23, 59, 95}, + { 13, 49, 85, 3, 39, 75, 29, 65, 101}, + { 19, 55, 91, 9, 45, 81, 35, 71, 107}, + { 25, 61, 97, 15, 51, 87, 5, 41, 77}, + { 31, 67, 103, 21, 57, 93, 11, 47, 83}, +}; + +/* macroblock bit budgets */ +static const uint8_t block_sizes_dv2550[8] = { + 112, 112, 112, 112, 80, 80, 0, 0, +}; + +static const uint8_t block_sizes_dv100[8] = { + 80, 80, 80, 80, 80, 80, 64, 64, +}; static const DVprofile dv_profiles[] = { { .dsf = 0, .video_stype = 0x0, diff --git a/libavcodec/dvdata.h b/libavcodec/dvdata.h index 46976f954a..d729b4dff5 100644 --- a/libavcodec/dvdata.h +++ b/libavcodec/dvdata.h @@ -65,45 +65,6 @@ typedef struct DVprofile { const uint8_t (*audio_shuffle)[9]; /* PCM shuffling table */ } DVprofile; -static const uint8_t dv_audio_shuffle525[10][9] = { - { 0, 30, 60, 20, 50, 80, 10, 40, 70 }, /* 1st channel */ - { 6, 36, 66, 26, 56, 86, 16, 46, 76 }, - { 12, 42, 72, 2, 32, 62, 22, 52, 82 }, - { 18, 48, 78, 8, 38, 68, 28, 58, 88 }, - { 24, 54, 84, 14, 44, 74, 4, 34, 64 }, - - { 1, 31, 61, 21, 51, 81, 11, 41, 71 }, /* 2nd channel */ - { 7, 37, 67, 27, 57, 87, 17, 47, 77 }, - { 13, 43, 73, 3, 33, 63, 23, 53, 83 }, - { 19, 49, 79, 9, 39, 69, 29, 59, 89 }, - { 25, 55, 85, 15, 45, 75, 5, 35, 65 }, -}; - -static const uint8_t dv_audio_shuffle625[12][9] = { - { 0, 36, 72, 26, 62, 98, 16, 52, 88}, /* 1st channel */ - { 6, 42, 78, 32, 68, 104, 22, 58, 94}, - { 12, 48, 84, 2, 38, 74, 28, 64, 100}, - { 18, 54, 90, 8, 44, 80, 34, 70, 106}, - { 24, 60, 96, 14, 50, 86, 4, 40, 76}, - { 30, 66, 102, 20, 56, 92, 10, 46, 82}, - - { 1, 37, 73, 27, 63, 99, 17, 53, 89}, /* 2nd channel */ - { 7, 43, 79, 33, 69, 105, 23, 59, 95}, - { 13, 49, 85, 3, 39, 75, 29, 65, 101}, - { 19, 55, 91, 9, 45, 81, 35, 71, 107}, - { 25, 61, 97, 15, 51, 87, 5, 41, 77}, - { 31, 67, 103, 21, 57, 93, 11, 47, 83}, -}; - -/* macroblock bit budgets */ -static const uint8_t block_sizes_dv2550[8] = { - 112, 112, 112, 112, 80, 80, 0, 0, -}; - -static const uint8_t block_sizes_dv100[8] = { - 80, 80, 80, 80, 80, 80, 64, 64, -}; - enum dv_section_type { dv_sect_header = 0x1f, dv_sect_subcode = 0x3f, -- cgit v1.2.3 From 45b7bd7c53b41bc5ff6fc2158831f2b1b1256113 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Thu, 9 Feb 2012 22:57:01 -0800 Subject: h264: disallow constrained intra prediction modes for luma. Conversion of the luma intra prediction mode to one of the constrained ("alzheimer") ones can happen by crafting special bitstreams, causing a crash because we'll call a NULL function pointer for 16x16 block intra prediction, since constrained intra prediction functions are only implemented for chroma (8x8 blocks). Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind CC: libav-stable@libav.org --- libavcodec/h264.c | 4 ++-- libavcodec/h264.h | 2 +- libavcodec/h264_cabac.c | 4 ++-- libavcodec/h264_cavlc.c | 4 ++-- libavcodec/svq3.c | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/h264.c b/libavcodec/h264.c index cf409c0978..a80183b4a1 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -105,7 +105,7 @@ int ff_h264_check_intra4x4_pred_mode(H264Context *h){ * Check if the top & left blocks are available if needed and * change the dc mode so it only uses the available blocks. */ -int ff_h264_check_intra_pred_mode(H264Context *h, int mode){ +int ff_h264_check_intra_pred_mode(H264Context *h, int mode, int is_chroma){ MpegEncContext * const s = &h->s; static const int8_t top [7]= {LEFT_DC_PRED8x8, 1,-1,-1}; static const int8_t left[7]= { TOP_DC_PRED8x8,-1, 2,-1,DC_128_PRED8x8}; @@ -125,7 +125,7 @@ int ff_h264_check_intra_pred_mode(H264Context *h, int mode){ if((h->left_samples_available&0x8080) != 0x8080){ mode= left[ mode ]; - if(h->left_samples_available&0x8080){ //mad cow disease mode, aka MBAFF + constrained_intra_pred + if(is_chroma && (h->left_samples_available&0x8080)){ //mad cow disease mode, aka MBAFF + constrained_intra_pred mode= ALZHEIMER_DC_L0T_PRED8x8 + (!(h->left_samples_available&0x8000)) + 2*(mode == DC_128_PRED8x8); } if(mode<0){ diff --git a/libavcodec/h264.h b/libavcodec/h264.h index 50255389fa..8680f5fdbd 100644 --- a/libavcodec/h264.h +++ b/libavcodec/h264.h @@ -657,7 +657,7 @@ int ff_h264_check_intra4x4_pred_mode(H264Context *h); /** * Check if the top & left blocks are available if needed & change the dc mode so it only uses the available blocks. */ -int ff_h264_check_intra_pred_mode(H264Context *h, int mode); +int ff_h264_check_intra_pred_mode(H264Context *h, int mode, int is_chroma); void ff_h264_hl_decode_mb(H264Context *h); int ff_h264_frame_start(H264Context *h); diff --git a/libavcodec/h264_cabac.c b/libavcodec/h264_cabac.c index a49ac6d498..75fb02cb63 100644 --- a/libavcodec/h264_cabac.c +++ b/libavcodec/h264_cabac.c @@ -2040,14 +2040,14 @@ decode_intra_mb: write_back_intra_pred_mode(h); if( ff_h264_check_intra4x4_pred_mode(h) < 0 ) return -1; } else { - h->intra16x16_pred_mode= ff_h264_check_intra_pred_mode( h, h->intra16x16_pred_mode ); + h->intra16x16_pred_mode= ff_h264_check_intra_pred_mode( h, h->intra16x16_pred_mode, 0 ); if( h->intra16x16_pred_mode < 0 ) return -1; } if(decode_chroma){ h->chroma_pred_mode_table[mb_xy] = pred_mode = decode_cabac_mb_chroma_pre_mode( h ); - pred_mode= ff_h264_check_intra_pred_mode( h, pred_mode ); + pred_mode= ff_h264_check_intra_pred_mode( h, pred_mode, 1 ); if( pred_mode < 0 ) return -1; h->chroma_pred_mode= pred_mode; } else { diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c index fdb7ab5709..a5b6403446 100644 --- a/libavcodec/h264_cavlc.c +++ b/libavcodec/h264_cavlc.c @@ -822,12 +822,12 @@ decode_intra_mb: if( ff_h264_check_intra4x4_pred_mode(h) < 0) return -1; }else{ - h->intra16x16_pred_mode= ff_h264_check_intra_pred_mode(h, h->intra16x16_pred_mode); + h->intra16x16_pred_mode= ff_h264_check_intra_pred_mode(h, h->intra16x16_pred_mode, 0); if(h->intra16x16_pred_mode < 0) return -1; } if(decode_chroma){ - pred_mode= ff_h264_check_intra_pred_mode(h, get_ue_golomb_31(&s->gb)); + pred_mode= ff_h264_check_intra_pred_mode(h, get_ue_golomb_31(&s->gb), 1); if(pred_mode < 0) return -1; h->chroma_pred_mode= pred_mode; diff --git a/libavcodec/svq3.c b/libavcodec/svq3.c index 3cd95ba594..5cc57a745d 100644 --- a/libavcodec/svq3.c +++ b/libavcodec/svq3.c @@ -612,7 +612,7 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type) dir = i_mb_type_info[mb_type - 8].pred_mode; dir = (dir >> 1) ^ 3*(dir & 1) ^ 1; - if ((h->intra16x16_pred_mode = ff_h264_check_intra_pred_mode(h, dir)) == -1){ + if ((h->intra16x16_pred_mode = ff_h264_check_intra_pred_mode(h, dir, 0)) == -1){ av_log(h->s.avctx, AV_LOG_ERROR, "check_intra_pred_mode = -1\n"); return -1; } @@ -711,7 +711,7 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type) s->current_picture.f.mb_type[mb_xy] = mb_type; if (IS_INTRA(mb_type)) { - h->chroma_pred_mode = ff_h264_check_intra_pred_mode(h, DC_PRED8x8); + h->chroma_pred_mode = ff_h264_check_intra_pred_mode(h, DC_PRED8x8, 1); } return 0; -- cgit v1.2.3 From 0c5d78a89806dc96244a3bd17b47e1d99f0a931a Mon Sep 17 00:00:00 2001 From: Yordan Makariev Date: Wed, 11 Jan 2012 21:27:20 +0200 Subject: 4xm, timefilter: K&R formatting cosmetics Signed-off-by: Diego Biurrun --- libavcodec/4xm.c | 898 +++++++++++++++++++++++++---------------------- libavdevice/timefilter.c | 94 ++--- 2 files changed, 523 insertions(+), 469 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/4xm.c b/libavcodec/4xm.c index da682dfb00..8d7db98653 100644 --- a/libavcodec/4xm.c +++ b/libavcodec/4xm.c @@ -26,9 +26,9 @@ #include "libavutil/intreadwrite.h" #include "avcodec.h" +#include "bytestream.h" #include "dsputil.h" #include "get_bits.h" -#include "bytestream.h" //#undef NDEBUG //#include @@ -38,95 +38,96 @@ #define CFRAME_BUFFER_COUNT 100 -static const uint8_t block_type_tab[2][4][8][2]={ - { - { //{8,4,2}x{8,4,2} - { 0,1}, { 2,2}, { 6,3}, {14,4}, {30,5}, {31,5}, { 0,0} - },{ //{8,4}x1 - { 0,1}, { 0,0}, { 2,2}, { 6,3}, {14,4}, {15,4}, { 0,0} - },{ //1x{8,4} - { 0,1}, { 2,2}, { 0,0}, { 6,3}, {14,4}, {15,4}, { 0,0} - },{ //1x2, 2x1 - { 0,1}, { 0,0}, { 0,0}, { 2,2}, { 6,3}, {14,4}, {15,4} - } - },{ - { //{8,4,2}x{8,4,2} - { 1,2}, { 4,3}, { 5,3}, {0,2}, {6,3}, {7,3}, {0,0} - },{//{8,4}x1 - { 1,2}, { 0,0}, { 2,2}, {0,2}, {6,3}, {7,3}, {0,0} - },{//1x{8,4} - { 1,2}, { 2,2}, { 0,0}, {0,2}, {6,3}, {7,3}, {0,0} - },{//1x2, 2x1 - { 1,2}, { 0,0}, { 0,0}, {0,2}, {2,2}, {6,3}, {7,3} - } - } +static const uint8_t block_type_tab[2][4][8][2] = { + { + { // { 8, 4, 2 } x { 8, 4, 2} + { 0, 1 }, { 2, 2 }, { 6, 3 }, { 14, 4 }, { 30, 5 }, { 31, 5 }, { 0, 0 } + }, { // { 8, 4 } x 1 + { 0, 1 }, { 0, 0 }, { 2, 2 }, { 6, 3 }, { 14, 4 }, { 15, 4 }, { 0, 0 } + }, { // 1 x { 8, 4 } + { 0, 1 }, { 2, 2 }, { 0, 0 }, { 6, 3 }, { 14, 4 }, { 15, 4 }, { 0, 0 } + }, { // 1 x 2, 2 x 1 + { 0, 1 }, { 0, 0 }, { 0, 0 }, { 2, 2 }, { 6, 3 }, { 14, 4 }, { 15, 4 } + } + }, { + { // { 8, 4, 2 } x { 8, 4, 2} + { 1, 2 }, { 4, 3 }, { 5, 3 }, { 0, 2 }, { 6, 3 }, { 7, 3 }, { 0, 0 } + }, {// { 8, 4 } x 1 + { 1, 2 }, { 0, 0 }, { 2, 2 }, { 0, 2 }, { 6, 3 }, { 7, 3 }, { 0, 0 } + }, {// 1 x { 8, 4 } + { 1, 2 }, { 2, 2 }, { 0, 0 }, { 0, 2 }, { 6, 3 }, { 7, 3 }, { 0, 0 } + }, {// 1 x 2, 2 x 1 + { 1, 2 }, { 0, 0 }, { 0, 0 }, { 0, 2 }, { 2, 2 }, { 6, 3 }, { 7, 3 } + } + } }; -static const uint8_t size2index[4][4]={ - {-1, 3, 1, 1}, - { 3, 0, 0, 0}, - { 2, 0, 0, 0}, - { 2, 0, 0, 0}, +static const uint8_t size2index[4][4] = { + { -1, 3, 1, 1 }, + { 3, 0, 0, 0 }, + { 2, 0, 0, 0 }, + { 2, 0, 0, 0 }, }; -static const int8_t mv[256][2]={ -{ 0, 0},{ 0, -1},{ -1, 0},{ 1, 0},{ 0, 1},{ -1, -1},{ 1, -1},{ -1, 1}, -{ 1, 1},{ 0, -2},{ -2, 0},{ 2, 0},{ 0, 2},{ -1, -2},{ 1, -2},{ -2, -1}, -{ 2, -1},{ -2, 1},{ 2, 1},{ -1, 2},{ 1, 2},{ -2, -2},{ 2, -2},{ -2, 2}, -{ 2, 2},{ 0, -3},{ -3, 0},{ 3, 0},{ 0, 3},{ -1, -3},{ 1, -3},{ -3, -1}, -{ 3, -1},{ -3, 1},{ 3, 1},{ -1, 3},{ 1, 3},{ -2, -3},{ 2, -3},{ -3, -2}, -{ 3, -2},{ -3, 2},{ 3, 2},{ -2, 3},{ 2, 3},{ 0, -4},{ -4, 0},{ 4, 0}, -{ 0, 4},{ -1, -4},{ 1, -4},{ -4, -1},{ 4, -1},{ 4, 1},{ -1, 4},{ 1, 4}, -{ -3, -3},{ -3, 3},{ 3, 3},{ -2, -4},{ -4, -2},{ 4, -2},{ -4, 2},{ -2, 4}, -{ 2, 4},{ -3, -4},{ 3, -4},{ 4, -3},{ -5, 0},{ -4, 3},{ -3, 4},{ 3, 4}, -{ -1, -5},{ -5, -1},{ -5, 1},{ -1, 5},{ -2, -5},{ 2, -5},{ 5, -2},{ 5, 2}, -{ -4, -4},{ -4, 4},{ -3, -5},{ -5, -3},{ -5, 3},{ 3, 5},{ -6, 0},{ 0, 6}, -{ -6, -1},{ -6, 1},{ 1, 6},{ 2, -6},{ -6, 2},{ 2, 6},{ -5, -4},{ 5, 4}, -{ 4, 5},{ -6, -3},{ 6, 3},{ -7, 0},{ -1, -7},{ 5, -5},{ -7, 1},{ -1, 7}, -{ 4, -6},{ 6, 4},{ -2, -7},{ -7, 2},{ -3, -7},{ 7, -3},{ 3, 7},{ 6, -5}, -{ 0, -8},{ -1, -8},{ -7, -4},{ -8, 1},{ 4, 7},{ 2, -8},{ -2, 8},{ 6, 6}, -{ -8, 3},{ 5, -7},{ -5, 7},{ 8, -4},{ 0, -9},{ -9, -1},{ 1, 9},{ 7, -6}, -{ -7, 6},{ -5, -8},{ -5, 8},{ -9, 3},{ 9, -4},{ 7, -7},{ 8, -6},{ 6, 8}, -{ 10, 1},{-10, 2},{ 9, -5},{ 10, -3},{ -8, -7},{-10, -4},{ 6, -9},{-11, 0}, -{ 11, 1},{-11, -2},{ -2, 11},{ 7, -9},{ -7, 9},{ 10, 6},{ -4, 11},{ 8, -9}, -{ 8, 9},{ 5, 11},{ 7,-10},{ 12, -3},{ 11, 6},{ -9, -9},{ 8, 10},{ 5, 12}, -{-11, 7},{ 13, 2},{ 6,-12},{ 10, 9},{-11, 8},{ -7, 12},{ 0, 14},{ 14, -2}, -{ -9, 11},{ -6, 13},{-14, -4},{ -5,-14},{ 5, 14},{-15, -1},{-14, -6},{ 3,-15}, -{ 11,-11},{ -7, 14},{ -5, 15},{ 8,-14},{ 15, 6},{ 3, 16},{ 7,-15},{-16, 5}, -{ 0, 17},{-16, -6},{-10, 14},{-16, 7},{ 12, 13},{-16, 8},{-17, 6},{-18, 3}, -{ -7, 17},{ 15, 11},{ 16, 10},{ 2,-19},{ 3,-19},{-11,-16},{-18, 8},{-19, -6}, -{ 2,-20},{-17,-11},{-10,-18},{ 8, 19},{-21, -1},{-20, 7},{ -4, 21},{ 21, 5}, -{ 15, 16},{ 2,-22},{-10,-20},{-22, 5},{ 20,-11},{ -7,-22},{-12, 20},{ 23, -5}, -{ 13,-20},{ 24, -2},{-15, 19},{-11, 22},{ 16, 19},{ 23,-10},{-18,-18},{ -9,-24}, -{ 24,-10},{ -3, 26},{-23, 13},{-18,-20},{ 17, 21},{ -4, 27},{ 27, 6},{ 1,-28}, -{-11, 26},{-17,-23},{ 7, 28},{ 11,-27},{ 29, 5},{-23,-19},{-28,-11},{-21, 22}, -{-30, 7},{-17, 26},{-27, 16},{ 13, 29},{ 19,-26},{ 10,-31},{-14,-30},{ 20,-27}, -{-29, 18},{-16,-31},{-28,-22},{ 21,-30},{-25, 28},{ 26,-29},{ 25,-32},{-32,-32} +static const int8_t mv[256][2] = { + { 0, 0 }, { 0, -1 }, { -1, 0 }, { 1, 0 }, { 0, 1 }, { -1, -1 }, { 1, -1 }, { -1, 1 }, + { 1, 1 }, { 0, -2 }, { -2, 0 }, { 2, 0 }, { 0, 2 }, { -1, -2 }, { 1, -2 }, { -2, -1 }, + { 2, -1 }, { -2, 1 }, { 2, 1 }, { -1, 2 }, { 1, 2 }, { -2, -2 }, { 2, -2 }, { -2, 2 }, + { 2, 2 }, { 0, -3 }, { -3, 0 }, { 3, 0 }, { 0, 3 }, { -1, -3 }, { 1, -3 }, { -3, -1 }, + { 3, -1 }, { -3, 1 }, { 3, 1 }, { -1, 3 }, { 1, 3 }, { -2, -3 }, { 2, -3 }, { -3, -2 }, + { 3, -2 }, { -3, 2 }, { 3, 2 }, { -2, 3 }, { 2, 3 }, { 0, -4 }, { -4, 0 }, { 4, 0 }, + { 0, 4 }, { -1, -4 }, { 1, -4 }, { -4, -1 }, { 4, -1 }, { 4, 1 }, { -1, 4 }, { 1, 4 }, + { -3, -3 }, { -3, 3 }, { 3, 3 }, { -2, -4 }, { -4, -2 }, { 4, -2 }, { -4, 2 }, { -2, 4 }, + { 2, 4 }, { -3, -4 }, { 3, -4 }, { 4, -3 }, { -5, 0 }, { -4, 3 }, { -3, 4 }, { 3, 4 }, + { -1, -5 }, { -5, -1 }, { -5, 1 }, { -1, 5 }, { -2, -5 }, { 2, -5 }, { 5, -2 }, { 5, 2 }, + { -4, -4 }, { -4, 4 }, { -3, -5 }, { -5, -3 }, { -5, 3 }, { 3, 5 }, { -6, 0 }, { 0, 6 }, + { -6, -1 }, { -6, 1 }, { 1, 6 }, { 2, -6 }, { -6, 2 }, { 2, 6 }, { -5, -4 }, { 5, 4 }, + { 4, 5 }, { -6, -3 }, { 6, 3 }, { -7, 0 }, { -1, -7 }, { 5, -5 }, { -7, 1 }, { -1, 7 }, + { 4, -6 }, { 6, 4 }, { -2, -7 }, { -7, 2 }, { -3, -7 }, { 7, -3 }, { 3, 7 }, { 6, -5 }, + { 0, -8 }, { -1, -8 }, { -7, -4 }, { -8, 1 }, { 4, 7 }, { 2, -8 }, { -2, 8 }, { 6, 6 }, + { -8, 3 }, { 5, -7 }, { -5, 7 }, { 8, -4 }, { 0, -9 }, { -9, -1 }, { 1, 9 }, { 7, -6 }, + { -7, 6 }, { -5, -8 }, { -5, 8 }, { -9, 3 }, { 9, -4 }, { 7, -7 }, { 8, -6 }, { 6, 8 }, + { 10, 1 }, { -10, 2 }, { 9, -5 }, { 10, -3 }, { -8, -7 }, { -10, -4 }, { 6, -9 }, { -11, 0 }, + { 11, 1 }, { -11, -2 }, { -2, 11 }, { 7, -9 }, { -7, 9 }, { 10, 6 }, { -4, 11 }, { 8, -9 }, + { 8, 9 }, { 5, 11 }, { 7, -10 }, { 12, -3 }, { 11, 6 }, { -9, -9 }, { 8, 10 }, { 5, 12 }, + { -11, 7 }, { 13, 2 }, { 6, -12 }, { 10, 9 }, { -11, 8 }, { -7, 12 }, { 0, 14 }, { 14, -2 }, + { -9, 11 }, { -6, 13 }, { -14, -4 }, { -5, -14 }, { 5, 14 }, { -15, -1 }, { -14, -6 }, { 3, -15 }, + { 11, -11 }, { -7, 14 }, { -5, 15 }, { 8, -14 }, { 15, 6 }, { 3, 16 }, { 7, -15 }, { -16, 5 }, + { 0, 17 }, { -16, -6 }, { -10, 14 }, { -16, 7 }, { 12, 13 }, { -16, 8 }, { -17, 6 }, { -18, 3 }, + { -7, 17 }, { 15, 11 }, { 16, 10 }, { 2, -19 }, { 3, -19 }, { -11, -16 }, { -18, 8 }, { -19, -6 }, + { 2, -20 }, { -17, -11 }, { -10, -18 }, { 8, 19 }, { -21, -1 }, { -20, 7 }, { -4, 21 }, { 21, 5 }, + { 15, 16 }, { 2, -22 }, { -10, -20 }, { -22, 5 }, { 20, -11 }, { -7, -22 }, { -12, 20 }, { 23, -5 }, + { 13, -20 }, { 24, -2 }, { -15, 19 }, { -11, 22 }, { 16, 19 }, { 23, -10 }, { -18, -18 }, { -9, -24 }, + { 24, -10 }, { -3, 26 }, { -23, 13 }, { -18, -20 }, { 17, 21 }, { -4, 27 }, { 27, 6 }, { 1, -28 }, + { -11, 26 }, { -17, -23 }, { 7, 28 }, { 11, -27 }, { 29, 5 }, { -23, -19 }, { -28, -11 }, { -21, 22 }, + { -30, 7 }, { -17, 26 }, { -27, 16 }, { 13, 29 }, { 19, -26 }, { 10, -31 }, { -14, -30 }, { 20, -27 }, + { -29, 18 }, { -16, -31 }, { -28, -22 }, { 21, -30 }, { -25, 28 }, { 26, -29 }, { 25, -32 }, { -32, -32 } }; -// this is simply the scaled down elementwise product of the standard jpeg quantizer table and the AAN premul table -static const uint8_t dequant_table[64]={ - 16, 15, 13, 19, 24, 31, 28, 17, - 17, 23, 25, 31, 36, 63, 45, 21, - 18, 24, 27, 37, 52, 59, 49, 20, - 16, 28, 34, 40, 60, 80, 51, 20, - 18, 31, 48, 66, 68, 86, 56, 21, - 19, 38, 56, 59, 64, 64, 48, 20, - 27, 48, 55, 55, 56, 51, 35, 15, - 20, 35, 34, 32, 31, 22, 15, 8, +/* This is simply the scaled down elementwise product of the standard JPEG + * quantizer table and the AAN premul table. */ +static const uint8_t dequant_table[64] = { + 16, 15, 13, 19, 24, 31, 28, 17, + 17, 23, 25, 31, 36, 63, 45, 21, + 18, 24, 27, 37, 52, 59, 49, 20, + 16, 28, 34, 40, 60, 80, 51, 20, + 18, 31, 48, 66, 68, 86, 56, 21, + 19, 38, 56, 59, 64, 64, 48, 20, + 27, 48, 55, 55, 56, 51, 35, 15, + 20, 35, 34, 32, 31, 22, 15, 8, }; static VLC block_type_vlc[2][4]; -typedef struct CFrameBuffer{ +typedef struct CFrameBuffer { unsigned int allocated_size; unsigned int size; int id; uint8_t *data; -}CFrameBuffer; +} CFrameBuffer; -typedef struct FourXContext{ +typedef struct FourXContext { AVCodecContext *avctx; DSPContext dsp; AVFrame current_picture, last_picture; @@ -150,54 +151,55 @@ typedef struct FourXContext{ #define FIX_1_847759065 121095 #define FIX_2_613125930 171254 -#define MULTIPLY(var,const) (((var)*(const)) >> 16) +#define MULTIPLY(var, const) (((var) * (const)) >> 16) -static void idct(DCTELEM block[64]){ +static void idct(DCTELEM block[64]) +{ int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; int tmp10, tmp11, tmp12, tmp13; int z5, z10, z11, z12, z13; int i; int temp[64]; - for(i=0; i<8; i++){ - tmp10 = block[8*0 + i] + block[8*4 + i]; - tmp11 = block[8*0 + i] - block[8*4 + i]; + for (i = 0; i < 8; i++) { + tmp10 = block[8 * 0 + i] + block[8 * 4 + i]; + tmp11 = block[8 * 0 + i] - block[8 * 4 + i]; - tmp13 = block[8*2 + i] + block[8*6 + i]; - tmp12 = MULTIPLY(block[8*2 + i] - block[8*6 + i], FIX_1_414213562) - tmp13; + tmp13 = block[8 * 2 + i] + block[8 * 6 + i]; + tmp12 = MULTIPLY(block[8 * 2 + i] - block[8 * 6 + i], FIX_1_414213562) - tmp13; tmp0 = tmp10 + tmp13; tmp3 = tmp10 - tmp13; tmp1 = tmp11 + tmp12; tmp2 = tmp11 - tmp12; - z13 = block[8*5 + i] + block[8*3 + i]; - z10 = block[8*5 + i] - block[8*3 + i]; - z11 = block[8*1 + i] + block[8*7 + i]; - z12 = block[8*1 + i] - block[8*7 + i]; + z13 = block[8 * 5 + i] + block[8 * 3 + i]; + z10 = block[8 * 5 + i] - block[8 * 3 + i]; + z11 = block[8 * 1 + i] + block[8 * 7 + i]; + z12 = block[8 * 1 + i] - block[8 * 7 + i]; tmp7 = z11 + z13; tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); z5 = MULTIPLY(z10 + z12, FIX_1_847759065); - tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; - tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; + tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; + tmp12 = MULTIPLY(z10, -FIX_2_613125930) + z5; tmp6 = tmp12 - tmp7; tmp5 = tmp11 - tmp6; tmp4 = tmp10 + tmp5; - temp[8*0 + i] = tmp0 + tmp7; - temp[8*7 + i] = tmp0 - tmp7; - temp[8*1 + i] = tmp1 + tmp6; - temp[8*6 + i] = tmp1 - tmp6; - temp[8*2 + i] = tmp2 + tmp5; - temp[8*5 + i] = tmp2 - tmp5; - temp[8*4 + i] = tmp3 + tmp4; - temp[8*3 + i] = tmp3 - tmp4; + temp[8 * 0 + i] = tmp0 + tmp7; + temp[8 * 7 + i] = tmp0 - tmp7; + temp[8 * 1 + i] = tmp1 + tmp6; + temp[8 * 6 + i] = tmp1 - tmp6; + temp[8 * 2 + i] = tmp2 + tmp5; + temp[8 * 5 + i] = tmp2 - tmp5; + temp[8 * 4 + i] = tmp3 + tmp4; + temp[8 * 3 + i] = tmp3 - tmp4; } - for(i=0; i<8*8; i+=8){ + for (i = 0; i < 8 * 8; i += 8) { tmp10 = temp[0 + i] + temp[4 + i]; tmp11 = temp[0 + i] - temp[4 + i]; @@ -214,207 +216,228 @@ static void idct(DCTELEM block[64]){ z11 = temp[1 + i] + temp[7 + i]; z12 = temp[1 + i] - temp[7 + i]; - tmp7 = z11 + z13; + tmp7 = z11 + z13; tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); - z5 = MULTIPLY(z10 + z12, FIX_1_847759065); - tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; - tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; + z5 = MULTIPLY(z10 + z12, FIX_1_847759065); + tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; + tmp12 = MULTIPLY(z10, -FIX_2_613125930) + z5; tmp6 = tmp12 - tmp7; tmp5 = tmp11 - tmp6; tmp4 = tmp10 + tmp5; - block[0 + i] = (tmp0 + tmp7)>>6; - block[7 + i] = (tmp0 - tmp7)>>6; - block[1 + i] = (tmp1 + tmp6)>>6; - block[6 + i] = (tmp1 - tmp6)>>6; - block[2 + i] = (tmp2 + tmp5)>>6; - block[5 + i] = (tmp2 - tmp5)>>6; - block[4 + i] = (tmp3 + tmp4)>>6; - block[3 + i] = (tmp3 - tmp4)>>6; + block[0 + i] = (tmp0 + tmp7) >> 6; + block[7 + i] = (tmp0 - tmp7) >> 6; + block[1 + i] = (tmp1 + tmp6) >> 6; + block[6 + i] = (tmp1 - tmp6) >> 6; + block[2 + i] = (tmp2 + tmp5) >> 6; + block[5 + i] = (tmp2 - tmp5) >> 6; + block[4 + i] = (tmp3 + tmp4) >> 6; + block[3 + i] = (tmp3 - tmp4) >> 6; } } -static av_cold void init_vlcs(FourXContext *f){ +static av_cold void init_vlcs(FourXContext *f) +{ static VLC_TYPE table[8][32][2]; int i; - for(i=0; i<8; i++){ - block_type_vlc[0][i].table= table[i]; - block_type_vlc[0][i].table_allocated= 32; + for (i = 0; i < 8; i++) { + block_type_vlc[0][i].table = table[i]; + block_type_vlc[0][i].table_allocated = 32; init_vlc(&block_type_vlc[0][i], BLOCK_TYPE_VLC_BITS, 7, &block_type_tab[0][i][0][1], 2, 1, &block_type_tab[0][i][0][0], 2, 1, INIT_VLC_USE_NEW_STATIC); } } -static void init_mv(FourXContext *f){ +static void init_mv(FourXContext *f) +{ int i; - for(i=0; i<256; i++){ - if(f->version>1) - f->mv[i] = mv[i][0] + mv[i][1] *f->current_picture.linesize[0]/2; + for (i = 0; i < 256; i++) { + if (f->version > 1) + f->mv[i] = mv[i][0] + mv[i][1] * f->current_picture.linesize[0] / 2; else - f->mv[i] = (i&15) - 8 + ((i>>4)-8)*f->current_picture.linesize[0]/2; + f->mv[i] = (i & 15) - 8 + ((i >> 4) - 8) * f->current_picture.linesize[0] / 2; } } #if HAVE_BIGENDIAN -#define LE_CENTRIC_MUL(dst, src, scale, dc) \ - { \ +#define LE_CENTRIC_MUL(dst, src, scale, dc) \ + { \ unsigned tmpval = AV_RN32(src); \ - tmpval = (tmpval << 16) | (tmpval >> 16); \ + tmpval = (tmpval << 16) | (tmpval >> 16); \ tmpval = tmpval * (scale) + (dc); \ - tmpval = (tmpval << 16) | (tmpval >> 16); \ + tmpval = (tmpval << 16) | (tmpval >> 16); \ AV_WN32A(dst, tmpval); \ } #else -#define LE_CENTRIC_MUL(dst, src, scale, dc) \ - { \ +#define LE_CENTRIC_MUL(dst, src, scale, dc) \ + { \ unsigned tmpval = AV_RN32(src) * (scale) + (dc); \ AV_WN32A(dst, tmpval); \ } #endif -static inline void mcdc(uint16_t *dst, uint16_t *src, int log2w, int h, int stride, int scale, unsigned dc){ - int i; - dc*= 0x10001; - - switch(log2w){ - case 0: - for(i=0; igb, block_type_vlc[1-(f->version>1)][index].table, BLOCK_TYPE_VLC_BITS, 1); - uint16_t *start= (uint16_t*)f->last_picture.data[0]; - uint16_t *end= start + stride*(f->avctx->height-h+1) - (1<gb, + block_type_vlc[1 - (f->version > 1)][index].table, + BLOCK_TYPE_VLC_BITS, 1); + uint16_t *start = (uint16_t *)f->last_picture.data[0]; + uint16_t *end = start + stride * (f->avctx->height - h + 1) - (1 << log2w); - assert(code>=0 && code<=6); + assert(code >= 0 && code <= 6); - if(code == 0){ + if (code == 0) { src += f->mv[bytestream2_get_byte(&f->g)]; - if(start > src || src > end){ + if (start > src || src > end) { av_log(f->avctx, AV_LOG_ERROR, "mv out of pic\n"); return; } mcdc(dst, src, log2w, h, stride, 1, 0); - }else if(code == 1){ + } else if (code == 1) { log2h--; - decode_p_block(f, dst , src , log2w, log2h, stride); - decode_p_block(f, dst + (stride<version<2){ + decode_p_block(f, dst , src, log2w, log2h, stride); + decode_p_block(f, dst + (1 << log2w), + src + (1 << log2w), log2w, log2h, stride); + } else if (code == 3 && f->version < 2) { mcdc(dst, src, log2w, h, stride, 1, 0); - }else if(code == 4){ + } else if (code == 4) { src += f->mv[bytestream2_get_byte(&f->g)]; - if(start > src || src > end){ + if (start > src || src > end) { av_log(f->avctx, AV_LOG_ERROR, "mv out of pic\n"); return; } mcdc(dst, src, log2w, h, stride, 1, bytestream2_get_le16(&f->g2)); - }else if(code == 5){ + } else if (code == 5) { mcdc(dst, src, log2w, h, stride, 0, bytestream2_get_le16(&f->g2)); - }else if(code == 6){ - if(log2w){ - dst[0] = bytestream2_get_le16(&f->g2); - dst[1] = bytestream2_get_le16(&f->g2); - }else{ - dst[0 ] = bytestream2_get_le16(&f->g2); + } else if (code == 6) { + if (log2w) { + dst[0] = bytestream2_get_le16(&f->g2); + dst[1] = bytestream2_get_le16(&f->g2); + } else { + dst[0] = bytestream2_get_le16(&f->g2); dst[stride] = bytestream2_get_le16(&f->g2); } } } -static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length){ +static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length) +{ int x, y; - const int width= f->avctx->width; - const int height= f->avctx->height; - uint16_t *src= (uint16_t*)f->last_picture.data[0]; - uint16_t *dst= (uint16_t*)f->current_picture.data[0]; - const int stride= f->current_picture.linesize[0]>>1; - unsigned int bitstream_size, bytestream_size, wordstream_size, extra, bytestream_offset, wordstream_offset; - - if(f->version>1){ - extra=20; - bitstream_size= AV_RL32(buf+8); - wordstream_size= AV_RL32(buf+12); - bytestream_size= AV_RL32(buf+16); - }else{ - extra=0; - bitstream_size = AV_RL16(buf-4); - wordstream_size= AV_RL16(buf-2); - bytestream_size= FFMAX(length - bitstream_size - wordstream_size, 0); + const int width = f->avctx->width; + const int height = f->avctx->height; + uint16_t *src = (uint16_t *)f->last_picture.data[0]; + uint16_t *dst = (uint16_t *)f->current_picture.data[0]; + const int stride = f->current_picture.linesize[0] >> 1; + unsigned int bitstream_size, bytestream_size, wordstream_size, extra, + bytestream_offset, wordstream_offset; + + if (f->version > 1) { + extra = 20; + bitstream_size = AV_RL32(buf + 8); + wordstream_size = AV_RL32(buf + 12); + bytestream_size = AV_RL32(buf + 16); + } else { + extra = 0; + bitstream_size = AV_RL16(buf - 4); + wordstream_size = AV_RL16(buf - 2); + bytestream_size = FFMAX(length - bitstream_size - wordstream_size, 0); } - if(bitstream_size+ bytestream_size+ wordstream_size + extra != length - || bitstream_size > (1<<26) - || bytestream_size > (1<<26) - || wordstream_size > (1<<26) - ){ - av_log(f->avctx, AV_LOG_ERROR, "lengths %d %d %d %d\n", bitstream_size, bytestream_size, wordstream_size, - bitstream_size+ bytestream_size+ wordstream_size - length); + if (bitstream_size + bytestream_size + wordstream_size + extra != length + || bitstream_size > (1 << 26) + || bytestream_size > (1 << 26) + || wordstream_size > (1 << 26)) { + av_log(f->avctx, AV_LOG_ERROR, "lengths %d %d %d %d\n", + bitstream_size, bytestream_size, wordstream_size, + bitstream_size + bytestream_size + wordstream_size - length); return -1; } - av_fast_malloc(&f->bitstream_buffer, &f->bitstream_buffer_size, bitstream_size + FF_INPUT_BUFFER_PADDING_SIZE); + av_fast_malloc(&f->bitstream_buffer, &f->bitstream_buffer_size, + bitstream_size + FF_INPUT_BUFFER_PADDING_SIZE); if (!f->bitstream_buffer) return AVERROR(ENOMEM); - f->dsp.bswap_buf(f->bitstream_buffer, (const uint32_t*)(buf + extra), bitstream_size/4); - memset((uint8_t*)f->bitstream_buffer + bitstream_size, 0, FF_INPUT_BUFFER_PADDING_SIZE); - init_get_bits(&f->gb, f->bitstream_buffer, 8*bitstream_size); + f->dsp.bswap_buf(f->bitstream_buffer, (const uint32_t*)(buf + extra), + bitstream_size / 4); + memset((uint8_t*)f->bitstream_buffer + bitstream_size, + 0, FF_INPUT_BUFFER_PADDING_SIZE); + init_get_bits(&f->gb, f->bitstream_buffer, 8 * bitstream_size); wordstream_offset = extra + bitstream_size; bytestream_offset = extra + bitstream_size + wordstream_size; - bytestream2_init(&f->g2, buf + wordstream_offset, length - wordstream_offset); - bytestream2_init(&f->g, buf + bytestream_offset, length - bytestream_offset); + bytestream2_init(&f->g2, buf + wordstream_offset, + length - wordstream_offset); + bytestream2_init(&f->g, buf + bytestream_offset, + length - bytestream_offset); init_mv(f); - for(y=0; ypre_gb, f->pre_vlc.table, ACDC_VLC_BITS, 3); - if (val>>4){ + if (val >> 4) av_log(f->avctx, AV_LOG_ERROR, "error dc run != 0\n"); - } - if(val) + if (val) val = get_xbits(&f->gb, val); - val = val * dequant_table[0] + f->last_dc; - f->last_dc = - block[0] = val; + val = val * dequant_table[0] + f->last_dc; + f->last_dc = block[0] = val; /* AC coefs */ i = 1; - for(;;) { + for (;;) { code = get_vlc2(&f->pre_gb, f->pre_vlc.table, ACDC_VLC_BITS, 3); /* EOB */ @@ -451,13 +473,13 @@ static int decode_i_block(FourXContext *f, DCTELEM *block){ i += 16; } else { level = get_xbits(&f->gb, code & 0xf); - i += code >> 4; + i += code >> 4; if (i >= 64) { av_log(f->avctx, AV_LOG_ERROR, "run %d oveflow\n", i); return 0; } - j= ff_zigzag_direct[i]; + j = ff_zigzag_direct[i]; block[j] = level * dequant_table[j]; i++; if (i >= 64) @@ -468,185 +490,199 @@ static int decode_i_block(FourXContext *f, DCTELEM *block){ return 0; } -static inline void idct_put(FourXContext *f, int x, int y){ - DCTELEM (*block)[64]= f->block; - int stride= f->current_picture.linesize[0]>>1; +static inline void idct_put(FourXContext *f, int x, int y) +{ + DCTELEM (*block)[64] = f->block; + int stride = f->current_picture.linesize[0] >> 1; int i; uint16_t *dst = ((uint16_t*)f->current_picture.data[0]) + y * stride + x; - for(i=0; i<4; i++){ - block[i][0] += 0x80*8*8; + for (i = 0; i < 4; i++) { + block[i][0] += 0x80 * 8 * 8; idct(block[i]); } - if(!(f->avctx->flags&CODEC_FLAG_GRAY)){ - for(i=4; i<6; i++) idct(block[i]); + if (!(f->avctx->flags & CODEC_FLAG_GRAY)) { + for (i = 4; i < 6; i++) + idct(block[i]); } -/* Note transform is: -y= ( 1b + 4g + 2r)/14 -cb=( 3b - 2g - 1r)/14 -cr=(-1b - 4g + 5r)/14 -*/ - for(y=0; y<8; y++){ - for(x=0; x<8; x++){ - DCTELEM *temp= block[(x>>2) + 2*(y>>2)] + 2*(x&3) + 2*8*(y&3); //FIXME optimize - int cb= block[4][x + 8*y]; - int cr= block[5][x + 8*y]; - int cg= (cb + cr)>>1; + /* Note transform is: + * y = ( 1b + 4g + 2r) / 14 + * cb = ( 3b - 2g - 1r) / 14 + * cr = (-1b - 4g + 5r) / 14 */ + for (y = 0; y < 8; y++) { + for (x = 0; x < 8; x++) { + DCTELEM *temp = block[(x >> 2) + 2 * (y >> 2)] + + 2 * (x & 3) + 2 * 8 * (y & 3); // FIXME optimize + int cb = block[4][x + 8 * y]; + int cr = block[5][x + 8 * y]; + int cg = (cb + cr) >> 1; int y; - cb+=cb; - - y = temp[0]; - dst[0 ]= ((y+cb)>>3) + (((y-cg)&0xFC)<<3) + (((y+cr)&0xF8)<<8); - y = temp[1]; - dst[1 ]= ((y+cb)>>3) + (((y-cg)&0xFC)<<3) + (((y+cr)&0xF8)<<8); - y = temp[8]; - dst[ stride]= ((y+cb)>>3) + (((y-cg)&0xFC)<<3) + (((y+cr)&0xF8)<<8); - y = temp[9]; - dst[1+stride]= ((y+cb)>>3) + (((y-cg)&0xFC)<<3) + (((y+cr)&0xF8)<<8); - dst += 2; + cb += cb; + + y = temp[0]; + dst[0] = ((y + cb) >> 3) + (((y - cg) & 0xFC) << 3) + (((y + cr) & 0xF8) << 8); + y = temp[1]; + dst[1] = ((y + cb) >> 3) + (((y - cg) & 0xFC) << 3) + (((y + cr) & 0xF8) << 8); + y = temp[8]; + dst[stride] = ((y + cb) >> 3) + (((y - cg) & 0xFC) << 3) + (((y + cr) & 0xF8) << 8); + y = temp[9]; + dst[1 + stride] = ((y + cb) >> 3) + (((y - cg) & 0xFC) << 3) + (((y + cr) & 0xF8) << 8); + dst += 2; } - dst += 2*stride - 2*8; + dst += 2 * stride - 2 * 8; } } -static int decode_i_mb(FourXContext *f){ +static int decode_i_mb(FourXContext *f) +{ int i; f->dsp.clear_blocks(f->block[0]); - for(i=0; i<6; i++){ - if(decode_i_block(f, f->block[i]) < 0) + for (i = 0; i < 6; i++) + if (decode_i_block(f, f->block[i]) < 0) return -1; - } return 0; } -static const uint8_t *read_huffman_tables(FourXContext *f, const uint8_t * const buf){ +static const uint8_t *read_huffman_tables(FourXContext *f, + const uint8_t * const buf) +{ int frequency[512]; uint8_t flag[512]; int up[512]; uint8_t len_tab[257]; int bits_tab[257]; int start, end; - const uint8_t *ptr= buf; + const uint8_t *ptr = buf; int j; memset(frequency, 0, sizeof(frequency)); memset(up, -1, sizeof(up)); - start= *ptr++; - end= *ptr++; - for(;;){ + start = *ptr++; + end = *ptr++; + for (;;) { int i; - for(i=start; i<=end; i++){ - frequency[i]= *ptr++; - } - start= *ptr++; - if(start==0) break; + for (i = start; i <= end; i++) + frequency[i] = *ptr++; + start = *ptr++; + if (start == 0) + break; - end= *ptr++; + end = *ptr++; } - frequency[256]=1; + frequency[256] = 1; - while((ptr - buf)&3) ptr++; // 4byte align + while ((ptr - buf) & 3) + ptr++; // 4byte align - for(j=257; j<512; j++){ - int min_freq[2]= {256*256, 256*256}; - int smallest[2]= {0, 0}; + for (j = 257; j < 512; j++) { + int min_freq[2] = { 256 * 256, 256 * 256 }; + int smallest[2] = { 0, 0 }; int i; - for(i=0; i 31) av_log(f->avctx, AV_LOG_ERROR, "vlc length overflow\n"); //can this happen at all ? + if (len > 31) + // can this happen at all ? + av_log(f->avctx, AV_LOG_ERROR, + "vlc length overflow\n"); } - bits_tab[j]= bits; - len_tab[j]= len; + bits_tab[j] = bits; + len_tab[j] = len; } - if (init_vlc(&f->pre_vlc, ACDC_VLC_BITS, 257, - len_tab , 1, 1, + if (init_vlc(&f->pre_vlc, ACDC_VLC_BITS, 257, len_tab, 1, 1, bits_tab, 4, 4, 0)) return NULL; return ptr; } -static int mix(int c0, int c1){ - int blue = 2*(c0&0x001F) + (c1&0x001F); - int green= (2*(c0&0x03E0) + (c1&0x03E0))>>5; - int red = 2*(c0>>10) + (c1>>10); - return red/3*1024 + green/3*32 + blue/3; +static int mix(int c0, int c1) +{ + int blue = 2 * (c0 & 0x001F) + (c1 & 0x001F); + int green = (2 * (c0 & 0x03E0) + (c1 & 0x03E0)) >> 5; + int red = 2 * (c0 >> 10) + (c1 >> 10); + return red / 3 * 1024 + green / 3 * 32 + blue / 3; } -static int decode_i2_frame(FourXContext *f, const uint8_t *buf, int length){ +static int decode_i2_frame(FourXContext *f, const uint8_t *buf, int length) +{ int x, y, x2, y2; - const int width= f->avctx->width; - const int height= f->avctx->height; - const int mbs = (FFALIGN(width, 16) >> 4) * (FFALIGN(height, 16) >> 4); - uint16_t *dst= (uint16_t*)f->current_picture.data[0]; - const int stride= f->current_picture.linesize[0]>>1; + const int width = f->avctx->width; + const int height = f->avctx->height; + const int mbs = (FFALIGN(width, 16) >> 4) * (FFALIGN(height, 16) >> 4); + uint16_t *dst = (uint16_t*)f->current_picture.data[0]; + const int stride = f->current_picture.linesize[0]>>1; GetByteContext g3; - if(length < mbs * 8) { + if (length < mbs * 8) { av_log(f->avctx, AV_LOG_ERROR, "packet size too small\n"); return AVERROR_INVALIDDATA; } bytestream2_init(&g3, buf, length); - for(y=0; y>2) + 8*(y2>>2); - dst[y2*stride+x2]= color[(bits>>index)&3]; + // warning following is purely guessed ... + color[0] = bytestream2_get_le16u(&g3); + color[1] = bytestream2_get_le16u(&g3); + + if (color[0] & 0x8000) + av_log(NULL, AV_LOG_ERROR, "unk bit 1\n"); + if (color[1] & 0x8000) + av_log(NULL, AV_LOG_ERROR, "unk bit 2\n"); + + color[2] = mix(color[0], color[1]); + color[3] = mix(color[1], color[0]); + + bits = bytestream2_get_le32u(&g3); + for (y2 = 0; y2 < 16; y2++) { + for (x2 = 0; x2 < 16; x2++) { + int index = 2 * (x2 >> 2) + 8 * (y2 >> 2); + dst[y2 * stride + x2] = color[(bits >> index) & 3]; } } - dst+=16; + dst += 16; } dst += 16 * stride - x; } @@ -654,11 +690,12 @@ static int decode_i2_frame(FourXContext *f, const uint8_t *buf, int length){ return 0; } -static int decode_i_frame(FourXContext *f, const uint8_t *buf, int length){ +static int decode_i_frame(FourXContext *f, const uint8_t *buf, int length) +{ int x, y; - const int width= f->avctx->width; - const int height= f->avctx->height; - const unsigned int bitstream_size= AV_RL32(buf); + const int width = f->avctx->width; + const int height = f->avctx->height; + const unsigned int bitstream_size = AV_RL32(buf); int token_count av_unused; unsigned int prestream_size; const uint8_t *prestream; @@ -668,159 +705,169 @@ static int decode_i_frame(FourXContext *f, const uint8_t *buf, int length){ return AVERROR_INVALIDDATA; } - token_count = AV_RL32(buf + bitstream_size + 8); + token_count = AV_RL32(buf + bitstream_size + 8); prestream_size = 4 * AV_RL32(buf + bitstream_size + 4); - prestream = buf + bitstream_size + 12; + prestream = buf + bitstream_size + 12; - if(prestream_size + bitstream_size + 12 != length - || bitstream_size > (1<<26) - || prestream_size > (1<<26)){ - av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d %d\n", prestream_size, bitstream_size, length); + if (prestream_size + bitstream_size + 12 != length + || bitstream_size > (1 << 26) + || prestream_size > (1 << 26)) { + av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d %d\n", + prestream_size, bitstream_size, length); return -1; } - prestream= read_huffman_tables(f, prestream); + prestream = read_huffman_tables(f, prestream); - init_get_bits(&f->gb, buf + 4, 8*bitstream_size); + init_get_bits(&f->gb, buf + 4, 8 * bitstream_size); - prestream_size= length + buf - prestream; + prestream_size = length + buf - prestream; - av_fast_malloc(&f->bitstream_buffer, &f->bitstream_buffer_size, prestream_size + FF_INPUT_BUFFER_PADDING_SIZE); + av_fast_malloc(&f->bitstream_buffer, &f->bitstream_buffer_size, + prestream_size + FF_INPUT_BUFFER_PADDING_SIZE); if (!f->bitstream_buffer) return AVERROR(ENOMEM); - f->dsp.bswap_buf(f->bitstream_buffer, (const uint32_t*)prestream, prestream_size/4); - memset((uint8_t*)f->bitstream_buffer + prestream_size, 0, FF_INPUT_BUFFER_PADDING_SIZE); - init_get_bits(&f->pre_gb, f->bitstream_buffer, 8*prestream_size); + f->dsp.bswap_buf(f->bitstream_buffer, (const uint32_t*)prestream, + prestream_size / 4); + memset((uint8_t*)f->bitstream_buffer + prestream_size, + 0, FF_INPUT_BUFFER_PADDING_SIZE); + init_get_bits(&f->pre_gb, f->bitstream_buffer, 8 * prestream_size); - f->last_dc= 0*128*8*8; + f->last_dc = 0 * 128 * 8 * 8; - for(y=0; ypre_gb, f->pre_vlc.table, ACDC_VLC_BITS, 3) != 256) + if (get_vlc2(&f->pre_gb, f->pre_vlc.table, ACDC_VLC_BITS, 3) != 256) av_log(f->avctx, AV_LOG_ERROR, "end mismatch\n"); return 0; } -static int decode_frame(AVCodecContext *avctx, - void *data, int *data_size, - AVPacket *avpkt) +static int decode_frame(AVCodecContext *avctx, void *data, + int *data_size, AVPacket *avpkt) { - const uint8_t *buf = avpkt->data; - int buf_size = avpkt->size; - FourXContext * const f = avctx->priv_data; - AVFrame *picture = data; + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + FourXContext *const f = avctx->priv_data; + AVFrame *picture = data; AVFrame *p, temp; int i, frame_4cc, frame_size; - frame_4cc= AV_RL32(buf); - if(buf_size != AV_RL32(buf+4)+8 || buf_size < 20){ - av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d\n", buf_size, AV_RL32(buf+4)); - } + frame_4cc = AV_RL32(buf); + if (buf_size != AV_RL32(buf + 4) + 8 || buf_size < 20) + av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d\n", + buf_size, AV_RL32(buf + 4)); - if(frame_4cc == AV_RL32("cfrm")){ - int free_index=-1; - const int data_size= buf_size - 20; - const int id= AV_RL32(buf+12); - const int whole_size= AV_RL32(buf+16); + if (frame_4cc == AV_RL32("cfrm")) { + int free_index = -1; + const int data_size = buf_size - 20; + const int id = AV_RL32(buf + 12); + const int whole_size = AV_RL32(buf + 16); CFrameBuffer *cfrm; - for(i=0; icfrm[i].id && f->cfrm[i].id < avctx->frame_number) - av_log(f->avctx, AV_LOG_ERROR, "lost c frame %d\n", f->cfrm[i].id); - } + for (i = 0; i < CFRAME_BUFFER_COUNT; i++) + if (f->cfrm[i].id && f->cfrm[i].id < avctx->frame_number) + av_log(f->avctx, AV_LOG_ERROR, "lost c frame %d\n", + f->cfrm[i].id); - for(i=0; icfrm[i].id == id) break; - if(f->cfrm[i].size == 0 ) free_index= i; + for (i = 0; i < CFRAME_BUFFER_COUNT; i++) { + if (f->cfrm[i].id == id) + break; + if (f->cfrm[i].size == 0) + free_index = i; } - if(i>=CFRAME_BUFFER_COUNT){ - i= free_index; - f->cfrm[i].id= id; + if (i >= CFRAME_BUFFER_COUNT) { + i = free_index; + f->cfrm[i].id = id; } - cfrm= &f->cfrm[i]; + cfrm = &f->cfrm[i]; - cfrm->data= av_fast_realloc(cfrm->data, &cfrm->allocated_size, cfrm->size + data_size + FF_INPUT_BUFFER_PADDING_SIZE); - if(!cfrm->data){ //explicit check needed as memcpy below might not catch a NULL + cfrm->data = av_fast_realloc(cfrm->data, &cfrm->allocated_size, + cfrm->size + data_size + FF_INPUT_BUFFER_PADDING_SIZE); + // explicit check needed as memcpy below might not catch a NULL + if (!cfrm->data) { av_log(f->avctx, AV_LOG_ERROR, "realloc falure"); return -1; } - memcpy(cfrm->data + cfrm->size, buf+20, data_size); + memcpy(cfrm->data + cfrm->size, buf + 20, data_size); cfrm->size += data_size; - if(cfrm->size >= whole_size){ - buf= cfrm->data; - frame_size= cfrm->size; + if (cfrm->size >= whole_size) { + buf = cfrm->data; + frame_size = cfrm->size; - if(id != avctx->frame_number){ - av_log(f->avctx, AV_LOG_ERROR, "cframe id mismatch %d %d\n", id, avctx->frame_number); - } + if (id != avctx->frame_number) + av_log(f->avctx, AV_LOG_ERROR, "cframe id mismatch %d %d\n", + id, avctx->frame_number); - cfrm->size= cfrm->id= 0; - frame_4cc= AV_RL32("pfrm"); - }else + cfrm->size = cfrm->id = 0; + frame_4cc = AV_RL32("pfrm"); + } else return buf_size; - }else{ - buf= buf + 12; - frame_size= buf_size - 12; + } else { + buf = buf + 12; + frame_size = buf_size - 12; } - temp= f->current_picture; - f->current_picture= f->last_picture; - f->last_picture= temp; + temp = f->current_picture; + f->current_picture = f->last_picture; + f->last_picture = temp; - p= &f->current_picture; - avctx->coded_frame= p; + p = &f->current_picture; + avctx->coded_frame = p; - avctx->flags |= CODEC_FLAG_EMU_EDGE; // alternatively we would have to use our own buffer management + // alternatively we would have to use our own buffer management + avctx->flags |= CODEC_FLAG_EMU_EDGE; - if(p->data[0]) + if (p->data[0]) avctx->release_buffer(avctx, p); - p->reference= 1; - if(avctx->get_buffer(avctx, p) < 0){ + p->reference = 1; + if (avctx->get_buffer(avctx, p) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return -1; } - if(frame_4cc == AV_RL32("ifr2")){ - p->pict_type= AV_PICTURE_TYPE_I; - if(decode_i2_frame(f, buf-4, frame_size + 4) < 0) + if (frame_4cc == AV_RL32("ifr2")) { + p->pict_type = AV_PICTURE_TYPE_I; + if (decode_i2_frame(f, buf - 4, frame_size + 4) < 0) return -1; - }else if(frame_4cc == AV_RL32("ifrm")){ - p->pict_type= AV_PICTURE_TYPE_I; - if(decode_i_frame(f, buf, frame_size) < 0) + } else if (frame_4cc == AV_RL32("ifrm")) { + p->pict_type = AV_PICTURE_TYPE_I; + if (decode_i_frame(f, buf, frame_size) < 0) return -1; - }else if(frame_4cc == AV_RL32("pfrm") || frame_4cc == AV_RL32("pfr2")){ - if(!f->last_picture.data[0]){ - f->last_picture.reference= 1; - if(avctx->get_buffer(avctx, &f->last_picture) < 0){ + } else if (frame_4cc == AV_RL32("pfrm") || frame_4cc == AV_RL32("pfr2")) { + if (!f->last_picture.data[0]) { + f->last_picture.reference = 1; + if (avctx->get_buffer(avctx, &f->last_picture) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return -1; } } - p->pict_type= AV_PICTURE_TYPE_P; - if(decode_p_frame(f, buf, frame_size) < 0) + p->pict_type = AV_PICTURE_TYPE_P; + if (decode_p_frame(f, buf, frame_size) < 0) return -1; - }else if(frame_4cc == AV_RL32("snd_")){ - av_log(avctx, AV_LOG_ERROR, "ignoring snd_ chunk length:%d\n", buf_size); - }else{ - av_log(avctx, AV_LOG_ERROR, "ignoring unknown chunk length:%d\n", buf_size); + } else if (frame_4cc == AV_RL32("snd_")) { + av_log(avctx, AV_LOG_ERROR, "ignoring snd_ chunk length:%d\n", + buf_size); + } else { + av_log(avctx, AV_LOG_ERROR, "ignoring unknown chunk length:%d\n", + buf_size); } - p->key_frame= p->pict_type == AV_PICTURE_TYPE_I; + p->key_frame = p->pict_type == AV_PICTURE_TYPE_I; - *picture= *p; + *picture = *p; *data_size = sizeof(AVPicture); emms_c(); @@ -829,47 +876,52 @@ static int decode_frame(AVCodecContext *avctx, } -static av_cold void common_init(AVCodecContext *avctx){ +static av_cold void common_init(AVCodecContext *avctx) +{ FourXContext * const f = avctx->priv_data; dsputil_init(&f->dsp, avctx); - f->avctx= avctx; + f->avctx = avctx; } -static av_cold int decode_init(AVCodecContext *avctx){ +static av_cold int decode_init(AVCodecContext *avctx) +{ FourXContext * const f = avctx->priv_data; - if(avctx->extradata_size != 4 || !avctx->extradata) { + if (avctx->extradata_size != 4 || !avctx->extradata) { av_log(avctx, AV_LOG_ERROR, "extradata wrong or missing\n"); return 1; } - f->version= AV_RL32(avctx->extradata)>>16; + f->version = AV_RL32(avctx->extradata) >> 16; common_init(avctx); init_vlcs(f); - if(f->version>2) avctx->pix_fmt= PIX_FMT_RGB565; - else avctx->pix_fmt= PIX_FMT_BGR555; + if (f->version > 2) + avctx->pix_fmt = PIX_FMT_RGB565; + else + avctx->pix_fmt = PIX_FMT_BGR555; return 0; } -static av_cold int decode_end(AVCodecContext *avctx){ +static av_cold int decode_end(AVCodecContext *avctx) +{ FourXContext * const f = avctx->priv_data; int i; av_freep(&f->bitstream_buffer); - f->bitstream_buffer_size=0; - for(i=0; ibitstream_buffer_size = 0; + for (i = 0; i < CFRAME_BUFFER_COUNT; i++) { av_freep(&f->cfrm[i].data); - f->cfrm[i].allocated_size= 0; + f->cfrm[i].allocated_size = 0; } free_vlc(&f->pre_vlc); - if(f->current_picture.data[0]) + if (f->current_picture.data[0]) avctx->release_buffer(avctx, &f->current_picture); - if(f->last_picture.data[0]) + if (f->last_picture.data[0]) avctx->release_buffer(avctx, &f->last_picture); return 0; @@ -884,5 +936,5 @@ AVCodec ff_fourxm_decoder = { .close = decode_end, .decode = decode_frame, .capabilities = CODEC_CAP_DR1, - .long_name = NULL_IF_CONFIG_SMALL("4X Movie"), + .long_name = NULL_IF_CONFIG_SMALL("4X Movie"), }; diff --git a/libavdevice/timefilter.c b/libavdevice/timefilter.c index 136661a541..cf9d2c623b 100644 --- a/libavdevice/timefilter.c +++ b/libavdevice/timefilter.c @@ -22,10 +22,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ - +#include "libavutil/mem.h" #include "config.h" #include "timefilter.h" -#include "libavutil/mem.h" struct TimeFilter { /// Delay Locked Loop data. These variables refer to mathematical @@ -37,12 +36,14 @@ struct TimeFilter { int count; }; -TimeFilter * ff_timefilter_new(double clock_period, double feedback2_factor, double feedback3_factor) +TimeFilter *ff_timefilter_new(double clock_period, + double feedback2_factor, + double feedback3_factor) { - TimeFilter *self = av_mallocz(sizeof(TimeFilter)); - self->clock_period = clock_period; - self->feedback2_factor = feedback2_factor; - self->feedback3_factor = feedback3_factor; + TimeFilter *self = av_mallocz(sizeof(TimeFilter)); + self->clock_period = clock_period; + self->feedback2_factor = feedback2_factor; + self->feedback3_factor = feedback3_factor; return self; } @@ -53,20 +54,20 @@ void ff_timefilter_destroy(TimeFilter *self) void ff_timefilter_reset(TimeFilter *self) { - self->count = 0; + self->count = 0; } double ff_timefilter_update(TimeFilter *self, double system_time, double period) { self->count++; - if (self->count==1) { + if (self->count == 1) { /// init loop - self->cycle_time = system_time; + self->cycle_time = system_time; } else { double loop_error; - self->cycle_time += self->clock_period * period; + self->cycle_time += self->clock_period * period; /// calculate loop error - loop_error = system_time - self->cycle_time; + loop_error = system_time - self->cycle_time; /// update loop self->cycle_time += FFMAX(self->feedback2_factor, 1.0 / self->count) * loop_error; @@ -84,60 +85,61 @@ double ff_timefilter_update(TimeFilter *self, double system_time, double period) int main(void) { AVLFG prng; - double n0,n1; + double n0, n1; #define SAMPLES 1000 double ideal[SAMPLES]; double samples[SAMPLES]; #if 1 - for(n0= 0; n0<40; n0=2*n0+1){ - for(n1= 0; n1<10; n1=2*n1+1){ + for (n0 = 0; n0 < 40; n0 = 2 * n0 + 1) { + for (n1 = 0; n1 < 10; n1 = 2 * n1 + 1) { #else - {{ - n0=7; - n1=1; + { + { + n0 = 7; + n1 = 1; #endif - double best_error= 1000000000; - double bestpar0=1; - double bestpar1=0.001; + double best_error = 1000000000; + double bestpar0 = 1; + double bestpar1 = 0.001; int better, i; av_lfg_init(&prng, 123); - for(i=0; i Date: Wed, 8 Feb 2012 17:46:48 -0500 Subject: cavs parser: fix parser context type Signed-off-by: Diego Biurrun --- libavcodec/cavs_parser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/cavs_parser.c b/libavcodec/cavs_parser.c index a91be3a04d..504fed9590 100644 --- a/libavcodec/cavs_parser.c +++ b/libavcodec/cavs_parser.c @@ -99,8 +99,8 @@ static int cavsvideo_parse(AVCodecParserContext *s, AVCodecParser ff_cavsvideo_parser = { .codec_ids = { CODEC_ID_CAVS }, - .priv_data_size = sizeof(ParseContext1), + .priv_data_size = sizeof(ParseContext), .parser_parse = cavsvideo_parse, - .parser_close = ff_parse1_close, + .parser_close = ff_parse_close, .split = ff_mpeg4video_split, }; -- cgit v1.2.3 From e40924887acead75f1410e5db65415d7986f4cb4 Mon Sep 17 00:00:00 2001 From: Rafaël Carré Date: Thu, 9 Feb 2012 20:26:17 -0500 Subject: mpeg4video parser: move specific fields into private context This obviates using ParseContext1, which is slated for removal. Signed-off-by: Diego Biurrun --- libavcodec/mpeg4video_parser.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/mpeg4video_parser.c b/libavcodec/mpeg4video_parser.c index 89bbf3465d..5362ad8d82 100644 --- a/libavcodec/mpeg4video_parser.c +++ b/libavcodec/mpeg4video_parser.c @@ -25,6 +25,11 @@ #include "mpeg4video.h" #include "mpeg4video_parser.h" +struct Mp4vParseContext { + ParseContext pc; + struct MpegEncContext enc; + int first_picture; +}; int ff_mpeg4_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){ int vop_found, i; @@ -68,8 +73,8 @@ static int av_mpeg4_decode_header(AVCodecParserContext *s1, AVCodecContext *avctx, const uint8_t *buf, int buf_size) { - ParseContext1 *pc = s1->priv_data; - MpegEncContext *s = pc->enc; + struct Mp4vParseContext *pc = s1->priv_data; + MpegEncContext *s = &pc->enc; GetBitContext gb1, *gb = &gb1; int ret; @@ -93,13 +98,10 @@ static int av_mpeg4_decode_header(AVCodecParserContext *s1, static av_cold int mpeg4video_parse_init(AVCodecParserContext *s) { - ParseContext1 *pc = s->priv_data; + struct Mp4vParseContext *pc = s->priv_data; - pc->enc = av_mallocz(sizeof(MpegEncContext)); - if (!pc->enc) - return -1; pc->first_picture = 1; - pc->enc->slice_context_count = 1; + pc->enc.slice_context_count = 1; return 0; } @@ -132,9 +134,9 @@ static int mpeg4video_parse(AVCodecParserContext *s, AVCodecParser ff_mpeg4video_parser = { .codec_ids = { CODEC_ID_MPEG4 }, - .priv_data_size = sizeof(ParseContext1), + .priv_data_size = sizeof(struct Mp4vParseContext), .parser_init = mpeg4video_parse_init, .parser_parse = mpeg4video_parse, - .parser_close = ff_parse1_close, + .parser_close = ff_parse_close, .split = ff_mpeg4video_split, }; -- cgit v1.2.3 From 07554ace702f66034954856bb45f654161fd011f Mon Sep 17 00:00:00 2001 From: Rafaël Carré Date: Wed, 8 Feb 2012 17:46:50 -0500 Subject: mpegvideo parser: move specific fields into private context This obviates using ParseContext1, which is slated for removal. Signed-off-by: Diego Biurrun --- libavcodec/mpegvideo_parser.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c index 1798f8386f..f0b3b202eb 100644 --- a/libavcodec/mpegvideo_parser.c +++ b/libavcodec/mpegvideo_parser.c @@ -23,11 +23,19 @@ #include "parser.h" #include "mpegvideo.h" +struct MpvParseContext { + ParseContext pc; + AVRational frame_rate; + int progressive_sequence; + int width, height; +}; + + static void mpegvideo_extract_headers(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t *buf, int buf_size) { - ParseContext1 *pc = s->priv_data; + struct MpvParseContext *pc = s->priv_data; const uint8_t *buf_end = buf + buf_size; uint32_t start_code; int frame_rate_index, ext_type, bytes_left; @@ -131,7 +139,7 @@ static int mpegvideo_parse(AVCodecParserContext *s, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size) { - ParseContext1 *pc1 = s->priv_data; + struct MpvParseContext *pc1 = s->priv_data; ParseContext *pc= &pc1->pc; int next; @@ -175,8 +183,8 @@ static int mpegvideo_split(AVCodecContext *avctx, AVCodecParser ff_mpegvideo_parser = { .codec_ids = { CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO }, - .priv_data_size = sizeof(ParseContext1), + .priv_data_size = sizeof(struct MpvParseContext), .parser_parse = mpegvideo_parse, - .parser_close = ff_parse1_close, + .parser_close = ff_parse_close, .split = mpegvideo_split, }; -- cgit v1.2.3 From 797639dcfdbd672d55e79c6a679cc1e58f863277 Mon Sep 17 00:00:00 2001 From: Rafaël Carré Date: Wed, 8 Feb 2012 17:46:51 -0500 Subject: vc1: use ff_parse_close It works as long as ParseContext is the first member of the private struct Signed-off-by: Diego Biurrun --- libavcodec/vc1_parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libavcodec') diff --git a/libavcodec/vc1_parser.c b/libavcodec/vc1_parser.c index 0cc5ea0fa8..55f97e1eef 100644 --- a/libavcodec/vc1_parser.c +++ b/libavcodec/vc1_parser.c @@ -196,6 +196,6 @@ AVCodecParser ff_vc1_parser = { .priv_data_size = sizeof(VC1ParseContext), .parser_init = vc1_parse_init, .parser_parse = vc1_parse, - .parser_close = ff_parse1_close, + .parser_close = ff_parse_close, .split = vc1_split, }; -- cgit v1.2.3 From b24aaabd44d68c6fafbfc476d1b70cc7ff8138ca Mon Sep 17 00:00:00 2001 From: Rafaël Carré Date: Wed, 8 Feb 2012 19:34:37 -0500 Subject: remove ParseContext1 Signed-off-by: Diego Biurrun --- libavcodec/parser.c | 8 -------- libavcodec/parser.h | 14 -------------- 2 files changed, 22 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/parser.c b/libavcodec/parser.c index 9fd7af6ce6..7a6b205207 100644 --- a/libavcodec/parser.c +++ b/libavcodec/parser.c @@ -289,14 +289,6 @@ void ff_parse_close(AVCodecParserContext *s) av_freep(&pc->buffer); } -void ff_parse1_close(AVCodecParserContext *s) -{ - ParseContext1 *pc1 = s->priv_data; - - av_free(pc1->pc.buffer); - av_free(pc1->enc); -} - /*************************/ int ff_mpeg4video_split(AVCodecContext *avctx, diff --git a/libavcodec/parser.h b/libavcodec/parser.h index 1e85ae4051..024b487bac 100644 --- a/libavcodec/parser.h +++ b/libavcodec/parser.h @@ -39,26 +39,12 @@ typedef struct ParseContext{ struct MpegEncContext; -typedef struct ParseContext1{ - ParseContext pc; -/* XXX/FIXME PC1 vs. PC */ - /* MPEG-2-specific */ - AVRational frame_rate; - int progressive_sequence; - int width, height; - - /* XXX: suppress that, needed by MPEG-4 */ - struct MpegEncContext *enc; - int first_picture; -} ParseContext1; - #define END_NOT_FOUND (-100) int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_size); int ff_mpeg4video_split(AVCodecContext *avctx, const uint8_t *buf, int buf_size); void ff_parse_close(AVCodecParserContext *s); -void ff_parse1_close(AVCodecParserContext *s); /** * Fetch timestamps for a specific byte within the current access unit. -- cgit v1.2.3 From 9e1db721c4329f4ac166a0bcc002c8d75f831aba Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Thu, 9 Feb 2012 20:21:47 -0800 Subject: svq3: Prevent illegal reads while parsing extradata. Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind --- libavcodec/svq3.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/svq3.c b/libavcodec/svq3.c index 5cc57a745d..eeb8ed7051 100644 --- a/libavcodec/svq3.c +++ b/libavcodec/svq3.c @@ -811,7 +811,9 @@ static av_cold int svq3_decode_init(AVCodecContext *avctx) MpegEncContext *s = &h->s; int m; unsigned char *extradata; + unsigned char *extradata_end; unsigned int size; + int marker_found = 0; if (ff_h264_decode_init(avctx) < 0) return -1; @@ -831,19 +833,26 @@ static av_cold int svq3_decode_init(AVCodecContext *avctx) /* prowl for the "SEQH" marker in the extradata */ extradata = (unsigned char *)avctx->extradata; - for (m = 0; m < avctx->extradata_size; m++) { - if (!memcmp(extradata, "SEQH", 4)) - break; - extradata++; + extradata_end = avctx->extradata + avctx->extradata_size; + if (extradata) { + for (m = 0; m + 8 < avctx->extradata_size; m++) { + if (!memcmp(extradata, "SEQH", 4)) { + marker_found = 1; + break; + } + extradata++; + } } /* if a match was found, parse the extra data */ - if (extradata && !memcmp(extradata, "SEQH", 4)) { + if (marker_found) { GetBitContext gb; int frame_size_code; size = AV_RB32(&extradata[4]); + if (size > extradata_end - extradata - 8) + return AVERROR_INVALIDDATA; init_get_bits(&gb, extradata + 8, size*8); /* 'frame size code' and optional 'width, height' */ -- cgit v1.2.3 From dcd2b55e1a7d1f88dc893c04cc86181fc7f11cc4 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Fri, 10 Feb 2012 00:05:14 +0000 Subject: Check AVCodec.pix_fmts in avcodec_open2() Signed-off-by: Paul B Mahol Signed-off-by: Justin Ruggles --- libavcodec/utils.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'libavcodec') diff --git a/libavcodec/utils.c b/libavcodec/utils.c index de3816b27f..e1863199c1 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -758,6 +758,16 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVD goto free_and_end; } } + if (avctx->codec->pix_fmts) { + for (i = 0; avctx->codec->pix_fmts[i] != PIX_FMT_NONE; i++) + if (avctx->pix_fmt == avctx->codec->pix_fmts[i]) + break; + if (avctx->codec->pix_fmts[i] == PIX_FMT_NONE) { + av_log(avctx, AV_LOG_ERROR, "Specified pix_fmt is not supported\n"); + ret = AVERROR(EINVAL); + goto free_and_end; + } + } if (avctx->codec->supported_samplerates) { for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++) if (avctx->sample_rate == avctx->codec->supported_samplerates[i]) -- cgit v1.2.3 From eeb9e61a518f6b3a1a85dd44e44d55e395e015f6 Mon Sep 17 00:00:00 2001 From: Aneesh Dogra Date: Wed, 8 Feb 2012 23:18:40 +0530 Subject: v210enc: Use Bytestream2 functions Signed-off-by: Justin Ruggles --- libavcodec/v210enc.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/v210enc.c b/libavcodec/v210enc.c index 77cb30bbfe..714b6fb551 100644 --- a/libavcodec/v210enc.c +++ b/libavcodec/v210enc.c @@ -55,18 +55,20 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, const AVFrame *pic = data; int aligned_width = ((avctx->width + 47) / 48) * 48; int stride = aligned_width * 8 / 3; + int line_padding = stride - ((avctx->width * 8 + 11) / 12) * 4; int h, w; const uint16_t *y = (const uint16_t*)pic->data[0]; const uint16_t *u = (const uint16_t*)pic->data[1]; const uint16_t *v = (const uint16_t*)pic->data[2]; - uint8_t *p = buf; - uint8_t *pdst = buf; + PutByteContext p; if (buf_size < avctx->height * stride) { av_log(avctx, AV_LOG_ERROR, "output buffer too small\n"); return AVERROR(ENOMEM); } + bytestream2_init_writer(&p, buf, buf_size); + #define CLIP(v) av_clip(v, 4, 1019) #define WRITE_PIXELS(a, b, c) \ @@ -74,7 +76,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, val = CLIP(*a++); \ val |= (CLIP(*b++) << 10) | \ (CLIP(*c++) << 20); \ - bytestream_put_le32(&p, val); \ + bytestream2_put_le32u(&p, val); \ } while (0) for (h = 0; h < avctx->height; h++) { @@ -90,25 +92,24 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, val = CLIP(*y++); if (w == avctx->width - 2) - bytestream_put_le32(&p, val); + bytestream2_put_le32u(&p, val); } if (w < avctx->width - 3) { val |= (CLIP(*u++) << 10) | (CLIP(*y++) << 20); - bytestream_put_le32(&p, val); + bytestream2_put_le32u(&p, val); val = CLIP(*v++) | (CLIP(*y++) << 10); - bytestream_put_le32(&p, val); + bytestream2_put_le32u(&p, val); } - pdst += stride; - memset(p, 0, pdst - p); - p = pdst; + bytestream2_set_buffer(&p, 0, line_padding); + y += pic->linesize[0] / 2 - avctx->width; u += pic->linesize[1] / 2 - avctx->width / 2; v += pic->linesize[2] / 2 - avctx->width / 2; } - return p - buf; + return bytestream2_tell_p(&p); } static av_cold int encode_close(AVCodecContext *avctx) -- cgit v1.2.3 From c388558d317f6bf8718ec3d22f4bf3540109dfe3 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Fri, 10 Feb 2012 18:51:57 +0000 Subject: wavpack: allow user to disable CRC checking Signed-off-by: Paul B Mahol Signed-off-by: Justin Ruggles --- libavcodec/wavpack.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c index 1098873d7c..31604f51fc 100644 --- a/libavcodec/wavpack.c +++ b/libavcodec/wavpack.c @@ -500,6 +500,21 @@ static void wv_reset_saved_context(WavpackFrameContext *s) s->sc.crc = s->extra_sc.crc = 0xFFFFFFFF; } +static inline int wv_check_crc(WavpackFrameContext *s, uint32_t crc, + uint32_t crc_extra_bits) +{ + if (crc != s->CRC) { + av_log(s->avctx, AV_LOG_ERROR, "CRC error\n"); + return AVERROR_INVALIDDATA; + } + if (s->got_extra_bits && crc_extra_bits != s->crc_extra_bits) { + av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n"); + return AVERROR_INVALIDDATA; + } + + return 0; +} + static inline int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb, void *dst, const int type) { @@ -610,14 +625,9 @@ static inline int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb, } while (!last && count < s->samples); wv_reset_saved_context(s); - if (crc != s->CRC) { - av_log(s->avctx, AV_LOG_ERROR, "CRC error\n"); - return -1; - } - if (s->got_extra_bits && crc_extra_bits != s->crc_extra_bits) { - av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n"); - return -1; - } + if ((s->avctx->err_recognition & AV_EF_CRCCHECK) && + wv_check_crc(s, crc, crc_extra_bits)) + return AVERROR_INVALIDDATA; return count * 2; } @@ -680,14 +690,9 @@ static inline int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb, } while (!last && count < s->samples); wv_reset_saved_context(s); - if (crc != s->CRC) { - av_log(s->avctx, AV_LOG_ERROR, "CRC error\n"); - return -1; - } - if (s->got_extra_bits && crc_extra_bits != s->crc_extra_bits) { - av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n"); - return -1; - } + if ((s->avctx->err_recognition & AV_EF_CRCCHECK) && + wv_check_crc(s, crc, crc_extra_bits)) + return AVERROR_INVALIDDATA; return count; } -- cgit v1.2.3 From f98ede7e610da644d3e5d553fc5d7102cf1ccde7 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Sun, 5 Feb 2012 21:14:33 +0000 Subject: v210enc: remove redundant check for pix_fmt Signed-off-by: Paul B Mahol Signed-off-by: Justin Ruggles --- libavcodec/v210enc.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/v210enc.c b/libavcodec/v210enc.c index 714b6fb551..d5445cb973 100644 --- a/libavcodec/v210enc.c +++ b/libavcodec/v210enc.c @@ -31,11 +31,6 @@ static av_cold int encode_init(AVCodecContext *avctx) return AVERROR(EINVAL); } - if (avctx->pix_fmt != PIX_FMT_YUV422P10) { - av_log(avctx, AV_LOG_ERROR, "v210 needs YUV422P10\n"); - return -1; - } - if (avctx->bits_per_raw_sample != 10) av_log(avctx, AV_LOG_WARNING, "bits per raw sample: %d != 10-bit\n", avctx->bits_per_raw_sample); -- cgit v1.2.3