sinek/src gtkxine.c,NONE,1.1 Makefile.am,1.9,1.10
[email protected] Sun, 05 Jan 2003 01:10:21 -0800
| Newsgroups | gmane.comp.video.sinek.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/sinek/sinek/src In directory sc8-pr-cvs1:/tmp/cvs-serv18797 Modified Files: Makefile.am Added Files: gtkxine.c Log Message: dunno if this even compiles; committed in case i do something stupid (like rm -rf) --- NEW FILE: gtkxine.c --- /* ** Sinek (Media Player) ** Copyright (c) 2002 Andres Salomon <[email protected]> ** ** This code is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License. ** ** $Id: gtkxine.c,v 1.1 2003/01/05 09:10:18 dilinger Exp $ */ #include "gtkxine.h" #include <gtk/gtk.h> #include <gdk/gdkx.h> #include <xine.h> #include <xine/video_out_x11.h> #include <math.h> #include <libintl.h> #ifdef HAVE_CONFIG_H #include <config.h> #endif struct _GtkXine { GtkWidget parent; xine_t *xine; char *conf_file; char *video_driver; char *audio_driver; char *display_name; 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 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->ao_driver = NULL; xine->vo_driver = NULL; xine->conf = NULL; xine->video_win_title = g_strdup ("Xine Video Output"); /* XXX: is this correct? */ gtk_set_locale (); xine_set_locale (); bindtextdomain (PACKAGE, XINE_LOCALEDIR); bind_textdomain_codeset (PACKAGE, "UTF-8"); textdomain (PACKAGE); } static void gtk_xine_build_audio_out (GtkXine *xine) { char *id, **driver_ids; int i; id = xine->conf->register_string (xine->conf, "audio.driver", "auto", "audio driver to use", NULL, NULL, NULL); if (xine->audio_driver) id = xine->audio_driver; if (strcmp (id, "null") != 0) { if (strcmp (id, "auto") != 0) xine->ao_driver = xine_load_audio_output_plugin (xine->conf, id); /* try guessing, if no audio driver is loaded at this point */ if (xine->ao_driver == NULL) { driver_ids = xine_list_audio_output_plugins (); for (i = 0; xine->ao_driver == NULL && driver_ids[i] != NULL; i++) { xine->ao_driver = xine_load_audio_output_plugin (xine->conf, driver_ids[i]); } g_strfreev (driver_ids); } } if (xine->ao_driver == NULL) id = "null"; xine->conf->update_string (xine->conf, "audio.driver", id); } #if 0 static int video_window_expose_event_cb (GtkWidget *w, GtkXine *xine) { g_print ("%s()\n", __FUNCTION__); gdk_draw_arc (w->window, w->style->fg_gc[GTK_WIDGET_STATE (w)], TRUE, 0, 0, w->allocation.width, w->allocation.height, 0, 64 * 360); return TRUE; } #endif #if 0 static void gtk_xine_frame_output_cb (GtkXine *xine, int vid_w, int vid_h, int *dest_x, int *dest_y, int *dest_w, int *dest_h, int *win_x, int *win_y) { *dest_x = 0; *dest_y = 0; *dest_w = xine->visual.video_width; *dest_h = xine->visual.video_height; /* TODO: cache x/y in GtkXine struct, update for every move signal */ gtk_window_get_position (GTK_WINDOW (xine->video_win), win_x, win_y); g_print ("%s(): x=%d,y=%d,w=%d,h=%d; window x=%d,y=%d\n", __FUNCTION__, *dest_x, *dest_y, *dest_w, *dest_h, *win_x, *win_y); } static void gtk_xine_dest_size_cb (void *widget, int vid_w, int vid_h, int *dest_w, int *dest_h) { GtkXine *xine = GTK_XINE (widget); *dest_w = xine->visual.video_width; *dest_h = xine->visual.video_height; } static GtkWidget *gtk_xine_build_video_out_window (GtkXine *xine) { int horiz, vert; GtkWidget *video_area; x11_visual_t visual; xine->visual.video_width = xine->conf->register_num (xine->conf, "video.win_width", 320, "video output window width", NULL, NULL, NULL); xine->visual.video_height = xine->conf->register_num (xine->conf, "video.win_height", 160, "video output window height", NULL, NULL, NULL); xine->video_win = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (xine->video_win), xine->video_win_title); gtk_window_set_policy (GTK_WINDOW (xine->video_win), TRUE, TRUE, FALSE); video_area = gtk_drawing_area_new (); gtk_widget_set_size_request (video_area, xine->visual.video_width, xine->visual.video_height); //gtk_widget_modify_bg (video_area, //g_signal_connect (G_OBJECT (video_area), "expose_event", G_CALLBACK (video_window_expose_event_cb), xine); // TODO: catch resizes! gtk_container_add (GTK_CONTAINER (xine->video_win), video_area); gtk_widget_show_all (xine->video_win); //gtk_widget_realize (video_area); visual.display = GDK_WINDOW_XDISPLAY (video_area->window); visual.screen = gdk_x11_get_default_screen (); visual.d = GDK_WINDOW_XWINDOW (video_area->window); horiz = (DisplayWidth (visual.display, visual.screen) * 1000) / DisplayWidthMM (visual.display, visual.screen); vert = (DisplayHeight (visual.display, visual.screen) * 1000) / DisplayHeightMM (visual.display, visual.screen); visual.display_ratio = horiz / vert; visual.frame_output_cb = gtk_xine_frame_output_cb; visual.dest_size_cb = gtk_xine_dest_size_cb; visual.user_data = (void *) xine; if (fabs (visual.display_ratio - 1.0) < 0.01) visual.display_ratio = 1.0; //gtk_main(); //sleep(20); //exit(2); //return xine->video_win; return visual; } static void gtk_xine_build_video_out (GtkXine *xine) { x11_visual_t vis; char *id, **driver_ids; double res_h, res_v; int i; id = xine->conf->register_string (xine->conf, "video.driver", "auto", "video driver to use", NULL, NULL, NULL); if (xine->video_driver) id = xine->video_driver; if (strcmp (id, "null") != 0) { vis = gtk_xine_build_video_out_window (xine); xine->visual.display = vis.display; xine->visual.screen = vis.screen; xine->visual.display_ratio = vis.display_ratio; xine->visual.d = vis.d; xine->visual.user_data = vis.user_data; xine->visual.dest_size_cb = vis.dest_size_cb; xine->visual.frame_output_cb = vis.frame_output_cb; xine->visual.depth = gdk_drawable_get_depth (GDK_DRAWABLE (xine->video_win->window)); /* fill in x11_visual_t info */ #if 0 if(XShmQueryExtension(di->display) == True) MyShmEvent = XShmGetEventBase(di->display) + ShmCompletion; #endif #if 0 if (xine->display_name) { vis.display = XOpenDisplay (xine->display_name); if (!vis.display) g_error ("Cannot connect to display '%s'.\n", xine->display_name); XLockDisplay (vis.display); vis.screen = DefaultScreen (vis.display); } else { vis.display = XOpenDisplay (gdk_get_display ()); XLockDisplay (vis.display); vis.screen = gdk_x11_get_default_screen (); } #endif if (strcmp (id, "auto") != 0) xine->vo_driver = xine_load_video_output_plugin (xine->conf, id, VISUAL_TYPE_GTK, (void *) &vis); /* try guessing, if no video driver is loaded at this point */ if (xine->vo_driver == NULL) { driver_ids = xine_list_video_output_plugins (VISUAL_TYPE_GTK); for (i = 0; xine->vo_driver == NULL && driver_ids[i] != NULL; i++) { xine->vo_driver = xine_load_video_output_plugin (xine->conf, driver_ids[i], VISUAL_TYPE_GTK, (void *) &vis); } g_strfreev (driver_ids); } //XUnlockDisplay (vis.display); } if (xine->vo_driver == NULL) id = "null"; xine->conf->update_string (xine->conf, "video.driver", id); } #endif static void gtk_xine_build_video_out (GtkXine *xine) { char *id, **driver_ids; double res_h, res_v; int width, height; GtkWidget *video_area; int i; id = xine->conf->register_string (xine->conf, "video.driver", "auto", "video driver to use", NULL, NULL, NULL); if (xine->video_driver) id = xine->video_driver; if (strcmp (id, "null") != 0) { /* create video window */ width = xine->conf->register_num (xine->conf, "video.win_width", 320, "video output window width", NULL, NULL, NULL); height = xine->conf->register_num (xine->conf, "video.win_height", 160, "video output window height", NULL, NULL, NULL); xine->video_win = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (xine->video_win), xine->video_win_title); gtk_window_set_policy (GTK_WINDOW (xine->video_win), FALSE, FALSE, FALSE); /* TODO: allow resizing */ video_area = gtk_drawing_area_new (); gtk_widget_set_size_request (video_area, width, height); //g_signal_connect (G_OBJECT (video_area), "expose_event", G_CALLBACK (video_window_expose_event_cb), xine); //g_signal_connect (G_OBJECT (video_area), "configure_event", G_CALLBACK (video_window_configure_event_cb), xine); gtk_container_add (GTK_CONTAINER (xine->video_win), video_area); gtk_widget_show_all (xine->video_win); //gtk_widget_realize (video_area); //horiz = (DisplayWidth (visual.display, visual.screen) * 1000) / DisplayWidthMM (visual.display, visual.screen); //vert = (DisplayHeight (visual.display, visual.screen) * 1000) / DisplayHeightMM (visual.display, visual.screen); //visual.display_ratio = horiz / vert; //visual.frame_output_cb = gtk_xine_frame_output_cb; //visual.dest_size_cb = gtk_xine_dest_size_cb; //visual.user_data = (void *) xine; //if (fabs (visual.display_ratio - 1.0) < 0.01) //visual.display_ratio = 1.0; g_print("%s(): id=%s\n", __FUNCTION__, id); if (strcmp (id, "auto") != 0) xine->vo_driver = xine_load_video_output_plugin (xine->conf, id, VISUAL_TYPE_GTK, (void *) video_area); /* try guessing, if no video driver is loaded at this point */ if (xine->vo_driver == NULL) { driver_ids = xine_list_video_output_plugins (VISUAL_TYPE_GTK); for (i = 0; xine->vo_driver == NULL && driver_ids[i] != NULL; i++) { g_print("%s(): trying %s\n", __FUNCTION__, driver_ids[i]); xine->vo_driver = xine_load_video_output_plugin (xine->conf, driver_ids[i], VISUAL_TYPE_GTK, (void *) video_area); } g_strfreev (driver_ids); } } if (xine->vo_driver == NULL) id = "null"; xine->conf->update_string (xine->conf, "video.driver", id); } static void gtk_xine_build (GtkXine *xine) { g_print ("%s()\n", __FUNCTION__); xine->conf = xine_config_file_init (xine->conf_file); gtk_xine_build_audio_out (xine); gtk_xine_build_video_out (xine); xine->xine = xine_init (xine->vo_driver, xine->ao_driver, xine->conf); } static void gtk_xine_dispose (GObject *obj) { GtkXine *xine = GTK_XINE (obj); GtkWidgetClass *parent = g_type_class_peek (GTK_TYPE_WIDGET); 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); if (G_OBJECT_CLASS (parent)->dispose) G_OBJECT_CLASS (parent)->dispose (obj); } static void gtk_xine_class_init (GtkXineClass *class) { GObjectClass *gobj_class = G_OBJECT_CLASS (class); GtkWidgetClass *gtkwid_class = GTK_WIDGET_CLASS (class); g_print ("%s()\n", __FUNCTION__); /* gobj_class->finalize = gtk_xine_finalize; */ gobj_class->dispose = gtk_xine_dispose; /* gobj_class->{set,get}_property = */ /* g_object_class_set_property (klass, .... ) */ } GtkType gtk_xine_get_type (void) { static GType type = 0; if (!type) { static const GTypeInfo info = { sizeof (GtkXineClass), NULL, NULL, (GClassInitFunc) gtk_xine_class_init, NULL, NULL, sizeof (GtkXine), 0, (GInstanceInitFunc) gtk_xine_init }; type = g_type_register_static (GTK_TYPE_WIDGET, "GtkXine", &info, 0); } return (GtkType) type; } 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) { GtkXine *xine; g_print ("%s\n", __FUNCTION__); 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); } void gtk_xine_select_config_file (GtkXine *xine, const char *fname) { g_return_if_fail (xine->xine == NULL); g_free (xine->conf_file); xine->conf_file = g_strdup (fname); } void gtk_xine_select_audio_driver (GtkXine *xine, const char *name) { g_return_if_fail (xine->xine == NULL); if (xine->audio_driver) g_free (xine->audio_driver); xine->audio_driver = g_strdup (name); } void gtk_xine_select_video_driver (GtkXine *xine, const char *name) { g_return_if_fail (xine->xine == NULL); if (xine->video_driver) g_free (xine->video_driver); xine->video_driver = g_strdup (name); } void gtk_xine_select_display (GtkXine *xine, const char *display_name) { g_return_if_fail (xine->xine == NULL); if (xine->display_name) g_free (xine->display_name); xine->display_name = g_strdup (display_name); } void gtk_xine_load (GtkXine *xine, const char *mrl) { if (xine->xine == NULL) gtk_xine_build (xine); } void gtk_xine_select_audio_channel (GtkXine *xine, int channel) { if (xine->xine == NULL) gtk_xine_build (xine); xine_select_audio_channel (xine->xine, channel); } void gtk_xine_select_spu_channel (GtkXine *xine, int channel) { if (xine->xine == NULL) gtk_xine_build (xine); xine_select_spu_channel (xine->xine, channel); } void gtk_xine_set_volume (GtkXine *xine, int volume) { if (xine->xine == NULL) gtk_xine_build (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_volume (GtkXine *xine) { 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); } void gtk_xine_set_mute (GtkXine *xine, int mute) { if (xine_get_audio_capabilities(xine->xine) & AO_CAP_MUTE_VOL) xine_set_audio_property(xine->xine, AO_PROP_MUTE_VOL, mute); } void gtk_xine_set_speed (GtkXine *xine, GtkXinePlaybackSpeed speed) { 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 */ } } GtkXinePlaybackSpeed gtk_xine_get_speed (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; } } Index: Makefile.am =================================================================== RCS file: /cvsroot/sinek/sinek/src/Makefile.am,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- Makefile.am 29 Dec 2002 20:37:33 -0000 1.9 +++ Makefile.am 5 Jan 2003 09:10:18 -0000 1.10 @@ -30,4 +30,5 @@ subtitle.c \ $(guile_c) \ about.c \ + gtkxine.c \ xml.c ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf