4 #include "testrtpool.h"
6 static GstTaskPool *pool;
9 event_loop (GstBus * bus, GstElement * pipe)
11 GstMessage *message = NULL;
14 message = gst_bus_poll (bus, GST_MESSAGE_ANY, -1);
16 g_assert (message != NULL);
18 switch (message->type) {
20 g_message ("received EOS");
21 gst_message_unref (message);
23 case GST_MESSAGE_WARNING:
28 gst_message_parse_warning (message, &gerror, &debug);
29 gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
30 gst_message_unref (message);
31 g_error_free (gerror);
35 case GST_MESSAGE_ERROR:{
39 gst_message_parse_error (message, &gerror, &debug);
40 gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
41 gst_message_unref (message);
42 g_error_free (gerror);
47 gst_message_unref (message);
53 static GstBusSyncReply
54 sync_bus_handler (GstBus * bus, GstMessage * message, GstElement * bin)
56 switch (GST_MESSAGE_TYPE (message)) {
57 case GST_MESSAGE_STREAM_STATUS:
59 GstStreamStatusType type;
65 g_message ("received STREAM_STATUS");
66 gst_message_parse_stream_status (message, &type, &owner);
68 val = gst_message_get_stream_status_object (message);
70 g_message ("type: %d", type);
71 path = gst_object_get_path_string (GST_MESSAGE_SRC (message));
72 g_message ("source: %s", path);
74 path = gst_object_get_path_string (GST_OBJECT (owner));
75 g_message ("owner: %s", path);
78 if (G_VALUE_HOLDS_OBJECT (val)) {
79 g_message ("object: type %s, value %p", G_VALUE_TYPE_NAME (val),
80 g_value_get_object (val));
81 } else if (G_VALUE_HOLDS_POINTER (val)) {
82 g_message ("object: type %s, value %p", G_VALUE_TYPE_NAME (val),
83 g_value_get_pointer (val));
84 } else if (G_IS_VALUE (val)) {
85 g_message ("object: type %s", G_VALUE_TYPE_NAME (val));
87 g_message ("object: (null)");
91 /* see if we know how to deal with this object */
92 if (G_VALUE_TYPE (val) == GST_TYPE_TASK) {
93 task = g_value_get_object (val);
97 case GST_STREAM_STATUS_TYPE_CREATE:
99 g_message ("created task %p, setting pool", task);
100 gst_task_set_pool (task, pool);
103 case GST_STREAM_STATUS_TYPE_ENTER:
105 case GST_STREAM_STATUS_TYPE_LEAVE:
115 /* pass all messages on the async queue */
120 main (int argc, char *argv[])
122 GstElement *bin, *alsasrc, *alsasink;
124 GstStateChangeReturn ret;
126 gst_init (&argc, &argv);
128 /* create a custom thread pool */
129 pool = test_rt_pool_new ();
131 /* create a new bin to hold the elements */
132 bin = gst_pipeline_new ("pipeline");
135 /* create a source */
136 alsasrc = gst_element_factory_make ("alsasrc", "alsasrc");
138 g_object_set (alsasrc, "device", "hw:0", NULL);
139 g_object_set (alsasrc, "latency-time", (gint64) 2000, NULL);
140 g_object_set (alsasrc, "slave-method", 2, NULL);
143 alsasink = gst_element_factory_make ("alsasink", "alsasink");
145 g_object_set (alsasink, "device", "hw:0", NULL);
146 g_object_set (alsasink, "latency-time", (gint64) 2000, NULL);
147 g_object_set (alsasink, "buffer-time", (gint64) 10000, NULL);
149 /* add objects to the main pipeline */
150 gst_bin_add_many (GST_BIN (bin), alsasrc, alsasink, NULL);
152 /* link the elements */
153 gst_element_link (alsasrc, alsasink);
155 /* get the bus, we need to install a sync handler */
156 bus = gst_pipeline_get_bus (GST_PIPELINE (bin));
157 gst_bus_set_sync_handler (bus, (GstBusSyncHandler) sync_bus_handler, bin);
160 ret = gst_element_set_state (bin, GST_STATE_PLAYING);
161 if (ret == GST_STATE_CHANGE_FAILURE)
164 /* Run event loop listening for bus messages until EOS or ERROR */
165 event_loop (bus, bin);
168 gst_element_set_state (bin, GST_STATE_NULL);
169 gst_object_unref (bus);