gstreamer_core/tsrc/examples/manual/manual_playbin/src/manual_playbin.c
changeset 0 0e761a78d257
equal deleted inserted replaced
-1:000000000000 0:0e761a78d257
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 /*** block a  from ../../../docs/manual/highlevel-components.xml ***/
       
    19 
       
    20 #define LOG_FILE "c:\\logs\\playbin_logs.txt" 
       
    21 
       
    22 #include <gst/gst_global.h>
       
    23 #include "std_log_result.h" 
       
    24 #define LOG_FILENAME_LINE __FILE__, __LINE__
       
    25 
       
    26 void create_xml(int result)
       
    27 {
       
    28     if(result)
       
    29         assert_failed = 1;
       
    30     
       
    31     testResultXml(xmlfile);
       
    32     close_log_file();
       
    33 }
       
    34 
       
    35 #include <gst/gst.h>
       
    36 
       
    37 /*** block b  from ../../../docs/manual/highlevel-components.xml ***/
       
    38 static gboolean
       
    39 my_bus_callback (GstBus     *bus,
       
    40 		 GstMessage *message,
       
    41 		 gpointer    data)
       
    42 {
       
    43   GMainLoop *loop = data;
       
    44 
       
    45   switch (GST_MESSAGE_TYPE (message)) {
       
    46     case GST_MESSAGE_ERROR: {
       
    47       GError *err;
       
    48       gchar *debug;
       
    49 
       
    50       gst_message_parse_error (message, &err, &debug);
       
    51       g_print ("Error: %s\n", err->message);
       
    52       g_error_free (err);
       
    53       g_free (debug);
       
    54 
       
    55       g_main_loop_quit (loop);
       
    56       break;
       
    57     }
       
    58     case GST_MESSAGE_EOS:
       
    59       /* end-of-stream */
       
    60       g_main_loop_quit (loop);
       
    61       break;
       
    62     default:
       
    63       /* unhandled message */
       
    64       break;
       
    65   }
       
    66 
       
    67   /* remove message from the queue */
       
    68   return TRUE;
       
    69 }
       
    70 
       
    71 /*** block c  from ../../../docs/manual/highlevel-components.xml ***/
       
    72 gint
       
    73 main (gint   argc,
       
    74       gchar *argv[])
       
    75 {
       
    76   GMainLoop *loop;
       
    77   GstElement *play;
       
    78   GstBus *bus;
       
    79 
       
    80 	 xmlfile = "playbin";
       
    81   std_log(LOG_FILENAME_LINE, "Test Started playbin");
       
    82   
       
    83   /* init GStreamer */
       
    84   gst_init (&argc, &argv);
       
    85   loop = g_main_loop_new (NULL, FALSE);
       
    86 
       
    87   /* make sure we have a URI */
       
    88   if (argc != 2) {
       
    89     g_print ("Usage: %s <URI>\n", argv[0]);
       
    90         std_log(LOG_FILENAME_LINE, "Test Failed");
       
    91         create_xml(1);
       
    92     return -1;
       
    93   }
       
    94 
       
    95   /* set up */
       
    96   play = gst_element_factory_make ("playbin", "play");
       
    97   g_object_set (G_OBJECT (play), "uri", argv[1], NULL);
       
    98 
       
    99   bus = gst_pipeline_get_bus (GST_PIPELINE (play));
       
   100   gst_bus_add_watch (bus, my_bus_callback, loop);
       
   101   gst_object_unref (bus);
       
   102 
       
   103   gst_element_set_state (play, GST_STATE_PLAYING);
       
   104 
       
   105   /* now run */
       
   106   g_main_loop_run (loop);
       
   107 
       
   108   /* also clean up */
       
   109   gst_element_set_state (play, GST_STATE_NULL);
       
   110   gst_object_unref (GST_OBJECT (play));
       
   111 
       
   112   std_log(LOG_FILENAME_LINE, "Test Successful");
       
   113   create_xml(0); 
       
   114   
       
   115   return 0;
       
   116 }