/* GStreamer * Copyright (C) <2010> Stefan Kost * * gtk-xoverlay: demonstrate overlay handling using gtk * * 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. */ /* Compilation : * * gcc test-eloi.c -o test-eloi `pkg-config --cflags --libs gstreamer-interfaces-0.10 gtk+-2.0 gstreamer-0.10` * * */ #include #include #include #include #include #if defined (GDK_WINDOWING_X11) #include #elif defined (GDK_WINDOWING_WIN32) #include #elif defined (GDK_WINDOWING_QUARTZ) #include #endif /* Define if we test with videotestsrc (flag = 0) or playbin2 (flag = 1) */ #define USE_PLAYBIN2 0 #ifdef _MSC_VER #pragma comment(lib, "D:\\Users\\100727012\\Desktop\\BasicTutorial-5\\Debug\\GStreamer\\0.10\\x86\\lib\\gstreamer-0.10.lib") #pragma comment(lib, "D:\\Users\\100727012\\Desktop\\BasicTutorial-5\\Debug\\GStreamer\\0.10\\x86\\lib\\gstinterfaces-0.10.lib") #pragma comment(lib, "D:\\Users\\100727012\\Desktop\\BasicTutorial-5\\Debug\\GStreamer\\0.10\\x86\\lib\\gthread-2.0.lib") #pragma comment(lib, "D:\\Users\\100727012\\Desktop\\BasicTutorial-5\\Debug\\GStreamer\\0.10\\x86\\lib\\gmodule-2.0.lib") #pragma comment(lib, "D:\\Users\\100727012\\Desktop\\BasicTutorial-5\\Debug\\GStreamer\\0.10\\x86\\lib\\gobject-2.0.lib") #pragma comment(lib, "D:\\Users\\100727012\\Desktop\\BasicTutorial-5\\Debug\\GStreamer\\0.10\\x86\\lib\\glib-2.0.lib") #pragma comment(lib, "D:\\Users\\100727012\\Desktop\\BasicTutorial-5\\Debug\\GStreamer\\0.10\\x86\\lib\\gdk_pixbuf-2.0.lib") #pragma comment(lib, "D:\\Users\\100727012\\Desktop\\BasicTutorial-5\\Debug\\GStreamer\\0.10\\x86\\lib\\cairo.lib") #pragma comment(lib, "D:\\Users\\100727012\\Desktop\\BasicTutorial-5\\Debug\\GStreamer\\0.10\\x86\\lib\\ges-0.10.lib") #pragma comment(lib, "D:\\Users\\100727012\\Desktop\\BasicTutorial-5\\Debug\\GStreamer\\0.10\\x86\\lib\\gtk-win32-2.0.lib") #pragma comment(lib, "D:\\Users\\100727012\\Desktop\\BasicTutorial-5\\Debug\\GStreamer\\0.10\\x86\\lib\\gdk-win32-2.0.lib") #endif static void window_closed (GtkWidget * widget, GdkEvent * event, gpointer user_data) { GstElement *pipeline = (GstElement *)user_data; gtk_widget_hide_all (widget); gst_element_set_state (pipeline, GST_STATE_NULL); gtk_main_quit (); } /* This function is called when the PAUSE button is clicked */ static void videorotate_cb (GtkButton *button, gpointer user_data) { GstElement* videoRotate = (GstElement*) user_data; gint flip_method; if (videoRotate == NULL ){ g_printerr("videoRotate is NULL !"); return; } g_object_get (videoRotate, "method", &flip_method); flip_method = (flip_method == 0 ? 1 : 0); g_object_set (videoRotate, "method", flip_method, NULL); } static void restart_cb (GtkButton *button, gpointer user_data) { GstElement* pipeline = (GstElement*) user_data; gst_element_set_state (pipeline, GST_STATE_READY); gst_element_set_state (pipeline, GST_STATE_PLAYING); } int main (int argc, char **argv) { GdkWindow *video_window_xwindow; GtkWidget *window, *video_window; GtkWidget *videorotate_button, *restart_button; /* Buttons */ GtkWidget *controls; /* Buttons */ gulong embed_xid; GstStateChangeReturn sret; GstPad *pad, *ghost_pad; GstElement *pipeline, *src, *sink, *videoRotate, *binSink; #ifdef WIN32 _putenv ("GST_PLUGIN_PATH=D:\\Users\\100727012\\Desktop\\BasicTutorial-5\\Debug\\GStreamer\\0.10\\x86\\lib\\gstreamer-0.10"); char* name = getenv("GST_PLUGIN_PATH"); #endif gst_init (&argc, &argv); gtk_init (&argc, &argv); /* prepare the pipeline */ #ifdef WIN32 sink = gst_element_factory_make ("d3dvideosink", NULL); #else sink = gst_element_factory_make ("ximagesink", NULL); #endif if (USE_PLAYBIN2 == 1) { pipeline = gst_element_factory_make ("playbin2", NULL); #ifdef WIN32 g_object_set (pipeline, "uri", "file:///D:/PARTAGE/00001f70-000003d8-000.00video.mov", NULL); #else g_object_set (pipeline, "uri", "file:///media/sf_PARTAGE/00001f70-000003d8-000.00video.mov", NULL); #endif videoRotate = gst_element_factory_make ("videoflip", "videorotate"); binSink = gst_bin_new ("video_sink_bin"); gst_bin_add_many (GST_BIN (binSink), videoRotate ,sink, NULL); gst_element_link (videoRotate,sink); pad = gst_element_get_static_pad (videoRotate, "sink"); ghost_pad = gst_ghost_pad_new ("sink", pad); gst_pad_set_active (ghost_pad, TRUE); gst_element_add_pad (binSink, ghost_pad); gst_object_unref (pad); g_object_set (GST_OBJECT (pipeline), "video-sink", binSink, NULL); }else{ pipeline = gst_pipeline_new ("xvoverlay"); src = gst_element_factory_make ("videotestsrc", NULL); videoRotate = gst_element_factory_make ("videoflip", "videorotate"); gst_bin_add_many (GST_BIN (pipeline), src, videoRotate ,sink, NULL); gst_element_link (src,videoRotate); gst_element_link (videoRotate,sink); } /* prepare the ui */ window = gtk_window_new (GTK_WINDOW_TOPLEVEL); controls = gtk_vbox_new (FALSE, 0); g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (window_closed), (gpointer) pipeline); gtk_window_set_default_size (GTK_WINDOW (window), 800, 600); gtk_window_set_title (GTK_WINDOW (window), "playbin2 - overlay - videoflip"); video_window = gtk_drawing_area_new (); gtk_widget_set_double_buffered (video_window, FALSE); gtk_box_pack_start (GTK_BOX (controls), video_window, TRUE, TRUE, 0); gtk_container_set_border_width (GTK_CONTAINER (window), 16); videorotate_button = gtk_button_new_from_stock (GTK_STOCK_CONVERT); g_signal_connect (G_OBJECT (videorotate_button), "clicked", G_CALLBACK (videorotate_cb), videoRotate); restart_button = gtk_button_new_from_stock (GTK_STOCK_STOP); g_signal_connect (G_OBJECT (restart_button), "clicked", G_CALLBACK (restart_cb), pipeline); gtk_box_pack_start (GTK_BOX (controls), videorotate_button, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (controls), restart_button, FALSE, FALSE, 0); gtk_container_add (GTK_CONTAINER (window), controls); gtk_box_pack_start (GTK_BOX (window), controls, FALSE, FALSE, 0); gtk_widget_show_all (window); gtk_widget_realize (window); video_window_xwindow = gtk_widget_get_window (video_window); /* Retrieve window handler from GDK */ #if defined (GDK_WINDOWING_WIN32) embed_xid = (guintptr)GDK_WINDOW_HWND (video_window_xwindow); #elif defined (GDK_WINDOWING_QUARTZ) embed_xid = gdk_quartz_window_get_nsview (video_window_xwindow); #elif defined (GDK_WINDOWING_X11) embed_xid = GDK_WINDOW_XID (video_window_xwindow); #endif if (USE_PLAYBIN2 == 1) { gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (pipeline), embed_xid); }else{ gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (sink), embed_xid); } /* run the pipeline */ sret = gst_element_set_state (pipeline, GST_STATE_PLAYING); if (sret == GST_STATE_CHANGE_FAILURE) gst_element_set_state (pipeline, GST_STATE_NULL); else gtk_main (); gst_object_unref (pipeline); return 0; }