1 <chapter id="cha-queues">
4 A <classname>GstQueue</classname> is a filter element.
5 Queues can be used to link two elements in such way that the data can
9 A buffer that is sinked to a Queue will not automatically be pushed to the
10 next linked element but will be buffered. It will be pushed to the next
11 element as soon as a gst_pad_pull () is called on the queue's source pad.
14 Queues are mostly used in conjunction with a <classname>GstThread</classname> to
15 provide an external link for the thread elements. You could have one
16 thread feeding buffers into a <classname>GstQueue</classname> and another
17 thread repeadedly calling gst_pad_pull () on the queue to feed its
22 Below is a figure of a two-threaded decoder. We have one thread (the main execution
23 thread) reading the data from a file, and another thread decoding the data.
25 <figure float="1" id="sec-queues-img">
26 <title>a two-threaded decoder with a queue</title>
29 <imagedata fileref="images/queue.&magic;" format="&MAGIC;" />
35 The standard <application>GStreamer</application> queue implementation has some
36 properties that can be changed using the g_objet_set () method. To set the
37 maximum number of buffers that can be queued to 30, do:
40 g_object_set (G_OBJECT (queue), "max_level", 30, NULL);
44 The following MP3 player shows you how to create the above pipeline
45 using a thread and a queue.
49 /* example-begin queue.c */
50 #include <stdlib.h>
51 #include <gst/gst.h>
55 /* eos will be called when the src element has an end of stream */
57 eos (GstElement *element, gpointer data)
59 g_print ("have eos, quitting\n");
65 main (int argc, char *argv[])
67 GstElement *filesrc, *audiosink, *queue, *decode;
71 gst_init (&argc,&argv);
74 g_print ("usage: %s <mp3 filename>\n", argv[0]);
78 /* create a new thread to hold the elements */
79 thread = gst_thread_new ("thread");
80 g_assert (thread != NULL);
82 /* create a new bin to hold the elements */
83 bin = gst_bin_new ("bin");
84 g_assert (bin != NULL);
86 /* create a disk reader */
87 filesrc = gst_element_factory_make ("filesrc", "disk_source");
88 g_assert (filesrc != NULL);
89 g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
90 g_signal_connect (G_OBJECT (filesrc), "eos",
91 G_CALLBACK (eos), thread);
93 queue = gst_element_factory_make ("queue", "queue");
94 g_assert (queue != NULL);
96 /* and an audio sink */
97 audiosink = gst_element_factory_make ("osssink", "play_audio");
98 g_assert (audiosink != NULL);
100 decode = gst_element_factory_make ("mad", "decode");
102 /* add objects to the main bin */
103 gst_bin_add_many (GST_BIN (thread), decode, audiosink, NULL);
105 gst_bin_add_many (GST_BIN (bin), filesrc, queue, thread, NULL);
108 gst_element_link (filesrc, queue);
109 gst_element_link_many (queue, decode, audiosink, NULL);
112 gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING);
117 gst_bin_iterate (GST_BIN (bin));
120 gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
124 /* example-end queue.c */