Modified in acordance to coding guidelines.
[glsdk/dual-decode.git] / src / gst-controller.c
index 7a26542a1b8b8da88c3932d1becf9b1837daada8..d436a12b7480c7ce44db3f777c24faa386d3901b 100644 (file)
@@ -42,7 +42,7 @@
 /**                                                                             
  * @file  gst-controller.c                                                                 
  *                                                                              
- * @brief                                                                       
+ * @brief Imeplements GStreamer related functions                                                                      
  */ 
 #include <stdint.h>
 #include <string.h>
@@ -54,6 +54,11 @@ gchar * fsinkArr [] = {"fsink0", "fsink1"};
 static gint fsinkCounter = 0;
 static void getTime (gint64 arr[], gint64 time);
 
+/******************************************************************************
+                     
+                           Static Functions
+
+******************************************************************************/
 static gboolean attachPipeElements (Pipeline *pipePtr, GstElement *sink0, 
                              GstElement *sink1)
 {
@@ -111,18 +116,15 @@ static gboolean attachPipeElements (Pipeline *pipePtr, GstElement *sink0,
        /*Connecting the tee through queues is necessary to sync the two displays*/ 
        gst_element_link(tee,queue0);                                               
        gst_element_link(tee,queue1);                                               
-       //gst_element_link(queue0,sink0);                                             
-       //gst_element_link(queue1,sink1);                                             
                                                                                 
        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)
 {    
        gchar *name             = (gchar *)data;
@@ -132,26 +134,27 @@ gboolean busCallback(GstBus *bus, GstMessage *msg, gpointer data)
 
     switch(GST_MESSAGE_TYPE(msg)){                                              
                                                                                 
-        case GST_MESSAGE_EOS:                                                   
-            g_printerr("%s -> Message (EOS) : End of stream.\n",name);                          
-                       count++;
-            break;                                                              
+    case GST_MESSAGE_EOS:                                                   
+        g_printerr("%s -> Message (EOS) : End of stream.\n",name);                          
+           count++;
+        break;                                                              
                                                                                
-         case GST_MESSAGE_ERROR: {                                             
-            gst_message_parse_error(msg,&err,&debugMsg);                      
-            g_printerr("%s -> Message (ERROR) : %s : debug ( %s )\n", name,err->message,debugMsg);                                                      
-            g_free(debugMsg);                                                   
-            g_error_free(err);                                                  
-                       count++;
-            break;                                                              
-        }                                                                       
-        case GST_MESSAGE_WARNING: {                                             
-            gst_message_parse_warning(msg,&err,&debugMsg);                      
-            g_printerr("%s -> Message (WARNING) : %s : debug ( %s )\n",
+    case GST_MESSAGE_ERROR: {                                             
+        gst_message_parse_error(msg,&err,&debugMsg);                      
+        g_printerr("%s -> Message (ERROR) : %s : debug ( %s )\n", 
+                            name,err->message,debugMsg);                                                      
+        g_free(debugMsg);                                                   
+        g_error_free(err);                                                  
+           count++;
+        break;                                                              
+    }                                                                       
+    case GST_MESSAGE_WARNING: {                                             
+        gst_message_parse_warning(msg,&err,&debugMsg);                      
+        g_printerr("%s -> Message (WARNING) : %s : debug ( %s )\n",
                                            name,err->message,debugMsg);                                                      
-            g_free(debugMsg);                                                   
-            g_error_free(err);                                                  
-            break;                                                              
+        g_free(debugMsg);                                                   
+        g_error_free(err);                                                  
+        break;                                                              
         }                                                                       
                                                                                 
         default:                                                                
@@ -159,8 +162,24 @@ gboolean busCallback(GstBus *bus, GstMessage *msg, gpointer data)
     }                                                                           
                                                                                 
     return TRUE;                                                                
+}
+
+static void getTime (gint64 arr[], gint64 time)
+{
+    gint8 i = 0;
+    time = time / (gint64) NANOSEC;
+
+    for (i = 0; i < 3; i++){
+        arr[i] = time % 60;
+        time = time / 60;
+    } 
+    
 } 
-       
+/*****************************************************************************
+
+                          Public Functions
+
+******************************************************************************/       
 Pipeline * DualDecode_createPipeline()
 {
     Pipeline *pipelinePtr = (Pipeline *) malloc (sizeof(Pipeline));
@@ -286,23 +305,13 @@ gboolean DualDecode_getMediaPosition (Pipeline *pipePtr, gdouble *seekScaleValue
     return ret;
 }
 
-static void getTime (gint64 arr[], gint64 time)
-{
-    gint8 i = 0;
-    time = time / (gint64) NANOSEC;
 
-    for (i = 0; i < 3; i++){
-        arr[i] = time % 60;
-        time = time / 60;
-    } 
-    
-}
 
-void DualDecode_setPipelineSink (Pipeline *pipePtr, GstElement *sink0, GstElement *sink1)
+void DualDecode_setPipelineSink (Pipeline *pipePtr, GstElement *sink0, 
+                                 GstElement *sink1)
 {
     g_print ("IN SET PIPE IN SINGLE MODE");
     attachPipeElements (pipePtr, sink0, sink1);
-    //gst_element_set_state (pipePtr->pipe, GST_STATE_READY);
 }
 
 gboolean DualDecode_playMedia (Pipeline *pipePtr, gchar *filename, gint64 position)            
@@ -327,44 +336,45 @@ gboolean DualDecode_singleToDual (Pipeline **pipes,GstElement * otherWindowSink,
 {
     gboolean ret = TRUE;
 
-    GstElement *thisbin = NULL;
-    GstElement *otherbin = NULL;
-    GstElement *fsink = NULL;
-    GstElement *queue0 = NULL;                                                  
-    GstElement *queue1 = NULL;                                                  
-    GstState state0 ; 
+    GstElement *thisbin   = NULL;
+    GstElement *otherbin  = NULL;
+    GstElement *fsink     = NULL;
+    GstElement *queue0    = NULL;                                                  
+    GstElement *queue1    = NULL;                                                  
+    GstState state0       = NULL
    
-    //gst_element_set_state (pipes[thisWindow]->pipe, GST_STATE_PAUSED);
     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);
     queue1 = gst_bin_get_by_name (GST_BIN (thisbin), "q1");                   
     gst_element_unlink (queue1, otherWindowSink);          
     gst_object_ref (otherWindowSink);                      
     gst_bin_remove (GST_BIN (thisbin), otherWindowSink);       
-                                                                                
+    
+    /*Remove a fake sink from the other pipeline*/                                                                            
     g_object_get (G_OBJECT (pipes[otherWindow]->pipe), "video-sink", &otherbin, NULL);
     queue0 = gst_bin_get_by_name (GST_BIN (otherbin), "q0");                  
     fsink = gst_bin_get_by_name (GST_BIN (otherbin), "fsink0");               
     gst_element_unlink (queue0, fsink);                                   
     gst_object_ref (fsink);                                               
     gst_bin_remove (GST_BIN (otherbin), fsink);                               
-                                                                                
+      
+    /*Add fakesink to this pipeline*/                                                                          
     gst_bin_add (GST_BIN (thisbin), fsink);                                  
     gst_element_sync_state_with_parent (fsink);                          
     gst_element_link (queue1, fsink);                                    
-                                                                                
+    
+    /* Add otherWindowSink to other pipeline */                                                                            
     gst_element_set_state (otherWindowSink, GST_STATE_READY);
     gst_bin_add (GST_BIN (otherbin), otherWindowSink);        
-    //gst_element_sync_state_with_parent (window[otherWindow]->sink);                          
     gst_element_link (queue0, otherWindowSink);           
                                                                                 
     DualDecode_playMedia (pipes[otherWindow], filename, 0);
-    //DualDecode_playMedia (pipes[thiswindow], filename[DECODER_INDEX_SINGLE], SEEK_START);
     gst_element_set_state (pipes[thisWindow]->pipe, state0); 
 
     return ret;
@@ -374,35 +384,36 @@ gboolean DualDecode_dualToSingle (Pipeline **pipes,GstElement * otherWindowSink,
                                   gint thisWindow, gint otherWindow)  
 {
     gboolean ret = TRUE;
-
-    GstElement *bin = NULL;
-    GstElement *bin2 = NULL;
-    GstElement *fsink = NULL;
+    GstElement *bin    = NULL;
+    GstElement *bin2   = NULL;
+    GstElement *fsink  = NULL;
     GstElement *fsink0 = NULL;
     GstElement *queue0 = NULL;
     GstElement *queue1 = NULL; 
-    gchar *name = NULL;
+    gchar *name        = NULL;
+    
+    /*Remove otherWindow sink from other pipeline*/
     gst_element_set_state (pipes[otherWindow]->pipe, GST_STATE_PAUSED);
-                                                                                
     g_object_get (G_OBJECT (pipes[otherWindow]->pipe), "video-sink", &bin2, NULL);
     queue0 = gst_bin_get_by_name (GST_BIN (bin2), "q0");                  
     gst_element_unlink (queue0, otherWindowSink);          
     gst_object_ref (otherWindowSink);                      
     gst_bin_remove (GST_BIN (bin2), otherWindowSink);       
-                                                                                
+    
+    /*Remove fake sink from this pipeline*/                                                                            
     g_object_get (G_OBJECT (pipes[thisWindow]->pipe), "video-sink", &bin, NULL);
     queue1 = gst_bin_get_by_name (GST_BIN (bin), "q1");                   
     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);                                   
-                                                                                
     gst_element_unlink (queue1, fsink);                                   
     gst_object_ref (fsink);                                               
     gst_bin_remove (GST_BIN (bin),fsink);                                 
                                                                                 
     gst_element_set_state (otherWindowSink, GST_STATE_READY);
-                                                                                
+    
+    /*Add fake sink to other pipeline */                                                                            
     gst_bin_add (GST_BIN (bin2), fsink);                                  
     gst_element_sync_state_with_parent (fsink);                           
                                                                                 
@@ -419,7 +430,9 @@ gboolean DualDecode_dualToSingle (Pipeline **pipes,GstElement * otherWindowSink,
         gst_element_link (queue1, fsink);                                 
         gst_element_link (queue0, fsink0);                                
     }                                                                     
-    g_free (name);                                                       
+    g_free (name);
+
+    /*Add otherWindowSink to this pipeline*/                                                      
     gst_bin_add (GST_BIN (bin), otherWindowSink);         
     gst_element_sync_state_with_parent (otherWindowSink); 
     gst_element_link (queue1, otherWindowSink);