Tizen 2.1 base
[profile/ivi/gst-plugins-ugly0.10.git] / gst / mpegstream / notes
1 Basic parsing method
2 ====================
3
4 In an MPEG-2 Program Stream, every chunk of data starts with at least 23
5 zeros and a one.  This is followed by a byte of ID.  At any given point I
6 can search for the next 3-byte string equal to 1 to find the next chunk.
7 I assume these start codes are aligned on byte boundaries.  I might be
8 wrong, in which case this thing has to be rewritten at some point in the
9 future.
10
11 This means there are two basic modes of operation.  The first is the
12 simple search for the next start code.  The second is a continuation mode,
13 where data from the previous buffer is available to attempt to complete a
14 chunk.  Hopefully the majority of time will be spent in the first mode, as
15 that is where the most efficiency is, since there's no copying of partial
16 chunks.
17
18 The parsing is done as a state machine, as long as there's data left in
19 the buffer, something is attempted.  What is attempted is based on the
20 state of the parser (gee, so that's why they call it a state machine <g>).
21 The stages are:
22
23 1) looking for sync (have_sync == FALSE)
24    a) have some zeros (zeros > 0)
25 2) getting ID (have_sync == TRUE, id == 0)
26 3) decoding the chunk contents (have_sync == TRUE, id != 0)
27
28 Mechanism for handling cross-buffer chunks of data
29 ==================================================
30
31 The problem: if data were to come to the parser in 64-byte chunks, the
32 pack head would be split across at least two buffers, possibly three.  Up
33 front I will make the assumption that no one will be sending buffers of
34 less size than the largest chunk (header, PES packet), such that no chunk
35 will be split across more than two buffers.
36
37 If we take the pack header as an example, when the stream starts out, we
38 can assume that the it starts at the beginning of the buffer and doesn't
39 exceed the bounds of it.  However, if we're mid-stream and starting
40 another pack, it can be split across two buffers.