libs: profile: Use get_codec_from_caps to get codec type.

There is no need to get a profile from the caps and then convert
that profile into codec type. We can get the codec type by caps's
name easily.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-vaapi/-/merge_requests/358>
This commit is contained in:
He Junyan 2020-07-29 14:22:18 +08:00 committed by GStreamer Merge Bot
parent 7acc3c4db8
commit cf3b0120cb
5 changed files with 50 additions and 21 deletions

View file

@ -420,14 +420,9 @@ set_caps (GstVaapiDecoder * decoder, const GstCaps * caps)
{
GstVideoCodecState *const codec_state = decoder->codec_state;
GstStructure *const structure = gst_caps_get_structure (caps, 0);
GstVaapiProfile profile;
const GValue *v_codec_data;
profile = gst_vaapi_profile_from_caps (caps);
if (!profile)
return FALSE;
decoder->codec = gst_vaapi_profile_get_codec (profile);
decoder->codec = gst_vaapi_get_codec_from_caps (caps);
if (!decoder->codec)
return FALSE;
@ -1142,7 +1137,6 @@ gboolean
gst_vaapi_decoder_update_caps (GstVaapiDecoder * decoder, GstCaps * caps)
{
GstCaps *decoder_caps;
GstVaapiProfile profile;
GstVaapiCodec codec;
g_return_val_if_fail (decoder != NULL, FALSE);
@ -1155,10 +1149,7 @@ gst_vaapi_decoder_update_caps (GstVaapiDecoder * decoder, GstCaps * caps)
if (gst_caps_is_always_compatible (caps, decoder_caps))
return set_caps (decoder, caps);
profile = gst_vaapi_profile_from_caps (caps);
if (profile == GST_VAAPI_PROFILE_UNKNOWN)
return FALSE;
codec = gst_vaapi_profile_get_codec (profile);
codec = gst_vaapi_get_codec_from_caps (caps);
if (codec == 0)
return FALSE;
if (codec == decoder->codec) {

View file

@ -457,6 +457,48 @@ gst_vaapi_profile_from_caps (const GstCaps * caps)
return profile ? profile : best_profile;
}
/**
* gst_vaapi_get_codec_from_caps:
* @caps: a #GstCaps
*
* Converts @caps into the corresponding #GstVaapiCodec. If we can
* not recognize the #GstVaapiCodec, then zero is returned.
*
* Return value: the #GstVaapiCodec describing the @caps
*/
GstVaapiCodec
gst_vaapi_get_codec_from_caps (const GstCaps * caps)
{
GstStructure *structure;
const gchar *name;
gsize namelen;
const GstVaapiProfileMap *m;
GstVaapiProfile profile;
if (!caps)
return 0;
structure = gst_caps_get_structure (caps, 0);
if (!structure)
return 0;
name = gst_structure_get_name (structure);
namelen = strlen (name);
profile = GST_VAAPI_PROFILE_UNKNOWN;
for (m = gst_vaapi_profiles; m->profile; m++) {
if (strncmp (name, m->media_str, namelen) == 0) {
profile = m->profile;
break;
}
}
if (profile == GST_VAAPI_PROFILE_UNKNOWN)
return 0;
return gst_vaapi_profile_get_codec (profile);
}
/**
* gst_vaapi_profile_get_va_profile:
* @profile: a #GstVaapiProfile

View file

@ -228,6 +228,9 @@ gst_vaapi_profile(VAProfile profile);
GstVaapiProfile
gst_vaapi_profile_from_caps(const GstCaps *caps);
GstVaapiCodec
gst_vaapi_get_codec_from_caps (const GstCaps *caps);
const gchar *
gst_vaapi_profile_get_name(GstVaapiProfile profile);

View file

@ -881,12 +881,6 @@ gst_vaapidecode_ensure_display (GstVaapiDecode * decode)
return gst_vaapi_plugin_base_ensure_display (GST_VAAPI_PLUGIN_BASE (decode));
}
static inline guint
gst_vaapi_codec_from_caps (GstCaps * caps)
{
return gst_vaapi_profile_get_codec (gst_vaapi_profile_from_caps (caps));
}
static gboolean
gst_vaapidecode_create (GstVaapiDecode * decode, GstCaps * caps)
{
@ -896,7 +890,7 @@ gst_vaapidecode_create (GstVaapiDecode * decode, GstCaps * caps)
return FALSE;
dpy = GST_VAAPI_PLUGIN_BASE_DISPLAY (decode);
switch (gst_vaapi_codec_from_caps (caps)) {
switch (gst_vaapi_get_codec_from_caps (caps)) {
case GST_VAAPI_CODEC_MPEG2:
decode->decoder = gst_vaapi_decoder_mpeg2_new (dpy, caps);
break;

View file

@ -611,9 +611,8 @@ gst_vaapiencode_set_format (GstVideoEncoder * venc, GstVideoCodecState * state)
gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE, GST_TAG_ENCODER, encoder,
NULL);
if ((codec =
gst_vaapi_codec_get_name (gst_vaapi_profile_get_codec
(gst_vaapi_profile_from_caps (state->caps)))))
if ((codec = gst_vaapi_codec_get_name
(gst_vaapi_get_codec_from_caps (state->caps))))
gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE, GST_TAG_CODEC, codec,
NULL);