From fb3d85f292802687cccb1e567ef610bcb9ddcd9d Mon Sep 17 00:00:00 2001 From: Stefan Kost Date: Thu, 4 Sep 2008 13:46:52 +0000 Subject: [PATCH] sys/xvimage/xvimagesink.*: Add a "draw-border" property that can be set to false to disable drawing borders. Original commit message from CVS: * sys/xvimage/xvimagesink.c: * sys/xvimage/xvimagesink.h: Add a "draw-border" property that can be set to false to disable drawing borders. * tests/icles/test-colorkey.c: * tests/icles/Makefile.am: Add new test application for the colorkey handling. --- ChangeLog | 11 +++ sys/xvimage/xvimagesink.c | 33 ++++++-- sys/xvimage/xvimagesink.h | 4 +- tests/icles/Makefile.am | 22 +++-- tests/icles/test-colorkey.c | 195 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 252 insertions(+), 13 deletions(-) create mode 100644 tests/icles/test-colorkey.c diff --git a/ChangeLog b/ChangeLog index e006b04..8df2623 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-09-04 Stefan Kost + + * sys/xvimage/xvimagesink.c: + * sys/xvimage/xvimagesink.h: + Add a "draw-border" property that can be set to false to disable + drawing borders. + + * tests/icles/test-colorkey.c: + * tests/icles/Makefile.am: + Add new test application for the colorkey handling. + 2008-09-03 Edward Hervey * gst-libs/gst/riff/riff-media.c: (gst_riff_create_audio_caps): diff --git a/sys/xvimage/xvimagesink.c b/sys/xvimage/xvimagesink.c index 07636b6..45f8e89 100644 --- a/sys/xvimage/xvimagesink.c +++ b/sys/xvimage/xvimagesink.c @@ -190,7 +190,8 @@ enum ARG_HANDLE_EXPOSE, ARG_DOUBLE_BUFFER, ARG_AUTOPAINT_COLORKEY, - ARG_COLORKEY + ARG_COLORKEY, + ARG_DRAW_BORDERS }; static GstVideoSinkClass *parent_class = NULL; @@ -761,7 +762,7 @@ gst_xvimagesink_xvimage_put (GstXvImageSink * xvimagesink, /* Draw borders when displaying the first frame. After this draw borders only on expose event or after a size change. */ - if (!xvimagesink->cur_image || xvimagesink->draw_border) { + if (!xvimagesink->cur_image || xvimagesink->redraw_border) { draw_border = TRUE; } @@ -778,8 +779,8 @@ gst_xvimagesink_xvimage_put (GstXvImageSink * xvimagesink, /* Expose sends a NULL image, we take the latest frame */ if (!xvimage) { - draw_border = TRUE; if (xvimagesink->cur_image) { + draw_border = TRUE; xvimage = xvimagesink->cur_image; } else { g_mutex_unlock (xvimagesink->flow_lock); @@ -806,10 +807,10 @@ gst_xvimagesink_xvimage_put (GstXvImageSink * xvimagesink, g_mutex_lock (xvimagesink->x_lock); - if (draw_border) { + if (draw_border && xvimagesink->draw_borders) { gst_xvimagesink_xwindow_draw_borders (xvimagesink, xvimagesink->xwindow, result); - xvimagesink->draw_border = FALSE; + xvimagesink->redraw_border = FALSE; } /* We scale to the window's geometry */ @@ -2079,7 +2080,7 @@ gst_xvimagesink_setcaps (GstBaseSink * bsink, GstCaps * caps) /* After a resize, we want to redraw the borders in case the new frame size * doesn't cover the same area */ - xvimagesink->draw_border = TRUE; + xvimagesink->redraw_border = TRUE; /* We renew our xvimage only if size or format changed; * the xvimage is the same size as the video pixel size */ @@ -2908,6 +2909,9 @@ gst_xvimagesink_set_property (GObject * object, guint prop_id, case ARG_AUTOPAINT_COLORKEY: xvimagesink->autopaint_colorkey = g_value_get_boolean (value); break; + case ARG_DRAW_BORDERS: + xvimagesink->draw_borders = g_value_get_boolean (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -2981,6 +2985,9 @@ gst_xvimagesink_get_property (GObject * object, guint prop_id, case ARG_COLORKEY: g_value_set_int (value, xvimagesink->colorkey); break; + case ARG_DRAW_BORDERS: + g_value_set_boolean (value, xvimagesink->draw_borders); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -3097,6 +3104,7 @@ gst_xvimagesink_init (GstXvImageSink * xvimagesink) xvimagesink->autopaint_colorkey = TRUE; xvimagesink->colorkey = -1; + xvimagesink->draw_borders = TRUE; } static void @@ -3215,6 +3223,19 @@ gst_xvimagesink_class_init (GstXvImageSinkClass * klass) "Color to use for the overlay mask", G_MININT, G_MAXINT, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + /** + * GstXvImageSink:draw-borders + * + * Draw black borders when using GstXvImageSink:force-aspect-ratio to fill + * unused parts of the video area. + * + * Since: 0.10.22 + */ + g_object_class_install_property (gobject_class, ARG_DRAW_BORDERS, + g_param_spec_boolean ("draw-borders", "Colorkey", + "Draw black borders to fill unused area in force-aspect-ratio mode", + TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + gobject_class->finalize = gst_xvimagesink_finalize; gstelement_class->change_state = diff --git a/sys/xvimage/xvimagesink.h b/sys/xvimage/xvimagesink.h index 295dce7..eec17c6 100644 --- a/sys/xvimage/xvimagesink.h +++ b/sys/xvimage/xvimagesink.h @@ -253,7 +253,7 @@ struct _GstXvImageSink { gboolean synchronous; gboolean double_buffer; gboolean keep_aspect; - gboolean draw_border; + gboolean redraw_border; gboolean handle_events; gboolean handle_expose; @@ -269,6 +269,8 @@ struct _GstXvImageSink { /* port attributes */ gboolean autopaint_colorkey; gint colorkey; + + gboolean draw_borders; }; struct _GstXvImageSinkClass { diff --git a/tests/icles/Makefile.am b/tests/icles/Makefile.am index faba6cb..34fddf5 100644 --- a/tests/icles/Makefile.am +++ b/tests/icles/Makefile.am @@ -1,21 +1,31 @@ if USE_X -X_TESTS = stress-xoverlay +X_TESTS = stress-xoverlay test-colorkey stress_xoverlay_SOURCES = stress-xoverlay.c stress_xoverlay_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) $(X_CFLAGS) -stress_xoverlay_LDFLAGS = $(GST_LIBS) $(X_LIBS) $(LIBM) -stress_xoverlay_LDADD = \ +stress_xoverlay_LDADD = $(GST_LIBS) $(X_LIBS) $(LIBM) \ $(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-$(GST_MAJORMINOR).la + +if HAVE_GTK +X_TESTS += test-colorkey + +test_colorkey_SOURCES = test-colorkey.c +test_colorkey_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) $(X_CFLAGS) $(GTK_CFLAGS) +test_colorkey_LDADD = $(GST_LIBS) $(X_LIBS) $(LIBM) $(GTK_LIBS) \ + $(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-$(GST_MAJORMINOR).la +endif + else X_TESTS = endif + if USE_PANGO PANGO_TESTS = test-textoverlay test_textoverlay_SOURCES = test-textoverlay.c test_textoverlay_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) -test_textoverlay_LDFLAGS = $(GST_LIBS) $(LIBM) +test_textoverlay_LDADD = $(GST_LIBS) $(LIBM) else PANGO_TESTS = @@ -23,10 +33,10 @@ endif stress_playbin_SOURCES = stress-playbin.c stress_playbin_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) -stress_playbin_LDFLAGS = $(GST_LIBS) $(LIBM) +stress_playbin_LDADD = $(GST_LIBS) $(LIBM) test_scale_SOURCES = test-scale.c test_scale_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) -test_scale_LDFLAGS = $(GST_LIBS) $(LIBM) +test_scale_LDADD = $(GST_LIBS) $(LIBM) noinst_PROGRAMS = $(X_TESTS) $(PANGO_TESTS) stress-playbin test-scale diff --git a/tests/icles/test-colorkey.c b/tests/icles/test-colorkey.c new file mode 100644 index 0000000..1b452f6 --- /dev/null +++ b/tests/icles/test-colorkey.c @@ -0,0 +1,195 @@ +/* GStreamer + * Copyright (C) <2008> Stefan Kost + * + * test-colorkey: test manual colorkey handling + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include + +#include +#include +#include + +static GtkWidget *video_window = NULL; +static GstElement *sink = NULL; +static guint embed_xid = 0; +static GdkGC *trans_gc = NULL; + +static GstBusSyncReply +bus_sync_handler (GstBus * bus, GstMessage * message, GstPipeline * pipeline) +{ + if ((GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT) && + gst_structure_has_name (message->structure, "prepare-xwindow-id")) { + GstElement *element = GST_ELEMENT (GST_MESSAGE_SRC (message)); + + g_print ("got prepare-xwindow-id\n"); + if (!embed_xid) { + embed_xid = GDK_WINDOW_XID (GDK_WINDOW (video_window->window)); + } + + if (g_object_class_find_property (G_OBJECT_GET_CLASS (element), + "force-aspect-ratio")) { + g_object_set (element, "force-aspect-ratio", TRUE, NULL); + } + + gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (GST_MESSAGE_SRC (message)), + embed_xid); + } + return GST_BUS_PASS; +} + +static gboolean +handle_resize_cb (GtkWidget * widget, GdkEventConfigure * event, gpointer data) +{ + gdk_draw_rectangle (widget->window, widget->style->white_gc, TRUE, + 0, 0, widget->allocation.width, widget->allocation.height); + + if (trans_gc) { + guint x, y; + guint h = widget->allocation.height * 0.75; + + gdk_draw_rectangle (widget->window, trans_gc, TRUE, + 0, 0, widget->allocation.width, h); + + for (y = h; y < widget->allocation.height; y++) { + for (x = 0; x < widget->allocation.width; x++) { + if (((x & 1) || (y & 1)) && (x & 1) != (y & 1)) { + gdk_draw_point (widget->window, trans_gc, x, y); + } + } + } + } + return FALSE; +} + +static void +msg_state_changed (GstBus * bus, GstMessage * message, GstPipeline * pipeline) +{ + const GstStructure *s; + + s = gst_message_get_structure (message); + + /* We only care about state changed on the pipeline */ + if (s && GST_MESSAGE_SRC (message) == GST_OBJECT_CAST (pipeline)) { + GstState old, new, pending; + gint color; + + gst_message_parse_state_changed (message, &old, &new, &pending); + + /* When state of the pipeline changes to paused or playing we start updating scale */ + switch (GST_STATE_TRANSITION (old, new)) { + case GST_STATE_CHANGE_READY_TO_PAUSED: + g_object_get (G_OBJECT (sink), "colorkey", &color, NULL); + if (color != -1) { + GdkColor trans_color = { 0, + (color & 0xff0000) >> 8, + (color & 0xff00), + (color & 0xff) << 8 + }; + + trans_gc = gdk_gc_new (video_window->window); + gdk_gc_set_rgb_fg_color (trans_gc, &trans_color); + } + handle_resize_cb (video_window, NULL, NULL); + break; + default: + break; + } + } +} + +static void +window_closed (GtkWidget * widget, GdkEvent * event, gpointer user_data) +{ + GstElement *pipeline = user_data; + + g_print ("stopping\n"); + gtk_widget_hide_all (widget); + gst_element_set_state (pipeline, GST_STATE_NULL); + gtk_main_quit (); +} + +int +main (int argc, char **argv) +{ + GtkWidget *window; + GstElement *pipeline, *src; + GstBus *bus; + + if (!g_thread_supported ()) + g_thread_init (NULL); + + if (!XInitThreads ()) { + g_print ("XInitThreads failed\n"); + exit (-1); + } + + gst_init (&argc, &argv); + gtk_init (&argc, &argv); + + /* prepare the pipeline */ + + pipeline = gst_pipeline_new ("xvoverlay"); + src = gst_element_factory_make ("videotestsrc", NULL); + sink = gst_element_factory_make ("xvimagesink", NULL); + gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL); + gst_element_link (src, sink); + + g_object_set (G_OBJECT (sink), + "autopaint-colorkey", FALSE, + "force-aspect-ratio", TRUE, "draw-borders", FALSE, NULL); + + bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); + gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bus_sync_handler, + pipeline); + gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH); + g_signal_connect (bus, "message::state-changed", + G_CALLBACK (msg_state_changed), pipeline); + gst_object_unref (bus); + + /* prepare the ui */ + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + video_window = gtk_drawing_area_new (); + gtk_widget_set_double_buffered (video_window, FALSE); + + gtk_window_set_default_size (GTK_WINDOW (window), 320, 240); + gtk_container_add (GTK_CONTAINER (window), video_window); + g_signal_connect (G_OBJECT (window), "delete-event", + G_CALLBACK (window_closed), (gpointer) pipeline); + g_signal_connect (G_OBJECT (video_window), "configure-event", + G_CALLBACK (handle_resize_cb), NULL); + + /* show the gui. */ + gtk_widget_show_all (window); + + //connect_bus_signals (pipeline); + gst_element_set_state (pipeline, GST_STATE_PLAYING); + gtk_main (); + gst_object_unref (pipeline); + + return 0; +} -- 2.7.4