annotate DOCS/tech/general.txt @ 753:34c1a9fb631b

oh, this much? :p
author gabucino
date Thu, 10 May 2001 14:12:22 +0000
parents e6263c6d377a
children 1f26877717f1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
1 So, I'll describe how this stuff works.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
2
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
3 The basis of the program's structure is basically logical, however it's
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
4 a big hack :)
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
5
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
6 The main modules:
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
7
551
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
8 1. streamer.c: this is the input, this reads the file or the VCD. what it has
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
9 to know: appropriate buffering by sector, seek, skip functions,
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
10 reading by bytes, or blocks with any size.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
11 The stream_t structure describes the input stream, file/device.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
12
136
eaec3aac23b7 a little correction
gabucino
parents: 133
diff changeset
13 2. demuxer.c: this does the demultiplexing of the input to audio and video
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
14 channels, and their reading by buffered packages.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
15 The demuxer.c is basically a framework, which is the same for all the
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
16 input formats, and there are parsers for each of them (mpeg-es,
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
17 mpeg-ps, avi, avi-ni, asf), these are in the demux_*.c files.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
18 The structure is the demuxer_t. There is only one demuxer.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
19
551
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
20 2.a. demux_packet_t, that is DP.
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
21 Contains one chunk (avi) or packet (asf,mpg). They are stored in memory as
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
22 in chained list, cause of their different size.
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
23
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
24 2.b. demuxer stream, that is DS. Struct: demux_stream_t
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
25 Every channel (a/v) has one. This contains the packets for the stream (see
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
26 2.a). For now, there can be 2 for each demuxer, one for the audio and
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
27 one for the video.
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
28
551
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
29 2.c. stream header. There are 2 types (for now): sh_audio_t and sh_video_t
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
30 This contains every parameter essential for decoding, such as input/output
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
31 buffers, chosen codec, fps, etc. There are each for every stream in
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
32 the file. At least one for video, if sound is present then another,
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
33 but if there are more, then there'll be one structure for each.
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
34 These are filled according to the header (avi/asf), or demux_mpg.c
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
35 does it (mpg) if it founds a new stream. If a new stream is found,
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
36 the ====> Found audio/video stream: <id> messages is displayed.
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
37
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
38 The chosen stream header and its demuxer are connected together
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
39 (ds->sh and sh->ds) to simplify the usage. So it's enough to pass the
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
40 ds or the sh, depending on the function.
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
41
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
42 For example: we have an asf file, 6 streams inside it, 1 audio, 5
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
43 video. During the reading of the header, 6 sh structs are created,
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
44 1 audio and 5 video. When it starts reading the packet, it chooses
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
45 the first found audio & video stream, and sets the sh pointers of
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
46 d_audio and d_video according to them. So later it reads only these
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
47 streams. Of course the user can force choosing a specific stream with
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
48 -vid and -aid switches.
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
49 A good example for this is the DVD, where the english stream is not
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
50 always the first, so every VOB has different language :)
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
51 That's when we have to use for example the -aid 128 switch.
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
52
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
53 Now, how this reading works?
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
54 - demuxer.c/demux_read_data() is called, it gets how many bytes,
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
55 and where (memory address), would we like to read, and from which
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
56 DS. The codecs call this.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
57 - this checks if the given DS's buffer contains something, if so, it
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
58 reads from there as much as needed. If there isn't enough, it calls
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
59 ds_fill_buffer(), which:
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
60 - checks if the given DS has buffered packages (DP's), if so, it moves
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
61 the oldest to the buffer, and reads on. If the list is empty, it
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
62 calls demux_fill_buffer() :
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
63 - this calls the parser for the input format, which reads the file
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
64 onward, and moves the found packages to their buffers.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
65 Well it we'd like an audio package, but only a bunch of video
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
66 packages are available, then sooner or later the:
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
67 DEMUXER: Too many (%d in %d bytes) audio packets in the buffer
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
68 error shows up.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
69
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
70 So everything is ok 'till now, I want to move them to a separate lib.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
71
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
72 Now, go on:
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
73
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
74 3. mplayer.c - ooh, he's the boss :)
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
75 The timing is solved odd, since it has/recommended to be done differently
138
5f2805a2d5de even more cosmetics
gabucino
parents: 136
diff changeset
76 for each of the formats, and sometimes can be done in many ways.
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
77 There are the a_frame and v_frame float variables, they store the
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
78 just played a/v position is seconds.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
79 A new frame is displayed if v_frame<a_frame, and sound is decoded if
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
80 a_frame<v_frame.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
81 When playing (a/v), it increases the variables by the duration of the
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
82 played a/v. In video, it's usually 1.0/fps, but I have to mention that
138
5f2805a2d5de even more cosmetics
gabucino
parents: 136
diff changeset
83 fps doesn't really matters at video, for example asf doesn't have that,
5f2805a2d5de even more cosmetics
gabucino
parents: 136
diff changeset
84 instead there is "duration" and it can change per frame.
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
85 MPEG2 has "repeat_count" which delays the frame by 1-2.5 ...
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
86 Maybe only AVI and MPEG1 has fixed fps.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
87
138
5f2805a2d5de even more cosmetics
gabucino
parents: 136
diff changeset
88 So everything works right until the audio and video are in perfect
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
89 synchronity, since the audio goes, it gives the timing, and if the
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
90 time of a frame passed, the next frame is displayed.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
91 But what if these two aren't synchronized in the input file?
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
92 PTS correction kicks in. The input demuxers read the PTS (presentation
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
93 timestamp) of the packages, and with it we can see if the streams
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
94 are synchronized. Then MPlayer can correct the a_frame, within
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
95 a given maximal bounder (see -mc option). The summary of the
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
96 corrections can be found in c_total .
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
97
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
98 Of course this is not everything, several things suck.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
99 For example the soundcards delay, which has to be corrected by
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
100 MPlayer: that's why it needs the size of the audio buffer. It can
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
101 be measured with select(), which is unfortunately not supported by
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
102 every card... That's when it has to be given with the -abs option.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
103
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
104 Then there's another problem: in MPEG, the PTS is not given by
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
105 frames, rather by sectors, which can contain 10 frames, or only 0.1 .
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
106 In order this won't fuck up timing, we average the PTS by 5 frames,
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
107 and use this when correcting.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
108
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
109 Life didn't get simpler with AVI. There's the "official" timing
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
110 method, the BPS-based, so the header contains how many compressed
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
111 audio bytes belong to one second of frames.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
112 Of course this doesn't always work... why it should :)
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
113 So I emulate the MPEG's PTS/sector method on AVI, that is the
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
114 AVI parser calculates a fake PTS for every read chunk, decided by
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
115 the type of the frames. This is how my timing is done. And sometimes
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
116 this works better.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
117
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
118 In AVI, usually there is a bigger piece of audio stored first, then
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
119 comes the video. This needs to be calculated into the delay, this is
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
120 called "Initial PTS delay".
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
121 Of course there are 2 of them, one is stored in the header and not
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
122 really used :) the other isn't stored anywhere, this can only be
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
123 measured...
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
124
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
125 4. Codecs. They are separate libs.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
126 For example libac3, libmpeg2, xa/*, alaw.c, opendivx/*, loader, mp3lib.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
127 mplayer.c calls them if a piece of audio or video needs to be played.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
128 (see the beginning of 3.)
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
129 And they call the appropriate demuxer, to get the compressed data.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
130 (see 2.)
551
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
131 We have to pass the appropriate stream header as parameter (sh_audio/
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
132 sh_video), this should contain all the needed info for decoding
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
133 (the demuxer too: sh->ds).
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
134 The codecs' seprating is underway, the audio is already done, the video is
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
135 work-in-progress. The aim is that mplayer.c won't have to know
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
136 which are the codecs and how to use 'em, instead it should call
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
137 an init/decode audio/video function.
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
138
551
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
139 5. libvo: this displays the frame.
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
140 The constants for different pixelformats are defined in img_format.h,
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
141 their usage is mandatory.
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
142
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
143 Each vo driver _has_ to implement these:
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
144
551
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
145 query_format() - queries if a given pixelformat is supported.
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
146 return value: flags:
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
147 0x1 - supported (by hardware or conversion)
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
148 0x2 - supported (by hardware, without conversion)
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
149 0x4 - sub/osd supported (has draw_alpha)
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
150 IMPORTANT: it's mandatorial that every vo driver support the YV12 format,
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
151 and one (or both) of BGR15 and BGR24, with conversion, if needed.
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
152 If these aren't supported, not every codec will work! The mpeg codecs
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
153 can output only YV12, and the older win32 DLLs only 15 and 24bpp.
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
154 There is a fast MMX-using 15->16bpp converter, so it's not a
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
155 significant speed-decrease!
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
156
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
157 The BPP table, if the driver can't change bpp:
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
158 current bpp has to accept these
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
159 15 15
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
160 16 15,16
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
161 24 24
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
162 24,32 24,32
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
163
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
164 If it can change bpp (for example DGA 2, fbdev, svgalib), then if possible
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
165 we have to change to the desired bpp. If the hardware doesn't support,
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
166 we have to change to the one closest to it, and do conversion!
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
167
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
168 init() - this is called before displaying of the first frame -
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
169 initializing buffers, etc.
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
170
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
171 draw_slice(): this displays YV12 pictures (3 planes, one full sized that
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
172 contains brightness (Y), and 2 quarter-sized which the colour-info
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
173 (U,V). MPEG codecs (libmpeg2, opendivx) use this. This doesn't have
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
174 to display the whole frame, only update small parts of it.
551
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
175
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
176 draw_frame(): this is the older interface, this displays only complete
133
1cb4ee3b4890 fixed small typos
arpi_esp
parents: 132
diff changeset
177 frames, and can do only packed format (YUY2, RGB/BGR).
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
178 Win32 codecs use this (DivX, Indeo, etc).
551
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
179
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
180 draw_alpha(): this displays subtitles and OSD.
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
181 It's a bit tricky to use it, since it's not a part of libvo API,
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
182 but a callback-style stuff. The flip_page() has to call
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
183 vo_draw_text(), so that it passes the size of the screen and the
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
184 corresponding draw_alpha() implementation for the pixelformat
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
185 (function pointer). The vo_draw_text() checks the characters to draw,
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
186 and calls draw_alpha() for each.
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
187 As a help, osd.c contains draw_alpha for each pixelformats, use this
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
188 if possible!
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
189
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
190 flip_page(): this is called after each frame, this diplays the buffer for
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
191 real. This is 'swapbuffers' when double-buffering.
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
192
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
193