* @author Michael Niedermayer <michaelni@gmx.at>
*/
-#define CABAC 1
+#define CABAC(h) 1
+#include "libavutil/attributes.h"
#include "config.h"
#include "cabac.h"
#include "cabac_functions.h"
#include "internal.h"
-#include "dsputil.h"
#include "avcodec.h"
#include "h264.h"
#include "h264data.h"
#include "x86/h264_i386.h"
#endif
-//#undef NDEBUG
#include <assert.h>
/* Cabac pre state table */
unsigned long ctx = 0;
- ctx += h->mb_field_decoding_flag & !!h->mb_x; //for FMO:(s->current_picture.f.mb_type[mba_xy] >> 7) & (h->slice_table[mba_xy] == h->slice_num);
- ctx += (h->cur_pic.f.mb_type[mbb_xy] >> 7) & (h->slice_table[mbb_xy] == h->slice_num);
+ ctx += h->mb_field_decoding_flag & !!h->mb_x; //for FMO:(s->current_picture.mb_type[mba_xy] >> 7) & (h->slice_table[mba_xy] == h->slice_num);
+ ctx += (h->cur_pic.mb_type[mbb_xy] >> 7) & (h->slice_table[mbb_xy] == h->slice_num);
return get_cabac_noinline( &h->cabac, &(h->cabac_state+70)[ctx] );
}
int mba_xy, mbb_xy;
int ctx = 0;
- if(FRAME_MBAFF){ //FIXME merge with the stuff in fill_caches?
+ if (FRAME_MBAFF(h)) { //FIXME merge with the stuff in fill_caches?
int mb_xy = mb_x + (mb_y&~1)*h->mb_stride;
mba_xy = mb_xy - 1;
if( (mb_y&1)
&& h->slice_table[mba_xy] == h->slice_num
- && MB_FIELD == !!IS_INTERLACED( h->cur_pic.f.mb_type[mba_xy] ) )
+ && MB_FIELD(h) == !!IS_INTERLACED( h->cur_pic.mb_type[mba_xy] ) )
mba_xy += h->mb_stride;
- if( MB_FIELD ){
+ if (MB_FIELD(h)) {
mbb_xy = mb_xy - h->mb_stride;
if( !(mb_y&1)
&& h->slice_table[mbb_xy] == h->slice_num
- && IS_INTERLACED( h->cur_pic.f.mb_type[mbb_xy] ) )
+ && IS_INTERLACED( h->cur_pic.mb_type[mbb_xy] ) )
mbb_xy -= h->mb_stride;
}else
mbb_xy = mb_x + (mb_y-1)*h->mb_stride;
}else{
int mb_xy = h->mb_xy;
mba_xy = mb_xy - 1;
- mbb_xy = mb_xy - (h->mb_stride << FIELD_PICTURE);
+ mbb_xy = mb_xy - (h->mb_stride << FIELD_PICTURE(h));
}
- if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP(h->cur_pic.f.mb_type[mba_xy] ))
+ if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP(h->cur_pic.mb_type[mba_xy] ))
ctx++;
- if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP(h->cur_pic.f.mb_type[mbb_xy] ))
+ if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP(h->cur_pic.mb_type[mbb_xy] ))
ctx++;
if( h->slice_type_nos == AV_PICTURE_TYPE_B )
#endif
significant_coeff_ctx_base = h->cabac_state
- + significant_coeff_flag_offset[MB_FIELD][cat];
+ + significant_coeff_flag_offset[MB_FIELD(h)][cat];
last_coeff_ctx_base = h->cabac_state
- + last_coeff_flag_offset[MB_FIELD][cat];
+ + last_coeff_flag_offset[MB_FIELD(h)][cat];
abs_level_m1_ctx_base = h->cabac_state
+ coeff_abs_level_m1_offset[cat];
if( last == max_coeff -1 ) {\
index[coeff_count++] = last;\
}
- const uint8_t *sig_off = significant_coeff_flag_offset_8x8[MB_FIELD];
+ const uint8_t *sig_off = significant_coeff_flag_offset_8x8[MB_FIELD(h)];
#ifdef decode_significance
coeff_count = decode_significance_8x8(CC, significant_coeff_ctx_base, index,
last_coeff_ctx_base, sig_off);
}
-static void decode_cabac_residual_dc_internal(H264Context *h, int16_t *block,
- int cat, int n,
- const uint8_t *scantable,
- int max_coeff)
+static av_noinline void decode_cabac_residual_dc_internal(H264Context *h,
+ int16_t *block,
+ int cat, int n,
+ const uint8_t *scantable,
+ int max_coeff)
{
decode_cabac_residual_internal(h, block, cat, n, scantable, NULL, max_coeff, 1, 0);
}
-static void decode_cabac_residual_dc_internal_422(H264Context *h, int16_t *block,
- int cat, int n, const uint8_t *scantable,
- int max_coeff)
+static av_noinline void decode_cabac_residual_dc_internal_422(H264Context *h,
+ int16_t *block,
+ int cat, int n,
+ const uint8_t *scantable,
+ int max_coeff)
{
decode_cabac_residual_internal(h, block, cat, n, scantable, NULL, max_coeff, 1, 1);
}
-static void decode_cabac_residual_nondc_internal(H264Context *h, int16_t *block,
- int cat, int n,
- const uint8_t *scantable,
- const uint32_t *qmul,
- int max_coeff)
+static av_noinline void decode_cabac_residual_nondc_internal(H264Context *h,
+ int16_t *block,
+ int cat, int n,
+ const uint8_t *scantable,
+ const uint32_t *qmul,
+ int max_coeff)
{
decode_cabac_residual_internal(h, block, cat, n, scantable, qmul, max_coeff, 0, 0);
}
int max_coeff)
{
/* read coded block flag */
- if( (cat != 5 || CHROMA444) && get_cabac( &h->cabac, &h->cabac_state[get_cabac_cbf_ctx( h, cat, n, max_coeff, 0 ) ] ) == 0 ) {
+ if( (cat != 5 || CHROMA444(h)) && get_cabac( &h->cabac, &h->cabac_state[get_cabac_cbf_ctx( h, cat, n, max_coeff, 0 ) ] ) == 0 ) {
if( max_coeff == 64 ) {
fill_rectangle(&h->non_zero_count_cache[scan8[n]], 2, 2, 8, 0, 1);
} else {
if( h->slice_type_nos != AV_PICTURE_TYPE_I ) {
int skip;
/* a skipped mb needs the aff flag from the following mb */
- if( FRAME_MBAFF && (h->mb_y&1)==1 && h->prev_mb_skipped )
+ if (FRAME_MBAFF(h) && (h->mb_y & 1) == 1 && h->prev_mb_skipped)
skip = h->next_mb_skipped;
else
skip = decode_cabac_mb_skip( h, h->mb_x, h->mb_y );
/* read skip flags */
if( skip ) {
- if( FRAME_MBAFF && (h->mb_y&1)==0 ){
- h->cur_pic.f.mb_type[mb_xy] = MB_TYPE_SKIP;
+ if (FRAME_MBAFF(h) && (h->mb_y & 1) == 0) {
+ h->cur_pic.mb_type[mb_xy] = MB_TYPE_SKIP;
h->next_mb_skipped = decode_cabac_mb_skip( h, h->mb_x, h->mb_y+1 );
if(!h->next_mb_skipped)
h->mb_mbaff = h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h);
}
}
- if(FRAME_MBAFF){
+ if (FRAME_MBAFF(h)) {
if( (h->mb_y&1) == 0 )
h->mb_mbaff =
h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h);
h->prev_mb_skipped = 0;
- fill_decode_neighbors(h, -(MB_FIELD));
+ fill_decode_neighbors(h, -(MB_FIELD(h)));
if( h->slice_type_nos == AV_PICTURE_TYPE_B ) {
int ctx = 0;
h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode;
mb_type= i_mb_type_info[mb_type].type;
}
- if(MB_FIELD)
+ if(MB_FIELD(h))
mb_type |= MB_TYPE_INTERLACED;
h->slice_table[ mb_xy ]= h->slice_num;
// The pixels are stored in the same order as levels in h->mb array.
if ((int) (h->cabac.bytestream_end - ptr) < mb_size)
return -1;
- memcpy(h->mb, ptr, mb_size); ptr+=mb_size;
+ h->intra_pcm_ptr = ptr;
+ ptr += mb_size;
ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr);
h->cbp_table[mb_xy] = 0xf7ef;
h->chroma_pred_mode_table[mb_xy] = 0;
// In deblocking, the quantizer is 0
- h->cur_pic.f.qscale_table[mb_xy] = 0;
+ h->cur_pic.qscale_table[mb_xy] = 0;
// All coeffs are present
memset(h->non_zero_count[mb_xy], 16, 48);
- h->cur_pic.f.mb_type[mb_xy] = mb_type;
+ h->cur_pic.mb_type[mb_xy] = mb_type;
h->last_qscale_diff = 0;
return 0;
}
for( i = 0; i < 4; i++ ) {
if(IS_DIRECT(h->sub_mb_type[i])) continue;
if(IS_DIR(h->sub_mb_type[i], 0, list)){
- int rc = h->ref_count[list] << MB_MBAFF;
+ int rc = h->ref_count[list] << MB_MBAFF(h);
if (rc > 1) {
ref[list][i] = decode_cabac_mb_ref( h, list, 4*i );
if (ref[list][i] >= (unsigned) rc) {
if(IS_16X16(mb_type)){
for(list=0; list<h->list_count; list++){
if(IS_DIR(mb_type, 0, list)){
- int ref, rc = h->ref_count[list] << MB_MBAFF;
+ int ref, rc = h->ref_count[list] << MB_MBAFF(h);
if (rc > 1) {
ref= decode_cabac_mb_ref(h, list, 0);
if (ref >= (unsigned) rc) {
for(list=0; list<h->list_count; list++){
for(i=0; i<2; i++){
if(IS_DIR(mb_type, i, list)){
- int ref, rc = h->ref_count[list] << MB_MBAFF;
+ int ref, rc = h->ref_count[list] << MB_MBAFF(h);
if (rc > 1) {
ref= decode_cabac_mb_ref( h, list, 8*i );
if (ref >= (unsigned) rc) {
for(list=0; list<h->list_count; list++){
for(i=0; i<2; i++){
if(IS_DIR(mb_type, i, list)){ //FIXME optimize
- int ref, rc = h->ref_count[list] << MB_MBAFF;
+ int ref, rc = h->ref_count[list] << MB_MBAFF(h);
if (rc > 1) {
ref= decode_cabac_mb_ref( h, list, 4*i );
if (ref >= (unsigned) rc) {
/* It would be better to do this in fill_decode_caches, but we don't know
* the transform mode of the current macroblock there. */
- if (CHROMA444 && IS_8x8DCT(mb_type)){
+ if (CHROMA444(h) && IS_8x8DCT(mb_type)){
int i;
uint8_t *nnz_cache = h->non_zero_count_cache;
for (i = 0; i < 2; i++){
}
}
if (h->top_type && !IS_8x8DCT(h->top_type)){
- uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040;
+ uint32_t top_empty = CABAC(h) && !IS_INTRA(mb_type) ? 0 : 0x40404040;
AV_WN32A(&nnz_cache[4+8* 0], top_empty);
AV_WN32A(&nnz_cache[4+8* 5], top_empty);
AV_WN32A(&nnz_cache[4+8*10], top_empty);
}
}
- h->cur_pic.f.mb_type[mb_xy] = mb_type;
+ h->cur_pic.mb_type[mb_xy] = mb_type;
if( cbp || IS_INTRA16x16( mb_type ) ) {
const uint8_t *scan, *scan8x8;
h->last_qscale_diff=0;
decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 0);
- if(CHROMA444){
+ if (CHROMA444(h)) {
decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 1);
decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 2);
- } else if (CHROMA422) {
+ } else if (CHROMA422(h)) {
if( cbp&0x30 ){
int c;
for (c = 0; c < 2; c++)
h->last_qscale_diff = 0;
}
- h->cur_pic.f.qscale_table[mb_xy] = h->qscale;
+ h->cur_pic.qscale_table[mb_xy] = h->qscale;
write_back_non_zero_count(h);
return 0;