patches/gnome-media-22-play-not-working.diff
author archana
Fri, 22 Apr 2005 06:01:16 +0000
changeset 5361 ce2c9fdba2e0
parent 5173 144f2bc329f8
permissions -rw-r--r--
2005-04-22 Archana Shah <[email protected]> * gnome-media.spec: Spec file updated * patches/gnome-media-22-play-not-working.diff: Patch modified to handle EBUSY error. Patch approved by [email protected]

--- gnome-media-2.6.1-org/grecord/src/gsr-window.c	2005-04-22 14:22:09.233632808 +0900
+++ gnome-media-2.6.1/grecord/src/gsr-window.c	2005-04-22 14:21:05.080385584 +0900
@@ -50,6 +50,10 @@ enum {
 #define KEY_SAVE_DIR        GCONF_DIR "system-state/save-file-directory"
 #define KEY_KVPS            GCONF_DIR "UIConf/kvps"
 #define KEY_LAST_PROFILE_ID GCONF_DIR "last-profile-id"
+#define EBUSY_TRY_AGAIN     3000    /* Empirical data */
+#define KEY_EVENT_SOUNDS    "/desktop/gnome/sound/event_sounds"
+
+static gint event_sounds_value_is_set = 0;
 
 #define CMD_SET_SENSITIVE(window, key, value)               \
   bonobo_ui_component_set_prop (window->priv->ui_component, \
@@ -482,6 +486,49 @@ cb_iterate (GstBin  *bin,
 }
 #endif
 
+static gboolean
+is_set_ebusy_timeout (GSRWindow *window)
+{
+	if (g_object_get_data (G_OBJECT (window), "ebusy_timeout"))
+		return TRUE;
+
+	return FALSE;
+}
+
+static void
+set_ebusy_timeout (GSRWindow *window, gpointer data)
+{
+	g_object_set_data (G_OBJECT (window), "ebusy_timeout", data);
+}
+
+static gboolean
+handle_ebusy_error (GSRWindow *window)
+{
+	GSRWindowPrivate *priv = window->priv;
+
+	/* FIXME:  which pipeline to reset state on? */
+	if (priv->play) {
+		gst_element_set_state (priv->play->pipeline, GST_STATE_NULL);
+		gst_element_set_state (priv->play->pipeline, GST_STATE_PLAYING);
+	} else if (priv->record) {
+		gst_element_set_state (priv->play->pipeline, GST_STATE_NULL);
+		gst_element_set_state (priv->play->pipeline, GST_STATE_PLAYING);
+	} else {
+		g_warning ("Don't know which pipeline to reset");
+	}
+
+	if (event_sounds_value_is_set) {
+		GConfClient *client;
+
+		client = gconf_client_get_default ();
+		gconf_client_set_bool (client, KEY_EVENT_SOUNDS, 1, NULL);
+		g_object_unref (G_OBJECT (client));
+	}
+
+	/* Try only once */
+	return FALSE;
+}
+
 static void
 pipeline_error_cb (GstElement *parent,
 		   GstElement *cause,
@@ -494,6 +541,34 @@ pipeline_error_cb (GstElement *parent,
 	GstElement *sink;
 
 	g_return_if_fail (GTK_IS_WINDOW (window));
+
+	if (error->code == GST_RESOURCE_ERROR_BUSY) {
+		if (! is_set_ebusy_timeout (window)) {
+			GConfClient *client;
+
+			/* We are disabling desktop sounds here so that esd will
+			 * not try to take the audio device until g-s-r gets it once.
+			 * Will reset it once we get into playing mode.
+			 */
+			client = gconf_client_get_default ();
+			if (gconf_client_get_bool (client, KEY_EVENT_SOUNDS, NULL)) {
+				event_sounds_value_is_set = 1;
+				gconf_client_set_bool (client, KEY_EVENT_SOUNDS, 0, NULL);
+			}
+			g_object_unref (G_OBJECT (client));
+
+			g_timeout_add (EBUSY_TRY_AGAIN, (GSourceFunc) handle_ebusy_error, window);
+			set_ebusy_timeout (window, GUINT_TO_POINTER (TRUE));
+
+			CMD_SET_SENSITIVE (window, "FileSave", "0");
+			CMD_SET_SENSITIVE (window, "FileSaveAs", "0");
+			CMD_SET_SENSITIVE (window, "MediaPlay", "0");
+			CMD_SET_SENSITIVE (window, "MediaRecord", "0");
+			return;
+		}
+	}
+
+	set_ebusy_timeout (window, NULL);
 	
 	show_error_dialog (GTK_WINDOW (window), error->message);
 
@@ -1380,6 +1455,7 @@ play_state_changed_cb (GstElement *eleme
 		bonobo_ui_component_set_status (window->priv->ui_component,
 						_("Playing..."), NULL);
 		gtk_widget_set_sensitive (window->priv->scale, TRUE);
+		set_ebusy_timeout (window, NULL);
 		break;
 
 	case GST_STATE_READY: