[Cogl] [PATCH 4/9] Get rid of the main loop from CoglGstVideoSink

Neil Roberts neil at linux.intel.com
Fri Mar 1 05:31:55 PST 2013


It doesn't seem like a good idea for the sink to force using any
particular main loop but instead it should let the application create
it. This is important for example if the application is using
GApplication in which case glib will internally handle creating the
main loop.

I don't think CoglGstVideoSink needs to create a GMainContext and it
can safely just assume that the application is using the default
context. GLib lets you pass NULL everywhere it expects a context in
order to just use the default one.
---
 cogl-gst/cogl-gst-video-sink.c     | 15 ++-------------
 examples/cogl-basic-video-player.c | 18 ++++++++----------
 2 files changed, 10 insertions(+), 23 deletions(-)

diff --git a/cogl-gst/cogl-gst-video-sink.c b/cogl-gst/cogl-gst-video-sink.c
index 2746d2e..774ded3 100644
--- a/cogl-gst/cogl-gst-video-sink.c
+++ b/cogl-gst/cogl-gst-video-sink.c
@@ -130,8 +130,6 @@ struct _CoglGstVideoSinkPrivate
   GSList *renderers;
   GstCaps *caps;
   CoglGstRenderer *renderer;
-  GMainContext *g_ctx;
-  GMainLoop *loop;
   GstFlowReturn flow_return;
   int free_layer;
   GstVideoInfo info;
@@ -159,12 +157,6 @@ cogl_gst_video_sink_get_pipeline (CoglGstVideoSink *vt)
   return vt->priv->pipeline;
 }
 
-GMainLoop*
-cogl_gst_video_sink_get_main_loop (CoglGstVideoSink *sink)
-{
-  return sink->priv->loop;
-}
-
 int
 cogl_gst_video_sink_get_free_layer (CoglGstVideoSink* sink)
 {
@@ -907,9 +899,6 @@ cogl_gst_video_sink_init (CoglGstVideoSink *sink)
   sink->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (sink,
                                                    COGL_GST_TYPE_VIDEO_SINK,
                                                    CoglGstVideoSinkPrivate);
-
-  sink->priv->loop = g_main_loop_new (NULL, TRUE);
-  sink->priv->g_ctx = g_main_loop_get_context (sink->priv->loop);
 }
 
 static GstFlowReturn
@@ -931,7 +920,7 @@ _cogl_gst_video_sink_render (GstBaseSink *bsink,
   gst_source->buffer = gst_buffer_ref (buffer);
   g_mutex_unlock (&gst_source->buffer_lock);
 
-  g_main_context_wakeup (priv->g_ctx);
+  g_main_context_wakeup (NULL);
 
   return GST_FLOW_OK;
 
@@ -989,7 +978,7 @@ cogl_gst_video_sink_start (GstBaseSink *base_sink)
   CoglGstVideoSinkPrivate *priv = sink->priv;
 
   priv->source = cogl_gst_source_new (sink);
-  g_source_attach ((GSource*) priv->source, priv->g_ctx);
+  g_source_attach ((GSource*) priv->source, NULL);
   priv->flow_return = GST_FLOW_OK;
   return TRUE;
 }
diff --git a/examples/cogl-basic-video-player.c b/examples/cogl-basic-video-player.c
index 3e61a8a..7b5be41 100644
--- a/examples/cogl-basic-video-player.c
+++ b/examples/cogl-basic-video-player.c
@@ -7,6 +7,7 @@ typedef struct _Data
   CoglPipeline *pln;
   CoglGstVideoSink *sink;
   CoglBool draw_ready;
+  GMainLoop *main_loop;
 }Data;
 
 static CoglBool
@@ -19,7 +20,7 @@ _bus_watch (GstBus *bus,
     {
       case GST_MESSAGE_EOS:
         {
-          g_main_loop_quit (cogl_gst_video_sink_get_main_loop (data->sink));
+          g_main_loop_quit (data->main_loop);
           break;
         }
       case GST_MESSAGE_ERROR:
@@ -35,7 +36,7 @@ _bus_watch (GstBus *bus,
               g_error ("Playback error: %s\n", error->message);
               g_error_free (error);
             }
-          g_main_loop_quit (cogl_gst_video_sink_get_main_loop (data->sink));
+          g_main_loop_quit (data->main_loop);
           break;
         }
       default:
@@ -141,7 +142,6 @@ main (int argc,
   CoglContext *ctx;
   CoglOnscreen *onscreen;
   CoglMatrix view;
-  GMainLoop *loop;
   float fovy, aspect, z_near, z_2d, z_far;
   GstElement *pipeline;
   GstElement *bin;
@@ -201,12 +201,7 @@ main (int argc,
   bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
   gst_bus_add_watch (bus, _bus_watch, &data);
 
-  /*
-    Retrieve the GMainLoop from the cogl-gst sink. GStreamer makes the use of a
-    GMainLoop necessary .
-  */
-
-  loop = cogl_gst_video_sink_get_main_loop (data.sink);
+  data.main_loop = g_main_loop_new (NULL, FALSE);
 
   /*
     The cogl-pipeline-ready signal tells you when the cogl pipeline is
@@ -219,7 +214,10 @@ main (int argc,
 
   data.draw_ready = TRUE;
 
-  g_main_loop_run (loop);
+  g_main_loop_run (data.main_loop);
+
+  g_main_loop_unref (data.main_loop);
+
   return 0;
 }
 
-- 
1.7.11.3.g3c3efa5



More information about the Cogl mailing list