From ee13415b389d5fceb91a6b330f375acc5b5fce22 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 20 Apr 2005 09:10:42 +0000 Subject: [PATCH] gst/: Make gst_caps_replace() work like other _replace() functions. Original commit message from CVS: * gst/base/gstbasesink.c: (gst_basesink_base_init), (gst_basesink_pad_getcaps), (gst_basesink_init), (gst_basesink_chain_unlocked): * gst/base/gsttypefindhelper.c: (helper_find_suggest), (gst_type_find_helper): * gst/elements/gsttypefindelement.c: (gst_type_find_element_have_type), (gst_type_find_element_init), (stop_typefinding), (gst_type_find_element_handle_event), (find_suggest), (gst_type_find_element_chain), (gst_type_find_element_checkgetrange), (gst_type_find_element_getrange), (do_typefind), (gst_type_find_element_activate): * gst/gstbuffer.c: (_gst_buffer_sub_free), (gst_buffer_default_free), (gst_buffer_default_copy), (gst_buffer_set_caps): * gst/gstcaps.c: (gst_caps_ref), (gst_caps_unref), (gst_caps_replace): * gst/gstmessage.c: (gst_message_new), (gst_message_new_state_changed): * gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active), (gst_pad_set_checkgetrange_function), (gst_pad_link_prepare_filtered), (gst_pad_relink_filtered), (gst_pad_set_caps), (gst_pad_check_pull_range), (gst_pad_pull_range), (gst_static_pad_template_get_caps): * gst/gstpad.h: * gst/gsttypefind.c: (gst_type_find_register): Make gst_caps_replace() work like other _replace() functions. Use _caps_replace() where possible. Make sure _message_new() initialises its field. Add gst_static_pad_template_get_caps() --- ChangeLog | 34 +++++++++++++++++++++++++++ gst/base/gstbasesink.c | 2 +- gst/base/gsttypefindhelper.c | 5 +++- gst/elements/gsttypefindelement.c | 2 +- gst/gstbuffer.c | 23 ++++-------------- gst/gstcaps.c | 18 ++++++++++---- gst/gstmessage.c | 11 +++++---- gst/gstpad.c | 25 ++++++++++++++++---- gst/gstpad.h | 1 + gst/gsttypefind.c | 2 +- libs/gst/base/gstbasesink.c | 2 +- libs/gst/base/gsttypefindhelper.c | 5 +++- plugins/elements/gsttypefindelement.c | 2 +- 13 files changed, 95 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index 57f37bd1e8..ef31397704 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,37 @@ +2005-04-20 Wim Taymans + + * gst/base/gstbasesink.c: (gst_basesink_base_init), + (gst_basesink_pad_getcaps), (gst_basesink_init), + (gst_basesink_chain_unlocked): + * gst/base/gsttypefindhelper.c: (helper_find_suggest), + (gst_type_find_helper): + * gst/elements/gsttypefindelement.c: + (gst_type_find_element_have_type), (gst_type_find_element_init), + (stop_typefinding), (gst_type_find_element_handle_event), + (find_suggest), (gst_type_find_element_chain), + (gst_type_find_element_checkgetrange), + (gst_type_find_element_getrange), (do_typefind), + (gst_type_find_element_activate): + * gst/gstbuffer.c: (_gst_buffer_sub_free), + (gst_buffer_default_free), (gst_buffer_default_copy), + (gst_buffer_set_caps): + * gst/gstcaps.c: (gst_caps_ref), (gst_caps_unref), + (gst_caps_replace): + * gst/gstmessage.c: (gst_message_new), + (gst_message_new_state_changed): + * gst/gstpad.c: (gst_pad_set_active), (gst_pad_peer_set_active), + (gst_pad_set_checkgetrange_function), + (gst_pad_link_prepare_filtered), (gst_pad_relink_filtered), + (gst_pad_set_caps), (gst_pad_check_pull_range), + (gst_pad_pull_range), (gst_static_pad_template_get_caps): + * gst/gstpad.h: + * gst/gsttypefind.c: (gst_type_find_register): + Make gst_caps_replace() work like other _replace() functions. + Use _caps_replace() where possible. + Make sure _message_new() initialises its field. + Add gst_static_pad_template_get_caps() + + 2005-04-18 Andy Wingo * gst/elements/gstfakesrc.c: s/ARG_/PROP_/. diff --git a/gst/base/gstbasesink.c b/gst/base/gstbasesink.c index 6bc6ce0bea..4720e357b4 100644 --- a/gst/base/gstbasesink.c +++ b/gst/base/gstbasesink.c @@ -669,7 +669,7 @@ gst_basesink_chain_unlocked (GstPad * pad, GstBuffer * buf) result = gst_basesink_finish_preroll (basesink, pad, buf); - DEBUG ("chain_unlocked %p after\n", basesink); + DEBUG ("chain_unlocked %p after, result %d\n", basesink, result); switch (result) { case PREROLL_QUEUEING: diff --git a/gst/base/gsttypefindhelper.c b/gst/base/gsttypefindhelper.c index 6aa44b4a6f..f0805394b9 100644 --- a/gst/base/gsttypefindhelper.c +++ b/gst/base/gsttypefindhelper.c @@ -90,7 +90,10 @@ helper_find_suggest (gpointer data, guint probability, const GstCaps * caps) GstTypeFindHelper *find = (GstTypeFindHelper *) data; if (probability > find->best_probability) { - gst_caps_replace (&find->caps, gst_caps_copy (caps)); + GstCaps *copy = gst_caps_copy (caps); + + gst_caps_replace (&find->caps, copy); + gst_caps_unref (copy); find->best_probability = probability; } } diff --git a/gst/elements/gsttypefindelement.c b/gst/elements/gsttypefindelement.c index a0e9ae9308..1cce1ab627 100644 --- a/gst/elements/gsttypefindelement.c +++ b/gst/elements/gsttypefindelement.c @@ -581,7 +581,7 @@ find_suggest (gpointer data, guint probability, const GstCaps * caps) GST_PLUGIN_FEATURE_NAME (entry->factory), probability, caps); if (((gint) probability) > entry->probability) { entry->probability = probability; - gst_caps_replace (&entry->caps, gst_caps_copy (caps)); + gst_caps_replace (&entry->caps, (GstCaps *) caps); } } diff --git a/gst/gstbuffer.c b/gst/gstbuffer.c index fd3feadd26..8a1171407b 100644 --- a/gst/gstbuffer.c +++ b/gst/gstbuffer.c @@ -74,8 +74,7 @@ _gst_buffer_sub_free (GstBuffer * buffer) GST_BUFFER_DATA (buffer) = NULL; GST_BUFFER_SIZE (buffer) = 0; - if (GST_BUFFER_CAPS (buffer)) - gst_caps_unref (GST_BUFFER_CAPS (buffer)); + gst_caps_replace (&GST_BUFFER_CAPS (buffer), NULL); _GST_DATA_DISPOSE (GST_DATA (buffer)); @@ -106,8 +105,7 @@ gst_buffer_default_free (GstBuffer * buffer) /* set to safe values */ GST_BUFFER_DATA (buffer) = NULL; GST_BUFFER_SIZE (buffer) = 0; - if (GST_BUFFER_CAPS (buffer)) - gst_caps_unref (GST_BUFFER_CAPS (buffer)); + gst_caps_replace (&GST_BUFFER_CAPS (buffer), NULL); _GST_DATA_DISPOSE (GST_DATA (buffer)); @@ -167,6 +165,8 @@ gst_buffer_default_copy (GstBuffer * buffer) GST_BUFFER_PRIVATE (copy) = NULL; if (GST_BUFFER_CAPS (buffer)) GST_BUFFER_CAPS (copy) = gst_caps_ref (GST_BUFFER_CAPS (buffer)); + else + GST_BUFFER_CAPS (copy) = NULL; return copy; } @@ -297,22 +297,9 @@ gst_buffer_get_caps (GstBuffer * buffer) void gst_buffer_set_caps (GstBuffer * buffer, GstCaps * caps) { - GstCaps *oldcaps; - g_return_if_fail (buffer != NULL); - /* get old caps */ - oldcaps = GST_BUFFER_CAPS (buffer); - /* ref new caps if any */ - if (caps) - caps = gst_caps_ref (caps); - /* set caps */ - GST_BUFFER_CAPS (buffer) = caps; - - /* unref old caps if any */ - if (oldcaps) { - gst_caps_unref (oldcaps); - } + gst_caps_replace (&GST_BUFFER_CAPS (buffer), caps); } /** diff --git a/gst/gstcaps.c b/gst/gstcaps.c index 300003f53c..2d9b86f721 100644 --- a/gst/gstcaps.c +++ b/gst/gstcaps.c @@ -27,7 +27,7 @@ #include "gstatomic_impl.h" #include -//#define DEBUG_REFCOUNT +/* #define DEBUG_REFCOUNT */ #define CAPS_POISON(caps) G_STMT_START{ \ if (caps) { \ @@ -311,6 +311,7 @@ gst_caps_ref (GstCaps * caps) GST_CAT_LOG (GST_CAT_CAPS, "%p %d->%d", caps, GST_CAPS_REFCOUNT_VALUE (caps), GST_CAPS_REFCOUNT_VALUE (caps) + 1); #endif + g_return_val_if_fail (GST_CAPS_REFCOUNT_VALUE (caps) > 0, NULL); gst_atomic_int_inc (&caps->refcount); @@ -328,13 +329,14 @@ void gst_caps_unref (GstCaps * caps) { g_return_if_fail (caps != NULL); - g_return_if_fail (GST_CAPS_REFCOUNT_VALUE (caps) > 0); #ifdef DEBUG_REFCOUNT GST_CAT_LOG (GST_CAT_CAPS, "%p %d->%d", caps, GST_CAPS_REFCOUNT_VALUE (caps), GST_CAPS_REFCOUNT_VALUE (caps) - 1); #endif + g_return_if_fail (GST_CAPS_REFCOUNT_VALUE (caps) > 0); + /* if we ended up with the refcount at zero, free the caps */ if (gst_atomic_int_dec_and_test (&caps->refcount)) { _gst_caps_free (caps); @@ -1472,14 +1474,22 @@ gst_caps_load_thyself (xmlNodePtr parent) void gst_caps_replace (GstCaps ** caps, GstCaps * newcaps) { + GstCaps *oldcaps; + #if 0 /* disable this, since too many plugins rely on undefined behavior */ #ifdef USE_POISONING //if (newcaps) CAPS_POISON (newcaps); #endif #endif - if (*caps) - gst_caps_unref (*caps); + oldcaps = *caps; + + if (newcaps) + gst_caps_ref (newcaps); + *caps = newcaps; + + if (oldcaps) + gst_caps_unref (oldcaps); } /** diff --git a/gst/gstmessage.c b/gst/gstmessage.c index f48c386b41..90616ea87a 100644 --- a/gst/gstmessage.c +++ b/gst/gstmessage.c @@ -143,9 +143,11 @@ gst_message_new (GstMessageType type, GstObject * src) GST_MESSAGE_TYPE (message) = type; GST_MESSAGE_TIMESTAMP (message) = G_GINT64_CONSTANT (0); if (src) { - gst_object_ref (src); - GST_MESSAGE_SRC (message) = src; + GST_MESSAGE_SRC (message) = gst_object_ref (src); + } else { + GST_MESSAGE_SRC (message) = NULL; } + message->structure = NULL; return message; } @@ -266,8 +268,9 @@ gst_message_new_state_changed (GstObject * src, GstElementState old, GstStructure *s; message = gst_message_new (GST_MESSAGE_STATE_CHANGED, src); - s = gst_structure_new ("GstMessageError", "old-state", G_TYPE_INT, old, - "new-state", G_TYPE_INT, new, NULL); + + s = gst_structure_new ("GstMessageError", "old-state", G_TYPE_INT, (gint) old, + "new-state", G_TYPE_INT, (gint) new, NULL); message->structure = s; return message; diff --git a/gst/gstpad.c b/gst/gstpad.c index 27cc978d05..8199b6cb3c 100644 --- a/gst/gstpad.c +++ b/gst/gstpad.c @@ -1459,10 +1459,10 @@ gst_pad_link_prepare_filtered (GstPad * srcpad, GstPad * sinkpad, GstCaps *filtercopy; filtercopy = gst_caps_copy (filtercaps); - filtercopy = gst_caps_ref (filtercopy); gst_caps_replace (&GST_PAD_APPFILTER (realsrc), filtercopy); gst_caps_replace (&GST_PAD_APPFILTER (realsink), filtercopy); + gst_caps_unref (filtercopy); } else { gst_caps_replace (&GST_PAD_APPFILTER (realsrc), NULL); gst_caps_replace (&GST_PAD_APPFILTER (realsink), NULL); @@ -1776,10 +1776,10 @@ gst_pad_relink_filtered (GstPad * srcpad, GstPad * sinkpad, GstCaps *filtercopy; filtercopy = gst_caps_copy (filtercaps); - filtercopy = gst_caps_ref (filtercopy); gst_caps_replace (&GST_PAD_APPFILTER (realsrc), filtercopy); gst_caps_replace (&GST_PAD_APPFILTER (realsink), filtercopy); + gst_caps_unref (filtercopy); } else { gst_caps_replace (&GST_PAD_APPFILTER (realsrc), NULL); gst_caps_replace (&GST_PAD_APPFILTER (realsink), NULL); @@ -2155,8 +2155,8 @@ gst_pad_set_caps (GstPad * pad, GstCaps * caps) } } - if (GST_PAD_CAPS (pad)) - gst_caps_unref (GST_PAD_CAPS (pad)); + if (GST_RPAD_CAPS (pad)) + gst_caps_unref (GST_RPAD_CAPS (pad)); if (caps) caps = gst_caps_ref (caps); @@ -3312,6 +3312,23 @@ gst_pad_template_new (const gchar * name_template, return new; } +/** + * gst_static_pad_template_get_caps: + * @templ: a #GstStaticPadTemplate to get capabilities of. + * + * Gets the capabilities of the static pad template. + * + * Returns: the #GstCaps of the static pad template. If you need to keep a + * reference to the caps, take a ref (see gst_caps_ref ()). + */ +GstCaps * +gst_static_pad_template_get_caps (GstStaticPadTemplate * templ) +{ + g_return_val_if_fail (templ, NULL); + + return (GstCaps *) gst_static_caps_get (&templ->static_caps); +} + /** * gst_pad_template_get_caps: * @templ: a #GstPadTemplate to get capabilities of. diff --git a/gst/gstpad.h b/gst/gstpad.h index 97b8a141bc..95e7d0d0d2 100644 --- a/gst/gstpad.h +++ b/gst/gstpad.h @@ -601,6 +601,7 @@ GstPadTemplate* gst_pad_template_new (const gchar *name_template, GstCaps *caps); GstPadTemplate * gst_static_pad_template_get (GstStaticPadTemplate *pad_template); +GstCaps* gst_static_pad_template_get_caps (GstStaticPadTemplate *templ); GstCaps* gst_pad_template_get_caps (GstPadTemplate *templ); #ifndef GST_DISABLE_LOADSAVE diff --git a/gst/gsttypefind.c b/gst/gsttypefind.c index fcb9058b1f..1ba77e8ac6 100644 --- a/gst/gsttypefind.c +++ b/gst/gsttypefind.c @@ -249,7 +249,7 @@ gst_type_find_register (GstPlugin * plugin, const gchar * name, guint rank, g_strfreev (factory->extensions); factory->extensions = g_strdupv (extensions); - gst_caps_replace (&factory->caps, gst_caps_copy (possible_caps)); + gst_caps_replace (&factory->caps, (GstCaps *) possible_caps); factory->function = func; factory->user_data = data; diff --git a/libs/gst/base/gstbasesink.c b/libs/gst/base/gstbasesink.c index 6bc6ce0bea..4720e357b4 100644 --- a/libs/gst/base/gstbasesink.c +++ b/libs/gst/base/gstbasesink.c @@ -669,7 +669,7 @@ gst_basesink_chain_unlocked (GstPad * pad, GstBuffer * buf) result = gst_basesink_finish_preroll (basesink, pad, buf); - DEBUG ("chain_unlocked %p after\n", basesink); + DEBUG ("chain_unlocked %p after, result %d\n", basesink, result); switch (result) { case PREROLL_QUEUEING: diff --git a/libs/gst/base/gsttypefindhelper.c b/libs/gst/base/gsttypefindhelper.c index 6aa44b4a6f..f0805394b9 100644 --- a/libs/gst/base/gsttypefindhelper.c +++ b/libs/gst/base/gsttypefindhelper.c @@ -90,7 +90,10 @@ helper_find_suggest (gpointer data, guint probability, const GstCaps * caps) GstTypeFindHelper *find = (GstTypeFindHelper *) data; if (probability > find->best_probability) { - gst_caps_replace (&find->caps, gst_caps_copy (caps)); + GstCaps *copy = gst_caps_copy (caps); + + gst_caps_replace (&find->caps, copy); + gst_caps_unref (copy); find->best_probability = probability; } } diff --git a/plugins/elements/gsttypefindelement.c b/plugins/elements/gsttypefindelement.c index a0e9ae9308..1cce1ab627 100644 --- a/plugins/elements/gsttypefindelement.c +++ b/plugins/elements/gsttypefindelement.c @@ -581,7 +581,7 @@ find_suggest (gpointer data, guint probability, const GstCaps * caps) GST_PLUGIN_FEATURE_NAME (entry->factory), probability, caps); if (((gint) probability) > entry->probability) { entry->probability = probability; - gst_caps_replace (&entry->caps, gst_caps_copy (caps)); + gst_caps_replace (&entry->caps, (GstCaps *) caps); } }