vaapiencode: flush pending frames before set format

Flush pending frames, if any, in the internal encorder, before setting
the new negotiated format.

https://bugzilla.gnome.org/show_bug.cgi?id=786173
This commit is contained in:
Víctor Manuel Jáquez Leal 2017-09-25 17:04:12 +02:00
parent a4daa2a04a
commit 9f4a5762d5

View file

@ -564,6 +564,22 @@ set_codec_state (GstVaapiEncode * encode, GstVideoCodecState * state)
return TRUE;
}
static gboolean
gst_vaapiencode_drain (GstVaapiEncode * encode)
{
GstVaapiEncoderStatus status;
if (!encode->encoder)
return TRUE;
status = gst_vaapi_encoder_flush (encode->encoder);
if (status != GST_VAAPI_ENCODER_STATUS_SUCCESS)
return FALSE;
gst_vaapiencode_purge (encode);
return TRUE;
}
static gboolean
gst_vaapiencode_set_format (GstVideoEncoder * venc, GstVideoCodecState * state)
{
@ -579,6 +595,9 @@ gst_vaapiencode_set_format (GstVideoEncoder * venc, GstVideoCodecState * state)
state->caps, NULL))
return FALSE;
if (!gst_vaapiencode_drain (encode))
return FALSE;
if (encode->input_state)
gst_video_codec_state_unref (encode->input_state);
encode->input_state = gst_video_codec_state_ref (state);
@ -824,17 +843,14 @@ static gboolean
gst_vaapiencode_flush (GstVideoEncoder * venc)
{
GstVaapiEncode *const encode = GST_VAAPIENCODE_CAST (venc);
GstVaapiEncoderStatus status;
if (!encode->encoder)
return FALSE;
GST_LOG_OBJECT (encode, "flushing");
status = gst_vaapi_encoder_flush (encode->encoder);
if (status != GST_VAAPI_ENCODER_STATUS_SUCCESS)
if (!gst_vaapiencode_drain (encode))
return FALSE;
gst_vaapiencode_purge (encode);
gst_vaapi_encoder_replace (&encode->encoder, NULL);
if (!ensure_encoder (encode))