return proper values for state change failures

Original commit message from CVS:
return proper values for state change failures
This commit is contained in:
Thomas Vander Stichele 2004-03-29 17:19:38 +00:00
parent 06f16a6950
commit 5b4a2facc1
3 changed files with 93 additions and 23 deletions

View file

@ -1,3 +1,13 @@
2004-03-29 Thomas Vander Stichele <thomas at apestaart dot org>
* examples/gstplay/player.c: (main):
* gst-libs/gst/play/play.c: (gst_play_class_init),
(gst_play_set_location), (gst_play_set_data_src),
(gst_play_set_video_sink), (gst_play_set_audio_sink),
(gst_play_set_visualization), (gst_play_connect_visualization):
check return values of element_set_state and return FALSE where
failed
2004-03-29 Benjamin Otte <otte@gnome.org>
* ext/mad/gstid3tag.c: (gst_id3_tag_handle_event):

View file

@ -127,13 +127,18 @@ main (int argc, char *argv[])
data_src = gst_element_factory_make ("gnomevfssrc", "source");
/* Let's send them to GstPlay object */
gst_play_set_audio_sink (play, audio_sink);
gst_play_set_video_sink (play, video_sink);
gst_play_set_data_src (play, data_src);
gst_play_set_visualization (play, vis_element);
if (!gst_play_set_audio_sink (play, audio_sink))
g_warning ("Could not set audio sink");
if (!gst_play_set_video_sink (play, video_sink))
g_warning ("Could not set video sink");
if (!gst_play_set_data_src (play, data_src))
g_warning ("Could not set data src");
if (!gst_play_set_visualization (play, vis_element))
g_warning ("Could not set visualisation");
/* Setting location we want to play */
gst_play_set_location (play, argv[1]);
if (!gst_play_set_location (play, argv[1]))
g_warning ("Could not set location");
/* Uncomment that line to get an XML dump of the pipeline */
/* gst_xml_write_file (GST_ELEMENT (play), stdout); */
@ -151,7 +156,9 @@ main (int argc, char *argv[])
g_signal_connect (G_OBJECT (play), "eos", G_CALLBACK (got_eos), NULL);
/* Change state to PLAYING */
gst_element_set_state (GST_ELEMENT (play), GST_STATE_PLAYING);
if (gst_element_set_state (GST_ELEMENT (play),
GST_STATE_PLAYING) == GST_STATE_FAILURE)
g_warning ("Could not set state to PLAYING");
g_idle_add ((GSourceFunc) idle_iterate, play);
g_timeout_add (20000, (GSourceFunc) seek_timer, play);

View file

