Re: [Rhythmbox-devel] monkey-media signal cleanups and errorhandling
- From: Colin Walters <walters debian org>
- To: rhythmbox-devel gnome org
- Subject: Re: [Rhythmbox-devel] monkey-media signal cleanups and errorhandling
- Date: 29 Jan 2003 18:20:45 -0500
On Wed, 2003-01-29 at 14:07, Jorn Baayen wrote:
> It would be cleaner to just disconnect the signal, then.
Ok...it seems equivalent to me, but no big deal :)
New patch attached. How's she look?
Index: tests/test-cmdline.c
===================================================================
RCS file: /cvs/gnome/monkey-media/tests/test-cmdline.c,v
retrieving revision 1.7
diff -u -d -I$Id: -r1.7 test-cmdline.c
--- tests/test-cmdline.c 25 Jan 2003 12:34:18 -0000 1.7
+++ tests/test-cmdline.c 29 Jan 2003 23:19:52 -0000
@@ -18,9 +18,12 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+#include <stdlib.h>
#include <glib.h>
#include <monkey-media.h>
+static int exitval = 0;
+
void
eos (MonkeyMediaPlayer *player, gpointer data)
{
@@ -37,10 +40,18 @@
GEnumValue *enumvalue = g_enum_get_value(g_type_class_peek(MONKEY_MEDIA_TYPE_STREAM_INFO_FIELD),
field);
char *str = g_strdup_value_contents(value);
- fprintf(stdout, "info: %s: %s\n", enumvalue->value_name, str);
+ fprintf (stdout, "info: %s: %s\n", enumvalue->value_name, str);
g_free(str);
}
+void
+error_cb (MonkeyMediaPlayer *player, GError *error, gpointer data)
+{
+ fprintf (stderr, "Error: %s\n", error->message);
+ monkey_media_main_quit ();
+ exitval = 1;
+}
+
int
main (int argc, char **argv)
{
@@ -65,6 +76,9 @@
g_error_free (error);
}
+ g_signal_connect (G_OBJECT (player), "error",
+ G_CALLBACK (error_cb), NULL);
+
g_signal_connect (G_OBJECT (player), "info",
G_CALLBACK (info), NULL);
@@ -77,5 +91,7 @@
/* go to main loop */
monkey_media_main ();
- return 0;
+ g_object_unref (G_OBJECT (player));
+
+ exit (exitval);
}
Index: src/monkey-media-player.h
===================================================================
RCS file: /cvs/gnome/monkey-media/src/monkey-media-player.h,v
retrieving revision 1.6
diff -u -d -I$Id: -r1.6 monkey-media-player.h
--- src/monkey-media-player.h 25 Jan 2003 12:34:17 -0000 1.6
+++ src/monkey-media-player.h 29 Jan 2003 23:19:52 -0000
@@ -34,7 +34,8 @@
MONKEY_MEDIA_PLAYER_ERROR_NO_VOLUME_PLUGIN,
MONKEY_MEDIA_PLAYER_ERROR_DEMUX_FAILED,
MONKEY_MEDIA_PLAYER_ERROR_NO_AUDIO,
- MONKEY_MEDIA_PLAYER_ERROR_INTERNAL
+ MONKEY_MEDIA_PLAYER_ERROR_GENERAL,
+ MONKEY_MEDIA_PLAYER_ERROR_INTERNAL,
} MonkeyMediaPlayerError;
#define MONKEY_MEDIA_PLAYER_ERROR monkey_media_player_error_quark ()
@@ -61,10 +62,11 @@
{
GObjectClass parent_class;
- void (*eos) (MonkeyMediaPlayer *mp);
- void (*info) (MonkeyMediaPlayer *mp, MonkeyMediaStreamInfoField field,
- GValue *value);
- void (*tick) (MonkeyMediaPlayer *mp, long elapsed);
+ void (*eos) (MonkeyMediaPlayer *mp);
+ void (*info) (MonkeyMediaPlayer *mp, MonkeyMediaStreamInfoField field,
+ GValue *value);
+ void (*error) (MonkeyMediaPlayer *mp, GError *error);
+ void (*tick) (MonkeyMediaPlayer *mp, long elapsed);
} MonkeyMediaPlayerClass;
GType monkey_media_player_get_type (void);
Index: src/monkey-media-player-gst.c
===================================================================
RCS file: /cvs/gnome/monkey-media/src/monkey-media-player-gst.c,v
retrieving revision 1.6
diff -u -d -I$Id: -r1.6 monkey-media-player-gst.c
--- src/monkey-media-player-gst.c 25 Jan 2003 20:12:26 -0000 1.6
+++ src/monkey-media-player-gst.c 29 Jan 2003 23:19:52 -0000
@@ -26,6 +26,7 @@
#include <gst/control/control.h>
#include <gst/control/dparam_smooth.h>
#include <math.h>
+#include <string.h>
#include <libgnomevfs/gnome-vfs-utils.h>
#include "monkey-media.h"
@@ -52,6 +53,8 @@
gboolean playing;
+ guint error_signal_id;
+
GstDParam *volume_dparam;
float cur_volume;
gboolean mute;
@@ -68,6 +71,7 @@
{
EOS,
INFO,
+ ERROR,
TICK,
LAST_SIGNAL
} MonkeyMediaPlayerSignalType;
@@ -76,8 +80,9 @@
{
GObject *object;
MonkeyMediaStreamInfoField info_field;
+ GError *error;
GValue *info;
-} MonkeyMediaPlayerInfoSignal;
+} MonkeyMediaPlayerSignal;
static guint monkey_media_player_signals[LAST_SIGNAL] = { 0 };
@@ -139,6 +144,16 @@
2,
MONKEY_MEDIA_TYPE_STREAM_INFO_FIELD,
G_TYPE_POINTER);
+ monkey_media_player_signals[ERROR] =
+ g_signal_new ("error",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (MonkeyMediaPlayerClass, error),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_POINTER);
monkey_media_player_signals[TICK] =
g_signal_new ("tick",
G_OBJECT_CLASS_TYPE (object_class),
@@ -159,7 +174,7 @@
g_signal_emit (G_OBJECT (mp), monkey_media_player_signals[TICK], 0,
monkey_media_player_get_time (mp));
-
+
return TRUE;
}
@@ -179,10 +194,16 @@
mp = MONKEY_MEDIA_PLAYER (object);
g_source_remove (mp->priv->tick_timeout_id);
+ g_signal_handler_block (G_OBJECT (mp->priv->pipeline), mp->priv->error_signal_id);
+
+ gst_element_set_state (mp->priv->pipeline,
+ GST_STATE_NULL);
gst_object_unref (GST_OBJECT (mp->priv->pipeline));
gst_object_unref (GST_OBJECT (mp->priv->typefind_pipeline));
+ g_signal_handler_unblock (G_OBJECT (mp->priv->pipeline), mp->priv->error_signal_id);
+
mp->priv->have_sane_pipeline = FALSE;
g_free (mp->priv->uri);
@@ -196,7 +217,7 @@
eos_signal_idle (MonkeyMediaPlayer *mp)
{
g_signal_emit (G_OBJECT (mp), monkey_media_player_signals[EOS], 0);
-
+ g_object_unref (G_OBJECT (mp));
return FALSE;
}
@@ -204,9 +225,41 @@
eos_cb (GstElement *element,
MonkeyMediaPlayer *mp)
{
+ g_object_ref (G_OBJECT (mp));
g_idle_add ((GSourceFunc) eos_signal_idle, mp);
}
+static gboolean
+error_signal_idle (MonkeyMediaPlayerSignal *signal)
+{
+ MonkeyMediaPlayer *mp = MONKEY_MEDIA_PLAYER (signal->object);
+ g_signal_emit (G_OBJECT (signal->object), monkey_media_player_signals[ERROR], 0,
+ signal->error);
+ g_error_free (signal->error);
+ monkey_media_player_close (mp);
+ g_object_unref (G_OBJECT (signal->object));
+ g_signal_handler_unblock (G_OBJECT (mp->priv->pipeline), mp->priv->error_signal_id);
+ g_free (signal);
+ return FALSE;
+}
+
+static void
+error_cb (GstElement *element,
+ GObject *arg1,
+ char *errmsg,
+ MonkeyMediaPlayer *mp)
+{
+ MonkeyMediaPlayerSignal *signal;
+ g_signal_handler_block (G_OBJECT (mp->priv->pipeline), mp->priv->error_signal_id);
+ signal = g_new0 (MonkeyMediaPlayerSignal, 1);
+ signal->object = G_OBJECT (mp);
+ signal->error = g_error_new_literal (MONKEY_MEDIA_PLAYER_ERROR,
+ MONKEY_MEDIA_PLAYER_ERROR_GENERAL,
+ errmsg);
+ g_object_ref (G_OBJECT (mp));
+ g_idle_add ((GSourceFunc) error_signal_idle, signal);
+}
+
static void
have_type_cb (GstElement *element,
GstCaps *caps,
@@ -217,12 +270,13 @@
}
static gboolean
-info_signal_idle (MonkeyMediaPlayerInfoSignal *signal)
+info_signal_idle (MonkeyMediaPlayerSignal *signal)
{
g_signal_emit (signal->object, monkey_media_player_signals[INFO], 0,
signal->info_field, signal->info);
g_free (signal->info);
+ g_object_unref (G_OBJECT (signal->object));
g_free (signal);
return FALSE;
@@ -263,14 +317,15 @@
if (ev != NULL)
{
- MonkeyMediaPlayerInfoSignal *signal;
+ MonkeyMediaPlayerSignal *signal;
- signal = g_new0 (MonkeyMediaPlayerInfoSignal, 1);
+ signal = g_new0 (MonkeyMediaPlayerSignal, 1);
signal->info_field = ev->value;
signal->info = value;
signal->object = G_OBJECT (player);
+ g_object_ref (G_OBJECT (player));
g_idle_add ((GSourceFunc) info_signal_idle, signal);
}
@@ -321,6 +376,12 @@
"deep_notify",
G_CALLBACK (deep_notify_cb),
mp);
+
+ mp->priv->error_signal_id =
+ g_signal_connect (G_OBJECT (mp->priv->pipeline),
+ "error",
+ G_CALLBACK (error_cb),
+ mp);
mp->priv->src = gst_element_factory_make ("gnomevfssrc", "src");
if (mp->priv->src == NULL) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]