41 switch (GST_MESSAGE_TYPE (msg)) { |
40 switch (GST_MESSAGE_TYPE (msg)) { |
42 case GST_MESSAGE_EOS: |
41 case GST_MESSAGE_EOS: |
43 gst_element_set_state (pipeline, GST_STATE_NULL); |
42 gst_element_set_state (pipeline, GST_STATE_NULL); |
44 g_main_loop_quit(loop); |
43 g_main_loop_quit(loop); |
45 gst_object_unref (GST_OBJECT (pipeline)); |
44 gst_object_unref (GST_OBJECT (pipeline)); |
46 std_log(LOG_FILENAME_LINE, "Test Successful"); |
45 //std_log(LOG_FILENAME_LINE, "Test Successful"); |
47 create_xml(0); |
46 create_xml(0); |
48 break; |
47 break; |
49 case GST_MESSAGE_ERROR: { |
48 case GST_MESSAGE_ERROR: { |
50 gchar *debug; |
49 gchar *debug; |
51 GError *err; |
50 GError *err; |
52 gst_message_parse_error (msg, &err, &debug); |
51 gst_message_parse_error (msg, &err, &debug); |
53 g_free (debug); |
52 g_free (debug); |
54 g_print ("Error: %s\n", err->message); |
53 g_print ("Error: %s\n", err->message); |
55 g_error_free (err); |
54 g_error_free (err); |
56 std_log(LOG_FILENAME_LINE, "Test Failed"); |
55 //std_log(LOG_FILENAME_LINE, "Test Failed"); |
57 create_xml(1); |
56 create_xml(1); |
58 break; |
57 break; |
59 } |
58 } |
60 default: |
59 default: |
61 break; |
60 break; |
62 } |
61 } |
63 |
62 |
64 return TRUE; |
63 return TRUE; |
65 } |
64 } |
66 |
65 |
67 static void |
66 //static void |
68 new_pad_cb (GstElement *wavparse, GstPad *new_pad, gpointer pipeline) |
67 //new_pad_cb (GstElement *wavparse, GstPad *new_pad, gpointer pipeline) |
69 { |
68 // { |
|
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 ; |
70 |
88 |
71 gst_element_set_state (pipeline, GST_STATE_PAUSED); |
89 |
72 |
90 GstPad* sinkpad = NULL; |
73 if (!gst_element_link (wavparse, audioconvert)) |
91 |
74 g_error ("link(wavparse, audioconvert) failed!\n"); |
92 |
75 |
93 /* check media type */ |
76 gst_element_set_state (pipeline, GST_STATE_PLAYING); |
94 caps = gst_pad_get_caps (pad); |
77 } |
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 } |
78 |
144 |
79 int main (int argc, char *argv[]) |
145 int main (int argc, char *argv[]) |
80 { |
146 { |
81 |
147 int is_mp3_file = 0; |
82 |
148 const char* ext = 0; |
83 xmlfile = "launch_logs"; |
149 //xmlfile = "launch_logs"; |
84 std_log(LOG_FILENAME_LINE, "Test Started launch"); |
150 ////std_log(LOG_FILENAME_LINE, "Test Started launch"); |
85 |
151 |
86 if (argc != 2) { |
152 if (argc != 2) { |
87 g_print ("usage: %s <mp3 file>\n", argv[0]); |
153 g_print ("usage: %s <Test file>\n", argv[0]); |
88 std_log(LOG_FILENAME_LINE, "Test Failed"); |
154 //std_log(LOG_FILENAME_LINE, "Test Failed"); |
89 create_xml(1); |
155 create_xml(1); |
90 exit (-1); |
156 exit (-1); |
91 } |
157 } |
92 |
158 ext = strrchr(argv[1],'.'); |
|
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; |
93 gst_init (&argc, &argv); |
162 gst_init (&argc, &argv); |
94 loop = g_main_loop_new (NULL, FALSE); |
163 loop = g_main_loop_new (NULL, FALSE); |
95 |
164 |
96 /* create elements */ |
165 /* create elements */ |
97 pipeline = gst_pipeline_new ("audio-player"); |
166 pipeline = gst_pipeline_new ("audio-player"); |
98 source = gst_element_factory_make ("filesrc", "file-source"); |
167 source = gst_element_factory_make ("filesrc", "file-source"); |
99 decoder = gst_element_factory_make ("wavparse", "wavparse-decoder"); |
168 if (is_mp3_file) |
100 sink = gst_element_factory_make ("devsoundsink", "sink"); |
169 decoder = gst_element_factory_make ("mp3parse", "mp3parse"); |
101 audioconvert = gst_element_factory_make ("audioconvert", "audioconvert"); |
170 else |
102 audioresample = gst_element_factory_make ("audioresample", "audioresample"); |
171 decoder = gst_element_factory_make ("decodebin2", "decodebin2-decoder"); |
103 if (!pipeline || !source || !decoder || !audioconvert || !audioresample) { |
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) { |
104 g_print ("One element could not be created\n"); |
180 g_print ("One element could not be created\n"); |
105 return -1; |
181 return -1; |
106 } |
182 } |
107 /* set filename property on the file source. Also add a message handler. */ |
183 /* set filename property on the file source. Also add a message handler. */ |
108 g_object_set (G_OBJECT (source), "location", "c:\\data\\khuda1.wav", NULL); |
184 g_object_set (G_OBJECT (source), "location", argv[1], NULL); |
109 /* put all elements in a bin */ |
185 /* put all elements in a bin */ |
110 gst_bin_add_many (GST_BIN (pipeline),source, decoder,audioconvert,audioresample,sink, NULL); |
186 gst_bin_add_many (GST_BIN (pipeline),source, decoder,sink, NULL); |
111 /* 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. */ |
187 if (is_mp3_file) |
112 gst_element_link (source, decoder); |
188 gst_element_link_many (source, decoder, sink, NULL); |
113 |
189 else |
114 if (!gst_element_link (audioconvert,audioresample)) |
190 { |
115 g_error ("link(audioconvert,audioresample, sink) failed!\n"); |
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. */ |
116 if (!gst_element_link (audioresample, sink)) |
192 gst_element_link (source, decoder); |
117 g_error ("link(audioconvert,audioresample, sink) failed!\n"); |
193 } |
118 |
194 |
119 |
195 |
120 gst_bus_add_watch (gst_pipeline_get_bus (GST_PIPELINE (pipeline)), bus_call, loop); |
196 gst_bus_add_watch (gst_pipeline_get_bus (GST_PIPELINE (pipeline)), bus_call, loop); |
121 g_signal_connect (decoder, "pad-added", G_CALLBACK (new_pad_cb),pipeline); |
197 if (!is_mp3_file) |
|
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); |
122 /* Now set to playing and iterate. */ |
204 /* Now set to playing and iterate. */ |
123 g_print ("Setting to PLAYING\n"); |
205 g_print ("Setting to PLAYING\n"); |
124 gst_element_set_state (pipeline, GST_STATE_PLAYING); |
206 gst_element_set_state (pipeline, GST_STATE_PLAYING); |
125 g_print ("Running\n"); |
207 g_print ("Running\n"); |
126 g_main_loop_run (loop); |
208 g_main_loop_run (loop); |