diff --git a/NEWS b/NEWS index 07c7042078..b0bd819706 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,7 @@ Copyright (C) 2010 Splitted-Desktop Systems Version 0.2.1 - DD.May.2010 * Fix integration within the playbin2 pipeline +* Fix vaapidecode to expose the HW supported caps only Version 0.2.0 - 05.May.2010 * Relicense gst-libs/ code to LGPL v2.1+ diff --git a/gst/vaapidecode/Makefile.am b/gst/vaapidecode/Makefile.am index b1fd20d5e2..f537e6e1f3 100644 --- a/gst/vaapidecode/Makefile.am +++ b/gst/vaapidecode/Makefile.am @@ -4,7 +4,7 @@ libgstvaapi_CFLAGS = \ -I$(top_srcdir)/gst-libs libgstvaapi_LIBS = \ - $(top_builddir)/gst-libs/gst/vaapi/libgstvaapi-$(GST_MAJORMINOR).la + $(top_builddir)/gst-libs/gst/vaapi/libgstvaapi-x11-$(GST_MAJORMINOR).la libgstvaapidecode_la_SOURCES = \ gstvaapidecode.c \ diff --git a/gst/vaapidecode/gstvaapidecode.c b/gst/vaapidecode/gstvaapidecode.c index 61e5797323..130424a1b4 100644 --- a/gst/vaapidecode/gstvaapidecode.c +++ b/gst/vaapidecode/gstvaapidecode.c @@ -28,6 +28,7 @@ #include "config.h" #include "gstvaapidecode.h" +#include #include #include #include @@ -241,6 +242,11 @@ gst_vaapidecode_finalize(GObject *object) decode->display = NULL; } + if (decode->allowed_caps) { + gst_caps_unref(decode->allowed_caps); + decode->allowed_caps = NULL; + } + G_OBJECT_CLASS(parent_class)->finalize(object); } @@ -336,6 +342,87 @@ gst_vaapidecode_class_init(GstVaapiDecodeClass *klass) G_PARAM_READWRITE)); } +static gboolean +gst_vaapidecode_ensure_allowed_caps(GstVaapiDecode *decode) +{ + GstVaapiDisplay *display; + GstCaps *decode_caps; + guint i, n_decode_caps; + + if (decode->allowed_caps) + return TRUE; + + if (gst_vaapidecode_ensure_display(decode)) + display = g_object_ref(decode->display); + else { + display = gst_vaapi_display_x11_new(NULL); + if (!display) + goto error_no_display; + } + + decode_caps = gst_vaapi_display_get_decode_caps(display); + if (!decode_caps) + goto error_no_decode_caps; + n_decode_caps = gst_caps_get_size(decode_caps); + + decode->allowed_caps = gst_caps_new_empty(); + if (!decode->allowed_caps) + goto error_no_memory; + + for (i = 0; i < n_decode_caps; i++) { + GstStructure *structure; + structure = gst_caps_get_structure(decode_caps, i); + if (!structure) + continue; + structure = gst_structure_copy(structure); + if (!structure) + continue; + gst_structure_remove_field(structure, "profile"); + gst_structure_set( + structure, + "width", GST_TYPE_INT_RANGE, 1, G_MAXINT, + "height", GST_TYPE_INT_RANGE, 1, G_MAXINT, + NULL + ); + gst_caps_merge_structure(decode->allowed_caps, structure); + } + + gst_caps_unref(decode_caps); + g_object_unref(display); + return TRUE; + + /* ERRORS */ +error_no_display: + { + GST_DEBUG("failed to retrieve VA display"); + return FALSE; + } +error_no_decode_caps: + { + GST_DEBUG("failed to retrieve VA decode caps"); + g_object_unref(display); + return FALSE; + } +error_no_memory: + { + GST_DEBUG("failed to allocate allowed-caps set"); + gst_caps_unref(decode_caps); + g_object_unref(display); + return FALSE; + } +} + +static GstCaps * +gst_vaapidecode_get_caps(GstPad *pad) +{ + GstVaapiDecode * const decode = GST_VAAPIDECODE(GST_OBJECT_PARENT(pad)); + + if (!gst_vaapidecode_ensure_allowed_caps(decode)) + return gst_caps_new_empty(); + + return gst_caps_ref(decode->allowed_caps); +} + static gboolean gst_vaapidecode_set_caps(GstPad *pad, GstCaps *caps) { @@ -424,6 +511,7 @@ gst_vaapidecode_init(GstVaapiDecode *decode, GstVaapiDecodeClass *klass) decode->display = NULL; decode->decoder = NULL; decode->decoder_caps = NULL; + decode->allowed_caps = NULL; decode->use_ffmpeg = TRUE; /* Pad through which data comes in to the element */ @@ -432,6 +520,7 @@ gst_vaapidecode_init(GstVaapiDecode *decode, GstVaapiDecodeClass *klass) "sink" ); + gst_pad_set_getcaps_function(decode->sinkpad, gst_vaapidecode_get_caps); gst_pad_set_setcaps_function(decode->sinkpad, gst_vaapidecode_set_caps); gst_pad_set_chain_function(decode->sinkpad, gst_vaapidecode_chain); gst_pad_set_event_function(decode->sinkpad, gst_vaapidecode_sink_event); diff --git a/gst/vaapidecode/gstvaapidecode.h b/gst/vaapidecode/gstvaapidecode.h index 068f198ca7..8791bd961f 100644 --- a/gst/vaapidecode/gstvaapidecode.h +++ b/gst/vaapidecode/gstvaapidecode.h @@ -64,6 +64,7 @@ struct _GstVaapiDecode { GstVaapiDisplay *display; GstVaapiDecoder *decoder; GstCaps *decoder_caps; + GstCaps *allowed_caps; unsigned int use_ffmpeg : 1; };