From: Fiona Glaser Date: Sat, 21 Aug 2010 21:51:39 +0000 (-0500) Subject: Add global #define for maximum reference count X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=34649ace2ce4cb4bde4bcbdc78919dfca358d6a3;p=libx264 Add global #define for maximum reference count This should make it easier to play around with reference frame counts that exceed the spec maximum. --- diff --git a/common/common.h b/common/common.h index 72fc1d84..670fd125 100644 --- a/common/common.h +++ b/common/common.h @@ -51,6 +51,7 @@ do {\ } while( 0 ) #define X264_BFRAME_MAX 16 +#define X264_REF_MAX 16 #define X264_THREAD_MAX 128 #define X264_PCM_COST (384*BIT_DEPTH+16) #define X264_LOOKAHEAD_MAX 250 @@ -340,10 +341,10 @@ typedef struct { int idc; int arg; - } ref_pic_list_order[2][16]; + } ref_pic_list_order[2][X264_REF_MAX]; /* P-frame weighting */ - x264_weight_t weight[32][3]; + x264_weight_t weight[X264_REF_MAX*2][3]; int i_mmco_remove_from_end; int i_mmco_command_count; @@ -351,7 +352,7 @@ typedef struct { int i_difference_of_pic_nums; int i_poc; - } mmco[16]; + } mmco[X264_REF_MAX]; int i_cabac_init_idc; @@ -479,7 +480,7 @@ struct x264_t x264_frame_t **blank_unused; /* frames used for reference + sentinels */ - x264_frame_t *reference[16+2]; + x264_frame_t *reference[X264_REF_MAX+2]; int i_last_keyframe; /* Frame number of the last keyframe */ int i_last_idr; /* Frame number of the last IDR (not RP)*/ @@ -511,9 +512,9 @@ struct x264_t /* references lists */ int i_ref0; - x264_frame_t *fref0[16+3]; /* ref list 0 */ + x264_frame_t *fref0[X264_REF_MAX+3]; /* ref list 0 */ int i_ref1; - x264_frame_t *fref1[16+3]; /* ref list 1 */ + x264_frame_t *fref1[X264_REF_MAX+3]; /* ref list 1 */ int b_ref_reorder[2]; /* hrd */ @@ -605,14 +606,14 @@ struct x264_t int16_t (*mv[2])[2]; /* mb mv. set to 0 for intra mb */ uint8_t (*mvd[2])[8][2]; /* absolute value of mb mv difference with predict, clipped to [0,33]. set to 0 if intra. cabac only */ int8_t *ref[2]; /* mb ref. set to -1 if non used (intra or Lx only) */ - int16_t (*mvr[2][32])[2]; /* 16x16 mv for each possible ref */ + int16_t (*mvr[2][X264_REF_MAX*2])[2];/* 16x16 mv for each possible ref */ int8_t *skipbp; /* block pattern for SKIP or DIRECT (sub)mbs. B-frames + cabac only */ int8_t *mb_transform_size; /* transform_size_8x8_flag of each mb */ uint16_t *slice_table; /* sh->first_mb of the slice that the indexed mb is part of * NOTE: this will fail on resolutions above 2^16 MBs... */ /* buffer for weighted versions of the reference frames */ - pixel *p_weight_buf[16]; + pixel *p_weight_buf[X264_REF_MAX]; /* current value */ int i_type; @@ -675,9 +676,9 @@ struct x264_t /* pointer over mb of the references */ int i_fref[2]; - pixel *p_fref[2][32][4+1]; /* last: yN, yH, yV, yHV, uv */ - pixel *p_fref_w[32]; /* weighted fullpel luma */ - uint16_t *p_integral[2][16]; + pixel *p_fref[2][X264_REF_MAX*2][4+1]; /* last: yN, yH, yV, yHV, uv */ + pixel *p_fref_w[X264_REF_MAX*2]; /* weighted fullpel luma */ + uint16_t *p_integral[2][X264_REF_MAX]; /* fref stride */ int i_stride[3]; @@ -732,15 +733,15 @@ struct x264_t int i_chroma_lambda2_offset; /* B_direct and weighted prediction */ - int16_t dist_scale_factor_buf[2][32][4]; + int16_t dist_scale_factor_buf[2][X264_REF_MAX*2][4]; int16_t (*dist_scale_factor)[4]; - int8_t bipred_weight_buf[2][32][4]; + int8_t bipred_weight_buf[2][X264_REF_MAX*2][4]; int8_t (*bipred_weight)[4]; /* maps fref1[0]'s ref indices into the current list0 */ #define map_col_to_list0(col) h->mb.map_col_to_list0[(col)+2] - int8_t map_col_to_list0[18]; + int8_t map_col_to_list0[X264_REF_MAX+2]; int ref_blind_dupe; /* The index of the blind reference frame duplicate. */ - int8_t deblock_ref_table[32+2]; + int8_t deblock_ref_table[X264_REF_MAX*2+2]; #define deblock_ref_table(x) h->mb.deblock_ref_table[(x)+2] } mb; @@ -765,7 +766,7 @@ struct x264_t int i_mb_count_p; int i_mb_count_skip; int i_mb_count_8x8dct[2]; - int i_mb_count_ref[2][32]; + 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]; @@ -794,7 +795,7 @@ struct x264_t int64_t i_mb_count[5][19]; int64_t i_mb_partition[2][17]; int64_t i_mb_count_8x8dct[2]; - int64_t i_mb_count_ref[2][2][32]; + int64_t i_mb_count_ref[2][2][X264_REF_MAX*2]; int64_t i_mb_cbp[6]; int64_t i_mb_pred_mode[4][13]; /* */ diff --git a/common/frame.h b/common/frame.h index fcc28d73..3e0a3f59 100644 --- a/common/frame.h +++ b/common/frame.h @@ -75,8 +75,8 @@ typedef struct x264_frame pixel *buffer[4]; pixel *buffer_lowres[4]; - x264_weight_t weight[16][3]; /* [ref_index][plane] */ - pixel *weighted[16]; /* plane[0] weighted of the reference frames */ + x264_weight_t weight[X264_REF_MAX][3]; /* [ref_index][plane] */ + pixel *weighted[X264_REF_MAX]; /* plane[0] weighted of the reference frames */ int b_duplicate; struct x264_frame *orig; @@ -97,7 +97,7 @@ typedef struct x264_frame int *lowres_mv_costs[2][X264_BFRAME_MAX+1]; int8_t *ref[2]; int i_ref[2]; - int ref_poc[2][16]; + int ref_poc[2][X264_REF_MAX]; int16_t inv_ref_poc[2]; // inverse values of ref0 poc to avoid divisions in temporal MV prediction /* for adaptive B-frame decision. diff --git a/common/macroblock.c b/common/macroblock.c index f8a689e8..62f3f28a 100644 --- a/common/macroblock.c +++ b/common/macroblock.c @@ -233,11 +233,11 @@ int x264_macroblock_cache_allocate( x264_t *h ) for( int i = 0; i < 2; i++ ) { - int i_refs = X264_MIN(16, (i ? 1 + !!h->param.i_bframe_pyramid : h->param.i_frame_reference) ) << h->param.b_interlaced; + int i_refs = X264_MIN(X264_REF_MAX, (i ? 1 + !!h->param.i_bframe_pyramid : h->param.i_frame_reference) ) << h->param.b_interlaced; if( h->param.analyse.i_weighted_pred == X264_WEIGHTP_SMART ) - i_refs = X264_MIN(16, i_refs + 2); //smart weights add two duplicate frames + i_refs = X264_MIN(X264_REF_MAX, i_refs + 2); //smart weights add two duplicate frames else if( h->param.analyse.i_weighted_pred == X264_WEIGHTP_BLIND ) - i_refs = X264_MIN(16, i_refs + 1); //blind weights add one duplicate frame + i_refs = X264_MIN(X264_REF_MAX, i_refs + 1); //blind weights add one duplicate frame for( int j = !i; j < i_refs; j++ ) { @@ -289,10 +289,10 @@ fail: void x264_macroblock_cache_free( x264_t *h ) { for( int i = 0; i < 2; i++ ) - for( int j = !i; j < 32; j++ ) + for( int j = !i; j < X264_REF_MAX*2; j++ ) if( h->mb.mvr[i][j] ) x264_free( h->mb.mvr[i][j]-1 ); - for( int i = 0; i < 16; i++ ) + for( int i = 0; i < X264_REF_MAX; i++ ) x264_free( h->mb.p_weight_buf[i] ); if( h->param.b_cabac ) diff --git a/encoder/encoder.c b/encoder/encoder.c index 6f98b676..e9225dbf 100644 --- a/encoder/encoder.c +++ b/encoder/encoder.c @@ -571,8 +571,8 @@ static int x264_validate_parameters( x264_t *h ) h->param.i_slice_count = 0; } - h->param.i_frame_reference = x264_clip3( h->param.i_frame_reference, 1, 16 ); - h->param.i_dpb_size = x264_clip3( h->param.i_dpb_size, 1, 16 ); + h->param.i_frame_reference = x264_clip3( h->param.i_frame_reference, 1, X264_REF_MAX ); + h->param.i_dpb_size = x264_clip3( h->param.i_dpb_size, 1, X264_REF_MAX ); h->param.i_keyint_max = x264_clip3( h->param.i_keyint_max, 1, X264_KEYINT_MAX_INFINITE ); if( h->param.i_scenecut_threshold < 0 ) h->param.i_scenecut_threshold = 0; @@ -1005,7 +1005,7 @@ x264_t *x264_encoder_open( x264_param_t *param ) CHECKED_MALLOCZERO( h->frames.unused[0], (h->frames.i_delay + 3) * sizeof(x264_frame_t *) ); /* Allocate room for max refs plus a few extra just in case. */ - CHECKED_MALLOCZERO( h->frames.unused[1], (h->i_thread_frames + 20) * sizeof(x264_frame_t *) ); + CHECKED_MALLOCZERO( h->frames.unused[1], (h->i_thread_frames + X264_REF_MAX + 4) * sizeof(x264_frame_t *) ); CHECKED_MALLOCZERO( h->frames.current, (h->param.i_sync_lookahead + h->param.i_bframe + h->i_thread_frames + 3) * sizeof(x264_frame_t *) ); if( h->param.analyse.i_weighted_pred > 0 ) @@ -1434,9 +1434,9 @@ int x264_weighted_reference_duplicate( x264_t *h, int i_ref, const x264_weight_t /* shift the frames to make space for the dupe. */ h->b_ref_reorder[0] = 1; - if( h->i_ref0 < 16 ) + if( h->i_ref0 < X264_REF_MAX ) ++h->i_ref0; - h->fref0[15] = NULL; + h->fref0[X264_REF_MAX-1] = NULL; x264_frame_unshift( &h->fref0[j], newframe ); return j; @@ -1616,7 +1616,7 @@ static inline void x264_reference_build_list( x264_t *h, int i_poc ) h->mb.ref_blind_dupe = idx; } - assert( h->i_ref0 + h->i_ref1 <= 16 ); + assert( h->i_ref0 + h->i_ref1 <= X264_REF_MAX ); h->mb.pic.i_fref[0] = h->i_ref0; h->mb.pic.i_fref[1] = h->i_ref1; } @@ -2801,7 +2801,7 @@ static int x264_encoder_frame_end( x264_t *h, x264_t *thread_current, h->stat.i_mb_pred_mode[i][j] += h->stat.frame.i_mb_pred_mode[i][j]; if( h->sh.i_type != SLICE_TYPE_I ) for( int i_list = 0; i_list < 2; i_list++ ) - for( int i = 0; i < 32; i++ ) + for( int i = 0; i < X264_REF_MAX*2; i++ ) h->stat.i_mb_count_ref[h->sh.i_type][i_list][i] += h->stat.frame.i_mb_count_ref[i_list][i]; if( h->sh.i_type == SLICE_TYPE_P ) { @@ -3169,7 +3169,7 @@ void x264_encoder_close ( x264_t *h ) char *p = buf; int64_t i_den = 0; int i_max = 0; - for( int i = 0; i < 32; i++ ) + for( int i = 0; i < X264_REF_MAX*2; i++ ) if( h->stat.i_mb_count_ref[i_slice][i_list][i] ) { i_den += h->stat.i_mb_count_ref[i_slice][i_list][i]; diff --git a/encoder/set.c b/encoder/set.c index a520b8a6..2c936182 100644 --- a/encoder/set.c +++ b/encoder/set.c @@ -125,7 +125,7 @@ void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param ) /* extra slot with pyramid so that we don't have to override the * order of forgetting old pictures */ sps->vui.i_max_dec_frame_buffering = - sps->i_num_ref_frames = X264_MIN(16, X264_MAX4(param->i_frame_reference, 1 + sps->vui.i_num_reorder_frames, + sps->i_num_ref_frames = X264_MIN(X264_REF_MAX, X264_MAX4(param->i_frame_reference, 1 + sps->vui.i_num_reorder_frames, param->i_bframe_pyramid ? 4 : 1, param->i_dpb_size)); sps->i_num_ref_frames -= param->i_bframe_pyramid == X264_B_PYRAMID_STRICT;