gstreamer_core/tsrc/examples/launch/src/launch.c
branchRCL_3
changeset 30 7e817e7e631c
parent 29 567bb019e3e3
equal deleted inserted replaced
29:567bb019e3e3 30:7e817e7e631c
     1 
     1 
     2 #include <gst/gst_global.h>
     2 #include <gst/gst_global.h>
     3 #include <stdlib.h>
     3 #include <stdlib.h>
     4 #include <gst/gst.h>
     4 #include <gst/gst.h>
     5 #include <gst/gstelement.h>
     5 #include <gst/gstelement.h>
     6 #include <string.h>
     6 
     7 #define LOG_FILE "c:\\logs\\launch_logs.txt" 
     7 #define LOG_FILE "c:\\logs\\launch_logs.txt" 
     8 #include "std_log_result.h" 
     8 #include "std_log_result.h" 
     9 #define LOG_FILENAME_LINE __FILE__, __LINE__
     9 #define LOG_FILENAME_LINE __FILE__, __LINE__
    10 
    10 
       
    11 
    11 void create_xml(int result)
    12 void create_xml(int result)
    12 {
    13 {
    13 
       
    14     if(result)
    14     if(result)
    15     {
       
    16         assert_failed = 1;
    15         assert_failed = 1;
    17     } 
    16     
    18 
       
    19     testResultXml(xmlfile);
    17     testResultXml(xmlfile);
    20     close_log_file();
    18     close_log_file();
    21 
       
    22     if(result)
       
    23     {
       
    24         exit (-1);
       
    25     }    
       
    26 
       
    27 }
    19 }
    28 
    20 GstElement *pipeline, *source, *wavparse,*sink,*conv,*resample,*decoder;
    29 GstElement *pipeline, *source, *wavparse,*sink,*conv,*resample,*decoder,*audioconvert,*audioresample ;
       
    30 GstBus *bus;
    21 GstBus *bus;
    31 GMainLoop *loop;
    22 GMainLoop *loop;
    32 //gboolean    link_with_devsoundsink;
       
    33 
    23 
    34 //audioconvert ! audioresample 
       
    35 static gboolean
    24 static gboolean
    36 bus_call (GstBus     *bus,
    25 bus_call (GstBus     *bus,
    37           GstMessage *msg,
    26           GstMessage *msg,
    38           gpointer    data)
    27           gpointer    data)
    39 {
    28 {
    40   switch (GST_MESSAGE_TYPE (msg)) {
    29   switch (GST_MESSAGE_TYPE (msg)) {
    41     case GST_MESSAGE_EOS:
    30     case GST_MESSAGE_EOS:
    42         gst_element_set_state (pipeline, GST_STATE_NULL);
    31         gst_element_set_state (pipeline, GST_STATE_NULL);
    43         g_main_loop_quit(loop);
    32         g_main_loop_quit(loop);
    44         gst_object_unref (GST_OBJECT (pipeline));
    33         gst_object_unref (GST_OBJECT (pipeline));
    45         //std_log(LOG_FILENAME_LINE, "Test Successful");
    34         std_log(LOG_FILENAME_LINE, "Test Successful");
    46         create_xml(0); 
    35         create_xml(0); 
    47       break;
    36       break;
    48     case GST_MESSAGE_ERROR: {
    37     case GST_MESSAGE_ERROR: {
    49       gchar *debug;
    38       gchar *debug;
    50       GError *err;
    39       GError *err;
    51       gst_message_parse_error (msg, &err, &debug);
    40       gst_message_parse_error (msg, &err, &debug);
    52       g_free (debug);
    41       g_free (debug);
    53       g_print ("Error: %s\n", err->message);
    42       g_print ("Error: %s\n", err->message);
    54       g_error_free (err);
    43       g_error_free (err);
    55       //std_log(LOG_FILENAME_LINE, "Test Failed");
    44       std_log(LOG_FILENAME_LINE, "Test Failed");
    56       create_xml(1); 
    45       create_xml(1); 
    57       break;
    46       break;
    58     }
    47     }
    59     default:
    48     default:
    60       break;
    49       break;
    61   }
    50   }
    62 
    51 
    63   return TRUE;
    52   return TRUE;
    64 }
    53 }
    65 
    54 
    66 //static void 
    55 static void 
    67 //new_pad_cb (GstElement *wavparse, GstPad *new_pad, gpointer pipeline)
    56 new_pad_cb (GstElement *wavparse, GstPad *new_pad, gpointer pipeline)
    68 // {
    57  {
    69 //   
       
    70 //   gst_element_set_state (pipeline, GST_STATE_PAUSED);
       
    71 //
       
    72 //   if (!gst_element_link (wavparse, audioconvert))
       
    73 //      g_error ("link(wavparse, audioconvert) failed!\n");
       
    74 //
       
    75 //   gst_element_set_state (pipeline, GST_STATE_PLAYING);
       
    76 // }
       
    77 
       
    78 
       
    79 static void
       
    80 cb_newpad (GstElement *decodebin,
       
    81        GstPad     *pad,
       
    82        gboolean    last,
       
    83        gpointer    data)
       
    84 {
       
    85     GstCaps *caps;
       
    86     GstStructure *str;
       
    87     GstPadLinkReturn linkret= GST_PAD_LINK_OK ;
       
    88    
    58    
    89 
    59    gst_element_set_state (pipeline, GST_STATE_PAUSED);
    90     GstPad* sinkpad = NULL;
    60    
    91 
    61    if (!gst_element_link (wavparse, sink))
       
    62       g_error ("link(wavparse, sink) failed!\n");
    92     
    63     
    93     /* check media type */
    64    gst_element_set_state (pipeline, GST_STATE_PLAYING);
    94     caps = gst_pad_get_caps (pad);
    65  }
    95     str = gst_caps_get_structure (caps, 0);
       
    96     if (!g_strrstr (gst_structure_get_name (str), "audio")) {
       
    97     gst_caps_unref (caps);
       
    98     return;
       
    99     }
       
   100     gst_caps_unref (caps);
       
   101     
       
   102 //    if( link_with_devsoundsink )
       
   103 //        {
       
   104         sinkpad = gst_element_get_pad( sink, "sink");
       
   105         //gst_bin_add_many (GST_BIN (pipeline),source, decoder,sink, NULL);
       
   106             
       
   107 //        }
       
   108 //    else
       
   109 //        {
       
   110 //        audioconvert = gst_element_factory_make ("audioconvert", "audioconvert");
       
   111 //        audioresample = gst_element_factory_make ("audioresample", "audioresample");        
       
   112 //        sinkpad = gst_element_get_pad( audioconvert, "sink");
       
   113 //        
       
   114 //        gst_bin_add_many (GST_BIN (pipeline),source, decoder,audioconvert,audioresample,sink, NULL);
       
   115 //        
       
   116 //        if (!gst_element_link (audioconvert,audioresample))
       
   117 //           g_error ("link(audioconvert,audioresample, sink) failed!\n");   
       
   118 //        if (!gst_element_link (audioresample, sink))
       
   119 //           g_error ("link(audioconvert,audioresample, sink) failed!\n");         
       
   120 //        }
       
   121     
       
   122     linkret = gst_pad_link (pad, sinkpad);
       
   123 }
       
   124 
       
   125 gboolean  cb_autoplug( GstBin * *bin,
       
   126                         GstPad        *pad,
       
   127                         GstCaps       *caps,
       
   128                         gpointer       user_data)
       
   129 {
       
   130     GstCaps* sinkcaps = NULL;    
       
   131     gboolean supported = FALSE;
       
   132     
       
   133     GstPad* sinkpad = gst_element_get_pad( sink, "sink");
       
   134     sinkcaps = gst_pad_get_caps( sinkpad );
       
   135     supported = gst_caps_is_subset( caps, sinkcaps );
       
   136     
       
   137     if( supported )
       
   138     {
       
   139         //link_with_devsoundsink = TRUE;
       
   140         return FALSE;
       
   141     }
       
   142     return TRUE;
       
   143 }
       
   144 
    66 
   145 int main (int argc, char *argv[])
    67 int main (int argc, char *argv[])
   146 {
    68 {
   147 	int is_mp3_file = 0;
    69     
   148   const char* ext = 0;  
    70     
   149     //xmlfile = "launch_logs";
    71     xmlfile = "launch_logs";
   150     ////std_log(LOG_FILENAME_LINE, "Test Started launch");
    72     std_log(LOG_FILENAME_LINE, "Test Started launch");
   151  
    73  
   152     if (argc != 2) {
    74     if (argc != 2) {
   153       g_print ("usage: %s <Test file>\n", argv[0]);
    75       g_print ("usage: %s <mp3 file>\n", argv[0]);
   154       //std_log(LOG_FILENAME_LINE, "Test Failed");
    76       std_log(LOG_FILENAME_LINE, "Test Failed");
   155       create_xml(1); 
    77       create_xml(1); 
   156       exit (-1);
    78       exit (-1);
   157     }
    79     }
   158     ext = strrchr(argv[1],'.');
    80     
   159     if ( ext && ( !strcmp(ext,".mp3") || !strcmp(ext,".Mp3") || !strcmp(ext,".MP3") || !strcmp(ext,".mP3") ) )
       
   160     	is_mp3_file = 1;
       
   161     //link_with_devsoundsink = FALSE;
       
   162     gst_init (&argc, &argv);
    81     gst_init (&argc, &argv);
   163     loop = g_main_loop_new (NULL, FALSE);
    82     loop = g_main_loop_new (NULL, FALSE);
   164     
    83     
   165     /* create elements */
    84     /* create elements */
   166     pipeline = gst_pipeline_new ("audio-player");
    85     pipeline = gst_pipeline_new ("audio-player");
   167     source = gst_element_factory_make ("filesrc", "file-source");
    86     source = gst_element_factory_make ("filesrc", "file-source");
   168     if (is_mp3_file)
    87     decoder = gst_element_factory_make ("wavparse", "wavparse-decoder");
   169 		  decoder = gst_element_factory_make ("mp3parse", "mp3parse");
    88     sink = gst_element_factory_make ("devsoundsink", "sink");
   170     else
    89         if (!pipeline || !source || !decoder) {
   171   		decoder = gst_element_factory_make ("decodebin2", "decodebin2-decoder");
       
   172 
       
   173   
       
   174     sink = gst_element_factory_make ("devsoundsink", "sink");    
       
   175 //    audioconvert = gst_element_factory_make ("audioconvert", "audioconvert");
       
   176 //    audioresample = gst_element_factory_make ("audioresample", "audioresample");    
       
   177 //    sink = gst_element_factory_make ("devsoundsink", "sink");
       
   178     
       
   179     if (!pipeline || !source || !decoder || !sink) {
       
   180         g_print ("One element could not be created\n");
    90         g_print ("One element could not be created\n");
   181         return -1;
    91         return -1;
   182         }
    92         }
   183     /* set filename property on the file source. Also add a message  handler. */
    93     /* set filename property on the file source. Also add a message  handler. */
   184     g_object_set (G_OBJECT (source), "location", argv[1], NULL);
    94     g_object_set (G_OBJECT (source), "location", argv[1], NULL);
   185             /* put all elements in a bin */
    95             /* put all elements in a bin */
   186     gst_bin_add_many (GST_BIN (pipeline),source, decoder,sink, NULL);
    96     gst_bin_add_many (GST_BIN (pipeline),source, decoder,sink, NULL);
   187     if (is_mp3_file)
    97             /* link together - note that we cannot link the parser and  decoder yet, because the parser uses dynamic pads. For that, we set a pad-added signal handler. */
   188   		gst_element_link_many (source, decoder, sink, NULL);
    98     gst_element_link (source, decoder);
   189 		else
       
   190 		{
       
   191       /* link together - note that we cannot link the parser and  decoder yet, because the parser uses dynamic pads. For that, we set a pad-added signal handler. */
       
   192     	gst_element_link (source, decoder);
       
   193     }
       
   194 
       
   195 
       
   196     gst_bus_add_watch (gst_pipeline_get_bus (GST_PIPELINE (pipeline)), bus_call, loop);
    99     gst_bus_add_watch (gst_pipeline_get_bus (GST_PIPELINE (pipeline)), bus_call, loop);
   197     if (!is_mp3_file)
   100     g_signal_connect (decoder, "pad-added", G_CALLBACK (new_pad_cb),pipeline);
   198 		{
       
   199     	g_signal_connect (decoder, "new-decoded-pad", G_CALLBACK (cb_newpad), NULL);
       
   200     	g_signal_connect (decoder, "autoplug-continue", G_CALLBACK (cb_autoplug), NULL);
       
   201 		}
       
   202     
       
   203     //g_signal_connect (decoder, "pad-added", G_CALLBACK (new_pad_cb),pipeline);
       
   204             /* Now set to playing and iterate. */
   101             /* Now set to playing and iterate. */
   205     g_print ("Setting to PLAYING\n");
   102     g_print ("Setting to PLAYING\n");
   206     gst_element_set_state (pipeline, GST_STATE_PLAYING);
   103     gst_element_set_state (pipeline, GST_STATE_PLAYING);
   207     g_print ("Running\n");
   104     g_print ("Running\n");
   208     g_main_loop_run (loop);
   105     g_main_loop_run (loop);
   211     gst_element_set_state (pipeline, GST_STATE_NULL);
   108     gst_element_set_state (pipeline, GST_STATE_NULL);
   212     g_print ("Deleting pipeline\n");
   109     g_print ("Deleting pipeline\n");
   213     gst_object_unref (GST_OBJECT (pipeline));
   110     gst_object_unref (GST_OBJECT (pipeline));
   214     
   111     
   215     g_print ("completed palying audio\n");
   112     g_print ("completed palying audio\n");
   216     ////std_log(LOG_FILENAME_LINE, "Test Successful");
   113     //std_log(LOG_FILENAME_LINE, "Test Successful");
   217     //create_xml(0); 
   114     //create_xml(0); 
   218     return 0;
   115     return 0;
   219 }
   116 }
   220 
   117