home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / mac / SiteBldr / AMOVIE / SDK / _SETUP / COMMON.Z / aviriff.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-16  |  12.2 KB  |  373 lines

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