diff --git a/gst-libs/gst/vaapi/gstvaapiminiobject.c b/gst-libs/gst/vaapi/gstvaapiminiobject.c index 11fb769758..f146d0faf3 100644 --- a/gst-libs/gst/vaapi/gstvaapiminiobject.c +++ b/gst-libs/gst/vaapi/gstvaapiminiobject.c @@ -23,7 +23,12 @@ #include #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); } diff --git a/gst-libs/gst/vaapi/gstvaapiminiobject.h b/gst-libs/gst/vaapi/gstvaapiminiobject.h index 7131a9d6c6..562c5fc472 100644 --- a/gst-libs/gst/vaapi/gstvaapiminiobject.h +++ b/gst-libs/gst/vaapi/gstvaapiminiobject.h @@ -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 */