gstreamer_core/tsrc/examples/manual/manual_helloworld/src/manual_helloworld.c
changeset 2 5505e8908944
child 8 4a7fac7dd34a
equal deleted inserted replaced
1:4c282e7dd6d3 2:5505e8908944
       
     1 
       
     2 /*** block  from ../../../docs/manual/basics-helloworld.xml ***/
       
     3 #include <gst/gst_global.h>
       
     4 #include <gst/gst.h>
       
     5 
       
     6 #ifdef HAVE_CONFIG_H
       
     7 #include "config.h"
       
     8 #endif
       
     9 
       
    10 #include <stdio.h>
       
    11 
       
    12 #include <glib.h>
       
    13 #include <glib/gstdio.h>
       
    14 
       
    15 #ifdef HAVE_UNISTD_H
       
    16 #include <unistd.h>             /* for close() */
       
    17 #endif
       
    18 
       
    19 #include "libgstreamer_wsd_macros.h"
       
    20 
       
    21 #ifndef EMULATOR
       
    22 int failed=0;
       
    23 FILE* fp_std_log_t=NULL;
       
    24 #define assert_failed *(get_assert_failed())
       
    25 #define fp_std_log *(get_fp_std_log())
       
    26 #endif
       
    27 
       
    28 #define LOG_FILE "c:\\logs\\helloworld_log1.txt"
       
    29 #include "std_log_result.h"
       
    30 #define LOG_FILENAME_LINE __FILE__, __LINE__
       
    31 
       
    32 //char* xmlfile = "helloworld";
       
    33 
       
    34 
       
    35 void create_xml(int result)
       
    36 {
       
    37     if(result)
       
    38         assert_failed = 1;
       
    39     
       
    40     testResultXml(xmlfile);
       
    41     close_log_file();
       
    42 }
       
    43 
       
    44 /*
       
    45  * Global objects are usually a bad thing. For the purpose of this
       
    46  * example, we will use them, however.
       
    47  */
       
    48 
       
    49 GstElement *pipeline, *source, *parser, *decoder, *conv, *sink;
       
    50 
       
    51 static gboolean
       
    52 bus_call (GstBus     *bus,
       
    53 	  GstMessage *msg,
       
    54 	  gpointer    data)
       
    55 {
       
    56   GMainLoop *loop = (GMainLoop *) data;
       
    57 
       
    58   switch (GST_MESSAGE_TYPE (msg)) {
       
    59     case GST_MESSAGE_EOS:
       
    60       g_print ("End-of-stream\n");
       
    61       g_main_loop_quit (loop);
       
    62       break;
       
    63     case GST_MESSAGE_ERROR: {
       
    64       gchar *debug;
       
    65       GError *err;
       
    66 
       
    67       gst_message_parse_error (msg, &err, &debug);
       
    68       g_free (debug);
       
    69 
       
    70       g_print ("Error: %s\n", err->message);
       
    71       g_error_free (err);
       
    72 
       
    73       g_main_loop_quit (loop);
       
    74       break;
       
    75     }
       
    76     default:
       
    77       break;
       
    78   }
       
    79 
       
    80   return TRUE;
       
    81 }
       
    82 
       
    83 static void
       
    84 new_pad (GstElement *element,
       
    85 	 GstPad     *pad,
       
    86 	 gpointer    data)
       
    87 {
       
    88   GstPad *sinkpad;
       
    89   /* We can now link this pad with the audio decoder */
       
    90   g_print ("Dynamic pad created, linking parser/decoder\n");
       
    91   gst_element_set_state (pipeline, GST_STATE_PAUSED);
       
    92   sink = gst_element_factory_make ("devsoundsink", "devoutput");
       
    93   gst_bin_add_many (GST_BIN (pipeline),sink,  NULL);
       
    94   // Since gst_element_get_pad is deprecated. Replace with gst_element_get_request_pad
       
    95   //sinkpad = gst_element_get_pad (decoder, "sink");
       
    96   //sinkpad = gst_element_get_request_pad (decoder, "sink");
       
    97   //gst_pad_link (pad, sinkpad);
       
    98   gst_element_link (element, sink);
       
    99   gst_element_set_state (pipeline, GST_STATE_PLAYING);
       
   100 }
       
   101 
       
   102 int
       
   103 main (int   argc,
       
   104       char *argv[])
       
   105 {
       
   106   GMainLoop *loop;
       
   107   GstBus *bus;
       
   108 	xmlfile = "helloworld";
       
   109   std_log(LOG_FILENAME_LINE, "Test Started helloworld");
       
   110 
       
   111   /* initialize GStreamer pt 1*/ 
       
   112   gst_init (&argc, &argv);
       
   113   loop = g_main_loop_new (NULL, FALSE);
       
   114  
       
   115   /* check input arguments */
       
   116  
       
   117   if (argc != 2) {
       
   118     g_print ("Usage: %s <wave file filename>\n", argv[0]);
       
   119     std_log(LOG_FILENAME_LINE, "Test Failed wave file as an argument need to be passed");
       
   120     create_xml(1); 
       
   121     exit (-1);
       
   122   }
       
   123   
       
   124 
       
   125   /* create elements  pt2*/
       
   126    pipeline = gst_pipeline_new ("audio-player");
       
   127   source = gst_element_factory_make ("filesrc", "file-source");
       
   128   
       
   129   // Path hardcoded need to change
       
   130   
       
   131  // g_object_set(source,"location",argv[1],NULL);
       
   132   
       
   133   g_object_set(source,"location",argv[1],NULL);
       
   134   
       
   135   parser = gst_element_factory_make ("wavparse", "waveparser");
       
   136  
       
   137  
       
   138   
       
   139   if (!pipeline || !source || !parser ) {
       
   140     g_print ("One element could not be created\n");
       
   141     return -1;
       
   142   }
       
   143 
       
   144   /* set filename property on the file source. Also add a message
       
   145    * handler.  pt3*/
       
   146   
       
   147 
       
   148   bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
       
   149   gst_bus_add_watch (bus, bus_call, loop);
       
   150   gst_object_unref (bus);
       
   151 
       
   152   /* put all elements in a bin pt4*/
       
   153   gst_bin_add_many (GST_BIN (pipeline),
       
   154 		    source, parser,  NULL);
       
   155 
       
   156   /* link together - note that we cannot link the parser and
       
   157    * decoder yet, becuse the parser uses dynamic pads. For that,
       
   158    * we set a pad-added signal handler. pt5*/
       
   159   gst_element_link (source, parser);
       
   160  
       
   161   g_signal_connect (parser, "pad-added", G_CALLBACK (new_pad), NULL);
       
   162 
       
   163   /* Now set to playing and iterate. pt6*/
       
   164   g_print ("Setting to PLAYING\n");
       
   165   gst_element_set_state (pipeline, GST_STATE_PLAYING);
       
   166   g_print ("Running\n");
       
   167   g_main_loop_run (loop);
       
   168 
       
   169   /* clean up nicely pt7*/
       
   170   g_print ("Returned, stopping playback\n");
       
   171   gst_element_set_state (pipeline, GST_STATE_NULL);
       
   172   g_print ("Deleting pipeline\n");
       
   173   gst_object_unref (GST_OBJECT (pipeline));
       
   174 
       
   175   std_log(LOG_FILENAME_LINE, "Test Successful");
       
   176   create_xml(0);
       
   177   return 0;
       
   178 }