[Ffmpeg-devel] H.264 encoder

Panagiotis Issaris takis.issaris
Thu Oct 12 11:31:39 CEST 2006


Hi,

On Wed, Oct 11, 2006 at 10:09:56PM +0200, Michael Niedermayer wrote:
[...]
> > > probably not -> change pred_non_zero_count() so it takes the top and left
> > > values as arguments instead of H264Context, or change it so a it takes a
> > > pointer to non_zero_count_cache ...
> > 
> > Something like the attached patch does? Or should I drop the const and move left
> > and top to the outer scope?
> 
> id move them out as the resulting code is simpler ...
I've attached two patches, one moving them to the outermost scope (well, within
the function) and one one scopelevel higher. Which one do you prefer (if any :)
)
?

With friendly regards,
Takis
-------------- next part --------------
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index cfb6116..0c9bd0f 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -1115,15 +1115,12 @@ static inline void write_back_non_zero_c
  * gets the predicted number of non zero coefficients.
  * @param n block index
  */
-static inline int pred_non_zero_count(H264Context *h, int n){
-    const int index8= scan8[n];
-    const int left= h->non_zero_count_cache[index8 - 1];
-    const int top = h->non_zero_count_cache[index8 - 8];
+static inline int pred_non_zero_count(H264Context *h, int left, int top){
     int i= left + top;
 
     if(i<64) i= (i+1)>>1;
 
-    tprintf("pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], i&31);
+    tprintf("pred_nnz L%X T%X P%X\n", left, top, i&31);
 
     return i&31;
 }
@@ -4956,12 +4953,20 @@ static int decode_residual(H264Context *
         coeff_token= get_vlc2(gb, chroma_dc_coeff_token_vlc.table, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 1);
         total_coeff= coeff_token>>2;
     }else{
+        int top, left;
         if(n == LUMA_DC_BLOCK_INDEX){
-            total_coeff= pred_non_zero_count(h, 0);
+            left= h->non_zero_count_cache[11];
+            top = h->non_zero_count_cache[4];
+            total_coeff= pred_non_zero_count(h, left, top);
+            tprintf("pred_nnz L%X T%X n%d s%d P%X\n", left, top, 0, 12, total_coeff);
             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;
         }else{
-            total_coeff= pred_non_zero_count(h, n);
+            const int index8= scan8[n];
+            left= h->non_zero_count_cache[index8 - 1];
+            top = h->non_zero_count_cache[index8 - 8];
+            total_coeff= pred_non_zero_count(h, left, top);
+            tprintf("pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], total_coeff);
             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;
-------------- next part --------------
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index cfb6116..55a0b9c 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -1115,15 +1115,12 @@ static inline void write_back_non_zero_c
  * gets the predicted number of non zero coefficients.
  * @param n block index
  */
-static inline int pred_non_zero_count(H264Context *h, int n){
-    const int index8= scan8[n];
-    const int left= h->non_zero_count_cache[index8 - 1];
-    const int top = h->non_zero_count_cache[index8 - 8];
+static inline int pred_non_zero_count(H264Context *h, int left, int top){
     int i= left + top;
 
     if(i<64) i= (i+1)>>1;
 
-    tprintf("pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], i&31);
+    tprintf("pred_nnz L%X T%X P%X\n", left, top, i&31);
 
     return i&31;
 }
@@ -4949,6 +4946,7 @@ static int decode_residual(H264Context *
     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 top, left;
 
     //FIXME put trailing_onex into the context
 
@@ -4957,11 +4955,18 @@ static int decode_residual(H264Context *
         total_coeff= coeff_token>>2;
     }else{
         if(n == LUMA_DC_BLOCK_INDEX){
-            total_coeff= pred_non_zero_count(h, 0);
+            left= h->non_zero_count_cache[11];
+            top = h->non_zero_count_cache[4];
+            total_coeff= pred_non_zero_count(h, left, top);
+            tprintf("pred_nnz L%X T%X n%d s%d P%X\n", left, top, 0, 12, total_coeff);
             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;
         }else{
-            total_coeff= pred_non_zero_count(h, n);
+            const int index8= scan8[n];
+            left= h->non_zero_count_cache[index8 - 1];
+            top = h->non_zero_count_cache[index8 - 8];
+            total_coeff= pred_non_zero_count(h, left, top);
+            tprintf("pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], total_coeff);
             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;



More information about the ffmpeg-devel mailing list