From: Wim Taymans Date: Thu, 2 Jun 2011 11:18:39 +0000 (+0200) Subject: caps: remove some custom refcounting methods X-Git-Tag: RELEASE-0.11.0~197 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9553ea1c07f14ee595a056f35e33f9f23104bcd7;p=platform%2Fupstream%2Fgstreamer.git caps: remove some custom refcounting methods Remove some custom made refcounting methods and use the miniobject ones instead. --- diff --git a/gst/gstcaps.c b/gst/gstcaps.c index 56ca30a..419aa7b 100644 --- a/gst/gstcaps.c +++ b/gst/gstcaps.c @@ -309,43 +309,6 @@ gst_caps_new_full_valist (GstStructure * structure, va_list var_args) return caps; } -/** - * gst_caps_make_writable: - * @caps: (transfer full): the #GstCaps to make writable - * - * Returns a writable copy of @caps. - * - * If there is only one reference count on @caps, the caller must be the owner, - * and so this function will return the caps object unchanged. If on the other - * hand there is more than one reference on the object, a new caps object will - * be returned. The caller's reference on @caps will be removed, and instead the - * caller will own a reference to the returned object. - * - * In short, this function unrefs the caps in the argument and refs the caps - * that it returns. Don't access the argument after calling this function. See - * also: gst_caps_ref(). - * - * Returns: (transfer full): the same #GstCaps object. - */ -GstCaps * -gst_caps_make_writable (GstCaps * caps) -{ - GstCaps *copy; - - g_return_val_if_fail (caps != NULL, NULL); - - /* we are the only instance reffing this caps */ - if (IS_WRITABLE (caps)) - return caps; - - /* else copy */ - GST_CAT_DEBUG (GST_CAT_PERFORMANCE, "copy caps"); - copy = _gst_caps_copy (caps); - gst_caps_unref (caps); - - return copy; -} - GType gst_static_caps_get_type (void) { @@ -1783,40 +1746,6 @@ gst_caps_do_simplify (GstCaps * caps) /* utility */ /** - * gst_caps_replace: - * @caps: (inout) (transfer full): a pointer to #GstCaps - * @newcaps: a #GstCaps to replace *caps - * - * Replaces *caps with @newcaps. Unrefs the #GstCaps in the location - * pointed to by @caps, if applicable, then modifies @caps to point to - * @newcaps. An additional ref on @newcaps is taken. - * - * This function does not take any locks so you might want to lock - * the object owning @caps pointer. - */ -void -gst_caps_replace (GstCaps ** caps, GstCaps * newcaps) -{ - GstCaps *oldcaps; - - g_return_if_fail (caps != NULL); - - oldcaps = *caps; - - GST_CAT_TRACE (GST_CAT_REFCOUNTING, "%p, %p -> %p", caps, oldcaps, newcaps); - - if (newcaps != oldcaps) { - if (newcaps) - gst_caps_ref (newcaps); - - *caps = newcaps; - - if (oldcaps) - gst_caps_unref (oldcaps); - } -} - -/** * gst_caps_to_string: * @caps: a #GstCaps * diff --git a/gst/gstcaps.h b/gst/gstcaps.h index 126b800..78aa277 100644 --- a/gst/gstcaps.h +++ b/gst/gstcaps.h @@ -254,6 +254,56 @@ gst_caps_copy (const GstCaps * caps) return GST_CAPS (gst_mini_object_copy (GST_MINI_OBJECT_CAST (caps))); } +/** + * gst_caps_is_writable: + * @caps: a #GstCaps + * + * Tests if you can safely modify @caps. It is only safe to modify caps when + * there is only one owner of the caps - ie, the refcount is 1. + */ +#define gst_caps_is_writable(caps) gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (caps)) + +/** + * gst_caps_make_writable: + * @caps: (transfer full): a #GstCaps + * + * Returns a writable copy of @caps. + * + * If there is only one reference count on @caps, the caller must be the owner, + * and so this function will return the caps object unchanged. If on the other + * hand there is more than one reference on the object, a new caps object will + * be returned. The caller's reference on @caps will be removed, and instead the + * caller will own a reference to the returned object. + * + * In short, this function unrefs the caps in the argument and refs the caps + * that it returns. Don't access the argument after calling this function. See + * also: gst_caps_ref(). + * + * Returns: (transfer full): a writable caps which may or may not be the + * same as @caps + */ +#define gst_caps_make_writable(caps) GST_CAPS_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (caps))) + +/** + * gst_caps_replace: + * @ocaps: (inout) (transfer full): pointer to a pointer to a #GstCaps to be + * replaced. + * @ncaps: (transfer none) (allow-none): pointer to a #GstCaps that will + * replace the caps pointed to by @ocaps. + * + * Modifies a pointer to a #GstCaps to point to a different #GstCaps. The + * modification is done atomically (so this is useful for ensuring thread safety + * in some cases), and the reference counts are updated appropriately (the old + * caps is unreffed, the new is reffed). + * + * Either @ncaps or the #GstCaps pointed to by @ocaps may be NULL. + */ +#define gst_caps_replace(ocaps,ncaps) \ +G_STMT_START { \ + GstCaps **___ocapsaddr = (GstCaps **)(ocaps); \ + gst_mini_object_replace ((GstMiniObject **)___ocapsaddr, \ + GST_MINI_OBJECT_CAST (ncaps)); \ +} G_STMT_END /** * GstCaps: @@ -298,9 +348,6 @@ GstCaps * gst_caps_new_full (GstStructure *struct1, ...) GstCaps * gst_caps_new_full_valist (GstStructure *structure, va_list var_args); -/* reference counting */ -GstCaps * gst_caps_make_writable (GstCaps *caps) G_GNUC_WARN_UNUSED_RESULT; - GType gst_static_caps_get_type (void); GstCaps * gst_static_caps_get (GstStaticCaps *static_caps); @@ -362,8 +409,6 @@ GstCaps * gst_caps_normalize (const GstCaps *caps); gboolean gst_caps_do_simplify (GstCaps *caps); /* utility */ -void gst_caps_replace (GstCaps **caps, - GstCaps *newcaps); gchar * gst_caps_to_string (const GstCaps *caps); GstCaps * gst_caps_from_string (const gchar *string);