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