2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #ifndef MPLAYER_AVIHEADER_H
20 #define MPLAYER_AVIHEADER_H
22 #include <sys/types.h>
24 #include "config.h" /* get correct definition of WORDS_BIGENDIAN */
25 #include "libavutil/common.h"
29 #define mmioFOURCC( ch0, ch1, ch2, ch3 ) \
30 ( (uint32_t)(uint8_t)(ch0) | ( (uint32_t)(uint8_t)(ch1) << 8 ) | \
31 ( (uint32_t)(uint8_t)(ch2) << 16 ) | ( (uint32_t)(uint8_t)(ch3) << 24 ) )
34 /* Macro to make a TWOCC out of two characters */
36 #define aviTWOCC(ch0, ch1) ((uint16_t)(uint8_t)(ch0) | ((uint16_t)(uint8_t)(ch1) << 8))
39 //typedef uint16_t TWOCC;
40 //typedef uint32_t FOURCC;
42 /* form types, list types, and chunk types */
43 #define formtypeAVI mmioFOURCC('A', 'V', 'I', ' ')
44 #define listtypeAVIHEADER mmioFOURCC('h', 'd', 'r', 'l')
45 #define ckidAVIMAINHDR mmioFOURCC('a', 'v', 'i', 'h')
46 #define listtypeSTREAMHEADER mmioFOURCC('s', 't', 'r', 'l')
47 #define ckidSTREAMHEADER mmioFOURCC('s', 't', 'r', 'h')
48 #define ckidSTREAMFORMAT mmioFOURCC('s', 't', 'r', 'f')
49 #define ckidSTREAMHANDLERDATA mmioFOURCC('s', 't', 'r', 'd')
50 #define ckidSTREAMNAME mmioFOURCC('s', 't', 'r', 'n')
52 #define listtypeAVIMOVIE mmioFOURCC('m', 'o', 'v', 'i')
53 #define listtypeAVIRECORD mmioFOURCC('r', 'e', 'c', ' ')
55 #define ckidAVINEWINDEX mmioFOURCC('i', 'd', 'x', '1')
58 ** Stream types for the <fccType> field of the stream header.
60 #define streamtypeVIDEO mmioFOURCC('v', 'i', 'd', 's')
61 #define streamtypeAUDIO mmioFOURCC('a', 'u', 'd', 's')
62 #define streamtypeMIDI mmioFOURCC('m', 'i', 'd', 's')
63 #define streamtypeTEXT mmioFOURCC('t', 'x', 't', 's')
65 /* Basic chunk types */
66 #define cktypeDIBbits aviTWOCC('d', 'b')
67 #define cktypeDIBcompressed aviTWOCC('d', 'c')
68 #define cktypePALchange aviTWOCC('p', 'c')
69 #define cktypeWAVEbytes aviTWOCC('w', 'b')
71 /* Chunk id to use for extra chunks for padding. */
72 #define ckidAVIPADDING mmioFOURCC('J', 'U', 'N', 'K')
74 /* flags for use in <dwFlags> in AVIFileHdr */
75 #define AVIF_HASINDEX 0x00000010 // Index at end of file?
76 #define AVIF_MUSTUSEINDEX 0x00000020
77 #define AVIF_ISINTERLEAVED 0x00000100
78 #define AVIF_TRUSTCKTYPE 0x00000800 // Use CKType to find key frames?
79 #define AVIF_WASCAPTUREFILE 0x00010000
80 #define AVIF_COPYRIGHTED 0x00020000
84 uint32_t dwMicroSecPerFrame
; // frame display rate (or 0L)
85 uint32_t dwMaxBytesPerSec
; // max. transfer rate
86 uint32_t dwPaddingGranularity
; // pad to multiples of this
88 uint32_t dwFlags
; // the ever-present flags
89 uint32_t dwTotalFrames
; // # frames in file
90 uint32_t dwInitialFrames
;
92 uint32_t dwSuggestedBufferSize
;
97 uint32_t dwReserved
[4];
100 typedef struct rectangle_t
{
110 uint32_t dwFlags
; /* Contains AVITF_* flags */
113 uint32_t dwInitialFrames
;
115 uint32_t dwRate
; /* dwRate / dwScale == samples/second */
117 uint32_t dwLength
; /* In units above... */
118 uint32_t dwSuggestedBufferSize
;
120 uint32_t dwSampleSize
;
124 /* Flags for index */
125 #define AVIIF_LIST 0x00000001L // chunk is a 'LIST'
126 #define AVIIF_KEYFRAME 0x00000010L // this frame is a key frame.
128 #define AVIIF_NOTIME 0x00000100L // this frame doesn't take any time
129 #define AVIIF_COMPUSE 0x0FFF0000L // these bits are for compressor use
131 #define FOURCC_RIFF mmioFOURCC('R', 'I', 'F', 'F')
132 #define FOURCC_LIST mmioFOURCC('L', 'I', 'S', 'T')
138 uint32_t dwChunkOffset
; // Position of chunk
139 uint32_t dwChunkLength
; // Length of chunk
143 typedef struct avisuperindex_entry
{
144 uint64_t qwOffset
; // absolute file offset
145 uint32_t dwSize
; // size of index chunk at this offset
146 uint32_t dwDuration
; // time span in stream ticks
147 } avisuperindex_entry
;
149 typedef struct avistdindex_entry
{
150 uint32_t dwOffset
; // qwBaseOffset + this is absolute file offset
151 uint32_t dwSize
; // bit 31 is set if this is NOT a keyframe
155 typedef struct __attribute__((packed
)) avistdindex_chunk
{
157 uint32_t dwSize
; // size of this chunk
158 uint16_t wLongsPerEntry
; // must be sizeof(aIndex[0])/sizeof(DWORD)
159 uint8_t bIndexSubType
; // must be 0
160 uint8_t bIndexType
; // must be AVI_INDEX_OF_CHUNKS
161 uint32_t nEntriesInUse
; // first unused entry
162 char dwChunkId
[4]; // '##dc' or '##db' or '##wb' etc..
163 uint64_t qwBaseOffset
; // all dwOffsets in aIndex array are relative to this
164 uint32_t dwReserved3
; // must be 0
165 avistdindex_entry
*aIndex
; // the actual frames
169 // Base Index Form 'indx'
170 typedef struct avisuperindex_chunk
{
172 uint32_t dwSize
; // size of this chunk
173 uint16_t wLongsPerEntry
; // size of each entry in aIndex array (must be 4*4 for us)
174 uint8_t bIndexSubType
; // future use. must be 0
175 uint8_t bIndexType
; // one of AVI_INDEX_* codes
176 uint32_t nEntriesInUse
; // index of first unused member in aIndex array
177 char dwChunkId
[4]; // fcc of what is indexed
178 uint32_t dwReserved
[3]; // meaning differs for each index type/subtype.
180 avisuperindex_entry
*aIndex
; // position of ix## chunks
181 avistdindex_chunk
*stdidx
; // the actual std indices
182 } avisuperindex_chunk
;
185 uint32_t CompressedBMHeight
;
186 uint32_t CompressedBMWidth
;
187 uint32_t ValidBMHeight
;
188 uint32_t ValidBMWidth
;
189 uint32_t ValidBMXOffset
;
190 uint32_t ValidBMYOffset
;
191 uint32_t VideoXOffsetInT
;
192 uint32_t VideoYValidStartLine
;
196 uint32_t VideoFormatToken
;
197 uint32_t VideoStandard
;
198 uint32_t dwVerticalRefreshRate
;
199 uint32_t dwHTotalInT
;
200 uint32_t dwVTotalInLines
;
201 uint32_t dwFrameAspectRatio
;
202 uint32_t dwFrameWidthInPixels
;
203 uint32_t dwFrameHeightInLines
;
204 uint32_t nbFieldPerFrame
;
205 VIDEO_FIELD_DESC FieldInfo
[2];
213 FORMAT_NTSC_CCIR_601
,
223 #define MAKE_AVI_ASPECT(a, b) (((a)<<16)|(b))
224 #define GET_AVI_ASPECT(a) ((float)((a)>>16)/(float)((a)&0xffff))
227 * Some macros to swap little endian structures read from an AVI file
228 * into machine endian format
230 #ifdef WORDS_BIGENDIAN
231 #define le2me_MainAVIHeader(h) { \
232 (h)->dwMicroSecPerFrame = le2me_32((h)->dwMicroSecPerFrame); \
233 (h)->dwMaxBytesPerSec = le2me_32((h)->dwMaxBytesPerSec); \
234 (h)->dwPaddingGranularity = le2me_32((h)->dwPaddingGranularity); \
235 (h)->dwFlags = le2me_32((h)->dwFlags); \
236 (h)->dwTotalFrames = le2me_32((h)->dwTotalFrames); \
237 (h)->dwInitialFrames = le2me_32((h)->dwInitialFrames); \
238 (h)->dwStreams = le2me_32((h)->dwStreams); \
239 (h)->dwSuggestedBufferSize = le2me_32((h)->dwSuggestedBufferSize); \
240 (h)->dwWidth = le2me_32((h)->dwWidth); \
241 (h)->dwHeight = le2me_32((h)->dwHeight); \
244 #define le2me_AVIStreamHeader(h) { \
245 (h)->fccType = le2me_32((h)->fccType); \
246 (h)->fccHandler = le2me_32((h)->fccHandler); \
247 (h)->dwFlags = le2me_32((h)->dwFlags); \
248 (h)->wPriority = le2me_16((h)->wPriority); \
249 (h)->wLanguage = le2me_16((h)->wLanguage); \
250 (h)->dwInitialFrames = le2me_32((h)->dwInitialFrames); \
251 (h)->dwScale = le2me_32((h)->dwScale); \
252 (h)->dwRate = le2me_32((h)->dwRate); \
253 (h)->dwStart = le2me_32((h)->dwStart); \
254 (h)->dwLength = le2me_32((h)->dwLength); \
255 (h)->dwSuggestedBufferSize = le2me_32((h)->dwSuggestedBufferSize); \
256 (h)->dwQuality = le2me_32((h)->dwQuality); \
257 (h)->dwSampleSize = le2me_32((h)->dwSampleSize); \
258 le2me_RECT(&(h)->rcFrame); \
260 #define le2me_RECT(h) { \
261 (h)->left = le2me_16((h)->left); \
262 (h)->top = le2me_16((h)->top); \
263 (h)->right = le2me_16((h)->right); \
264 (h)->bottom = le2me_16((h)->bottom); \
266 #define le2me_BITMAPINFOHEADER(h) { \
267 (h)->biSize = le2me_32((h)->biSize); \
268 (h)->biWidth = le2me_32((h)->biWidth); \
269 (h)->biHeight = le2me_32((h)->biHeight); \
270 (h)->biPlanes = le2me_16((h)->biPlanes); \
271 (h)->biBitCount = le2me_16((h)->biBitCount); \
272 (h)->biCompression = le2me_32((h)->biCompression); \
273 (h)->biSizeImage = le2me_32((h)->biSizeImage); \
274 (h)->biXPelsPerMeter = le2me_32((h)->biXPelsPerMeter); \
275 (h)->biYPelsPerMeter = le2me_32((h)->biYPelsPerMeter); \
276 (h)->biClrUsed = le2me_32((h)->biClrUsed); \
277 (h)->biClrImportant = le2me_32((h)->biClrImportant); \
279 #define le2me_WAVEFORMATEX(h) { \
280 (h)->wFormatTag = le2me_16((h)->wFormatTag); \
281 (h)->nChannels = le2me_16((h)->nChannels); \
282 (h)->nSamplesPerSec = le2me_32((h)->nSamplesPerSec); \
283 (h)->nAvgBytesPerSec = le2me_32((h)->nAvgBytesPerSec); \
284 (h)->nBlockAlign = le2me_16((h)->nBlockAlign); \
285 (h)->wBitsPerSample = le2me_16((h)->wBitsPerSample); \
286 (h)->cbSize = le2me_16((h)->cbSize); \
288 #define le2me_AVIINDEXENTRY(h) { \
289 (h)->ckid = le2me_32((h)->ckid); \
290 (h)->dwFlags = le2me_32((h)->dwFlags); \
291 (h)->dwChunkOffset = le2me_32((h)->dwChunkOffset); \
292 (h)->dwChunkLength = le2me_32((h)->dwChunkLength); \
294 #define le2me_AVISTDIDXCHUNK(h) {\
296 c = (h)->fcc[0]; (h)->fcc[0] = (h)->fcc[3]; (h)->fcc[3] = c; \
297 c = (h)->fcc[1]; (h)->fcc[1] = (h)->fcc[2]; (h)->fcc[2] = c; \
298 (h)->dwSize = le2me_32((h)->dwSize); \
299 (h)->wLongsPerEntry = le2me_16((h)->wLongsPerEntry); \
300 (h)->nEntriesInUse = le2me_32((h)->nEntriesInUse); \
301 c = (h)->dwChunkId[0]; (h)->dwChunkId[0] = (h)->dwChunkId[3]; (h)->dwChunkId[3] = c; \
302 c = (h)->dwChunkId[1]; (h)->dwChunkId[1] = (h)->dwChunkId[2]; (h)->dwChunkId[2] = c; \
303 (h)->qwBaseOffset = le2me_64((h)->qwBaseOffset); \
304 (h)->dwReserved3 = le2me_32((h)->dwReserved3); \
306 #define le2me_AVISTDIDXENTRY(h) {\
307 (h)->dwOffset = le2me_32((h)->dwOffset); \
308 (h)->dwSize = le2me_32((h)->dwSize); \
310 #define le2me_VideoPropHeader(h) { \
311 (h)->VideoFormatToken = le2me_32((h)->VideoFormatToken); \
312 (h)->VideoStandard = le2me_32((h)->VideoStandard); \
313 (h)->dwVerticalRefreshRate = le2me_32((h)->dwVerticalRefreshRate); \
314 (h)->dwHTotalInT = le2me_32((h)->dwHTotalInT); \
315 (h)->dwVTotalInLines = le2me_32((h)->dwVTotalInLines); \
316 (h)->dwFrameAspectRatio = le2me_32((h)->dwFrameAspectRatio); \
317 (h)->dwFrameWidthInPixels = le2me_32((h)->dwFrameWidthInPixels); \
318 (h)->dwFrameHeightInLines = le2me_32((h)->dwFrameHeightInLines); \
319 (h)->nbFieldPerFrame = le2me_32((h)->nbFieldPerFrame); \
321 #define le2me_VIDEO_FIELD_DESC(h) { \
322 (h)->CompressedBMHeight = le2me_32((h)->CompressedBMHeight); \
323 (h)->CompressedBMWidth = le2me_32((h)->CompressedBMWidth); \
324 (h)->ValidBMHeight = le2me_32((h)->ValidBMHeight); \
325 (h)->ValidBMWidth = le2me_32((h)->ValidBMWidth); \
326 (h)->ValidBMXOffset = le2me_32((h)->ValidBMXOffset); \
327 (h)->ValidBMYOffset = le2me_32((h)->ValidBMYOffset); \
328 (h)->VideoXOffsetInT = le2me_32((h)->VideoXOffsetInT); \
329 (h)->VideoYValidStartLine = le2me_32((h)->VideoYValidStartLine); \
333 #define le2me_MainAVIHeader(h) /**/
334 #define le2me_AVIStreamHeader(h) /**/
335 #define le2me_RECT(h) /**/
336 #define le2me_BITMAPINFOHEADER(h) /**/
337 #define le2me_WAVEFORMATEX(h) /**/
338 #define le2me_AVIINDEXENTRY(h) /**/
339 #define le2me_AVISTDIDXCHUNK(h) /**/
340 #define le2me_AVISTDIDXENTRY(h) /**/
341 #define le2me_VideoPropHeader(h) /**/
342 #define le2me_VIDEO_FIELD_DESC(h) /**/
352 off_t idx_offset
; // ennyit kell hozzaadni az index offset ertekekhez
353 // bps-based PTS stuff:
355 int audio_block_size
;
356 off_t audio_block_no
;
357 // interleaved PTS stuff:
358 int skip_video_frames
;
362 float pts_correction
;
363 unsigned int pts_corr_bytes
;
364 unsigned char pts_corrected
;
365 unsigned char pts_has_video
;
366 unsigned int numberofframes
;
367 avisuperindex_chunk
*suidx
;
372 #define AVI_PRIV ((avi_priv_t*)(demuxer->priv))
374 #define AVI_IDX_OFFSET(x) ((((uint64_t)(x)->dwFlags&0xffff0000)<<16)+(x)->dwChunkOffset)
376 #endif /* MPLAYER_AVIHEADER_H */