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