1 | #include <gst/gst.h> |
---|
2 | |
---|
3 | #define ITERS 100 |
---|
4 | #include <stdlib.h> |
---|
5 | |
---|
6 | static GstElement * |
---|
7 | create_bin (void) |
---|
8 | { |
---|
9 | GstElement *bin; |
---|
10 | GstElement *element; |
---|
11 | |
---|
12 | bin = gst_bin_new ("testbin"); |
---|
13 | g_assert (GST_IS_BIN (bin)); |
---|
14 | element = gst_element_factory_make ("fakesrc", NULL); |
---|
15 | g_assert (GST_IS_ELEMENT (element)); |
---|
16 | gst_element_set_name (element, "test1"); |
---|
17 | gst_bin_add (GST_BIN (bin), element); |
---|
18 | element = gst_element_factory_make ("fakesrc", NULL); |
---|
19 | g_assert (GST_IS_ELEMENT (element)); |
---|
20 | gst_element_set_name (element, "test2"); |
---|
21 | gst_bin_add (GST_BIN (bin), element); |
---|
22 | |
---|
23 | return bin; |
---|
24 | } |
---|
25 | |
---|
26 | static GstElement * |
---|
27 | create_bin_ghostpads (void) |
---|
28 | { |
---|
29 | GstElement *bin; |
---|
30 | GstElement *element1, *element2; |
---|
31 | |
---|
32 | bin = gst_bin_new ("testbin"); |
---|
33 | element1 = gst_element_factory_make ("identity", NULL); |
---|
34 | gst_bin_add (GST_BIN (bin), element1); |
---|
35 | element2 = gst_element_factory_make ("fakesink", NULL); |
---|
36 | gst_bin_add (GST_BIN (bin), element2); |
---|
37 | gst_element_link_pads (element1, "src", element2, "sink"); |
---|
38 | gst_element_add_ghost_pad (bin, gst_element_get_pad (element1, "sink"), |
---|
39 | "ghost_sink"); |
---|
40 | |
---|
41 | return bin; |
---|
42 | } |
---|
43 | |
---|
44 | static void |
---|
45 | add_remove_test1 (void) |
---|
46 | { |
---|
47 | GstElement *bin; |
---|
48 | GstElement *element; |
---|
49 | |
---|
50 | bin = gst_bin_new ("testbin"); |
---|
51 | element = gst_element_factory_make ("fakesrc", NULL); |
---|
52 | gst_element_set_name (element, "test1"); |
---|
53 | g_assert (GST_OBJECT_FLOATING (element)); |
---|
54 | gst_bin_add (GST_BIN (bin), element); |
---|
55 | g_assert (!GST_OBJECT_FLOATING (element)); |
---|
56 | gst_bin_remove (GST_BIN (bin), element); |
---|
57 | |
---|
58 | gst_object_unref (GST_OBJECT (bin)); |
---|
59 | } |
---|
60 | |
---|
61 | static void |
---|
62 | add_remove_test2 (void) |
---|
63 | { |
---|
64 | GstElement *bin; |
---|
65 | GstElement *element; |
---|
66 | |
---|
67 | bin = gst_bin_new ("testbin"); |
---|
68 | element = gst_element_factory_make ("fakesrc", NULL); |
---|
69 | gst_element_set_name (element, "test1"); |
---|
70 | gst_object_ref (GST_OBJECT (element)); |
---|
71 | g_assert (GST_OBJECT_FLOATING (element)); |
---|
72 | gst_bin_add (GST_BIN (bin), element); |
---|
73 | g_assert (!GST_OBJECT_FLOATING (element)); |
---|
74 | gst_bin_remove (GST_BIN (bin), element); |
---|
75 | g_assert (!GST_OBJECT_FLOATING (element)); |
---|
76 | g_assert (!GST_OBJECT_DESTROYED (element)); |
---|
77 | |
---|
78 | gst_object_unref (GST_OBJECT (element)); |
---|
79 | #if 0 |
---|
80 | g_assert (GST_OBJECT_DESTROYED (element)); |
---|
81 | gst_object_unref (GST_OBJECT (element)); |
---|
82 | #endif |
---|
83 | |
---|
84 | gst_object_unref (GST_OBJECT (bin)); |
---|
85 | } |
---|
86 | |
---|
87 | #if 0 |
---|
88 | /* This code is bogus */ |
---|
89 | static void |
---|
90 | add_remove_test3 (void) |
---|
91 | { |
---|
92 | GstElement *bin; |
---|
93 | GstElement *element; |
---|
94 | |
---|
95 | bin = gst_bin_new ("testbin"); |
---|
96 | element = gst_element_factory_make ("fakesrc", NULL); |
---|
97 | gst_element_set_name (element, "test1"); |
---|
98 | g_assert (GST_OBJECT_FLOATING (element)); |
---|
99 | gst_bin_add (GST_BIN (bin), element); |
---|
100 | g_assert (!GST_OBJECT_FLOATING (element)); |
---|
101 | |
---|
102 | gst_object_unref (GST_OBJECT (element)); |
---|
103 | g_assert (gst_bin_get_by_name (GST_BIN (bin), "test1") == NULL); |
---|
104 | |
---|
105 | gst_object_unref (GST_OBJECT (bin)); |
---|
106 | } |
---|
107 | #endif |
---|
108 | |
---|
109 | #if 0 |
---|
110 | /* This code is bogus */ |
---|
111 | static void |
---|
112 | add_remove_test4 (void) |
---|
113 | { |
---|
114 | GstElement *bin, *bin2; |
---|
115 | GstElement *element; |
---|
116 | |
---|
117 | bin = gst_bin_new ("testbin"); |
---|
118 | element = gst_element_factory_make ("fakesrc", NULL); |
---|
119 | gst_element_set_name (element, "test1"); |
---|
120 | g_assert (GST_OBJECT_FLOATING (element)); |
---|
121 | gst_bin_add (GST_BIN (bin), element); |
---|
122 | g_assert (!GST_OBJECT_FLOATING (element)); |
---|
123 | |
---|
124 | bin2 = create_bin (); |
---|
125 | g_assert (GST_OBJECT_FLOATING (bin2)); |
---|
126 | gst_bin_add (GST_BIN (bin), bin2); |
---|
127 | g_assert (!GST_OBJECT_FLOATING (bin2)); |
---|
128 | |
---|
129 | gst_object_unref (GST_OBJECT (bin2)); |
---|
130 | g_assert (gst_bin_get_by_name (GST_BIN (bin), "testbin") == NULL); |
---|
131 | gst_object_unref (GST_OBJECT (element)); |
---|
132 | g_assert (gst_bin_get_by_name (GST_BIN (bin), "test1") == NULL); |
---|
133 | |
---|
134 | gst_object_unref (GST_OBJECT (bin)); |
---|
135 | } |
---|
136 | #endif |
---|
137 | |
---|
138 | int |
---|
139 | main (int argc, gchar * argv[]) |
---|
140 | { |
---|
141 | GstElement *bin; |
---|
142 | int usage1; |
---|
143 | gint i, iters; |
---|
144 | |
---|
145 | gst_alloc_trace_set_flags_all (GST_ALLOC_TRACE_LIVE); |
---|
146 | |
---|
147 | gst_init (&argc, &argv); |
---|
148 | |
---|
149 | if (argc == 2) |
---|
150 | iters = atoi (argv[1]); |
---|
151 | else |
---|
152 | iters = ITERS; |
---|
153 | |
---|
154 | |
---|
155 | g_print ("starting test\n"); |
---|
156 | |
---|
157 | usage1 = gst_alloc_trace_live_all (); |
---|
158 | //gst_alloc_trace_print_all (); |
---|
159 | |
---|
160 | bin = gst_bin_new ("somebin"); |
---|
161 | gst_object_unref (GST_OBJECT (bin)); |
---|
162 | g_print ("create/unref new bin %d\n", gst_alloc_trace_live_all () - usage1); |
---|
163 | |
---|
164 | for (i = 0; i < iters; i++) { |
---|
165 | bin = gst_bin_new ("somebin"); |
---|
166 | gst_object_unref (GST_OBJECT (bin)); |
---|
167 | } |
---|
168 | g_print ("create/unref %d bins %d\n", iters, |
---|
169 | gst_alloc_trace_live_all () - usage1); |
---|
170 | |
---|
171 | bin = gst_bin_new ("somebin"); |
---|
172 | g_assert (GST_OBJECT_FLOATING (bin)); |
---|
173 | gst_object_ref (GST_OBJECT (bin)); |
---|
174 | gst_object_sink (GST_OBJECT (bin)); |
---|
175 | g_assert (!GST_OBJECT_FLOATING (bin)); |
---|
176 | gst_object_unref (GST_OBJECT (bin)); |
---|
177 | g_print ("create/ref/sink/unref new bin %d\n", |
---|
178 | gst_alloc_trace_live_all () - usage1); |
---|
179 | |
---|
180 | |
---|
181 | for (i = 0; i < iters; i++) { |
---|
182 | bin = gst_bin_new ("somebin"); |
---|
183 | gst_object_ref (GST_OBJECT (bin)); |
---|
184 | gst_object_sink (GST_OBJECT (bin)); |
---|
185 | gst_object_unref (GST_OBJECT (bin)); |
---|
186 | } |
---|
187 | g_print ("create/ref/sink/unref %d bins %d\n", iters, |
---|
188 | gst_alloc_trace_live_all () - usage1); |
---|
189 | |
---|
190 | bin = gst_bin_new ("somebin"); |
---|
191 | g_assert (!GST_OBJECT_DESTROYED (bin)); |
---|
192 | gst_object_unref (GST_OBJECT (bin)); |
---|
193 | #if 0 |
---|
194 | g_assert (GST_OBJECT_DESTROYED (bin)); |
---|
195 | gst_object_unref (GST_OBJECT (bin)); |
---|
196 | #endif |
---|
197 | g_print ("create/destroy/unref new bin %d\n", |
---|
198 | gst_alloc_trace_live_all () - usage1); |
---|
199 | |
---|
200 | for (i = 0; i < iters; i++) { |
---|
201 | bin = gst_bin_new ("somebin"); |
---|
202 | gst_object_unref (GST_OBJECT (bin)); |
---|
203 | #if 0 |
---|
204 | gst_object_unref (GST_OBJECT (bin)); |
---|
205 | #endif |
---|
206 | } |
---|
207 | g_print ("create/destroy/unref %d bin %d\n", iters, |
---|
208 | gst_alloc_trace_live_all () - usage1); |
---|
209 | |
---|
210 | bin = gst_bin_new ("somebin"); |
---|
211 | gst_object_ref (GST_OBJECT (bin)); |
---|
212 | gst_object_unref (GST_OBJECT (bin)); |
---|
213 | gst_object_unref (GST_OBJECT (bin)); |
---|
214 | g_print ("create/ref/unref/unref new bin %d\n", |
---|
215 | gst_alloc_trace_live_all () - usage1); |
---|
216 | |
---|
217 | for (i = 0; i < iters; i++) { |
---|
218 | bin = gst_bin_new ("somebin"); |
---|
219 | gst_object_ref (GST_OBJECT (bin)); |
---|
220 | gst_object_unref (GST_OBJECT (bin)); |
---|
221 | gst_object_unref (GST_OBJECT (bin)); |
---|
222 | } |
---|
223 | g_print ("create/ref/unref/unref %d bin %d\n", iters, |
---|
224 | gst_alloc_trace_live_all () - usage1); |
---|
225 | |
---|
226 | bin = gst_bin_new ("somebin"); |
---|
227 | gst_object_ref (GST_OBJECT (bin)); |
---|
228 | gst_object_unref (GST_OBJECT (bin)); |
---|
229 | gst_object_unref (GST_OBJECT (bin)); |
---|
230 | #if 0 |
---|
231 | gst_object_unref (GST_OBJECT (bin)); |
---|
232 | #endif |
---|
233 | g_print ("craete/ref/destroy/unref/unref new bin %d\n", |
---|
234 | gst_alloc_trace_live_all () - usage1); |
---|
235 | |
---|
236 | for (i = 0; i < iters; i++) { |
---|
237 | bin = gst_bin_new ("somebin"); |
---|
238 | gst_object_ref (GST_OBJECT (bin)); |
---|
239 | gst_object_unref (GST_OBJECT (bin)); |
---|
240 | gst_object_unref (GST_OBJECT (bin)); |
---|
241 | #if 0 |
---|
242 | gst_object_unref (GST_OBJECT (bin)); |
---|
243 | #endif |
---|
244 | } |
---|
245 | g_print ("craete/ref/destroy/unref/unref %d bins %d\n", iters, |
---|
246 | gst_alloc_trace_live_all () - usage1); |
---|
247 | |
---|
248 | for (i = 0; i < iters; i++) { |
---|
249 | bin = gst_bin_new ("somebin"); |
---|
250 | gst_object_ref (GST_OBJECT (bin)); |
---|
251 | gst_element_set_name (bin, "testing123"); |
---|
252 | gst_object_unref (GST_OBJECT (bin)); |
---|
253 | gst_element_set_name (bin, "testing123"); |
---|
254 | gst_object_unref (GST_OBJECT (bin)); |
---|
255 | #if 0 |
---|
256 | gst_object_unref (GST_OBJECT (bin)); |
---|
257 | #endif |
---|
258 | } |
---|
259 | g_print ("craete/ref/destroy/unref/unref %d bins with name %d\n", iters, |
---|
260 | gst_alloc_trace_live_all () - usage1); |
---|
261 | |
---|
262 | bin = gst_bin_new ("somebin"); |
---|
263 | for (i = 0; i < iters; i++) { |
---|
264 | gst_element_set_name (bin, "testing"); |
---|
265 | } |
---|
266 | gst_object_unref (GST_OBJECT (bin)); |
---|
267 | g_print ("set name %d times %d\n", iters, |
---|
268 | gst_alloc_trace_live_all () - usage1); |
---|
269 | |
---|
270 | for (i = 0; i < iters; i++) { |
---|
271 | bin = create_bin (); |
---|
272 | gst_object_unref (GST_OBJECT (bin)); |
---|
273 | } |
---|
274 | g_print ("create/unref %d bin with children %d\n", iters, |
---|
275 | gst_alloc_trace_live_all () - usage1); |
---|
276 | |
---|
277 | for (i = 0; i < iters / 2; i++) { |
---|
278 | bin = create_bin_ghostpads (); |
---|
279 | gst_object_unref (GST_OBJECT (bin)); |
---|
280 | } |
---|
281 | g_print ("create/unref %d bin with children and ghostpads %d\n", iters / 2, |
---|
282 | gst_alloc_trace_live_all () - usage1); |
---|
283 | |
---|
284 | for (i = 0; i < iters; i++) { |
---|
285 | add_remove_test1 (); |
---|
286 | } |
---|
287 | g_print ("add/remove test1 %d in bin %d\n", iters, |
---|
288 | gst_alloc_trace_live_all () - usage1); |
---|
289 | |
---|
290 | for (i = 0; i < iters; i++) { |
---|
291 | add_remove_test2 (); |
---|
292 | } |
---|
293 | g_print ("add/remove test2 %d in bin %d\n", iters, |
---|
294 | gst_alloc_trace_live_all () - usage1); |
---|
295 | |
---|
296 | #if 0 |
---|
297 | for (i = 0; i < iters; i++) { |
---|
298 | add_remove_test3 (); |
---|
299 | } |
---|
300 | g_print ("add/destroy/remove test3 %d in bin %d\n", iters, |
---|
301 | gst_alloc_trace_live_all () - usage1); |
---|
302 | #endif |
---|
303 | |
---|
304 | #if 0 |
---|
305 | for (i = 0; i < iters; i++) { |
---|
306 | add_remove_test4 (); |
---|
307 | } |
---|
308 | g_print ("add/destroy/remove test4 %d in bin %d\n", iters, |
---|
309 | gst_alloc_trace_live_all () - usage1); |
---|
310 | #endif |
---|
311 | |
---|
312 | g_print ("leaked: %d\n", gst_alloc_trace_live_all () - usage1); |
---|
313 | |
---|
314 | //gst_alloc_trace_print_all (); |
---|
315 | |
---|
316 | //return (gst_alloc_trace_live_all () - usage1 ? -1 : 0); |
---|
317 | return 0; |
---|
318 | } |
---|