libs: expose GstVaapiMiniObject APIs to all backends.

Make it possible to have all libgstvaapi backends (libs) access to a
common GstVaapiMiniObject API and implementation. This is a minor step
towards full exposure when needed, but restrict it to libgstvaapi at
this time.
This commit is contained in:
Gwenole Beauchesne 2014-12-02 16:51:20 +01:00
parent c2afdb4650
commit fd775b4400
2 changed files with 56 additions and 12 deletions

View file

@ -23,7 +23,12 @@
#include <string.h>
#include "gstvaapiminiobject.h"
static void
/* Ensure those symbols are actually defined in the resulting libraries */
#undef gst_vaapi_mini_object_ref
#undef gst_vaapi_mini_object_unref
#undef gst_vaapi_mini_object_replace
void
gst_vaapi_mini_object_free (GstVaapiMiniObject * object)
{
const GstVaapiMiniObjectClass *const klass = object->object_class;
@ -116,8 +121,7 @@ gst_vaapi_mini_object_ref (GstVaapiMiniObject * object)
{
g_return_val_if_fail (object != NULL, NULL);
g_atomic_int_inc (&object->ref_count);
return object;
return gst_vaapi_mini_object_ref_internal (object);
}
/**
@ -133,8 +137,7 @@ gst_vaapi_mini_object_unref (GstVaapiMiniObject * object)
g_return_if_fail (object != NULL);
g_return_if_fail (object->ref_count > 0);
if (g_atomic_int_dec_and_test (&object->ref_count))
gst_vaapi_mini_object_free (object);
gst_vaapi_mini_object_unref_internal (object);
}
/**
@ -160,12 +163,12 @@ gst_vaapi_mini_object_replace (GstVaapiMiniObject ** old_object_ptr,
return;
if (new_object)
gst_vaapi_mini_object_ref (new_object);
gst_vaapi_mini_object_ref_internal (new_object);
while (!g_atomic_pointer_compare_and_exchange ((gpointer *) old_object_ptr,
old_object, new_object))
old_object = g_atomic_pointer_get ((gpointer *) old_object_ptr);
if (old_object)
gst_vaapi_mini_object_unref (old_object);
gst_vaapi_mini_object_unref_internal (old_object);
}

View file

@ -142,27 +142,68 @@ struct _GstVaapiMiniObjectClass
GDestroyNotify finalize;
};
G_GNUC_INTERNAL
GstVaapiMiniObject *
gst_vaapi_mini_object_new (const GstVaapiMiniObjectClass * object_class);
G_GNUC_INTERNAL
GstVaapiMiniObject *
gst_vaapi_mini_object_new0 (const GstVaapiMiniObjectClass * object_class);
G_GNUC_INTERNAL
GstVaapiMiniObject *
gst_vaapi_mini_object_ref (GstVaapiMiniObject * object);
G_GNUC_INTERNAL
void
gst_vaapi_mini_object_unref (GstVaapiMiniObject * object);
G_GNUC_INTERNAL
void
gst_vaapi_mini_object_replace (GstVaapiMiniObject ** old_object_ptr,
GstVaapiMiniObject * new_object);
#ifdef IN_LIBGSTVAAPI_CORE
#undef gst_vaapi_mini_object_ref
#define gst_vaapi_mini_object_ref(object) \
gst_vaapi_mini_object_ref_internal (object)
#undef gst_vaapi_mini_object_unref
#define gst_vaapi_mini_object_unref(object) \
gst_vaapi_mini_object_unref_internal (object)
G_GNUC_INTERNAL
void
gst_vaapi_mini_object_free (GstVaapiMiniObject * object);
/**
* gst_vaapi_mini_object_ref_internal:
* @object: a #GstVaapiMiniObject
*
* Atomically increases the reference count of the given @object by one.
* This is an internal function that does not do any run-time type check.
*
* Returns: The same @object argument
*/
static inline GstVaapiMiniObject *
gst_vaapi_mini_object_ref_internal (GstVaapiMiniObject * object)
{
g_atomic_int_inc (&object->ref_count);
return object;
}
/**
* gst_vaapi_mini_object_unref_internal:
* @object: a #GstVaapiMiniObject
*
* Atomically decreases the reference count of the @object by one. If
* the reference count reaches zero, the object will be free'd.
*
* This is an internal function that does not do any run-time type check.
*/
static inline void
gst_vaapi_mini_object_unref_internal (GstVaapiMiniObject * object)
{
if (g_atomic_int_dec_and_test (&object->ref_count))
gst_vaapi_mini_object_free (object);
}
#endif
G_END_DECLS
#endif /* GST_VAAPI_MINI_OBJECT_H */