From 647621cf3c272891565e2c4c7bdf90da257d21f6 Mon Sep 17 00:00:00 2001 From: gb Date: Wed, 24 Mar 2010 09:52:43 +0000 Subject: [PATCH] Add GstVaapiID abstraction. --- docs/reference/libs/libs-sections.txt | 3 + docs/reference/libs/libs.types | 1 + gst-libs/gst/vaapi/Makefile.am | 1 + gst-libs/gst/vaapi/gstvaapitypes.c | 164 ++++++++++++++++++++++++++++++++++ gst-libs/gst/vaapi/gstvaapitypes.h | 53 ++++++++++- 5 files changed, 220 insertions(+), 2 deletions(-) create mode 100644 gst-libs/gst/vaapi/gstvaapitypes.c diff --git a/docs/reference/libs/libs-sections.txt b/docs/reference/libs/libs-sections.txt index d512dd9..bc0f284 100644 --- a/docs/reference/libs/libs-sections.txt +++ b/docs/reference/libs/libs-sections.txt @@ -158,6 +158,9 @@ GST_VAAPI_VIDEO_BUFFER_GET_CLASS
gstvaapitypes Basic data structures +GstVaapiID +gst_vaapi_value_get_id +gst_vaapi_value_set_id GstVaapiPoint GstVaapiRectangle
diff --git a/docs/reference/libs/libs.types b/docs/reference/libs/libs.types index 3d7aca2..6678c0d 100644 --- a/docs/reference/libs/libs.types +++ b/docs/reference/libs/libs.types @@ -1,5 +1,6 @@ gst_vaapi_display_get_type gst_vaapi_display_x11_get_type +gst_vaapi_id_get_type gst_vaapi_image_get_type gst_vaapi_image_pool_get_type gst_vaapi_object_get_type diff --git a/gst-libs/gst/vaapi/Makefile.am b/gst-libs/gst/vaapi/Makefile.am index d5148c3..0b3cb93 100644 --- a/gst-libs/gst/vaapi/Makefile.am +++ b/gst-libs/gst/vaapi/Makefile.am @@ -16,6 +16,7 @@ libgstvaapi_source_c = \ gstvaapisubpicture.c \ gstvaapisurface.c \ gstvaapisurfacepool.c \ + gstvaapitypes.c \ gstvaapiutils.c \ gstvaapivideobuffer.c \ gstvaapivideopool.c \ diff --git a/gst-libs/gst/vaapi/gstvaapitypes.c b/gst-libs/gst/vaapi/gstvaapitypes.c new file mode 100644 index 0000000..7a18995 --- /dev/null +++ b/gst-libs/gst/vaapi/gstvaapitypes.c @@ -0,0 +1,164 @@ +/* + * gstvaapitypes.h - Basic types + * + * gstreamer-vaapi (C) 2010 Splitted-Desktop Systems + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/** + * SECTION:gstvaapitypes + * @short_description: Basic types + */ + +#include "config.h" +#include +#include +#include "gstvaapitypes.h" + +#if GST_VAAPI_TYPE_ID_SIZE == 4 +# define GST_VAAPI_VALUE_ID_(cvalue) ((cvalue).v_int) +# define GST_VAAPI_VALUE_ID_CFORMAT "i" +#elif GST_VAAPI_TYPE_ID_SIZE == 8 +# define GST_VAAPI_VALUE_ID_(cvalue) ((cvalue).v_int64) +# define GST_VAAPI_VALUE_ID_CFORMAT "q" +#else +# error "unsupported GstVaapiID size" +#endif +#define GST_VAAPI_VALUE_ID(value) GST_VAAPI_VALUE_ID_((value)->data[0]) + +static void +gst_vaapi_value_id_init(GValue *value) +{ + GST_VAAPI_VALUE_ID(value) = 0; +} + +static void +gst_vaapi_value_id_copy(const GValue *src_value, GValue *dst_value) +{ + GST_VAAPI_VALUE_ID(dst_value) = GST_VAAPI_VALUE_ID(src_value); +} + +static gchar * +gst_vaapi_value_id_collect( + GValue *value, + guint n_collect_values, + GTypeCValue *collect_values, + guint collect_flags +) +{ + GST_VAAPI_VALUE_ID(value) = GST_VAAPI_VALUE_ID_(collect_values[0]); + + return NULL; +} + +static gchar * +gst_vaapi_value_id_lcopy( + const GValue *value, + guint n_collect_values, + GTypeCValue *collect_values, + guint collect_flags +) +{ + GstVaapiID *id_p = collect_values[0].v_pointer; + + if (!id_p) + return g_strdup_printf("value location for `%s' passed as NULL", + G_VALUE_TYPE_NAME(value)); + + *id_p = GST_VAAPI_VALUE_ID(value); + return NULL; +} + +static GTypeInfo gst_vaapi_type_info = { + 0, + NULL, + NULL, + NULL, + NULL, + NULL, + 0, + 0, + NULL, + NULL, +}; + +static GTypeFundamentalInfo gst_vaapi_type_finfo = { + 0 +}; + +#define GST_VAAPI_TYPE_DEFINE(type, name) \ +GType gst_vaapi_ ## type ## _get_type(void) \ +{ \ + static GType gst_vaapi_ ## type ## _type = 0; \ + \ + if (G_UNLIKELY(gst_vaapi_ ## type ## _type == 0)) { \ + gst_vaapi_type_info.value_table = \ + &gst_vaapi_ ## type ## _value_table; \ + gst_vaapi_ ## type ## _type = g_type_register_fundamental( \ + g_type_fundamental_next(), \ + name, \ + &gst_vaapi_type_info, \ + &gst_vaapi_type_finfo, \ + 0 \ + ); \ + } \ + \ + return gst_vaapi_ ## type ## _type; \ +} + +static const GTypeValueTable gst_vaapi_id_value_table = { + gst_vaapi_value_id_init, + NULL, + gst_vaapi_value_id_copy, + NULL, + GST_VAAPI_VALUE_ID_CFORMAT, + gst_vaapi_value_id_collect, + "p", + gst_vaapi_value_id_lcopy +}; + +GST_VAAPI_TYPE_DEFINE(id, "GstVaapiID"); + +/** + * gst_vaapi_value_get_id: + * @value: a GValue initialized to #GstVaapiID + * + * Gets the integer contained in @value. + * + * Return value: the integer contained in @value + */ +GstVaapiID +gst_vaapi_value_get_id(const GValue *value) +{ + g_return_val_if_fail(GST_VAAPI_VALUE_HOLDS_ID(value), 0); + + return GST_VAAPI_VALUE_ID(value); +} + +/** + * gst_vaapi_value_set_id: + * @value: a GValue initialized to #GstVaapiID + * @id: a #GstVaapiID + * + * Sets the integer contained in @id to @value. + */ +void +gst_vaapi_value_set_id(GValue *value, GstVaapiID id) +{ + g_return_if_fail(GST_VAAPI_VALUE_HOLDS_ID(value)); + + GST_VAAPI_VALUE_ID(value) = id; +} diff --git a/gst-libs/gst/vaapi/gstvaapitypes.h b/gst-libs/gst/vaapi/gstvaapitypes.h index 97dd598..57b8a81 100644 --- a/gst-libs/gst/vaapi/gstvaapitypes.h +++ b/gst-libs/gst/vaapi/gstvaapitypes.h @@ -1,5 +1,5 @@ /* - * gstvaapitypes.h - Misc types + * gstvaapitypes.h - Basic types * * gstreamer-vaapi (C) 2010 Splitted-Desktop Systems * @@ -21,11 +21,60 @@ #ifndef GST_VAAPI_TYPES_H #define GST_VAAPI_TYPES_H -#include +#include G_BEGIN_DECLS /** + * GstVaapiID: + * + * An integer large enough to hold a generic VA id or a pointer + * wherever necessary. + */ +#if defined(GLIB_SIZEOF_VOID_P) +# define GST_VAAPI_TYPE_ID_SIZE GLIB_SIZEOF_VOID_P +#elif G_MAXULONG == 0xffffffff +# define GST_VAAPI_TYPE_ID_SIZE 4 +#elif G_MAXULONG == 0xffffffffffffffffull +# define GST_VAAPI_TYPE_ID_SIZE 8 +#else +# error "could not determine size of GstVaapiID" +#endif +#if GST_VAAPI_TYPE_ID_SIZE == 4 +typedef guint32 GstVaapiID; +#elif GST_VAAPI_TYPE_ID_SIZE == 8 +typedef guint64 GstVaapiID; +#else +# error "unsupported value for GST_VAAPI_TYPE_ID_SIZE" +#endif + +/** + * GST_VAAPI_TYPE_ID: + * + * A #GValue type that represents a VA identifier. + * + * Return value: the #GType of GstVaapiID + */ +#define GST_VAAPI_TYPE_ID gst_vaapi_id_get_type() + +/** + * GST_VAAPI_VALUE_HOLDS_ID: + * @x: the #GValue to check + * + * Checks if the given #GValue contains a #GstVaapiID value. + */ +#define GST_VAAPI_VALUE_HOLDS_ID(x) (G_VALUE_HOLDS((x), GST_VAAPI_TYPE_ID)) + +GType +gst_vaapi_id_get_type(void); + +GstVaapiID +gst_vaapi_value_get_id(const GValue *value); + +void +gst_vaapi_value_set_id(GValue *value, GstVaapiID id); + +/** * GstVaapiPoint: * @x: X coordinate * @y: Y coordinate -- 2.7.4