mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-19 23:06:49 +00:00
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:
parent
7acc3c4db8
commit
cf3b0120cb
5 changed files with 50 additions and 21 deletions
|
@ -420,14 +420,9 @@ set_caps (GstVaapiDecoder * decoder, const GstCaps * caps)
|
||||||
{
|
{
|
||||||
GstVideoCodecState *const codec_state = decoder->codec_state;
|
GstVideoCodecState *const codec_state = decoder->codec_state;
|
||||||
GstStructure *const structure = gst_caps_get_structure (caps, 0);
|
GstStructure *const structure = gst_caps_get_structure (caps, 0);
|
||||||
GstVaapiProfile profile;
|
|
||||||
const GValue *v_codec_data;
|
const GValue *v_codec_data;
|
||||||
|
|
||||||
profile = gst_vaapi_profile_from_caps (caps);
|
decoder->codec = gst_vaapi_get_codec_from_caps (caps);
|
||||||
if (!profile)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
decoder->codec = gst_vaapi_profile_get_codec (profile);
|
|
||||||
if (!decoder->codec)
|
if (!decoder->codec)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
@ -1142,7 +1137,6 @@ gboolean
|
||||||
gst_vaapi_decoder_update_caps (GstVaapiDecoder * decoder, GstCaps * caps)
|
gst_vaapi_decoder_update_caps (GstVaapiDecoder * decoder, GstCaps * caps)
|
||||||
{
|
{
|
||||||
GstCaps *decoder_caps;
|
GstCaps *decoder_caps;
|
||||||
GstVaapiProfile profile;
|
|
||||||
GstVaapiCodec codec;
|
GstVaapiCodec codec;
|
||||||
|
|
||||||
g_return_val_if_fail (decoder != NULL, FALSE);
|
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))
|
if (gst_caps_is_always_compatible (caps, decoder_caps))
|
||||||
return set_caps (decoder, caps);
|
return set_caps (decoder, caps);
|
||||||
|
|
||||||
profile = gst_vaapi_profile_from_caps (caps);
|
codec = gst_vaapi_get_codec_from_caps (caps);
|
||||||
if (profile == GST_VAAPI_PROFILE_UNKNOWN)
|
|
||||||
return FALSE;
|
|
||||||
codec = gst_vaapi_profile_get_codec (profile);
|
|
||||||
if (codec == 0)
|
if (codec == 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (codec == decoder->codec) {
|
if (codec == decoder->codec) {
|
||||||
|
|
|
@ -457,6 +457,48 @@ gst_vaapi_profile_from_caps (const GstCaps * caps)
|
||||||
return profile ? profile : best_profile;
|
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:
|
* gst_vaapi_profile_get_va_profile:
|
||||||
* @profile: a #GstVaapiProfile
|
* @profile: a #GstVaapiProfile
|
||||||
|
|
|
@ -228,6 +228,9 @@ gst_vaapi_profile(VAProfile profile);
|
||||||
GstVaapiProfile
|
GstVaapiProfile
|
||||||
gst_vaapi_profile_from_caps(const GstCaps *caps);
|
gst_vaapi_profile_from_caps(const GstCaps *caps);
|
||||||
|
|
||||||
|
GstVaapiCodec
|
||||||
|
gst_vaapi_get_codec_from_caps (const GstCaps *caps);
|
||||||
|
|
||||||
const gchar *
|
const gchar *
|
||||||
gst_vaapi_profile_get_name(GstVaapiProfile profile);
|
gst_vaapi_profile_get_name(GstVaapiProfile profile);
|
||||||
|
|
||||||
|
|
|
@ -881,12 +881,6 @@ gst_vaapidecode_ensure_display (GstVaapiDecode * decode)
|
||||||
return gst_vaapi_plugin_base_ensure_display (GST_VAAPI_PLUGIN_BASE (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
|
static gboolean
|
||||||
gst_vaapidecode_create (GstVaapiDecode * decode, GstCaps * caps)
|
gst_vaapidecode_create (GstVaapiDecode * decode, GstCaps * caps)
|
||||||
{
|
{
|
||||||
|
@ -896,7 +890,7 @@ gst_vaapidecode_create (GstVaapiDecode * decode, GstCaps * caps)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
dpy = GST_VAAPI_PLUGIN_BASE_DISPLAY (decode);
|
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:
|
case GST_VAAPI_CODEC_MPEG2:
|
||||||
decode->decoder = gst_vaapi_decoder_mpeg2_new (dpy, caps);
|
decode->decoder = gst_vaapi_decoder_mpeg2_new (dpy, caps);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -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,
|
gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE, GST_TAG_ENCODER, encoder,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if ((codec =
|
if ((codec = gst_vaapi_codec_get_name
|
||||||
gst_vaapi_codec_get_name (gst_vaapi_profile_get_codec
|
(gst_vaapi_get_codec_from_caps (state->caps))))
|
||||||
(gst_vaapi_profile_from_caps (state->caps)))))
|
|
||||||
gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE, GST_TAG_CODEC, codec,
|
gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE, GST_TAG_CODEC, codec,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue