Modified in accordance to coding guidelines for header and C files.
[glsdk/dual-decode.git] / src / gst-controller.c
index d436a12b7480c7ce44db3f777c24faa386d3901b..90e4dcec81056551749d6f86424e331127b3f158 100644 (file)
@@ -71,68 +71,64 @@ static gboolean attachPipeElements (Pipeline *pipePtr, GstElement *sink0,
     GstElement *queue1 = NULL;                                                  
     GstPad *pad = NULL;   
     
-    
-    
-       bin = gst_bin_new ("vsinkbin");
-       tee = gst_element_factory_make ("tee","splitter"); 
-       //sink0 = createImageSinkFromWindow (drawArea1, "sink0");
-       queue0 = gst_element_factory_make ("queue","q0");  
-        queue1 = gst_element_factory_make ("queue","q1");
-
-        if (NULL == sink0)
-           fsink0 = gst_element_factory_make ("fakesink", fsinkArr[fsinkCounter++]);
-        if (NULL == sink1)                         
-            fsink1 = gst_element_factory_make ("fakesink", fsinkArr[fsinkCounter++]); 
+    bin = gst_bin_new ("vsinkbin");
+    tee = gst_element_factory_make ("tee","splitter"); 
+    queue0 = gst_element_factory_make ("queue","q0");  
+    queue1 = gst_element_factory_make ("queue","q1");
+
+    if (NULL == sink0)
+       fsink0 = gst_element_factory_make ("fakesink", fsinkArr[fsinkCounter++]);
+    if (NULL == sink1)                         
+        fsink1 = gst_element_factory_make ("fakesink", fsinkArr[fsinkCounter++]); 
                
-
-       if ( !bin || !tee || !queue0 || !queue1) {
-           ret = FALSE;
-           goto exit;
-       }
-        if (NULL == sink0 && NULL == sink1) {           
-           gst_bin_add_many (GST_BIN (bin), tee, 
-                              fsink0, fsink1, queue0, queue1,NULL); 
-            gst_element_link (queue0, fsink0);
-            gst_element_link(queue1,fsink1);
-       }
-
-        else if (NULL != sink0 && NULL == sink1){
-            gst_bin_add_many (GST_BIN (bin), tee,                               
-                              sink0, fsink1, queue0, queue1,NULL);
-            gst_element_link (queue0, sink0);
-            gst_element_link(queue1,fsink1);
-        }
-        else if (NULL!= sink0 && NULL!=sink1) {
-             gst_bin_add_many (GST_BIN (bin), tee,                               
-                              sink0, sink1, queue0, queue1,NULL);              
-            gst_element_link (queue0, sink0);                                    
-            gst_element_link(queue1,sink1);                                    
-        }      
+    if (!bin || !tee || !queue0 || !queue1) {
+        ret = FALSE;
+       goto exit;
+    }
+    if (NULL == sink0 && NULL == sink1) {           
+       gst_bin_add_many (GST_BIN (bin), tee, fsink0, fsink1, queue0, queue1,
+                          NULL); 
+        gst_element_link (queue0, fsink0);
+        gst_element_link (queue1,fsink1);
+    }
+
+    else if (NULL != sink0 && NULL == sink1) {
+        gst_bin_add_many (GST_BIN (bin), tee, sink0, fsink1, queue0, queue1,
+                          NULL);
+        gst_element_link (queue0, sink0);
+        gst_element_link (queue1,fsink1);
+   }
+   else if (NULL!= sink0 && NULL!=sink1) {
+       gst_bin_add_many (GST_BIN (bin), tee, sink0, sink1, queue0, queue1,
+                         NULL);              
+       gst_element_link (queue0, sink0);                                    
+       gst_element_link (queue1,sink1);                                    
+    }      
     
-        else {
-            ret = FALSE;
-            goto exit;
-        }
-       /*Connecting the tee through queues is necessary to sync the two displays*/ 
-       gst_element_link(tee,queue0);                                               
-       gst_element_link(tee,queue1);                                               
-                                                                                
-       pad = gst_element_get_static_pad (tee, "sink");                             
-       gst_element_add_pad (bin, gst_ghost_pad_new ("sink", pad));                 
-       gst_object_unref (GST_OBJECT (pad)); 
-       g_object_set (G_OBJECT (pipePtr->pipe), "video-sink", bin, NULL);     
+    else {
+        ret = FALSE;
+        goto exit;
+    }
+    /*Connecting the tee through queues is necessary to sync the two displays*/ 
+    gst_element_link (tee,queue0);                                               
+    gst_element_link (tee,queue1);                                               
+    
+    pad = gst_element_get_static_pad (tee, "sink");                             
+    gst_element_add_pad (bin, gst_ghost_pad_new ("sink", pad));                 
+    gst_object_unref (GST_OBJECT (pad)); 
+    g_object_set (G_OBJECT (pipePtr->pipe), "video-sink", bin, NULL);     
  
 exit:    return ret;
 }
 
