From 5d747fb6be06cb933f9b89de754faf5198f1ffa8 Mon Sep 17 00:00:00 2001 From: Xavi Artigas Date: Mon, 6 May 2013 17:13:03 +0200 Subject: [PATCH] Add comments, debug output, a bit of variable renaming and some code reorganization. --- .../xcode iOS/Tutorial 2/GStreamerBackend.h | 7 ++- .../xcode iOS/Tutorial 2/GStreamerBackend.m | 64 +++++++++++++--------- .../Tutorial 2/GStreamerBackendDelegate.h | 5 ++ .../xcode iOS/Tutorial 2/ViewController.m | 10 ++++ 4 files changed, 58 insertions(+), 28 deletions(-) diff --git a/gst-sdk/tutorials/xcode iOS/Tutorial 2/GStreamerBackend.h b/gst-sdk/tutorials/xcode iOS/Tutorial 2/GStreamerBackend.h index bcd804c..b00f758 100644 --- a/gst-sdk/tutorials/xcode iOS/Tutorial 2/GStreamerBackend.h +++ b/gst-sdk/tutorials/xcode iOS/Tutorial 2/GStreamerBackend.h @@ -3,9 +3,14 @@ @interface GStreamerBackend : NSObject +/* Initialization method. Pass the delegate that will take care of the UI. + * This delegate must implement the GStreamerBackendDelegate protocol */ -(id) init:(id) uiDelegate; + +/* Set the pipeline to PLAYING */ -(void) play; + +/* Set the pipeline to PAUSED */ -(void) pause; --(void) stop; @end \ No newline at end of file diff --git a/gst-sdk/tutorials/xcode iOS/Tutorial 2/GStreamerBackend.m b/gst-sdk/tutorials/xcode iOS/Tutorial 2/GStreamerBackend.m index 0ab205e..814d15a 100644 --- a/gst-sdk/tutorials/xcode iOS/Tutorial 2/GStreamerBackend.m +++ b/gst-sdk/tutorials/xcode iOS/Tutorial 2/GStreamerBackend.m @@ -2,6 +2,9 @@ #include +GST_DEBUG_CATEGORY_STATIC (debug_category); +#define GST_CAT_DEFAULT debug_category + @interface GStreamerBackend() -(void)setUIMessage:(gchar*) message; -(void)app_function; @@ -9,18 +12,25 @@ @end @implementation GStreamerBackend { - id delegate; /* Class that we use to interact with the user interface */ + id ui_delegate; /* Class that we use to interact with the user interface */ GstElement *pipeline; /* The running pipeline */ GMainContext *context; /* GLib context used to run the main loop */ GMainLoop *main_loop; /* GLib main loop */ gboolean initialized; /* To avoid informing the UI multiple times about the initialization */ } +/* + * Interface methods + */ + -(id) init:(id) uiDelegate { if (self = [super init]) { - self->delegate = uiDelegate; + self->ui_delegate = uiDelegate; + + GST_DEBUG_CATEGORY_INIT (debug_category, "tutorial-2", 0, "iOS tutorial 2"); + gst_debug_set_threshold_for_name("tutorial-2", GST_LEVEL_DEBUG); /* Start the bus monitoring task */ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ @@ -34,18 +44,38 @@ -(void) dealloc { if (pipeline) { + GST_DEBUG("Setting the pipeline to NULL"); gst_element_set_state(pipeline, GST_STATE_NULL); gst_object_unref(pipeline); pipeline = NULL; } } +-(void) play +{ + if(gst_element_set_state(pipeline, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) { + [self setUIMessage:"Failed to set pipeline to playing"]; + } +} + +-(void) pause +{ + if(gst_element_set_state(pipeline, GST_STATE_PAUSED) == GST_STATE_CHANGE_FAILURE) { + [self setUIMessage:"Failed to set pipeline to paused"]; + } +} + +/* + * Private methods + */ + +/* Change the message on the UI through the UI delegate */ -(void)setUIMessage:(gchar*) message { NSString *string = [NSString stringWithUTF8String:message]; - if(delegate && [delegate respondsToSelector:@selector(gstreamerSetUIMessage:)]) + if(ui_delegate && [ui_delegate respondsToSelector:@selector(gstreamerSetUIMessage:)]) { - [delegate gstreamerSetUIMessage:string]; + [ui_delegate gstreamerSetUIMessage:string]; } } @@ -84,15 +114,15 @@ static void state_changed_cb (GstBus *bus, GstMessage *msg, GStreamerBackend *se { if (!initialized && main_loop) { GST_DEBUG ("Initialization complete, notifying application."); - if (delegate && [delegate respondsToSelector:@selector(gstreamerInitialized)]) + if (ui_delegate && [ui_delegate respondsToSelector:@selector(gstreamerInitialized)]) { - [delegate gstreamerInitialized]; + [ui_delegate gstreamerInitialized]; } initialized = TRUE; } } -/* Main method for the native code. This is executed on its own thread. */ +/* Main method for the bus monitoring code */ -(void) app_function { GstBus *bus; @@ -143,25 +173,5 @@ static void state_changed_cb (GstBus *bus, GstMessage *msg, GStreamerBackend *se return; } --(void) play -{ - if(gst_element_set_state(pipeline, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) { - [self setUIMessage:"Failed to set pipeline to playing"]; - } -} - --(void) pause -{ - if(gst_element_set_state(pipeline, GST_STATE_PAUSED) == GST_STATE_CHANGE_FAILURE) { - [self setUIMessage:"Failed to set pipeline to paused"]; - } -} - --(void) stop -{ - if(pipeline) - gst_element_set_state(pipeline, GST_STATE_NULL); -} - @end diff --git a/gst-sdk/tutorials/xcode iOS/Tutorial 2/GStreamerBackendDelegate.h b/gst-sdk/tutorials/xcode iOS/Tutorial 2/GStreamerBackendDelegate.h index b909591..5586373 100644 --- a/gst-sdk/tutorials/xcode iOS/Tutorial 2/GStreamerBackendDelegate.h +++ b/gst-sdk/tutorials/xcode iOS/Tutorial 2/GStreamerBackendDelegate.h @@ -3,7 +3,12 @@ @protocol GStreamerBackendDelegate @optional +/* Called when the GStreamer backend has finished initializing + * and is ready to accept orders. */ -(void) gstreamerInitialized; + +/* Called when the GStreamer backend wants to output some message + * to the screen. */ -(void) gstreamerSetUIMessage:(NSString *)message; @end diff --git a/gst-sdk/tutorials/xcode iOS/Tutorial 2/ViewController.m b/gst-sdk/tutorials/xcode iOS/Tutorial 2/ViewController.m index 99c2b1c..512ede7 100644 --- a/gst-sdk/tutorials/xcode iOS/Tutorial 2/ViewController.m +++ b/gst-sdk/tutorials/xcode iOS/Tutorial 2/ViewController.m @@ -10,6 +10,10 @@ @implementation ViewController +/* + * Methods from UIViewController + */ + - (void)viewDidLoad { [super viewDidLoad]; @@ -26,16 +30,22 @@ // Dispose of any resources that can be recreated. } +/* Called when the Play button is pressed */ -(IBAction) play:(id)sender { [gst_backend play]; } +/* Called when the Pause button is pressed */ -(IBAction) pause:(id)sender { [gst_backend pause]; } +/* + * Methods from GstreamerBackendDelegate + */ + -(void) gstreamerInitialized { dispatch_async(dispatch_get_main_queue(), ^{ -- 2.7.4