From: Steve B. <sb...@us...> - 2002-06-09 15:53:18
|
CVS Root: /cvsroot/gstreamer Module: gst-player Changes by: sbaker3 Date: Sun Jun 09 2002 08:53:17 PDT Log message: a player that seeks, hoo gra! Modified files: libs/gst/player : gstcontrol.c gstcontrol.h gstmediaplay.c gstmediaplay.h Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gst-player/libs/gst/player/gstcontrol.c.diff?r1=1.14&r2=1.15 http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gst-player/libs/gst/player/gstcontrol.h.diff?r1=1.4&r2=1.5 http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gst-player/libs/gst/player/gstmediaplay.c.diff?r1=1.41&r2=1.42 http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gst-player/libs/gst/player/gstmediaplay.h.diff?r1=1.13&r2=1.14 ====Begin Diffs==== Index: gstcontrol.c =================================================================== RCS file: /cvsroot/gstreamer/gst-player/libs/gst/player/gstcontrol.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- gstcontrol.c 19 May 2002 01:19:13 -0000 1.14 +++ gstcontrol.c 9 Jun 2002 15:53:05 -0000 1.15 @@ -14,15 +14,17 @@ GtkWidget *button_list; GtkWidget *button_mini; - GObject *adjustment; + GObject *adjustment_volume; GtkWidget *hscale_volume; + GObject *adjustment_seek; + GtkWidget *hscale_seek; + gboolean seek_in_progress; + GtkWidget *image_playing; GtkWidget *image_paused; GtkWidget *event_box_mini; - GtkWidget *image_seek; - GtkWidget *image_seek_small; GtkWidget *image_volume; }; @@ -34,6 +36,7 @@ BUTTON_LIST, MINI_MODE, VOLUME_CHANGE, + SEEK_CHANGE, LAST_SIGNAL }; @@ -90,12 +93,10 @@ gtk_widget_hide (priv->button_next); gtk_widget_hide (priv->button_list); gtk_widget_hide (priv->hscale_volume); - gtk_widget_hide (priv->image_seek); gtk_widget_hide (priv->image_volume); - gtk_widget_show (priv->image_seek_small); gtk_fixed_move (GTK_FIXED (priv->fixed), priv->button_play, 6, 4); - gtk_fixed_move (GTK_FIXED (priv->fixed), priv->image_seek_small, 60, 5); + gtk_fixed_move (GTK_FIXED (priv->fixed), priv->hscale_seek, 60, 5); gtk_image_set_from_pixmap_file (GTK_IMAGE (priv->button_mini), "mini-up.png"); gtk_fixed_move (GTK_FIXED (priv->fixed), priv->event_box_mini, 300, 3); @@ -111,13 +112,12 @@ gtk_widget_show (priv->button_next); gtk_widget_show (priv->button_list); gtk_widget_show (priv->hscale_volume); - gtk_widget_show (priv->image_seek); + gtk_widget_show (priv->hscale_seek); gtk_widget_show (priv->image_volume); - gtk_widget_hide (priv->image_seek_small); gtk_fixed_move (GTK_FIXED (priv->fixed), priv->button_play, 81, 36); - gtk_fixed_move (GTK_FIXED (priv->fixed), priv->image_seek_small, 60, 13); - + gtk_fixed_move (GTK_FIXED (priv->fixed), priv->hscale_seek, 60, 13); + gtk_image_set_from_pixmap_file (GTK_IMAGE (priv->button_mini), "mini-down.png"); gtk_fixed_move (GTK_FIXED (priv->fixed), priv->event_box_mini, 300, 12); @@ -141,6 +141,26 @@ g_signal_emit (control, gst_control_signals [VOLUME_CHANGE], 0, adjustment->value); } +static gboolean +seek_changed (GtkWidget *widget, GdkEventButton *event, GstControl *control) +{ + g_return_if_fail (GST_IS_CONTROL (control)); + g_print("do seek\n"); + g_signal_emit (control, gst_control_signals [SEEK_CHANGE], 0, + gtk_adjustment_get_value(GTK_ADJUSTMENT(control->_priv->adjustment_seek))); + control->_priv->seek_in_progress = FALSE; + return FALSE; +} + +static gboolean +seek_started (GtkWidget *widget, GdkEventButton *event, GstControl *control) +{ + g_return_if_fail (GST_IS_CONTROL (control)); + g_print("start seek\n"); + control->_priv->seek_in_progress = TRUE; + return FALSE; +} + static void gst_control_class_init (GstControlClass *class) { @@ -220,6 +240,16 @@ G_TYPE_NONE, 1, G_TYPE_DOUBLE); + gst_control_signals [SEEK_CHANGE] = + g_signal_new ("seek_change", + G_TYPE_FROM_CLASS (gobject_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (GstControlClass, seek_change), + NULL, NULL, + g_cclosure_marshal_VOID__DOUBLE, + G_TYPE_NONE, 1, + G_TYPE_DOUBLE); + class->button_play = NULL; class->button_stop = NULL; class->button_next = NULL; @@ -237,7 +267,6 @@ GtkWidget *button; GtkWidget *hbox; GtkWidget *event_box; - GObject *adjustment; GtkWidget *slider; control->_priv = g_new0 (GstControlPrivate, 1); @@ -247,24 +276,28 @@ gtk_widget_set_usize (priv->fixed, 320, 61); gtk_box_pack_start (GTK_BOX (control), priv->fixed, TRUE, TRUE, 0); - priv->image_seek = gtk_image_new_from_pixmap_file ("seek.png"); - gtk_fixed_put (GTK_FIXED (priv->fixed), priv->image_seek, 10, 13); - gtk_widget_set_usize (priv->image_seek, 281, 17); - - priv->image_seek_small = gtk_image_new_from_pixmap_file ("seek-small.png"); - gtk_fixed_put (GTK_FIXED (priv->fixed), priv->image_seek_small, 60, 13); - gtk_widget_set_usize (priv->image_seek_small, 231, 17); + priv->adjustment_seek = G_OBJECT (gtk_adjustment_new (0.0, 0.0, 1.0, 0.1, 0.10, 0.10)); + priv->hscale_seek = gtk_hscale_new (GTK_ADJUSTMENT (priv->adjustment_seek)); + gtk_scale_set_draw_value (GTK_SCALE (priv->hscale_seek), FALSE); + gtk_fixed_put (GTK_FIXED (priv->fixed), priv->hscale_seek, 60, 13); + gtk_widget_set_usize (priv->hscale_seek, 231, 17); + g_signal_connect (GTK_OBJECT (priv->hscale_seek), "button_press_event", + G_CALLBACK (seek_started), control); + g_signal_connect (GTK_OBJECT (priv->hscale_seek), "button_release_event", + G_CALLBACK (seek_changed), control); + gtk_widget_set_sensitive(priv->hscale_seek, FALSE); + control->_priv->seek_in_progress = FALSE; priv->image_volume = gtk_image_new_from_pixmap_file ("volume.png"); gtk_fixed_put (GTK_FIXED (priv->fixed), priv->image_volume, 176, 38); gtk_widget_set_usize (priv->image_volume, 16, 16); - - priv->adjustment = G_OBJECT (gtk_adjustment_new (0.9, 0.0, 1.0, 0.1, 0.10, 0.10)); - priv->hscale_volume = gtk_hscale_new (GTK_ADJUSTMENT (priv->adjustment)); + + priv->adjustment_volume = G_OBJECT (gtk_adjustment_new (0.9, 0.0, 1.0, 0.1, 0.10, 0.10)); + priv->hscale_volume = gtk_hscale_new (GTK_ADJUSTMENT (priv->adjustment_volume)); gtk_scale_set_draw_value (GTK_SCALE (priv->hscale_volume), FALSE); gtk_fixed_put (GTK_FIXED (priv->fixed), priv->hscale_volume, 194, 37); gtk_widget_set_usize (priv->hscale_volume, 66, 17); - g_signal_connect (G_OBJECT (priv->adjustment), "value_changed", + g_signal_connect (G_OBJECT (priv->adjustment_volume), "value_changed", G_CALLBACK (volume_changed), control); priv->button_list = gtk_button_new (); @@ -318,7 +351,6 @@ gtk_widget_pop_colormap (); gtk_widget_show_all (priv->fixed); - gtk_widget_hide (priv->image_seek_small); } static void @@ -376,4 +408,23 @@ gst_control_set_mini_mode (GstControl *control) { set_mini_mode (control); +} + +void +gst_control_set_enable_seek (GstControl* control, gboolean enable) +{ + g_return_if_fail (GST_IS_CONTROL (control)); + gtk_widget_set_sensitive(control->_priv->hscale_seek, enable); + gtk_adjustment_set_value(GTK_ADJUSTMENT(control->_priv->adjustment_seek), 0.0); +} + +void +gst_control_set_seek_pos (GstControl* control, gdouble seek_pos) +{ + g_return_if_fail (GST_IS_CONTROL (control)); + + if (control->_priv->seek_in_progress == FALSE){ + g_print("tick\n"); + gtk_adjustment_set_value(GTK_ADJUSTMENT(control->_priv->adjustment_seek), seek_pos); + } } Index: gstcontrol.h =================================================================== RCS file: /cvsroot/gstreamer/gst-player/libs/gst/player/gstcontrol.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- gstcontrol.h 6 May 2002 10:46:25 -0000 1.4 +++ gstcontrol.h 9 Jun 2002 15:53:05 -0000 1.5 @@ -34,12 +34,14 @@ void (*button_list) (GstControl *control); void (*mini_mode) (GstControl *control); void (*volume_change) (GstControl *control); + void (*seek_change) (GstControl *control); }; GtkType gst_control_get_type (void); GtkWidget* gst_control_new (void); void gst_control_set_mini_mode (GstControl *control); +void gst_control_set_enable_seek (GstControl* control, gboolean enable); G_END_DECLS Index: gstmediaplay.c =================================================================== RCS file: /cvsroot/gstreamer/gst-player/libs/gst/player/gstmediaplay.c,v retrieving revision 1.41 retrieving revision 1.42 diff -u -d -r1.41 -r1.42 --- gstmediaplay.c 7 Jun 2002 19:54:57 -0000 1.41 +++ gstmediaplay.c 9 Jun 2002 15:53:05 -0000 1.42 @@ -32,6 +32,8 @@ void gst_media_play_set_volume (GtkWidget *widget, gdouble value, GstMediaPlay *mplay); void gst_media_play_play_next (GtkWidget *widget, GstMediaPlay *mplay); +static void gst_media_play_seek_to_pos (GtkWidget *widget, gdouble value, GstMediaPlay *mplay); + static void gst_media_play_mini_mode (GtkWidget *widget, GstMediaPlay *mplay); static void gst_media_play_set_mini_mode (GtkWidget *widget, GstMediaPlay *mplay); static void gst_media_play_half_size (GtkWidget *widget, GstMediaPlay *mplay); @@ -44,6 +46,9 @@ static void gst_media_play_set_selected (GtkWidget *widget, GstMediaPlay *mplay); static void gst_media_play_show_playlist (GtkWidget *widget, GstMediaPlay *mplay); +static void gst_media_play_time_tick (GstPlay *play, gint64 time_nanos, GstMediaPlay *mplay); +static void gst_media_play_got_length (GstPlay *play, gint64 length_nanos, GstMediaPlay *mplay); + static GObject *parent_class = NULL; static GnomeUIInfo file_menu [] = @@ -166,7 +171,6 @@ { _gstplay_stock_icons_init (); } - static void gst_media_play_init (GstMediaPlay *mplay) { @@ -176,6 +180,10 @@ mplay->play = gst_play_new (GST_PLAY_PIPE_VIDEO_THREADSAFE); g_signal_connect (G_OBJECT (mplay->play), "stream_end", G_CALLBACK (gst_media_play_play_next), mplay); + g_signal_connect (G_OBJECT (mplay->play), "time_tick", + G_CALLBACK (gst_media_play_time_tick), mplay); + g_signal_connect (G_OBJECT (mplay->play), "stream_length", + G_CALLBACK (gst_media_play_got_length), mplay); mplay->window = gnome_app_new ("gst-player", "GStreamer Player"); gtk_window_set_default_size (GTK_WINDOW (mplay->window), 300, -1); @@ -217,6 +225,8 @@ G_CALLBACK (gst_media_play_mini_mode), mplay); g_signal_connect (G_OBJECT (mplay->control), "volume_change", G_CALLBACK (gst_media_play_set_volume), mplay); + g_signal_connect (G_OBJECT (mplay->control), "seek_change", + G_CALLBACK (gst_media_play_seek_to_pos), mplay); mplay->playlist = gst_playlist_new (); gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (mplay->playlist), 1, 1, 0); @@ -378,6 +388,7 @@ gst_play_set_volume (mplay->play, value); } + void gst_media_play_play_next (GtkWidget *widget, GstMediaPlay *mplay) { @@ -443,6 +454,15 @@ } static void +gst_media_play_seek_to_pos (GtkWidget *widget, gdouble value, GstMediaPlay *mplay) +{ + gdouble length_nanos = (gdouble)mplay->length_nanos; + gint64 seek_time = (gint64)(length_nanos * value); + g_print ("seeking to %lld out of %lld\n", seek_time, mplay->length_nanos); + gst_play_seek_to_time (mplay->play, seek_time); +} + +static void gst_media_play_mini_mode (GtkWidget *widget, GstMediaPlay *mplay) { if (GTK_WIDGET_VISIBLE (GNOME_APP (mplay->window)->menubar) == TRUE) @@ -538,3 +558,28 @@ gtk_widget_show (mplay->playlist); } } + +static void +gst_media_play_time_tick (GstPlay *play, gint64 time_nanos, GstMediaPlay *mplay) +{ + gdouble seek_pos = ((gdouble) time_nanos) / ((gdouble) mplay->length_nanos); + gint seconds = (gint) (time_nanos / GST_SECOND); + g_print("time: %02d:%02d\n", seconds/60, seconds%60); + gst_control_set_seek_pos (mplay->control, seek_pos); +} + +static void +gst_media_play_got_length (GstPlay *play, gint64 length_nanos, GstMediaPlay *mplay) +{ + gint seconds = (gint) (length_nanos / GST_SECOND); + if (length_nanos > 0LL){ + g_print("stream is %02dmin %02dsec long\n", seconds/60, seconds%60); + } + else { + g_print("stream length is unknown\n"); + } + mplay->length_nanos = length_nanos; + gst_control_set_enable_seek (GST_CONTROL (mplay->control), TRUE); +} + + Index: gstmediaplay.h =================================================================== RCS file: /cvsroot/gstreamer/gst-player/libs/gst/player/gstmediaplay.h,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- gstmediaplay.h 31 May 2002 18:55:08 -0000 1.13 +++ gstmediaplay.h 9 Jun 2002 15:53:05 -0000 1.14 @@ -27,6 +27,7 @@ GtkWidget *playlist; gchar *filename; + gint64 length_nanos; }; struct _GstMediaPlayClass |