From: <ds...@fr...> - 2004-07-28 08:21:32
|
CVS Root: /home/cvs/gstreamer Module: gst-sandbox Changes by: ds Date: Wed Jul 28 2004 18:21:31 EST Log message: * src/gst-mozilla-player.c: (main), (new_gtk_window), (button_press_event): Add a prototype popup menu. * src/plugin.c: (plugin_thread), (plugin_newp), (plugin_destroy), (plugin_write_ready), (plugin_write): Add a thread which notices when the helper app dies, and redirects the browser to bugzilla. Modified files: gst-mozilla-plugin: ChangeLog gst-mozilla-plugin/src: gst-mozilla-player.c plugin.c Links: http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-sandbox/gst-mozilla-plugin/ChangeLog.diff?r1=1.4&r2=1.5 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-sandbox/gst-mozilla-plugin/src/gst-mozilla-player.c.diff?r1=1.3&r2=1.4 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-sandbox/gst-mozilla-plugin/src/plugin.c.diff?r1=1.4&r2=1.5 ====Begin Diffs==== Index: ChangeLog =================================================================== RCS file: /home/cvs/gstreamer/gst-sandbox/gst-mozilla-plugin/ChangeLog,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- ChangeLog 28 Jul 2004 05:59:21 -0000 1.4 +++ ChangeLog 28 Jul 2004 08:21:18 -0000 1.5 @@ -1,3 +1,11 @@ +2004-07-28 David Schleef <ds...@sc...> + + * src/gst-mozilla-player.c: (main), (new_gtk_window), + (button_press_event): Add a prototype popup menu. + * src/plugin.c: (plugin_thread), (plugin_newp), (plugin_destroy), + (plugin_write_ready), (plugin_write): Add a thread which notices + when the helper app dies, and redirects the browser to bugzilla. 2004-07-27 David Schleef <ds...@sc...> * src/formats.c: rewrite to use a struct instead of a char * Index: gst-mozilla-player.c RCS file: /home/cvs/gstreamer/gst-sandbox/gst-mozilla-plugin/src/gst-mozilla-player.c,v retrieving revision 1.3 diff -u -d -r1.3 -r1.4 --- gst-mozilla-player.c 28 Jul 2004 05:59:21 -0000 1.3 +++ gst-mozilla-player.c 28 Jul 2004 08:21:19 -0000 1.4 @@ -74,6 +74,7 @@ static void destroy_cb (GtkWidget *widget, gpointer data); static void embedded (GtkPlug *plug, gpointer data); static int expose_cb (GtkWidget *widget, GdkEventExpose *evt, gpointer data); +static int button_press_event (GtkWidget *widget, GdkEventButton *evt, gpointer data); static int key_press (GtkWidget *widget, GdkEventKey *evt, gpointer data); static int motion_notify (GtkWidget *widget, GdkEventMotion *evt, gpointer data); static int configure_cb (GtkWidget *widget, GdkEventConfigure *evt, gpointer data); @@ -103,7 +104,7 @@ int c; int index; GError *error; - int log_fd; + //int log_fd; static struct option options[] = { { "xid", 1, NULL, 'x' }, { "width", 1, NULL, 'w' }, @@ -115,8 +116,10 @@ { 0 }, }; +#if 0 log_fd = g_file_open_tmp ("gst-mozilla-plugin.log.XXXXXX", NULL, NULL); dup2(log_fd, 2); +#endif gst_init(&argc,&argv); @@ -181,12 +184,12 @@ src = gst_element_factory_make ("appsrc", NULL); g_assert(src); #if 0 - { + if (strcmp(argv[optind],"-") != 0) { gchar *contents; int length; - //g_file_get_contents(argv[optind],&contents,&length,NULL); - g_file_get_contents("/home/ds/media/alien.mpg",&contents,&length,NULL); + g_file_get_contents(argv[optind],&contents,&length,NULL); gst_appsrc_add_data(GST_APPSRC(src), contents, length); } #endif @@ -285,10 +288,12 @@ g_signal_connect (G_OBJECT (video_widget), "size_allocate", GTK_SIGNAL_FUNC(video_widget_allocate), NULL); - g_signal_connect (G_OBJECT(gtk_wind), "key_press_event", + g_signal_connect (G_OBJECT(video_widget), "key_press_event", GTK_SIGNAL_FUNC(key_press), NULL); - g_signal_connect (G_OBJECT(gtk_wind), "motion_notify_event", + g_signal_connect (G_OBJECT(video_widget), "motion_notify_event", GTK_SIGNAL_FUNC(motion_notify), NULL); + g_signal_connect (G_OBJECT(video_widget), "button_press_event", + GTK_SIGNAL_FUNC(button_press_event), NULL); gtk_widget_add_events(gtk_wind, GDK_POINTER_MOTION_MASK); @@ -313,6 +318,29 @@ /* GTK callbacks */ +static int button_press_event (GtkWidget *widget, GdkEventButton *evt, gpointer data) +{ + GtkWidget *menu; + if(debug)fprintf(stderr,"button\n"); + if (evt->button == 3) { + GtkWidget *item; + menu = gtk_menu_new(); + item = gtk_menu_item_new_with_label("Moo"); + gtk_menu_shell_append(GTK_MENU_SHELL(menu),item); + item = gtk_menu_item_new_with_label("File bug..."); + gtk_widget_show_all (menu); + gtk_menu_popup (GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, evt->time); + } + + return FALSE; +} static int key_press (GtkWidget *widget, GdkEventKey *evt, gpointer data) { if(debug)fprintf(stderr,"key press\n"); Index: plugin.c RCS file: /home/cvs/gstreamer/gst-sandbox/gst-mozilla-plugin/src/plugin.c,v --- plugin.c 28 Jul 2004 05:59:21 -0000 1.4 +++ plugin.c 28 Jul 2004 08:21:19 -0000 1.5 @@ -17,12 +17,17 @@ * Boston, MA 02111-1307, USA. */ +#ifdef HAVE_CONFIG_H +#include "config.h" #include <stdio.h> #include <stdint.h> #include <unistd.h> #include <fcntl.h> #include <sys/wait.h> -#include <config.h> +#include <pthread.h> +#include <errno.h> #include <X11/Xlib.h> #include <X11/Intrinsic.h> @@ -47,6 +52,8 @@ void *buffer_data; int buffer_len; int buffer_offset; + pthread_t thread; + int run_thread; }Plugin; @@ -183,6 +190,69 @@ return NULL; } +static void * +plugin_thread (void *arg) + Plugin *plugin = arg; + DEBUG("starting thread"); + while (plugin->run_thread) { + fd_set read_fds; + fd_set except_fds; + struct timeval timeout; + int max_fd = 0; + int ret; + FD_ZERO (&read_fds); + FD_ZERO (&except_fds); + timeout.tv_sec = 1; + timeout.tv_usec = 0; + if (plugin->recv_fd > 0) { + FD_SET (plugin->recv_fd, &read_fds); + FD_SET (plugin->recv_fd, &except_fds); + max_fd = plugin->recv_fd; + } + ret = select (max_fd + 1, &read_fds, NULL, &except_fds, &timeout); + if (ret < 0) { + fprintf(stderr, "select failed %d\n", errno); + } else if (ret == 0) { + /* timeout */ + } else { + if (plugin->recv_fd > 0 && FD_ISSET(plugin->recv_fd, &read_fds)) { + char buf[100]; + int n; + fprintf(stderr, "something to read\n"); + n = read(plugin->recv_fd, buf, 100); + if (n < 0) { + fprintf(stderr, "read returned %d (%d)\n", n, errno); + } else if (n == 0) { + /* this means the child closed the descriptor, i.e., died */ + fprintf(stderr, "read returned 0\n"); + close (plugin->recv_fd); + plugin->recv_fd = -1; + mozilla_funcs.geturl (plugin->instance, + "http://bugzilla.gnome.org", "_self"); + } else { + fprintf(stderr, "%.*s", n, buf); + } + } + if (plugin->recv_fd > 0 && FD_ISSET(plugin->recv_fd, &except_fds)) { + fprintf(stderr, "some exception\n"); + + DEBUG("stopping thread"); + return NULL; static NPError plugin_newp(NPMIMEType mime_type, NPP instance, uint16_t mode, int16_t argc, char *argn[], char *argv[], NPSavedData *saved) @@ -215,6 +285,9 @@ } } + plugin->run_thread = TRUE; + pthread_create (&plugin->thread, NULL, plugin_thread, plugin); return NPERR_NO_ERROR; @@ -238,6 +311,9 @@ kill(plugin->player_pid, SIGKILL); waitpid(plugin->player_pid, &status,0); + plugin->run_thread = FALSE; + pthread_join (plugin->thread, NULL); mozilla_funcs.memfree(instance->pdata); instance->pdata = NULL; @@ -304,7 +380,7 @@ Plugin *plugin; - DEBUG("plugin_write_ready"); + //DEBUG("plugin_write_ready"); if (instance == NULL){ DEBUG("plugin_write_ready instance is NULL"); @@ -321,7 +397,7 @@ int ret; - DEBUG("plugin_write"); + //DEBUG("plugin_write"); if (instance == NULL) return 0; plugin = (Plugin *) instance->pdata; |