1 | /* |
---|
2 | * test for fakesrc and fakesink element |
---|
3 | * thomas@apestaart.org |
---|
4 | * originally written for 0.3.2 |
---|
5 | */ |
---|
6 | |
---|
7 | #include <gst/gst.h> |
---|
8 | #include "property.h" |
---|
9 | |
---|
10 | GstElement * |
---|
11 | element_create (char *name, char *element) |
---|
12 | /* |
---|
13 | * create the element |
---|
14 | * print an error if it can't be created |
---|
15 | * return NULL if it couldn't be created |
---|
16 | * return element if it did work |
---|
17 | */ |
---|
18 | { |
---|
19 | GstElement *el = NULL; |
---|
20 | |
---|
21 | el = (GstElement *) gst_element_factory_make (element, name); |
---|
22 | if (el == NULL) { |
---|
23 | fprintf (stderr, "Could not create element %s (%s) !\n", name, element); |
---|
24 | return NULL; |
---|
25 | } else |
---|
26 | return el; |
---|
27 | } |
---|
28 | |
---|
29 | int |
---|
30 | main (int argc, char *argv[]) |
---|
31 | { |
---|
32 | GstElement *pipeline = NULL; |
---|
33 | GstElement *src, *sink; |
---|
34 | gint retval = 0; |
---|
35 | |
---|
36 | /* init */ |
---|
37 | gst_init (&argc, &argv); |
---|
38 | |
---|
39 | /* create */ |
---|
40 | g_print ("Creating pipeline\n"); |
---|
41 | pipeline = gst_pipeline_new ("pipeline"); |
---|
42 | |
---|
43 | g_print ("Connecting signals to pipeline\n"); |
---|
44 | g_signal_connect (pipeline, "deep_notify", |
---|
45 | G_CALLBACK (property_change_callback), NULL); |
---|
46 | g_print ("Creating elements\n"); |
---|
47 | if (!(src = element_create ("src", "fakesrc"))) |
---|
48 | return 1; |
---|
49 | g_object_set (G_OBJECT (src), "sizetype", 2, NULL); |
---|
50 | if (!(sink = element_create ("sink", "fakesink"))) |
---|
51 | return 1; |
---|
52 | |
---|
53 | /* add */ |
---|
54 | g_print ("Adding elements to bin\n"); |
---|
55 | gst_bin_add (GST_BIN (pipeline), src); |
---|
56 | gst_bin_add (GST_BIN (pipeline), sink); |
---|
57 | |
---|
58 | /* link */ |
---|
59 | g_print ("Linking elements\n"); |
---|
60 | gst_element_set_state (pipeline, GST_STATE_PLAYING); |
---|
61 | |
---|
62 | /* we expect this to give an error */ |
---|
63 | if (gst_bin_iterate (GST_BIN (pipeline)) != FALSE) { |
---|
64 | g_warning |
---|
65 | ("Iterating a bin with unlinked elements should return FALSE !\n"); |
---|
66 | retval = 1; |
---|
67 | } |
---|
68 | |
---|
69 | gst_pad_link (gst_element_get_pad (src, "src"), |
---|
70 | gst_element_get_pad (sink, "sink")); |
---|
71 | |
---|
72 | /* set to play */ |
---|
73 | g_print ("Doing 1 iteration\n"); |
---|
74 | gst_element_set_state (pipeline, GST_STATE_PLAYING); |
---|
75 | |
---|
76 | /* we expect this to work */ |
---|
77 | if (gst_bin_iterate (GST_BIN (pipeline)) != TRUE) { |
---|
78 | g_error ("Iterating a bin with linked elements should return TRUE !\n"); |
---|
79 | retval = 1; |
---|
80 | } |
---|
81 | |
---|
82 | g_print ("Done !\n"); |
---|
83 | return retval; |
---|
84 | } |
---|