A much-needed refactoring, plus makes the next patch easier.
int i_num_ref_idx_l0_active;
int i_num_ref_idx_l1_active;
- int b_ref_pic_list_reordering_l0;
- int b_ref_pic_list_reordering_l1;
+ int b_ref_pic_list_reordering[2];
struct
{
int idc;
x264_frame_t *fdec;
/* references lists */
- int i_ref0;
- x264_frame_t *fref0[X264_REF_MAX+3]; /* ref list 0 */
- int i_ref1;
- x264_frame_t *fref1[X264_REF_MAX+3]; /* ref list 1 */
+ int i_ref[2];
+ x264_frame_t *fref[2][X264_REF_MAX+3];
int b_ref_reorder[2];
/* hrd */
h->mb.type = h->fdec->mb_type;
h->mb.partition = h->fdec->mb_partition;
- h->fdec->i_ref[0] = h->i_ref0;
- h->fdec->i_ref[1] = h->i_ref1;
- for( int i = 0; i < h->i_ref0; i++ )
- h->fdec->ref_poc[0][i] = h->fref0[i]->i_poc;
+ h->fdec->i_ref[0] = h->i_ref[0];
+ h->fdec->i_ref[1] = h->i_ref[1];
+ for( int i = 0; i < h->i_ref[0]; i++ )
+ h->fdec->ref_poc[0][i] = h->fref[0][i]->i_poc;
if( h->sh.i_type == SLICE_TYPE_B )
{
- for( int i = 0; i < h->i_ref1; i++ )
- h->fdec->ref_poc[1][i] = h->fref1[i]->i_poc;
+ for( int i = 0; i < h->i_ref[1]; i++ )
+ h->fdec->ref_poc[1][i] = h->fref[1][i]->i_poc;
map_col_to_list0(-1) = -1;
map_col_to_list0(-2) = -2;
- for( int i = 0; i < h->fref1[0]->i_ref[0]; i++ )
+ for( int i = 0; i < h->fref[1][0]->i_ref[0]; i++ )
{
- int poc = h->fref1[0]->ref_poc[0][i];
+ int poc = h->fref[1][0]->ref_poc[0][i];
map_col_to_list0(i) = -2;
- for( int j = 0; j < h->i_ref0; j++ )
- if( h->fref0[j]->i_poc == poc )
+ for( int j = 0; j < h->i_ref[0]; j++ )
+ if( h->fref[0][j]->i_poc == poc )
{
map_col_to_list0(i) = j;
break;
{
deblock_ref_table(-2) = -2;
deblock_ref_table(-1) = -1;
- for( int i = 0; i < h->i_ref0 << h->sh.b_mbaff; i++ )
+ for( int i = 0; i < h->i_ref[0] << h->sh.b_mbaff; i++ )
{
/* Mask off high bits to avoid frame num collisions with -1/-2.
* In current x264 frame num values don't cover a range of more
* than 32, so 6 bits is enough for uniqueness. */
if( !h->mb.b_interlaced )
- deblock_ref_table(i) = h->fref0[i]->i_frame_num&63;
+ deblock_ref_table(i) = h->fref[0][i]->i_frame_num&63;
else
- deblock_ref_table(i) = ((h->fref0[i>>1]->i_frame_num&63)<<1) + (i&1);
+ deblock_ref_table(i) = ((h->fref[0][i>>1]->i_frame_num&63)<<1) + (i&1);
}
}
}
/* init with not available (for top right idx=7,15) */
memset( h->mb.cache.ref, -2, sizeof( h->mb.cache.ref ) );
- if( h->i_ref0 > 0 )
+ if( h->i_ref[0] > 0 )
for( int field = 0; field <= h->sh.b_mbaff; field++ )
{
int curpoc = h->fdec->i_poc + field*h->sh.i_delta_poc_bottom;
- int refpoc = h->fref0[0]->i_poc;
+ int refpoc = h->fref[0][0]->i_poc;
if( h->sh.b_mbaff && field )
refpoc += h->sh.i_delta_poc_bottom;
int delta = curpoc - refpoc;
pixel *plane_fdec = &h->fdec->plane[i][i_pix_offset];
pixel *intra_fdec = &h->intra_border_backup[mb_y&1][i][mb_x*16];
int ref_pix_offset[2] = { i_pix_offset, i_pix_offset };
- x264_frame_t **fref[2] = { h->fref0, h->fref1 };
if( b_interlaced )
ref_pix_offset[1] += (1-2*(mb_y&1)) * i_stride;
h->mb.pic.i_stride[i] = i_stride2;
}
for( int j = 0; j < h->mb.pic.i_fref[0]; j++ )
{
- h->mb.pic.p_fref[0][j][i?4:0] = &fref[0][j >> b_interlaced]->plane[i][ref_pix_offset[j&1]];
+ h->mb.pic.p_fref[0][j][i?4:0] = &h->fref[0][j >> b_interlaced]->plane[i][ref_pix_offset[j&1]];
if( !i )
{
for( int k = 1; k < 4; k++ )
- h->mb.pic.p_fref[0][j][k] = &fref[0][j >> b_interlaced]->filtered[k][ref_pix_offset[j&1]];
+ h->mb.pic.p_fref[0][j][k] = &h->fref[0][j >> b_interlaced]->filtered[k][ref_pix_offset[j&1]];
if( h->sh.weight[j][0].weightfn )
h->mb.pic.p_fref_w[j] = &h->fenc->weighted[j >> b_interlaced][ref_pix_offset[j&1]];
else
if( h->sh.i_type == SLICE_TYPE_B )
for( int j = 0; j < h->mb.pic.i_fref[1]; j++ )
{
- h->mb.pic.p_fref[1][j][i?4:0] = &fref[1][j >> b_interlaced]->plane[i][ref_pix_offset[j&1]];
+ h->mb.pic.p_fref[1][j][i?4:0] = &h->fref[1][j >> b_interlaced]->plane[i][ref_pix_offset[j&1]];
if( !i )
for( int k = 1; k < 4; k++ )
- h->mb.pic.p_fref[1][j][k] = &fref[1][j >> b_interlaced]->filtered[k][ref_pix_offset[j&1]];
+ h->mb.pic.p_fref[1][j][k] = &h->fref[1][j >> b_interlaced]->filtered[k][ref_pix_offset[j&1]];
}
}
if( h->sh.b_mbaff )
{
- h->mb.pic.i_fref[0] = h->i_ref0 << h->mb.b_interlaced;
- h->mb.pic.i_fref[1] = h->i_ref1 << h->mb.b_interlaced;
+ h->mb.pic.i_fref[0] = h->i_ref[0] << h->mb.b_interlaced;
+ h->mb.pic.i_fref[1] = h->i_ref[1] << h->mb.b_interlaced;
h->mb.cache.i_neighbour_interlaced =
!!(h->mb.i_neighbour & MB_LEFT)
+ !!(h->mb.i_neighbour & MB_TOP);
if( h->fdec->integral )
{
int offset = 16 * (mb_x + mb_y * h->fdec->i_stride[0]);
- for( int i = 0; i < h->mb.pic.i_fref[0]; i++ )
- h->mb.pic.p_integral[0][i] = &h->fref0[i]->integral[offset];
- for( int i = 0; i < h->mb.pic.i_fref[1]; i++ )
- h->mb.pic.p_integral[1][i] = &h->fref1[i]->integral[offset];
+ for( int list = 0; list < 2; list++ )
+ for( int i = 0; i < h->mb.pic.i_fref[list]; i++ )
+ h->mb.pic.p_integral[list][i] = &h->fref[list][i]->integral[offset];
}
x264_prefetch_fenc( h, h->fenc, mb_x, mb_y );
void x264_macroblock_bipred_init( x264_t *h )
{
for( int field = 0; field <= h->sh.b_mbaff; field++ )
- for( int i_ref0 = 0; i_ref0 < (h->i_ref0<<h->sh.b_mbaff); i_ref0++ )
+ for( int i_ref0 = 0; i_ref0 < (h->i_ref[0]<<h->sh.b_mbaff); i_ref0++ )
{
- int poc0 = h->fref0[i_ref0>>h->sh.b_mbaff]->i_poc;
+ int poc0 = h->fref[0][i_ref0>>h->sh.b_mbaff]->i_poc;
if( h->sh.b_mbaff && field^(i_ref0&1) )
poc0 += h->sh.i_delta_poc_bottom;
- for( int i_ref1 = 0; i_ref1 < (h->i_ref1<<h->sh.b_mbaff); i_ref1++ )
+ for( int i_ref1 = 0; i_ref1 < (h->i_ref[1]<<h->sh.b_mbaff); i_ref1++ )
{
int dist_scale_factor;
- int poc1 = h->fref1[i_ref1>>h->sh.b_mbaff]->i_poc;
+ int poc1 = h->fref[1][i_ref1>>h->sh.b_mbaff]->i_poc;
if( h->sh.b_mbaff && field^(i_ref1&1) )
poc1 += h->sh.i_delta_poc_bottom;
int cur_poc = h->fdec->i_poc + field*h->sh.i_delta_poc_bottom;
{
int i_mb_4x4 = 16 * h->mb.i_mb_stride * h->mb.i_mb_y + 4 * h->mb.i_mb_x;
int i_mb_8x8 = 4 * h->mb.i_mb_stride * h->mb.i_mb_y + 2 * h->mb.i_mb_x;
- const int type_col = h->fref1[0]->mb_type[h->mb.i_mb_xy];
- const int partition_col = h->fref1[0]->mb_partition[h->mb.i_mb_xy];
+ const int type_col = h->fref[1][0]->mb_type[h->mb.i_mb_xy];
+ const int partition_col = h->fref[1][0]->mb_partition[h->mb.i_mb_xy];
x264_macroblock_cache_ref( h, 0, 0, 4, 4, 1, 0 );
int x8 = i8&1;
int y8 = i8>>1;
int i_part_8x8 = i_mb_8x8 + x8 + y8 * h->mb.i_b8_stride;
- int i_ref1_ref = h->fref1[0]->ref[0][i_part_8x8];
+ int i_ref1_ref = h->fref[1][0]->ref[0][i_part_8x8];
int i_ref = (map_col_to_list0(i_ref1_ref>>h->sh.b_mbaff) << h->sh.b_mbaff) + (i_ref1_ref&h->sh.b_mbaff);
if( i_ref >= 0 )
{
int dist_scale_factor = h->mb.dist_scale_factor[i_ref][0];
- int16_t *mv_col = h->fref1[0]->mv[0][i_mb_4x4 + 3*x8 + 3*y8 * h->mb.i_b4_stride];
+ int16_t *mv_col = h->fref[1][0]->mv[0][i_mb_4x4 + 3*x8 + 3*y8 * h->mb.i_b4_stride];
int l0x = ( dist_scale_factor * mv_col[0] + 128 ) >> 8;
int l0y = ( dist_scale_factor * mv_col[1] + 128 ) >> 8;
if( h->param.i_threads > 1 && (l0y > h->mb.mv_max_spel[1] || l0y-mv_col[1] > h->mb.mv_max_spel[1]) )
{
int8_t ref[2];
ALIGNED_ARRAY_8( int16_t, mv,[2],[2] );
- const int8_t *l1ref0 = &h->fref1[0]->ref[0][h->mb.i_b8_xy];
- const int8_t *l1ref1 = &h->fref1[0]->ref[1][h->mb.i_b8_xy];
- const int16_t (*l1mv[2])[2] = { (const int16_t (*)[2]) &h->fref1[0]->mv[0][h->mb.i_b4_xy],
- (const int16_t (*)[2]) &h->fref1[0]->mv[1][h->mb.i_b4_xy] };
- const int type_col = h->fref1[0]->mb_type[h->mb.i_mb_xy];
- const int partition_col = h->fref1[0]->mb_partition[h->mb.i_mb_xy];
+ const int8_t *l1ref0 = &h->fref[1][0]->ref[0][h->mb.i_b8_xy];
+ const int8_t *l1ref1 = &h->fref[1][0]->ref[1][h->mb.i_b8_xy];
+ const int16_t (*l1mv[2])[2] = { (const int16_t (*)[2]) &h->fref[1][0]->mv[0][h->mb.i_b4_xy],
+ (const int16_t (*)[2]) &h->fref[1][0]->mv[1][h->mb.i_b4_xy] };
+ const int type_col = h->fref[1][0]->mb_type[h->mb.i_mb_xy];
+ const int partition_col = h->fref[1][0]->mb_partition[h->mb.i_mb_xy];
h->mb.i_partition = partition_col;
if( i_ref == 0 && h->frames.b_have_lowres )
{
- int idx = i_list ? h->fref1[0]->i_frame-h->fenc->i_frame-1
- : h->fenc->i_frame-h->fref0[0]->i_frame-1;
+ int idx = i_list ? h->fref[1][0]->i_frame-h->fenc->i_frame-1
+ : h->fenc->i_frame-h->fref[0][0]->i_frame-1;
if( idx <= h->param.i_bframe )
{
int16_t (*lowres_mv)[2] = h->fenc->lowres_mvs[i_list][idx];
#undef SET_MVP
/* temporal predictors */
- if( h->fref0[0]->i_ref[0] > 0 )
+ if( h->fref[0][0]->i_ref[0] > 0 )
{
- x264_frame_t *l0 = h->fref0[0];
- x264_frame_t **fref = i_list ? h->fref1 : h->fref0;
+ x264_frame_t *l0 = h->fref[0][0];
int field = h->mb.i_mb_y&1;
int curpoc = h->fdec->i_poc + field*h->sh.i_delta_poc_bottom;
- int refpoc = fref[i_ref>>h->sh.b_mbaff]->i_poc;
+ int refpoc = h->fref[i_list][i_ref>>h->sh.b_mbaff]->i_poc;
if( h->sh.b_mbaff && field^(i_ref&1) )
refpoc += h->sh.i_delta_poc_bottom;
void x264_analyse_weight_frame( x264_t *h, int end )
{
- for( int j = 0; j < h->i_ref0; j++ )
+ for( int j = 0; j < h->i_ref[0]; j++ )
{
if( h->sh.weight[j][0].weightfn )
{
- x264_frame_t *frame = h->fref0[j];
+ x264_frame_t *frame = h->fref[0][j];
int width = frame->i_width[0] + 2*PADH;
int i_padv = PADV << h->param.b_interlaced;
int offset, height;
pixel *src = frame->filtered[0] - frame->i_stride[0]*i_padv - PADH;
- height = X264_MIN( 16 + end + i_padv, h->fref0[j]->i_lines[0] + i_padv*2 ) - h->fenc->i_lines_weighted;
+ height = X264_MIN( 16 + end + i_padv, h->fref[0][j]->i_lines[0] + i_padv*2 ) - h->fenc->i_lines_weighted;
offset = h->fenc->i_lines_weighted*frame->i_stride[0];
h->fenc->i_lines_weighted += height;
if( height )
- for( int k = j; k < h->i_ref0; k++ )
+ for( int k = j; k < h->i_ref[0]; k++ )
if( h->sh.weight[k][0].weightfn )
{
pixel *dst = h->fenc->weighted[k] - h->fenc->i_stride[0]*i_padv - PADH;
h->mb.mv_max_spel[0] = CLIP_FMV( h->mb.mv_max[0] );
if( h->param.b_intra_refresh && h->sh.i_type == SLICE_TYPE_P )
{
- int max_x = (h->fref0[0]->i_pir_end_col * 16 - 3)*4; /* 3 pixels of hpel border */
+ int max_x = (h->fref[0][0]->i_pir_end_col * 16 - 3)*4; /* 3 pixels of hpel border */
int max_mv = max_x - 4*16*h->mb.i_mb_x;
/* If we're left of the refresh bar, don't reference right of it. */
if( max_mv > 0 && h->mb.i_mb_x < h->fdec->i_pir_start_col )
int pix_y = (h->mb.i_mb_y | h->mb.b_interlaced) * 16;
int thresh = pix_y + h->param.analyse.i_mv_range_thread;
for( int i = (h->sh.i_type == SLICE_TYPE_B); i >= 0; i-- )
- {
- x264_frame_t **fref = i ? h->fref1 : h->fref0;
- int i_ref = i ? h->i_ref1 : h->i_ref0;
- for( int j = 0; j < i_ref; j++ )
+ for( int j = 0; j < h->i_ref[i]; j++ )
{
- x264_frame_cond_wait( fref[j]->orig, thresh );
- thread_mvy_range = X264_MIN( thread_mvy_range, fref[j]->orig->i_lines_completed - pix_y );
+ x264_frame_cond_wait( h->fref[i][j]->orig, thresh );
+ thread_mvy_range = X264_MIN( thread_mvy_range, h->fref[i][j]->orig->i_lines_completed - pix_y );
}
- }
if( h->param.b_deterministic )
thread_mvy_range = h->param.analyse.i_mv_range_thread;
IS_INTRA( h->mb.i_mb_type_top ) ||
IS_INTRA( h->mb.i_mb_type_topleft ) ||
IS_INTRA( h->mb.i_mb_type_topright ) ||
- (h->sh.i_type == SLICE_TYPE_P && IS_INTRA( h->fref0[0]->mb_type[h->mb.i_mb_xy] )) ||
+ (h->sh.i_type == SLICE_TYPE_P && IS_INTRA( h->fref[0][0]->mb_type[h->mb.i_mb_xy] )) ||
(h->mb.i_mb_xy - h->sh.i_first_mb < 3*(h->stat.frame.i_mb_count[I_4x4] + h->stat.frame.i_mb_count[I_8x8] + h->stat.frame.i_mb_count[I_16x16])) ) )
{ /* intra is likely */ }
else
int ref = h->mb.cache.ref[l][x264_scan8[0]];
if( ref < 0 )
continue;
- completed = (l ? h->fref1 : h->fref0)[ ref >> h->mb.b_interlaced ]->orig->i_lines_completed;
+ completed = h->fref[l][ ref >> h->mb.b_interlaced ]->orig->i_lines_completed;
if( (h->mb.cache.mv[l][x264_scan8[15]][1] >> (2 - h->mb.b_interlaced)) + h->mb.i_mb_y*16 > completed )
{
x264_log( h, X264_LOG_WARNING, "internal error (MV out of thread range)\n");
if( !h->mb.b_direct_auto_read && sh->i_type == SLICE_TYPE_B )
{
- if( h->fref1[0]->i_poc_l0ref0 == h->fref0[0]->i_poc )
+ if( h->fref[1][0]->i_poc_l0ref0 == h->fref[0][0]->i_poc )
{
if( h->mb.b_direct_auto_write )
sh->b_direct_spatial_mv_pred = ( h->stat.i_direct_score[1] > h->stat.i_direct_score[0] );
sh->i_num_ref_idx_l0_active = 1;
sh->i_num_ref_idx_l1_active = 1;
- sh->b_ref_pic_list_reordering_l0 = h->b_ref_reorder[0];
- sh->b_ref_pic_list_reordering_l1 = h->b_ref_reorder[1];
+ sh->b_ref_pic_list_reordering[0] = h->b_ref_reorder[0];
+ sh->b_ref_pic_list_reordering[1] = h->b_ref_reorder[1];
/* If the ref list isn't in the default order, construct reordering header */
/* List1 reordering isn't needed yet */
- if( sh->b_ref_pic_list_reordering_l0 )
+ for( int list = 0; list < 2; list++ )
{
- int pred_frame_num = i_frame;
- for( int i = 0; i < h->i_ref0; i++ )
+ if( sh->b_ref_pic_list_reordering[list] )
{
- int diff = h->fref0[i]->i_frame_num - pred_frame_num;
- sh->ref_pic_list_order[0][i].idc = ( diff > 0 );
- sh->ref_pic_list_order[0][i].arg = (abs(diff) - 1) & ((1 << sps->i_log2_max_frame_num) - 1);
- pred_frame_num = h->fref0[i]->i_frame_num;
+ int pred_frame_num = i_frame;
+ for( int i = 0; i < h->i_ref[list]; i++ )
+ {
+ int diff = h->fref[list][i]->i_frame_num - pred_frame_num;
+ sh->ref_pic_list_order[list][i].idc = ( diff > 0 );
+ sh->ref_pic_list_order[list][i].arg = (abs(diff) - 1) & ((1 << sps->i_log2_max_frame_num) - 1);
+ pred_frame_num = h->fref[list][i]->i_frame_num;
+ }
}
}
/* ref pic list reordering */
if( sh->i_type != SLICE_TYPE_I )
{
- bs_write1( s, sh->b_ref_pic_list_reordering_l0 );
- if( sh->b_ref_pic_list_reordering_l0 )
+ bs_write1( s, sh->b_ref_pic_list_reordering[0] );
+ if( sh->b_ref_pic_list_reordering[0] )
{
for( int i = 0; i < sh->i_num_ref_idx_l0_active; i++ )
{
}
if( sh->i_type == SLICE_TYPE_B )
{
- bs_write1( s, sh->b_ref_pic_list_reordering_l1 );
- if( sh->b_ref_pic_list_reordering_l1 )
+ bs_write1( s, sh->b_ref_pic_list_reordering[1] );
+ if( sh->b_ref_pic_list_reordering[1] )
{
for( int i = 0; i < sh->i_num_ref_idx_l1_active; i++ )
{
+ h->i_thread_frames + 3) * sizeof(x264_frame_t *) );
if( h->param.analyse.i_weighted_pred > 0 )
CHECKED_MALLOCZERO( h->frames.blank_unused, h->i_thread_frames * 4 * sizeof(x264_frame_t *) );
- h->i_ref0 = 0;
- h->i_ref1 = 0;
+ h->i_ref[0] = h->i_ref[1] = 0;
h->i_cpb_delay = h->i_coded_fields = h->i_disp_fields = 0;
h->i_prev_duration = ((uint64_t)h->param.i_fps_den * h->sps->vui.i_time_scale) / ((uint64_t)h->param.i_fps_num * h->sps->vui.i_num_units_in_tick);
h->i_disp_fields_last_frame = -1;
h->b_ref_reorder[0] = 1;
return;
}
- for( int i = 0; i < h->i_ref0 - 1; i++ )
+ for( int i = 0; i < h->i_ref[0] - 1; i++ )
/* P and B-frames use different default orders. */
- if( h->sh.i_type == SLICE_TYPE_P ? h->fref0[i]->i_frame_num < h->fref0[i+1]->i_frame_num
- : h->fref0[i]->i_poc < h->fref0[i+1]->i_poc )
+ if( h->sh.i_type == SLICE_TYPE_P ? h->fref[0][i]->i_frame_num < h->fref[0][i+1]->i_frame_num
+ : h->fref[0][i]->i_poc < h->fref[0][i+1]->i_poc )
{
h->b_ref_reorder[0] = 1;
return;
/* return -1 on failure, else return the index of the new reference frame */
int x264_weighted_reference_duplicate( x264_t *h, int i_ref, const x264_weight_t *w )
{
- int i = h->i_ref0;
+ int i = h->i_ref[0];
int j = 1;
x264_frame_t *newframe;
if( i <= 1 ) /* empty list, definitely can't duplicate frame */
newframe = x264_frame_pop_blank_unused( h );
//FIXME: probably don't need to copy everything
- *newframe = *h->fref0[i_ref];
+ *newframe = *h->fref[0][i_ref];
newframe->i_reference_count = 1;
- newframe->orig = h->fref0[i_ref];
+ newframe->orig = h->fref[0][i_ref];
newframe->b_duplicate = 1;
memcpy( h->fenc->weight[j], w, sizeof(h->fenc->weight[i]) );
/* shift the frames to make space for the dupe. */
h->b_ref_reorder[0] = 1;
- if( h->i_ref0 < X264_REF_MAX )
- ++h->i_ref0;
- h->fref0[X264_REF_MAX-1] = NULL;
- x264_frame_unshift( &h->fref0[j], newframe );
+ if( h->i_ref[0] < X264_REF_MAX )
+ ++h->i_ref[0];
+ h->fref[0][X264_REF_MAX-1] = NULL;
+ x264_frame_unshift( &h->fref[0][j], newframe );
return j;
}
static void x264_weighted_pred_init( x264_t *h )
{
/* for now no analysis and set all weights to nothing */
- for( int i_ref = 0; i_ref < h->i_ref0; i_ref++ )
- h->fenc->weighted[i_ref] = h->fref0[i_ref]->filtered[0];
+ for( int i_ref = 0; i_ref < h->i_ref[0]; i_ref++ )
+ h->fenc->weighted[i_ref] = h->fref[0][i_ref]->filtered[0];
// FIXME: This only supports weighting of one reference frame
// and duplicates of that frame.
h->fenc->i_lines_weighted = 0;
- for( int i_ref = 0; i_ref < (h->i_ref0 << h->sh.b_mbaff); i_ref++ )
+ for( int i_ref = 0; i_ref < (h->i_ref[0] << h->sh.b_mbaff); i_ref++ )
for( int i = 0; i < 3; i++ )
h->sh.weight[i_ref][i].weightfn = NULL;
int buffer_next = 0;
for( int i = 0; i < 3; i++ )
{
- for( int j = 0; j < h->i_ref0; j++ )
+ for( int j = 0; j < h->i_ref[0]; j++ )
{
if( h->fenc->weight[j][i].weightfn )
{
//scale full resolution frame
if( h->param.i_threads == 1 )
{
- pixel *src = h->fref0[j]->filtered[0] - h->fref0[j]->i_stride[0]*i_padv - PADH;
+ pixel *src = h->fref[0][j]->filtered[0] - h->fref[0][j]->i_stride[0]*i_padv - PADH;
pixel *dst = h->fenc->weighted[j] - h->fenc->i_stride[0]*i_padv - PADH;
int stride = h->fenc->i_stride[0];
int width = h->fenc->i_width[0] + PADH*2;
}
if( weightplane[1] )
- for( int i = 0; i < h->i_ref0; i++ )
+ for( int i = 0; i < h->i_ref[0]; i++ )
{
if( h->sh.weight[i][1].weightfn && !h->sh.weight[i][2].weightfn )
{
int b_ok;
/* build ref list 0/1 */
- h->mb.pic.i_fref[0] = h->i_ref0 = 0;
- h->mb.pic.i_fref[1] = h->i_ref1 = 0;
+ h->mb.pic.i_fref[0] = h->i_ref[0] = 0;
+ h->mb.pic.i_fref[1] = h->i_ref[1] = 0;
if( h->sh.i_type == SLICE_TYPE_I )
return;
if( h->frames.reference[i]->b_corrupt )
continue;
if( h->frames.reference[i]->i_poc < i_poc )
- h->fref0[h->i_ref0++] = h->frames.reference[i];
+ h->fref[0][h->i_ref[0]++] = h->frames.reference[i];
else if( h->frames.reference[i]->i_poc > i_poc )
- h->fref1[h->i_ref1++] = h->frames.reference[i];
+ h->fref[1][h->i_ref[1]++] = h->frames.reference[i];
}
/* Order ref0 from higher to lower poc */
do
{
b_ok = 1;
- for( int i = 0; i < h->i_ref0 - 1; i++ )
+ for( int i = 0; i < h->i_ref[0] - 1; i++ )
{
- if( h->fref0[i]->i_poc < h->fref0[i+1]->i_poc )
+ if( h->fref[0][i]->i_poc < h->fref[0][i+1]->i_poc )
{
- XCHG( x264_frame_t*, h->fref0[i], h->fref0[i+1] );
+ XCHG( x264_frame_t*, h->fref[0][i], h->fref[0][i+1] );
b_ok = 0;
break;
}
} while( !b_ok );
if( h->sh.i_mmco_remove_from_end )
- for( int i = h->i_ref0-1; i >= h->i_ref0 - h->sh.i_mmco_remove_from_end; i-- )
+ for( int i = h->i_ref[0]-1; i >= h->i_ref[0] - h->sh.i_mmco_remove_from_end; i-- )
{
- int diff = h->i_frame_num - h->fref0[i]->i_frame_num;
- h->sh.mmco[h->sh.i_mmco_command_count].i_poc = h->fref0[i]->i_poc;
+ int diff = h->i_frame_num - h->fref[0][i]->i_frame_num;
+ h->sh.mmco[h->sh.i_mmco_command_count].i_poc = h->fref[0][i]->i_poc;
h->sh.mmco[h->sh.i_mmco_command_count++].i_difference_of_pic_nums = diff;
}
do
{
b_ok = 1;
- for( int i = 0; i < h->i_ref1 - 1; i++ )
+ for( int i = 0; i < h->i_ref[1] - 1; i++ )
{
- if( h->fref1[i]->i_poc > h->fref1[i+1]->i_poc )
+ if( h->fref[1][i]->i_poc > h->fref[1][i+1]->i_poc )
{
- XCHG( x264_frame_t*, h->fref1[i], h->fref1[i+1] );
+ XCHG( x264_frame_t*, h->fref[1][i], h->fref[1][i+1] );
b_ok = 0;
break;
}
x264_reference_check_reorder( h );
- h->i_ref1 = X264_MIN( h->i_ref1, h->frames.i_max_ref1 );
- h->i_ref0 = X264_MIN( h->i_ref0, h->frames.i_max_ref0 );
- h->i_ref0 = X264_MIN( h->i_ref0, h->param.i_frame_reference ); // if reconfig() has lowered the limit
+ h->i_ref[1] = X264_MIN( h->i_ref[1], h->frames.i_max_ref1 );
+ h->i_ref[0] = X264_MIN( h->i_ref[0], h->frames.i_max_ref0 );
+ h->i_ref[0] = X264_MIN( h->i_ref[0], h->param.i_frame_reference ); // if reconfig() has lowered the limit
/* add duplicates */
if( h->fenc->i_type == X264_TYPE_P )
h->mb.ref_blind_dupe = idx;
}
- 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;
+ assert( h->i_ref[0] + h->i_ref[1] <= X264_REF_MAX );
+ h->mb.pic.i_fref[0] = h->i_ref[0];
+ h->mb.pic.i_fref[1] = h->i_ref[1];
}
static void x264_fdec_filter_row( x264_t *h, int mb_y, int b_inloop )
{
x264_slice_header_init( h, &h->sh, h->sps, h->pps, -1, h->i_frame_num, i_global_qp );
- h->sh.i_num_ref_idx_l0_active = h->i_ref0 <= 0 ? 1 : h->i_ref0;
- h->sh.i_num_ref_idx_l1_active = h->i_ref1 <= 0 ? 1 : h->i_ref1;
+ h->sh.i_num_ref_idx_l0_active = h->i_ref[0] <= 0 ? 1 : h->i_ref[0];
+ h->sh.i_num_ref_idx_l1_active = h->i_ref[1] <= 0 ? 1 : h->i_ref[1];
if( h->sh.i_num_ref_idx_l0_active != h->pps->i_num_ref_idx_l0_default_active ||
(h->sh.i_type == SLICE_TYPE_B && h->sh.i_num_ref_idx_l1_active != h->pps->i_num_ref_idx_l1_default_active) )
{
}
else if( h->fenc->i_type == X264_TYPE_P )
{
- int pocdiff = (h->fdec->i_poc - h->fref0[0]->i_poc)/2;
+ int pocdiff = (h->fdec->i_poc - h->fref[0][0]->i_poc)/2;
float increment = X264_MAX( ((float)h->mb.i_mb_width-1) / h->param.i_keyint_max, 1 );
- h->fdec->f_pir_position = h->fref0[0]->f_pir_position;
- h->fdec->i_frames_since_pir = h->fref0[0]->i_frames_since_pir + pocdiff;
+ h->fdec->f_pir_position = h->fref[0][0]->f_pir_position;
+ h->fdec->i_frames_since_pir = h->fref[0][0]->i_frames_since_pir + pocdiff;
if( h->fdec->i_frames_since_pir >= h->param.i_keyint_max ||
(h->b_queued_intra_refresh && h->fdec->f_pir_position + 0.5 >= h->mb.i_mb_width) )
{
x264_reference_check_reorder( h );
}
- if( h->i_ref0 )
- h->fdec->i_poc_l0ref0 = h->fref0[0]->i_poc;
+ if( h->i_ref[0] )
+ h->fdec->i_poc_l0ref0 = h->fref[0][0]->i_poc;
if( h->sh.i_type == SLICE_TYPE_B )
x264_macroblock_bipred_init( h );
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 )
{
- h->stat.i_consecutive_bframes[h->fdec->i_frame - h->fref0[0]->i_frame - 1]++;
+ h->stat.i_consecutive_bframes[h->fdec->i_frame - h->fref[0][0]->i_frame - 1]++;
if( h->param.analyse.i_weighted_pred >= X264_WEIGHTP_SIMPLE )
{
h->stat.i_wpred[0] += !!h->sh.weight[0][0].weightfn;
/* Remove duplicates, must be done near the end as breaks h->fref0 array
* by freeing some of its pointers. */
- for( int i = 0; i < h->i_ref0; i++ )
- if( h->fref0[i] && h->fref0[i]->b_duplicate )
+ for( int i = 0; i < h->i_ref[0]; i++ )
+ if( h->fref[0][i] && h->fref[0][i]->b_duplicate )
{
- x264_frame_push_blank_unused( h, h->fref0[i] );
- h->fref0[i] = 0;
+ x264_frame_push_blank_unused( h, h->fref[0][i] );
+ h->fref[0][i] = 0;
}
if( h->param.psz_dump_yuv )
x264_weight_t weights[16][3];
int refcount[16];
- if( rce->refs != h->i_ref0 )
+ if( rce->refs != h->i_ref[0] )
return -1;
- memcpy( frames, h->fref0, sizeof(frames) );
+ memcpy( frames, h->fref[0], sizeof(frames) );
memcpy( refcount, rce->refcount, sizeof(refcount) );
memcpy( weights, h->fenc->weight, sizeof(weights) );
memset( &h->fenc->weight[1][0], 0, sizeof(x264_weight_t[15][3]) );
/* For now don't reorder ref 0; it seems to lower quality
in most cases due to skips. */
- for( int ref = 1; ref < h->i_ref0; ref++ )
+ for( int ref = 1; ref < h->i_ref[0]; ref++ )
{
int max = -1;
int bestref = 1;
- for( int i = 1; i < h->i_ref0; i++ )
+ for( int i = 1; i < h->i_ref[0]; i++ )
/* Favor lower POC as a tiebreaker. */
COPY2_IF_GT( max, refcount[i], bestref, i );
* that the optimal ordering doesnt place every duplicate. */
refcount[bestref] = -1;
- h->fref0[ref] = frames[bestref];
+ h->fref[0][ref] = frames[bestref];
memcpy( h->fenc->weight[ref], weights[bestref], sizeof(weights[bestref]) );
}
x264_ratecontrol_t *rc = h->rc;
double pred_s = predict_size( rc->row_pred[0], qp2qscale( qp ), h->fdec->i_row_satd[y] );
double pred_t = 0;
- if( h->sh.i_type == SLICE_TYPE_I || qp >= h->fref0[0]->f_row_qp[y] )
+ if( h->sh.i_type == SLICE_TYPE_I || qp >= h->fref[0][0]->f_row_qp[y] )
{
if( h->sh.i_type == SLICE_TYPE_P
- && h->fref0[0]->i_type == h->fdec->i_type
- && h->fref0[0]->i_row_satd[y] > 0
- && (abs(h->fref0[0]->i_row_satd[y] - h->fdec->i_row_satd[y]) < h->fdec->i_row_satd[y]/2))
+ && h->fref[0][0]->i_type == h->fdec->i_type
+ && h->fref[0][0]->i_row_satd[y] > 0
+ && (abs(h->fref[0][0]->i_row_satd[y] - h->fdec->i_row_satd[y]) < h->fdec->i_row_satd[y]/2))
{
- pred_t = h->fref0[0]->i_row_bits[y] * h->fdec->i_row_satd[y] / h->fref0[0]->i_row_satd[y]
- * qp2qscale( h->fref0[0]->f_row_qp[y] ) / qp2qscale( qp );
+ pred_t = h->fref[0][0]->i_row_bits[y] * h->fdec->i_row_satd[y] / h->fref[0][0]->i_row_satd[y]
+ * qp2qscale( h->fref[0][0]->f_row_qp[y] ) / qp2qscale( qp );
}
if( pred_t == 0 )
pred_t = pred_s;
h->fdec->f_row_qp[y] = rc->qpm;
update_predictor( rc->row_pred[0], qp2qscale( rc->qpm ), h->fdec->i_row_satd[y], h->fdec->i_row_bits[y] );
- if( h->sh.i_type == SLICE_TYPE_P && rc->qpm < h->fref0[0]->f_row_qp[y] )
+ if( h->sh.i_type == SLICE_TYPE_P && rc->qpm < h->fref[0][0]->f_row_qp[y] )
update_predictor( rc->row_pred[1], qp2qscale( rc->qpm ), h->fdec->i_row_satds[0][0][y], h->fdec->i_row_bits[y] );
/* tweak quality based on difference from predicted size */
/* B-frames shouldn't use lower QP than their reference frames. */
if( h->sh.i_type == SLICE_TYPE_B )
{
- qp_min = X264_MAX( qp_min, X264_MAX( h->fref0[0]->f_row_qp[y+1], h->fref1[0]->f_row_qp[y+1] ) );
+ qp_min = X264_MAX( qp_min, X264_MAX( h->fref[0][0]->f_row_qp[y+1], h->fref[1][0]->f_row_qp[y+1] ) );
rc->qpm = X264_MAX( rc->qpm, qp_min );
}
/* Only write information for reference reordering once. */
int use_old_stats = h->param.rc.b_stat_read && rc->rce->refs > 1;
- for( int i = 0; i < (use_old_stats ? rc->rce->refs : h->i_ref0); i++ )
+ for( int i = 0; i < (use_old_stats ? rc->rce->refs : h->i_ref[0]); i++ )
{
int refcount = use_old_stats ? rc->rce->refcount[i]
: h->param.b_interlaced ? h->stat.frame.i_mb_count_ref[0][i*2]
if( h->fenc->b_last_minigop_bframe )
{
update_predictor( rc->pred_b_from_p, qp2qscale( rc->qpa_rc ),
- h->fref1[h->i_ref1-1]->i_satd, rc->bframe_bits / rc->bframes );
+ h->fref[1][h->i_ref[1]-1]->i_satd, rc->bframe_bits / rc->bframes );
rc->bframe_bits = 0;
}
}
/* B-frames don't have independent ratecontrol, but rather get the
* average QP of the two adjacent P-frames + an offset */
- int i0 = IS_X264_TYPE_I(h->fref0[0]->i_type);
- int i1 = IS_X264_TYPE_I(h->fref1[0]->i_type);
- int dt0 = abs(h->fenc->i_poc - h->fref0[0]->i_poc);
- int dt1 = abs(h->fenc->i_poc - h->fref1[0]->i_poc);
- float q0 = h->fref0[0]->f_qp_avg_rc;
- float q1 = h->fref1[0]->f_qp_avg_rc;
+ int i0 = IS_X264_TYPE_I(h->fref[0][0]->i_type);
+ int i1 = IS_X264_TYPE_I(h->fref[1][0]->i_type);
+ int dt0 = abs(h->fenc->i_poc - h->fref[0][0]->i_poc);
+ int dt1 = abs(h->fenc->i_poc - h->fref[1][0]->i_poc);
+ float q0 = h->fref[0][0]->f_qp_avg_rc;
+ float q1 = h->fref[1][0]->f_qp_avg_rc;
- if( h->fref0[0]->i_type == X264_TYPE_BREF )
+ if( h->fref[0][0]->i_type == X264_TYPE_BREF )
q0 -= rcc->pb_offset/2;
- if( h->fref1[0]->i_type == X264_TYPE_BREF )
+ if( h->fref[1][0]->i_type == X264_TYPE_BREF )
q1 -= rcc->pb_offset/2;
if( i0 && i1 )
if( rcc->b_2pass && rcc->b_vbv )
rcc->frame_size_planned = qscale2bits( &rce, qp2qscale( q ) );
else
- rcc->frame_size_planned = predict_size( rcc->pred_b_from_p, qp2qscale( q ), h->fref1[h->i_ref1-1]->i_satd );
+ rcc->frame_size_planned = predict_size( rcc->pred_b_from_p, qp2qscale( q ), h->fref[1][h->i_ref[1]-1]->i_satd );
h->rc->frame_size_estimated = rcc->frame_size_planned;
/* For row SATDs */
p1 = b = h->fenc->i_bframes + 1;
else //B
{
- p1 = (h->fref1[0]->i_poc - h->fref0[0]->i_poc)/2;
- b = (h->fenc->i_poc - h->fref0[0]->i_poc)/2;
+ p1 = (h->fref[1][0]->i_poc - h->fref[0][0]->i_poc)/2;
+ b = (h->fenc->i_poc - h->fref[0][0]->i_poc)/2;
}
/* We don't need to assign p0/p1 since we are not performing any real analysis here. */
x264_frame_t **frames = &h->fenc - b;