sync with en/mplayer.1 r28991
[mplayer/glamo.git] / libmpdemux / aviheader.h
blob2fd81d248a98c06e798ee44ae81eb6c009c2dc6d
1 #ifndef MPLAYER_AVIHEADER_H
2 #define MPLAYER_AVIHEADER_H
4 #include <sys/types.h>
5 #include <stdint.h>
6 #include "config.h" /* get correct definition of WORDS_BIGENDIAN */
7 #include "libavutil/common.h"
8 #include "mpbswap.h"
10 #ifndef mmioFOURCC
11 #define mmioFOURCC( ch0, ch1, ch2, ch3 ) \
12 ( (uint32_t)(uint8_t)(ch0) | ( (uint32_t)(uint8_t)(ch1) << 8 ) | \
13 ( (uint32_t)(uint8_t)(ch2) << 16 ) | ( (uint32_t)(uint8_t)(ch3) << 24 ) )
14 #endif
16 /* Macro to make a TWOCC out of two characters */
17 #ifndef aviTWOCC
18 #define aviTWOCC(ch0, ch1) ((uint16_t)(uint8_t)(ch0) | ((uint16_t)(uint8_t)(ch1) << 8))
19 #endif
21 //typedef uint16_t TWOCC;
22 //typedef uint32_t FOURCC;
24 /* form types, list types, and chunk types */
25 #define formtypeAVI mmioFOURCC('A', 'V', 'I', ' ')
26 #define listtypeAVIHEADER mmioFOURCC('h', 'd', 'r', 'l')
27 #define ckidAVIMAINHDR mmioFOURCC('a', 'v', 'i', 'h')
28 #define listtypeSTREAMHEADER mmioFOURCC('s', 't', 'r', 'l')
29 #define ckidSTREAMHEADER mmioFOURCC('s', 't', 'r', 'h')
30 #define ckidSTREAMFORMAT mmioFOURCC('s', 't', 'r', 'f')
31 #define ckidSTREAMHANDLERDATA mmioFOURCC('s', 't', 'r', 'd')
32 #define ckidSTREAMNAME mmioFOURCC('s', 't', 'r', 'n')
34 #define listtypeAVIMOVIE mmioFOURCC('m', 'o', 'v', 'i')
35 #define listtypeAVIRECORD mmioFOURCC('r', 'e', 'c', ' ')
37 #define ckidAVINEWINDEX mmioFOURCC('i', 'd', 'x', '1')
40 ** Stream types for the <fccType> field of the stream header.
42 #define streamtypeVIDEO mmioFOURCC('v', 'i', 'd', 's')
43 #define streamtypeAUDIO mmioFOURCC('a', 'u', 'd', 's')
44 #define streamtypeMIDI mmioFOURCC('m', 'i', 'd', 's')
45 #define streamtypeTEXT mmioFOURCC('t', 'x', 't', 's')
47 /* Basic chunk types */
48 #define cktypeDIBbits aviTWOCC('d', 'b')
49 #define cktypeDIBcompressed aviTWOCC('d', 'c')
50 #define cktypePALchange aviTWOCC('p', 'c')
51 #define cktypeWAVEbytes aviTWOCC('w', 'b')
53 /* Chunk id to use for extra chunks for padding. */
54 #define ckidAVIPADDING mmioFOURCC('J', 'U', 'N', 'K')
56 /* flags for use in <dwFlags> in AVIFileHdr */
57 #define AVIF_HASINDEX 0x00000010 // Index at end of file?
58 #define AVIF_MUSTUSEINDEX 0x00000020
59 #define AVIF_ISINTERLEAVED 0x00000100
60 #define AVIF_TRUSTCKTYPE 0x00000800 // Use CKType to find key frames?
61 #define AVIF_WASCAPTUREFILE 0x00010000
62 #define AVIF_COPYRIGHTED 0x00020000
64 typedef struct
66 uint32_t dwMicroSecPerFrame; // frame display rate (or 0L)
67 uint32_t dwMaxBytesPerSec; // max. transfer rate
68 uint32_t dwPaddingGranularity; // pad to multiples of this
69 // size; normally 2K.
70 uint32_t dwFlags; // the ever-present flags
71 uint32_t dwTotalFrames; // # frames in file
72 uint32_t dwInitialFrames;
73 uint32_t dwStreams;
74 uint32_t dwSuggestedBufferSize;
76 uint32_t dwWidth;
77 uint32_t dwHeight;
79 uint32_t dwReserved[4];
80 } MainAVIHeader;
82 typedef struct rectangle_t {
83 short left;
84 short top;
85 short right;
86 short bottom;
87 } rectangle_t;
89 typedef struct {
90 uint32_t fccType;
91 uint32_t fccHandler;
92 uint32_t dwFlags; /* Contains AVITF_* flags */
93 uint16_t wPriority;
94 uint16_t wLanguage;
95 uint32_t dwInitialFrames;
96 uint32_t dwScale;
97 uint32_t dwRate; /* dwRate / dwScale == samples/second */
98 uint32_t dwStart;
99 uint32_t dwLength; /* In units above... */
100 uint32_t dwSuggestedBufferSize;
101 uint32_t dwQuality;
102 uint32_t dwSampleSize;
103 rectangle_t rcFrame;
104 } AVIStreamHeader;
106 /* Flags for index */
107 #define AVIIF_LIST 0x00000001L // chunk is a 'LIST'
108 #define AVIIF_KEYFRAME 0x00000010L // this frame is a key frame.
110 #define AVIIF_NOTIME 0x00000100L // this frame doesn't take any time
111 #define AVIIF_COMPUSE 0x0FFF0000L // these bits are for compressor use
113 #define FOURCC_RIFF mmioFOURCC('R', 'I', 'F', 'F')
114 #define FOURCC_LIST mmioFOURCC('L', 'I', 'S', 'T')
116 typedef struct
118 uint32_t ckid;
119 uint32_t dwFlags;
120 uint32_t dwChunkOffset; // Position of chunk
121 uint32_t dwChunkLength; // Length of chunk
122 } AVIINDEXENTRY;
125 typedef struct avisuperindex_entry {
126 uint64_t qwOffset; // absolute file offset
127 uint32_t dwSize; // size of index chunk at this offset
128 uint32_t dwDuration; // time span in stream ticks
129 } avisuperindex_entry;
131 typedef struct avistdindex_entry {
132 uint32_t dwOffset; // qwBaseOffset + this is absolute file offset
133 uint32_t dwSize; // bit 31 is set if this is NOT a keyframe
134 } avistdindex_entry;
136 // Standard index
137 typedef struct __attribute__((packed)) avistdindex_chunk {
138 char fcc[4]; // ix##
139 uint32_t dwSize; // size of this chunk
140 uint16_t wLongsPerEntry; // must be sizeof(aIndex[0])/sizeof(DWORD)
141 uint8_t bIndexSubType; // must be 0
142 uint8_t bIndexType; // must be AVI_INDEX_OF_CHUNKS
143 uint32_t nEntriesInUse; // first unused entry
144 char dwChunkId[4]; // '##dc' or '##db' or '##wb' etc..
145 uint64_t qwBaseOffset; // all dwOffsets in aIndex array are relative to this
146 uint32_t dwReserved3; // must be 0
147 avistdindex_entry *aIndex; // the actual frames
148 } avistdindex_chunk;
151 // Base Index Form 'indx'
152 typedef struct avisuperindex_chunk {
153 char fcc[4];
154 uint32_t dwSize; // size of this chunk
155 uint16_t wLongsPerEntry; // size of each entry in aIndex array (must be 4*4 for us)
156 uint8_t bIndexSubType; // future use. must be 0
157 uint8_t bIndexType; // one of AVI_INDEX_* codes
158 uint32_t nEntriesInUse; // index of first unused member in aIndex array
159 char dwChunkId[4]; // fcc of what is indexed
160 uint32_t dwReserved[3]; // meaning differs for each index type/subtype.
161 // 0 if unused
162 avisuperindex_entry *aIndex; // position of ix## chunks
163 avistdindex_chunk *stdidx; // the actual std indices
164 } avisuperindex_chunk;
166 typedef struct {
167 uint32_t CompressedBMHeight;
168 uint32_t CompressedBMWidth;
169 uint32_t ValidBMHeight;
170 uint32_t ValidBMWidth;
171 uint32_t ValidBMXOffset;
172 uint32_t ValidBMYOffset;
173 uint32_t VideoXOffsetInT;
174 uint32_t VideoYValidStartLine;
175 } VIDEO_FIELD_DESC;
177 typedef struct {
178 uint32_t VideoFormatToken;
179 uint32_t VideoStandard;
180 uint32_t dwVerticalRefreshRate;
181 uint32_t dwHTotalInT;
182 uint32_t dwVTotalInLines;
183 uint32_t dwFrameAspectRatio;
184 uint32_t dwFrameWidthInPixels;
185 uint32_t dwFrameHeightInLines;
186 uint32_t nbFieldPerFrame;
187 VIDEO_FIELD_DESC FieldInfo[2];
188 } VideoPropHeader;
190 typedef enum {
191 FORMAT_UNKNOWN,
192 FORMAT_PAL_SQUARE,
193 FORMAT_PAL_CCIR_601,
194 FORMAT_NTSC_SQUARE,
195 FORMAT_NTSC_CCIR_601,
196 } VIDEO_FORMAT;
198 typedef enum {
199 STANDARD_UNKNOWN,
200 STANDARD_PAL,
201 STANDARD_NTSC,
202 STANDARD_SECAM
203 } VIDEO_STANDARD;
205 #define MAKE_AVI_ASPECT(a, b) (((a)<<16)|(b))
206 #define GET_AVI_ASPECT(a) ((float)((a)>>16)/(float)((a)&0xffff))
209 * Some macros to swap little endian structures read from an AVI file
210 * into machine endian format
212 #ifdef WORDS_BIGENDIAN
213 #define le2me_MainAVIHeader(h) { \
214 (h)->dwMicroSecPerFrame = le2me_32((h)->dwMicroSecPerFrame); \
215 (h)->dwMaxBytesPerSec = le2me_32((h)->dwMaxBytesPerSec); \
216 (h)->dwPaddingGranularity = le2me_32((h)->dwPaddingGranularity); \
217 (h)->dwFlags = le2me_32((h)->dwFlags); \
218 (h)->dwTotalFrames = le2me_32((h)->dwTotalFrames); \
219 (h)->dwInitialFrames = le2me_32((h)->dwInitialFrames); \
220 (h)->dwStreams = le2me_32((h)->dwStreams); \
221 (h)->dwSuggestedBufferSize = le2me_32((h)->dwSuggestedBufferSize); \
222 (h)->dwWidth = le2me_32((h)->dwWidth); \
223 (h)->dwHeight = le2me_32((h)->dwHeight); \
226 #define le2me_AVIStreamHeader(h) { \
227 (h)->fccType = le2me_32((h)->fccType); \
228 (h)->fccHandler = le2me_32((h)->fccHandler); \
229 (h)->dwFlags = le2me_32((h)->dwFlags); \
230 (h)->wPriority = le2me_16((h)->wPriority); \
231 (h)->wLanguage = le2me_16((h)->wLanguage); \
232 (h)->dwInitialFrames = le2me_32((h)->dwInitialFrames); \
233 (h)->dwScale = le2me_32((h)->dwScale); \
234 (h)->dwRate = le2me_32((h)->dwRate); \
235 (h)->dwStart = le2me_32((h)->dwStart); \
236 (h)->dwLength = le2me_32((h)->dwLength); \
237 (h)->dwSuggestedBufferSize = le2me_32((h)->dwSuggestedBufferSize); \
238 (h)->dwQuality = le2me_32((h)->dwQuality); \
239 (h)->dwSampleSize = le2me_32((h)->dwSampleSize); \
240 le2me_RECT(&(h)->rcFrame); \
242 #define le2me_RECT(h) { \
243 (h)->left = le2me_16((h)->left); \
244 (h)->top = le2me_16((h)->top); \
245 (h)->right = le2me_16((h)->right); \
246 (h)->bottom = le2me_16((h)->bottom); \
248 #define le2me_BITMAPINFOHEADER(h) { \
249 (h)->biSize = le2me_32((h)->biSize); \
250 (h)->biWidth = le2me_32((h)->biWidth); \
251 (h)->biHeight = le2me_32((h)->biHeight); \
252 (h)->biPlanes = le2me_16((h)->biPlanes); \
253 (h)->biBitCount = le2me_16((h)->biBitCount); \
254 (h)->biCompression = le2me_32((h)->biCompression); \
255 (h)->biSizeImage = le2me_32((h)->biSizeImage); \
256 (h)->biXPelsPerMeter = le2me_32((h)->biXPelsPerMeter); \
257 (h)->biYPelsPerMeter = le2me_32((h)->biYPelsPerMeter); \
258 (h)->biClrUsed = le2me_32((h)->biClrUsed); \
259 (h)->biClrImportant = le2me_32((h)->biClrImportant); \
261 #define le2me_WAVEFORMATEX(h) { \
262 (h)->wFormatTag = le2me_16((h)->wFormatTag); \
263 (h)->nChannels = le2me_16((h)->nChannels); \
264 (h)->nSamplesPerSec = le2me_32((h)->nSamplesPerSec); \
265 (h)->nAvgBytesPerSec = le2me_32((h)->nAvgBytesPerSec); \
266 (h)->nBlockAlign = le2me_16((h)->nBlockAlign); \
267 (h)->wBitsPerSample = le2me_16((h)->wBitsPerSample); \
268 (h)->cbSize = le2me_16((h)->cbSize); \
270 #define le2me_AVIINDEXENTRY(h) { \
271 (h)->ckid = le2me_32((h)->ckid); \
272 (h)->dwFlags = le2me_32((h)->dwFlags); \
273 (h)->dwChunkOffset = le2me_32((h)->dwChunkOffset); \
274 (h)->dwChunkLength = le2me_32((h)->dwChunkLength); \
276 #define le2me_AVISTDIDXCHUNK(h) {\
277 char c; \
278 c = (h)->fcc[0]; (h)->fcc[0] = (h)->fcc[3]; (h)->fcc[3] = c; \
279 c = (h)->fcc[1]; (h)->fcc[1] = (h)->fcc[2]; (h)->fcc[2] = c; \
280 (h)->dwSize = le2me_32((h)->dwSize); \
281 (h)->wLongsPerEntry = le2me_16((h)->wLongsPerEntry); \
282 (h)->nEntriesInUse = le2me_32((h)->nEntriesInUse); \
283 c = (h)->dwChunkId[0]; (h)->dwChunkId[0] = (h)->dwChunkId[3]; (h)->dwChunkId[3] = c; \
284 c = (h)->dwChunkId[1]; (h)->dwChunkId[1] = (h)->dwChunkId[2]; (h)->dwChunkId[2] = c; \
285 (h)->qwBaseOffset = le2me_64((h)->qwBaseOffset); \
286 (h)->dwReserved3 = le2me_32((h)->dwReserved3); \
288 #define le2me_AVISTDIDXENTRY(h) {\
289 (h)->dwOffset = le2me_32((h)->dwOffset); \
290 (h)->dwSize = le2me_32((h)->dwSize); \
292 #define le2me_VideoPropHeader(h) { \
293 (h)->VideoFormatToken = le2me_32((h)->VideoFormatToken); \
294 (h)->VideoStandard = le2me_32((h)->VideoStandard); \
295 (h)->dwVerticalRefreshRate = le2me_32((h)->dwVerticalRefreshRate); \
296 (h)->dwHTotalInT = le2me_32((h)->dwHTotalInT); \
297 (h)->dwVTotalInLines = le2me_32((h)->dwVTotalInLines); \
298 (h)->dwFrameAspectRatio = le2me_32((h)->dwFrameAspectRatio); \
299 (h)->dwFrameWidthInPixels = le2me_32((h)->dwFrameWidthInPixels); \
300 (h)->dwFrameHeightInLines = le2me_32((h)->dwFrameHeightInLines); \
301 (h)->nbFieldPerFrame = le2me_32((h)->nbFieldPerFrame); \
303 #define le2me_VIDEO_FIELD_DESC(h) { \
304 (h)->CompressedBMHeight = le2me_32((h)->CompressedBMHeight); \
305 (h)->CompressedBMWidth = le2me_32((h)->CompressedBMWidth); \
306 (h)->ValidBMHeight = le2me_32((h)->ValidBMHeight); \
307 (h)->ValidBMWidth = le2me_32((h)->ValidBMWidth); \
308 (h)->ValidBMXOffset = le2me_32((h)->ValidBMXOffset); \
309 (h)->ValidBMYOffset = le2me_32((h)->ValidBMYOffset); \
310 (h)->VideoXOffsetInT = le2me_32((h)->VideoXOffsetInT); \
311 (h)->VideoYValidStartLine = le2me_32((h)->VideoYValidStartLine); \
314 #else
315 #define le2me_MainAVIHeader(h) /**/
316 #define le2me_AVIStreamHeader(h) /**/
317 #define le2me_RECT(h) /**/
318 #define le2me_BITMAPINFOHEADER(h) /**/
319 #define le2me_WAVEFORMATEX(h) /**/
320 #define le2me_AVIINDEXENTRY(h) /**/
321 #define le2me_AVISTDIDXCHUNK(h) /**/
322 #define le2me_AVISTDIDXENTRY(h) /**/
323 #define le2me_VideoPropHeader(h) /**/
324 #define le2me_VIDEO_FIELD_DESC(h) /**/
325 #endif
327 typedef struct {
328 // index stuff:
329 void* idx;
330 int idx_size;
331 off_t idx_pos;
332 off_t idx_pos_a;
333 off_t idx_pos_v;
334 off_t idx_offset; // ennyit kell hozzaadni az index offset ertekekhez
335 // bps-based PTS stuff:
336 int video_pack_no;
337 int audio_block_size;
338 off_t audio_block_no;
339 // interleaved PTS stuff:
340 int skip_video_frames;
341 int audio_streams;
342 float avi_audio_pts;
343 float avi_video_pts;
344 float pts_correction;
345 unsigned int pts_corr_bytes;
346 unsigned char pts_corrected;
347 unsigned char pts_has_video;
348 unsigned int numberofframes;
349 avisuperindex_chunk *suidx;
350 int suidx_size;
351 int isodml;
352 } avi_priv_t;
354 #define AVI_PRIV ((avi_priv_t*)(demuxer->priv))
356 #define AVI_IDX_OFFSET(x) ((((uint64_t)(x)->dwFlags&0xffff0000)<<16)+(x)->dwChunkOffset)
358 #endif /* MPLAYER_AVIHEADER_H */