src/framework/mlt_consumer.c src/framework/mlt_consumer.h
[melted] / src / modules / kino / avi.h
1 /*
2 * avi.h library for AVI file format i/o
3 * Copyright (C) 2000 - 2002 Arne Schirmacher <arne@schirmacher.de>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 *
19 * Tag: $Name$
20 *
21 * Change log:
22 *
23 * $Log$
24 * Revision 1.3 2005/06/21 20:59:39 lilo_booter
25 * src/framework/mlt_consumer.c src/framework/mlt_consumer.h
26 * + Added a general profile handling for size, aspect ratio and display ratio
27 *
28 * src/framework/mlt_producer.c
29 * + Correction to aspect ratio properties
30 *
31 * src/inigo/inigo.c
32 * + Minimalist support for sdl_preview (still not very good)
33 *
34 * src/modules/avformat/consumer_avformat.c
35 * + Takes consumer profile into account
36 *
37 * src/modules/core/filter_resize.c
38 * + Corrections for synthesised producers and aspect ratio (inherits from consumer)
39 *
40 * src/modules/core/producer_colour.c
41 * src/modules/core/producer_noise.c
42 * src/modules/gtk2/producer_pango.c
43 * + Ensures that resize picks up consumer aspect ratio
44 *
45 * src/modules/dv/consumer_libdv.c
46 * + Honour wide screen output
47 *
48 * src/modules/gtk2/producer_pixbuf.c
49 * + Correction for 1:1 aspect ratio
50 *
51 * src/modules/kino/Makefile
52 * src/modules/kino/avi.cc
53 * src/modules/kino/avi.h
54 * src/modules/kino/configure
55 * src/modules/kino/filehandler.cc
56 * + Attempt to allow mov dv files to provide audio
57 *
58 * src/modules/sdl/consumer_sdl.c
59 * src/modules/sdl/consumer_sdl_preview.c
60 * src/modules/sdl/consumer_sdl_still.c
61 * + Takes consumer profile into account
62 *
63 * Revision 1.2 2005/04/15 14:37:03 lilo_booter
64 * Minor correction
65 *
66 * Revision 1.1 2005/04/15 14:28:26 lilo_booter
67 * Initial version
68 *
69 * Revision 1.16 2005/04/01 23:43:10 ddennedy
70 * apply endian fixes from Daniel Kobras
71 *
72 * Revision 1.15 2004/10/11 01:37:11 ddennedy
73 * mutex safety locks in RIFF and AVI classes, type 2 AVI optimization, mencoder export script
74 *
75 * Revision 1.14 2003/11/25 23:00:52 ddennedy
76 * cleanup and a few bugfixes
77 *
78 * Revision 1.13 2003/10/21 16:34:32 ddennedy
79 * GNOME2 port phase 1: initial checkin
80 *
81 * Revision 1.11.2.5 2003/07/24 14:13:57 ddennedy
82 * support for distinct audio stream in type2 AVI and Quicktime; support for more DV FOURCCs
83 *
84 * Revision 1.11.2.4 2003/06/10 23:53:36 ddennedy
85 * Daniel Kobras' WriteFrame error handling and automatic OpenDML, bugfixes in scene list updates, export AV/C Record
86 *
87 * Revision 1.11.2.3 2003/02/20 21:59:57 ddennedy
88 * bugfixes to capture and AVI
89 *
90 * Revision 1.11.2.2 2003/01/13 05:15:31 ddennedy
91 * added More Info panel and supporting methods
92 *
93 * Revision 1.11.2.1 2002/11/25 04:48:31 ddennedy
94 * bugfix to report errors when loading files
95 *
96 * Revision 1.11 2002/10/08 07:46:41 ddennedy
97 * AVI bugfixes, compatibility, optimization, warn bad file in capture and export dv file, allow no mplex
98 *
99 * Revision 1.10 2002/05/17 08:04:25 ddennedy
100 * revert const-ness of Frame references in Frame, FileHandler, and AVI classes
101 *
102 * Revision 1.9 2002/05/15 04:39:35 ddennedy
103 * bugfixes to dv2 AVI write, audio export, Xv init
104 *
105 * Revision 1.8 2002/04/29 05:09:22 ddennedy
106 * raw dv file support, Frame::ExtractAudio uses libdv, audioScrub prefs
107 *
108 * Revision 1.7 2002/04/09 06:53:42 ddennedy
109 * cleanup, new libdv 0.9.5, large AVI, dnd storyboard
110 *
111 * Revision 1.7 2002/03/25 21:34:25 arne
112 * Support for large (64 bit) files mostly completed
113 *
114 * Revision 1.6 2002/03/10 13:29:41 arne
115 * more changes for 64 bit access
116 *
117 * Revision 1.5 2002/03/09 17:59:28 arne
118 * moved index routines to AVIFile
119 *
120 * Revision 1.4 2002/03/09 10:26:26 arne
121 * improved constructors and assignment operator
122 *
123 * Revision 1.3 2002/03/09 08:55:57 arne
124 * moved a few variables to AVIFile
125 *
126 * Revision 1.2 2002/03/04 19:22:43 arne
127 * updated to latest Kino avi code
128 *
129 * Revision 1.1.1.1 2002/03/03 19:08:08 arne
130 * import of version 1.01
131 *
132 */
133
134 /** Common AVI declarations
135
136 Some of this comes from the public domain AVI specification, which
137 explains the microsoft-style definitions.
138
139 \file avi.h
140 */
141
142 #ifndef _AVI_H
143 #define _AVI_H 1
144
145 #include <stdint.h>
146 #include "riff.h"
147
148 #define PACKED(x) __attribute__((packed)) x
149
150 #define AVI_SMALL_INDEX (0x01)
151 #define AVI_LARGE_INDEX (0x02)
152 #define KINO_AVI_INDEX_OF_INDEXES (0x00)
153 #define KINO_AVI_INDEX_OF_CHUNKS (0x01)
154 #define AVI_INDEX_2FIELD (0x01)
155
156 enum { AVI_PAL, AVI_NTSC, AVI_AUDIO_48KHZ, AVI_AUDIO_44KHZ, AVI_AUDIO_32KHZ };
157
158 /** Declarations of the main AVI file header
159
160 The contents of this struct goes into the 'avih' chunk. */
161
162 typedef struct
163 {
164 /// frame display rate (or 0L)
165 DWORD dwMicroSecPerFrame;
166
167 /// max. transfer rate
168 DWORD dwMaxBytesPerSec;
169
170 /// pad to multiples of this size, normally 2K
171 DWORD dwPaddingGranularity;
172
173 /// the ever-present flags
174 DWORD dwFlags;
175
176 /// # frames in file
177 DWORD dwTotalFrames;
178 DWORD dwInitialFrames;
179 DWORD dwStreams;
180 DWORD dwSuggestedBufferSize;
181
182 DWORD dwWidth;
183 DWORD dwHeight;
184
185 DWORD dwReserved[ 4 ];
186 }
187 PACKED(MainAVIHeader);
188
189 typedef struct
190 {
191 WORD top, bottom, left, right;
192 }
193 PACKED(RECT);
194
195 /** Declaration of a stream header
196
197 The contents of this struct goes into the 'strh' header. */
198
199 typedef struct
200 {
201 FOURCC fccType;
202 FOURCC fccHandler;
203 DWORD dwFlags; /* Contains AVITF_* flags */
204 WORD wPriority;
205 WORD wLanguage;
206 DWORD dwInitialFrames;
207 DWORD dwScale;
208 DWORD dwRate; /* dwRate / dwScale == samples/second */
209 DWORD dwStart;
210 DWORD dwLength; /* In units above... */
211 DWORD dwSuggestedBufferSize;
212 DWORD dwQuality;
213 DWORD dwSampleSize;
214 RECT rcFrame;
215 }
216 PACKED(AVIStreamHeader);
217
218 typedef struct
219 {
220 DWORD dwDVAAuxSrc;
221 DWORD dwDVAAuxCtl;
222 DWORD dwDVAAuxSrc1;
223 DWORD dwDVAAuxCtl1;
224 DWORD dwDVVAuxSrc;
225 DWORD dwDVVAuxCtl;
226 DWORD dwDVReserved[ 2 ];
227 }
228 PACKED(DVINFO);
229
230 typedef struct
231 {
232 DWORD biSize;
233 LONG biWidth;
234 LONG biHeight;
235 WORD biPlanes;
236 WORD biBitCount;
237 DWORD biCompression;
238 DWORD biSizeImage;
239 LONG biXPelsPerMeter;
240 LONG biYPelsPerMeter;
241 DWORD biClrUsed;
242 DWORD biClrImportant;
243 }
244 PACKED(BITMAPINFOHEADER);
245
246 typedef struct
247 {
248 WORD wFormatTag;
249 WORD nChannels;
250 DWORD nSamplesPerSec;
251 DWORD nAvgBytesPerSec;
252 WORD nBlockAlign;
253 WORD wBitsPerSample;
254 WORD cbSize;
255 WORD dummy;
256 }
257 PACKED(WAVEFORMATEX);
258
259 typedef struct
260 {
261 WORD wLongsPerEntry;
262 BYTE bIndexSubType;
263 BYTE bIndexType;
264 DWORD nEntriesInUse;
265 FOURCC dwChunkId;
266 DWORD dwReserved[ 3 ];
267 struct avisuperindex_entry
268 {
269 QUADWORD qwOffset;
270 DWORD dwSize;
271 DWORD dwDuration;
272 }
273 aIndex[ 2014 ];
274 }
275 PACKED(AVISuperIndex);
276
277 typedef struct
278 {
279 WORD wLongsPerEntry;
280 BYTE bIndexSubType;
281 BYTE bIndexType;
282 DWORD nEntriesInUse;
283 FOURCC dwChunkId;
284 QUADWORD qwBaseOffset;
285 DWORD dwReserved;
286 struct avifieldindex_entry
287 {
288 DWORD dwOffset;
289 DWORD dwSize;
290 }
291 aIndex[ 4028 ];
292 }
293 PACKED(AVIStdIndex);
294
295 typedef struct
296 {
297 struct avisimpleindex_entry
298 {
299 FOURCC dwChunkId;
300 DWORD dwFlags;
301 DWORD dwOffset;
302 DWORD dwSize;
303 }
304 aIndex[ 20000 ];
305 DWORD nEntriesInUse;
306 }
307 PACKED(AVISimpleIndex);
308
309 typedef struct
310 {
311 DWORD dirEntryType;
312 DWORD dirEntryName;
313 DWORD dirEntryLength;
314 size_t dirEntryOffset;
315 int dirEntryWrittenFlag;
316 int dirEntryParentList;
317 }
318 AviDirEntry;
319
320
321 /** base class for all AVI type files
322
323 It contains methods and members which are the same in all AVI type files regardless of the particular compression, number
324 of streams etc.
325
326 The AVIFile class also contains methods for handling several indexes to the video frame content. */
327
328 class AVIFile : public RIFFFile
329 {
330 public:
331 AVIFile();
332 AVIFile( const AVIFile& );
333 virtual ~AVIFile();
334 virtual AVIFile& operator=( const AVIFile& );
335
336 virtual void Init( int format, int sampleFrequency, int indexType );
337 virtual int GetDVFrameInfo( off_t &offset, int &size, int frameNum );
338 virtual int GetFrameInfo( off_t &offset, int &size, int frameNum, FOURCC chunkID );
339 virtual int GetDVFrame( uint8_t *data, int frameNum );
340 virtual int getFrame( void *data, int frameNum, FOURCC chunkID );
341 virtual int GetTotalFrames() const;
342 virtual void PrintDirectoryEntryData( const RIFFDirEntry &entry ) const;
343 //virtual bool WriteFrame( const Frame &frame ) { return false; }
344 virtual void ParseList( int parent );
345 virtual void ParseRIFF( void );
346 virtual void ReadIndex( void );
347 virtual void WriteRIFF( void )
348 { }
349 virtual void FlushIndx( int stream );
350 virtual void UpdateIndx( int stream, int chunk, int duration );
351 virtual void UpdateIdx1( int chunk, int flags );
352 virtual bool verifyStreamFormat( FOURCC type );
353 virtual bool verifyStream( FOURCC type );
354 virtual bool isOpenDML( void );
355 virtual void setDVINFO( DVINFO& )
356 { }
357 virtual void setFccHandler( FOURCC type, FOURCC handler );
358 virtual bool getStreamFormat( void* data, FOURCC type );
359
360 protected:
361 MainAVIHeader mainHdr;
362 AVISimpleIndex *idx1;
363 int file_list;
364 int riff_list;
365 int hdrl_list;
366 int avih_chunk;
367 int movi_list;
368 int junk_chunk;
369 int idx1_chunk;
370
371 AVIStreamHeader streamHdr[ 2 ];
372 AVISuperIndex *indx[ 2 ];
373 AVIStdIndex *ix[ 2 ];
374 int indx_chunk[ 2 ];
375 int ix_chunk[ 2 ];
376 int strl_list[ 2 ];
377 int strh_chunk[ 2 ];
378 int strf_chunk[ 2 ];
379
380 int index_type;
381 int current_ix00;
382
383 DWORD dmlh[ 62 ];
384 int odml_list;
385 int dmlh_chunk;
386 bool isUpdateIdx1;
387
388 };
389
390
391 /** writing Type 1 DV AVIs
392
393 */
394
395 class AVI1File : public AVIFile
396 {
397 public:
398 AVI1File();
399 virtual ~AVI1File();
400
401 virtual void Init( int format, int sampleFrequency, int indexType );
402 //virtual bool WriteFrame( const Frame &frame );
403 virtual void WriteRIFF( void );
404 virtual void setDVINFO( DVINFO& );
405
406 private:
407 DVINFO dvinfo;
408
409 AVI1File( const AVI1File& );
410 AVI1File& operator=( const AVI1File& );
411 };
412
413
414 /** writing Type 2 (separate audio data) DV AVIs
415
416 This file type contains both audio and video tracks. It is therefore more compatible
417 to certain Windows programs, which expect any AVI having both audio and video tracks.
418 The video tracks contain the raw DV data (as in type 1) and the extracted audio tracks.
419
420 Note that because the DV data contains audio information anyway, this means duplication
421 of data and a slight increase of file size.
422
423 */
424
425 class AVI2File : public AVIFile
426 {
427 public:
428 AVI2File();
429 virtual ~AVI2File();
430
431 virtual void Init( int format, int sampleFrequency, int indexType );
432 //virtual bool WriteFrame( const Frame &frame );
433 virtual void WriteRIFF( void );
434 virtual void setDVINFO( DVINFO& );
435
436 private:
437 BITMAPINFOHEADER bitmapinfo;
438 WAVEFORMATEX waveformatex;
439
440 AVI2File( const AVI2File& );
441 AVI2File& operator=( const AVI2File& );
442 };
443 #endif