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