|
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 |
|
22 |
|
23 #define LOG_FILE "c:\\logs\\hello_world_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 |
|
37 static void |
|
38 event_loop (GstElement * pipe) |
|
39 { |
|
40 GstBus *bus; |
|
41 GstMessage *message = NULL; |
|
42 |
|
43 bus = gst_element_get_bus (GST_ELEMENT (pipe)); |
|
44 |
|
45 while (TRUE) { |
|
46 message = gst_bus_poll (bus, GST_MESSAGE_ANY, -1); |
|
47 |
|
48 g_assert (message != NULL); |
|
49 |
|
50 switch (message->type) { |
|
51 case GST_MESSAGE_EOS: |
|
52 gst_message_unref (message); |
|
53 return; |
|
54 case GST_MESSAGE_WARNING: |
|
55 case GST_MESSAGE_ERROR:{ |
|
56 GError *gerror; |
|
57 gchar *debug; |
|
58 |
|
59 gst_message_parse_error (message, &gerror, &debug); |
|
60 gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug); |
|
61 gst_message_unref (message); |
|
62 g_error_free (gerror); |
|
63 g_free (debug); |
|
64 return; |
|
65 } |
|
66 default: |
|
67 gst_message_unref (message); |
|
68 break; |
|
69 } |
|
70 } |
|
71 } |
|
72 |
|
73 int |
|
74 main (int argc, char *argv[]) |
|
75 { |
|
76 GstElement *bin, *filesrc, *decoder, *audiosink; |
|
77 GstElement *conv, *resample; |
|
78 xmlfile = "helloworld_logs"; |
|
79 std_log(LOG_FILENAME_LINE, "Test Started hellowworld"); |
|
80 |
|
81 gst_init (&argc, &argv); |
|
82 |
|
83 if (argc != 2) { |
|
84 g_print ("usage: %s <mp3 file>\n", argv[0]); |
|
85 std_log(LOG_FILENAME_LINE, "Test Failed argument need to be passed"); |
|
86 create_xml(1); |
|
87 exit (-1); |
|
88 } |
|
89 |
|
90 /* create a new bin to hold the elements */ |
|
91 bin = gst_pipeline_new ("pipeline"); |
|
92 g_assert (bin); |
|
93 |
|
94 /* create a disk reader */ |
|
95 filesrc = gst_element_factory_make ("filesrc", "disk_source"); |
|
96 g_assert (filesrc); |
|
97 g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL); |
|
98 |
|
99 /* now it's time to get the decoder */ |
|
100 decoder = gst_element_factory_make ("mad", "decode"); |
|
101 if (!decoder) { |
|
102 std_log(LOG_FILENAME_LINE, "could not find plugin mad"); |
|
103 g_print ("could not find plugin \"mad\""); |
|
104 return -1; |
|
105 } |
|
106 |
|
107 /* also, we need to add some converters to make sure the audio stream |
|
108 * from the decoder is converted into a format the audio sink can |
|
109 * understand (if necessary) */ |
|
110 conv = gst_element_factory_make ("audioconvert", "audioconvert"); |
|
111 if (!conv) { |
|
112 std_log(LOG_FILENAME_LINE, "could not create \"audioconvert\" element!"); |
|
113 g_print ("could not create \"audioconvert\" element!"); |
|
114 return -1; |
|
115 } |
|
116 resample = gst_element_factory_make ("audioresample", "audioresample"); |
|
117 if (!conv) { |
|
118 std_log(LOG_FILENAME_LINE, "could not create \"audioresample\" element!"); |
|
119 g_print ("could not create \"audioresample\" element!"); |
|
120 return -1; |
|
121 } |
|
122 |
|
123 /* and an audio sink */ |
|
124 audiosink = gst_element_factory_make ("devsoundsink", "play_audio"); |
|
125 g_assert (audiosink); |
|
126 |
|
127 /* add objects to the main pipeline */ |
|
128 gst_bin_add_many (GST_BIN (bin), filesrc, decoder, conv, |
|
129 resample, audiosink, NULL); |
|
130 |
|
131 /* link the elements */ |
|
132 gst_element_link_many (filesrc, decoder, conv, resample, audiosink, NULL); |
|
133 |
|
134 /* start playing */ |
|
135 std_log(LOG_FILENAME_LINE, "START PLAYING"); |
|
136 gst_element_set_state (bin, GST_STATE_PLAYING); |
|
137 std_log(LOG_FILENAME_LINE, "STOP PLAYING "); |
|
138 /* Run event loop listening for bus messages until EOS or ERROR */ |
|
139 event_loop (bin); |
|
140 |
|
141 /* stop the bin */ |
|
142 std_log(LOG_FILENAME_LINE, "START BIN"); |
|
143 gst_element_set_state (bin, GST_STATE_NULL); |
|
144 std_log(LOG_FILENAME_LINE, "START BIN"); |
|
145 |
|
146 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
147 create_xml(0); |
|
148 exit (0); |
|
149 } |