home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / avifmt.h < prev    next >
C/C++ Source or Header  |  1998-04-25  |  9KB  |  252 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*        AVIFMT.H - Include file for working with AVI files                */
  4. /*                                                                          */
  5. /*        Note: You must include WINDOWS.H and MMSYSTEM.H before            */
  6. /*        including this file.                                              */
  7. /*                                                                          */
  8. /*        Copyright 1991 - 1998, Microsoft Corp.  All rights reserved.      */
  9. /*                                                                          */
  10. /*                                                                          */
  11. /****************************************************************************/
  12.  
  13. #ifndef _INC_AVIFMT
  14. #define _INC_AVIFMT    100    /* version number * 100 + revision */
  15.  
  16. #ifdef __cplusplus
  17. extern "C" {            /* Assume C declarations for C++ */
  18. #endif    /* __cplusplus */
  19.  
  20. // begin_vfw32
  21.  
  22. #ifdef _MSC_VER
  23. #pragma warning(disable:4200)
  24. #endif
  25.  
  26. /* The following is a short description of the AVI file format.  Please
  27.  * see the accompanying documentation for a full explanation.
  28.  *
  29.  * An AVI file is the following RIFF form:
  30.  *
  31.  *    RIFF('AVI'
  32.  *          LIST('hdrl'
  33.  *            avih(<MainAVIHeader>)
  34.  *                  LIST ('strl'
  35.  *                      strh(<Stream header>)
  36.  *                      strf(<Stream format>)
  37.  *                      ... additional header data
  38.  *            LIST('movi'    
  39.  *            { LIST('rec'
  40.  *                    SubChunk...
  41.  *                 )
  42.  *                | SubChunk } ....    
  43.  *            )
  44.  *            [ <AVIIndex> ]
  45.  *      )
  46.  *
  47.  *    The main file header specifies how many streams are present.  For
  48.  *    each one, there must be a stream header chunk and a stream format
  49.  *    chunk, enlosed in a 'strl' LIST chunk.  The 'strf' chunk contains
  50.  *    type-specific format information; for a video stream, this should
  51.  *    be a BITMAPINFO structure, including palette.  For an audio stream,
  52.  *    this should be a WAVEFORMAT (or PCMWAVEFORMAT) structure.
  53.  *
  54.  *    The actual data is contained in subchunks within the 'movi' LIST
  55.  *    chunk.  The first two characters of each data chunk are the
  56.  *    stream number with which that data is associated.
  57.  *
  58.  *    Some defined chunk types:
  59.  *           Video Streams:
  60.  *                  ##db:    RGB DIB bits
  61.  *                  ##dc:    RLE8 compressed DIB bits
  62.  *                  ##pc:    Palette Change
  63.  *
  64.  *           Audio Streams:
  65.  *                  ##wb:    waveform audio bytes
  66.  *
  67.  * The grouping into LIST 'rec' chunks implies only that the contents of
  68.  *   the chunk should be read into memory at the same time.  This
  69.  *   grouping is used for files specifically intended to be played from
  70.  *   CD-ROM.
  71.  *
  72.  * The index chunk at the end of the file should contain one entry for
  73.  *   each data chunk in the file.
  74.  *
  75.  * Limitations for the current software:
  76.  *    Only one video stream and one audio stream are allowed.
  77.  *    The streams must start at the beginning of the file.
  78.  *
  79.  *
  80.  * To register codec types please obtain a copy of the Multimedia
  81.  * Developer Registration Kit from:
  82.  *
  83.  *  Microsoft Corporation
  84.  *  Multimedia Systems Group
  85.  *  Product Marketing
  86.  *  One Microsoft Way
  87.  *  Redmond, WA 98052-6399
  88.  *
  89.  */
  90.  
  91. #ifndef mmioFOURCC
  92. #define mmioFOURCC( ch0, ch1, ch2, ch3 )                \
  93.         ( (DWORD)(BYTE)(ch0) | ( (DWORD)(BYTE)(ch1) << 8 ) |    \
  94.         ( (DWORD)(BYTE)(ch2) << 16 ) | ( (DWORD)(BYTE)(ch3) << 24 ) )
  95. #endif
  96.  
  97. /* Macro to make a TWOCC out of two characters */
  98. #ifndef aviTWOCC
  99. #define aviTWOCC(ch0, ch1) ((WORD)(BYTE)(ch0) | ((WORD)(BYTE)(ch1) << 8))
  100. #endif
  101.  
  102. typedef WORD TWOCC;
  103.  
  104. /* form types, list types, and chunk types */
  105. #define formtypeAVI             mmioFOURCC('A', 'V', 'I', ' ')
  106. #define listtypeAVIHEADER       mmioFOURCC('h', 'd', 'r', 'l')
  107. #define ckidAVIMAINHDR          mmioFOURCC('a', 'v', 'i', 'h')
  108. #define listtypeSTREAMHEADER    mmioFOURCC('s', 't', 'r', 'l')
  109. #define ckidSTREAMHEADER        mmioFOURCC('s', 't', 'r', 'h')
  110. #define ckidSTREAMFORMAT        mmioFOURCC('s', 't', 'r', 'f')
  111. #define ckidSTREAMHANDLERDATA   mmioFOURCC('s', 't', 'r', 'd')
  112. #define ckidSTREAMNAME        mmioFOURCC('s', 't', 'r', 'n')
  113.  
  114. #define listtypeAVIMOVIE        mmioFOURCC('m', 'o', 'v', 'i')
  115. #define listtypeAVIRECORD       mmioFOURCC('r', 'e', 'c', ' ')
  116.  
  117. #define ckidAVINEWINDEX         mmioFOURCC('i', 'd', 'x', '1')
  118.  
  119. /*
  120. ** Stream types for the <fccType> field of the stream header.
  121. */
  122. #define streamtypeVIDEO         mmioFOURCC('v', 'i', 'd', 's')
  123. #define streamtypeAUDIO         mmioFOURCC('a', 'u', 'd', 's')
  124. #define streamtypeMIDI        mmioFOURCC('m', 'i', 'd', 's')
  125. #define streamtypeTEXT          mmioFOURCC('t', 'x', 't', 's')
  126.  
  127. /* Basic chunk types */
  128. #define cktypeDIBbits           aviTWOCC('d', 'b')
  129. #define cktypeDIBcompressed     aviTWOCC('d', 'c')
  130. #define cktypePALchange         aviTWOCC('p', 'c')
  131. #define cktypeWAVEbytes         aviTWOCC('w', 'b')
  132.  
  133. /* Chunk id to use for extra chunks for padding. */
  134. #define ckidAVIPADDING          mmioFOURCC('J', 'U', 'N', 'K')
  135.  
  136. /*
  137. ** Useful macros
  138. **
  139. ** Warning: These are nasty macro, and MS C 6.0 compiles some of them
  140. ** incorrectly if optimizations are on.  Ack.
  141. */
  142.  
  143. /* Macro to get stream number out of a FOURCC ckid */
  144. #define FromHex(n)    (((n) >= 'A') ? ((n) + 10 - 'A') : ((n) - '0'))
  145. #define StreamFromFOURCC(fcc) ((WORD) ((FromHex(LOBYTE(LOWORD(fcc))) << 4) + \
  146.                                              (FromHex(HIBYTE(LOWORD(fcc))))))
  147.  
  148. /* Macro to get TWOCC chunk type out of a FOURCC ckid */
  149. #define TWOCCFromFOURCC(fcc)    HIWORD(fcc)
  150.  
  151. /* Macro to make a ckid for a chunk out of a TWOCC and a stream number
  152. ** from 0-255.
  153. */
  154. #define ToHex(n)    ((BYTE) (((n) > 9) ? ((n) - 10 + 'A') : ((n) + '0')))
  155. #define MAKEAVICKID(tcc, stream) \
  156.         MAKELONG((ToHex((stream) & 0x0f) << 8) | \
  157.                 (ToHex(((stream) & 0xf0) >> 4)), tcc)
  158.  
  159. /*
  160. ** Main AVI File Header
  161. */    
  162.         
  163. /* flags for use in <dwFlags> in AVIFileHdr */
  164. #define AVIF_HASINDEX        0x00000010    // Index at end of file
  165. #define AVIF_MUSTUSEINDEX    0x00000020
  166. #define AVIF_ISINTERLEAVED    0x00000100
  167. #define AVIF_TRUSTCKTYPE    0x00000800    // Use CKType to find key frames
  168. #define AVIF_WASCAPTUREFILE    0x00010000
  169. #define AVIF_COPYRIGHTED    0x00020000
  170.  
  171. /* The AVI File Header LIST chunk should be padded to this size */
  172. #define AVI_HEADERSIZE  2048                    // size of AVI header list
  173.  
  174. typedef struct
  175. {
  176.     DWORD        dwMicroSecPerFrame;    // frame display rate (or 0L)
  177.     DWORD        dwMaxBytesPerSec;    // max. transfer rate
  178.     DWORD        dwPaddingGranularity;    // pad to multiples of this
  179.                                                 // size; normally 2K.
  180.     DWORD        dwFlags;        // the ever-present flags
  181.     DWORD        dwTotalFrames;        // # frames in file
  182.     DWORD        dwInitialFrames;
  183.     DWORD        dwStreams;
  184.     DWORD        dwSuggestedBufferSize;
  185.  
  186.     DWORD        dwWidth;
  187.     DWORD        dwHeight;
  188.  
  189.     DWORD        dwReserved[4];
  190. } MainAVIHeader;
  191.  
  192. /*
  193. ** Stream header
  194. */
  195.  
  196. #define AVISF_DISABLED            0x00000001
  197.  
  198. #define AVISF_VIDEO_PALCHANGES        0x00010000
  199.  
  200. typedef struct {
  201.     FOURCC        fccType;
  202.     FOURCC        fccHandler;
  203.     DWORD        dwFlags;    /* Contains AVITF_* flags */
  204.     WORD        wPriority;
  205.     WORD        wLanguage;
  206.     DWORD        dwInitialFrames;
  207.     DWORD        dwScale;    
  208.     DWORD        dwRate;    /* dwRate / dwScale == samples/second */
  209.     DWORD        dwStart;
  210.     DWORD        dwLength; /* In units above... */
  211.     DWORD        dwSuggestedBufferSize;
  212.     DWORD        dwQuality;
  213.     DWORD        dwSampleSize;
  214.     RECT        rcFrame;
  215. } AVIStreamHeader;
  216.  
  217. /* Flags for index */
  218. #define AVIIF_LIST          0x00000001L // chunk is a 'LIST'
  219. #define AVIIF_KEYFRAME      0x00000010L // this frame is a key frame.
  220.  
  221. #define AVIIF_NOTIME        0x00000100L // this frame doesn't take any time
  222. #define AVIIF_COMPUSE       0x0FFF0000L // these bits are for compressor use
  223.  
  224. typedef struct
  225. {
  226.     DWORD        ckid;
  227.     DWORD        dwFlags;
  228.     DWORD        dwChunkOffset;        // Position of chunk
  229.     DWORD        dwChunkLength;        // Length of chunk
  230. } AVIINDEXENTRY;
  231.  
  232. /*
  233. ** Palette change chunk
  234. **
  235. ** Used in video streams.
  236. */
  237. typedef struct
  238. {
  239.     BYTE        bFirstEntry;    /* first entry to change */
  240.     BYTE        bNumEntries;    /* # entries to change (0 if 256) */
  241.     WORD        wFlags;        /* Mostly to preserve alignment... */
  242.     PALETTEENTRY    peNew[];    /* New color specifications */
  243. } AVIPALCHANGE;
  244.  
  245. // end_vfw32
  246.  
  247. #ifdef __cplusplus
  248. }                       /* End of extern "C" { */
  249. #endif    /* __cplusplus */
  250.  
  251. #endif /* _INC_AVIFMT */
  252.