Commit 3c50b9b4 authored by Anton Mitrofanov's avatar Anton Mitrofanov Committed by Fiona Glaser

Fix some possible overflows in VFR ratecontrol with extreme timebases

parent 5b91a48c
......@@ -429,16 +429,16 @@ struct x264_t
int i_nal_type;
int i_nal_ref_idc;
int i_disp_fields; /* Number of displayed fields (both coded and implied via pic_struct) */
int64_t i_disp_fields; /* Number of displayed fields (both coded and implied via pic_struct) */
int i_disp_fields_last_frame;
int i_prev_duration; /* Duration of previous frame */
int i_coded_fields; /* Number of coded fields (both coded and implied via pic_struct) */
int i_cpb_delay; /* Equal to number of fields preceding this field
int64_t i_prev_duration; /* Duration of previous frame */
int64_t i_coded_fields; /* Number of coded fields (both coded and implied via pic_struct) */
int64_t i_cpb_delay; /* Equal to number of fields preceding this field
* since last buffering_period SEI */
int i_coded_fields_lookahead; /* Use separate counters for lookahead */
int i_cpb_delay_lookahead;
int64_t i_coded_fields_lookahead; /* Use separate counters for lookahead */
int64_t i_cpb_delay_lookahead;
int i_cpb_delay_pir_offset;
int64_t i_cpb_delay_pir_offset;
int b_queued_intra_refresh;
int64_t i_last_idr_pts;
......
......@@ -41,16 +41,16 @@ typedef struct x264_frame
int64_t i_pts;
int64_t i_dts;
int64_t i_reordered_pts;
int i_duration; /* in SPS time_scale units (i.e 2 * timebase units) used for vfr */
int64_t i_duration; /* in SPS time_scale units (i.e 2 * timebase units) used for vfr */
float f_duration; /* in seconds */
int i_cpb_duration;
int i_cpb_delay; /* in SPS time_scale units (i.e 2 * timebase units) */
int i_dpb_output_delay;
int64_t i_cpb_duration;
int64_t i_cpb_delay; /* in SPS time_scale units (i.e 2 * timebase units) */
int64_t i_dpb_output_delay;
x264_param_t *param;
int i_frame; /* Presentation frame number */
int i_coded; /* Coded frame number */
int i_field_cnt; /* Presentation field count */
int64_t i_field_cnt; /* Presentation field count */
int i_frame_num; /* 7.4.3 frame_num */
int b_kept_as_ref;
int i_pic_struct;
......@@ -134,8 +134,8 @@ typedef struct x264_frame
uint8_t i_planned_type[X264_LOOKAHEAD_MAX+1];
int i_planned_satd[X264_LOOKAHEAD_MAX+1];
double f_planned_cpb_duration[X264_LOOKAHEAD_MAX+1];
int i_coded_fields_lookahead;
int i_cpb_delay_lookahead;
int64_t i_coded_fields_lookahead;
int64_t i_cpb_delay_lookahead;
/* threading */
int i_lines_completed; /* in pixels */
......
......@@ -57,8 +57,8 @@ typedef struct
int16_t i_weight_denom[2];
int refcount[16];
int refs;
int i_duration;
int i_cpb_duration;
int64_t i_duration;
int64_t i_cpb_duration;
} ratecontrol_entry_t;
typedef struct
......@@ -834,7 +834,7 @@ int x264_ratecontrol_new( x264_t *h )
rce = &rc->entry[frame_number];
rce->direct_mode = 0;
e += sscanf( p, " in:%*d out:%*d type:%c dur:%d cpbdur:%d q:%f tex:%d mv:%d misc:%d imb:%d pmb:%d smb:%d d:%c",
e += sscanf( p, " in:%*d out:%*d type:%c dur:%"SCNd64" cpbdur:%"SCNd64" q:%f tex:%d mv:%d misc:%d imb:%d pmb:%d smb:%d d:%c",
&pict_type, &rce->i_duration, &rce->i_cpb_duration, &qp, &rce->tex_bits,
&rce->mv_bits, &rce->misc_bits, &rce->i_count, &rce->p_count,
&rce->s_count, &rce->direct_mode );
......@@ -1534,7 +1534,7 @@ int x264_ratecontrol_end( x264_t *h, int bits, int *filler )
dir_avg>0 ? 's' : dir_avg<0 ? 't' : '-' )
: '-';
if( fprintf( rc->p_stat_file_out,
"in:%d out:%d type:%c dur:%d cpbdur:%d q:%.2f tex:%d mv:%d misc:%d imb:%d pmb:%d smb:%d d:%c ref:",
"in:%d out:%d type:%c dur:%"PRId64" cpbdur:%"PRId64" q:%.2f tex:%d mv:%d misc:%d imb:%d pmb:%d smb:%d d:%c ref:",
h->fenc->i_frame, h->i_frame,
c_type, h->fenc->i_duration,
h->fenc->i_cpb_duration, rc->qpa_rc,
......
......@@ -955,7 +955,7 @@ static int x264_vbv_frame_cost( x264_t *h, x264_mb_analysis_t *a, x264_frame_t *
return cost;
}
static void x264_calculate_durations( x264_t *h, x264_frame_t *cur_frame, x264_frame_t *prev_frame, int *i_cpb_delay, int *i_coded_fields )
static void x264_calculate_durations( x264_t *h, x264_frame_t *cur_frame, x264_frame_t *prev_frame, int64_t *i_cpb_delay, int64_t *i_coded_fields )
{
cur_frame->i_cpb_delay = *i_cpb_delay;
cur_frame->i_dpb_output_delay = cur_frame->i_field_cnt - *i_coded_fields;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment