]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/h264_cabac.c
Move av_fast_{m,re}alloc from lavc to lavu.
[ffmpeg] / libavcodec / h264_cabac.c
index 12eb2c7b2247c67d8468e7b75f522e814b350444..43ddf7d56e59b8ae94247db12d02d6d0cbbedde3 100644 (file)
@@ -25,8 +25,9 @@
  * @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"
@@ -41,7 +42,6 @@
 #include "x86/h264_i386.h"
 #endif
 
-//#undef NDEBUG
 #include <assert.h>
 
 /* Cabac pre state table */
@@ -1323,14 +1323,14 @@ static int decode_cabac_mb_skip( H264Context *h, int mb_x, int mb_y ) {
     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.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
@@ -1341,7 +1341,7 @@ static int decode_cabac_mb_skip( H264Context *h, int mb_x, int mb_y ) {
     }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.mb_type[mba_xy] ))
@@ -1625,9 +1625,9 @@ decode_cabac_residual_internal(H264Context *h, int16_t *block,
 #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];
 
@@ -1647,7 +1647,7 @@ decode_cabac_residual_internal(H264Context *h, int16_t *block,
         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);
@@ -1741,26 +1741,30 @@ decode_cabac_residual_internal(H264Context *h, int16_t *block,
 
 }
 
-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);
 }
@@ -1812,7 +1816,7 @@ static av_always_inline void decode_cabac_residual_nondc(H264Context *h,
                                                          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 {
@@ -1886,13 +1890,13 @@ int ff_h264_decode_mb_cabac(H264Context *h) {
     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 ){
+            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)
@@ -1909,7 +1913,7 @@ int ff_h264_decode_mb_cabac(H264Context *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);
@@ -1917,7 +1921,7 @@ int ff_h264_decode_mb_cabac(H264Context *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;
@@ -1981,7 +1985,7 @@ decode_intra_mb:
         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;
@@ -2088,7 +2092,7 @@ decode_intra_mb:
                 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) {
@@ -2174,7 +2178,7 @@ decode_intra_mb:
         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) {
@@ -2202,7 +2206,7 @@ decode_intra_mb:
             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) {
@@ -2237,7 +2241,7 @@ decode_intra_mb:
             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) {
@@ -2289,7 +2293,7 @@ decode_intra_mb:
 
     /* 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++){
@@ -2303,7 +2307,7 @@ decode_intra_mb:
             }
         }
         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);
@@ -2354,10 +2358,10 @@ decode_intra_mb:
             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++)