Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

529 lines
20 KiB

  1. /****************************************************************************/
  2. /* */
  3. /* AVIFFMT.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-1992, Microsoft Corp. All rights reserved. */
  9. /* */
  10. /****************************************************************************/
  11. /*
  12. *
  13. * An AVI file is the following RIFF form:
  14. *
  15. * RIFF('AVI'
  16. * LIST('hdrl'
  17. * avih(<MainAVIHeader>)
  18. * LIST ('strl'
  19. * strh(<Stream header>)
  20. * strf(<Stream format>)
  21. * ... additional header data
  22. * LIST('movi'
  23. * { LIST('rec'
  24. * SubChunk...
  25. * )
  26. * | SubChunk } ....
  27. * )
  28. * [ <AVIIndex> ]
  29. * )
  30. *
  31. * The first two characters of each chunk are the track number.
  32. * SubChunk = { xxdh(<AVI DIB header>)
  33. * | xxdb(<AVI DIB bits>)
  34. * | xxdc(<AVI compressed DIB bits>)
  35. * | xxpc(<AVI Palette Change>)
  36. * | xxwb(<AVI WAVE bytes>)
  37. * | xxws(<AVI Silence record>)
  38. * | xxmd(<MIDI data>)
  39. * | additional custom chunks }
  40. *
  41. */
  42. /*
  43. * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  44. * We need a better description of the AVI file header here.
  45. * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  46. *
  47. * The grouping into LIST 'rec' chunks implies only that the contents of
  48. * the chunk should be read into memory at the same time. This
  49. * grouping is only necessary for interleaved files.
  50. *
  51. * For loading efficiency, the beginning of each LIST 'rec' chunk may
  52. * be aligned on a 2K boundary. (Actually, the beginning of the LIST
  53. * chunk should be 12 bytes before a 2K boundary, so that the data chunks
  54. * inside the LIST chunk are aligned.)
  55. *
  56. * If the AVI file is being played from CD-ROM in, it is recommended that
  57. * the file be padded.
  58. *
  59. * Limitations for the Alpha release:
  60. * If the AVI file has audio, each record LIST must contain exactly
  61. * one audio chunk, which must be the first chunk.
  62. * Each record must contain exactly one video chunk (possibly preceded
  63. * by one or more palette change chunks).
  64. * No wave format or DIB header chunks may occur outside of the header.
  65. */
  66. #ifndef _INC_AVIFFMT
  67. #define _INC_AVIFFMT
  68. #ifndef RC_INVOKED
  69. #pragma pack(1) /* Assume byte packing throughout */
  70. #endif /* RC_INVOKED */
  71. #ifndef mmioFOURCC
  72. #define mmioFOURCC( ch0, ch1, ch2, ch3 ) \
  73. ( (DWORD)(BYTE)(ch0) | ( (DWORD)(BYTE)(ch1) << 8 ) | \
  74. ( (DWORD)(BYTE)(ch2) << 16 ) | ( (DWORD)(BYTE)(ch3) << 24 ) )
  75. #endif
  76. /* Macro to make a TWOCC out of two characters */
  77. #ifndef aviTWOCC
  78. #define aviTWOCC(ch0, ch1) ((WORD)(BYTE)(ch0) | ((WORD)(BYTE)(ch1) << 8))
  79. #endif
  80. typedef WORD TWOCC;
  81. /* form types, list types, and chunk types */
  82. #define formtypeAVI mmioFOURCC('A', 'V', 'I', ' ')
  83. #define listtypeAVIHEADER mmioFOURCC('h', 'd', 'r', 'l')
  84. #define ckidAVIMAINHDR mmioFOURCC('a', 'v', 'i', 'h')
  85. #define listtypeSTREAMHEADER mmioFOURCC('s', 't', 'r', 'l')
  86. #define ckidSTREAMHEADER mmioFOURCC('s', 't', 'r', 'h')
  87. #define ckidSTREAMFORMAT mmioFOURCC('s', 't', 'r', 'f')
  88. #define ckidSTREAMHANDLERDATA mmioFOURCC('s', 't', 'r', 'd')
  89. #define listtypeAVIMOVIE mmioFOURCC('m', 'o', 'v', 'i')
  90. #define listtypeAVIRECORD mmioFOURCC('r', 'e', 'c', ' ')
  91. #define ckidAVINEWINDEX mmioFOURCC('i', 'd', 'x', '1')
  92. /*
  93. ** Here are some stream types. Currently, only audio and video
  94. ** are supported.
  95. */
  96. #define streamtypeVIDEO mmioFOURCC('v', 'i', 'd', 's')
  97. #define streamtypeAUDIO mmioFOURCC('a', 'u', 'd', 's')
  98. #define streamtypeMIDI mmioFOURCC('m', 'i', 'd', 's')
  99. #define streamtypeTEXT mmioFOURCC('t', 'x', 't', 's')
  100. /*
  101. ** Here are some compression types.
  102. */
  103. #define comptypeRLE0 mmioFOURCC('R','L','E','0')
  104. #define comptypeRLE mmioFOURCC('R','L','E',' ')
  105. #define comptypeDIB mmioFOURCC('D','I','B',' ')
  106. #define cktypeDIBbits aviTWOCC('d', 'b')
  107. #define cktypeDIBcompressed aviTWOCC('d', 'c')
  108. #define cktypeDIBhalf aviTWOCC('d', 'x')
  109. #define cktypePALchange aviTWOCC('p', 'c')
  110. #define cktypeWAVEbytes aviTWOCC('w', 'b')
  111. #define cktypeWAVEsilence aviTWOCC('w', 's')
  112. #define cktypeMIDIdata aviTWOCC('m', 'd')
  113. #define cktypeDIBheader aviTWOCC('d', 'h')
  114. #define cktypeWAVEformat aviTWOCC('w', 'f')
  115. #define ckidAVIPADDING mmioFOURCC('J', 'U', 'N', 'K')
  116. #define ckidOLDPADDING mmioFOURCC('p', 'a', 'd', 'd')
  117. /*
  118. ** Useful macros
  119. */
  120. #define ToHex(n) ((BYTE) (((n) > 9) ? ((n) - 10 + 'A') : ((n) + '0')))
  121. #define FromHex(n) (((n) >= 'A') ? ((n) + 10 - 'A') : ((n) - '0'))
  122. /* Macro to get stream number out of a FOURCC ckid */
  123. #define StreamFromFOURCC(fcc) ((WORD) ((FromHex(LOBYTE(LOWORD(fcc))) << 4) + \
  124. (FromHex(HIBYTE(LOWORD(fcc))))))
  125. /* Macro to get TWOCC chunk type out of a FOURCC ckid */
  126. #define TWOCCFromFOURCC(fcc) HIWORD(fcc)
  127. /* Macro to make a ckid for a chunk out of a TWOCC and a stream number
  128. ** from 0-255.
  129. **
  130. ** Warning: This is a nasty macro, and MS C 6.0 compiles it incorrectly
  131. ** if optimizations are on. Ack.
  132. */
  133. #define MAKEAVICKID(tcc, stream) \
  134. MAKELONG((ToHex((stream) & 0x0f) << 8) | ToHex(((stream) & 0xf0) >> 4), tcc)
  135. /*
  136. ** Main AVI File Header
  137. */
  138. /* flags for use in <dwFlags> in AVIFileHdr */
  139. #define AVIF_HASINDEX 0x00000010 // Index at end of file?
  140. #define AVIF_MUSTUSEINDEX 0x00000020
  141. #define AVIF_ISINTERLEAVED 0x00000100
  142. #define AVIF_VARIABLESIZEREC 0x00000200
  143. #define AVIF_NOPADDING 0x00000400
  144. #define AVIF_WASCAPTUREFILE 0x00010000
  145. #define AVIF_COPYRIGHTED 0x00020000
  146. /* The AVI File Header LIST chunk should be padded to this size */
  147. #define AVI_HEADERSIZE 2048 // size of AVI header list
  148. /*****************************************************************************
  149. * @doc EXTERNAL AVI_FFMT
  150. *
  151. * @types MainAVIHeader | The <t MainAVIHeader> structure contains
  152. * global information for the entire AVI file. It is contained
  153. * within an 'avih' chunk within the LIST 'hdrl' chunk at the
  154. * beginning of an AVI RIFF file.
  155. *
  156. * @field DWORD | dwMicroSecPerFrame | Specifies the number of
  157. * microseconds between frames.
  158. *
  159. * @field DWORD | dwMaxBytesPerSec | Specifies the approximate
  160. * maximum data rate of file.
  161. *
  162. * @field DWORD | dwReserved1 | Reserved. (This field should be set to 0.)
  163. *
  164. * @field DWORD | dwFlags | Specifies any applicable flags.
  165. * The following flags are defined:
  166. *
  167. * @flag AVIF_HASINDEX | Indicates
  168. * the AVI file has an 'idx1' chunk containing an index
  169. * at the end of the file. For good performance, all AVI
  170. * files should contain an index.
  171. *
  172. * @flag AVIF_MUSTUSEINDEX | Indicates that the
  173. * index, rather than the physical ordering of the chunks
  174. * in the file, should be used to determine the order of
  175. * presentation of the data. For example, this could be
  176. * used for creating a list frames for editing.
  177. *
  178. * @flag AVIF_ISINTERLEAVED | Indicates
  179. * the AVI file is interleaved.
  180. *
  181. * @flag AVIF_WASCAPTUREFILE | Indicates
  182. * the AVI file is a specially allocated file used for
  183. * capturing real-time video. Applications should warn the
  184. * user before writing over a file with this flag set
  185. * because the user probably defragmented
  186. * this file.
  187. *
  188. * @flag AVIF_COPYRIGHTED | Indicates the
  189. * AVI file contains copyrighted data and software.
  190. * When this flag is used,
  191. * software should not permit the data to be duplicated.
  192. *
  193. * @field DWORD | dwTotalFrames | Specifies the number of
  194. * frames of data in file.
  195. *
  196. * @field DWORD | dwInitialFrames | Specifies the initial frame
  197. * for interleaved files. Non-interleaved files should specify
  198. * zero.
  199. *
  200. * @field DWORD | dwStreams | Specifies the number of streams in the file.
  201. * For example, a file with audio and video has 2 streams.
  202. *
  203. * @field DWORD | dwSuggestedBufferSize | Specifies the suggested
  204. * buffer size for reading the file. Generally, this size
  205. * should be large enough to contain the largest chunk in
  206. * the file. If set to zero, or if it is too small, the playback
  207. * software will have to reallocate memory during playback
  208. * which will reduce performance.
  209. *
  210. * For an interleaved file, this buffer size should be large
  211. * enough to read an entire record and not just a chunk.
  212. *
  213. * @field DWORD | dwWidth | Specifies the width of the AVI file in pixels.
  214. *
  215. * @field DWORD | dwHeight | Specifies the height of the AVI file in pixels.
  216. *
  217. * @field DWORD | dwScale | This field is used with
  218. * <e MainAVIHeader.dwRate> to specify the time scale that
  219. * applies to the AVI file. In addition, each stream
  220. * can have its own time scale.
  221. *
  222. * Dividing <e MainAVIHeader.dwRate> by <e AVIStreamHeader.dwScale>
  223. * gives the number of samples per second.
  224. *
  225. * @field DWORD | dwRate | See <e MainAVIHeader.dwScale>.
  226. *
  227. * @field DWORD | dwStart | Specifies the starting time of the AVI file.
  228. * The units are defined by <e MainAVIHeader.dwRate> and
  229. * <e MainAVIHeader.dwScale>. This field is usually set to zero.
  230. *
  231. * @field DWORD | dwLength | Specifies the length of the AVI file.
  232. * The units are defined by <e AVIStreamHeader.dwRate> and
  233. * <e AVIStreamHeader.dwScale>. This length is returned by MCIAVI when
  234. * using the frames time format.
  235. *
  236. ****************************************************************************/
  237. typedef struct
  238. {
  239. DWORD dwMicroSecPerFrame; // frame display rate (or 0L)
  240. DWORD dwMaxBytesPerSec; // max. transfer rate
  241. DWORD dwPaddingGranularity; // pad to multiples of this
  242. // size; normally 2K.
  243. DWORD dwFlags; // the ever-present flags
  244. DWORD dwTotalFrames; // # frames in file
  245. DWORD dwInitialFrames;
  246. DWORD dwStreams;
  247. DWORD dwSuggestedBufferSize;
  248. DWORD dwWidth;
  249. DWORD dwHeight;
  250. /* Do we want the stuff below for the whole movie, or just
  251. ** for the individual streams?
  252. */
  253. DWORD dwScale;
  254. DWORD dwRate; /* dwRate / dwScale == samples/second */
  255. DWORD dwStart; /* Is this always zero? */
  256. DWORD dwLength; /* In units above... */
  257. } MainAVIHeader;
  258. /*
  259. ** Stream header
  260. */
  261. /* !!! Do we need to distinguish between discrete and continuous streams? */
  262. #define AVISF_DISABLED 0x00000001
  263. #define AVISF_VIDEO_PALCHANGES 0x00010000
  264. /* Do we need identity palette support? */
  265. /*****************************************************************************
  266. * @doc EXTERNAL AVI_FFMT
  267. *
  268. * @types AVIStreamHeader | The <t AVIStreamHeader> structure contains
  269. * header information for a single stream of an file. It is contained
  270. * within an 'strh' chunk within a LIST 'strl' chunk that is itself
  271. * contained within the LIST 'hdrl' chunk at the beginning of
  272. * an AVI RIFF file.
  273. *
  274. * @field FOURCC | fccType | Contains a four-character code which specifies
  275. * the type of data contained in the stream. The following values are
  276. * currently defined:
  277. *
  278. * @flag 'vids' | Indicates the stream contains video data. The stream
  279. * format chunk contains a <t BITMAPINFO> structure which can include
  280. * palette information.
  281. *
  282. * @flag 'auds' | Indicates the stream contains video data. The stream
  283. * format chunk contains a <t WAVEFORMATEX> or <t PCMWAVEFORMAT>
  284. * structure.
  285. *
  286. * New data types should be registered with the <MI>Multimedia Developer
  287. * Registration Kit<D>.
  288. *
  289. * @field FOURCC | fccHandler | Contains a four-character code that
  290. * identifies a specific data handler.
  291. *
  292. * @field DWORD | dwFlags | Specifies any applicable flags.
  293. * The bits in the high-order word of these flags
  294. * are specific to the type of data contained in the stream.
  295. * The following flags are currently defined:
  296. *
  297. * @flag AVISF_DISABLED | Indicates
  298. * this stream should not be enabled by default.
  299. *
  300. * @flag AVISF_VIDEO_PALCHANGES | Indicates
  301. * this video stream contains palette changes. This flag warns
  302. * the playback software that it will need to animate the
  303. * palette.
  304. *
  305. * @field DWORD | dwReserved1 | Reserved. (Should be set to 0.)
  306. *
  307. * @field DWORD | dwInitialFrames | Reserved for interleaved files.
  308. * (Set this to 0 for non-interleaved files.)
  309. *
  310. * @field DWORD | dwScale | This field is used together with
  311. * <e AVIStreamHeader.dwRate> to specify the time scale that
  312. * this stream will use.
  313. *
  314. * Dividing <e AVIStreamHeader.dwRate> by <e AVIStreamHeader.dwScale>
  315. * gives the number of samples per second.
  316. *
  317. * For video streams, this rate should be the frame rate.
  318. *
  319. * For audio streams, this rate should correspond to the time needed for
  320. * <e WAVEFORMATEX.nBlockAlign> bytes of audio, which for PCM audio simply
  321. * reduces to the sample rate.
  322. *
  323. * @field DWORD | dwRate | See <e AVIStreamHeader.dwScale>.
  324. *
  325. * @field DWORD | dwStart | Specifies the starting time of the AVI file.
  326. * The units are defined by the
  327. * <e MainAVIHeader.dwRate> and <e MainAVIHeader.dwScale> fields
  328. * in the main file header. Normally, this is zero, but it can
  329. * specify a delay time for a stream which does not start concurrently
  330. * with the file.
  331. *
  332. * Note: The 1.0 release of the AVI tools does not support a non-zero
  333. * starting time.
  334. *
  335. * @field DWORD | dwLength | Specifies the length of this stream.
  336. * The units are defined by the
  337. * <e AVIStreamHeader.dwRate> and <e AVIStreamHeader.dwScale>
  338. * fields of the stream's header.
  339. *
  340. * @field DWORD | dwSuggestedBufferSize | Suggests how large a buffer
  341. * should be used to read this stream. Typically, this contains a
  342. * value corresponding to the largest chunk present in the stream.
  343. * Using the correct buffer size makes playback more efficient.
  344. * Use zero if you do not know the correct buffer size.
  345. *
  346. * @field DWORD | dwQuality | Specifies an indicator of the quality
  347. * of the data in the stream. Quality is
  348. * represented as a number between 0 and 10000. For compressed data,
  349. * this typically represent the value of the quality parameter
  350. * passed to the compression software.
  351. *
  352. * @field DWORD | dwSampleSize | Specifies the size of a single sample
  353. * of data. This is set to
  354. * zero if the samples can vary in size. If this number is non-zero, then
  355. * multiple samples of data can be grouped into a single chunk within
  356. * the file. If it is zero, each sample of data (such as a video
  357. * frame) must be in a separate chunk.
  358. *
  359. * For video streams, this number is typically zero, although it
  360. * can be non-zero if all video frames are the same size.
  361. *
  362. * For audio streams, this number should be the same as the
  363. * <e WAVEFORMATEX.nBlockAlign> field of the <t WAVEFORMATEX> structure
  364. * describing the audio.
  365. *
  366. ****************************************************************************/
  367. typedef struct {
  368. FOURCC fccType;
  369. FOURCC fccHandler;
  370. DWORD dwFlags; /* Contains AVITF_* flags */
  371. WORD wPriority;
  372. WORD wLanguage;
  373. DWORD dwInitialFrames;
  374. DWORD dwScale;
  375. DWORD dwRate; /* dwRate / dwScale == samples/second */
  376. DWORD dwStart;
  377. DWORD dwLength; /* In units above... */
  378. // new....
  379. DWORD dwSuggestedBufferSize;
  380. DWORD dwQuality;
  381. DWORD dwSampleSize;
  382. RECT rcFrame; /* does each frame need this? */
  383. /* additional type-specific data goes in StreamInfo chunk */
  384. /* For video: position within rectangle... */
  385. /* For audio: volume? stereo channel? */
  386. } AVIStreamHeader;
  387. typedef struct {
  388. RECT rcFrame;
  389. } AVIVideoStreamInfo;
  390. typedef struct {
  391. WORD wLeftVolume; // !!! Range?
  392. WORD wRightVolume;
  393. DWORD dwLanguage; // !!! Is there a standard representation of this?
  394. } AVIAudioStreamInfo;
  395. #define AVIIF_LIST 0x00000001L // chunk is a 'LIST'
  396. #define AVIIF_TWOCC 0x00000002L // ckid is a TWOCC?
  397. #define AVIIF_KEYFRAME 0x00000010L // this frame is a key frame.
  398. #define AVIIF_FIRSTPART 0x00000020L // this frame is the start of a partial frame.
  399. #define AVIIF_LASTPART 0x00000040L // this frame is the end of a partial frame.
  400. #define AVIIF_MIDPART (AVIIF_LASTPART|AVIIF_FIRSTPART)
  401. #define AVIIF_NOTIME 0x00000100L // this frame doesn't take any time
  402. #define AVIIF_COMPUSE 0x0FFF0000L // these bits are for compressor use
  403. /*****************************************************************************
  404. * @doc EXTERNAL AVI_FFMT
  405. *
  406. * @types AVIINDEXENTRY | The AVI file index consists of an array
  407. * of <t AVIINDEXENTRY> structures contained within an 'idx1'
  408. * chunk at the end of an AVI file. This chunk follows the main LIST 'movi'
  409. * chunk which contains the actual data.
  410. *
  411. * @field DWORD | ckid | Specifies a four-character code corresponding
  412. * to the chunk ID of a data chunk in the file.
  413. *
  414. * @field DWORD | dwFlags | Specifies any applicable flags.
  415. * The flags in the low-order word are reserved for AVI,
  416. * while those in the high-order word can be used
  417. * for stream- and compressor/decompressor-specific information.
  418. *
  419. * The following values are currently defined:
  420. *
  421. * @flag AVIIF_LIST | Indicates the specified
  422. * chunk is a 'LIST' chunk, and the <e AVIINDEXENTRY.ckid>
  423. * field contains the list type of the chunk.
  424. *
  425. * @flag AVIIF_KEYFRAME | Indicates this chunk
  426. * is a key frame. Key frames do not require
  427. * additional preceding chunks to be properly decoded.
  428. *
  429. * @flag AVIIF_NOTIME | Indicates this chunk should have no effect
  430. * on timing or calculating time values based on the number of chunks.
  431. * For example, palette change chunks in a video stream
  432. * should have this flag set, so that they are not counted
  433. * as taking up a frame's worth of time.
  434. *
  435. * @field DWORD | dwChunkOffset | Specifies the position in the file of the
  436. * specified chunk. The position value includes the eight byte RIFF header.
  437. *
  438. * @field DWORD | dwChunkLength | Specifies the length of the
  439. * specified chunk. The length value does not include the eight
  440. * byte RIFF header.
  441. *
  442. ****************************************************************************/
  443. typedef struct
  444. {
  445. DWORD ckid;
  446. DWORD dwFlags;
  447. DWORD dwChunkOffset; // Position of chunk
  448. DWORD dwChunkLength; // Length of chunk
  449. } AVIINDEXENTRY;
  450. /*
  451. ** Palette change chunk
  452. **
  453. ** Used in video streams.
  454. */
  455. typedef struct
  456. {
  457. BYTE bFirstEntry; /* first entry to change */
  458. BYTE bNumEntries; /* # entries to change (0 if 256) */
  459. WORD wFlags; /* Mostly to preserve alignment... */
  460. PALETTEENTRY peNew[]; /* New color specifications */
  461. } AVIPALCHANGE;
  462. /*****************************************************************************
  463. * @doc EXTERNAL AVI_FFMT
  464. *
  465. * @types AVIPALCHANGE | The <t AVIPALCHANGE> structure is used in
  466. * video streams containing palettized data to indicate the
  467. * palette should change for subsequent video data.
  468. *
  469. * @field BYTE | bFirstEntry | Specifies the first palette entry to change.
  470. *
  471. * @field BYTE | bNumEntries | Specifies the number of entries to change.
  472. *
  473. * @field WORD | wFlags | Reserved. (This should be set to 0.)
  474. *
  475. * @field PALETTEENTRY | peNew | Specifies an array of new palette entries.
  476. *
  477. ****************************************************************************/
  478. #ifndef RC_INVOKED
  479. #pragma pack() /* Revert to default packing */
  480. #endif /* RC_INVOKED */
  481. #endif /* INC_AVIFFMT */