| 1 |
#ifndef AVIFILE_AVIFMT_H |
| 2 |
#define AVIFILE_AVIFMT_H |
| 3 |
|
| 4 |
/**************************************************************************** |
| 5 |
* |
| 6 |
* AVIFMT - AVI file format definitions |
| 7 |
* |
| 8 |
****************************************************************************/ |
| 9 |
|
| 10 |
#include "utils.h" |
| 11 |
|
| 12 |
#ifndef NOAVIFMT |
| 13 |
|
| 14 |
#ifndef __WINE_WINDEF_H |
| 15 |
|
| 16 |
#define LOBYTE(w) ((uint8_t)(uint16_t)(w)) |
| 17 |
#define HIBYTE(w) ((uint8_t)((uint16_t)(w) >> 8)) |
| 18 |
|
| 19 |
#define LOWORD(l) ((uint16_t)(uint32_t)(l)) |
| 20 |
#define HIWORD(l) ((uint16_t)((uint32_t)(l) >> 16)) |
| 21 |
|
| 22 |
#define MAKELONG(low,high) ((int32_t)(((uint16_t)(low)) | (((uint32_t)((uint16_t)(high))) << 16))) |
| 23 |
|
| 24 |
typedef struct __attribute__((__packed__)) |
| 25 |
{ |
| 26 |
int16_t left; |
| 27 |
int16_t top; |
| 28 |
int16_t right; |
| 29 |
int16_t bottom; |
| 30 |
} RECT, *PRECT, *LPRECT; |
| 31 |
#endif // __WINE_WINDEF_H |
| 32 |
|
| 33 |
#ifdef _MSC_VER |
| 34 |
#pragma warning(disable:4200) |
| 35 |
#endif |
| 36 |
|
| 37 |
/* The following is a short description of the AVI file format. |
| 38 |
* Please see the accompanying documentation for a full explanation. |
| 39 |
* |
| 40 |
* An AVI file is the following RIFF form: |
| 41 |
* |
| 42 |
* RIFF('AVI' |
| 43 |
* LIST('hdrl' |
| 44 |
* avih(<AVIMainHeader>) |
| 45 |
* LIST ('strl' |
| 46 |
* strh(<Stream header>) |
| 47 |
* strf(<Stream format>) |
| 48 |
* [junk(data)] |
| 49 |
* ... additional header data |
| 50 |
* LIST('movi' |
| 51 |
* { LIST('rec' |
| 52 |
* SubChunk... |
| 53 |
* ) |
| 54 |
* | SubChunk } .... |
| 55 |
* ) |
| 56 |
* [ <AVIIndex> ] |
| 57 |
* ) |
| 58 |
* |
| 59 |
* The main file header specifies how many streams are present. For |
| 60 |
* each one, there must be a stream header chunk and a stream format |
| 61 |
* chunk, enlosed in a 'strl' LIST chunk. The 'strf' chunk contains |
| 62 |
* type-specific format information; for a video stream, this should |
| 63 |
* be a BITMAPINFO structure, including palette. For an audio stream, |
| 64 |
* this should be a WAVEFORMAT (or PCMWAVEFORMAT) structure. |
| 65 |
* |
| 66 |
* The actual data is contained in subchunks within the 'movi' LIST |
| 67 |
* chunk. The first two characters of each data chunk are the |
| 68 |
* stream number with which that data is associated. |
| 69 |
* |
| 70 |
* Some defined chunk types: |
| 71 |
* Video Streams: |
| 72 |
* ##db: RGB DIB bits |
| 73 |
* ##dc: RLE8 compressed DIB bits |
| 74 |
* ##pc: Palette Change |
| 75 |
* |
| 76 |
* Audio Streams: |
| 77 |
* ##wb: waveform audio bytes |
| 78 |
* |
| 79 |
* The grouping into LIST 'rec' chunks implies only that the contents of |
| 80 |
* the chunk should be read into memory at the same time. This grouping |
| 81 |
* is used for files specifically intended to be played from CD-ROM. |
| 82 |
* |
| 83 |
* The index chunk at the end of the file should contain one entry for |
| 84 |
* each data chunk in the file. |
| 85 |
* |
| 86 |
* Limitations for the current software: |
| 87 |
* Only one video stream and one audio stream are allowed. |
| 88 |
* The streams must start at the beginning of the file. |
| 89 |
* |
| 90 |
* |
| 91 |
* To register codec types please obtain a copy of the Multimedia |
| 92 |
* Developer Registration Kit from: |
| 93 |
* |
| 94 |
* Microsoft Corporation |
| 95 |
* Multimedia Systems Group |
| 96 |
* Product Marketing |
| 97 |
* One Microsoft Way |
| 98 |
* Redmond, WA 98052-6399 |
| 99 |
* |
| 100 |
*/ |
| 101 |
|
| 102 |
#ifndef mmioFOURCC |
| 103 |
#define mmioFOURCC( ch0, ch1, ch2, ch3 ) \ |
| 104 |
( (int)(unsigned char)(ch0) | ( (int)(unsigned char)(ch1) << 8 ) | \ |
| 105 |
( (int)(unsigned char)(ch2) << 16 ) | ( (int)(unsigned char)(ch3) << 24 ) ) |
| 106 |
#endif |
| 107 |
|
| 108 |
/* Macro to make a TWOCC out of two characters */ |
| 109 |
#ifndef aviTWOCC |
| 110 |
#define aviTWOCC(ch0, ch1) ((unsigned short)(unsigned char)(ch0) | ((unsigned short)(unsigned char)(ch1) << 8)) |
| 111 |
#endif |
| 112 |
|
| 113 |
//typedef uint16_t TWOCC; |
| 114 |
|
| 115 |
/* form types, list types, and chunk types */ |
| 116 |
#define formtypeAVI mmioFOURCC('A', 'V', 'I', ' ') |
| 117 |
|
| 118 |
#define listtypeAVIHEADER mmioFOURCC('h', 'd', 'r', 'l') |
| 119 |
#define listtypeSTREAMHEADER mmioFOURCC('s', 't', 'r', 'l') |
| 120 |
#define listtypeAVIMOVIE mmioFOURCC('m', 'o', 'v', 'i') |
| 121 |
#define listtypeAVIRECORD mmioFOURCC('r', 'e', 'c', ' ') |
| 122 |
#define listtypeINFO mmioFOURCC('I', 'N', 'F', 'O') |
| 123 |
|
| 124 |
#define ckidAVIMAINHDR mmioFOURCC('a', 'v', 'i', 'h') |
| 125 |
#define ckidSTREAMHEADER mmioFOURCC('s', 't', 'r', 'h') |
| 126 |
#define ckidSTREAMFORMAT mmioFOURCC('s', 't', 'r', 'f') |
| 127 |
#define ckidSTREAMHANDLERDATA mmioFOURCC('s', 't', 'r', 'd') |
| 128 |
#define ckidSTREAMNAME mmioFOURCC('s', 't', 'r', 'n') |
| 129 |
#define ckidAVINEWINDEX mmioFOURCC('i', 'd', 'x', '1') |
| 130 |
/* Chunk id to use for extra chunks for padding. */ |
| 131 |
#define ckidAVIPADDING mmioFOURCC('J', 'U', 'N', 'K') |
| 132 |
|
| 133 |
/* |
| 134 |
** Stream types for the <fccType> field of the stream header. |
| 135 |
*/ |
| 136 |
#define streamtypeVIDEO mmioFOURCC('v', 'i', 'd', 's') |
| 137 |
#define streamtypeIAVS mmioFOURCC('i', 'a', 'v', 's') |
| 138 |
#define streamtypeAUDIO mmioFOURCC('a', 'u', 'd', 's') |
| 139 |
#define streamtypeMIDI mmioFOURCC('m', 'i', 'd', 's') |
| 140 |
#define streamtypeTEXT mmioFOURCC('t', 'x', 't', 's') |
| 141 |
|
| 142 |
/* Basic chunk types */ |
| 143 |
#define cktypeDIBbits aviTWOCC('d', 'b') |
| 144 |
#define cktypeDIBcompressed aviTWOCC('d', 'c') |
| 145 |
#define cktypePALchange aviTWOCC('p', 'c') |
| 146 |
#define cktypeWAVEbytes aviTWOCC('w', 'b') |
| 147 |
#define cktypeINDEX aviTWOCC('i', 'x') |
| 148 |
|
| 149 |
|
| 150 |
/* |
| 151 |
* Useful macros |
| 152 |
* |
| 153 |
* Warning: These are nasty macro, and MS C 6.0 compiles some of them |
| 154 |
* incorrectly if optimizations are on. Ack. |
| 155 |
*/ |
| 156 |
|
| 157 |
/* Macro to get stream number out of a FOURCC ckid */ |
| 158 |
#define FromHex(n) (((n) >= 'A') ? ((n) + 10 - 'A') : ((n) - '0')) |
| 159 |
#define StreamFromFOURCC(fcc) \ |
| 160 |
((uint16_t) ((FromHex(LOBYTE(LOWORD(fcc))) << 4) + \ |
| 161 |
(FromHex(HIBYTE(LOWORD(fcc)))))) |
| 162 |
|
| 163 |
/* Macro to get TWOCC chunk type out of a FOURCC ckid */ |
| 164 |
#define TWOCCFromFOURCC(fcc) HIWORD(fcc) |
| 165 |
|
| 166 |
/* Macro to make a ckid for a chunk out of a TWOCC and a stream number |
| 167 |
* from 0-255. |
| 168 |
*/ |
| 169 |
#define ToHex(n) ((uint8_t) (((n) > 9) ? ((n) - 10 + 'A') : ((n) + '0'))) |
| 170 |
#define MAKEAVICKID(tcc, stream) \ |
| 171 |
MAKELONG((ToHex((stream) & 0x0f) << 8) | (ToHex(((stream) & 0xf0) >> 4)), tcc) |
| 172 |
|
| 173 |
/* The AVI File Header LIST chunk should be padded to this size */ |
| 174 |
#define AVI_HEADERSIZE 2048 ///< size of AVI header list |
| 175 |
|
| 176 |
/** |
| 177 |
* Main AVI File Header |
| 178 |
*/ |
| 179 |
typedef struct __attribute__((__packed__)) |
| 180 |
{ |
| 181 |
uint32_t dwMicroSecPerFrame; ///< frame display rate (or 0L) |
| 182 |
uint32_t dwMaxBytesPerSec; ///< max. transfer rate |
| 183 |
uint32_t dwPaddingGranularity; ///< pad to multiples of this |
| 184 |
///< size; normally 2K |
| 185 |
int32_t dwFlags; ///< the ever-present flags |
| 186 |
#define AVIF_HASINDEX 0x00000010 ///< AVI file has index |
| 187 |
#define AVIF_MUSTUSEINDEX 0x00000020 ///< Index should be used for determining presentation order |
| 188 |
///< i.e flag could be used to create a list of frames for editing |
| 189 |
#define AVIF_ISINTERLEAVED 0x00000100 ///< AVI is interleave |
| 190 |
#define AVIF_TRUSTCKTYPE 0x00000800 ///< Use CKType to find key frames? |
| 191 |
#define AVIF_WASCAPTUREFILE 0x00010000 ///< From capturing real time video |
| 192 |
#define AVIF_COPYRIGHTED 0x00020000 ///< User should not copy this material |
| 193 |
|
| 194 |
uint32_t dwTotalFrames; ///< # frames in file |
| 195 |
uint32_t dwInitialFrames; ///< # frames prior init frame of AVI sequence |
| 196 |
///< for interleaved file |
| 197 |
uint32_t dwStreams; |
| 198 |
uint32_t dwSuggestedBufferSize; ///< largets needed buffer (fits larges chunk) |
| 199 |
|
| 200 |
uint32_t dwWidth; |
| 201 |
uint32_t dwHeight; |
| 202 |
|
| 203 |
uint32_t dwScale; |
| 204 |
uint32_t dwRate; |
| 205 |
uint32_t dwStart; |
| 206 |
uint32_t dwLength; |
| 207 |
} AVIMainHeader; |
| 208 |
|
| 209 |
/** |
| 210 |
* Stream header |
| 211 |
*/ |
| 212 |
typedef struct __attribute__((__packed__)) |
| 213 |
{ |
| 214 |
uint32_t fccType; |
| 215 |
uint32_t fccHandler; |
| 216 |
int32_t dwFlags; ///< Contains AVISF_* flags |
| 217 |
#define AVISF_DISABLED 0x00000001 ///< Stream should not be enabled by default |
| 218 |
#define AVISF_VIDEO_PALCHANGES 0x00010000 ///< Video stream contains palette changes |
| 219 |
|
| 220 |
uint16_t wPriority; ///< Priority level selects between multiple audio stream |
| 221 |
uint16_t wLanguage; |
| 222 |
uint32_t dwInitialFrames; ///< Specifies how far audio data is skewed ahead of the video frames in interleaved files |
| 223 |
///< typically about 0.75sec |
| 224 |
uint32_t dwScale; |
| 225 |
uint32_t dwRate; ///< dwRate / dwScale == samples per second |
| 226 |
uint32_t dwStart; |
| 227 |
uint32_t dwLength; ///< In units above... |
| 228 |
uint32_t dwSuggestedBufferSize; |
| 229 |
int32_t dwQuality; ///< Quality parameter passed to compressor 1..10000, -1 == default quality |
| 230 |
uint32_t dwSampleSize; ///< Specifies the size of a single sample of data |
| 231 |
///< This is set to zero if the samples can vary in size. |
| 232 |
///< If this number is non-zero, then multiple |
| 233 |
///< samples of data can be grouped into a single chunk within the file. If |
| 234 |
///< it is zero, each sample of data (such as a video frame) must be in a |
| 235 |
///< separate chunk. |
| 236 |
///< For video streams, this number is typically zero, although it can be |
| 237 |
///< non-zero if all video frames are the same size. |
| 238 |
///< For audio streams, this number should be the same as the nBlockAlign |
| 239 |
///< field of the WAVEFORMAT structure describing the audio. |
| 240 |
|
| 241 |
RECT rcFrame; ///< Specifies the destination rectangle for a text or video stream within |
| 242 |
///< the movie rectangle specified by the dwWidth and dwHeight members of the AVIMainHeader. |
| 243 |
} AVIStreamHeader; |
| 244 |
|
| 245 |
#define FOURCC_RIFF mmioFOURCC('R', 'I', 'F', 'F') |
| 246 |
#define FOURCC_LIST mmioFOURCC('L', 'I', 'S', 'T') |
| 247 |
|
| 248 |
|
| 249 |
// The following comes from the OpenDML 1.0 spec for extended AVI files |
| 250 |
|
| 251 |
// bIndexType codes |
| 252 |
// |
| 253 |
|
| 254 |
#define AVI_INDEX_OF_INDEXES 0x00 // when each entry in aIndex |
| 255 |
// array points to an index chunk |
| 256 |
|
| 257 |
#define AVI_INDEX_OF_CHUNKS 0x01 // when each entry in aIndex |
| 258 |
// array points to a chunk in the file |
| 259 |
|
| 260 |
#define AVI_INDEX_IS_DATA 0x80 // when each entry is aIndex is |
| 261 |
// really the data |
| 262 |
|
| 263 |
// bIndexSubtype codes for INDEX_OF_CHUNKS |
| 264 |
|
| 265 |
#define AVI_INDEX_2FIELD 0x01 // when fields within frames |
| 266 |
|
| 267 |
typedef struct __attribute__((__packed__)) |
| 268 |
{ |
| 269 |
uint32_t ckid; |
| 270 |
int32_t dwFlags; |
| 271 |
#define AVIIF_LIST 0x00000001 ///< chunk is a 'LIST' |
| 272 |
#define AVIIF_KEYFRAME 0x00000010 ///< this frame is a key frame. |
| 273 |
#define AVIIF_NOTIME 0x00000100 ///< this frame doesn't take any time |
| 274 |
#define AVIIF_COMPUSE 0x0FFF0000 ///< these bits are for compressor use |
| 275 |
|
| 276 |
uint32_t dwChunkOffset; ///< Position of chunk |
| 277 |
uint32_t dwChunkLength; ///< Length of chunk |
| 278 |
} AVIIndexEntry; |
| 279 |
|
| 280 |
typedef struct __attribute__((__packed__)) |
| 281 |
{ |
| 282 |
uint64_t qwOffset; ///< absolute file offset, offset 0 is |
| 283 |
// unused entry?? |
| 284 |
uint32_t dwSize; ///< size of index chunk at this offset |
| 285 |
uint32_t dwDuration; ///< time span in stream ticks |
| 286 |
} AVISuperIndexEntry; |
| 287 |
|
| 288 |
typedef struct __attribute__((__packed__)) |
| 289 |
{ |
| 290 |
uint32_t fccType; |
| 291 |
uint32_t cb; |
| 292 |
uint16_t wLongsPerEntry; ///< must be 4 (size of each entry in aIndex array) |
| 293 |
uint8_t bIndexSubType; ///< must be 0 or AVI_INDEX_2FIELD |
| 294 |
uint8_t bIndexType; ///< must be AVI_INDEX_OF_INDEXES |
| 295 |
uint32_t nEntriesInUse; ///< used entries in aIndex array |
| 296 |
uint32_t dwChunkId; ///< ##dc or ##db or ##wb.. |
| 297 |
uint32_t dwReserved[3]; ///< must be 0 |
| 298 |
AVISuperIndexEntry* aIndex; |
| 299 |
|
| 300 |
uint32_t dwChunkOffset; ///< Position of chunk |
| 301 |
uint32_t dwChunkLength; ///< Length of chunk |
| 302 |
} AVISuperIndex; |
| 303 |
|
| 304 |
typedef struct __attribute__((__packed__)) |
| 305 |
{ |
| 306 |
int32_t dwOffset; ///< qwBaseOffset + this is absolute file offset |
| 307 |
int32_t dwSize; ///< bit 31 is set if this is NOT a keyframe |
| 308 |
} AVIStdIndexEntry; |
| 309 |
|
| 310 |
typedef struct __attribute__((__packed__)) |
| 311 |
{ |
| 312 |
uint32_t fcc; ///< ##ix |
| 313 |
uint32_t cb; |
| 314 |
uint16_t wLongsPerEntry; ///< must be sizeof(aIndex[0])/sizeof(DWORD) |
| 315 |
uint8_t bIndexSubType; ///< must be 0 |
| 316 |
uint8_t bIndexType; ///< must be AVI_INDEX_OF_CHUNKS |
| 317 |
uint32_t nEntriesInUse; ///< used entries |
| 318 |
uint32_t dwChunkId; ///< ##dc or ##db or ##wb |
| 319 |
uint64_t qwBaseOffset; ///< all dwOffsets in aIndex array are |
| 320 |
// relative to this |
| 321 |
uint64_t dwReserved3; ///< must be 0 |
| 322 |
AVIStdIndexEntry* aIndex; |
| 323 |
} AVIStdIndex; |
| 324 |
|
| 325 |
#define AVISTREAMREAD_CONVENIENT (-1L) |
| 326 |
|
| 327 |
/* |
| 328 |
* Palette change chunk |
| 329 |
* |
| 330 |
* Used in video streams. |
| 331 |
*/ |
| 332 |
#endif /* NOAVIFMT */ |
| 333 |
|
| 334 |
#endif /* AVIFILE_AVIFMT_H */ |