shithub: libvpx

Download patch

ref: 4fa8d36f760904c1ad6c8e64597ab2afc8340d11
parent: 6a80032280305c41f20403b07698ca969ec7edb2
parent: 3ac73173a4c7e5be0a9846bc323699e7365c60ee
author: John Koleszar <jkoleszar@google.com>
date: Wed Dec 15 03:08:18 EST 2010

Merge remote branch 'origin/master' into experimental

Conflicts:
	vp8/common/entropy.c

Change-Id: I35fd49cf92a50d09082fe199d3bf21bfca68a94f

--- a/vp8/common/entropy.c
+++ b/vp8/common/entropy.c
@@ -36,7 +36,7 @@
     7, 11, 14, 15,
 };
 
-DECLARE_ALIGNED(16, const short, vp8_default_inv_zig_zag[16]) = 
+DECLARE_ALIGNED(16, const short, vp8_default_inv_zig_zag[16]) =
 {
     1,  2,  6,  7,
     3,  5,  8, 13,
@@ -114,23 +114,20 @@
     init_bit_tree(cat6, 13);
 }
 
-
-static vp8bc_index_t bcc1[1], bcc2[2], bcc3[3], bcc4[4], bcc5[5], bcc6[11];
-
 vp8_extra_bit_struct vp8_extra_bits[12] =
 {
-    { 0, 0, 0, 0, 0},
-    { 0, 0, 0, 0, 1},
-    { 0, 0, 0, 0, 2},
-    { 0, 0, 0, 0, 3},
-    { 0, 0, 0, 0, 4},
-    { cat1, Pcat1, bcc1, 1, 5},
-    { cat2, Pcat2, bcc2, 2, 7},
-    { cat3, Pcat3, bcc3, 3, 11},
-    { cat4, Pcat4, bcc4, 4, 19},
-    { cat5, Pcat5, bcc5, 5, 35},
-    { cat6, Pcat6, bcc6, 13, 67},
-    { 0, 0, 0, 0, 0}
+    { 0, 0, 0, 0},
+    { 0, 0, 0, 1},
+    { 0, 0, 0, 2},
+    { 0, 0, 0, 3},
+    { 0, 0, 0, 4},
+    { cat1, Pcat1, 1, 5},
+    { cat2, Pcat2, 2, 7},
+    { cat3, Pcat3, 3, 11},
+    { cat4, Pcat4, 4, 19},
+    { cat5, Pcat5, 5, 35},
+    { cat6, Pcat6, 13, 67},
+    { 0, 0, 0, 0}
 };
 #include "defaultcoefcounts.h"
 
--- a/vp8/common/entropy.h
+++ b/vp8/common/entropy.h
@@ -42,7 +42,6 @@
 {
     vp8_tree_p tree;
     const vp8_prob *prob;
-    vp8bc_index_t *prob_bc;
     int Len;
     int base_val;
 } vp8_extra_bit_struct;
--- a/vp8/encoder/arm/armv5te/vp8_packtokens_armv5.asm
+++ b/vp8/encoder/arm/armv5te/vp8_packtokens_armv5.asm
@@ -29,10 +29,9 @@
     push    {r4-r11, lr}
 
     ; Add size of xcount * sizeof (TOKENEXTRA) to get stop
-    ;  sizeof (TOKENEXTRA) is 20
-    add     r2, r2, r2, lsl #2          ; xcount
+    ;  sizeof (TOKENEXTRA) is 8
     sub     sp, sp, #12
