From 68d1ca33ae00b779c23ced3c516eed793527578e Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Wed, 15 Sep 2004 08:35:18 +0000 Subject: [PATCH] gst/playback/gstplaybasebin.c: Handle the case where we failed to setup a clear pipeline. This will throw an error (o... Original commit message from CVS: * gst/playback/gstplaybasebin.c: (state_change), (setup_source), (gst_play_base_bin_change_state): Handle the case where we failed to setup a clear pipeline. This will throw an error (or EOS, another nice case) and if you don't catch that, the app will wait for the signal forever (and thus hang). --- ChangeLog | 9 +++++++++ gst/playback/gstplaybasebin.c | 30 ++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 00d1badc19..e1bad937c5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2004-09-15 Ronald S. Bultje + + * gst/playback/gstplaybasebin.c: (state_change), (setup_source), + (gst_play_base_bin_change_state): + Handle the case where we failed to setup a clear pipeline. This + will throw an error (or EOS, another nice case) and if you don't + catch that, the app will wait for the signal forever (and thus + hang). + 2004-09-15 Ronald S. Bultje * ext/gnomevfs/gstgnomevfssink.c: diff --git a/gst/playback/gstplaybasebin.c b/gst/playback/gstplaybasebin.c index e49990beca..2d1c3ad73e 100644 --- a/gst/playback/gstplaybasebin.c +++ b/gst/playback/gstplaybasebin.c @@ -325,6 +325,24 @@ new_decoded_pad (GstElement * element, GstPad * pad, gboolean last, play_base_bin->streaminfo = g_list_append (play_base_bin->streaminfo, info); } +static void +state_change (GstElement * element, + GstElementState old_state, GstElementState new_state, gpointer data) +{ + GstPlayBaseBin *play_base_bin = GST_PLAY_BASE_BIN (data); + + if (old_state > new_state) { + /* EOS or error occurred */ + GST_DEBUG ("state changed downwards"); + g_mutex_lock (play_base_bin->preroll_lock); + GST_DEBUG ("signal preroll done"); + g_cond_signal (play_base_bin->preroll_cond); + GST_DEBUG ("signaled preroll done"); + g_mutex_unlock (play_base_bin->preroll_lock); + } +} + + static gboolean setup_source (GstPlayBaseBin * play_base_bin) { @@ -351,7 +369,7 @@ setup_source (GstPlayBaseBin * play_base_bin) { gboolean res; - gint sig1, sig2, sig3; + gint sig1, sig2, sig3, sig4; GstElement *old_dec; old_dec = play_base_bin->decoder; @@ -385,6 +403,8 @@ setup_source (GstPlayBaseBin * play_base_bin) G_CALLBACK (no_more_pads), play_base_bin); sig3 = g_signal_connect (G_OBJECT (play_base_bin->decoder), "unknown-type", G_CALLBACK (unknown_type), play_base_bin); + sig4 = g_signal_connect (G_OBJECT (play_base_bin->decoder), + "state-change", G_CALLBACK (state_change), play_base_bin); /* either when the queues are filled or when the decoder element has no more * dynamic streams, the cond is unlocked. We can remove the signal handlers then @@ -396,6 +416,7 @@ setup_source (GstPlayBaseBin * play_base_bin) GST_DEBUG ("preroll done !"); g_mutex_unlock (play_base_bin->preroll_lock); + g_signal_handler_disconnect (G_OBJECT (play_base_bin->decoder), sig4); g_signal_handler_disconnect (G_OBJECT (play_base_bin->decoder), sig3); g_signal_handler_disconnect (G_OBJECT (play_base_bin->decoder), sig2); g_signal_handler_disconnect (G_OBJECT (play_base_bin->decoder), sig1); @@ -403,7 +424,7 @@ setup_source (GstPlayBaseBin * play_base_bin) play_base_bin->need_rebuild = FALSE; } - return TRUE; + return (GST_STATE (play_base_bin->thread) == GST_STATE_PLAYING); } static void @@ -519,8 +540,9 @@ gst_play_base_bin_change_state (GstElement * element) case GST_STATE_READY_TO_PAUSED: { if (!setup_source (play_base_bin)) { - GST_ELEMENT_ERROR (GST_ELEMENT (play_base_bin), LIBRARY, TOO_LAZY, - (NULL), ("cannot handle uri \"%s\"", play_base_bin->uri)); + GST_ELEMENT_ERROR (GST_ELEMENT (play_base_bin), STREAM, + CODEC_NOT_FOUND, + ("cannot open file \"%s\"", play_base_bin->uri), (NULL)); ret = GST_STATE_FAILURE; } else { ret = gst_element_set_state (play_base_bin->thread, GST_STATE_PAUSED);