@ -26,6 +26,9 @@
#define TICK_INTERVAL_MSEC 200
GST_DEBUG_CATEGORY_STATIC (play_debug);
#define GST_CAT_DEFAULT play_debug
enum
{
TIME_TICK,
@ -669,6 +672,8 @@ gst_play_class_init (GstPlayClass * klass)
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GstPlayClass, have_video_size), NULL, NULL,
gst_marshal_VOID__INT_INT, G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
GST_DEBUG_CATEGORY_INIT (play_debug, "GST_PLAY", 0, "GStreamer Play library");
GST_DEBUG ("Play class initialized");
}
/* ======================================================= */
@ -700,8 +705,13 @@ gst_play_set_location (GstPlay * play, const char *location)
play->priv->location = g_strdup (location);
if (GST_STATE (GST_ELEMENT (play)) != GST_STATE_READY)
gst_element_set_state (GST_ELEMENT (play), GST_STATE_READY);
if (GST_STATE (GST_ELEMENT (play)) != GST_STATE_READY) {
GstElementStateReturn ret;
ret = gst_element_set_state (GST_ELEMENT (play), GST_STATE_READY);
if (ret == GST_STATE_FAILURE)
return FALSE;
}
work_thread = g_hash_table_lookup (play->priv->elements, "work_thread");
if (!GST_IS_ELEMENT (work_thread))
@ -840,8 +850,13 @@ gst_play_set_data_src (GstPlay * play, GstElement * data_src)
g_return_val_if_fail (GST_IS_PLAY (play), FALSE);
/* We bring back the pipeline to READY */
if (GST_STATE (GST_ELEMENT (play)) != GST_STATE_READY)
gst_element_set_state (GST_ELEMENT (play), GST_STATE_READY);
if (GST_STATE (GST_ELEMENT (play)) != GST_STATE_READY) {
GstElementStateReturn ret;
ret = gst_element_set_state (GST_ELEMENT (play), GST_STATE_READY);
if (ret == GST_STATE_FAILURE)
return FALSE;
}
/* Getting needed objects */
work_thread = g_hash_table_lookup (play->priv->elements, "work_thread");
@ -880,6 +895,7 @@ gboolean
gst_play_set_video_sink (GstPlay * play, GstElement * video_sink)
{
GstElement *video_thread, *old_video_sink, *video_scaler, *video_sink_element;
GstElementStateReturn ret;
g_return_val_if_fail (play != NULL, FALSE);
g_return_val_if_fail (GST_IS_PLAY (play), FALSE);
@ -887,8 +903,13 @@ gst_play_set_video_sink (GstPlay * play, GstElement * video_sink)
g_return_val_if_fail (GST_IS_ELEMENT (video_sink), FALSE);
/* We bring back the pipeline to READY */
if (GST_STATE (GST_ELEMENT (play)) != GST_STATE_READY)
gst_element_set_state (GST_ELEMENT (play), GST_STATE_READY);
if (GST_STATE (GST_ELEMENT (play)) != GST_STATE_READY) {
GstElementStateReturn ret;
ret = gst_element_set_state (GST_ELEMENT (play), GST_STATE_READY);
if (ret == GST_STATE_FAILURE)
return FALSE;
}
/* Getting needed objects */
video_thread = g_hash_table_lookup (play->priv->elements, "video_thread");
@ -921,7 +942,9 @@ gst_play_set_video_sink (GstPlay * play, GstElement * video_sink)
}
}
gst_element_set_state (video_sink, GST_STATE (GST_ELEMENT (play)));
ret = gst_element_set_state (video_sink, GST_STATE (GST_ELEMENT (play)));
if (ret == GST_STATE_FAILURE)
return FALSE;
return TRUE;
}
@ -939,6 +962,7 @@ gboolean
gst_play_set_audio_sink (GstPlay * play, GstElement * audio_sink)
{
GstElement *old_audio_sink, *audio_thread, *volume, *audio_sink_element;
GstElementStateReturn ret;
g_return_val_if_fail (play != NULL, FALSE);
g_return_val_if_fail (GST_IS_PLAY (play), FALSE);
@ -946,8 +970,13 @@ gst_play_set_audio_sink (GstPlay * play, GstElement * audio_sink)
g_return_val_if_fail (GST_IS_ELEMENT (audio_sink), FALSE);
/* We bring back the pipeline to READY */
if (GST_STATE (GST_ELEMENT (play)) != GST_STATE_READY)
gst_element_set_state (GST_ELEMENT (play), GST_STATE_READY);
if (GST_STATE (GST_ELEMENT (play)) != GST_STATE_READY) {
GstElementStateReturn ret;
ret = gst_element_set_state (GST_ELEMENT (play), GST_STATE_READY);
if (ret == GST_STATE_FAILURE)
return FALSE;
}
/* Getting needed objects */
old_audio_sink = g_hash_table_lookup (play->priv->elements, "audio_sink");
@ -976,7 +1005,9 @@ gst_play_set_audio_sink (GstPlay * play, GstElement * audio_sink)
audio_sink_element);
}
gst_element_set_state (audio_sink, GST_STATE (GST_ELEMENT (play)));
ret = gst_element_set_state (audio_sink, GST_STATE (GST_ELEMENT (play)));
if (ret == GST_STATE_FAILURE)
return FALSE;
return TRUE;
}
@ -1017,7 +1048,11 @@ gst_play_set_visualization (GstPlay * play, GstElement * vis_element)
/* We bring back the pipeline to PAUSED */
if (GST_STATE (GST_ELEMENT (play)) == GST_STATE_PLAYING) {
gst_element_set_state (GST_ELEMENT (play), GST_STATE_PAUSED);
GstElementStateReturn ret;
ret = gst_element_set_state (GST_ELEMENT (play), GST_STATE_PAUSED);
if (ret == GST_STATE_FAILURE)
return FALSE;
was_playing = TRUE;
}
@ -1028,8 +1063,13 @@ gst_play_set_visualization (GstPlay * play, GstElement * vis_element)
g_hash_table_replace (play->priv->elements, "vis_element", vis_element);
if (was_playing)
gst_element_set_state (GST_ELEMENT (play), GST_STATE_PLAYING);
if (was_playing) {
GstElementStateReturn ret;
ret = gst_element_set_state (GST_ELEMENT (play), GST_STATE_PLAYING);
if (ret == GST_STATE_FAILURE)
return FALSE;
}
return TRUE;
}
@ -1092,7 +1132,11 @@ gst_play_connect_visualization (GstPlay * play, gboolean connect)
/* We bring back the pipeline to PAUSED */
if (GST_STATE (GST_ELEMENT (play)) == GST_STATE_PLAYING) {
gst_element_set_state (GST_ELEMENT (play), GST_STATE_PAUSED);
GstElementStateReturn ret;
ret = gst_element_set_state (GST_ELEMENT (play), GST_STATE_PAUSED);
if (ret == GST_STATE_FAILURE)
return FALSE;
was_playing = TRUE;
}
@ -1115,7 +1159,11 @@ gst_play_connect_visualization (GstPlay * play, gboolean connect)
/* We bring back the pipeline to PAUSED */
if (GST_STATE (GST_ELEMENT (play)) == GST_STATE_PLAYING) {
gst_element_set_state (GST_ELEMENT (play), GST_STATE_PAUSED);
GstElementStateReturn ret;
ret = gst_element_set_state (GST_ELEMENT (play), GST_STATE_PAUSED);
if (ret == GST_STATE_FAILURE)
return FALSE;
was_playing = TRUE;
}
@ -1127,8 +1175,13 @@ gst_play_connect_visualization (GstPlay * play, gboolean connect)
gst_element_link (vis_bin, video_switch);
}
if (was_playing)
gst_element_set_state (GST_ELEMENT (play), GST_STATE_PLAYING);
if (was_playing) {
GstElementStateReturn ret;
ret = gst_element_set_state (GST_ELEMENT (play), GST_STATE_PLAYING);
if (ret == GST_STATE_FAILURE)
return FALSE;
}
return TRUE;
}