From 8fb882253231d99d80a448f7f8e91c9220201be3 Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Fri, 26 Nov 2010 23:55:12 -0300 Subject: [PATCH] examples: Adds camerabin2 example Adds gtk camerabin2 example app --- configure.ac | 1 + tests/examples/Makefile.am | 4 +- tests/examples/camerabin2/.gitignore | 2 + tests/examples/camerabin2/Makefile.am | 33 +++++ tests/examples/camerabin2/gst-camera2.c | 179 +++++++++++++++++++++++ tests/examples/camerabin2/gst-camera2.h | 48 ++++++ tests/examples/camerabin2/gst-camera2.ui | 109 ++++++++++++++ 7 files changed, 374 insertions(+), 2 deletions(-) create mode 100644 tests/examples/camerabin2/.gitignore create mode 100644 tests/examples/camerabin2/Makefile.am create mode 100644 tests/examples/camerabin2/gst-camera2.c create mode 100644 tests/examples/camerabin2/gst-camera2.h create mode 100644 tests/examples/camerabin2/gst-camera2.ui diff --git a/configure.ac b/configure.ac index 51b6d0e2bc..c8aab6f994 100644 --- a/configure.ac +++ b/configure.ac @@ -1808,6 +1808,7 @@ tests/check/Makefile tests/files/Makefile tests/examples/Makefile tests/examples/camerabin/Makefile +tests/examples/camerabin2/Makefile tests/examples/directfb/Makefile tests/examples/mxf/Makefile tests/examples/scaletempo/Makefile diff --git a/tests/examples/Makefile.am b/tests/examples/Makefile.am index 0e92667d58..218f2c622c 100644 --- a/tests/examples/Makefile.am +++ b/tests/examples/Makefile.am @@ -4,7 +4,7 @@ JACK_EXAMPLES=jack else JACK_EXAMPLES= endif -GTK_EXAMPLES=camerabin mxf scaletempo +GTK_EXAMPLES=camerabin mxf scaletempo camerabin2 else GTK_EXAMPLES= endif @@ -16,4 +16,4 @@ DIRECTFB_DIR= endif SUBDIRS= $(DIRECTFB_DIR) $(GTK_EXAMPLES) $(JACK_EXAMPLES) switch -DIST_SUBDIRS= camerabin directfb jack mxf scaletempo switch +DIST_SUBDIRS= camerabin camerabin2 directfb jack mxf scaletempo switch diff --git a/tests/examples/camerabin2/.gitignore b/tests/examples/camerabin2/.gitignore new file mode 100644 index 0000000000..cf225216fa --- /dev/null +++ b/tests/examples/camerabin2/.gitignore @@ -0,0 +1,2 @@ +gst-camera2 +test_*.jpg diff --git a/tests/examples/camerabin2/Makefile.am b/tests/examples/camerabin2/Makefile.am new file mode 100644 index 0000000000..781f201639 --- /dev/null +++ b/tests/examples/camerabin2/Makefile.am @@ -0,0 +1,33 @@ +GST_CAMERABIN_UI_FILES = gst-camera2.ui + +if HAVE_GTK + +GST_CAMERABIN_GTK_EXAMPLES = gst-camera2 + +gst_camera2_SOURCES = gst-camera2.h gst-camera2.c +gst_camera2_CFLAGS = \ + $(GST_PLUGINS_BAD_CFLAGS) \ + $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) \ + $(GTK_CFLAGS) \ + $(GMODULE_EXPORT_CFLAGS) \ + -DGST_USE_UNSTABLE_API +gst_camera2_LDADD = \ + $(top_builddir)/gst-libs/gst/interfaces/libgstphotography-@GST_MAJORMINOR@.la \ + $(GST_PLUGINS_BASE_LIBS) \ + -lgstinterfaces-@GST_MAJORMINOR@ \ + $(GST_LIBS) \ + $(GTK_LIBS) \ + $(GMODULE_EXPORT_LIBS) + +noinst_DATA = $(GST_CAMERABIN_UI_FILES) + +INCLUDES = -DCAMERA_APPS_UIDIR=\""$(uidir)"\" + +else +GST_CAMERABIN_GTK_EXAMPLES = +endif + +noinst_PROGRAMS = $(GST_CAMERABIN_GTK_EXAMPLES) + +EXTRA_DIST = $(GST_CAMERABIN_UI_FILES) + diff --git a/tests/examples/camerabin2/gst-camera2.c b/tests/examples/camerabin2/gst-camera2.c new file mode 100644 index 0000000000..b079adc309 --- /dev/null +++ b/tests/examples/camerabin2/gst-camera2.c @@ -0,0 +1,179 @@ +/* + * GStreamer + * Copyright (C) 2010 Thiago Santos + * + * 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. + */ +/* + * This is a demo application to test the camerabin element. + * If you have question don't hesitate in contact me edgard.lima@indt.org.br + */ + +/* + * Includes + */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "gst-camera2.h" + +#include +#include +#include +#include +#include + +#define UI_FILE "gst-camera2.ui" + +static GstElement *camera; +static GtkBuilder *builder; + +void +on_mainWindow_delete_event (GtkWidget * widget, GdkEvent * event, gpointer data) +{ + gtk_main_quit (); +} + +void +on_captureButton_clicked (GtkButton * button, gpointer user_data) +{ + g_signal_emit_by_name (camera, "start-capture", NULL); +} + +void +on_stopCaptureButton_clicked (GtkButton * button, gpointer user_data) +{ + g_signal_emit_by_name (camera, "stop-capture", NULL); +} + +void +on_imageRButton_toggled (GtkToggleButton * button, gpointer user_data) +{ + if (gtk_toggle_button_get_active (button)) { + g_object_set (camera, "mode", 1, NULL); /* Image mode */ + } +} + +void +on_videoRButton_toggled (GtkToggleButton * button, gpointer user_data) +{ + if (gtk_toggle_button_get_active (button)) { + g_object_set (camera, "mode", 2, NULL); /* Video mode */ + } +} + +void +on_viewfinderArea_realize (GtkWidget * widget, gpointer data) +{ +#if GTK_CHECK_VERSION (2, 18, 0) + gdk_window_ensure_native (gtk_widget_get_window (widget)); +#endif +} + +static GstBusSyncReply +bus_sync_callback (GstBus * bus, GstMessage * message, gpointer data) +{ + GtkWidget *ui_drawing; + + if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT) + return GST_BUS_PASS; + + if (!gst_structure_has_name (message->structure, "prepare-xwindow-id")) + return GST_BUS_PASS; + + /* FIXME: make sure to get XID in main thread */ + ui_drawing = GTK_WIDGET (gtk_builder_get_object (builder, "viewfinderArea")); + gst_x_overlay_set_window_handle (GST_X_OVERLAY (message->src), + GDK_WINDOW_XWINDOW (gtk_widget_get_window (ui_drawing))); + + gst_message_unref (message); + return GST_BUS_DROP; +} + + +static gboolean +bus_callback (GstBus * bus, GstMessage * message, gpointer data) +{ + switch (GST_MESSAGE_TYPE (message)) { + case GST_MESSAGE_WARNING:{ + GError *err; + gchar *debug; + + gst_message_parse_warning (message, &err, &debug); + g_print ("Warning: %s\n", err->message); + g_error_free (err); + g_free (debug); + break; + } + case GST_MESSAGE_ERROR:{ + //print_error_message (message); + //me_gst_cleanup_element (); + gtk_main_quit (); + break; + } + case GST_MESSAGE_EOS: + /* end-of-stream */ + gtk_main_quit (); + break; + case GST_MESSAGE_ELEMENT: + { + //handle_element_message (message); + break; + } + default: + /* unhandled message */ + break; + } + return TRUE; +} + +int +main (int argc, char *argv[]) +{ + int ret = 0; + GtkWidget *ui_main_window; + GError *error = NULL; + GstBus *bus; + + gst_init (&argc, &argv); + gtk_init (&argc, &argv); + + builder = gtk_builder_new (); + if (!gtk_builder_add_from_file (builder, UI_FILE, &error)) { + g_warning ("Error: %s", error->message); + g_free (error); + return 1; + } + + camera = gst_element_factory_make ("camerabin2", "camera"); + bus = gst_pipeline_get_bus (GST_PIPELINE (camera)); + gst_bus_add_watch (bus, bus_callback, NULL); + gst_bus_set_sync_handler (bus, bus_sync_callback, NULL); + gst_object_unref (bus); + + ui_main_window = GTK_WIDGET (gtk_builder_get_object (builder, "mainWindow")); + gtk_builder_connect_signals (builder, NULL); + gtk_widget_show_all (ui_main_window); + + gst_element_set_state (camera, GST_STATE_PLAYING); + + gtk_main (); + + gst_element_set_state (camera, GST_STATE_NULL); + gst_object_unref (camera); + return ret; +} diff --git a/tests/examples/camerabin2/gst-camera2.h b/tests/examples/camerabin2/gst-camera2.h new file mode 100644 index 0000000000..d96e2de63a --- /dev/null +++ b/tests/examples/camerabin2/gst-camera2.h @@ -0,0 +1,48 @@ +/* + * GStreamer + * Copyright (C) 2008 Nokia Corporation + * + * 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. + */ +/* + * This is a demo application to test the camerabin element. + * If you have question don't hesitate in contact me edgard.lima@indt.org.br + */ + +#ifndef __GST_CAMERA_BIN_H__ +#define __GST_CAMERA_BIN_H__ + +#include + +void +on_mainWindow_delete_event (GtkWidget * widget, GdkEvent * event, gpointer data); + +void +on_captureButton_clicked (GtkButton * button, gpointer user_data); + +void +on_stopCaptureButton_clicked (GtkButton * button, gpointer user_data); + +void +on_imageRButton_toggled (GtkToggleButton * button, gpointer user_data); + +void +on_videoRButton_toggled (GtkToggleButton * button, gpointer user_data); + +void +on_viewfinderArea_realize (GtkWidget * widget, gpointer data); + +#endif /* __GST_CAMERA_BIN_H__ */ diff --git a/tests/examples/camerabin2/gst-camera2.ui b/tests/examples/camerabin2/gst-camera2.ui new file mode 100644 index 0000000000..48fe1410ab --- /dev/null +++ b/tests/examples/camerabin2/gst-camera2.ui @@ -0,0 +1,109 @@ + + + + + + 800 + 600 + + + + True + + + True + + + Image + True + True + False + True + True + + + + 0 + + + + + Video + True + True + False + True + True + imageRButton + + + + 1 + + + + + False + False + 0 + + + + + True + + + True + + + + 0 + + + + + True + + + Capture + True + True + True + + + + False + False + 0 + + + + + Stop Capture + True + True + True + + + + False + False + 1 + + + + + False + False + 1 + + + + + 1 + + + + + +