vaapiencode: h264,h265: validate fps numerator

Validate that fps numerator is non-zero so it can be used to calculate
the duration of the B frame.

Also it gst_util_uint64_scale() is used instead of normal arithmetic in
order to aviod overflows, underflows and loss of precision.

https://bugzilla.gnome.org/show_bug.cgi?id=768458
This commit is contained in:
Víctor Manuel Jáquez Leal 2016-07-05 20:07:15 +02:00
parent f182b8be2b
commit 4259d1aec7
2 changed files with 8 additions and 8 deletions

View file

@ -2467,11 +2467,11 @@ reset_properties (GstVaapiEncoderH264 * encoder)
encoder->num_bframes = 0;
}
if (encoder->num_bframes)
encoder->cts_offset = GST_SECOND * GST_VAAPI_ENCODER_FPS_D (encoder) /
GST_VAAPI_ENCODER_FPS_N (encoder);
if (encoder->num_bframes > 0 && GST_VAAPI_ENCODER_FPS_N (encoder) > 0)
encoder->cts_offset = gst_util_uint64_scale (GST_SECOND,
GST_VAAPI_ENCODER_FPS_D (encoder), GST_VAAPI_ENCODER_FPS_N (encoder));
else
encoder->cts_offset = 0;
encoder->cts_offset = GST_CLOCK_TIME_NONE;
/* init max_frame_num, max_poc */
encoder->log2_max_frame_num =

View file

@ -2030,11 +2030,11 @@ reset_properties (GstVaapiEncoderH265 * encoder)
if (encoder->num_bframes > (base_encoder->keyframe_period + 1) / 2)
encoder->num_bframes = (base_encoder->keyframe_period + 1) / 2;
if (encoder->num_bframes)
encoder->cts_offset = GST_SECOND * GST_VAAPI_ENCODER_FPS_D (encoder) /
GST_VAAPI_ENCODER_FPS_N (encoder);
if (encoder->num_bframes > 0 && GST_VAAPI_ENCODER_FPS_N (encoder) > 0)
encoder->cts_offset = gst_util_uint64_scale (GST_SECOND,
GST_VAAPI_ENCODER_FPS_D (encoder), GST_VAAPI_ENCODER_FPS_N (encoder));
else
encoder->cts_offset = 0;
encoder->cts_offset = GST_CLOCK_TIME_NONE;
/* init max_poc */
encoder->log2_max_pic_order_cnt =