sinek/src gtkxine.c,1.1,1.2

[email protected] Sun, 05 Jan 2003 03:37:14 -0800
Newsgroups gmane.comp.video.sinek.cvs
Message-ID <[email protected]>
Update of /cvsroot/sinek/sinek/src
In directory sc8-pr-cvs1:/tmp/cvs-serv19844/src

Modified Files:
	gtkxine.c 
Log Message:
compiles.. untested


Index: gtkxine.c
===================================================================
RCS file: /cvsroot/sinek/sinek/src/gtkxine.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- gtkxine.c	5 Jan 2003 09:10:18 -0000	1.1
+++ gtkxine.c	5 Jan 2003 11:37:12 -0000	1.2
@@ -12,7 +12,6 @@
 #include <gtk/gtk.h>
 #include <gdk/gdkx.h>
 #include <xine.h>
-#include <xine/video_out_x11.h>
 #include <math.h>
 #include <libintl.h>
 
@@ -20,56 +19,61 @@
 #include <config.h>
 #endif
 
+#define _(x) (x)
+
 struct _GtkXine
 {
 	GtkWidget parent;
 
 	xine_t *xine;
+	int conf_loaded;
+	xine_audio_port_t *ao_driver;
+	xine_video_port_t *vo_driver;
+	xine_stream_t *stream;
 
-	char *conf_file;
-	char *video_driver;
-	char *audio_driver;
-	char *display_name;
+	void (*warning_cb) (const char *msg);
+	void (*error_cb) (const char *msg);
 
 	char *video_win_title;
 	GtkWidget *video_win;
 	x11_visual_t visual;
 	int video_width, video_height;
 
-#if XINE_MAJOR_VERSION < 1
-	/* 0.9.13 API */
-	ao_driver_t *ao_driver;
-	vo_driver_t *vo_driver;
-	config_values_t *conf;
-#else
 	/* 1.0.0 API */
-	xine_audio_port_t *ao_driver;
-	xine_video_port_t *vo_driver;
-	xine_stream_t *vidstream;
-#endif
 };
 
+static void default_warning_cb (const char *msg)
+{
+	g_warning ("%s\n", msg);
+}
+
+static void default_error_cb (const char *msg)
+{
+	g_error ("%s\n", msg);
+}
+
 static void gtk_xine_init (GtkXine *xine)
 {
-	xine->xine = NULL;
-	xine->conf_file = g_strconcat (g_get_home_dir (), "/.xine/config", NULL);
-	xine->audio_driver = NULL;
-	xine->video_driver = NULL;
-	xine->display_name = NULL;
+	xine->xine = xine_new ();
+	xine->conf_loaded = 0;
 	xine->ao_driver = NULL;
 	xine->vo_driver = NULL;
-	xine->conf = NULL;
+
+	xine->warning_cb = default_warning_cb;
+	xine->error_cb = default_error_cb;
+
 	xine->video_win_title = g_strdup ("Xine Video Output");
 
 	/* XXX: is this correct? */
 	gtk_set_locale ();
-	xine_set_locale ();
+	/* xine_set_locale (); */
 	bindtextdomain (PACKAGE, XINE_LOCALEDIR);
 	bind_textdomain_codeset (PACKAGE, "UTF-8");
 	textdomain (PACKAGE);
 
 }
 
+#if 0
 static void gtk_xine_build_audio_out (GtkXine *xine)
 {
 	char *id, **driver_ids;
@@ -307,6 +311,7 @@
 	gtk_xine_build_video_out (xine);
 	xine->xine = xine_init (xine->vo_driver, xine->ao_driver, xine->conf);
 }
