Debian Codegraph @

doc/README-DEVEL

raw
1
2 --- 1. Overview of library services ---
3
4 Plugin-based architecture that provides access to audio & video
5 compressors/decompressors for a wide range of formats.
6
7 Interfaces for reading from AVI & ASF files, with and without implicit
8 decompression.
9
10 Interfaces for writing to AVI files, with and without implicit compression.
11
12 Object that provides core of movie player for supported file types.
13
14 --- 2. Subdirectories ---
15
16 include/: All header files which may be needed for
17 programmer to use the library.
18
19 plugins/: Main set of codec plugins.
20 plugins/libwin32/: Win32 DLL loading plugin.
21 plugins/libaudiodec/: Audio decoder plugins for a few formats.
22 plugins/libmpeg_audiodec/: MPEG layer-1..3 audio decoder plugin
23 plugins/libmp3lame_audioenc/: MPEG layer-3 audio encoder plugin
24 plugins/libmp3lamebin_audioenc/:MPEG layer-3 audio encoder plugin loaded
25 at runtime using libmp3lame
26
27 lib/: Core library.
28 lib/common/: Set of utility functions and implementations
29 of non-pure methods in plugin interfaces.
30 lib/aviread/: Implementation of AVI & ASF readers.
31 lib/aviwrite/: Implementation of AVI writer.
32 lib/aviplay/: Implementation of AVI/ASF player.
33
34 player/: Movie player.
35 samples/: Various tools & examples of using library.
36
37 --- 3. Coding style conventions ---
38
39 All methods of public interfaces are named in MFC style ( one or
40 more concatenated words, each word beginning with CAPITAL letter );
41 for example, IAviPlayer::SetColorSpace() or CImage::Width(). On the opposite,
42 internal function names start with lowercase letters
43 ( AviPlayer::getVideoAsync() ).
44 Class member variables begin with capital letters and are prefixed with m_
45 and with appropriate type information:
46 p pointer
47 b bool
48 u unsigned
49 c char
50 s short
51 i 32-bit integer ( int, long )
52 l 64-bit integer ( long long )
53 f float
54 d double
55 Code is indented in BSD style with 4-space tabs. Short if() expressions
56 may be written in one line, as in 'if(...) return; '.
57 For imported parts of project ( such as lame mp3 encoder ) original coding
58 style is left untouched.
59
60 --- 4. Using codecs ---
61
62 All codec object creation functions are declared in include/creators.h. To
63 avoid possible naming collisions, they were put into namespace Creators.
64 Decoder creation functions take pointer to compressed format description
65 structure ( which is WAVEFORMATEX for audio and BITMAPINFOHEADER for video;
66 both are declared in include/formats.h ). Encoder creators take pointer
67 to structure that describes uncompressed format and so-called FOURCC -
68 which describes desired compression format.
69 All of them look through the list of registered plugins and try to find
70 the codec matching request. They return pointer to initialized object on
71 success and 0 on failure.
72 When codec object is not needed any more, use one of Free* functions from
73 include/creators.h to destroy it. It frees all data structures and decrements
74 usage count of the plugin that provided the codec.
75 Each codec interface includes function GetCodecInfo(). It returns reference
76 to CodecInfo structure with all known information about codec ( such as: is it
77 video or audio codec, does it support both encoding & decoding, etc. )
78 Many codecs have 'attributes' which affect their performance, quality, etc.
79 These attributes can be enumerated using fields of CodecInfo structure.
80 Attributes should be set before codec object starts operation. They can
81 be read and written with Creators::GetCodecAttr/Creators::SetCodecAttr.
82 Once set, these values will be stored in config file and reused every
83 time codec is initialized.
84
85 --- 5. Video codecs specifics ---
86
87 Some video codecs support run-time setting of attributes ( during the encoding
88 or decoding process ). For example, video decoder may suggest the option to
89 do post-processing with different levels of quality independently on each frame,
90 or to adjust brightness of picture. This video decoder will inherit from
91 interface IRtConfig ( declared in include/videodecoder.h ). Do a dynamic_cast
92 on received interface to determine if it's the case.
93 Initial value for run-time attribute will be read from config file. If you
94 want to permanently change it, do two calls - to Creators::SetCodecAttr and to
95 IRtConfig::SetValue with the same attribute name.
96 Video decoders can produce data in any of the following formats: RGB 16-bit
97 ( color weights 555 & 565 ), 24-bit, 32-bit, YUY2 and YV12. User can specify
98 desired format in call to IVideoDecoder::SetDestFmt(). However, internal video
99 decoder logic does not always support all these formats. For these cases library
100 provides a set of conversion functions between all supported formats. It is
101 optimal in terms of efficiency when the decoder itself performs the conversion
102 ( it is especially important for conversions into YUV formats ). For this purpose,
103 video decoders have method GetCapabilities(), which can be used to determine
104 internal capabilities of decoder.
105 Video decoders take a special attribute - 'flip' to the constructing function.
106 'True' here means that decoder shouldn't flip vertically picture. By default decoder
107 produces flipped picture: it allows to do simple memcpy() to X11 screen.
108 Unfortunately, not all encoders are able to compress 'flipped' video formats,
109 which are indicated by negative value in biHeight field of BITMAPINFOHEADER
110 structure.
111
112 --- 6. Audio decoders specifics ---
113
114 Audio decoder objects convert input compressed data into raw PCM ( 16-bit
115 signed low-endian, suitable for feeding to /dev/dsp ). Unlike with video decoders,
116 there's generally no need here to start/stop conversion because it's usually
117 done on per-sample basis and samples are independent from each other.
118
119 --- 7. Audio encoders specifics ---
120
121 Area of audio encoding is not well developed. There's only one experimental
122 audio encoder plugin, based on Lame MP3 encoder v. 3.70.
123
124 --- 8. ASF and AVI reading ( without decompression ) ---
125
126 Direct ASF, MMS and AVI reading interface is described in include/ReadHandlers.h.
127 Reader object is created with CreateAVIReadHandler() ( for AVI ) and
128 CreateASXReadHandler() ( for ASF family ).
129 CreateAVIReadHandler() is synchronous. It either returns pointer to valid
130 reader object, or throws an exception in one of formats from include/except.h.
131 On the other hand, opening of ASF file may be an asynchronous operation.
132 That is, constructor only performs sanity checking on the file name, starts
133 actual opening process ( in another thread ) and returns successfully. You should
134 periodically call IMediaReadHandler::isOpened() until it returns true, which
135 means that opening process has finished. After that, you can determine if it
136 was successful by calling IMediaReadHandler::isValid().
137 MMS URL or local ASX file may point to the 'redirector' - XML file that
138 includes copyrights, file information, etc. and other URLs. Call
139 IMediaReadHandler::isRedirector() after isOpened() and isValid() returned true
140 to determine if it's the case.
141 After successful opening of non-redirector file you can read data from its
142 streams through IMediaReadStream* interfaces. You don't need to destroy
143 them manually when they are not needed any more, and multiple requests
144 for the interface to the same stream will return the same pointer.
145
146 --- 9. ASF and AVI reading with implicit decompression ---
147
148 This interface is described in include/avifile.h. Reader object is created
149 with CreateIAviReadFile(). This function has the same semantics as object
150 creators from previous section. It tries to open passed URL as a local AVI file,
151 if it fails, as an ASF, and it it fails too, throws an exception.
152 To read the data, use IAviReadStream interface. It acts as a 'wrapper' to
153 IMediaReadStream and I[Video|Audio]Decoder. To start reading uncompressed data,
154 call IAviReadStream::StartStreaming(). It returns 0 on success and negative
155 value if it fails to create decoder object.
156 Audio data should be read using IAviReadStream::ReadFrames() and video data -
157 using IAviReadStream::GetFrame() and IAviReadStream::ReadFrame().
158
159 --- 10. AVI writing ---
160
161 This interface is also described in include/avifile.h. You can either use
162 implicit compression ( by writing into streams returned with
163 IAviWriteFile::AddAudioStream() & IAviWriteFile::AddVideoStream() ) or write
164 directly into file ( IAviWriteFile::AddStream() ). File headers will be
165 updated and written to the disk each 1000 accesses to streams to minimize
166 damage of hardware or software failure. When writing is finished, delete the
167 object; it writes final version of headers, appends an index chunk and closes
168 the file.
169 The library is able to write 'segmented' AVI files. It is a convenient way
170 to work-around 2 Gb file size limit which exists both because of AVI format
171 specification misfeature and because of limitations of most Linux kernels
172 ( >2Gb files are properly supported only in 2.4 series ). When such object is
173 created, you pass the file size limit as an argument to constructor. Each time
174 physical file grows beyond that size, library automatically closes it, changes
175 the name and starts a new one.
176
177 --- 11. Movie player core ---
178
179 Movie player core is declared in include/aviplay.h. It suggests two choices.
180 If you want to do all GUI-related work by yourself, use interface IAviPlayer.
181 You'll have to pass to the core a pointer to draw function which will be called
182 when there's a need to draw new frame. Library will do all internal work, such
183 as opening file and ( if needed ) audio device, synchronizing audio with video,
184 etc. You will handle initialization, changing media ( in case of ASF redirectors ),
185 passing events from keyboard/mouse to the library and drawing.
186 The second choice is to allow library to do drawing. Use interface IAviPlayer2
187 for it. If you want to have video output, establish the connection with X server
188 and pass the connection handle (Display*) to the library through construction
189 function. Library will accept NULL handle, which will mean that there'll be no
190 video output.
191
192 --- 12. Plugin system ---
193
194 Important feature of the library is its ability to automatically discover
195 and use plugins with predefined interface to perform compression/decompression
196 of data. Plugins have to be dlopen()'able libtool libraries ( linked with -module
197 flag ) and be installed in predefined directory. By default it's /usr/lib/win32,
198 it can be changed during compilation ( with --with-win32-path configure
199 parameter ) or after installation ith WIN32_PATH environment variable. Each
200 plugin exports several functions, which are defined and described in
201 include/plugin.h.
202 Plugin system is not tightly bound to avifile. One can compile and use its plugins
203 without core library.
204 If you want to write your own plugin that can be used by avifile, take a look at
205 the opendivx plugin sample ( it can be found at http://divx.euro.ru/download.htm ).
206 It is made completely independent of avifile. You will notice that it includes a
207 subset of avifile headers, ~40k total, which describe all necessary types and
208 interfaces.
209 Using these plugins by themselves is also possible. You'll have to do the following:
210 1) Copy API/ and common/ directories from opendivx plugin into your project.
211 Link your application against code in common/.
212 2) Search the plugin directory for files with .la extension. Parse them to find
213 line "dlname='...'". Dlopen() corresponding shared library.
214 3) Make sure that API versions of plugin and your code are the same.
215 4) Call exported functions of plugin to create codec objects.
216
217 --- 13. Image conversion speeds ----
218
219 Numbers are approximate CPU cycles per pixel and measured on non-MMX processor
220 for 640x480 random image without overflows. Source format is the determined by
221 the row. For typical 600 MHz processor 100 cycles/pixel correspond to 20 frames
222 per second with 640x480 image. Your numbers may differ, depending on processor
223 family, memory speed, etc.
224 Many of these conversions can possibly be optimized ( so far the only
225 MMX-optimized conversion is RGB15->RGB16 ).
226
227 Without flipping:
228 RGB15 RGB16 RGB24 RGB32 YUY2 YV12
229 RGB15 10 20 31 67 101 84
230 RGB16 68 10 31 66 103 83
231 RGB24 36 35 15 34 68 52
232 RGB32 63 63 27 20 96 79
233 YUY2 133 135 113 159 10 19
234 YV12 133 132 97 132 20 7
235
236 With flipping:
237 RGB15 RGB16 RGB24 RGB32 YUY2 YV12
238 RGB15 10 18 30 76 101 82
239 RGB16 70 10 30 78 101 84
240 RGB24 41 40 15 46 68 53
241 RGB32 72 66 26 19 96 79
242 YUY2 138 137 98 142 10 18
243 YV12 135 134 95 140 20 7
244
245 Last modified; January 21, 2001