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

  1. //==========================================================================;
  2. //
  3. //  Copyright (c) 1996 - 1997  Microsoft Corporation.  All Rights Reserved.
  4. //
  5. //--------------------------------------------------------------------------;
  6. #pragma warning(disable: 4097 4511 4512 4514 4705)
  7.  
  8. /*+
  9.  *
  10.  * Structures and defines for the RIFF AVI file format extended to
  11.  * handle very large/long files
  12.  *
  13.  *-=====================================================================*/
  14.  
  15. #if !defined AVIRIFF_H
  16. #define AVIRIFF_H
  17.  
  18. #if !defined NUMELMS
  19.   #define NUMELMS(aa) (sizeof(aa)/sizeof((aa)[0]))
  20. #endif
  21.  
  22. // all structures in this file are packed on word boundaries
  23. //
  24. #include <pshpack2.h>
  25.  
  26. /*
  27.  * heres the general layout of an AVI riff file (new format)
  28.  *
  29.  * RIFF (3F??????) AVI       <- not more than 1 GB in size
  30.  *     LIST (size) hdrl
  31.  *         avih (0038)
  32.  *         LIST (size) strl
  33.  *             strh (0038)
  34.  *             strf (????)
  35.  *             indx (3ff8)   <- size may vary, should be sector sized
  36.  *         LIST (size) strl
  37.  *             strh (0038)
  38.  *             strf (????)
  39.  *             indx (3ff8)   <- size may vary, should be sector sized
  40.  *         LIST (size) odml
  41.  *             dmlh (????)
  42.  *         JUNK (size)       <- fill to align to sector - 12
  43.  *     LIST (7f??????) movi  <- aligned on sector - 12
  44.  *         00dc (size)       <- sector aligned
  45.  *         01wb (size)       <- sector aligned
  46.  *         ix00 (size)       <- sector aligned
  47.  *     idx1 (00??????)       <- sector aligned
  48.  * RIFF (7F??????) AVIX
  49.  *     JUNK (size)           <- fill to align to sector -12
  50.  *     LIST (size) movi
  51.  *         00dc (size)       <- sector aligned
  52.  * RIFF (7F??????) AVIX      <- not more than 2GB in size
  53.  *     JUNK (size)           <- fill to align to sector - 12
  54.  *     LIST (size) movi
  55.  *         00dc (size)       <- sector aligned
  56.  *
  57.  *-===================================================================*/
  58.  
  59. //
  60. // structures for manipulating RIFF headers
  61. //
  62. #define FCC(ch4) ((((DWORD)(ch4) & 0xFF) << 24) |     \
  63.                   (((DWORD)(ch4) & 0xFF00) << 8) |    \
  64.                   (((DWORD)(ch4) & 0xFF0000) >> 8) |  \
  65.                   (((DWORD)(ch4) & 0xFF000000) >> 24))
  66.  
  67. typedef struct _riffchunk {
  68.    FOURCC fcc;
  69.    DWORD  cb;
  70.    } RIFFCHUNK, * LPRIFFCHUNK;
  71. typedef struct _rifflist {
  72.    FOURCC fcc;
  73.    DWORD  cb;
  74.    FOURCC fccListType;
  75.    } RIFFLIST, * LPRIFFLIST;
  76.  
  77. #define RIFFROUND(cb) ((cb) + ((cb)&1))
  78. #define RIFFNEXT(pChunk) (LPRIFFCHUNK)((LPBYTE)(pChunk) \
  79.                           + sizeof(RIFFCHUNK) \
  80.                           + RIFFROUND(((LPRIFFCHUNK)pChunk)->cb))
  81.  
  82.  
  83. //
  84. // ==================== avi header structures ===========================
  85. //
  86.  
  87. // main header for the avi file (compatibility header)
  88. //
  89. #define ckidMAINAVIHEADER FCC('avih')
  90. typedef struct _avimainheader {
  91.     FOURCC fcc;                    // 'avih'
  92.     DWORD  cb;                     // size of this structure -8
  93.     DWORD  dwMicroSecPerFrame;     // frame display rate (or 0L)
  94.     DWORD  dwMaxBytesPerSec;       // max. transfer rate
  95.     DWORD  dwPaddingGranularity;   // pad to multiples of this size; normally 2K.
  96.     DWORD  dwFlags;                // the ever-present flags
  97.     #define AVIF_HASINDEX        0x00000010 // Index at end of file?
  98.     #define AVIF_MUSTUSEINDEX    0x00000020
  99.     #define AVIF_ISINTERLEAVED   0x00000100
  100.     #define AVIF_TRUSTCKTYPE     0x00000800 // Use CKType to find key frames
  101.     #define AVIF_WASCAPTUREFILE  0x00010000
  102.     #define AVIF_COPYRIGHTED     0x00020000
  103.     DWORD  dwTotalFrames;          // # frames in first movi list
  104.     DWORD  dwInitialFrames;
  105.     DWORD  dwStreams;
  106.     DWORD  dwSuggestedBufferSize;
  107.     DWORD  dwWidth;
  108.     DWORD  dwHeight;
  109.     DWORD  dwReserved[4];
  110.     } AVIMAINHEADER;
  111.  
  112. #define ckidODML          FCC('odml')
  113. #define ckidAVIEXTHEADER  FCC('dmlh')
  114. typedef struct _aviextheader {
  115.    FOURCC  fcc;                    // 'dmlh'
  116.    DWORD   cb;                     // size of this structure -8
  117.    DWORD   dwGrandFrames;          // total number of frames in the file
  118.    DWORD   dwFuture[61];           // to be defined later
  119.    } AVIEXTHEADER;
  120.  
  121. //
  122. // structure of an AVI stream header riff chunk
  123. //
  124. #define ckidSTREAMLIST   FCC('strl')
  125.  
  126. #ifndef ckidSTREAMHEADER
  127. #define ckidSTREAMHEADER FCC('strh')
  128. #endif
  129. typedef struct _avistreamheader {
  130.    FOURCC fcc;          // 'strh'
  131.    DWORD  cb;           // size of this structure - 8
  132.  
  133.    FOURCC fccType;      // stream type codes
  134.  
  135.    #ifndef streamtypeVIDEO
  136.    #define streamtypeVIDEO FCC('vids')
  137.    #define streamtypeAUDIO FCC('auds')
  138.    #define streamtypeMIDI  FCC('mids')
  139.    #define streamtypeTEXT  FCC('txts')
  140.    #endif
  141.  
  142.    FOURCC fccHandler;
  143.    DWORD  dwFlags;
  144.    #define AVISF_DISABLED          0x00000001
  145.    #define AVISF_VIDEO_PALCHANGES  0x00010000
  146.  
  147.    WORD   wPriority;
  148.    WORD   wLanguage;
  149.    DWORD  dwInitialFrames;
  150.    DWORD  dwScale;
  151.    DWORD  dwRate;       // dwRate/dwScale is stream tick rate in ticks/sec
  152.    DWORD  dwStart;
  153.    DWORD  dwLength;
  154.    DWORD  dwSuggestedBufferSize;
  155.    DWORD  dwQuality;
  156.    DWORD  dwSampleSize;
  157.    struct {
  158.       short int left;
  159.       short int top;
  160.       short int right;
  161.       short int bottom;
  162.       }   rcFrame;
  163.    } AVISTREAMHEADER;
  164.  
  165.  
  166. //
  167. // structure of an AVI stream format chunk
  168. //
  169. #ifndef ckidSTREAMFORMAT
  170. #define ckidSTREAMFORMAT FCC('strf')
  171. #endif
  172. //
  173. // avi stream formats are different for each stream type
  174. //
  175. // BITMAPINFOHEADER for video streams
  176. // WAVEFORMATEX or PCMWAVEFORMAT for audio streams
  177. // nothing for text streams
  178. // nothing for midi streams
  179.  
  180.  
  181. #pragma warning(disable:4200)
  182. //
  183. // structure of old style AVI index
  184. //
  185. #define ckidAVIOLDINDEX FCC('idx1')
  186. typedef struct _avioldindex {
  187.    FOURCC  fcc;        // 'idx1'
  188.    DWORD   cb;         // size of this structure -8
  189.    struct _avioldindex_entry {
  190.       DWORD   dwChunkId;
  191.       DWORD   dwFlags;
  192.  
  193.       #ifndef AVIIF_LIST
  194.       #define AVIIF_LIST       0x00000001
  195.       #define AVIIF_KEYFRAME   0x00000010
  196.       #endif
  197.      
  198.       #define AVIIF_NO_TIME    0x00000100
  199.       #define AVIIF_COMPRESSOR 0x0FFF0000  // unused?
  200.       DWORD   dwOffset;    // offset of riff chunk header for the data
  201.       DWORD   dwSize;      // size of the data (excluding riff header size)
  202.       } aIndex[];          // size of this array
  203.    } AVIOLDINDEX;
  204.  
  205.  
  206. //
  207. // ============ structures for timecode in an AVI file =================
  208. //
  209.  
  210. #ifndef TIMECODE_DEFINED
  211. #define TIMECODE_DEFINED
  212.  
  213. // defined
  214. // timecode time structure
  215. //
  216. typedef union _timecode {
  217.    struct {
  218.       WORD   wFrameRate;
  219.       WORD   wFrameFract;
  220.       LONG   cFrames;
  221.       };
  222.    DWORDLONG  qw;
  223.    } TIMECODE;
  224.  
  225. #endif // TIMECODE_DEFINED
  226.  
  227. #define TIMECODE_RATE_30DROP 0   // this MUST be zero
  228.  
  229. // struct for all the SMPTE timecode info
  230. //
  231. typedef struct _timecodedata {
  232.    TIMECODE time;
  233.    DWORD    dwSMPTEflags;
  234.    DWORD    dwUser;
  235.    } TIMECODEDATA;
  236.  
  237. // dwSMPTEflags masks/values
  238. //
  239. #define TIMECODE_SMPTE_BINARY_GROUP 0x07
  240. #define TIMECODE_SMPTE_COLOR_FRAME  0x08
  241.  
  242. //
  243. // ============ structures for new style AVI indexes =================
  244. //
  245.  
  246. // index type codes
  247. //
  248. #define AVI_INDEX_OF_INDEXES       0x00
  249. #define AVI_INDEX_OF_CHUNKS        0x01
  250. #define AVI_INDEX_OF_TIMED_CHUNKS  0x02
  251. #define AVI_INDEX_OF_SUB_2FIELD    0x03
  252. #define AVI_INDEX_IS_DATA          0x80
  253.  
  254. // index subtype codes
  255. //
  256. #define AVI_INDEX_SUB_DEFAULT     0x00
  257.  
  258. // INDEX_OF_CHUNKS subtype codes
  259. //
  260. #define AVI_INDEX_SUB_2FIELD      0x01
  261.  
  262. // meta structure of all avi indexes
  263. //
  264. typedef struct _avimetaindex {
  265.    FOURCC fcc;
  266.    UINT   cb;
  267.    WORD   wLongsPerEntry;
  268.    BYTE   bIndexSubType;
  269.    BYTE   bIndexType;
  270.    DWORD  nEntriesInUse;
  271.    DWORD  dwChunkId;
  272.    DWORD  dwReserved[3];
  273.    DWORD  adwIndex[];
  274.    } AVIMETAINDEX;
  275.  
  276. #define STDINDEXSIZE 0x4000
  277. #define NUMINDEX(wLongsPerEntry) ((STDINDEXSIZE-32)/4/(wLongsPerEntry))
  278. #define NUMINDEXFILL(wLongsPerEntry) ((STDINDEXSIZE/4) - NUMINDEX(wLongsPerEntry))
  279.  
  280. // structure of a super index (INDEX_OF_INDEXES)
  281. //
  282. #define ckidAVISUPERINDEX FCC('indx')
  283. typedef struct _avisuperindex {
  284.    FOURCC   fcc;               // 'indx'
  285.    UINT     cb;                // size of this structure
  286.    WORD     wLongsPerEntry;    // ==4
  287.    BYTE     bIndexSubType;     // ==0 (frame index) or AVI_INDEX_SUB_2FIELD 
  288.    BYTE     bIndexType;        // ==AVI_INDEX_OF_INDEXES
  289.    DWORD    nEntriesInUse;     // offset of next unused entry in aIndex
  290.    DWORD    dwChunkId;         // chunk ID of chunks being indexed, (i.e. RGB8)
  291.    DWORD    dwReserved[3];     // must be 0
  292.    struct _avisuperindex_entry {
  293.       DWORDLONG qwOffset;    // 64 bit offset to sub index chunk
  294.       DWORD    dwSize;       // 32 bit size of sub index chunk
  295.       DWORD    dwDuration;   // time span of subindex chunk (in stream ticks)
  296.       } aIndex[NUMINDEX(4)];
  297.    } AVISUPERINDEX;
  298. #define Valid_SUPERINDEX(pi) (*(DWORD *)(&((pi)->wLongsPerEntry)) == (4 | (AVI_INDEX_OF_INDEXES << 24)))
  299.  
  300. // struct of a standard index (AVI_INDEX_OF_CHUNKS)
  301. //
  302. typedef struct _avistdindex_entry {
  303.    DWORD dwOffset;       // 32 bit offset to data (points to data, not riff header)
  304.    DWORD dwSize;         // 31 bit size of data (does not include size of riff header), bit 31 is deltaframe bit
  305.    } AVISTDINDEX_ENTRY;
  306. #define AVISTDINDEX_DELTAFRAME ( 0x80000000) // Delta frames have the high bit set
  307. #define AVISTDINDEX_SIZEMASK   (~0x80000000)
  308.  
  309. typedef struct _avistdindex {
  310.    FOURCC   fcc;               // 'indx' or '##ix'
  311.    UINT     cb;                // size of this structure
  312.    WORD     wLongsPerEntry;    // ==2
  313.    BYTE     bIndexSubType;     // ==0
  314.    BYTE     bIndexType;        // ==AVI_INDEX_OF_CHUNKS
  315.    DWORD    nEntriesInUse;     // offset of next unused entry in aIndex
  316.    DWORD    dwChunkId;         // chunk ID of chunks being indexed, (i.e. RGB8)
  317.    DWORDLONG qwBaseOffset;     // base offset that all index intries are relative to
  318.    DWORD    dwReserved_3;      // must be 0
  319.    AVISTDINDEX_ENTRY aIndex[NUMINDEX(2)];
  320.    } AVISTDINDEX;
  321.  
  322. // struct of a time variant standard index (AVI_INDEX_OF_TIMED_CHUNKS)
  323. //
  324. typedef struct _avitimedindex_entry {
  325.    DWORD dwOffset;       // 32 bit offset to data (points to data, not riff header)
  326.    DWORD dwSize;         // 31 bit size of data (does not include size of riff header) (high bit is deltaframe bit)
  327.    DWORD dwDuration;     // how much time the chunk should be played (in stream ticks)
  328.    } AVITIMEDINDEX_ENTRY;
  329.  
  330. typedef struct _avitimedindex {
  331.    FOURCC   fcc;               // 'indx' or '##ix'
  332.    UINT     cb;                // size of this structure
  333.    WORD     wLongsPerEntry;    // ==3
  334.    BYTE     bIndexSubType;     // ==0
  335.    BYTE     bIndexType;        // ==AVI_INDEX_OF_TIMED_CHUNKS
  336.    DWORD    nEntriesInUse;     // offset of next unused entry in aIndex
  337.    DWORD    dwChunkId;         // chunk ID of chunks being indexed, (i.e. RGB8)
  338.    DWORDLONG qwBaseOffset;     // base offset that all index intries are relative to
  339.    DWORD    dwReserved_3;      // must be 0
  340.    AVITIMEDINDEX_ENTRY aIndex[NUMINDEX(3)];
  341.    DWORD adwTrailingFill[NUMINDEXFILL(3)]; // to align struct to correct size
  342.    } AVITIMEDINDEX;
  343.  
  344. // structure of a timecode stream
  345. //
  346. typedef struct _avitimecodeindex {
  347.    FOURCC   fcc;               // 'indx' or '##ix'
  348.    UINT     cb;                // size of this structure
  349.    WORD     wLongsPerEntry;    // ==4
  350.    BYTE     bIndexSubType;     // ==0
  351.    BYTE     bIndexType;        // ==AVI_INDEX_IS_DATA
  352.    DWORD    nEntriesInUse;     // offset of next unused entry in aIndex
  353.    DWORD    dwChunkId;         // 'time'
  354.    DWORD    dwReserved[3];     // must be 0
  355.    TIMECODEDATA aIndex[NUMINDEX(sizeof(TIMECODEDATA)/sizeof(LONG))];
  356.    } AVITIMECODEINDEX;
  357.  
  358. // structure of a timecode discontinuity list (when wLongsPerEntry == 7)
  359. //
  360. typedef struct _avitcdlindex_entry {
  361.     DWORD    dwTick;           // stream tick time that maps to this timecode value
  362.     TIMECODE time;
  363.     DWORD    dwSMPTEflags;
  364.     DWORD    dwUser;
  365.     TCHAR    szReelId[12];
  366.     } AVITCDLINDEX_ENTRY;
  367.  
  368. typedef struct _avitcdlindex {
  369.    FOURCC   fcc;               // 'indx' or '##ix'
  370.    UINT     cb;                // size of this structure
  371.    WORD     wLongsPerEntry;    // ==7 (must be 4 or more all 'tcdl' indexes
  372.    BYTE     bIndexSubType;     // ==0
  373.    BYTE     bIndexType;        // ==AVI_INDEX_IS_DATA
  374.    DWORD    nEntriesInUse;     // offset of next unused entry in aIndex
  375.    DWORD    dwChunkId;         // 'tcdl'
  376.    DWORD    dwReserved[3];     // must be 0
  377.    AVITCDLINDEX_ENTRY aIndex[NUMINDEX(7)];
  378.    DWORD adwTrailingFill[NUMINDEXFILL(7)]; // to align struct to correct size
  379.    } AVITCDLINDEX;
  380.  
  381. typedef struct _avifieldindex_chunk {
  382.    FOURCC   fcc;               // 'ix##'
  383.    DWORD    cb;                // size of this structure
  384.    WORD     wLongsPerEntry;    // must be 3 (size of each entry in
  385.                                // aIndex array)
  386.    BYTE     bIndexSubType;     // AVI_INDEX_2FIELD
  387.    BYTE     bIndexType;        // AVI_INDEX_OF_CHUNKS
  388.    DWORD    nEntriesInUse;     //
  389.    DWORD    dwChunkId;         // '##dc' or '##db'
  390.    DWORDLONG qwBaseOffset;     // offsets in aIndex array are relative to this
  391.    DWORD    dwReserved3;       // must be 0
  392.    struct _avifieldindex_entry {
  393.       DWORD    dwOffset;
  394.       DWORD    dwSize;         // size of all fields
  395.                                // (bit 31 set for NON-keyframes)
  396.       DWORD    dwOffsetField2; // offset to second field
  397.    } aIndex[  ];
  398. } AVIFIELDINDEX, * PAVIFIELDINDEX;
  399.  
  400.  
  401. #include <poppack.h>
  402.  
  403. #endif
  404.