From 528b5adc5a488cf3175b5334062bf18bb91a77e1 Mon Sep 17 00:00:00 2001 From: Gwenole Beauchesne Date: Sat, 21 Dec 2013 06:41:34 +0100 Subject: [PATCH] plugins: factor out construction of GValue from GstVideoFormat. Add new helper functions to build GValues from GstVideoFormat: - gst_vaapi_value_set_format(): build a GValue from the supplied video format - gst_vaapi_value_set_format_list(): build a GValue list from the supplied array of video formats --- gst/vaapi/gstvaapipluginutil.c | 43 +++++++++++++++++++++++++++ gst/vaapi/gstvaapipluginutil.h | 9 ++++++ gst/vaapi/gstvaapipostproc.c | 54 ++++------------------------------ 3 files changed, 58 insertions(+), 48 deletions(-) diff --git a/gst/vaapi/gstvaapipluginutil.c b/gst/vaapi/gstvaapipluginutil.c index 33b74dab70..c4652b839b 100644 --- a/gst/vaapi/gstvaapipluginutil.c +++ b/gst/vaapi/gstvaapipluginutil.c @@ -361,6 +361,49 @@ gst_vaapi_apply_composition (GstVaapiSurface * surface, GstBuffer * buffer) composition, TRUE); } +gboolean +gst_vaapi_value_set_format (GValue * value, GstVideoFormat format) +{ +#if GST_CHECK_VERSION(1,0,0) + const gchar *str; + + str = gst_video_format_to_string (format); + if (!str) + return FALSE; + + g_value_init (value, G_TYPE_STRING); + g_value_set_string (value, str); +#else + guint32 fourcc; + + fourcc = gst_video_format_to_fourcc (format); + if (!fourcc) + return FALSE; + + g_value_init (value, GST_TYPE_FOURCC); + gst_value_set_fourcc (value, fourcc); +#endif + return TRUE; +} + +gboolean +gst_vaapi_value_set_format_list (GValue * value, GArray * formats) +{ + GValue v_format = G_VALUE_INIT; + guint i; + + g_value_init (value, GST_TYPE_LIST); + for (i = 0; i < formats->len; i++) { + GstVideoFormat const format = g_array_index (formats, GstVideoFormat, i); + + if (!gst_vaapi_value_set_format (&v_format, format)) + continue; + gst_value_list_append_value (value, &v_format); + g_value_unset (&v_format); + } + return TRUE; +} + gboolean gst_caps_set_interlaced (GstCaps * caps, GstVideoInfo * vip) { diff --git a/gst/vaapi/gstvaapipluginutil.h b/gst/vaapi/gstvaapipluginutil.h index 31db3e414a..3d04588c5c 100644 --- a/gst/vaapi/gstvaapipluginutil.h +++ b/gst/vaapi/gstvaapipluginutil.h @@ -55,6 +55,15 @@ gst_vaapi_apply_composition (GstVaapiSurface * surface, GstBuffer * buffer); } while (0) #endif +/* Helpers for GValue construction for video formats */ +G_GNUC_INTERNAL +gboolean +gst_vaapi_value_set_format (GValue * value, GstVideoFormat format); + +G_GNUC_INTERNAL +gboolean +gst_vaapi_value_set_format_list (GValue * value, GArray * formats); + /* Helpers to handle interlaced contents */ #if GST_CHECK_VERSION(1,0,0) # define GST_CAPS_INTERLACED_MODES \ diff --git a/gst/vaapi/gstvaapipostproc.c b/gst/vaapi/gstvaapipostproc.c index 58fff7a172..d84ca3c123 100644 --- a/gst/vaapi/gstvaapipostproc.c +++ b/gst/vaapi/gstvaapipostproc.c @@ -826,57 +826,11 @@ ensure_allowed_sinkpad_caps(GstVaapiPostproc *postproc) return TRUE; } -/* Build list of supported formats */ -static gboolean -build_format_list_value(GArray *formats, GValue *out_value) -{ - GValue v_format = { 0, }; - guint i; -#if GST_CHECK_VERSION(1,0,0) - const gchar *str; - - g_value_init(out_value, GST_TYPE_LIST); - - g_value_init(&v_format, G_TYPE_STRING); - g_value_set_string(&v_format, "encoded"); - gst_value_list_append_value(out_value, &v_format); - - for (i = 0; i < formats->len; i++) { - GstVideoFormat const format = - g_array_index(formats, GstVideoFormat, i); - - str = gst_vaapi_video_format_to_string(format); - if (!str) - continue; - g_value_set_string(&v_format, str); - gst_value_list_append_value(out_value, &v_format); - } -#else - guint32 fourcc; - - g_value_init(out_value, GST_TYPE_LIST); - g_value_init(&v_format, GST_TYPE_FOURCC); - for (i = 0; i < formats->len; i++) { - GstVideoFormat const format = - g_array_index(formats, GstVideoFormat, i); - - fourcc = gst_video_format_to_fourcc(format); - if (!fourcc) - continue; - gst_value_set_fourcc(&v_format, fourcc); - gst_value_list_append_value(out_value, &v_format); - } -#endif - - g_value_unset(&v_format); - return TRUE; -} - /* Fixup output caps so that to reflect the supported set of pixel formats */ static GstCaps * expand_allowed_srcpad_caps(GstVaapiPostproc *postproc, GstCaps *caps) { - GValue value = { 0, }; + GValue value = G_VALUE_INIT, v_format = G_VALUE_INIT; guint i, num_structures; gboolean had_filter; @@ -887,8 +841,12 @@ expand_allowed_srcpad_caps(GstVaapiPostproc *postproc, GstCaps *caps) goto cleanup; /* Reset "format" field for each structure */ - if (!build_format_list_value(postproc->filter_formats, &value)) + if (!gst_vaapi_value_set_format_list(&value, postproc->filter_formats)) goto cleanup; + if (gst_vaapi_value_set_format(&v_format, GST_VIDEO_FORMAT_ENCODED)) { + gst_value_list_prepend_value(&value, &v_format); + g_value_unset(&v_format); + } num_structures = gst_caps_get_size(caps); for (i = 0; i < num_structures; i++) {