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