tee: Check for the removed pad flag also in the slow pushing path
[platform/upstream/gstreamer.git] / docs / random / sources
1 There are a number of different ways of coding a GstSrc.  I'll try to
2 outline them and how the function here: 
3
4 1a) Simple push-function based with single output
5
6
7  *------*      *------
8  !      !      !
9  ! src  !--->--! plugin
10  !      !      !      
11  *------*      *------
12
13 This is the style that all the existing sources use.  There is a single
14 output pad, and a _push function that's global to the whole element.  The
15 _push function simply constructs buffers and pushes them out the pad. 
16
17 Chained (current implementation): 
18
19
20       bin               src               pad1           pad2            plugin
21        !                                              (= pad1->peer)
22  gst_bin_iterate
23        !
24        ! (find entry)
25        !
26        ! gst_src_push
27        !---------------->!  
28                          ! (create buffer)
29                          !
30                          ! gst_pad_push    
31                          !---------------->! 
32                                            !
33                                            ! pad1->chainfunc (pad1->peer) 
34                                            !------------------------------->!
35                                            !                                !
36                                            :                                :
37                                                                       (more chaining)
38                                            :                                :
39                                            !<-------------------------------!
40                          !<----------------!
41       !<-----------------!
42       !
43   iteration ends
44       !
45      ---
46       -
47
48 Typically this will be the/an entry into the Bin.  The Bin's iterate
49 function simply calls the Src's _push function.  When the _push function
50 pushes a buffer out it's pad, the chain function of the peer pad is
51 called, presumably causing a push out the other side of that element, and
52 eventually data gets to the other end.  The stack unrolls, and the
53 iteration ends for that Src. 
54
55
56
57 Cothreaded: 
58
59 Again, the source would generally be an entry into the Bin.  A loopfunc
60 will be constructed around it, which will simply loop calling the Src's
61 _push function as in the non-cothreaded case.  When the _push function
62 pushes a buffer, it finds a pushfunc attached to the pad, drops the buffer
63 in the pen, and calls the pushfunc provided by the Bin.  This causes a
64 switch to the next element, then the next, to the end, at which point a
65 buffer pull will travel back down the chain.  The _push function gets
66 context and finishes, at which point the loopfunc wrapper simply calls it
67 again in the next iteration. 
68
69 (current implementation): 
70
71
72       bin               cothread1         src               pad1           pad2       cothread2      plugin
73        !                 (src)                          (= pad2->peer)                (plugin)
74  gst_bin_iterate
75        !
76        ! (first entry)
77        !
78        ! cothread_switch
79        !---------------->!  
80                          ! gst_src_push    
81                          !---------------->! 
82                                            ! (create buffer)
83                                            !
84                                            ! gst_pad_push (pad1) 
85                                            !
86                                            !--------------------!
87                                                                 ! (fill bufpen)
88                                                                 !
89                                                                 ! cothread switch
90                                                                 ----------------------->!
91                                                                                         ! gst_pad_pull (pad2)
92                                                                                         !
93                                                                             !<----------!
94                                                                             !
95                                                                             ! (get buffer from bufpen)
96                                                                             !
97                                                                             !---------->!
98                                                                                         ! pad2->chainfunc
99                                                                                         !------------->!
100                                                                                                        !
101                                                                                                        :
102                                                                                                        
103                                                                                                        :
104                                                                                         !<-------------!
105                                                                                         ! gst_pad_pull (pad2)
106                                                                             !<----------!
107                                                                             ! 
108                                                                             ! (bufpen empty)
109                                                                 !<----------! 
110                          !<-------------------------------------! cothread switch
111        !<----------------!
112        !
113   iteration ends
114        !
115        :
116
117        :
118        !
119   next iteration
120        !
121        ! cothread_switch
122        !---------------->!  
123                          ! gst_src_push    
124                          !---------------->! 
125                                            ! (create buffer)
126                                            !
127                                            ! gst_pad_push (pad1) 
128                                            !
129                                            !--------------------!
130                                                                 ! (fill bufpen)
131                                                                 !
132                                                                 ! cothread switch
133                                                                 !---------->!
134                                                                             ! (get buffer from bufpen)
135                                                                             !
136                                                                             !---------->!
137                                                                                         ! pad2->chainfunc
138                                                                                         !------------->!
139                                                                                                        !
140                                                                                                        :
141                                                                                                        
142                                                                                                        :
143                                                                                         !<-------------!
144                                                                                         ! gst_pad_pull (pad2)
145                                                                             !<----------!
146                                                                             ! 
147                                                                             ! (bufpen empty)
148                                                                 !<----------! 
149                          !<-------------------------------------! cothread switch
150        !<----------------!
151        !
152   iteration ends
153        !
154        :
155
156       
157 -----------------------------------------------------------------------------------------------
158 1b) Simple push-function based with multiple output
159
160 Chained: 
161
162 Similar to the single output variant, except several chains are spawned
163 off, one per push, hanging off whichever pad the buffer is pushed off of. 
164 The stack will grow and unwind as many times as buffers are pushed out. 
165
166 (current implementation)
167
168       bin               src               pad1           pad2            plugin
169        !                                              (= pad1->peer)
170  gst_bin_iterate
171        !
172        ! (find entry)
173        !
174        ! gst_src_push
175        !---------------->!  
176                          ! (create buffer)
177                          !
178                          ! gst_pad_push    
179                          !---------------->! 
180                                            !
181                                            ! pad1->chainfunc (pad1->peer) 
182                                            !------------------------------->!
183                                            !                                !
184                                            :                                :
185                                                                       (more chaining)
186                                            :                                :
187                                            !<-------------------------------!
188                          !<----------------!
189                          ! (create buffer)
190                          !
191                          ! gst_pad_push    
192                          !---------------->! 
193                                            !
194                                            ! pad1->chainfunc (pad1->peer) 
195                                            !------------------------------->!
196                                            !                                !
197                                            :                                :
198                                                                       (more chaining)
199                                            :                                :
200                                            !<-------------------------------!
201                          !<----------------!
202                          :
203                    (more pushes)
204                          :
205       !<-----------------!
206       !
207   iteration ends
208       !
209      ---
210       -
211
212
213 Cothreaded: 
214
215 Also similar to the single output variant.  When the pull winds its way
216 back from the first push, execution returns to the Src's _push function,
217 which simply goes off and pushes out another buffer, causing another
218 series of context switches.  Eventually the loopfunc wrapper starts over,
219 round and round we go. 
220
221
222
223 -----------------------------------------------------------------------------------------------
224 2) Pull-function based with single output
225
226 Similar to a regular filter with a chain function associated with each
227 pad, this kind of source doesn't provide a src-wide push function, but
228 does provide pullfuncs for its pad.  A pullfunc puts a buffer in the pen
229 and exits. 
230
231 Chained: 
232
233       bin               src               pad1           pad2            plugin
234        !                                              (= pad1->peer)
235  gst_bin_iterate
236        !
237        ! (find entry)
238        !
239        ! (find src pad
240        !  of entry element)
241        !
242        ! gst_pad_pull
243        !------------------------------------------------>!
244                                  ?                       !
245                          !<------------------------------!
246                          !  
247                          ! (create buffer)
248                          !
249                          ! gst_pad_push    
250                          !------------------------------>!
251                                                          ! (bufpen filled)
252                         (return buffer)                  !
253        !<------------------------------------------------!
254        !
255        ! gst_pad_chain
256        !------------------------------------------------------------------->!
257                                                                             !
258                                                                             :
259                                                                       (more chaining)
260                                                                             :
261        !<-------------------------------------------------------------------!
262        !
263   iteration ends
264        !
265       ---
266        -
267
268 As usual, is likely to be an entry into a Bin.  The Bin iterate code must
269 explicitly pull a buffer and pass it on to the peer.
270
271 Cothreaded: 
272
273
274       bin               cothread1         src               pad1           pad2       cothread2      plugin
275        !                 (src)                          (= pad2->peer)                (plugin)
276  gst_bin_iterate
277        !
278        ! (first entry)
279        !
280        ! cothread_switch
281        !---------------->! gst_pad_pull 
282                          !------------------------------------------------>!
283                                                    ?                       !
284                                            !<------------------------------!
285                                            !  
286                                            ! (create buffer)
287                                            !
288                                            ! gst_pad_push    
289                                            !------------------------------>!
290                                                                            ! (bufpen filled)
291                                                 (return buffer)            !
292                          !<------------------------------------------------!
293                          !
294                          ! pad_chain
295                          !--------------------------------------! cothread switch
296                                                                 |---------------------->!
297                                                                                         ! gst_pad_pull (pad2)
298                                                                                         !
299                                                                             !<----------!
300                                                                             !
301                                                                             ! (get buffer from bufpen)
302                                                                             !
303                                                                             !---------->!
304                                                                                         ! pad2->chainfunc
305                                                                                         !------------->!
306                                                                                                        !
307                                                                                                        :
308                                                                                                        
309                                                                                                        :
310                                                                                         !<-------------!
311                                                                                         ! gst_pad_pull (pad2)
312                                                                             !<----------!
313                                                                             ! 
314                                                                             ! (bufpen empty)
315                                                                !<-----------!
316                                                                !   cothread switch
317                                            !-------------------!   
318                          !<----------------!
319        !<----------------!                                     
320        !
321   iteration ends
322        !
323        :
324