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)
    return FALSE;
  gst_vaapiencode_purge (encode);

  gst_vaapi_encoder_replace (&encode->encoder, NULL);
  if (!ensure_encoder (encode))
    return FALSE;
  if (!set_codec_state (encode, encode->input_state))
    return FALSE;

  return TRUE;
}
static gboolean
gst_vaapiencode_set_format (GstVideoEncoder * venc, GstVideoCodecState * state)
{
  GstVaapiEncode *const encode = GST_VAAPIENCODE_CAST (venc);

  g_return_val_if_fail (state->caps != NULL, FALSE);

  if (!ensure_encoder (encode))
    return FALSE;
  if (!set_codec_state (encode, state))
    return FALSE;

  if (!gst_vaapi_plugin_base_set_caps (GST_VAAPI_PLUGIN_BASE (encode),
          state->caps, NULL))
    return FALSE;

  if (encode->input_state)
    gst_video_codec_state_unref (encode->input_state);
  encode->input_state = gst_video_codec_state_ref (state);
  encode->input_state_changed = TRUE;

  return gst_pad_start_task (GST_VAAPI_PLUGIN_BASE_SRC_PAD (encode),
      (GstTaskFunction) gst_vaapiencode_buffer_loop, encode, NULL);
}
static gboolean
gst_vaapiencode_start (GstVideoEncoder * venc)
{
  return ensure_encoder (GST_VAAPIENCODE_CAST (venc));
}