|
1 |
|
2 #include <gst/gst_global.h> |
|
3 #include <stdlib.h> |
|
4 #include <gst/gst.h> |
|
5 #include <gst/gstelement.h> |
|
6 #include <string.h> |
|
7 #define LOG_FILE "c:\\logs\\wav_record_logs.txt" |
|
8 #include "std_log_result.h" |
|
9 #define LOG_FILENAME_LINE __FILE__, __LINE__ |
|
10 |
|
11 void create_xml(int result) |
|
12 { |
|
13 |
|
14 if(result) |
|
15 { |
|
16 assert_failed = 1; |
|
17 } |
|
18 |
|
19 testResultXml(xmlfile); |
|
20 close_log_file(); |
|
21 |
|
22 if(result) |
|
23 { |
|
24 exit (-1); |
|
25 } |
|
26 |
|
27 } |
|
28 |
|
29 GstElement *pipeline, *source, *wavenc,*sink; |
|
30 GstBus *bus; |
|
31 GMainLoop *loop; |
|
32 |
|
33 static gboolean |
|
34 bus_call (GstBus *bus, |
|
35 GstMessage *msg, |
|
36 gpointer data) |
|
37 { |
|
38 switch (GST_MESSAGE_TYPE (msg)) { |
|
39 case GST_MESSAGE_EOS: |
|
40 gst_element_set_state (pipeline, GST_STATE_NULL); |
|
41 g_main_loop_quit(loop); |
|
42 gst_object_unref (GST_OBJECT (pipeline)); |
|
43 //std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
44 create_xml(0); |
|
45 break; |
|
46 case GST_MESSAGE_ERROR: { |
|
47 gchar *debug; |
|
48 GError *err; |
|
49 gst_message_parse_error (msg, &err, &debug); |
|
50 g_free (debug); |
|
51 g_print ("Error: %s\n", err->message); |
|
52 g_error_free (err); |
|
53 //std_log(LOG_FILENAME_LINE, "Test Failed"); |
|
54 create_xml(1); |
|
55 break; |
|
56 } |
|
57 default: |
|
58 break; |
|
59 } |
|
60 |
|
61 return TRUE; |
|
62 } |
|
63 |
|
64 static gboolean |
|
65 quit_loop (gpointer data) |
|
66 { |
|
67 gst_element_send_event (pipeline, gst_event_new_eos ()); |
|
68 |
|
69 } |
|
70 |
|
71 |
|
72 /// exe name record_duration sampling_rate chans width |
|
73 int main (int argc, char *argv[]) |
|
74 { |
|
75 char filename[1024]; |
|
76 GstCaps* caps; |
|
77 int sampling_rate = 8000; |
|
78 int chans = 1; |
|
79 int width = 16; |
|
80 guint record_duration = 10000; |
|
81 |
|
82 if (argc > 1) { |
|
83 record_duration = (guint) atoi( argv[1] ) * 1000; |
|
84 } |
|
85 |
|
86 if (argc > 2) { |
|
87 sampling_rate = (int) atoi( argv[2] ); |
|
88 } |
|
89 |
|
90 if (argc > 3) { |
|
91 chans = (int) atoi( argv[3] ); |
|
92 } |
|
93 |
|
94 if (argc > 4) { |
|
95 width = (int) atoi( argv[4] ); |
|
96 } |
|
97 |
|
98 |
|
99 gst_init (&argc, &argv); |
|
100 loop = g_main_loop_new (NULL, FALSE); |
|
101 |
|
102 /* create elements */ |
|
103 pipeline = gst_pipeline_new ("audio-player"); |
|
104 source = gst_element_factory_make ("devsoundsrc", "audio-source"); |
|
105 wavenc = gst_element_factory_make ("wavenc", "mp3parse"); |
|
106 sink = gst_element_factory_make ("filesink", "sink"); |
|
107 |
|
108 if (!pipeline || !source || !wavenc || !sink) { |
|
109 g_print ("One element could not be created\n"); |
|
110 return -1; |
|
111 } |
|
112 snprintf(filename, 1024, "C:\\data\\wav_record_samp-%d-chans-%d-duration-%dsec.wav", |
|
113 sampling_rate, chans,record_duration/1000 ); |
|
114 |
|
115 /* set filename property on the file source. Also add a message handler. */ |
|
116 g_object_set (G_OBJECT (sink), "location", filename, NULL); |
|
117 /* put all elements in a bin */ |
|
118 gst_bin_add_many (GST_BIN (pipeline),source, wavenc,sink, NULL); |
|
119 |
|
120 caps = gst_caps_new_simple ("audio/x-raw-int", |
|
121 "width", G_TYPE_INT, width, |
|
122 "depth", G_TYPE_INT, width, |
|
123 "signed",G_TYPE_BOOLEAN, TRUE, |
|
124 "endianness",G_TYPE_INT, G_BYTE_ORDER, |
|
125 "rate", G_TYPE_INT, sampling_rate, |
|
126 "channels", G_TYPE_INT, chans, NULL); |
|
127 |
|
128 gst_element_link_filtered (source, wavenc, caps); |
|
129 gst_element_link (wavenc, sink); |
|
130 |
|
131 gst_bus_add_watch (gst_pipeline_get_bus (GST_PIPELINE (pipeline)), bus_call, loop); |
|
132 //g_signal_connect (decoder, "pad-added", G_CALLBACK (new_pad_cb),pipeline); |
|
133 /* Now set to playing and iterate. */ |
|
134 g_print ("Setting to PLAYING\n"); |
|
135 gst_element_set_state (pipeline, GST_STATE_PLAYING); |
|
136 g_timeout_add (record_duration, quit_loop, loop); |
|
137 g_print ("Running\n"); |
|
138 g_main_loop_run (loop); |
|
139 /* clean up nicely */ |
|
140 g_print ("Returned, stopping playback\n"); |
|
141 gst_element_set_state (pipeline, GST_STATE_NULL); |
|
142 g_print ("Deleting pipeline\n"); |
|
143 gst_object_unref (GST_OBJECT (pipeline)); |
|
144 |
|
145 g_print ("completed palying audio\n"); |
|
146 return 0; |
|
147 } |
|
148 |