1 A little explanation of the first autoplugger in GStreamer:
3 Autoplugging is implemented in the following places:
5 gstpipeline.c : construction of the pipeline
6 gstautoplug.c : selection of the elementfactories needed for autoplugging
11 before any autoplugging will take place, a new GstPipeline has to be created.
12 The autoplugger needs to have a src element and one or more sink elements. the
13 autoplugger will try to find the elements needed to connect the src element
18 gst_pipeline_add_src (GstPipeline *pipeline, GstElement *element);
20 a source element is added to the pipeline. only one src element can be added
25 gst_pipeline_add_sink (GstPipeline *pipeline, GstElement *element);
27 a sink element can be added to the pipeline.
32 when the pipeline has been set up as above, you will call
34 gst_pipeline_autoplug (GstPipeline *pipeline);
36 to start the autoplugger. this will be done in four phases
38 ex. we are going to autoplug an mpeg1 system stream.
40 2a) phase1: figure out the type (GstCaps) of the src element.
41 -------------------------------------------------------------
43 the gsttypefind element is connected to the "src" pad of the source
44 element. gst_bin_iterate is called in a loop until gsttypefind
45 signals "have_type". the gst_bin_iterate is stopped and the GstCaps
46 is retrieved from the gsttypefind element.
48 gsttypefind is disconnected from the src element and removed from the
51 the GstCaps of the source element is called src_caps later on.
53 ex. all typefind functions are tried and the one in mpeg1types will
57 "systemstream", GST_PROPS_BOOLEAN (TRUE),
58 "mpegversion", GST_PROPS_INT (1),
62 2b) phase2: create lists of factories.
63 ---------------------------------------
67 sinkpad = take the first sinkpad of the sink (HACK)
70 list[i] = gst_autoplug_caps (src_caps, sinkpad->caps);
75 gst_autoplug_caps will figure out (based on the padtemplates)
76 which elementfactories are needed to connect src_caps to sinkpad->caps
77 and will return them in a list.
79 ex. we have two sinks with following caps:
84 gst_autoplug_caps will figure out that for the first sink the following
87 mpeg1parse, mp1videoparse, mpeg_play
89 for the second sink the following is needed:
91 mpeg1parse, mp3parse, mpg123
93 We now have two lists of elementfactories.
95 2c) phase3: collect common elements from the lists.
96 ---------------------------------------------------
98 the rationale is that from the lists we have created in phase2, there
99 must be some element that is a splitter and that it has to come first (HACK)
100 We try to find that element by comparing the lists until an element differs.
102 we add the common elements to the bin and run gst_pipeline_pads_autoplug. this
103 function will loop over the pads of the previous element and the one we
104 just added, and tries to connect src to sink if possible.
106 If a connection between the two elements could not be made, a signal "new_pad"
107 is connected to the element so that pad connection can occur later on when
108 the pad is actually created.
110 ex. when we compare the two lists we see that we have common element: mpeg1parse.
112 we add this element to the bin and try to connect it to the previous element in
113 the bin, the disksrc.
115 we see that the src pad of the disksrc and the sinkpad of the mpeg1parse element
116 can be connected because they are compatible. We have a pipeline like:
119 disksrc ! ! mpeg1parse
124 2d) phase4: add remaining elements
125 ----------------------------------
127 now we loop over all the list and try to add the remaining elements
129 (HACK) we always use a new thread for the elements when there is a common
132 if a new thread is needed (either bacuase the previous element is a common
133 element or the object flag of the next element is set to GST_SUGGEST_THREAD)
134 we add a queue to the bin and we add a new thread. We add the elements to
135 the bin and connect them using gst_pipeline_pads_autoplug.
137 If we add a queue, we have to copy the caps of the sink element of the queue
138 to the src pad of the queue (else they won't connect)
140 we finally arrive at the sink element and we're done.
144 we have just found our mpeg1parse common element, so we start a thread.
145 We add a queue to the bin and a new thread, we add the elements
146 mp1videoparse and mpeg_play to the thread. We arrive at the videosink, we
147 see that the SUGGEST_THREAD flag is set, we add a queue and a thread and
148 add the videosink in the thread.
150 the same procedure happens for the audio part. We are now left with the
153 We will also have set a signal "new_pad" on the mpeg1parse element bacause
154 the element mp1videoparse could not be connected to the element just yet.
156 (------------------------------------) (----------
158 ! (-------------) (---------) ! ! (---------)
159 ! !mp1videoparse! !mpeg_play! ! ! !videosink!
160 videoqueue--sink src -- sink src -- queue --- sink !
161 ---------) (-----------) ! (-------------) (---------) ! ! (---------)
162 disksrc ! ! mpeg1parse! (------------------------------------) (-------------
164 ---------) (-----------)
165 queue----- same for audio
168 then we play, create_plan happens, data is flowing and the "new_pad" signal is called
169 from mpeg1parse, gst_pipeline_pad_autoplug is called and the connection between
170 mpeg1parse and the videoqueue is made. same for audio.
172 voila. smame procedure for mp3/vorbis/avi/qt/mpeg2 etc...
178 this is obviously a very naive solution. the creation of the elements actually happens
179 beforehand. MPEG2, for one, fails bacause there are multiple possibilities to go
180 from the mpeg demuxer to audio/raw (ac3, mp3)
182 Also any intermedia elements like mixers (subtitles) are not possible because we
183 assume that after the common elements, the streams to not converge anymore.