|
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 #include <gst/gst_global.h> |
|
19 #include <stdlib.h> |
|
20 #include <gst/gst.h> |
|
21 #include <gst/gstelement.h> |
|
22 |
|
23 #define LOG_FILE "c:\\logs\\launch_logs.txt" |
|
24 #include "std_log_result.h" |
|
25 #define LOG_FILENAME_LINE __FILE__, __LINE__ |
|
26 |
|
27 |
|
28 void create_xml(int result) |
|
29 { |
|
30 if(result) |
|
31 assert_failed = 1; |
|
32 |
|
33 testResultXml(xmlfile); |
|
34 close_log_file(); |
|
35 } |
|
36 GstElement *pipeline, *source, *wavparse,*sink,*conv,*resample,*decoder; |
|
37 GstBus *bus; |
|
38 GMainLoop *loop; |
|
39 |
|
40 static gboolean |
|
41 bus_call (GstBus *bus, |
|
42 GstMessage *msg, |
|
43 gpointer data) |
|
44 { |
|
45 switch (GST_MESSAGE_TYPE (msg)) { |
|
46 case GST_MESSAGE_EOS: |
|
47 gst_element_set_state (pipeline, GST_STATE_NULL); |
|
48 g_main_loop_quit(loop); |
|
49 gst_object_unref (GST_OBJECT (pipeline)); |
|
50 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
51 create_xml(0); |
|
52 break; |
|
53 case GST_MESSAGE_ERROR: { |
|
54 gchar *debug; |
|
55 GError *err; |
|
56 gst_message_parse_error (msg, &err, &debug); |
|
57 g_free (debug); |
|
58 g_print ("Error: %s\n", err->message); |
|
59 g_error_free (err); |
|
60 std_log(LOG_FILENAME_LINE, "Test Failed"); |
|
61 create_xml(1); |
|
62 break; |
|
63 } |
|
64 default: |
|
65 break; |
|
66 } |
|
67 |
|
68 return TRUE; |
|
69 } |
|
70 |
|
71 static void |
|
72 new_pad_cb (GstElement *wavparse, GstPad *new_pad, gpointer pipeline) |
|
73 { |
|
74 |
|
75 gst_element_set_state (pipeline, GST_STATE_PAUSED); |
|
76 |
|
77 if (!gst_element_link (wavparse, sink)) |
|
78 g_error ("link(wavparse, sink) failed!\n"); |
|
79 |
|
80 gst_element_set_state (pipeline, GST_STATE_PLAYING); |
|
81 } |
|
82 |
|
83 int main (int argc, char *argv[]) |
|
84 { |
|
85 |
|
86 |
|
87 xmlfile = "launch_logs"; |
|
88 std_log(LOG_FILENAME_LINE, "Test Started launch"); |
|
89 |
|
90 if (argc != 2) { |
|
91 g_print ("usage: %s <mp3 file>\n", argv[0]); |
|
92 std_log(LOG_FILENAME_LINE, "Test Failed"); |
|
93 create_xml(1); |
|
94 exit (-1); |
|
95 } |
|
96 |
|
97 gst_init (&argc, &argv); |
|
98 loop = g_main_loop_new (NULL, FALSE); |
|
99 |
|
100 /* create elements */ |
|
101 pipeline = gst_pipeline_new ("audio-player"); |
|
102 source = gst_element_factory_make ("filesrc", "file-source"); |
|
103 decoder = gst_element_factory_make ("wavparse", "wavparse-decoder"); |
|
104 sink = gst_element_factory_make ("devsoundsink", "sink"); |
|
105 if (!pipeline || !source || !decoder) { |
|
106 g_print ("One element could not be created\n"); |
|
107 return -1; |
|
108 } |
|
109 /* set filename property on the file source. Also add a message handler. */ |
|
110 g_object_set (G_OBJECT (source), "location", argv[1], NULL); |
|
111 /* put all elements in a bin */ |
|
112 gst_bin_add_many (GST_BIN (pipeline),source, decoder,sink, NULL); |
|
113 /* 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. */ |
|
114 gst_element_link (source, decoder); |
|
115 gst_bus_add_watch (gst_pipeline_get_bus (GST_PIPELINE (pipeline)), bus_call, loop); |
|
116 g_signal_connect (decoder, "pad-added", G_CALLBACK (new_pad_cb),pipeline); |
|
117 /* Now set to playing and iterate. */ |
|
118 g_print ("Setting to PLAYING\n"); |
|
119 gst_element_set_state (pipeline, GST_STATE_PLAYING); |
|
120 g_print ("Running\n"); |
|
121 g_main_loop_run (loop); |
|
122 /* clean up nicely */ |
|
123 g_print ("Returned, stopping playback\n"); |
|
124 gst_element_set_state (pipeline, GST_STATE_NULL); |
|
125 g_print ("Deleting pipeline\n"); |
|
126 gst_object_unref (GST_OBJECT (pipeline)); |
|
127 |
|
128 g_print ("completed palying audio\n"); |
|
129 //std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
130 //create_xml(0); |
|
131 return 0; |
|
132 } |
|
133 |