Index: gnome-media/grecord/ChangeLog
===================================================================
RCS file: /export/cvs/head/gnome-media/grecord/ChangeLog,v
retrieving revision 1.137
diff -p -u -5 -r1.137 ChangeLog
--- gnome-media/grecord/ChangeLog	24 Jan 2005 14:08:16 -0000	1.137
+++ gnome-media/grecord/ChangeLog	1 Feb 2005 11:15:40 -0000
@@ -1,5 +1,14 @@
+2005-02-01  Archana Shah  <archana.shah@wipro.com>
+
+	* src/gsr-window.c (pipeline_error_cb), (play_state_changed_cb):	
+	Add timeout function of 3 seconds if we encounter EBUSY while trying to
+	get the device.
+	(handles_ebusy_error): Try to grab the device just once more
+	(is_set_timeout_exists), (set_timeout_exists): Use them
+	Fixes bug #160340
+
 2005-01-24  Balamurali Viswanathan <balamurali.viswanathan@wipro.com>
 
 	* src/gnome-recorder.c (main): Check for the registry if its not there
 	give an error dialog and exit. Fixes bug #138582
 
Index: gnome-media/grecord/src/gsr-window.c
===================================================================
RCS file: /export/cvs/head/gnome-media/grecord/src/gsr-window.c,v
retrieving revision 1.38
diff -p -u -5 -r1.38 gsr-window.c
--- gnome-media/grecord/src/gsr-window.c	27 Jan 2005 23:12:50 -0000	1.38
+++ gnome-media/grecord/src/gsr-window.c	1 Feb 2005 11:15:41 -0000
@@ -51,10 +51,11 @@ enum {
 #define GCONF_DIR           "/apps/gnome-sound-recorder/"
 #define KEY_OPEN_DIR        GCONF_DIR "system-state/open-file-directory"
 #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 CMD_SET_SENSITIVE(window, key, value)               \
   bonobo_ui_component_set_prop (window->priv->ui_component, \
 				"/commands/" key,           \
 				"sensitive", value, NULL)
@@ -440,10 +441,37 @@ cb_iterate (GstBin  *bin,
 	/* we don't do anything here */
 	return FALSE;
 }
 #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;
+
+	gst_element_set_state (priv->play->pipeline, GST_STATE_NULL);
+	gst_element_set_state (priv->play->pipeline, GST_STATE_PLAYING);
+
+	/* Try only once */
+	return FALSE;
+}
+
 static void
 pipeline_error_cb (GstElement *parent,
 		   GstElement *cause,
 		   GError     *error,
 		   gchar      *debug,
@@ -453,10 +481,25 @@ pipeline_error_cb (GstElement *parent,
 	struct _eos_data *ed;
 	GstElement *sink;
 
 	g_return_if_fail (GTK_IS_WINDOW (window));
 	
+	if (error->code == GST_RESOURCE_ERROR_BUSY) {
+		if (! is_set_ebusy_timeout (window)) {
+			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);
 
 	ed = g_new (struct _eos_data, 1);
 	ed->window = window;
 	ed->pipeline = parent;
@@ -1225,10 +1268,11 @@ play_state_changed_cb (GstElement *eleme
 		CMD_SET_SENSITIVE (window, "FileSaveAs", "0");
 		
 		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:
 		gtk_adjustment_set_value (GTK_RANGE (window->priv->scale)->adjustment, 0.0);
 		gtk_widget_set_sensitive (window->priv->scale, FALSE);
