diff --git a/ChangeLog b/ChangeLog index 2a02099c61..6369ea86e5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2005-08-01 Tim-Philipp Müller + + * gst/elements/gsttypefindelement.c: + (gst_type_find_element_have_type), + (gst_type_find_element_check_set_buffer_caps), + (gst_type_find_element_init), (stop_typefinding), + (gst_type_find_element_handle_event), + (gst_type_find_element_chain), (gst_type_find_element_getrange): + * gst/elements/gsttypefindelement.h: + Set caps on first outgoing buffer when we've found the type. + 2005-08-01 Tim-Philipp Müller * docs/gst/gstreamer-docs.sgml: diff --git a/gst/elements/gsttypefindelement.c b/gst/elements/gsttypefindelement.c index e897bd14f5..28ea098484 100644 --- a/gst/elements/gsttypefindelement.c +++ b/gst/elements/gsttypefindelement.c @@ -148,9 +148,20 @@ gst_type_find_element_have_type (GstTypeFindElement * typefind, GST_INFO_OBJECT (typefind, "found caps %" GST_PTR_FORMAT, caps); typefind->caps = gst_caps_copy (caps); + typefind->caps_changed = TRUE; gst_pad_set_caps (typefind->src, (GstCaps *) caps); } +static inline void +gst_type_find_element_check_set_buffer_caps (GstTypeFindElement * typefind, + GstBuffer * buffer) +{ + if (typefind->caps_changed && buffer != NULL) { + gst_buffer_set_caps (buffer, typefind->caps); + typefind->caps_changed = FALSE; + } +} + static void gst_type_find_element_base_init (gpointer g_class) { @@ -229,6 +240,7 @@ gst_type_find_element_init (GstTypeFindElement * typefind) typefind->mode = MODE_TYPEFIND; typefind->caps = NULL; + typefind->caps_changed = FALSE; typefind->min_probability = 1; typefind->max_probability = GST_TYPE_FIND_MAXIMUM; @@ -429,6 +441,7 @@ stop_typefinding (GstTypeFindElement * typefind) gst_buffer_unref (typefind->store); } else { typefind->mode = MODE_NORMAL; + gst_type_find_element_check_set_buffer_caps (typefind, typefind->store); gst_pad_push (typefind->src, typefind->store); } typefind->store = NULL; @@ -499,6 +512,8 @@ gst_type_find_element_handle_event (GstPad * pad, GstEvent * event) g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE], 0, entry->probability, entry->caps); stop_typefinding (typefind); + gst_type_find_element_check_set_buffer_caps (typefind, + typefind->store); gst_pad_push (typefind->src, typefind->store); typefind->store = NULL; res = gst_pad_event_default (pad, event); @@ -599,6 +614,7 @@ gst_type_find_element_chain (GstPad * pad, GstBuffer * buffer) switch (typefind->mode) { case MODE_NORMAL: + gst_type_find_element_check_set_buffer_caps (typefind, buffer); return gst_pad_push (typefind->src, buffer); case MODE_TYPEFIND:{ gboolean done = TRUE; @@ -744,10 +760,20 @@ gst_type_find_element_getrange (GstPad * srcpad, guint64 offset, guint length, GstBuffer ** buffer) { GstTypeFindElement *typefind; + GstFlowReturn ret; typefind = GST_TYPE_FIND_ELEMENT (GST_PAD_PARENT (srcpad)); - return gst_pad_pull_range (typefind->sink, offset, length, buffer); + ret = gst_pad_pull_range (typefind->sink, offset, length, buffer); + + if (typefind->caps_changed) { + if (ret == GST_FLOW_OK && buffer && *buffer) { + gst_buffer_set_caps (*buffer, typefind->caps); + typefind->caps_changed = FALSE; + } + } + + return ret; } static gboolean diff --git a/gst/elements/gsttypefindelement.h b/gst/elements/gsttypefindelement.h index 76b8e6063f..6307017924 100644 --- a/gst/elements/gsttypefindelement.h +++ b/gst/elements/gsttypefindelement.h @@ -51,6 +51,7 @@ struct _GstTypeFindElement { guint min_probability; guint max_probability; GstCaps * caps; + gboolean caps_changed; guint mode; GstBuffer * store; diff --git a/plugins/elements/gsttypefindelement.c b/plugins/elements/gsttypefindelement.c index e897bd14f5..28ea098484 100644 --- a/plugins/elements/gsttypefindelement.c +++ b/plugins/elements/gsttypefindelement.c @@ -148,9 +148,20 @@ gst_type_find_element_have_type (GstTypeFindElement * typefind, GST_INFO_OBJECT (typefind, "found caps %" GST_PTR_FORMAT, caps); typefind->caps = gst_caps_copy (caps); + typefind->caps_changed = TRUE; gst_pad_set_caps (typefind->src, (GstCaps *) caps); } +static inline void +gst_type_find_element_check_set_buffer_caps (GstTypeFindElement * typefind, + GstBuffer * buffer) +{ + if (typefind->caps_changed && buffer != NULL) { + gst_buffer_set_caps (buffer, typefind->caps); + typefind->caps_changed = FALSE; + } +} + static void gst_type_find_element_base_init (gpointer g_class) { @@ -229,6 +240,7 @@ gst_type_find_element_init (GstTypeFindElement * typefind) typefind->mode = MODE_TYPEFIND; typefind->caps = NULL; + typefind->caps_changed = FALSE; typefind->min_probability = 1; typefind->max_probability = GST_TYPE_FIND_MAXIMUM; @@ -429,6 +441,7 @@ stop_typefinding (GstTypeFindElement * typefind) gst_buffer_unref (typefind->store); } else { typefind->mode = MODE_NORMAL; + gst_type_find_element_check_set_buffer_caps (typefind, typefind->store); gst_pad_push (typefind->src, typefind->store); } typefind->store = NULL; @@ -499,6 +512,8 @@ gst_type_find_element_handle_event (GstPad * pad, GstEvent * event) g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE], 0, entry->probability, entry->caps); stop_typefinding (typefind); + gst_type_find_element_check_set_buffer_caps (typefind, + typefind->store); gst_pad_push (typefind->src, typefind->store); typefind->store = NULL; res = gst_pad_event_default (pad, event); @@ -599,6 +614,7 @@ gst_type_find_element_chain (GstPad * pad, GstBuffer * buffer) switch (typefind->mode) { case MODE_NORMAL: + gst_type_find_element_check_set_buffer_caps (typefind, buffer); return gst_pad_push (typefind->src, buffer); case MODE_TYPEFIND:{ gboolean done = TRUE; @@ -744,10 +760,20 @@ gst_type_find_element_getrange (GstPad * srcpad, guint64 offset, guint length, GstBuffer ** buffer) { GstTypeFindElement *typefind; + GstFlowReturn ret; typefind = GST_TYPE_FIND_ELEMENT (GST_PAD_PARENT (srcpad)); - return gst_pad_pull_range (typefind->sink, offset, length, buffer); + ret = gst_pad_pull_range (typefind->sink, offset, length, buffer); + + if (typefind->caps_changed) { + if (ret == GST_FLOW_OK && buffer && *buffer) { + gst_buffer_set_caps (*buffer, typefind->caps); + typefind->caps_changed = FALSE; + } + } + + return ret; } static gboolean diff --git a/plugins/elements/gsttypefindelement.h b/plugins/elements/gsttypefindelement.h index 76b8e6063f..6307017924 100644 --- a/plugins/elements/gsttypefindelement.h +++ b/plugins/elements/gsttypefindelement.h @@ -51,6 +51,7 @@ struct _GstTypeFindElement { guint min_probability; guint max_probability; GstCaps * caps; + gboolean caps_changed; guint mode; GstBuffer * store;