avi.h

Go to the documentation of this file.
00001 /*
00002 * avi.h library for AVI file format i/o
00003 * Copyright (C) 2000 - 2002 Arne Schirmacher <arne@schirmacher.de>
00004 *
00005 * This program is free software; you can redistribute it and/or modify
00006 * it under the terms of the GNU General Public License as published by
00007 * the Free Software Foundation; either version 2 of the License, or
00008 * (at your option) any later version.
00009 *
00010 * This program is distributed in the hope that it will be useful,
00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 * GNU General Public License for more details.
00014 *
00015 * You should have received a copy of the GNU General Public License
00016 * along with this program; if not, write to the Free Software Foundation,
00017 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 *
00019 * Tag: $Name:  $
00020 *
00021 * Change log:
00022 * 
00023 * $Log: avi.h,v $
00024 * Revision 1.16  2005/04/01 23:43:10  ddennedy
00025 * apply endian fixes from Daniel Kobras
00026 *
00027 * Revision 1.15  2004/10/11 01:37:11  ddennedy
00028 * mutex safety locks in RIFF and AVI classes, type 2 AVI optimization, mencoder export script
00029 *
00030 * Revision 1.14  2003/11/25 23:00:52  ddennedy
00031 * cleanup and a few bugfixes
00032 *
00033 * Revision 1.13  2003/10/21 16:34:32  ddennedy
00034 * GNOME2 port phase 1: initial checkin
00035 *
00036 * Revision 1.11.2.5  2003/07/24 14:13:57  ddennedy
00037 * support for distinct audio stream in type2 AVI and Quicktime; support for more DV FOURCCs
00038 *
00039 * Revision 1.11.2.4  2003/06/10 23:53:36  ddennedy
00040 * Daniel Kobras' WriteFrame error handling and automatic OpenDML, bugfixes in scene list updates, export AV/C Record
00041 *
00042 * Revision 1.11.2.3  2003/02/20 21:59:57  ddennedy
00043 * bugfixes to capture and AVI
00044 *
00045 * Revision 1.11.2.2  2003/01/13 05:15:31  ddennedy
00046 * added More Info panel and supporting methods
00047 *
00048 * Revision 1.11.2.1  2002/11/25 04:48:31  ddennedy
00049 * bugfix to report errors when loading files
00050 *
00051 * Revision 1.11  2002/10/08 07:46:41  ddennedy
00052 * AVI bugfixes, compatibility, optimization, warn bad file in capture and export dv file, allow no mplex
00053 *
00054 * Revision 1.10  2002/05/17 08:04:25  ddennedy
00055 * revert const-ness of Frame references in Frame, FileHandler, and AVI classes
00056 *
00057 * Revision 1.9  2002/05/15 04:39:35  ddennedy
00058 * bugfixes to dv2 AVI write, audio export, Xv init
00059 *
00060 * Revision 1.8  2002/04/29 05:09:22  ddennedy
00061 * raw dv file support, Frame::ExtractAudio uses libdv, audioScrub prefs
00062 *
00063 * Revision 1.7  2002/04/09 06:53:42  ddennedy
00064 * cleanup, new libdv 0.9.5, large AVI, dnd storyboard
00065 *
00066 * Revision 1.7  2002/03/25 21:34:25  arne
00067 * Support for large (64 bit) files mostly completed
00068 *
00069 * Revision 1.6  2002/03/10 13:29:41  arne
00070 * more changes for 64 bit access
00071 *
00072 * Revision 1.5  2002/03/09 17:59:28  arne
00073 * moved index routines to AVIFile
00074 *
00075 * Revision 1.4  2002/03/09 10:26:26  arne
00076 * improved constructors and assignment operator
00077 *
00078 * Revision 1.3  2002/03/09 08:55:57  arne
00079 * moved a few variables to AVIFile
00080 *
00081 * Revision 1.2  2002/03/04 19:22:43  arne
00082 * updated to latest Kino avi code
00083 *
00084 * Revision 1.1.1.1  2002/03/03 19:08:08  arne
00085 * import of version 1.01
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;                /* Contains AVITF_* flags */
00159         WORD wPriority;
00160         WORD wLanguage;
00161         DWORD dwInitialFrames;
00162         DWORD dwScale;
00163         DWORD dwRate;                 /* dwRate / dwScale == samples/second */
00164         DWORD dwStart;
00165         DWORD dwLength;               /* In units above... */
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

Generated on Tue Jan 22 17:07:29 2008 for MUAN by  doxygen 1.4.7