From cfdcc450caa5d17e2a7bbe50867e1b9f0fe20e6f Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 18 Jul 2005 10:53:03 +0000 Subject: [PATCH] examples/seeking/seek.c: Updated seek example. Original commit message from CVS: * examples/seeking/seek.c: (make_vorbis_theora_pipeline), (query_rates), (query_positions_elems), (query_positions_pads), (do_seek), (seek_cb), (stop_seek): Updated seek example. * gst/playback/gstdecodebin.c: (remove_element_chain), (unlinked): * gst/playback/gstplaybasebin.c: (queue_threshold_reached), (queue_out_of_data), (gen_preroll_element), (new_decoded_pad): * gst/playback/gstplaybin.c: (add_sink): * gst/playback/gststreaminfo.c: (gst_stream_info_dispose), (gst_stream_info_set_mute): Some refcount leak fixes. --- ChangeLog | 15 +++++++++++++++ examples/seeking/seek.c | 13 +++++++++++-- gst/playback/gstdecodebin.c | 22 ++++++++++++---------- gst/playback/gstplaybasebin.c | 8 ++++---- gst/playback/gstplaybin.c | 13 +++++++++---- gst/playback/gststreaminfo.c | 30 ++++++++++++++++++------------ tests/examples/seek/seek.c | 13 +++++++++++-- 7 files changed, 80 insertions(+), 34 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5cc7124b48..df51374ded 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2005-07-18 Wim Taymans + + * examples/seeking/seek.c: (make_vorbis_theora_pipeline), + (query_rates), (query_positions_elems), (query_positions_pads), + (do_seek), (seek_cb), (stop_seek): + Updated seek example. + + * gst/playback/gstdecodebin.c: (remove_element_chain), (unlinked): + * gst/playback/gstplaybasebin.c: (queue_threshold_reached), + (queue_out_of_data), (gen_preroll_element), (new_decoded_pad): + * gst/playback/gstplaybin.c: (add_sink): + * gst/playback/gststreaminfo.c: (gst_stream_info_dispose), + (gst_stream_info_set_mute): + Some refcount leak fixes. + 2005-07-16 Wim Taymans * gst-libs/gst/audio/gstbaseaudiosink.c: diff --git a/examples/seeking/seek.c b/examples/seeking/seek.c index e14bb685a8..8e07251c33 100644 --- a/examples/seeking/seek.c +++ b/examples/seeking/seek.c @@ -1005,7 +1005,9 @@ do_seek (GtkWidget * widget) static void seek_cb (GtkWidget * widget) { -#ifdef SCRUB +#ifndef SCRUB + GTimeVal timeval; +#else /* If the timer hasn't expired yet, then the pipeline is running */ if (seek_timeout_id != 0) { gst_element_set_state (pipeline, GST_STATE_PAUSED); @@ -1014,6 +1016,12 @@ seek_cb (GtkWidget * widget) do_seek (widget); +#ifndef SCRUB + /* wait for preroll */ + GST_TIME_TO_TIMEVAL (50 * GST_MSECOND, timeval); + gst_element_get_state (pipeline, NULL, NULL, &timeval); +#endif + #ifdef SCRUB gst_element_set_state (pipeline, GST_STATE_PLAYING); @@ -1047,8 +1055,9 @@ stop_seek (GtkWidget * widget, gpointer user_data) gtk_timeout_remove (seek_timeout_id); seek_timeout_id = 0; /* Still scrubbing, so the pipeline is already playing */ - } else + } else { gst_element_set_state (pipeline, GST_STATE_PLAYING); + } update_id = gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); diff --git a/gst/playback/gstdecodebin.c b/gst/playback/gstdecodebin.c index d7e03f9e50..91d15757fd 100644 --- a/gst/playback/gstdecodebin.c +++ b/gst/playback/gstdecodebin.c @@ -741,16 +741,18 @@ remove_element_chain (GstDecodeBin * decode_bin, GstPad * pad) GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (peer)); { - GstElement *parent = gst_pad_get_parent (peer); + GstObject *parent = gst_pad_get_parent (peer); if (parent) { - if (parent != GST_ELEMENT (decode_bin)) { - GST_DEBUG_OBJECT (decode_bin, "dead end pad %s:%s", - GST_DEBUG_PAD_NAME (peer)); - } else { - GST_DEBUG_OBJECT (decode_bin, "recursing element %s on pad %s:%s", - GST_ELEMENT_NAME (elem), GST_DEBUG_PAD_NAME (pad)); - remove_element_chain (decode_bin, peer); + if (GST_IS_ELEMENT (parent)) { + if (parent != GST_OBJECT (decode_bin)) { + GST_DEBUG_OBJECT (decode_bin, "dead end pad %s:%s", + GST_DEBUG_PAD_NAME (peer)); + } else { + GST_DEBUG_OBJECT (decode_bin, "recursing element %s on pad %s:%s", + GST_ELEMENT_NAME (elem), GST_DEBUG_PAD_NAME (pad)); + remove_element_chain (decode_bin, peer); + } } gst_object_unref (parent); } @@ -834,8 +836,8 @@ unlinked (GstPad * pad, GstPad * peerpad, GstDecodeBin * decode_bin) /* inactivate pad */ gst_pad_set_active (pad, GST_ACTIVATE_NONE); - element = gst_pad_get_parent (pad); - peer = gst_pad_get_parent (peerpad); + element = gst_pad_get_parent_element (pad); + peer = gst_pad_get_parent_element (peerpad); if (!is_our_kid (peer, decode_bin)) goto exit; diff --git a/gst/playback/gstplaybasebin.c b/gst/playback/gstplaybasebin.c index 6536f1d562..ae96dab082 100644 --- a/gst/playback/gstplaybasebin.c +++ b/gst/playback/gstplaybasebin.c @@ -499,7 +499,7 @@ queue_threshold_reached (GstElement * queue, GstPlayBaseBin * play_base_bin) g_object_set_data (G_OBJECT (queue), "probe", NULL); gst_pad_remove_buffer_probe (sinkpad, G_CALLBACK (check_queue), queue); - g_object_unref (G_OBJECT (sinkpad)); + gst_object_unref (sinkpad); } } @@ -524,7 +524,7 @@ queue_out_of_data (GstElement * queue, GstPlayBaseBin * play_base_bin) GST_DEBUG_OBJECT (play_base_bin, "Re-attaching buffering probe to pad %s:%s", GST_DEBUG_PAD_NAME (sinkpad), sinkpad); - g_object_unref (G_OBJECT (sinkpad)); + gst_object_unref (sinkpad); fill_buffer (play_base_bin, 0); } @@ -596,7 +596,7 @@ gen_preroll_element (GstPlayBaseBin * play_base_bin, gst_pad_add_buffer_probe (sinkpad, G_CALLBACK (check_queue), preroll); GST_DEBUG_OBJECT (play_base_bin, "Attaching probe to pad %s:%s (%p)", GST_DEBUG_PAD_NAME (sinkpad), sinkpad); - g_object_unref (G_OBJECT (sinkpad)); + gst_object_unref (sinkpad); g_object_set_data (G_OBJECT (preroll), "pbb", play_base_bin); g_object_set_data (G_OBJECT (preroll), "probe", (gpointer) 0x1); @@ -956,7 +956,7 @@ new_decoded_pad (GstElement * element, GstPad * pad, gboolean last, /* keep a ref to the signal id so that we can disconnect the signal callback */ g_object_set_data (G_OBJECT (sinkpad), "unlinked_id", GINT_TO_POINTER (sig)); gst_pad_link (pad, sinkpad); - g_object_unref (G_OBJECT (sinkpad)); + gst_object_unref (sinkpad); /* add the stream to the list */ gst_caps_unref (caps); diff --git a/gst/playback/gstplaybin.c b/gst/playback/gstplaybin.c index 50c0eae164..9647fbca97 100644 --- a/gst/playback/gstplaybin.c +++ b/gst/playback/gstplaybin.c @@ -717,7 +717,7 @@ add_sink (GstPlayBin * play_bin, GstElement * sink, GstPad * srcpad) { GstPad *sinkpad; GstPadLinkReturn res; - GstElement *parent; + GstObject *parent; gst_bin_add (GST_BIN (play_bin), sink); @@ -726,10 +726,15 @@ add_sink (GstPlayBin * play_bin, GstElement * sink, GstPad * srcpad) res = gst_pad_link (srcpad, sinkpad); gst_object_unref (sinkpad); + /* this is only for debugging */ parent = gst_pad_get_parent (srcpad); - GST_DEBUG ("Adding sink with state %d (parent: %d, peer: %d)\n", - GST_STATE (sink), GST_STATE (play_bin), GST_STATE (parent)); - gst_object_unref (parent); + if (parent) { + if (GST_IS_ELEMENT (parent)) { + GST_DEBUG ("Adding sink with state %d (parent: %d, peer: %d)\n", + GST_STATE (sink), GST_STATE (play_bin), GST_STATE (parent)); + } + gst_object_unref (parent); + } /* try to link the pad of the sink to the stream */ if (res < 0) { diff --git a/gst/playback/gststreaminfo.c b/gst/playback/gststreaminfo.c index da2a4aa8bd..1c70974a6a 100644 --- a/gst/playback/gststreaminfo.c +++ b/gst/playback/gststreaminfo.c @@ -234,14 +234,16 @@ gst_stream_info_dispose (GObject * object) stream_info = GST_STREAM_INFO (object); if (stream_info->object) { - GstElement *parent; + GstObject *parent; parent = gst_pad_get_parent ((GstPad *) GST_PAD_CAST (stream_info->object)); if (parent != NULL) { - g_signal_handlers_disconnect_by_func (parent, - G_CALLBACK (stream_info_change_state), stream_info); - g_object_unref (G_OBJECT (parent)); + if (GST_IS_ELEMENT (parent)) { + g_signal_handlers_disconnect_by_func (parent, + G_CALLBACK (stream_info_change_state), stream_info); + } + gst_object_unref (parent); } gst_object_unref (stream_info->object); @@ -291,7 +293,7 @@ gst_stream_info_set_mute (GstStreamInfo * stream_info, gboolean mute) } if (mute != stream_info->mute) { - GstElement *element; + GstObject *element; stream_info->mute = mute; //gst_pad_set_active_recursive ((GstPad *) @@ -300,14 +302,18 @@ gst_stream_info_set_mute (GstStreamInfo * stream_info, gboolean mute) element = gst_pad_get_parent ((GstPad *) GST_PAD_CAST (stream_info->object)); - if (mute) { - g_signal_connect (element, "state-change", - G_CALLBACK (stream_info_change_state), stream_info); - } else { - g_signal_handlers_disconnect_by_func (element, - G_CALLBACK (stream_info_change_state), stream_info); + if (element) { + if (GST_IS_ELEMENT (element)) { + if (mute) { + g_signal_connect (element, "state-change", + G_CALLBACK (stream_info_change_state), stream_info); + } else { + g_signal_handlers_disconnect_by_func (element, + G_CALLBACK (stream_info_change_state), stream_info); + } + } + gst_object_unref (element); } - g_object_unref (G_OBJECT (element)); } return TRUE; } diff --git a/tests/examples/seek/seek.c b/tests/examples/seek/seek.c index e14bb685a8..8e07251c33 100644 --- a/tests/examples/seek/seek.c +++ b/tests/examples/seek/seek.c @@ -1005,7 +1005,9 @@ do_seek (GtkWidget * widget) static void seek_cb (GtkWidget * widget) { -#ifdef SCRUB +#ifndef SCRUB + GTimeVal timeval; +#else /* If the timer hasn't expired yet, then the pipeline is running */ if (seek_timeout_id != 0) { gst_element_set_state (pipeline, GST_STATE_PAUSED); @@ -1014,6 +1016,12 @@ seek_cb (GtkWidget * widget) do_seek (widget); +#ifndef SCRUB + /* wait for preroll */ + GST_TIME_TO_TIMEVAL (50 * GST_MSECOND, timeval); + gst_element_get_state (pipeline, NULL, NULL, &timeval); +#endif + #ifdef SCRUB gst_element_set_state (pipeline, GST_STATE_PLAYING); @@ -1047,8 +1055,9 @@ stop_seek (GtkWidget * widget, gpointer user_data) gtk_timeout_remove (seek_timeout_id); seek_timeout_id = 0; /* Still scrubbing, so the pipeline is already playing */ - } else + } else { gst_element_set_state (pipeline, GST_STATE_PLAYING); + } update_id = gtk_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline);