|
1 |
|
2 /*** block a from ../../../docs/manual/basics-pads.xml ***/ |
|
3 |
|
4 #define LOG_FILE "c:\\logs\\pad_logs.txt" |
|
5 |
|
6 #include <gst/gst_global.h> |
|
7 #include "std_log_result.h" |
|
8 #define LOG_FILENAME_LINE __FILE__, __LINE__ |
|
9 |
|
10 void create_xml(int result) |
|
11 { |
|
12 if(result) |
|
13 assert_failed = 1; |
|
14 |
|
15 testResultXml(xmlfile); |
|
16 close_log_file(); |
|
17 } |
|
18 |
|
19 |
|
20 #include <gst/gst.h> |
|
21 GstElement* pipeline; |
|
22 GMainLoop *loop; |
|
23 |
|
24 static gboolean |
|
25 bus_call (GstBus *bus, |
|
26 GstMessage *msg, |
|
27 gpointer data) |
|
28 { |
|
29 switch (GST_MESSAGE_TYPE (msg)) { |
|
30 case GST_MESSAGE_EOS: |
|
31 gst_element_set_state (pipeline, GST_STATE_NULL); |
|
32 gst_object_unref (GST_OBJECT (pipeline)); |
|
33 g_main_loop_quit(loop); |
|
34 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
35 create_xml(0); |
|
36 break; |
|
37 case GST_MESSAGE_ERROR: { |
|
38 gchar *debug; |
|
39 GError *err; |
|
40 gst_message_parse_error (msg, &err, &debug); |
|
41 g_free (debug); |
|
42 g_print ("Error: %s\n", err->message); |
|
43 g_error_free (err); |
|
44 std_log(LOG_FILENAME_LINE, "Test Failed"); |
|
45 create_xml(1); |
|
46 break; |
|
47 } |
|
48 default: |
|
49 break; |
|
50 } |
|
51 |
|
52 return TRUE; |
|
53 } |
|
54 |
|
55 static void |
|
56 cb_new_pad (GstElement *element, |
|
57 GstPad *pad, |
|
58 gpointer data) |
|
59 { |
|
60 gchar *name; |
|
61 GstElement* sink; |
|
62 //name = gst_pad_get_name (pad); |
|
63 gst_element_set_state (pipeline, GST_STATE_PAUSED); |
|
64 sink = gst_element_factory_make ("devsoundsink", "sink"); |
|
65 gst_bin_add_many (GST_BIN (pipeline),sink, NULL); |
|
66 gst_element_link(element,sink); |
|
67 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); |
|
68 /* here, you would setup a new pad link for the newly created pad */ |
|
69 |
|
70 /*** block b from ../../../docs/manual/basics-pads.xml ***/ |
|
71 } |
|
72 |
|
73 int |
|
74 main (int argc, |
|
75 char *argv[]) |
|
76 { |
|
77 GstElement *source, *demux, *parser; |
|
78 |
|
79 xmlfile = "pad"; |
|
80 std_log(LOG_FILENAME_LINE, "Test Started pad"); |
|
81 |
|
82 /* init */ |
|
83 gst_init (&argc, &argv); |
|
84 |
|
85 if (argc != 2) { |
|
86 g_print ("usage: %s <filename>\n", argv[0]); |
|
87 std_log(LOG_FILENAME_LINE, "Test Failed wave file as an argument need to be passed"); |
|
88 create_xml(1); |
|
89 exit (-1); |
|
90 } |
|
91 |
|
92 loop = g_main_loop_new (NULL, FALSE); |
|
93 /* create elements */ |
|
94 pipeline = gst_pipeline_new ("my_pipeline"); |
|
95 source = gst_element_factory_make ("filesrc", "source"); |
|
96 g_object_set (source, "location", argv[1], NULL); |
|
97 //demux = gst_element_factory_make ("oggdemux", "demuxer"); |
|
98 |
|
99 parser = gst_element_factory_make ("wavparse", "waveparser"); |
|
100 /* you would normally check that the elements were created properly */ |
|
101 |
|
102 /* put together a pipeline */ |
|
103 //gst_bin_add_many (GST_BIN (pipeline), source, demux, NULL); |
|
104 gst_bin_add_many (GST_BIN (pipeline), source, parser, NULL); |
|
105 //gst_element_link_pads (source, "src", demux, "sink"); |
|
106 |
|
107 gst_element_link_many (source,parser,NULL); |
|
108 |
|
109 /* listen for newly created pads */ |
|
110 //g_signal_connect (demux, "pad-added", G_CALLBACK (cb_new_pad), NULL); |
|
111 gst_bus_add_watch (gst_pipeline_get_bus (GST_PIPELINE (pipeline)), bus_call, loop); |
|
112 g_signal_connect (parser, "pad-added", G_CALLBACK (cb_new_pad), NULL); |
|
113 /* start the pipeline */ |
|
114 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); |
|
115 |
|
116 g_main_loop_run (loop); |
|
117 |
|
118 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
119 create_xml(0); |
|
120 return 0; |
|
121 |
|
122 /*** block d from ../../../docs/manual/basics-pads.xml ***/ |
|
123 } |