diff --git a/gst-libs/gst/vaapi/gstvaapidecoder.c b/gst-libs/gst/vaapi/gstvaapidecoder.c index 093fcc0573..192d71aab2 100644 --- a/gst-libs/gst/vaapi/gstvaapidecoder.c +++ b/gst-libs/gst/vaapi/gstvaapidecoder.c @@ -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) { diff --git a/gst-libs/gst/vaapi/gstvaapiprofile.c b/gst-libs/gst/vaapi/gstvaapiprofile.c index 05480dffc1..cbf2db5703 100644 --- a/gst-libs/gst/vaapi/gstvaapiprofile.c +++ b/gst-libs/gst/vaapi/gstvaapiprofile.c @@ -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 diff --git a/gst-libs/gst/vaapi/gstvaapiprofile.h b/gst-libs/gst/vaapi/gstvaapiprofile.h index c3080f4ee3..3ba23f69c4 100644 --- a/gst-libs/gst/vaapi/gstvaapiprofile.h +++ b/gst-libs/gst/vaapi/gstvaapiprofile.h @@ -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); diff --git a/gst/vaapi/gstvaapidecode.c b/gst/vaapi/gstvaapidecode.c index 59ec6e958c..afe2dd2730 100644 --- a/gst/vaapi/gstvaapidecode.c +++ b/gst/vaapi/gstvaapidecode.c @@ -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; diff --git a/gst/vaapi/gstvaapiencode.c b/gst/vaapi/gstvaapiencode.c index eacf13c3d9..a970f827b1 100644 --- a/gst/vaapi/gstvaapiencode.c +++ b/gst/vaapi/gstvaapiencode.c @@ -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);