|
1 /* GStreamer typefind element example |
|
2 * Copyright (C) <2005> Stefan Kost |
|
3 * Copyright (C) <2006> Tim-Philipp Müller |
|
4 * |
|
5 * This library is free software; you can redistribute it and/or |
|
6 * modify it under the terms of the GNU Library General Public |
|
7 * License as published by the Free Software Foundation; either |
|
8 * version 2 of the License, or (at your option) any later version. |
|
9 * |
|
10 * This library is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 * Library General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU Library General Public |
|
16 * License along with this library; if not, write to the |
|
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
18 * Boston, MA 02111-1307, USA. |
|
19 */ |
|
20 |
|
21 |
|
22 #include <gst/gst_global.h> |
|
23 #include <gst/gst.h> |
|
24 |
|
25 #define LOG_FILE "c:\\logs\\typefind_logs.txt" |
|
26 #include "std_log_result.h" |
|
27 #define LOG_FILENAME_LINE __FILE__, __LINE__ |
|
28 |
|
29 |
|
30 void create_xml(int result) |
|
31 { |
|
32 if(result) |
|
33 assert_failed = 1; |
|
34 |
|
35 testResultXml(xmlfile); |
|
36 close_log_file(); |
|
37 } |
|
38 static void |
|
39 type_found (GstElement * typefind, guint probability, const GstCaps * caps, |
|
40 gpointer user_data) |
|
41 { |
|
42 gchar *xml, *caps_str; |
|
43 |
|
44 caps_str = gst_caps_to_string (caps); |
|
45 xml = g_markup_printf_escaped ("<?xml version=\"1.0\"?>\n<Capabilities>\n" |
|
46 " <Caps1>%s</Caps1>\n</Capabilities>", caps_str); |
|
47 g_free (caps_str); |
|
48 |
|
49 g_print ("%s\n", xml); |
|
50 g_free (xml); |
|
51 } |
|
52 |
|
53 static void |
|
54 event_loop (GstElement * pipe) |
|
55 { |
|
56 GstBus *bus; |
|
57 GstMessage *message = NULL; |
|
58 |
|
59 bus = gst_element_get_bus (GST_ELEMENT (pipe)); |
|
60 |
|
61 while (TRUE) { |
|
62 message = gst_bus_poll (bus, GST_MESSAGE_ANY, -1); |
|
63 |
|
64 g_assert (message != NULL); |
|
65 |
|
66 switch (message->type) { |
|
67 case GST_MESSAGE_EOS: |
|
68 gst_message_unref (message); |
|
69 return; |
|
70 case GST_MESSAGE_WARNING: |
|
71 case GST_MESSAGE_ERROR:{ |
|
72 GError *gerror; |
|
73 gchar *debug; |
|
74 |
|
75 gst_message_parse_error (message, &gerror, &debug); |
|
76 gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug); |
|
77 gst_message_unref (message); |
|
78 g_error_free (gerror); |
|
79 g_free (debug); |
|
80 return; |
|
81 } |
|
82 default: |
|
83 gst_message_unref (message); |
|
84 break; |
|
85 } |
|
86 } |
|
87 } |
|
88 |
|
89 int |
|
90 main (int argc, char *argv[]) |
|
91 { |
|
92 GstElement *pipeline, *filesrc, *typefind, *sink; |
|
93 |
|
94 xmlfile = "typefind_logs"; |
|
95 std_log(LOG_FILENAME_LINE, "Test Started typefind_logs"); |
|
96 gst_init (&argc, &argv); |
|
97 |
|
98 if (argc != 2) { |
|
99 g_print ("usage: %s <filename>\n", argv[0]); |
|
100 exit (-1); |
|
101 } |
|
102 |
|
103 /* create a new pipeline to hold the elements */ |
|
104 pipeline = gst_pipeline_new ("pipeline"); |
|
105 g_assert (pipeline != NULL); |
|
106 |
|
107 /* create a file reader */ |
|
108 filesrc = gst_element_factory_make ("filesrc", "file_source"); |
|
109 g_assert (filesrc != NULL); |
|
110 g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL); |
|
111 |
|
112 typefind = gst_element_factory_make ("typefind", "typefind"); |
|
113 g_assert (typefind != NULL); |
|
114 |
|
115 sink = gst_element_factory_make ("fakesink", "sink"); |
|
116 g_assert (sink != NULL); |
|
117 |
|
118 /* add objects to the main pipeline */ |
|
119 gst_bin_add (GST_BIN (pipeline), filesrc); |
|
120 gst_bin_add (GST_BIN (pipeline), typefind); |
|
121 gst_bin_add (GST_BIN (pipeline), sink); |
|
122 |
|
123 g_signal_connect (G_OBJECT (typefind), "have-type", |
|
124 G_CALLBACK (type_found), NULL); |
|
125 |
|
126 gst_element_link_many (filesrc, typefind, sink, NULL); |
|
127 |
|
128 /* start playing */ |
|
129 gst_element_set_state (pipeline, GST_STATE_PLAYING); |
|
130 |
|
131 /* Run event loop listening for bus messages until EOS or ERROR */ |
|
132 event_loop (pipeline); |
|
133 |
|
134 /* stop the bin */ |
|
135 gst_element_set_state (pipeline, GST_STATE_NULL); |
|
136 gst_object_unref (pipeline); |
|
137 |
|
138 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
139 create_xml(0); |
|
140 exit (0); |
|
141 } |