vaapidecode: simplify codec lookup from caps.

Add new gst_vaapi_codec_from_caps() helper to determine codec type from
the specified caps. Don't globally expose this function since this is
really trivial and only used in the vaapidecode element.
This commit is contained in:
Gwenole Beauchesne 2012-09-11 16:41:32 +02:00
parent 9afe700005
commit 2b71db3059

View file

@ -303,12 +303,16 @@ gst_vaapidecode_ensure_display(GstVaapiDecode *decode)
&decode->display); &decode->display);
} }
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)
{ {
GstVaapiDisplay *dpy; GstVaapiDisplay *dpy;
GstStructure *structure;
int version;
if (!gst_vaapidecode_ensure_display(decode)) if (!gst_vaapidecode_ensure_display(decode))
return FALSE; return FALSE;
@ -322,30 +326,30 @@ gst_vaapidecode_create(GstVaapiDecode *decode, GstCaps *caps)
if (!decode->decoder_ready) if (!decode->decoder_ready)
return FALSE; return FALSE;
structure = gst_caps_get_structure(caps, 0); switch (gst_vaapi_codec_from_caps(caps)) {
if (!structure) case GST_VAAPI_CODEC_MPEG2:
return FALSE; decode->decoder = gst_vaapi_decoder_mpeg2_new(dpy, caps);
break;
if (gst_structure_has_name(structure, "video/x-h264")) case GST_VAAPI_CODEC_MPEG4:
decode->decoder = gst_vaapi_decoder_h264_new(dpy, caps); case GST_VAAPI_CODEC_H263:
else if (gst_structure_has_name(structure, "video/mpeg")) {
if (!gst_structure_get_int(structure, "mpegversion", &version))
return FALSE;
if (version == 2)
decode->decoder = gst_vaapi_decoder_mpeg2_new(dpy, caps);
else if (version == 4)
decode->decoder = gst_vaapi_decoder_mpeg4_new(dpy, caps);
}
else if (gst_structure_has_name(structure, "video/x-wmv"))
decode->decoder = gst_vaapi_decoder_vc1_new(dpy, caps);
else if (gst_structure_has_name(structure, "video/x-h263") ||
gst_structure_has_name(structure, "video/x-divx") ||
gst_structure_has_name(structure, "video/x-xvid"))
decode->decoder = gst_vaapi_decoder_mpeg4_new(dpy, caps); decode->decoder = gst_vaapi_decoder_mpeg4_new(dpy, caps);
break;
case GST_VAAPI_CODEC_H264:
decode->decoder = gst_vaapi_decoder_h264_new(dpy, caps);
break;
case GST_VAAPI_CODEC_WMV3:
case GST_VAAPI_CODEC_VC1:
decode->decoder = gst_vaapi_decoder_vc1_new(dpy, caps);
break;
#if USE_JPEG_DECODER #if USE_JPEG_DECODER
else if (gst_structure_has_name(structure, "image/jpeg")) case GST_VAAPI_CODEC_JPEG:
decode->decoder = gst_vaapi_decoder_jpeg_new(dpy, caps); decode->decoder = gst_vaapi_decoder_jpeg_new(dpy, caps);
break;
#endif #endif
default:
decode->decoder = NULL;
break;
}
if (!decode->decoder) if (!decode->decoder)
return FALSE; return FALSE;