-    add     r2, r1, r2, lsl #2          ; stop = p + xcount
+    add     r2, r1, r2, lsl #3          ; stop = p + xcount*sizeof(TOKENEXTRA)
     str     r2, [sp, #0]
     str     r3, [sp, #8]                ; save vp8_coef_encodings
     ldr     r2, [r0, #vp8_writer_lowvalue]
@@ -41,13 +40,13 @@
     b       check_p_lt_stop
 
 while_p_lt_stop
-    ldr     r6, [r1, #tokenextra_token] ; t
+    ldrb    r6, [r1, #tokenextra_token] ; t
     ldr     r4, [sp, #8]                ; vp8_coef_encodings
     mov     lr, #0
     add     r4, r4, r6, lsl #3          ; a = vp8_coef_encodings + t
     ldr     r9, [r1, #tokenextra_context_tree]   ; pp
 
-    ldr     r7, [r1, #tokenextra_skip_eob_node]
+    ldrb    r7, [r1, #tokenextra_skip_eob_node]
 
     ldr     r6, [r4, #vp8_token_value]  ; v
     ldr     r8, [r4, #vp8_token_len]    ; n
@@ -142,12 +141,11 @@
     subs    r8, r8, #1                  ; --n
     bne     token_loop
 
-    ldr     r6, [r1, #tokenextra_token] ; t
+    ldrb    r6, [r1, #tokenextra_token] ; t
     ldr     r7, [sp, #48]               ; vp8_extra_bits
     ; Add t * sizeof (vp8_extra_bit_struct) to get the desired
-    ;  element.  Here vp8_extra_bit_struct == 20
-    add     r6, r6, r6, lsl #2          ; b = vp8_extra_bits + t
-    add     r12, r7, r6, lsl #2         ; b = vp8_extra_bits + t
+    ;  element.  Here vp8_extra_bit_struct == 16
+    add     r12, r7, r6, lsl #4         ; b = vp8_extra_bits + t
 
     ldr     r4, [r12, #vp8_extra_bit_struct_base_val]
     cmp     r4, #0
@@ -155,7 +153,7 @@
 
 ;   if( b->base_val)
     ldr     r8, [r12, #vp8_extra_bit_struct_len] ; L
-    ldr     lr, [r1, #tokenextra_extra] ; e = p->Extra
+    ldrsh   lr, [r1, #tokenextra_extra] ; e = p->Extra
     cmp     r8, #0                      ; if( L)
     beq     no_extra_bits
 
--- a/vp8/encoder/arm/armv5te/vp8_packtokens_mbrow_armv5.asm
+++ b/vp8/encoder/arm/armv5te/vp8_packtokens_mbrow_armv5.asm
@@ -62,13 +62,13 @@
     ; actuall work gets done here!
 
 while_p_lt_stop
-    ldr     r6, [r1, #tokenextra_token] ; t
+    ldrb    r6, [r1, #tokenextra_token] ; t
     ldr     r4, [sp, #20]               ; vp8_coef_encodings
     mov     lr, #0
     add     r4, r4, r6, lsl #3          ; a = vp8_coef_encodings + t
     ldr     r9, [r1, #tokenextra_context_tree]   ; pp
 
-    ldr     r7, [r1, #tokenextra_skip_eob_node]
+    ldrb    r7, [r1, #tokenextra_skip_eob_node]
 
     ldr     r6, [r4, #vp8_token_value]  ; v
     ldr     r8, [r4, #vp8_token_len]    ; n
@@ -163,12 +163,11 @@
     subs    r8, r8, #1                  ; --n
     bne     token_loop
 
-    ldr     r6, [r1, #tokenextra_token] ; t
+    ldrb    r6, [r1, #tokenextra_token] ; t
     ldr     r7, [sp, #8]                ; vp8_extra_bits
     ; Add t * sizeof (vp8_extra_bit_struct) to get the desired
-    ;  element.  Here vp8_extra_bit_struct == 20
-    add     r6, r6, r6, lsl #2          ; b = vp8_extra_bits + t
-    add     r12, r7, r6, lsl #2         ; b = vp8_extra_bits + t
+    ;  element.  Here vp8_extra_bit_struct == 16
+    add     r12, r7, r6, lsl #4         ; b = vp8_extra_bits + t
 
     ldr     r4, [r12, #vp8_extra_bit_struct_base_val]
     cmp     r4, #0
@@ -176,7 +175,7 @@
 
 ;   if( b->base_val)
     ldr     r8, [r12, #vp8_extra_bit_struct_len] ; L
-    ldr     lr, [r1, #tokenextra_extra] ; e = p->Extra
+    ldrsh   lr, [r1, #tokenextra_extra] ; e = p->Extra
     cmp     r8, #0                      ; if( L)
     beq     no_extra_bits
 
--- a/vp8/encoder/arm/armv5te/vp8_packtokens_partitions_armv5.asm
+++ b/vp8/encoder/arm/armv5te/vp8_packtokens_partitions_armv5.asm
@@ -90,13 +90,13 @@
     ; actual work gets done here!
 
 while_p_lt_stop
-    ldr     r6, [r1, #tokenextra_token] ; t
+    ldrb    r6, [r1, #tokenextra_token] ; t
     ldr     r4, [sp, #80]               ; vp8_coef_encodings
     mov     lr, #0
     add     r4, r4, r6, lsl #3          ; a = vp8_coef_encodings + t
     ldr     r9, [r1, #tokenextra_context_tree]   ; pp
 
-    ldr     r7, [r1, #tokenextra_skip_eob_node]
+    ldrb    r7, [r1, #tokenextra_skip_eob_node]
 
     ldr     r6, [r4, #vp8_token_value]  ; v
     ldr     r8, [r4, #vp8_token_len]    ; n
@@ -191,12 +191,11 @@
     subs    r8, r8, #1                  ; --n
     bne     token_loop
 
-    ldr     r6, [r1, #tokenextra_token] ; t
+    ldrb    r6, [r1, #tokenextra_token] ; t
     ldr     r7, [sp, #84]                ; vp8_extra_bits
     ; Add t * sizeof (vp8_extra_bit_struct) to get the desired
-    ;  element.  Here vp8_extra_bit_struct == 20
-    add     r6, r6, r6, lsl #2          ; b = vp8_extra_bits + t
-    add     r12, r7, r6, lsl #2         ; b = vp8_extra_bits + t
+    ;  element.  Here vp8_extra_bit_struct == 16
+    add     r12, r7, r6, lsl #4         ; b = vp8_extra_bits + t
 
     ldr     r4, [r12, #vp8_extra_bit_struct_base_val]
     cmp     r4, #0
@@ -204,7 +203,7 @@
 
 ;   if( b->base_val)
     ldr     r8, [r12, #vp8_extra_bit_struct_len] ; L
-    ldr     lr, [r1, #tokenextra_extra] ; e = p->Extra
+    ldrsh   lr, [r1, #tokenextra_extra] ; e = p->Extra
     cmp     r8, #0                      ; if( L)
     beq     no_extra_bits
 
--- a/vp8/encoder/arm/vpx_vp8_enc_asm_offsets.c
+++ b/vp8/encoder/arm/vpx_vp8_enc_asm_offsets.c
@@ -51,7 +51,6 @@
 
 DEFINE(vp8_extra_bit_struct_tree,                 offsetof(vp8_extra_bit_struct, tree));
 DEFINE(vp8_extra_bit_struct_prob,                 offsetof(vp8_extra_bit_struct, prob));
-DEFINE(vp8_extra_bit_struct_prob_bc,               offsetof(vp8_extra_bit_struct, prob_bc));
 DEFINE(vp8_extra_bit_struct_len,                  offsetof(vp8_extra_bit_struct, Len));
 DEFINE(vp8_extra_bit_struct_base_val,              offsetof(vp8_extra_bit_struct, base_val));
 
@@ -67,8 +66,8 @@
 
 // These two sizes are used in vp7cx_pack_tokens.  They are hard coded
 //  so if the size changes this will have to be adjusted.
-ct_assert(TOKENEXTRA_SZ, sizeof(TOKENEXTRA) == 20)
-ct_assert(vp8_extra_bit_struct_sz, sizeof(vp8_extra_bit_struct) == 20)
+ct_assert(TOKENEXTRA_SZ, sizeof(TOKENEXTRA) == 8)
+ct_assert(vp8_extra_bit_struct_sz, sizeof(vp8_extra_bit_struct) == 16)
 
 //add asserts for any offset that is not supported by assembly code
 //add asserts for any size that is not supported by assembly code
--- a/vp8/encoder/ethreading.c
+++ b/vp8/encoder/ethreading.c
@@ -281,6 +281,7 @@
     z->vp8_short_fdct8x4     = x->vp8_short_fdct8x4;
     z->short_walsh4x4    = x->short_walsh4x4;
     z->quantize_b        = x->quantize_b;
+    z->optimize          = x->optimize;
 
     /*
     z->mvc              = x->mvc;
--- a/vp8/encoder/mcomp.c
+++ b/vp8/encoder/mcomp.c
@@ -941,6 +941,18 @@
     unsigned char *check_here;
     int thissad;
 
+    int search_range = 128>>search_param;
+
+    *num00 = 0;
+
+    // Trap uncodable vectors
+    if (((abs(ref_mv->col - center_mv->col) + (search_range<<4)) > MAX_POSSIBLE_MV) || ((abs(ref_mv->row - center_mv->row) + (search_range<<4)) > MAX_POSSIBLE_MV))
+    {
+        best_mv->row = ref_row;
+        best_mv->col = ref_col;
+        return INT_MAX;
+    }
+
     // Work out the start point for the search
     in_what = (unsigned char *)(*(d->base_pre) + d->pre + (ref_row * (d->pre_stride)) + ref_col);
     best_address = in_what;
@@ -962,8 +974,6 @@
     best_mv->row = ref_row;
     best_mv->col = ref_col;
 
-    *num00 = 0;
-
     for (step = 0; step < tot_steps ; step++)
     {
         for (j = 0 ; j < x->searches_per_step ; j++)
@@ -1057,6 +1067,18 @@
     unsigned char *check_here;
     unsigned int thissad;
 
+    int search_range = 128>>search_param;
+
+    *num00 = 0;
+
+    // Trap uncodable vectors
+    if (((abs(ref_mv->col - center_mv->col) + (search_range<<4)) > MAX_POSSIBLE_MV) || ((abs(ref_mv->row - center_mv->row) + (search_range<<4)) > MAX_POSSIBLE_MV))
+    {
+        best_mv->row = ref_row;
+        best_mv->col = ref_col;
+        return INT_MAX;
+    }
+
     // Work out the start point for the search
     in_what = (unsigned char *)(*(d->base_pre) + d->pre + (ref_row * (d->pre_stride)) + ref_col);
     best_address = in_what;
@@ -1078,8 +1100,6 @@
     best_mv->row = ref_row;
     best_mv->col = ref_col;
 
-    *num00 = 0;
-
     for (step = 0; step < tot_steps ; step++)
     {
         int all_in = 1, t;
@@ -1194,11 +1214,25 @@
     int ref_row = ref_mv->row >> 3;
     int ref_col = ref_mv->col >> 3;
 
-    int row_min = ref_row - distance;
-    int row_max = ref_row + distance;
-    int col_min = ref_col - distance;
-    int col_max = ref_col + distance;
+    int row_min, row_max, col_min, col_max;
 
+    int drow = abs(ref_mv->row - center_mv->row);
+    int dcol = abs(ref_mv->col - center_mv->col);
+
+    // reduce search distance and make sure MV obtained is in range.
+    if (((dcol + (distance<<3)) > MAX_POSSIBLE_MV) || (( drow + (distance<<3)) > MAX_POSSIBLE_MV))
+    {
+        if(dcol > drow)
+            distance = (MAX_POSSIBLE_MV - dcol)>>3;
+        else
+            distance = (MAX_POSSIBLE_MV - drow)>>3;
+    }
+
+    row_min = ref_row - distance;
+    row_max = ref_row + distance;
+    col_min = ref_col - distance;
+    col_max = ref_col + distance;
+
     // Work out the mid point for the search
     in_what = *(d->base_pre) + d->pre;
     bestaddress = in_what + (ref_row * d->pre_stride) + ref_col;
@@ -1284,13 +1318,25 @@
     int ref_row = ref_mv->row >> 3;
     int ref_col = ref_mv->col >> 3;
 
-    int row_min = ref_row - distance;
-    int row_max = ref_row + distance;
-    int col_min = ref_col - distance;
-    int col_max = ref_col + distance;
-
+    int row_min, row_max, col_min, col_max;
     unsigned int sad_array[3];
+    int drow = abs(ref_mv->row - center_mv->row);
+    int dcol = abs(ref_mv->col - center_mv->col);
 
+    // reduce search distance and make sure MV obtained is in range.
+    if (((dcol + (distance<<3)) > MAX_POSSIBLE_MV) || (( drow + (distance<<3)) > MAX_POSSIBLE_MV))
+    {
+        if(dcol > drow)
+            distance = (MAX_POSSIBLE_MV - dcol)>>3;
+        else
+            distance = (MAX_POSSIBLE_MV - drow)>>3;
+    }
+
+    row_min = ref_row - distance;
+    row_max = ref_row + distance;
+    col_min = ref_col - distance;
+    col_max = ref_col + distance;
+
     // Work out the mid point for the search
     in_what = *(d->base_pre) + d->pre;
     bestaddress = in_what + (ref_row * d->pre_stride) + ref_col;
@@ -1409,13 +1455,25 @@
     int ref_row = ref_mv->row >> 3;
     int ref_col = ref_mv->col >> 3;
 
-    int row_min = ref_row - distance;
-    int row_max = ref_row + distance;
-    int col_min = ref_col - distance;
-    int col_max = ref_col + distance;
-
+    int row_min, row_max, col_min, col_max;
     unsigned short sad_array8[8];
     unsigned int sad_array[3];
+    int drow = abs(ref_mv->row - center_mv->row);
+    int dcol = abs(ref_mv->col - center_mv->col);
+
+    // reduce search distance and make sure MV obtained is in range.
+    if (((dcol + (distance<<3)) > MAX_POSSIBLE_MV) || (( drow + (distance<<3)) > MAX_POSSIBLE_MV))
+    {
+        if(dcol > drow)
+            distance = (MAX_POSSIBLE_MV - dcol)>>3;
+        else
+            distance = (MAX_POSSIBLE_MV - drow)>>3;
+    }
+
+    row_min = ref_row - distance;
+    row_max = ref_row + distance;
+    col_min = ref_col - distance;
+    col_max = ref_col + distance;
 
     // Work out the mid point for the search
     in_what = *(d->base_pre) + d->pre;
--- a/vp8/encoder/mcomp.h
+++ b/vp8/encoder/mcomp.h
@@ -24,7 +24,7 @@
 #define MAX_MVSEARCH_STEPS 8                                    // The maximum number of steps in a step search given the largest allowed initial step
 #define MAX_FULL_PEL_VAL ((1 << (MAX_MVSEARCH_STEPS+3)) - 8)    // Max full pel mv specified in 1/8 pel units
 #define MAX_FIRST_STEP (1 << (MAX_MVSEARCH_STEPS-1))            // Maximum size of the first step in full pel units
-
+#define MAX_POSSIBLE_MV (1 << 11)                               // Maximum MV in 1/8 pel units
 
 extern void print_mode_context(void);
 extern int vp8_mv_bit_cost(MV *mv, MV *ref, int *mvcost[2], int Weight);
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -4221,8 +4221,7 @@
     // Update the GF useage maps.
     // This is done after completing the compression of a frame when all modes etc. are finalized but before loop filter
     vp8_update_gf_useage_maps(cpi, cm, &cpi->mb);
-////////////////////////////////
-////////////////////////////////
+
     // This frame's MVs are saved and will be used in next frame's MV prediction.
     if(cm->show_frame)   //do not save for altref frame
     {
@@ -4231,21 +4230,6 @@
       MODE_INFO *tmp = cm->mip; //point to beginning of allocated MODE_INFO arrays.
       //static int last_video_frame = 0;
 
-      /*
-      if (cm->current_video_frame == 0)   //first frame: set to 0
-      {
-        for (mb_row = 0; mb_row < cm->mb_rows+1; mb_row ++)
-        {
-            for (mb_col = 0; mb_col < cm->mb_cols+1; mb_col ++)
-            {
-                cpi->lfmv[mb_col + mb_row*(cm->mode_info_stride)].as_int = 0;
-                cpi->lf_ref_frame_sign_bias[mb_col + mb_row*(cm->mode_info_stride)] = 0;
-                cpi->lf_ref_frame[mb_col + mb_row*(cm->mode_info_stride)] = 0;
-            }
-        }
-      }else
-      */
-
       if(cm->frame_type != KEY_FRAME)
       {
         for (mb_row = 0; mb_row < cm->mb_rows+1; mb_row ++)
@@ -4257,19 +4241,11 @@
 
               cpi->lf_ref_frame_sign_bias[mb_col + mb_row*(cm->mode_info_stride)] = cm->ref_frame_sign_bias[tmp->mbmi.ref_frame];
               cpi->lf_ref_frame[mb_col + mb_row*(cm->mode_info_stride)] = tmp->mbmi.ref_frame;
-              //printf("[%d, %d]  ", cpi->lfmv[mb_col + mb_row*(cm->mode_info_stride-1)].as_mv.row, cpi->lfmv[mb_col + mb_row*(cm->mode_info_stride-1)].as_mv.col);
               tmp++;
           }
         }
-
-      //last_video_frame = cm->current_video_frame;
       }
     }
-
-//printf("after: %d   %d \n", cm->current_video_frame, cm->show_frame );
-
-
-
 
 
     // Update the GF useage maps.
--- a/vp8/encoder/rdopt.c
+++ b/vp8/encoder/rdopt.c
@@ -1344,8 +1344,6 @@
 }
 
 
-
-/////////////////////////
 static void mv_bias(const MODE_INFO *x, int refframe, int_mv *mvp, const int *ref_frame_sign_bias)
 {
     MV xmv;
@@ -1884,6 +1882,16 @@
 
             vp8_mv_pred(cpi, &x->e_mbd, x->e_mbd.mode_info_context, &mvp,
                         x->e_mbd.mode_info_context->mbmi.ref_frame, cpi->common.ref_frame_sign_bias, &sr, &near_sadidx[0]);
+
+            /* adjust mvp to make sure it is within MV range */
+            if(mvp.row > best_ref_mv.row + MAX_POSSIBLE_MV)
+                mvp.row = best_ref_mv.row + MAX_POSSIBLE_MV;
+            if(mvp.row < best_ref_mv.row - MAX_POSSIBLE_MV)
+                mvp.row = best_ref_mv.row - MAX_POSSIBLE_MV;
+            if(mvp.col > best_ref_mv.col + MAX_POSSIBLE_MV)
+                mvp.col = best_ref_mv.col + MAX_POSSIBLE_MV;
+            if(mvp.col < best_ref_mv.col - MAX_POSSIBLE_MV)
+                mvp.col = best_ref_mv.col - MAX_POSSIBLE_MV;
         }
 
         // Estimate the reference frame signaling cost and add it to the rolling cost variable.
@@ -2163,13 +2171,6 @@
                     {
                         int sadpb = x->sadperbit16 >> 2;
                         thissme = cpi->full_search_sad(x, b, d, &full_mvp, sadpb, search_range, &cpi->fn_ptr[BLOCK_16X16], x->mvcost, x->mvsadcost,&best_ref_mv);
-                        /*
-                        MV dia_ref_mv;
-                        dia_ref_mv.row = d->bmi.mv.as_mv.row << 3;
-                        dia_ref_mv.col = d->bmi.mv.as_mv.col << 3;
-                        thissme = cpi->full_search_sad(x, b, d, &dia_ref_mv, sadpb, search_range, &cpi->fn_ptr[BLOCK_16X16], x->mvcost, x->mvsadcost,&best_ref_mv);
-                        */
-
                     }
 
                     // Barrier threshold to initiating full search
--- a/vp8/encoder/tokenize.c
+++ b/vp8/encoder/tokenize.c
@@ -131,6 +131,7 @@
 
         t->Token = x;
         t->context_tree = cpi->common.fc.coef_probs [type] [band] [pt];
+
         t->skip_eob_node = pt == 0 && ((band > 0 && type > 0) || (band > 1 && type == 0));
 
         ++cpi->coef_counts       [type] [band] [pt] [x];
@@ -181,6 +182,7 @@
 
         t->Token = x;
         t->context_tree = cpi->common.fc.coef_probs [type] [band] [pt];
+
         t->skip_eob_node = pt == 0 && ((band > 0 && type > 0) || (band > 1 && type == 0));
 
         ++cpi->coef_counts       [type] [band] [pt] [x];
--- a/vp8/encoder/tokenize.h
+++ b/vp8/encoder/tokenize.h
@@ -26,9 +26,9 @@
 typedef struct
 {
     const vp8_prob *context_tree;
-    char            skip_eob_node;
-    char            Token;
     short           Extra;
+    unsigned char   Token;
+    unsigned char   skip_eob_node;
 } TOKENEXTRA;
 
 int rd_cost_mby(MACROBLOCKD *);