00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00097 #ifndef _AVI_H
00098 #define _AVI_H 1
00099
00100 #include "riff.h"
00101 #include "frame.h"
00102
00103 #define PACKED(x) __attribute__((packed)) x
00104
00105 #define AVI_SMALL_INDEX (0x01)
00106 #define AVI_LARGE_INDEX (0x02)
00107 #define AVI_INDEX_OF_INDEXES (0x00)
00108 #define AVI_INDEX_OF_CHUNKS (0x01)
00109 #define AVI_INDEX_2FIELD (0x01)
00110
00111 enum { AVI_PAL, AVI_NTSC, AVI_AUDIO_48KHZ, AVI_AUDIO_44KHZ, AVI_AUDIO_32KHZ };
00112
00117 typedef struct
00118 {
00120 DWORD dwMicroSecPerFrame;
00121
00123 DWORD dwMaxBytesPerSec;
00124
00126 DWORD dwPaddingGranularity;
00127
00129 DWORD dwFlags;
00130
00132 DWORD dwTotalFrames;
00133 DWORD dwInitialFrames;
00134 DWORD dwStreams;
00135 DWORD dwSuggestedBufferSize;
00136
00137 DWORD dwWidth;
00138 DWORD dwHeight;
00139
00140 DWORD dwReserved[ 4 ];
00141 }
00142 PACKED(MainAVIHeader);
00143
00144 typedef struct
00145 {
00146 WORD top, bottom, left, right;
00147 }
00148 PACKED(RECT);
00149
00154 typedef struct
00155 {
00156 FOURCC fccType;
00157 FOURCC fccHandler;
00158 DWORD dwFlags;
00159 WORD wPriority;
00160 WORD wLanguage;
00161 DWORD dwInitialFrames;
00162 DWORD dwScale;
00163 DWORD dwRate;
00164 DWORD dwStart;
00165 DWORD dwLength;
00166 DWORD dwSuggestedBufferSize;
00167 DWORD dwQuality;
00168 DWORD dwSampleSize;
00169 RECT rcFrame;
00170 }
00171 PACKED(AVIStreamHeader);
00172
00173 typedef struct
00174 {
00175 DWORD dwDVAAuxSrc;
00176 DWORD dwDVAAuxCtl;
00177 DWORD dwDVAAuxSrc1;
00178 DWORD dwDVAAuxCtl1;
00179 DWORD dwDVVAuxSrc;
00180 DWORD dwDVVAuxCtl;
00181 DWORD dwDVReserved[ 2 ];
00182 }
00183 PACKED(DVINFO);
00184
00185 typedef struct
00186 {
00187 DWORD biSize;
00188 LONG biWidth;
00189 LONG biHeight;
00190 WORD biPlanes;
00191 WORD biBitCount;
00192 DWORD biCompression;
00193 DWORD biSizeImage;
00194 LONG biXPelsPerMeter;
00195 LONG biYPelsPerMeter;
00196 DWORD biClrUsed;
00197 DWORD biClrImportant;
00198 }
00199 PACKED(BITMAPINFOHEADER);
00200
00201 typedef struct
00202 {
00203 WORD wFormatTag;
00204 WORD nChannels;
00205 DWORD nSamplesPerSec;
00206 DWORD nAvgBytesPerSec;
00207 WORD nBlockAlign;
00208 WORD wBitsPerSample;
00209 WORD cbSize;
00210 WORD dummy;
00211 }
00212 PACKED(WAVEFORMATEX);
00213
00214 typedef struct
00215 {
00216 WORD wLongsPerEntry;
00217 BYTE bIndexSubType;
00218 BYTE bIndexType;
00219 DWORD nEntriesInUse;
00220 FOURCC dwChunkId;
00221 DWORD dwReserved[ 3 ];
00222 struct avisuperindex_entry
00223 {
00224 QUADWORD qwOffset;
00225 DWORD dwSize;
00226 DWORD dwDuration;
00227 }
00228 aIndex[ 2014 ];
00229 }
00230 PACKED(AVISuperIndex);
00231
00232 typedef struct
00233 {
00234 WORD wLongsPerEntry;
00235 BYTE bIndexSubType;
00236 BYTE bIndexType;
00237 DWORD nEntriesInUse;
00238 FOURCC dwChunkId;
00239 QUADWORD qwBaseOffset;
00240 DWORD dwReserved;
00241 struct avifieldindex_entry
00242 {
00243 DWORD dwOffset;
00244 DWORD dwSize;
00245 }
00246 aIndex[ 4028 ];
00247 }
00248 PACKED(AVIStdIndex);
00249
00250 typedef struct
00251 {
00252 struct avisimpleindex_entry
00253 {
00254 FOURCC dwChunkId;
00255 DWORD dwFlags;
00256 DWORD dwOffset;
00257 DWORD dwSize;
00258 }
00259 aIndex[ 20000 ];
00260 DWORD nEntriesInUse;
00261 }
00262 PACKED(AVISimpleIndex);
00263
00264 typedef struct
00265 {
00266 DWORD dirEntryType;
00267 DWORD dirEntryName;
00268 DWORD dirEntryLength;
00269 size_t dirEntryOffset;
00270 int dirEntryWrittenFlag;
00271 int dirEntryParentList;
00272 }
00273 AviDirEntry;
00274
00275
00283 class AVIFile : public RIFFFile
00284 {
00285 public:
00286 AVIFile();
00287 AVIFile( const AVIFile& );
00288 virtual ~AVIFile();
00289 virtual AVIFile& operator=( const AVIFile& );
00290
00291 virtual void Init( int format, int sampleFrequency, int indexType );
00292 virtual int GetDVFrameInfo( off_t &offset, int &size, int frameNum );
00293 virtual int GetFrameInfo( off_t &offset, int &size, int frameNum, FOURCC chunkID );
00294 virtual int GetDVFrame( Frame &frame, int frameNum );
00295 virtual int getFrame( void *data, int frameNum, FOURCC chunkID );
00296 virtual int GetTotalFrames() const;
00297 virtual void PrintDirectoryEntryData( const RIFFDirEntry &entry ) const;
00298 virtual bool WriteFrame( const Frame &frame )
00299 {
00300 return false;
00301 }
00302 virtual void ParseList( int parent );
00303 virtual void ParseRIFF( void );
00304 virtual void ReadIndex( void );
00305 virtual void WriteRIFF( void )
00306 { }
00307 virtual void FlushIndx( int stream );
00308 virtual void UpdateIndx( int stream, int chunk, int duration );
00309 virtual void UpdateIdx1( int chunk, int flags );
00310 virtual bool verifyStreamFormat( FOURCC type );
00311 virtual bool verifyStream( FOURCC type );
00312 virtual bool isOpenDML( void );
00313 virtual void setDVINFO( DVINFO& )
00314 { }
00315 virtual void setFccHandler( FOURCC type, FOURCC handler );
00316 virtual bool getStreamFormat( void* data, FOURCC type );
00317
00318 protected:
00319 MainAVIHeader mainHdr;
00320 AVISimpleIndex *idx1;
00321 int file_list;
00322 int riff_list;
00323 int hdrl_list;
00324 int avih_chunk;
00325 int movi_list;
00326 int junk_chunk;
00327 int idx1_chunk;
00328
00329 AVIStreamHeader streamHdr[ 2 ];
00330 AVISuperIndex *indx[ 2 ];
00331 AVIStdIndex *ix[ 2 ];
00332 int indx_chunk[ 2 ];
00333 int ix_chunk[ 2 ];
00334 int strl_list[ 2 ];
00335 int strh_chunk[ 2 ];
00336 int strf_chunk[ 2 ];
00337
00338 int index_type;
00339 int current_ix00;
00340
00341 DWORD dmlh[ 62 ];
00342 int odml_list;
00343 int dmlh_chunk;
00344 bool isUpdateIdx1;
00345
00346 };
00347
00348
00353 class AVI1File : public AVIFile
00354 {
00355 public:
00356 AVI1File();
00357 virtual ~AVI1File();
00358
00359 virtual void Init( int format, int sampleFrequency, int indexType );
00360 virtual bool WriteFrame( const Frame &frame );
00361 virtual void WriteRIFF( void );
00362 virtual void setDVINFO( DVINFO& );
00363
00364 private:
00365 DVINFO dvinfo;
00366
00367 AVI1File( const AVI1File& );
00368 AVI1File& operator=( const AVI1File& );
00369 };
00370
00371
00383 class AVI2File : public AVIFile
00384 {
00385 public:
00386 AVI2File();
00387 virtual ~AVI2File();
00388
00389 virtual void Init( int format, int sampleFrequency, int indexType );
00390 virtual bool WriteFrame( const Frame &frame );
00391 virtual void WriteRIFF( void );
00392 virtual void setDVINFO( DVINFO& );
00393
00394 private:
00395 BITMAPINFOHEADER bitmapinfo;
00396 WAVEFORMATEX waveformatex;
00397
00398 AVI2File( const AVI2File& );
00399 AVI2File& operator=( const AVI2File& );
00400 };
00401 #endif