camerabin2: Reset last state change result on state-locked elements
authorThiago Santos <thiago.sousa.santos@collabora.co.uk>
Thu, 15 Sep 2011 20:35:44 +0000 (17:35 -0300)
committerThiago Santos <thiago.sousa.santos@collabora.co.uk>
Fri, 16 Sep 2011 03:52:53 +0000 (00:52 -0300)
An element stores the result for the last state change it did and
GstBin's state change handler will use this last result for state
locked elements to decide if its state change was successfull or not.

In camerabin2, the filesinks have their state locked and when they
fail switching states, this last failure will be used if the application
tries to change camerabin2's state, causing any state change to fail.

This patch makes camerabin2 reset this last change failure, avoiding
that camerabin2 fails on its next state changes.

gst/camerabin2/gstcamerabin2.c

index e554d5b..aac9cc3 100644 (file)
@@ -485,7 +485,12 @@ gst_camera_bin_src_notify_readyforcapture (GObject * obj, GParamSpec * pspec,
       GST_DEBUG_OBJECT (camera, "Switching videobin location to %s", location);
       g_object_set (camera->videosink, "location", location, NULL);
       g_free (location);
-      gst_element_set_state (camera->videosink, GST_STATE_PLAYING);
+      if (gst_element_set_state (camera->videosink, GST_STATE_PLAYING) ==
+          GST_STATE_CHANGE_FAILURE) {
+        /* Resets the latest state change return, that would be a failure
+         * and could cause problems in a camerabin2 state change */
+        gst_element_set_state (camera->videosink, GST_STATE_NULL);
+      }
       gst_element_set_state (camera->video_encodebin, GST_STATE_PLAYING);
       gst_element_set_state (camera->videobin_capsfilter, GST_STATE_PLAYING);
     }
@@ -1219,7 +1224,12 @@ gst_camera_bin_image_sink_event_probe (GstPad * pad, GstEvent * event,
         GST_DEBUG_OBJECT (camerabin, "Setting filename to imagesink: %s",
             filename);
         g_object_set (camerabin->imagesink, "location", filename, NULL);
-        gst_element_set_state (camerabin->imagesink, GST_STATE_PLAYING);
+        if (gst_element_set_state (camerabin->imagesink, GST_STATE_PLAYING) ==
+            GST_STATE_CHANGE_FAILURE) {
+          /* Resets the latest state change return, that would be a failure
+           * and could cause problems in a camerabin2 state change */
+          gst_element_set_state (camerabin->imagesink, GST_STATE_NULL);
+        }
       }
     }
       break;