8a669235b39eb3c45f36ac77cb4caf50aa4702c3
[platform/upstream/gstreamer.git] / docs / random / omega / pad-negotiation
1 When two pads are connected, a negotiation phase is going to have to
2 happen.  Ideally, the caps of the two pads will both be fully-specified,
3 and match.  That's the ideal case, but may rarely happen in practice.
4
5 It'll work the following way:
6
7 1) gst_pad_connect(pad1,pad2) is called by something
8 2) pad1's negotiate() method is called, with pad2 as argument
9 3) negotiate() repeatedly calls pad2's set_caps() method
10
11 At some point, the two pads will agree on a set of caps, and proceed by
12 returning TRUE from negotiate(), at which point gst_pad_connect()
13 finishes.  If it returns FALSE, gst_pad_connect() is forced to fail.
14
15 Now, obviously the algorithm used to find matching caps can get
16 complicated.  But in some cases it'll be simple.  Ideally, if there is no
17 negotiate() function for pad1, there'll be a function that will go through
18 the options and try to make pad1 and pad2 meet in the middle, with no
19 specific knowledge of what the caps actually mean.
20
21 Another detail is deciding which pads are pad1 and pad2.  In the autoplug
22 case, the code will sometimes know which of the pads have the more
23 specific caps.  In others, you may not.  Either you can guess, and
24 possibly lose to having the slower of the two pad's negotiate() methods do
25 the work, or you might be able to actually guess at which is the most
26 specific set of caps:
27
28 For any given typeid in the union of both pads, look at all properties
29   For each property, find the smallest range, assign this a 1.0
30     For all other instances of this property, assign relative to 1.0
31 For each pad1,pad2
32   Take the assigned value of every property, and multiply together
33
34 Whichever value is lower between pad1 and pad2 is most likely to be the
35 most specific set of caps.  The trick is implementing the above
36 efficiently, but on the surface there appear to be more than enough
37 potential optimizations.