]> git.sesse.net Git - x264/blobdiff - common/common.h
Try 8x8 transform analysis even when sub8x8 partitions are present
[x264] / common / common.h
index a4e1cf96a413849bd0cc91c5de0e1ce50d727574..04ac11dae5274427c01153ceeb8933815ae13fdd 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * common.h: misc common functions
  *****************************************************************************
- * Copyright (C) 2003-2011 x264 project
+ * Copyright (C) 2003-2012 x264 project
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *          Loren Merritt <lorenm@u.washington.edu>
@@ -56,7 +56,8 @@ do {\
 #define X264_BFRAME_MAX 16
 #define X264_REF_MAX 16
 #define X264_THREAD_MAX 128
-#define X264_PCM_COST ((384<<CHROMA444)*BIT_DEPTH+16)
+#define X264_LOOKAHEAD_THREAD_MAX 16
+#define X264_PCM_COST (FRAME_SIZE(256*BIT_DEPTH)+16)
 #define X264_LOOKAHEAD_MAX 250
 #define QP_BD_OFFSET (6*(BIT_DEPTH-8))
 #define QP_MAX_SPEC (51+QP_BD_OFFSET)
@@ -102,7 +103,18 @@ do {\
 #   define PARAM_INTERLACED 0
 #endif
 
-#define CHROMA444 (h->sps->i_chroma_format_idc == 3)
+#ifdef CHROMA_FORMAT
+#    define CHROMA_H_SHIFT (CHROMA_FORMAT == CHROMA_420 || CHROMA_FORMAT == CHROMA_422)
+#    define CHROMA_V_SHIFT (CHROMA_FORMAT == CHROMA_420)
+#else
+#    define CHROMA_FORMAT h->sps->i_chroma_format_idc
+#    define CHROMA_H_SHIFT h->mb.chroma_h_shift
+#    define CHROMA_V_SHIFT h->mb.chroma_v_shift
+#endif
+
+#define CHROMA_SIZE(s) ((s)>>(CHROMA_H_SHIFT+CHROMA_V_SHIFT))
+#define FRAME_SIZE(s) ((s)+2*CHROMA_SIZE(s))
+#define CHROMA444 (CHROMA_FORMAT == CHROMA_444)
 
 /* Unions for type-punning.
  * Mn: load or store n bits, aligned, native-endian
@@ -225,7 +237,7 @@ void x264_log( x264_t *h, int i_level, const char *psz_fmt, ... );
 
 void x264_reduce_fraction( uint32_t *n, uint32_t *d );
 void x264_reduce_fraction64( uint64_t *n, uint64_t *d );
-void x264_cavlc_init( void );
+void x264_cavlc_init( x264_t *h );
 void x264_cabac_init( x264_t *h );
 
 static ALWAYS_INLINE pixel x264_clip_pixel( int x )
@@ -374,6 +386,7 @@ typedef struct
     } ref_pic_list_order[2][X264_REF_MAX];
 
     /* P-frame weighting */
+    int b_weighted_pred;
     x264_weight_t weight[X264_REF_MAX*2][3];
 
     int i_mmco_remove_from_end;
@@ -423,17 +436,51 @@ typedef struct x264_left_table_t
     uint8_t ref[4];
 } x264_left_table_t;
 
+/* Current frame stats */
+typedef struct
+{
+    /* MV bits (MV+Ref+Block Type) */
+    int i_mv_bits;
+    /* Texture bits (DCT coefs) */
+    int i_tex_bits;
+    /* ? */
+    int i_misc_bits;
+    /* MB type counts */
+    int i_mb_count[19];
+    int i_mb_count_i;
+    int i_mb_count_p;
+    int i_mb_count_skip;
+    int i_mb_count_8x8dct[2];
+    int i_mb_count_ref[2][X264_REF_MAX*2];
+    int i_mb_partition[17];
+    int i_mb_cbp[6];
+    int i_mb_pred_mode[4][13];
+    int i_mb_field[3];
+    /* Adaptive direct mv pred */
+    int i_direct_score[2];
+    /* Metrics */
+    int64_t i_ssd[3];
+    double f_ssim;
+    int i_ssim_cnt;
+} x264_frame_stat_t;
+
 struct x264_t
 {
     /* encoder parameters */
     x264_param_t    param;
 
     x264_t          *thread[X264_THREAD_MAX+1];
+    x264_t          *lookahead_thread[X264_LOOKAHEAD_THREAD_MAX];
     int             b_thread_active;
     int             i_thread_phase; /* which thread to use for the next frame */
+    int             i_thread_idx;   /* which thread this is */
     int             i_threadslice_start; /* first row in this thread slice */
     int             i_threadslice_end; /* row after the end of this thread slice */
+    int             i_threadslice_pass; /* which pass of encoding we are on */
     x264_threadpool_t *threadpool;
+    x264_threadpool_t *lookaheadpool;
+    x264_pthread_mutex_t mutex;
+    x264_pthread_cond_t cv;
 
     /* bitstream output */
     struct
@@ -470,6 +517,7 @@ struct x264_t
     int64_t         i_cpb_delay_lookahead;
 
     int64_t         i_cpb_delay_pir_offset;
+    int64_t         i_cpb_delay_pir_offset_next;
 
     int             b_queued_intra_refresh;
     int64_t         i_last_idr_pts;
@@ -487,6 +535,8 @@ struct x264_t
     udctcoef        (*quant8_mf[4])[64];     /* [4][52][64] */
     udctcoef        (*quant4_bias[4])[16];   /* [4][52][16] */
     udctcoef        (*quant8_bias[4])[64];   /* [4][52][64] */
+    udctcoef        (*quant4_bias0[4])[16];  /* [4][52][16] */
+    udctcoef        (*quant8_bias0[4])[64];  /* [4][52][64] */
     udctcoef        (*nr_offset_emergency)[4][64];
 
     /* mv/ref cost arrays. */
@@ -565,7 +615,7 @@ struct x264_t
     struct
     {
         ALIGNED_16( dctcoef luma16x16_dc[3][16] );
-        ALIGNED_16( dctcoef chroma_dc[2][4] );
+        ALIGNED_16( dctcoef chroma_dc[2][8] );
         // FIXME share memory?
         ALIGNED_16( dctcoef luma8x8[12][64] );
         ALIGNED_16( dctcoef luma4x4[16*3][16] );
@@ -578,6 +628,10 @@ struct x264_t
         int     i_mb_height;
         int     i_mb_count;                 /* number of mbs in a frame */
 
+        /* Chroma subsampling */
+        int     chroma_h_shift;
+        int     chroma_v_shift;
+
         /* Strides */
         int     i_mb_stride;
         int     i_b8_stride;
@@ -778,6 +832,9 @@ struct x264_t
             /* extra data required for mbaff in mv prediction */
             int16_t topright_mv[2][3][2];
             int8_t  topright_ref[2][3];
+
+            /* current mb deblock strength */
+            uint8_t (*deblock_strength)[8][4];
         } cache;
 
         /* */
@@ -815,32 +872,7 @@ struct x264_t
     struct
     {
         /* Current frame stats */
-        struct
-        {
-            /* MV bits (MV+Ref+Block Type) */
-            int i_mv_bits;
-            /* Texture bits (DCT coefs) */
-            int i_tex_bits;
-            /* ? */
-            int i_misc_bits;
-            /* MB type counts */
-            int i_mb_count[19];
-            int i_mb_count_i;
-            int i_mb_count_p;
-            int i_mb_count_skip;
-            int i_mb_count_8x8dct[2];
-            int i_mb_count_ref[2][X264_REF_MAX*2];
-            int i_mb_partition[17];
-            int i_mb_cbp[6];
-            int i_mb_pred_mode[4][13];
-            int i_mb_field[3];
-            /* Adaptive direct mv pred */
-            int i_direct_score[2];
-            /* Metrics */
-            int64_t i_ssd[3];
-            double f_ssim;
-            int i_ssim_cnt;
-        } frame;
+        x264_frame_stat_t frame;
 
         /* Cumulated stats */
 
@@ -882,8 +914,11 @@ struct x264_t
     ALIGNED_16( uint32_t nr_residual_sum_buf[2][4][64] );
     uint32_t nr_count_buf[2][4];
 
+    uint8_t luma2chroma_pixel[7]; /* Subsampled pixel size */
+
     /* Buffers that are allocated per-thread even in sliced threads. */
     void *scratch_buffer; /* for any temporary storage that doesn't want repeated malloc */
+    void *scratch_buffer2; /* if the first one's already in use */
     pixel *intra_border_backup[5][3]; /* bottom pixels of the previous mb row, used for intra prediction after the framebuffer has been deblocked */
     /* Deblock strength values are stored for each 4x4 partition. In MBAFF
      * there are four extra values that need to be stored, located in [4][i]. */
@@ -891,9 +926,11 @@ struct x264_t
 
     /* CPU functions dependents */
     x264_predict_t      predict_16x16[4+3];
-    x264_predict_t      predict_8x8c[4+3];
     x264_predict8x8_t   predict_8x8[9+3];
     x264_predict_t      predict_4x4[9+3];
+    x264_predict_t      predict_chroma[4+3];
+    x264_predict_t      predict_8x8c[4+3];
+    x264_predict_t      predict_8x16c[4+3];
     x264_predict_8x8_filter_t predict_8x8_filter;
 
     x264_pixel_function_t pixf;