* H.26L/H.264/AVC/JVT/14496-10/... cavlc bitstream decoding
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of FFmpeg.
+ * This file is part of Libav.
*
- * FFmpeg is free software; you can redistribute it and/or
+ * 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.
*
- * FFmpeg is distributed in the hope that it will be useful,
+ * 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 FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
- * @file libavcodec/h264_cavlc.c
+ * @file
* H.264 / AVC / MPEG4 part10 cavlc bitstream decoding.
* @author Michael Niedermayer <michaelni@gmx.at>
*/
MpegEncContext * const s = &h->s;
static const int coeff_token_table_index[17]= {0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3};
int level[16];
- int zeros_left, coeff_num, coeff_token, total_coeff, i, j, trailing_ones, run_before;
+ int zeros_left, coeff_token, total_coeff, i, trailing_ones, run_before;
//FIXME put trailing_onex into the context
- if(n == CHROMA_DC_BLOCK_INDEX){
+ if(n >= CHROMA_DC_BLOCK_INDEX){
coeff_token= get_vlc2(gb, chroma_dc_coeff_token_vlc.table, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 1);
total_coeff= coeff_token>>2;
}else{
total_coeff= pred_non_zero_count(h, n);
coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2);
total_coeff= coeff_token>>2;
- h->non_zero_count_cache[ scan8[n] ]= total_coeff;
}
}
+ h->non_zero_count_cache[ scan8[n] ]= total_coeff;
//FIXME set last_non_zero?
level_code= prefix + get_bits(gb, 4); //part
}else{
level_code= 30 + get_bits(gb, prefix-3); //part
- if(prefix>=16)
+ if(prefix>=16){
+ if(prefix > 25+3){
+ av_log(h->s.avctx, AV_LOG_ERROR, "Invalid level prefix\n");
+ return -1;
+ }
level_code += (1<<(prefix-3))-4096;
+ }
}
if(trailing_ones < 3) level_code += 2;
if(total_coeff == max_coeff)
zeros_left=0;
else{
- if(n == CHROMA_DC_BLOCK_INDEX)
+ if(n >= CHROMA_DC_BLOCK_INDEX)
zeros_left= get_vlc2(gb, (chroma_dc_total_zeros_vlc-1)[ total_coeff ].table, CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 1);
else
zeros_left= get_vlc2(gb, (total_zeros_vlc-1)[ total_coeff ].table, TOTAL_ZEROS_VLC_BITS, 1);
}
- coeff_num = zeros_left + total_coeff - 1;
- j = scantable[coeff_num];
- if(n > 24){
- block[j] = level[0];
- for(i=1;i<total_coeff;i++) {
- if(zeros_left <= 0)
- run_before = 0;
- else if(zeros_left < 7){
+ scantable += zeros_left + total_coeff - 1;
+ if(n >= LUMA_DC_BLOCK_INDEX){
+ block[*scantable] = level[0];
+ for(i=1;i<total_coeff && zeros_left > 0;i++) {
+ if(zeros_left < 7)
run_before= get_vlc2(gb, (run_vlc-1)[zeros_left].table, RUN_VLC_BITS, 1);
- }else{
+ else
run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2);
- }
zeros_left -= run_before;
- coeff_num -= 1 + run_before;
- j= scantable[ coeff_num ];
-
- block[j]= level[i];
+ scantable -= 1 + run_before;
+ block[*scantable]= level[i];
+ }
+ for(;i<total_coeff;i++) {
+ scantable--;
+ block[*scantable]= level[i];
}
}else{
- block[j] = (level[0] * qmul[j] + 32)>>6;
- for(i=1;i<total_coeff;i++) {
- if(zeros_left <= 0)
- run_before = 0;
- else if(zeros_left < 7){
+ block[*scantable] = (level[0] * qmul[*scantable] + 32)>>6;
+ for(i=1;i<total_coeff && zeros_left > 0;i++) {
+ if(zeros_left < 7)
run_before= get_vlc2(gb, (run_vlc-1)[zeros_left].table, RUN_VLC_BITS, 1);
- }else{
+ else
run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2);
- }
zeros_left -= run_before;
- coeff_num -= 1 + run_before;
- j= scantable[ coeff_num ];
-
- block[j]= (level[i] * qmul[j] + 32)>>6;
+ scantable -= 1 + run_before;
+ block[*scantable]= (level[i] * qmul[*scantable] + 32)>>6;
+ }
+ for(;i<total_coeff;i++) {
+ scantable--;
+ block[*scantable]= (level[i] * qmul[*scantable] + 32)>>6;
}
}
if(FRAME_MBAFF && (s->mb_y&1) == 0){
if(s->mb_skip_run==0)
h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&s->gb);
- else
- predict_field_decoding_flag(h);
}
decode_mb_skip(h);
return 0;
h->ref_count[1] <<= 1;
}
+ fill_decode_neighbors(h, mb_type);
fill_decode_caches(h, mb_type);
//mb_pred
if(pred_mode < 0)
return -1;
h->chroma_pred_mode= pred_mode;
+ } else {
+ h->chroma_pred_mode = DC_128_PRED8x8;
}
}else if(partition_count==4){
int i, j, sub_partition_count[4], list, ref[2][4];
return -1;
}
}
- }else
- val= LIST_NOT_USED&0xFF;
fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, val, 1);
+ }
}
for(list=0; list<h->list_count; list++){
- unsigned int val;
if(IS_DIR(mb_type, 0, list)){
pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my);
mx += get_se_golomb(&s->gb);
my += get_se_golomb(&s->gb);
tprintf(s->avctx, "final mv:%d %d\n", mx, my);
- val= pack16to32(mx,my);
- }else
- val=0;
- fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, val, 4);
+ fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4);
+ }
}
}
else if(IS_16X8(mb_type)){
}
if(dct8x8_allowed && (cbp&15) && !IS_INTRA(mb_type)){
- if(get_bits1(&s->gb)){
- mb_type |= MB_TYPE_8x8DCT;
- }
+ mb_type |= MB_TYPE_8x8DCT*get_bits1(&s->gb);
}
h->cbp=
h->cbp_table[mb_xy]= cbp;
int i8x8, i4x4, chroma_idx;
int dquant;
GetBitContext *gb= IS_INTRA(mb_type) ? h->intra_gb_ptr : h->inter_gb_ptr;
- const uint8_t *scan, *scan8x8, *dc_scan;
+ const uint8_t *scan, *scan8x8;
if(IS_INTERLACED(mb_type)){
scan8x8= s->qscale ? h->field_scan8x8_cavlc : h->field_scan8x8_cavlc_q0;
scan= s->qscale ? h->field_scan : h->field_scan_q0;
- dc_scan= luma_dc_field_scan;
}else{
scan8x8= s->qscale ? h->zigzag_scan8x8_cavlc : h->zigzag_scan8x8_cavlc_q0;
scan= s->qscale ? h->zigzag_scan : h->zigzag_scan_q0;
- dc_scan= luma_dc_zigzag_scan;
}
dquant= get_se_golomb(&s->gb);
h->chroma_qp[0]= get_chroma_qp(h, 0, s->qscale);
h->chroma_qp[1]= get_chroma_qp(h, 1, s->qscale);
if(IS_INTRA16x16(mb_type)){
- if( decode_residual(h, h->intra_gb_ptr, h->mb, LUMA_DC_BLOCK_INDEX, dc_scan, h->dequant4_coeff[0][s->qscale], 16) < 0){
+ AV_ZERO128(h->mb_luma_dc+0);
+ AV_ZERO128(h->mb_luma_dc+8);
+ if( decode_residual(h, h->intra_gb_ptr, h->mb_luma_dc, LUMA_DC_BLOCK_INDEX, scan, h->dequant4_coeff[0][s->qscale], 16) < 0){
return -1; //FIXME continue if partitioned and other return -1 too
}
if(cbp&0x30){
for(chroma_idx=0; chroma_idx<2; chroma_idx++)
- if( decode_residual(h, gb, h->mb + 256 + 16*4*chroma_idx, CHROMA_DC_BLOCK_INDEX, chroma_dc_scan, NULL, 4) < 0){
+ if( decode_residual(h, gb, h->mb + 256 + 16*4*chroma_idx, CHROMA_DC_BLOCK_INDEX+chroma_idx, chroma_dc_scan, NULL, 4) < 0){
return -1;
}
}