-gboolean busCallback(GstBus *bus, GstMessage *msg, gpointer data)
+static gboolean busCallback (GstBus *bus, GstMessage *msg, gpointer data)
 {    
        gchar *name             = (gchar *)data;
     gchar *debugMsg     = NULL;                                                 
     GError *err         = NULL;                                                 
-    static int count = 0;
+    static int count    = 0;
 
-    switch(GST_MESSAGE_TYPE(msg)){                                              
+    switch (GST_MESSAGE_TYPE(msg)) {                                              
                                                                                 
     case GST_MESSAGE_EOS:                                                   
         g_printerr("%s -> Message (EOS) : End of stream.\n",name);                          
@@ -180,6 +176,11 @@ static void getTime (gint64 arr[], gint64 time)
                           Public Functions
 
 ******************************************************************************/       
+
+
+/*****************************************************************************
+*                         see gst-controller.h
+******************************************************************************/
 Pipeline * DualDecode_createPipeline()
 {
     Pipeline *pipelinePtr = (Pipeline *) malloc (sizeof(Pipeline));
@@ -188,8 +189,8 @@ Pipeline * DualDecode_createPipeline()
     GstBus *bus = NULL;
                                                                                 
            
-    pipelinePtr->pipe = gst_element_factory_make("playbin2",NULL);                 
-    bus = gst_pipeline_get_bus (GST_PIPELINE(pipelinePtr->pipe));                    
+    pipelinePtr->pipe = gst_element_factory_make ("playbin2",NULL);                 
+    bus = gst_pipeline_get_bus (GST_PIPELINE (pipelinePtr->pipe));                    
     pipelinePtr->busSignal = gst_bus_add_watch (bus,busCallback, NULL);                                   
     gst_object_unref (bus);     
     pipelinePtr->logFunc = NULL;
@@ -198,7 +199,8 @@ Pipeline * DualDecode_createPipeline()
     return pipelinePtr;                
 }
 
-gboolean DualDecode_setSinksForPipes (Pipeline **pipes,GstElement *sink0, GstElement *sink1)
+gboolean DualDecode_setSinksForPipes (Pipeline **pipes, GstElement *sink0, 
+                                      GstElement *sink1)
 {
     gboolean ret = TRUE;
     attachPipeElements (pipes[0], sink0, NULL);
@@ -207,15 +209,14 @@ gboolean DualDecode_setSinksForPipes (Pipeline **pipes,GstElement *sink0, GstEle
 
     return ret;
 }
-gboolean DualDecode_seekMedia(Pipeline *pipePtr, gint64 position)
+gboolean DualDecode_seekMedia (Pipeline *pipePtr, gint64 position)
 {
-       if(position < 0){
+       if (position < 0) {
                return FALSE;
        }
-       return gst_element_seek_simple(pipePtr->pipe,
-                       GST_FORMAT_TIME,
-                       GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT,
-                       position);
+       return gst_element_seek_simple (pipePtr->pipe, GST_FORMAT_TIME,
+                                          GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT,
+                                              position);
 }
 
 
@@ -223,13 +224,15 @@ gboolean DualDecode_pauseMedia (Pipeline *pipePtr)
 {
     gboolean ret = TRUE;
     GstStateChangeReturn stateReturn;
-    if (GST_STATE_CHANGE_ASYNC == gst_element_set_state (pipePtr->pipe, GST_STATE_PAUSED)){
+    if (GST_STATE_CHANGE_ASYNC == 
+        gst_element_set_state (pipePtr->pipe, GST_STATE_PAUSED)) {
         g_print ("STATE CHANGE RETURNED ASYNC \n");
         stateReturn = gst_element_get_state (pipePtr->pipe,
                                 NULL,
                                 NULL,
                                 TIMEOUT);
-        g_print ("GET STATE RETURNED %s\n", gst_element_state_change_return_get_name (stateReturn));
+        g_print ("GET STATE RETURNED %s\n", 
+                  gst_element_state_change_return_get_name (stateReturn));
     
     }    
     return ret;
@@ -238,7 +241,7 @@ gboolean DualDecode_pauseMedia (Pipeline *pipePtr)
 gboolean DualDecode_resumeMedia (Pipeline *pipePtr)                              
 {                                                                               
     gboolean ret = TRUE;                                                        
-    if(!gst_element_set_state (pipePtr->pipe, GST_STATE_PLAYING))                
+    if (!gst_element_set_state (pipePtr->pipe, GST_STATE_PLAYING))                
         ret = FALSE;                                                            
     g_print ("IN RESUME MEDIA\n");                                                                            
     return ret;                                                                 
@@ -247,7 +250,7 @@ gboolean DualDecode_resumeMedia (Pipeline *pipePtr)
 gboolean DualDecode_stopMedia (Pipeline *pipePtr)                             
 {                                                                               
     gboolean ret = TRUE;                                                        
-    if(!gst_element_set_state (pipePtr->pipe, GST_STATE_NULL))               
+    if (!gst_element_set_state (pipePtr->pipe, GST_STATE_NULL))               
         ret = FALSE;                                                            
                                                                                 
     return ret;                                                                 
@@ -266,15 +269,12 @@ GstState DualDecode_getMediaState(Pipeline *pipePtr)
 {
        GstState state, pending;
     g_print ("IN GET MEDIA STATE ENTRY\n");
-       if(GST_STATE_CHANGE_SUCCESS != gst_element_get_state(
-                               pipePtr->pipe,
-                               &state,
-                               &pending,
-                               GST_CLOCK_TIME_NONE)){
+       if (GST_STATE_CHANGE_SUCCESS != gst_element_get_state(
+               pipePtr->pipe, &state, &pending, GST_CLOCK_TIME_NONE)) {
                /*TODO : a bug here*/
-               g_printerr("No state in GstElement\n");
-       }
-    g_print("EXITING FROM GET MEDIA STATE\n");
+               g_printerr ("No state in GstElement\n");
+       } 
+    g_print ("EXITING FROM GET MEDIA STATE\n");
        return state;
 }
 
@@ -319,12 +319,12 @@ gboolean DualDecode_playMedia (Pipeline *pipePtr, gchar *filename, gint64 positi
     gboolean ret = TRUE;                                                        
 
     g_print ("IN PLAYMEDIA2");                                                                                
-    g_object_set(G_OBJECT(pipePtr->pipe),"uri", filename,NULL);                 
+    g_object_set (G_OBJECT (pipePtr->pipe),"uri", filename,NULL);                 
     gst_element_set_state (pipePtr->pipe, GST_STATE_NULL);                      
     gst_element_set_state (pipePtr->pipe, GST_STATE_PLAYING);                   
                                                                                 
-    DualDecode_getMediaState(pipePtr);                                          
-    DualDecode_seekMedia(pipePtr, position);                                    
+    DualDecode_getMediaState (pipePtr);                                          
+    DualDecode_seekMedia (pipePtr, position);                                    
     
     return ret;                                                                            
                                                                                 
@@ -341,13 +341,10 @@ gboolean DualDecode_singleToDual (Pipeline **pipes,GstElement * otherWindowSink,
     GstElement *fsink     = NULL;
     GstElement *queue0    = NULL;                                                  
     GstElement *queue1    = NULL;                                                  
-    GstState state0       = NULL; 
+    GstState state0       = GST_STATE_NULL; 
    
-    gst_element_get_state(                                              
-                pipes[thisWindow]->pipe,                                                  
-                &state0,                                                         
-                NULL,                                                        
-                GST_CLOCK_TIME_NONE);  
+    gst_element_get_state (pipes[thisWindow]->pipe, &state0, NULL,                                                        
+                           GST_CLOCK_TIME_NONE);  
 
     /*Remove  otherWindowsink from this pipeline*/
     g_object_get (G_OBJECT (pipes[thisWindow]->pipe),"video-sink", &thisbin,NULL);
@@ -406,7 +403,7 @@ gboolean DualDecode_dualToSingle (Pipeline **pipes,GstElement * otherWindowSink,
     fsink = gst_bin_get_by_name (GST_BIN (bin), "fsink0");                
     if (NULL == fsink)                                                    
         fsink = gst_bin_get_by_name (GST_BIN (bin), "fsink1");            
-    name = gst_element_get_name(fsink);                                   
+    name = gst_element_get_name (fsink);                                   
     gst_element_unlink (queue1, fsink);                                   
     gst_object_ref (fsink);                                               
     gst_bin_remove (GST_BIN (bin),fsink);