vaapiencode: enhance how the profile is defined

This code doesn't define the profile used by the internal encoder, but
it used to "predict" which is going to be used and to get the caps
restrictions.

Before the profile was predicted by checking the donwstream caps, but
sometimes they are not defined, setting an unknown profile. In order
to enhances this situation, the encoder asks to internal encoder if it
has one. If so, it is used.

To ask the internal encoder's profile a new accessor function was
added: gst_vaapi_encoder_get_profile()
This commit is contained in:
Víctor Manuel Jáquez Leal 2019-08-16 19:28:27 +02:00
parent bd3d347fd7
commit 3ba3966fc3
3 changed files with 43 additions and 12 deletions

View file

@ -1869,6 +1869,14 @@ gst_vaapi_encoder_ensure_max_num_ref_frames (GstVaapiEncoder * encoder,
return TRUE; return TRUE;
} }
GstVaapiProfile
gst_vaapi_encoder_get_profile (GstVaapiEncoder * encoder)
{
g_return_val_if_fail (encoder, GST_VAAPI_PROFILE_UNKNOWN);
return encoder->profile;
}
/** Returns a GType for the #GstVaapiEncoderTune set */ /** Returns a GType for the #GstVaapiEncoderTune set */
GType GType
gst_vaapi_encoder_tune_get_type (void) gst_vaapi_encoder_tune_get_type (void)

View file

@ -216,6 +216,10 @@ gst_vaapi_encoder_flush (GstVaapiEncoder * encoder);
GArray * GArray *
gst_vaapi_encoder_get_surface_formats (GstVaapiEncoder * encoder, gst_vaapi_encoder_get_surface_formats (GstVaapiEncoder * encoder,
GstVaapiProfile profile); GstVaapiProfile profile);
GstVaapiProfile
gst_vaapi_encoder_get_profile (GstVaapiEncoder * encoder);
G_END_DECLS G_END_DECLS
#endif /* GST_VAAPI_ENCODER_H */ #endif /* GST_VAAPI_ENCODER_H */

View file

@ -365,35 +365,54 @@ gst_vaapiencode_buffer_loop (GstVaapiEncode * encode)
gst_pad_pause_task (GST_VAAPI_PLUGIN_BASE_SRC_PAD (encode)); gst_pad_pause_task (GST_VAAPI_PLUGIN_BASE_SRC_PAD (encode));
} }
static GstVaapiProfile
get_profile (GstVaapiEncode * encode)
{
GstVaapiEncodeClass *klass = GST_VAAPIENCODE_GET_CLASS (encode);
if (klass->get_profile) {
GstVaapiProfile profile = GST_VAAPI_PROFILE_UNKNOWN;
GstCaps *allowed =
gst_pad_get_allowed_caps (GST_VAAPI_PLUGIN_BASE_SRC_PAD (encode));
if (allowed) {
if (!gst_caps_is_empty (allowed) && !gst_caps_is_any (allowed))
profile = klass->get_profile (allowed);
gst_caps_unref (allowed);
}
if (profile != GST_VAAPI_PROFILE_UNKNOWN)
return profile;
}
if (encode->encoder)
return gst_vaapi_encoder_get_profile (encode->encoder);
return GST_VAAPI_PROFILE_UNKNOWN;
}
static gboolean static gboolean
ensure_allowed_sinkpad_caps (GstVaapiEncode * encode) ensure_allowed_sinkpad_caps (GstVaapiEncode * encode)
{ {
GstVaapiEncodeClass *klass = GST_VAAPIENCODE_GET_CLASS (encode);
GstCaps *out_caps, *raw_caps = NULL; GstCaps *out_caps, *raw_caps = NULL;
GArray *formats = NULL; GArray *formats = NULL;
gboolean ret = FALSE; gboolean ret = FALSE;
GstVaapiProfile profile = GST_VAAPI_PROFILE_UNKNOWN; GstVaapiProfile profile;
if (encode->allowed_sinkpad_caps) if (encode->allowed_sinkpad_caps)
return TRUE; return TRUE;
if (!encode->encoder) if (!encode->encoder)
return TRUE; return TRUE;
profile = get_profile (encode);
if (profile == GST_VAAPI_PROFILE_UNKNOWN)
return TRUE;
out_caps = gst_caps_from_string (GST_VAAPI_MAKE_SURFACE_CAPS ";" out_caps = gst_caps_from_string (GST_VAAPI_MAKE_SURFACE_CAPS ";"
GST_VAAPI_MAKE_DMABUF_CAPS); GST_VAAPI_MAKE_DMABUF_CAPS);
if (!out_caps) if (!out_caps)
goto failed_create_va_caps; goto failed_create_va_caps;
if (klass->get_profile) {
GstCaps *allowed =
gst_pad_get_allowed_caps (GST_VAAPI_PLUGIN_BASE_SRC_PAD (encode));
if (allowed) {
if (!gst_caps_is_empty (allowed) && !gst_caps_is_any (allowed))
profile = klass->get_profile (allowed);
gst_caps_unref (allowed);
}
}
formats = gst_vaapi_encoder_get_surface_formats (encode->encoder, profile); formats = gst_vaapi_encoder_get_surface_formats (encode->encoder, profile);
if (!formats) if (!formats)
goto failed_get_formats; goto failed_get_formats;