+#endif
 
 static void gtk_xine_dispose (GObject *obj)
 {
@@ -315,18 +320,7 @@
 
 	g_print ("%s()\n", __FUNCTION__);
 
-	g_free (xine->conf_file);
-	if (xine->audio_driver)
-		g_free (xine->audio_driver);
-	if (xine->video_driver)
-		g_free (xine->video_driver);
-
-	/* xine 0913api retardedness; doesn't clean up the config object */
-	if (xine->conf)
-		xine->conf->dispose (xine->conf);
-
-	if (xine->xine)
-		xine_exit (xine->xine);
+	xine_exit (xine->xine);
 
 	if (G_OBJECT_CLASS (parent)->dispose)
 		G_OBJECT_CLASS (parent)->dispose (obj);
@@ -335,7 +329,7 @@
 static void gtk_xine_class_init (GtkXineClass *class)
 {
 	GObjectClass *gobj_class = G_OBJECT_CLASS (class);
-	GtkWidgetClass *gtkwid_class = GTK_WIDGET_CLASS (class);
+	/* GtkWidgetClass *gtkwid_class = GTK_WIDGET_CLASS (class); */
 	g_print ("%s()\n", __FUNCTION__);
 
 	/* gobj_class->finalize = gtk_xine_finalize; */
@@ -372,65 +366,171 @@
 
 GtkWidget *gtk_xine_new (void)
 {
-	g_print ("%s()\n", __FUNCTION__);
-
 	return GTK_WIDGET (gtk_type_new (GTK_TYPE_XINE));
 }
 
-GtkWidget *gtk_xine_new_with_values (const char *fname, const char *audio_driver, const char *video_driver, const char *display_name)
+/* config file */
+
+int gtk_xine_config_load (GtkXine *xine, const char *conffile)
 {
-	GtkXine *xine;
+	if (xine->conf_loaded) {
+		xine->warning_cb (_("loading over old config file, discarding previous."));
+		xine_config_reset (xine->xine);
+	}
 
-	g_print ("%s\n", __FUNCTION__);
+	xine_config_load (xine->xine, conffile);
+	xine->conf_loaded = 1;
+	return 0;
+}
 
-	xine = gtk_type_new (GTK_TYPE_XINE);
-	if (fname)
-		gtk_xine_select_config_file (xine, fname);
-	if (audio_driver)
-		gtk_xine_select_audio_driver (xine, audio_driver);
-	if (video_driver)
-		gtk_xine_select_video_driver (xine, video_driver);
-	if (display_name)
-		gtk_xine_select_display (xine, display_name);
-	 
-	return GTK_WIDGET (xine);
+int gtk_xine_config_save (GtkXine *xine, const char *conffile)
+{
+	if (xine->conf_loaded) {
+		xine_config_save (xine->xine, conffile);
+		return 1;
+	}
+
+	return 0;
 }
 
-void gtk_xine_select_config_file (GtkXine *xine, const char *fname)
+const char *gtk_xine_config_register_string (GtkXine *xine, const char *key, const char *default_value)
 {
-	g_return_if_fail (xine->xine == NULL);
+	return xine_config_register_string (xine->xine, key, default_value, NULL, NULL, 0, NULL, NULL);
+}
 
-	g_free (xine->conf_file);
-	xine->conf_file = g_strdup (fname);
+int gtk_xine_config_register_range (GtkXine *xine, const char *key, int default_value, int min, int max)
+{
+	return xine_config_register_range (xine->xine, key, default_value, min, max, NULL, NULL, 0, NULL, NULL);
 }
 
-void gtk_xine_select_audio_driver (GtkXine *xine, const char *name)
+int gtk_xine_config_register_enum (GtkXine *xine, const char *key, int default_value, char **values)
 {
-	g_return_if_fail (xine->xine == NULL);
+	return xine_config_register_enum (xine->xine, key, default_value, values, NULL, NULL, 0, NULL, NULL);
+}
 
-	if (xine->audio_driver)
-		g_free (xine->audio_driver);
-	xine->audio_driver = g_strdup (name);
+int gtk_xine_config_register_num (GtkXine *xine, const char *key, int default_value)
+{
+	return xine_config_register_num (xine->xine, key, default_value, NULL, NULL, 0, NULL, NULL);
 }
 
-void gtk_xine_select_video_driver (GtkXine *xine, const char *name)
+int gtk_xine_config_register_bool (GtkXine *xine, const char *key, int default_value)
 {
-	g_return_if_fail (xine->xine == NULL);
+	return xine_config_register_bool (xine->xine, key, default_value, NULL, NULL, 0, NULL, NULL);
+}
 
-	if (xine->video_driver)
-		g_free (xine->video_driver);
-	xine->video_driver = g_strdup (name);
+int gtk_xine_config_set (GtkXine *xine, const char *key, void *value)
+{
+	xine_cfg_entry_t entry;
+
+	if (xine_config_lookup_entry (xine->xine, key, &entry)) {
+		switch (entry.type) {
+			case XINE_CONFIG_TYPE_UNKNOWN:
+				entry.unknown_value = (char *) value;
+				break;
+			case XINE_CONFIG_TYPE_STRING:
+				entry.str_value = (char *) value;
+				break;
+			default:
+				entry.num_value = (int) value;
+				break;
+		}
+		xine_config_update_entry (xine->xine, &entry);
+		return 0;
+	}
+	
+	return 1;
 }
 
-void gtk_xine_select_display (GtkXine *xine, const char *display_name)
+int gtk_xine_config_get (GtkXine *xine, const char *key, void **value)
 {
-	g_return_if_fail (xine->xine == NULL);
+	xine_cfg_entry_t entry;
 
-	if (xine->display_name)
-		g_free (xine->display_name);
-	xine->display_name = g_strdup (display_name);
+	if (xine_config_lookup_entry (xine->xine, key, &entry)) {
+		switch (entry.type) {
+			case XINE_CONFIG_TYPE_UNKNOWN:
+				*((char **) value) = entry.unknown_value;
+				break;
+			case XINE_CONFIG_TYPE_STRING:
+				*((char **) value) = entry.str_value;
+				break;
+			default:
+				*((int *) value) = entry.num_value;
+				break;
+		}
+
+		return 0;
+	}
+
+	return 1;
+}
+
+const char *gtk_xine_set_audio_driver (GtkXine *xine, const char *name)
+{
+	const char *const *driver_ids;
+	int i;
+
+	if (xine->ao_driver) {
+		xine_close_audio_driver (xine->xine, xine->ao_driver);
+		xine->ao_driver = NULL;
+	}
+		
+	if (strcmp (name, "null") == 0)
+		return name;
+	if (strcmp (name, "auto") != 0)
+		xine->ao_driver = xine_open_audio_driver (xine->xine, name, NULL);
+
+	if (xine->ao_driver == NULL) {
+		/* autodetect */
+		driver_ids = xine_list_audio_output_plugins (xine->xine);
+		for (i = 0; driver_ids[i] != NULL; i++) {
+			xine->ao_driver = xine_open_audio_driver (xine->xine, driver_ids[i], NULL);
+			if (xine->ao_driver) {
+				name = (const char *) driver_ids[i];
+				break;
+			}
+		}
+	}
+
+	if (xine->ao_driver == NULL)
+		name = "null";
+
+	return name;
 }
 
+const char *gtk_xine_set_video_driver (GtkXine *xine, const char *name)
+{
+	const char *const *driver_ids;
+	int i;
+
+	if (xine->vo_driver) {
+		xine_close_video_driver (xine->xine, xine->vo_driver);
+		xine->vo_driver = NULL;
+	}
+	
+	if (strcmp (name, "null") == 0)
+		return name;
+	if (strcmp (name, "auto") != 0)
+		xine->vo_driver = xine_open_video_driver (xine->xine, name, XINE_VISUAL_TYPE_X11, NULL);
+
+	if (xine->vo_driver == NULL) {
+		/* autodetect */
+		driver_ids = xine_list_video_output_plugins (xine->xine);
+		for (i = 0; driver_ids[i] != NULL; i++) {
+			xine->vo_driver = xine_open_video_driver (xine->xine, driver_ids[i], XINE_VISUAL_TYPE_X11, NULL);
+			if (xine->vo_driver) {
+				name = (const char *) driver_ids[i];
+				break;
+			}
+		}
+	}
+
+	if (xine->vo_driver == NULL)
+		name = "null";
+
+	return name;
+}
+
+#if 0
 void gtk_xine_load (GtkXine *xine, const char *mrl)
 {
 	if (xine->xine == NULL)
@@ -438,92 +538,126 @@
 
 
 }
+#endif
 
-void gtk_xine_select_audio_channel (GtkXine *xine, int channel)
+/* parameters */
+
+GtkXinePlaybackSpeed gtk_xine_set_speed (GtkXine *xine, GtkXinePlaybackSpeed speed)
 {
-	if (xine->xine == NULL)
-		gtk_xine_build (xine);
+	xine_set_param (xine->stream, XINE_PARAM_SPEED, speed);
+	return gtk_xine_get_speed (xine);
+}
 
-	xine_select_audio_channel (xine->xine, channel);
+GtkXinePlaybackSpeed gtk_xine_get_speed (GtkXine *xine)
+{
+	return xine_get_param (xine->stream, XINE_PARAM_SPEED);
 }
 
-void gtk_xine_select_spu_channel (GtkXine *xine, int channel)
+#if 0
+int gtk_xine_set_av_offset (GtkXine *xine, int avoffset)
 {
-	if (xine->xine == NULL)
-		gtk_xine_build (xine);
+}
 
-	xine_select_spu_channel (xine->xine, channel);
+int gtk_xine_get_av_offset (GtkXine *xine)
+{
 }
+#endif
 
-void gtk_xine_set_volume (GtkXine *xine, int volume)
+int gtk_xine_set_audio_channel (GtkXine *xine, int channel)
 {
-	if (xine->xine == NULL)
-		gtk_xine_build (xine);
+	xine_set_param (xine->stream, XINE_PARAM_AUDIO_CHANNEL_LOGICAL, channel);
+	return gtk_xine_get_audio_channel (xine);
+}
 
-	if (volume < 0)
-		volume = 0;
-	if (volume > 100)
-		volume = 100;
-	if (xine_set_audio_property(xine->xine, AO_PROP_MIXER_VOL, volume) != volume)
-		xine_set_audio_property(xine->xine, AO_PROP_PCM_VOL, volume);
+int gtk_xine_get_audio_channel (GtkXine *xine)
+{
+	return xine_get_param (xine->stream, XINE_PARAM_AUDIO_CHANNEL_LOGICAL);
 }
 
-int gtk_xine_get_volume (GtkXine *xine)
+int gtk_xine_set_spu_channel (GtkXine *xine, int channel)
 {
-	if (xine_get_audio_capabilities(xine->xine) & AO_CAP_MIXER_VOL)
-		return xine_get_audio_property(xine->xine, AO_PROP_MIXER_VOL);
-	return xine_get_audio_property(xine->xine, AO_PROP_PCM_VOL);
+	xine_set_param (xine->stream, XINE_PARAM_SPU_CHANNEL, channel);
+	return gtk_xine_get_spu_channel (xine);
 }
 
-void gtk_xine_set_mute (GtkXine *xine, int mute)
+int gtk_xine_get_spu_channel (GtkXine *xine)
 {
-	if (xine_get_audio_capabilities(xine->xine) & AO_CAP_MUTE_VOL)
-		xine_set_audio_property(xine->xine, AO_PROP_MUTE_VOL, mute);
+	return xine_get_param (xine->stream, XINE_PARAM_SPU_CHANNEL);
 }
 
-void gtk_xine_set_speed (GtkXine *xine, GtkXinePlaybackSpeed speed)
+int gtk_xine_set_video_channel (GtkXine *xine, int channel)
 {
-	switch (speed) {
-		case GTK_XINE_PLAYBACK_SPEED_PAUSE:
-			xine_set_speed (xine->xine, SPEED_PAUSE);
-			break;
-		case GTK_XINE_PLAYBACK_SPEED_QUARTER_SLOW:
-			xine_set_speed (xine->xine, SPEED_SLOW_4);
-			break;
-		case GTK_XINE_PLAYBACK_SPEED_HALF_SLOW:
-			xine_set_speed (xine->xine, SPEED_SLOW_2);
-			break;
-		case GTK_XINE_PLAYBACK_SPEED_NORMAL:
-			xine_set_speed (xine->xine, SPEED_NORMAL);
-			break;
-		case GTK_XINE_PLAYBACK_SPEED_TWICE_FAST:
-			xine_set_speed (xine->xine, SPEED_FAST_2);
-			break;
-		case GTK_XINE_PLAYBACK_SPEED_FOUR_FAST:
-			xine_set_speed (xine->xine, SPEED_FAST_4);
-			break;
-		default:
-			/* error */
-	}
+	xine_set_param (xine->stream, XINE_PARAM_VIDEO_CHANNEL, channel);
+	return gtk_xine_get_video_channel (xine);
 }
 
-GtkXinePlaybackSpeed gtk_xine_get_speed (GtkXine *xine)
+int gtk_xine_get_video_channel (GtkXine *xine)
 {
-	switch (xine_get_speed (xine->xine)) {
-		case SPEED_PAUSE:
-			return GTK_XINE_PLAYBACK_SPEED_PAUSE;
-		case SPEED_SLOW_4:
-			return GTK_XINE_PLAYBACK_SPEED_QUARTER_SLOW;
-		case SPEED_SLOW_2:
-			return GTK_XINE_PLAYBACK_SPEED_HALF_SLOW;
-		case SPEED_NORMAL:
-			return GTK_XINE_PLAYBACK_SPEED_NORMAL;
-		case SPEED_FAST_2:
-			return GTK_XINE_PLAYBACK_SPEED_TWICE_FAST;
-		case SPEED_FAST_4:
-			return GTK_XINE_PLAYBACK_SPEED_FOUR_FAST;
-		default:
-			/* error */
-			return -1;
+	return xine_get_param (xine->stream, XINE_PARAM_VIDEO_CHANNEL);
+}
+
+int gtk_xine_set_volume (GtkXine *xine, int volume)
+{
+	if (volume < 0 || volume > 100) {
+		char *str = g_strdup_printf (_("attempt to set audio volume to out-of-range value '%d'."), volume);
+		if (volume < 0)
+			volume = 0;
+		if (volume > 100)
+			volume = 100;
+		xine->warning_cb (str);
+		g_free (str);
 	}
+
+	xine_set_param (xine->stream, XINE_PARAM_AUDIO_VOLUME, volume);
+	return gtk_xine_get_volume (xine);
 }
+
+int gtk_xine_get_volume (GtkXine *xine)
+{
+	return xine_get_param (xine->stream, XINE_PARAM_AUDIO_VOLUME);
+}
+
+int gtk_xine_set_mute (GtkXine *xine, int muted)
+{
+	xine_set_param (xine->stream, XINE_PARAM_AUDIO_MUTE, muted);
+	return gtk_xine_get_mute (xine);
+}
+
+int gtk_xine_get_mute (GtkXine *xine)
+{
+	return xine_get_param (xine->stream, XINE_PARAM_AUDIO_MUTE);
+}
+
+#if 0
+int gtk_xine_set_audio_compression (GtkXine *xine, int level)
+{
+}
+
+int gtk_xine_get_audio_compression (GtkXine *xine)
+{
+}
+
+int gtk_xine_set_audio_amplify (GtkXine *xine, int level)
+{
+}
+
+int gtk_xine_get_audio_amplify (GtkXine *xine)
+{
+}
+
+int gtk_xine_set_report (GtkXine *xine, int on)
+{
+}
+
+int gtk_xine_get_report (GtkXine *xine)
+{
+}
+
+int gtk_xine_set_verbosity (GtkXine *xine, int level)
+{
+}
+
+int gtk_xine_get_verbosity (GtkXine *xine)
+{
+}
+#endif




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf