Attempting to change field order during encoding could cause slight corruption.
Also fix delta_poc_bottom to be correctly set if interlaced mode is used without B-frames.
{
/* */
int i_poc;
+ int i_delta_poc[2];
int i_type;
int i_qpplus1;
int64_t i_pts;
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->fref[0][0]->i_poc;
- if( h->sh.b_mbaff && field )
- refpoc += h->sh.i_delta_poc_bottom;
+ int curpoc = h->fdec->i_poc + h->fdec->i_delta_poc[field];
+ int refpoc = h->fref[0][0]->i_poc + h->fref[0][0]->i_delta_poc[field];
int delta = curpoc - refpoc;
h->fdec->inv_ref_poc[field] = (256 + delta/2) / delta;
for( int field = 0; field <= h->sh.b_mbaff; field++ )
for( int i_ref0 = 0; i_ref0 < (h->i_ref[0]<<h->sh.b_mbaff); i_ref0++ )
{
- 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;
+ x264_frame_t *l0 = h->fref[0][i_ref0>>h->sh.b_mbaff];
+ int poc0 = l0->i_poc + l0->i_delta_poc[field^(i_ref0&1)];
for( int i_ref1 = 0; i_ref1 < (h->i_ref[1]<<h->sh.b_mbaff); i_ref1++ )
{
int dist_scale_factor;
- 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;
+ x264_frame_t *l1 = h->fref[1][i_ref1>>h->sh.b_mbaff];
+ int poc1 = l1->i_poc + l1->i_delta_poc[field^(i_ref1&1)];
+ int cur_poc = h->fdec->i_poc + h->fdec->i_delta_poc[field];
int td = x264_clip3( poc1 - poc0, -128, 127 );
if( td == 0 /* || pic0 is a long-term ref */ )
dist_scale_factor = 256;
{
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 curpoc = h->fdec->i_poc + h->fdec->i_delta_poc[field];
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;
+ refpoc += l0->i_delta_poc[field^(i_ref&1)];
#define SET_TMVP( dx, dy ) \
{ \
if( h->param.b_interlaced )
{
h->sh.i_delta_poc_bottom = h->param.b_tff ? 1 : -1;
- if( h->sh.i_delta_poc_bottom == -1 )
- h->sh.i_poc = h->fdec->i_poc + 1;
+ h->sh.i_poc += h->sh.i_delta_poc_bottom == -1;
}
else
h->sh.i_delta_poc_bottom = 0;
+ h->fdec->i_delta_poc[0] = h->sh.i_delta_poc_bottom == -1;
+ h->fdec->i_delta_poc[1] = h->sh.i_delta_poc_bottom == 1;
}
else if( h->sps->i_poc_type == 1 )
{
if( h->i_ref[0] )
h->fdec->i_poc_l0ref0 = h->fref[0][0]->i_poc;
+ /* ------------------------ Create slice header ----------------------- */
+ x264_slice_init( h, i_nal_type, i_global_qp );
+
+ /*------------------------- Weights -------------------------------------*/
if( h->sh.i_type == SLICE_TYPE_B )
x264_macroblock_bipred_init( h );
- /*------------------------- Weights -------------------------------------*/
x264_weighted_pred_init( h );
- /* ------------------------ Create slice header ----------------------- */
- x264_slice_init( h, i_nal_type, i_global_qp );
-
if( i_nal_ref_idc != NAL_PRIORITY_DISPOSABLE )
h->i_frame_num++;
while( (1 << sps->i_log2_max_frame_num) <= max_frame_num )
sps->i_log2_max_frame_num++;
- sps->i_poc_type = param->i_bframe ? 0 : 2;
+ sps->i_poc_type = param->i_bframe || param->b_interlaced ? 0 : 2;
if( sps->i_poc_type == 0 )
{
int max_delta_poc = (param->i_bframe + 2) * (!!param->i_bframe_pyramid + 1) * 2;