From 6f5ecebb6a42527baa7add7dd0d5714ea5f7719a Mon Sep 17 00:00:00 2001 From: Julien Isorce Date: Fri, 2 May 2014 05:46:18 +0100 Subject: gl: rename cocoa example and move it to its parent directory --- configure.ac | 1 - tests/examples/gl/cocoa/.gitignore | 1 + tests/examples/gl/cocoa/Makefile.am | 14 +- tests/examples/gl/cocoa/cocoa-videooverlay.m | 240 +++++++++++++++++++++++ tests/examples/gl/cocoa/videooverlay/.gitignore | 1 - tests/examples/gl/cocoa/videooverlay/Makefile.am | 14 -- tests/examples/gl/cocoa/videooverlay/main.m | 240 ----------------------- 7 files changed, 253 insertions(+), 258 deletions(-) create mode 100644 tests/examples/gl/cocoa/.gitignore create mode 100755 tests/examples/gl/cocoa/cocoa-videooverlay.m delete mode 100644 tests/examples/gl/cocoa/videooverlay/.gitignore delete mode 100755 tests/examples/gl/cocoa/videooverlay/Makefile.am delete mode 100755 tests/examples/gl/cocoa/videooverlay/main.m diff --git a/configure.ac b/configure.ac index e73032f46..99a97d62e 100644 --- a/configure.ac +++ b/configure.ac @@ -3240,7 +3240,6 @@ tests/examples/camerabin2/Makefile tests/examples/directfb/Makefile tests/examples/gl/Makefile tests/examples/gl/cocoa/Makefile -tests/examples/gl/cocoa/videooverlay/Makefile tests/examples/gl/clutter/Makefile tests/examples/gl/generic/Makefile tests/examples/gl/generic/cube/Makefile diff --git a/tests/examples/gl/cocoa/.gitignore b/tests/examples/gl/cocoa/.gitignore new file mode 100644 index 000000000..5cfb85ef2 --- /dev/null +++ b/tests/examples/gl/cocoa/.gitignore @@ -0,0 +1 @@ +cocoa-videooverlay diff --git a/tests/examples/gl/cocoa/Makefile.am b/tests/examples/gl/cocoa/Makefile.am index 716aa30e5..c13ec526e 100755 --- a/tests/examples/gl/cocoa/Makefile.am +++ b/tests/examples/gl/cocoa/Makefile.am @@ -1,4 +1,14 @@ - if HAVE_WINDOW_COCOA -SUBDIRS = videooverlay + +noinst_PROGRAMS = cocoa-videooverlay + +cocoa_videooverlay_SOURCES = cocoa-videooverlay.m + +cocoa_videooverlay_OBJCFLAGS=$(GST_PLUGINS_GL_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) \ + $(GL_CFLAGS) ${GL_OBJCFLAGS} +cocoa_videooverlay_LDADD=$(GST_PLUGINS_GL_LIBS) $(GST_PLUGINS_BASE_LIBS) $(GST_LIBS) \ + $(GL_LIBS) -lgstvideo-$(GST_API_VERSION) + +cocoa_videooverlay_LIBTOOLFLAGS = --tag=OBJC + endif diff --git a/tests/examples/gl/cocoa/cocoa-videooverlay.m b/tests/examples/gl/cocoa/cocoa-videooverlay.m new file mode 100755 index 000000000..8f959fe0b --- /dev/null +++ b/tests/examples/gl/cocoa/cocoa-videooverlay.m @@ -0,0 +1,240 @@ +#include +#include +#include + +/* ============================================================= */ +/* */ +/* MainWindow */ +/* */ +/* ============================================================= */ + +@interface MainWindow: NSWindow { + GMainLoop *m_loop; + GstElement *m_pipeline; + gboolean m_isClosed; +} +- (id) initWithContentRect:(NSRect) contentRect Loop:(GMainLoop*)loop Pipeline:(GstElement*)pipeline; +- (GMainLoop*) loop; +- (GstElement*) pipeline; +- (gboolean) isClosed; +@end + +@implementation MainWindow + +- (id) initWithContentRect:(NSRect)contentRect Loop:(GMainLoop*)loop Pipeline:(GstElement*)pipeline +{ + m_loop = loop; + m_pipeline = pipeline; + m_isClosed = FALSE; + + self = [super initWithContentRect: contentRect + styleMask: (NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask) + backing: NSBackingStoreBuffered defer: NO screen: nil]; + + [self setReleasedWhenClosed:NO]; + [NSApp setDelegate:self]; + + [self setTitle:@"gst-plugins-gl implements videooverlay interface"]; + + return self; +} + +- (GMainLoop*) loop { + return m_loop; +} + +- (GstElement*) pipeline { + return m_pipeline; +} + +- (gboolean) isClosed { + return m_isClosed; +} + +- (void) customClose { + m_isClosed = TRUE; +} + +- (BOOL) windowShouldClose:(id)sender { + gst_element_send_event (m_pipeline, gst_event_new_eos ()); + return YES; +} + +- (void) applicationDidFinishLaunching: (NSNotification *) not { + [self makeMainWindow]; + [self center]; + [self orderFront:self]; +} + +- (BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)app { + return NO; +} + +@end + + +/* ============================================================= */ +/* */ +/* gstreamer callbacks */ +/* */ +/* ============================================================= */ + + +static GstBusSyncReply create_window (GstBus* bus, GstMessage* message, MainWindow* window) +{ + // ignore anything but 'prepare-window-handle' element messages + if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT) + return GST_BUS_PASS; + + if (!gst_is_video_overlay_prepare_window_handle_message (message)) + return GST_BUS_PASS; + + g_print ("setting window handle %lud\n", (gulong) window); + + gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (GST_MESSAGE_SRC (message)), (guintptr) window); + + gst_message_unref (message); + + return GST_BUS_DROP; +} + + +static void end_stream_cb(GstBus* bus, GstMessage* message, MainWindow* window) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + g_print ("end of stream\n"); + + gst_element_set_state ([window pipeline], GST_STATE_NULL); + gst_object_unref ([window pipeline]); + g_main_loop_quit ([window loop]); + + [window performSelectorOnMainThread:@selector(customClose) withObject:nil waitUntilDone:YES]; + + [pool release]; +} + +static gpointer thread_func (MainWindow* window) +{ +#ifdef GNUSTEP + GSRegisterCurrentThread(); +#endif + + g_main_loop_run ([window loop]); + +#ifdef GNUSTEP + GSUnregisterCurrentThread(); +#endif + return NULL; +} + + +/* ============================================================= */ +/* */ +/* application */ +/* */ +/* ============================================================= */ + +int main(int argc, char **argv) +{ + int width = 640; + int height = 480; + + GMainLoop *loop = NULL; + GstElement *pipeline = NULL; + + GstElement *videosrc = NULL; + GstElement *videosink = NULL; + GstCaps *caps=NULL; + gboolean ok=FALSE; + GstBus *bus=NULL; + GThread *loop_thread=NULL; + NSAutoreleasePool *pool=nil; + NSRect rect; + MainWindow *window=nil; + +#ifdef GNUSTEP + GstState state; +#endif + + g_print("app created\n"); + + gst_init (&argc, &argv); + + loop = g_main_loop_new (NULL, FALSE); + pipeline = gst_pipeline_new ("pipeline"); + + videosrc = gst_element_factory_make ("videotestsrc", "videotestsrc"); + videosink = gst_element_factory_make ("glimagesink", "glimagesink"); + + g_object_set(G_OBJECT(videosrc), "num-buffers", 500, NULL); + + gst_bin_add_many (GST_BIN (pipeline), videosrc, videosink, NULL); + + caps = gst_caps_new_simple("video/x-raw", + "width", G_TYPE_INT, width, + "height", G_TYPE_INT, height, + "framerate", GST_TYPE_FRACTION, 25, 1, + "format", G_TYPE_STRING, "I420", + NULL); + + ok = gst_element_link_filtered(videosrc, videosink, caps); + gst_caps_unref(caps); + if (!ok) + g_warning("could not link videosrc to videosink\n"); + +#ifdef GNUSTEP + gst_element_set_state (pipeline, GST_STATE_PAUSED); + state = GST_STATE_PAUSED; + gst_element_get_state (pipeline, &state, &state, GST_CLOCK_TIME_NONE); + g_print("pipeline paused\n"); + GSRegisterCurrentThread(); +#endif + + pool = [[NSAutoreleasePool alloc] init]; +#ifndef GNUSTEP + [NSApplication sharedApplication]; +#endif + + rect.origin.x = 0; rect.origin.y = 0; + rect.size.width = width; rect.size.height = height; + + window = [[MainWindow alloc] initWithContentRect:rect Loop:loop Pipeline:pipeline]; + + bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); + gst_bus_add_signal_watch (bus); + g_signal_connect(bus, "message::error", G_CALLBACK(end_stream_cb), window); + g_signal_connect(bus, "message::warning", G_CALLBACK(end_stream_cb), window); + g_signal_connect(bus, "message::eos", G_CALLBACK(end_stream_cb), window); + gst_bus_set_sync_handler (bus, (GstBusSyncHandler) create_window, window, NULL); + gst_object_unref (bus); + + loop_thread = g_thread_new (NULL, + (GThreadFunc) thread_func, window); + + gst_element_set_state (pipeline, GST_STATE_PLAYING); + + [window orderFront:window]; + +#ifndef GNUSTEP + while (![window isClosed]) { + NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask + untilDate:[NSDate dateWithTimeIntervalSinceNow:1] + inMode:NSDefaultRunLoopMode dequeue:YES]; + if (event) + [NSApp sendEvent:event]; + } +#endif + + g_thread_join (loop_thread); + + [window release]; + + [pool release]; + +#ifdef GNUSTEP + GSUnregisterCurrentThread(); +#endif + + return 0; +} diff --git a/tests/examples/gl/cocoa/videooverlay/.gitignore b/tests/examples/gl/cocoa/videooverlay/.gitignore deleted file mode 100644 index c5ee310fb..000000000 --- a/tests/examples/gl/cocoa/videooverlay/.gitignore +++ /dev/null @@ -1 +0,0 @@ -videooverlay diff --git a/tests/examples/gl/cocoa/videooverlay/Makefile.am b/tests/examples/gl/cocoa/videooverlay/Makefile.am deleted file mode 100755 index 47dac610c..000000000 --- a/tests/examples/gl/cocoa/videooverlay/Makefile.am +++ /dev/null @@ -1,14 +0,0 @@ -if HAVE_WINDOW_COCOA - -noinst_PROGRAMS = videooverlay - -videooverlay_SOURCES = main.m - -videooverlay_OBJCFLAGS=$(GST_PLUGINS_GL_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) \ - $(GL_CFLAGS) -I/usr/local/include/gstreamer-${GST_API_VERSION} ${GL_OBJCFLAGS} -videooverlay_LDADD=$(GST_PLUGINS_GL_LIBS) $(GST_PLUGINS_BASE_LIBS) $(GST_LIBS) \ - $(GL_LIBS) -lgstvideo-$(GST_API_VERSION) - -videooverlay_LIBTOOLFLAGS = --tag=OBJC - -endif diff --git a/tests/examples/gl/cocoa/videooverlay/main.m b/tests/examples/gl/cocoa/videooverlay/main.m deleted file mode 100755 index 8f959fe0b..000000000 --- a/tests/examples/gl/cocoa/videooverlay/main.m +++ /dev/null @@ -1,240 +0,0 @@ -#include -#include -#include - -/* ============================================================= */ -/* */ -/* MainWindow */ -/* */ -/* ============================================================= */ - -@interface MainWindow: NSWindow { - GMainLoop *m_loop; - GstElement *m_pipeline; - gboolean m_isClosed; -} -- (id) initWithContentRect:(NSRect) contentRect Loop:(GMainLoop*)loop Pipeline:(GstElement*)pipeline; -- (GMainLoop*) loop; -- (GstElement*) pipeline; -- (gboolean) isClosed; -@end - -@implementation MainWindow - -- (id) initWithContentRect:(NSRect)contentRect Loop:(GMainLoop*)loop Pipeline:(GstElement*)pipeline -{ - m_loop = loop; - m_pipeline = pipeline; - m_isClosed = FALSE; - - self = [super initWithContentRect: contentRect - styleMask: (NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask) - backing: NSBackingStoreBuffered defer: NO screen: nil]; - - [self setReleasedWhenClosed:NO]; - [NSApp setDelegate:self]; - - [self setTitle:@"gst-plugins-gl implements videooverlay interface"]; - - return self; -} - -- (GMainLoop*) loop { - return m_loop; -} - -- (GstElement*) pipeline { - return m_pipeline; -} - -- (gboolean) isClosed { - return m_isClosed; -} - -- (void) customClose { - m_isClosed = TRUE; -} - -- (BOOL) windowShouldClose:(id)sender { - gst_element_send_event (m_pipeline, gst_event_new_eos ()); - return YES; -} - -- (void) applicationDidFinishLaunching: (NSNotification *) not { - [self makeMainWindow]; - [self center]; - [self orderFront:self]; -} - -- (BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)app { - return NO; -} - -@end - - -/* ============================================================= */ -/* */ -/* gstreamer callbacks */ -/* */ -/* ============================================================= */ - - -static GstBusSyncReply create_window (GstBus* bus, GstMessage* message, MainWindow* window) -{ - // ignore anything but 'prepare-window-handle' element messages - if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT) - return GST_BUS_PASS; - - if (!gst_is_video_overlay_prepare_window_handle_message (message)) - return GST_BUS_PASS; - - g_print ("setting window handle %lud\n", (gulong) window); - - gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (GST_MESSAGE_SRC (message)), (guintptr) window); - - gst_message_unref (message); - - return GST_BUS_DROP; -} - - -static void end_stream_cb(GstBus* bus, GstMessage* message, MainWindow* window) -{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - g_print ("end of stream\n"); - - gst_element_set_state ([window pipeline], GST_STATE_NULL); - gst_object_unref ([window pipeline]); - g_main_loop_quit ([window loop]); - - [window performSelectorOnMainThread:@selector(customClose) withObject:nil waitUntilDone:YES]; - - [pool release]; -} - -static gpointer thread_func (MainWindow* window) -{ -#ifdef GNUSTEP - GSRegisterCurrentThread(); -#endif - - g_main_loop_run ([window loop]); - -#ifdef GNUSTEP - GSUnregisterCurrentThread(); -#endif - return NULL; -} - - -/* ============================================================= */ -/* */ -/* application */ -/* */ -/* ============================================================= */ - -int main(int argc, char **argv) -{ - int width = 640; - int height = 480; - - GMainLoop *loop = NULL; - GstElement *pipeline = NULL; - - GstElement *videosrc = NULL; - GstElement *videosink = NULL; - GstCaps *caps=NULL; - gboolean ok=FALSE; - GstBus *bus=NULL; - GThread *loop_thread=NULL; - NSAutoreleasePool *pool=nil; - NSRect rect; - MainWindow *window=nil; - -#ifdef GNUSTEP - GstState state; -#endif - - g_print("app created\n"); - - gst_init (&argc, &argv); - - loop = g_main_loop_new (NULL, FALSE); - pipeline = gst_pipeline_new ("pipeline"); - - videosrc = gst_element_factory_make ("videotestsrc", "videotestsrc"); - videosink = gst_element_factory_make ("glimagesink", "glimagesink"); - - g_object_set(G_OBJECT(videosrc), "num-buffers", 500, NULL); - - gst_bin_add_many (GST_BIN (pipeline), videosrc, videosink, NULL); - - caps = gst_caps_new_simple("video/x-raw", - "width", G_TYPE_INT, width, - "height", G_TYPE_INT, height, - "framerate", GST_TYPE_FRACTION, 25, 1, - "format", G_TYPE_STRING, "I420", - NULL); - - ok = gst_element_link_filtered(videosrc, videosink, caps); - gst_caps_unref(caps); - if (!ok) - g_warning("could not link videosrc to videosink\n"); - -#ifdef GNUSTEP - gst_element_set_state (pipeline, GST_STATE_PAUSED); - state = GST_STATE_PAUSED; - gst_element_get_state (pipeline, &state, &state, GST_CLOCK_TIME_NONE); - g_print("pipeline paused\n"); - GSRegisterCurrentThread(); -#endif - - pool = [[NSAutoreleasePool alloc] init]; -#ifndef GNUSTEP - [NSApplication sharedApplication]; -#endif - - rect.origin.x = 0; rect.origin.y = 0; - rect.size.width = width; rect.size.height = height; - - window = [[MainWindow alloc] initWithContentRect:rect Loop:loop Pipeline:pipeline]; - - bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); - gst_bus_add_signal_watch (bus); - g_signal_connect(bus, "message::error", G_CALLBACK(end_stream_cb), window); - g_signal_connect(bus, "message::warning", G_CALLBACK(end_stream_cb), window); - g_signal_connect(bus, "message::eos", G_CALLBACK(end_stream_cb), window); - gst_bus_set_sync_handler (bus, (GstBusSyncHandler) create_window, window, NULL); - gst_object_unref (bus); - - loop_thread = g_thread_new (NULL, - (GThreadFunc) thread_func, window); - - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - [window orderFront:window]; - -#ifndef GNUSTEP - while (![window isClosed]) { - NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask - untilDate:[NSDate dateWithTimeIntervalSinceNow:1] - inMode:NSDefaultRunLoopMode dequeue:YES]; - if (event) - [NSApp sendEvent:event]; - } -#endif - - g_thread_join (loop_thread); - - [window release]; - - [pool release]; - -#ifdef GNUSTEP - GSUnregisterCurrentThread(); -#endif - - return 0; -} -- cgit v1.2.1