Port GstVaapiObject to GstVaapiMiniObject.

This commit is contained in:
Gwenole Beauchesne 2013-04-30 17:20:46 +02:00
parent 6439169db5
commit 1f15c28a1b
4 changed files with 195 additions and 200 deletions

View file

@ -20,6 +20,7 @@ libgstvaapi_includedir = \
$(includedir)/gstreamer-$(GST_API_VERSION)/gst/vaapi $(includedir)/gstreamer-$(GST_API_VERSION)/gst/vaapi
libgstvaapi_cflags = \ libgstvaapi_cflags = \
-DGST_VAAPI_CORE \
-DGST_USE_UNSTABLE_API \ -DGST_USE_UNSTABLE_API \
-I$(top_srcdir)/gst-libs \ -I$(top_srcdir)/gst-libs \
-I$(top_builddir)/gst-libs \ -I$(top_builddir)/gst-libs \

View file

@ -27,169 +27,117 @@
#include "sysdeps.h" #include "sysdeps.h"
#include "gstvaapiobject.h" #include "gstvaapiobject.h"
#include "gstvaapi_priv.h" #include "gstvaapiobject_priv.h"
#include "gstvaapiparamspecs.h" #include "gstvaapiminiobject.h"
#include "gstvaapivalue.h" #include "gstvaapidisplay_priv.h"
#define DEBUG 1 #define DEBUG 1
#include "gstvaapidebug.h" #include "gstvaapidebug.h"
G_DEFINE_TYPE(GstVaapiObject, gst_vaapi_object, G_TYPE_OBJECT) /* Ensure those symbols are actually defined in the resulting libraries */
#undef gst_vaapi_object_ref
enum { #undef gst_vaapi_object_unref
PROP_0, #undef gst_vaapi_object_replace
PROP_DISPLAY,
PROP_ID
};
enum {
DESTROY,
LAST_SIGNAL
};
static guint object_signals[LAST_SIGNAL] = { 0, };
static void static void
gst_vaapi_object_dispose(GObject *object) gst_vaapi_object_finalize(GstVaapiObject *object)
{ {
GstVaapiObjectPrivate * const priv = GST_VAAPI_OBJECT(object)->priv; const GstVaapiObjectClass * const klass =
GST_VAAPI_OBJECT_GET_CLASS(object);
if (!priv->is_destroying) { if (klass->finalize)
priv->is_destroying = TRUE; klass->finalize(object);
g_signal_emit(object, object_signals[DESTROY], 0); g_clear_object(&object->display);
priv->is_destroying = FALSE;
}
G_OBJECT_CLASS(gst_vaapi_object_parent_class)->dispose(object);
} }
static void void
gst_vaapi_object_finalize(GObject *object) gst_vaapi_object_class_init(GstVaapiObjectClass *klass, guint size)
{ {
GstVaapiObjectPrivate * const priv = GST_VAAPI_OBJECT(object)->priv; GstVaapiMiniObjectClass * const object_class =
GST_VAAPI_MINI_OBJECT_CLASS(klass);
priv->id = GST_VAAPI_ID_NONE; object_class->size = size;
object_class->finalize = (GDestroyNotify)gst_vaapi_object_finalize;
g_clear_object(&priv->display);
G_OBJECT_CLASS(gst_vaapi_object_parent_class)->finalize(object);
} }
static void /**
gst_vaapi_object_set_property( * gst_vaapi_object_new:
GObject *gobject, * @object_class: The object class
guint prop_id,
const GValue *value,
GParamSpec *pspec
)
{
GstVaapiObject * const object = GST_VAAPI_OBJECT(gobject);
switch (prop_id) {
case PROP_DISPLAY:
object->priv->display = g_object_ref(g_value_get_object(value));
break;
case PROP_ID:
object->priv->id = gst_vaapi_value_get_id(value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
break;
}
}
static void
gst_vaapi_object_get_property(
GObject *gobject,
guint prop_id,
GValue *value,
GParamSpec *pspec
)
{
GstVaapiObject * const object = GST_VAAPI_OBJECT(gobject);
switch (prop_id) {
case PROP_DISPLAY:
g_value_set_object(value, gst_vaapi_object_get_display(object));
break;
case PROP_ID:
gst_vaapi_value_set_id(value, gst_vaapi_object_get_id(object));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
break;
}
}
static void
gst_vaapi_object_class_init(GstVaapiObjectClass *klass)
{
GObjectClass * const object_class = G_OBJECT_CLASS(klass);
g_type_class_add_private(klass, sizeof(GstVaapiObjectPrivate));
object_class->dispose = gst_vaapi_object_dispose;
object_class->finalize = gst_vaapi_object_finalize;
object_class->set_property = gst_vaapi_object_set_property;
object_class->get_property = gst_vaapi_object_get_property;
/**
* GstVaapiObject:display:
* *
* The #GstVaapiDisplay this object is bound to. * Creates a new #GstVaapiObject. If @object_class is NULL, then the
*/ * size of the allocated object is the same as sizeof(GstVaapiObject).
g_object_class_install_property * If @object_class is not NULL, typically when a sub-class is implemented,
(object_class, * that pointer shall reference a statically allocated descriptor.
PROP_DISPLAY,
g_param_spec_object("display",
"Display",
"The GstVaapiDisplay this object is bound to",
GST_VAAPI_TYPE_DISPLAY,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
/**
* GstVaapiObject:id:
* *
* The #GstVaapiID contained in this object. * This function zero-initializes the derived object data. Also note
*/ * that this is an internal function that shall not be used outside of
g_object_class_install_property * libgstvaapi libraries.
(object_class,
PROP_ID,
gst_vaapi_param_spec_id("id",
"ID",
"The GstVaapiID contained in this object",
GST_VAAPI_ID_NONE,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
/**
* GstVaapiObject::destroy:
* @object: the object which received the signal
* *
* The ::destroy signal is emitted when an object is destroyed, * Returns: The newly allocated #GstVaapiObject
* when the user released the last reference to @object.
*/ */
object_signals[DESTROY] = g_signal_new( gpointer
"destroy", gst_vaapi_object_new(const GstVaapiObjectClass *klass, GstVaapiDisplay *display)
G_TYPE_FROM_CLASS(object_class), {
G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, const GstVaapiMiniObjectClass * const object_class =
G_STRUCT_OFFSET(GstVaapiObjectClass, destroy), GST_VAAPI_MINI_OBJECT_CLASS(klass);
NULL, NULL, GstVaapiObject *object;
g_cclosure_marshal_VOID__VOID, guint sub_size;
G_TYPE_NONE, 0
); g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), NULL);
object = (GstVaapiObject *)gst_vaapi_mini_object_new(object_class);
if (!object)
return NULL;
object->display = g_object_ref(display);
object->object_id = VA_INVALID_ID;
sub_size = object_class->size - sizeof(*object);
if (sub_size > 0)
memset(((guchar *)object) + sizeof(*object), 0, sub_size);
return object;
} }
static void /**
gst_vaapi_object_init(GstVaapiObject *object) * gst_vaapi_object_ref:
* @object: a #GstVaapiObject
*
* Atomically increases the reference count of the given @object by one.
*
* Returns: The same @object argument
*/
gpointer
gst_vaapi_object_ref(gpointer object)
{ {
GstVaapiObjectPrivate *priv = GST_VAAPI_OBJECT_GET_PRIVATE(object); return gst_vaapi_object_ref_internal(object);
}
object->priv = priv; /**
priv->display = NULL; * gst_vaapi_object_unref:
priv->id = GST_VAAPI_ID_NONE; * @object: a #GstVaapiObject
priv->is_destroying = FALSE; *
* Atomically decreases the reference count of the @object by one. If
* the reference count reaches zero, the object will be free'd.
*/
void
gst_vaapi_object_unref(gpointer object)
{
gst_vaapi_object_unref_internal(object);
}
/**
* gst_vaapi_object_replace:
* @old_object_ptr: a pointer to a #GstVaapiObject
* @new_object: a #GstVaapiObject
*
* Atomically replaces the object object held in @old_object_ptr with
* @new_object. This means that @old_object_ptr shall reference a
* valid object. However, @new_object can be NULL.
*/
void
gst_vaapi_object_replace(gpointer old_object_ptr, gpointer new_object)
{
gst_vaapi_object_replace_internal(old_object_ptr, new_object);
} }
/** /**
@ -205,7 +153,7 @@ gst_vaapi_object_get_display(GstVaapiObject *object)
{ {
g_return_val_if_fail(GST_VAAPI_IS_OBJECT(object), NULL); g_return_val_if_fail(GST_VAAPI_IS_OBJECT(object), NULL);
return object->priv->display; return GST_VAAPI_OBJECT_DISPLAY(object);
} }
/** /**
@ -253,5 +201,5 @@ gst_vaapi_object_get_id(GstVaapiObject *object)
{ {
g_return_val_if_fail(GST_VAAPI_IS_OBJECT(object), GST_VAAPI_ID_NONE); g_return_val_if_fail(GST_VAAPI_IS_OBJECT(object), GST_VAAPI_ID_NONE);
return object->priv->id; return GST_VAAPI_OBJECT_ID(object);
} }

View file

@ -28,62 +28,22 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define GST_VAAPI_TYPE_OBJECT \
(gst_vaapi_object_get_type())
#define GST_VAAPI_OBJECT(obj) \ #define GST_VAAPI_OBJECT(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \ ((GstVaapiObject *)(obj))
GST_VAAPI_TYPE_OBJECT, \
GstVaapiObject))
#define GST_VAAPI_OBJECT_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GST_VAAPI_TYPE_OBJECT, \
GstVaapiObjectClass))
#define GST_VAAPI_IS_OBJECT(obj) \ #define GST_VAAPI_IS_OBJECT(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_OBJECT)) ((obj) != NULL)
#define GST_VAAPI_IS_OBJECT_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_OBJECT))
#define GST_VAAPI_OBJECT_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), \
GST_VAAPI_TYPE_OBJECT, \
GstVaapiObjectClass))
typedef struct _GstVaapiObject GstVaapiObject; typedef struct _GstVaapiObject GstVaapiObject;
typedef struct _GstVaapiObjectPrivate GstVaapiObjectPrivate;
typedef struct _GstVaapiObjectClass GstVaapiObjectClass;
/** gpointer
* GstVaapiObject: gst_vaapi_object_ref(gpointer object);
*
* VA object base.
*/
struct _GstVaapiObject {
/*< private >*/
GObject parent_instance;
GstVaapiObjectPrivate *priv; void
}; gst_vaapi_object_unref(gpointer object);
/** void
* GstVaapiObjectClass: gst_vaapi_object_replace(gpointer old_object_ptr, gpointer new_object);
* @destroy: signal class handler for #GstVaapiObject::destroy
*
* VA object base class.
*/
struct _GstVaapiObjectClass {
/*< private >*/
GObjectClass parent_class;
/*< public >*/
void (*destroy)(GstVaapiObject *oject);
};
GType
gst_vaapi_object_get_type(void) G_GNUC_CONST;
GstVaapiDisplay * GstVaapiDisplay *
gst_vaapi_object_get_display(GstVaapiObject *object); gst_vaapi_object_get_display(GstVaapiObject *object);

View file

@ -24,15 +24,45 @@
#define GST_VAAPI_OBJECT_PRIV_H #define GST_VAAPI_OBJECT_PRIV_H
#include <gst/vaapi/gstvaapiobject.h> #include <gst/vaapi/gstvaapiobject.h>
#include "gstvaapiminiobject.h"
#include "gstvaapidisplay_priv.h"
G_BEGIN_DECLS G_BEGIN_DECLS
#define GST_VAAPI_OBJECT_GET_PRIVATE(obj) \ #define GST_VAAPI_OBJECT_CLASS(klass) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), \ ((GstVaapiObjectClass *)(klass))
GST_VAAPI_TYPE_OBJECT, \
GstVaapiObjectPrivate))
#define GST_VAAPI_OBJECT_CAST(object) ((GstVaapiObject *)(object)) #define GST_VAAPI_IS_OBJECT_CLASS(klass) \
((klass) != NULL)
#define GST_VAAPI_OBJECT_GET_CLASS(object) \
GST_VAAPI_OBJECT_CLASS(GST_VAAPI_MINI_OBJECT_GET_CLASS(object))
typedef struct _GstVaapiObjectClass GstVaapiObjectClass;
typedef void (*GstVaapiObjectInitFunc) (GstVaapiObject *object);
typedef void (*GstVaapiObjectFinalizeFunc) (GstVaapiObject *object);
#define GST_VAAPI_OBJECT_DEFINE_CLASS_WITH_CODE(TN, t_n, code) \
static inline const GstVaapiObjectClass * \
G_PASTE(t_n,_class)(void) \
{ \
static G_PASTE(TN,Class) g_class; \
static gsize g_class_init = FALSE; \
\
if (g_once_init_enter(&g_class_init)) { \
GstVaapiObjectClass * const klass = \
GST_VAAPI_OBJECT_CLASS(&g_class); \
gst_vaapi_object_class_init(klass, sizeof(TN)); \
code; \
klass->finalize = (GstVaapiObjectFinalizeFunc) \
G_PASTE(t_n,_finalize); \
g_once_init_leave(&g_class_init, TRUE); \
} \
return GST_VAAPI_OBJECT_CLASS(&g_class); \
}
#define GST_VAAPI_OBJECT_DEFINE_CLASS(TN, t_n) \
GST_VAAPI_OBJECT_DEFINE_CLASS_WITH_CODE(TN, t_n, /**/)
/** /**
* GST_VAAPI_OBJECT_DISPLAY: * GST_VAAPI_OBJECT_DISPLAY:
@ -42,7 +72,7 @@ G_BEGIN_DECLS
* This is an internal macro that does not do any run-time type check. * This is an internal macro that does not do any run-time type check.
*/ */
#define GST_VAAPI_OBJECT_DISPLAY(object) \ #define GST_VAAPI_OBJECT_DISPLAY(object) \
GST_VAAPI_OBJECT_CAST(object)->priv->display GST_VAAPI_OBJECT(object)->display
/** /**
* GST_VAAPI_OBJECT_ID: * GST_VAAPI_OBJECT_ID:
@ -52,7 +82,7 @@ G_BEGIN_DECLS
* This is an internal macro that does not do any run-time type checks. * This is an internal macro that does not do any run-time type checks.
*/ */
#define GST_VAAPI_OBJECT_ID(object) \ #define GST_VAAPI_OBJECT_ID(object) \
GST_VAAPI_OBJECT_CAST(object)->priv->id GST_VAAPI_OBJECT(object)->object_id
/** /**
* GST_VAAPI_OBJECT_DISPLAY_X11: * GST_VAAPI_OBJECT_DISPLAY_X11:
@ -152,16 +182,72 @@ G_BEGIN_DECLS
GST_VAAPI_DISPLAY_UNLOCK(GST_VAAPI_OBJECT_DISPLAY(object)) GST_VAAPI_DISPLAY_UNLOCK(GST_VAAPI_OBJECT_DISPLAY(object))
/** /**
* GstVaapiObjectPrivate: * GstVaapiObject:
* *
* VA object base. * VA object base.
*/ */
struct _GstVaapiObjectPrivate { struct _GstVaapiObject {
/*< private >*/
GstVaapiMiniObject parent_instance;
GstVaapiDisplay *display; GstVaapiDisplay *display;
GstVaapiID id; GstVaapiID object_id;
guint is_destroying : 1;
}; };
/**
* GstVaapiObjectClass:
*
* VA object base class.
*/
struct _GstVaapiObjectClass {
/*< private >*/
GstVaapiMiniObjectClass parent_class;
GstVaapiObjectInitFunc init;
GstVaapiObjectFinalizeFunc finalize;
};
void
gst_vaapi_object_class_init(GstVaapiObjectClass *klass, guint size);
gpointer
gst_vaapi_object_new(const GstVaapiObjectClass *klass,
GstVaapiDisplay *display);
/* Inline reference counting for core libgstvaapi library */
#ifdef GST_VAAPI_CORE
static inline gpointer
gst_vaapi_object_ref_internal(gpointer object)
{
return gst_vaapi_mini_object_ref(object);
}
static inline void
gst_vaapi_object_unref_internal(gpointer object)
{
gst_vaapi_mini_object_unref(object);
}
static inline void
gst_vaapi_object_replace_internal(gpointer old_object_ptr, gpointer new_object)
{
gst_vaapi_mini_object_replace((GstVaapiMiniObject **)old_object_ptr,
new_object);
}
#undef gst_vaapi_object_ref
#define gst_vaapi_object_ref(object) \
gst_vaapi_object_ref_internal((object))
#undef gst_vaapi_object_unref
#define gst_vaapi_object_unref(object) \
gst_vaapi_object_unref_internal((object))
#undef gst_vaapi_object_replace
#define gst_vaapi_object_replace(old_object_ptr, new_object) \
gst_vaapi_object_replace_internal((old_object_ptr), (new_object))
#endif
G_END_DECLS G_END_DECLS
#endif /* GST_VAAPI_OBJECT_PRIV_H */ #endif /* GST_VAAPI_OBJECT_PRIV_H */