Merge branch 'upstream/1.16' into tizen_gst_1.16.2
[platform/upstream/gstreamer.git] / docs / random / typefind
1 1) Goal:
2 ========
3 The goal of this document is to analyze current problems
4 in media type detection as we currently handle it in
5 GStreamer (as of 27/9/2003), and how these can be solved.
6 This touches upon typefinding, autoplugging and (optionally)
7 bytestream.
8
9 2) Typefinding, bytestream & autoplugging:
10 ==========================================
11
12 bytestream:
13 -----------
14 currently, bytestream collects incoming buffers and adds
15 them up (gst_buffer_merge ()). From this, a subbuffer is
16 created, which is inexpensive. In case of filesrc, the
17 merging is not expensive, too (mmap ()). However, in any
18 other source case, _merge () needs a new buffer plus copy
19 of the data. This is plain wrong. Source elements need to
20 be able to support a _read ()- instead of a _get ()-based
21 way of providing data to the pipeline on their choice. To
22 the rest of GStreamer, _get () and _read () are the same,
23 the only difference is that _read () also requests a size
24 of the buffer to be returned.
25
26 Surely, this does not mean that bytestream will read any
27 buffer size that is requested from it plainly, this would
28 be ineffective. It is still allowed to cache (although the
29 kernel will do this too...).
30
31 typefinding:
32 ------------
33 the typefind function type is currently defined as:
34
35 typedef struct _GstTypeDefinition {
36   gchar *name;
37   gchar *mimetype;
38   gchar *extension;
39   GstTypefindFunc func;
40 } GstTypeDefinition;
41
42 typedef (GstCaps *) (* GstTypefindFunc) (GstBuffer *buffer,
43                                          gpointer   private);
44
45 GstTypeFactory * gst_type_factory_new (GstTypeDefinition *def);
46
47 Although is is unclear what private is and how to use it
48 in a plugin. ;). The current approach has one large
49 disadvantage: the plugin cannot control the input for type
50 detection. Therefore, if the incoming buffer is not large
51 enough, typefinding will inappropriately fail. This is
52 unacceptable. The plugin needs to control input data flow
53 itself, so that we will have less false negatives and/or
54 will need only one cycle through the plugins to find the
55 type of a data stream.
56
57 Therefore, I propose the following change to the typefind
58 system:
59
60 typedef (GstCaps *) (* GstTypefindFunc) (GstBytestream *input,
61                                          gpointer       private);
62
63 and 
64
65 GstTypeFactory * gst_type_factory_new (GstTypeDefinition *definition,
66                                        gpointer           data);
67
68 The data gpointer will be provided as second argument to the
69 typefind function and is for private use to the plugin.
70
71 There is one rule: at the end of typefinding, the plugin needs
72 to take care that the state of the bytestream is exactly the
73 same as before typefinding. It may cache data, but it may not
74 skip (and therefore lose) data. If the bytestream supports
75 seeking, this is easy: simply seek back to 0 (start of stream)
76 after typefinding. If it does not, then you need to assure
77 that you only used _peek (), not _read () or _flush ().
78
79 The caller of the typefind function is responsible for creating
80 the bytestream and for emptying the cache and reusing it in the
81 data stream after the typefind function returns.
82
83 spider:
84 -------
85 Imo, spider should use GstTypefind (a public element) for
86 typefinding. Ideally, it would derive from it.
87
88 GstTypefind emits a signal when a type is found, and furtherly
89 only has a sink pad. the derived elements from this should
90 implement anything needed to make a proper autoplugger.
91
92 3) Status of this document
93 ==========================
94 Proposal, pending to be implemented. Target release is 0.8.0 or
95 any 0.7.x release.
96
97 4) Copyright and blabla
98 =======================
99 (c) Ronald Bultje, 2003 <rbultje@ronald.bitfreak.net> under the
100 terms of the GNU Free Documentation License. See http://www.gnu.org/
101 for details.