]> git.sesse.net Git - mlt/blob - src/modules/kino/avi.h
Avoid unnecessary compilation when running "./configure; make; make install" multiple...
[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
20 /** Common AVI declarations
21  
22     Some of this comes from the public domain AVI specification, which
23     explains the microsoft-style definitions.
24  
25     \file avi.h
26 */
27
28 #ifndef _AVI_H
29 #define _AVI_H 1
30
31 #include <stdint.h>
32 #include "riff.h"
33
34 #define PACKED(x)       __attribute__((packed)) x
35
36 #define AVI_SMALL_INDEX (0x01)
37 #define AVI_LARGE_INDEX (0x02)
38 #define KINO_AVI_INDEX_OF_INDEXES (0x00)
39 #define KINO_AVI_INDEX_OF_CHUNKS (0x01)
40 #define AVI_INDEX_2FIELD (0x01)
41
42 enum { AVI_PAL, AVI_NTSC, AVI_AUDIO_48KHZ, AVI_AUDIO_44KHZ, AVI_AUDIO_32KHZ };
43
44 /** Declarations of the main AVI file header
45  
46     The contents of this struct goes into the 'avih' chunk.  */
47
48 typedef struct
49 {
50         /// frame display rate (or 0L)
51         DWORD dwMicroSecPerFrame;
52
53         /// max. transfer rate
54         DWORD dwMaxBytesPerSec;
55
56         /// pad to multiples of this size, normally 2K
57         DWORD dwPaddingGranularity;
58
59         /// the ever-present flags
60         DWORD dwFlags;
61
62         /// # frames in file
63         DWORD dwTotalFrames;
64         DWORD dwInitialFrames;
65         DWORD dwStreams;
66         DWORD dwSuggestedBufferSize;
67
68         DWORD dwWidth;
69         DWORD dwHeight;
70
71         DWORD dwReserved[ 4 ];
72 }
73 PACKED(MainAVIHeader);
74
75 typedef struct
76 {
77         WORD top, bottom, left, right;
78 }
79 PACKED(RECT);
80
81 /** Declaration of a stream header
82  
83     The contents of this struct goes into the 'strh' header. */
84
85 typedef struct
86 {
87         FOURCC fccType;
88         FOURCC fccHandler;
89         DWORD dwFlags;                /* Contains AVITF_* flags */
90         WORD wPriority;
91         WORD wLanguage;
92         DWORD dwInitialFrames;
93         DWORD dwScale;
94         DWORD dwRate;                 /* dwRate / dwScale == samples/second */
95         DWORD dwStart;
96         DWORD dwLength;               /* In units above... */
97         DWORD dwSuggestedBufferSize;
98         DWORD dwQuality;
99         DWORD dwSampleSize;
100         RECT rcFrame;
101 }
102 PACKED(AVIStreamHeader);
103
104 typedef struct
105 {
106         DWORD dwDVAAuxSrc;
107         DWORD dwDVAAuxCtl;
108         DWORD dwDVAAuxSrc1;
109         DWORD dwDVAAuxCtl1;
110         DWORD dwDVVAuxSrc;
111         DWORD dwDVVAuxCtl;
112         DWORD dwDVReserved[ 2 ];
113 }
114 PACKED(DVINFO);
115
116 typedef struct
117 {
118         DWORD biSize;
119         LONG biWidth;
120         LONG biHeight;
121         WORD biPlanes;
122         WORD biBitCount;
123         DWORD biCompression;
124         DWORD biSizeImage;
125         LONG biXPelsPerMeter;
126         LONG biYPelsPerMeter;
127         DWORD biClrUsed;
128         DWORD biClrImportant;
129         char dummy[ 1040 ];
130 }
131 PACKED(BITMAPINFOHEADER);
132
133 typedef struct
134 {
135         WORD wFormatTag;
136         WORD nChannels;
137         DWORD nSamplesPerSec;
138         DWORD nAvgBytesPerSec;
139         WORD nBlockAlign;
140         WORD wBitsPerSample;
141         WORD cbSize;
142         WORD dummy;
143 }
144 PACKED(WAVEFORMATEX);
145
146 typedef struct
147 {
148         WORD wLongsPerEntry;
149         BYTE bIndexSubType;
150         BYTE bIndexType;
151         DWORD nEntriesInUse;
152         FOURCC dwChunkId;
153         DWORD dwReserved[ 3 ];
154         struct avisuperindex_entry
155         {
156                 QUADWORD qwOffset;
157                 DWORD dwSize;
158                 DWORD dwDuration;
159         }
160         aIndex[ 3198 ];
161 }
162 PACKED(AVISuperIndex);
163
164 typedef struct
165 {
166         WORD wLongsPerEntry;
167         BYTE bIndexSubType;
168         BYTE bIndexType;
169         DWORD nEntriesInUse;
170         FOURCC dwChunkId;
171         QUADWORD qwBaseOffset;
172         DWORD dwReserved;
173         struct avifieldindex_entry
174         {
175                 DWORD dwOffset;
176                 DWORD dwSize;
177         }
178         aIndex[ 17895 ];
179 }
180 PACKED(AVIStdIndex);
181
182 typedef struct
183 {
184         struct avisimpleindex_entry
185         {
186                 FOURCC  dwChunkId;
187                 DWORD   dwFlags;
188                 DWORD   dwOffset;
189                 DWORD   dwSize;
190         }
191         aIndex[ 20000 ];
192         DWORD   nEntriesInUse;
193 }
194 PACKED(AVISimpleIndex);
195
196 typedef struct
197 {
198         DWORD dirEntryType;
199         DWORD dirEntryName;
200         DWORD dirEntryLength;
201         size_t dirEntryOffset;
202         int dirEntryWrittenFlag;
203         int dirEntryParentList;
204 }
205 AviDirEntry;
206
207
208 /** base class for all AVI type files
209  
210     It contains methods and members which are the same in all AVI type files regardless of the particular compression, number
211     of streams etc. 
212  
213     The AVIFile class also contains methods for handling several indexes to the video frame content. */
214
215 class AVIFile : public RIFFFile
216 {
217 public:
218         AVIFile();
219         AVIFile( const AVIFile& );
220         virtual ~AVIFile();
221         virtual AVIFile& operator=( const AVIFile& );
222
223         virtual void Init( int format, int sampleFrequency, int indexType );
224         virtual int GetDVFrameInfo( off_t &offset, int &size, int frameNum );
225         virtual int GetFrameInfo( off_t &offset, int &size, int frameNum, FOURCC chunkID );
226         virtual int GetDVFrame( uint8_t *data, int frameNum );
227         virtual int getFrame( void *data, int frameNum, FOURCC chunkID );
228         virtual int GetTotalFrames() const;
229         virtual void PrintDirectoryEntryData( const RIFFDirEntry &entry ) const;
230         //virtual bool WriteFrame( const Frame &frame ) { return false; }
231         virtual void ParseList( int parent );
232         virtual void ParseRIFF( void );
233         virtual void ReadIndex( void );
234         virtual void WriteRIFF( void )
235         { }
236         virtual void FlushIndx( int stream );
237         virtual void UpdateIndx( int stream, int chunk, int duration );
238         virtual void UpdateIdx1( int chunk, int flags );
239         virtual bool verifyStreamFormat( FOURCC type );
240         virtual bool verifyStream( FOURCC type );
241         virtual bool isOpenDML( void );
242         virtual void setDVINFO( DVINFO& )
243         { }
244         virtual void setFccHandler( FOURCC type, FOURCC handler );
245         virtual bool getStreamFormat( void* data, FOURCC type );
246
247 protected:
248         MainAVIHeader mainHdr;
249         AVISimpleIndex *idx1;
250         int file_list;
251         int riff_list;
252         int hdrl_list;
253         int avih_chunk;
254         int movi_list;
255         int junk_chunk;
256         int idx1_chunk;
257
258         AVIStreamHeader streamHdr[ 2 ];
259         AVISuperIndex *indx[ 2 ];
260         AVIStdIndex *ix[ 2 ];
261         int indx_chunk[ 2 ];
262         int ix_chunk[ 2 ];
263         int strl_list[ 2 ];
264         int strh_chunk[ 2 ];
265         int strf_chunk[ 2 ];
266
267         int index_type;
268         int current_ix00;
269
270         DWORD dmlh[ 62 ];
271         int odml_list;
272         int dmlh_chunk;
273         bool isUpdateIdx1;
274
275 };
276
277
278 /** writing Type 1 DV AVIs
279  
280 */
281
282 class AVI1File : public AVIFile
283 {
284 public:
285         AVI1File();
286         virtual ~AVI1File();
287
288         virtual void Init( int format, int sampleFrequency, int indexType );
289         //virtual bool WriteFrame( const Frame &frame );
290         virtual void WriteRIFF( void );
291         virtual void setDVINFO( DVINFO& );
292
293 private:
294         DVINFO dvinfo;
295
296         AVI1File( const AVI1File& );
297         AVI1File& operator=( const AVI1File& );
298 };
299
300
301 /** writing Type 2 (separate audio data) DV AVIs
302  
303 This file type contains both audio and video tracks. It is therefore more compatible
304 to certain Windows programs, which expect any AVI having both audio and video tracks.
305 The video tracks contain the raw DV data (as in type 1) and the extracted audio tracks.
306  
307 Note that because the DV data contains audio information anyway, this means duplication
308 of data and a slight increase of file size.
309  
310 */
311
312 class AVI2File : public AVIFile
313 {
314 public:
315         AVI2File();
316         virtual ~AVI2File();
317
318         virtual void Init( int format, int sampleFrequency, int indexType );
319         //virtual bool WriteFrame( const Frame &frame );
320         virtual void WriteRIFF( void );
321         virtual void setDVINFO( DVINFO& );
322
323 private:
324         BITMAPINFOHEADER bitmapinfo;
325         WAVEFORMATEX waveformatex;
326
327         AVI2File( const AVI2File& );
328         AVI2File& operator=( const AVI2File& );
329 };
330 #endif