4 //#include "config.h" /* get correct definition WORDS_BIGENDIAN */
5 #include "libavutil/common.h"
9 #define mmioFOURCC( ch0, ch1, ch2, ch3 ) \
10 ( (uint32_t)(uint8_t)(ch0) | ( (uint32_t)(uint8_t)(ch1) << 8 ) | \
11 ( (uint32_t)(uint8_t)(ch2) << 16 ) | ( (uint32_t)(uint8_t)(ch3) << 24 ) )
14 /* Macro to make a TWOCC out of two characters */
16 #define aviTWOCC(ch0, ch1) ((uint16_t)(uint8_t)(ch0) | ((uint16_t)(uint8_t)(ch1) << 8))
19 //typedef uint16_t TWOCC;
20 //typedef uint32_t FOURCC;
22 /* form types, list types, and chunk types */
23 #define formtypeAVI mmioFOURCC('A', 'V', 'I', ' ')
24 #define listtypeAVIHEADER mmioFOURCC('h', 'd', 'r', 'l')
25 #define ckidAVIMAINHDR mmioFOURCC('a', 'v', 'i', 'h')
26 #define listtypeSTREAMHEADER mmioFOURCC('s', 't', 'r', 'l')
27 #define ckidSTREAMHEADER mmioFOURCC('s', 't', 'r', 'h')
28 #define ckidSTREAMFORMAT mmioFOURCC('s', 't', 'r', 'f')
29 #define ckidSTREAMHANDLERDATA mmioFOURCC('s', 't', 'r', 'd')
30 #define ckidSTREAMNAME mmioFOURCC('s', 't', 'r', 'n')
32 #define listtypeAVIMOVIE mmioFOURCC('m', 'o', 'v', 'i')
33 #define listtypeAVIRECORD mmioFOURCC('r', 'e', 'c', ' ')
35 #define ckidAVINEWINDEX mmioFOURCC('i', 'd', 'x', '1')
38 ** Stream types for the <fccType> field of the stream header.
40 #define streamtypeVIDEO mmioFOURCC('v', 'i', 'd', 's')
41 #define streamtypeAUDIO mmioFOURCC('a', 'u', 'd', 's')
42 #define streamtypeMIDI mmioFOURCC('m', 'i', 'd', 's')
43 #define streamtypeTEXT mmioFOURCC('t', 'x', 't', 's')
45 /* Basic chunk types */
46 #define cktypeDIBbits aviTWOCC('d', 'b')
47 #define cktypeDIBcompressed aviTWOCC('d', 'c')
48 #define cktypePALchange aviTWOCC('p', 'c')
49 #define cktypeWAVEbytes aviTWOCC('w', 'b')
51 /* Chunk id to use for extra chunks for padding. */
52 #define ckidAVIPADDING mmioFOURCC('J', 'U', 'N', 'K')
54 /* flags for use in <dwFlags> in AVIFileHdr */
55 #define AVIF_HASINDEX 0x00000010 // Index at end of file?
56 #define AVIF_MUSTUSEINDEX 0x00000020
57 #define AVIF_ISINTERLEAVED 0x00000100
58 #define AVIF_TRUSTCKTYPE 0x00000800 // Use CKType to find key frames?
59 #define AVIF_WASCAPTUREFILE 0x00010000
60 #define AVIF_COPYRIGHTED 0x00020000
64 uint32_t dwMicroSecPerFrame
; // frame display rate (or 0L)
65 uint32_t dwMaxBytesPerSec
; // max. transfer rate
66 uint32_t dwPaddingGranularity
; // pad to multiples of this
68 uint32_t dwFlags
; // the ever-present flags
69 uint32_t dwTotalFrames
; // # frames in file
70 uint32_t dwInitialFrames
;
72 uint32_t dwSuggestedBufferSize
;
77 uint32_t dwReserved
[4];
80 typedef struct rectangle_t
{
90 uint32_t dwFlags
; /* Contains AVITF_* flags */
93 uint32_t dwInitialFrames
;
95 uint32_t dwRate
; /* dwRate / dwScale == samples/second */
97 uint32_t dwLength
; /* In units above... */
98 uint32_t dwSuggestedBufferSize
;
100 uint32_t dwSampleSize
;
104 /* Flags for index */
105 #define AVIIF_LIST 0x00000001L // chunk is a 'LIST'
106 #define AVIIF_KEYFRAME 0x00000010L // this frame is a key frame.
108 #define AVIIF_NOTIME 0x00000100L // this frame doesn't take any time
109 #define AVIIF_COMPUSE 0x0FFF0000L // these bits are for compressor use
111 #define FOURCC_RIFF mmioFOURCC('R', 'I', 'F', 'F')
112 #define FOURCC_LIST mmioFOURCC('L', 'I', 'S', 'T')
118 uint32_t dwChunkOffset
; // Position of chunk
119 uint32_t dwChunkLength
; // Length of chunk
123 typedef struct avisuperindex_entry
{
124 uint64_t qwOffset
; // absolute file offset
125 uint32_t dwSize
; // size of index chunk at this offset
126 uint32_t dwDuration
; // time span in stream ticks
127 } avisuperindex_entry
;
129 typedef struct avistdindex_entry
{
130 uint32_t dwOffset
; // qwBaseOffset + this is absolute file offset
131 uint32_t dwSize
; // bit 31 is set if this is NOT a keyframe
135 typedef struct __attribute__((packed
)) avistdindex_chunk
{
137 uint32_t dwSize
; // size of this chunk
138 uint16_t wLongsPerEntry
; // must be sizeof(aIndex[0])/sizeof(DWORD)
139 uint8_t bIndexSubType
; // must be 0
140 uint8_t bIndexType
; // must be AVI_INDEX_OF_CHUNKS
141 uint32_t nEntriesInUse
; // first unused entry
142 char dwChunkId
[4]; // '##dc' or '##db' or '##wb' etc..
143 uint64_t qwBaseOffset
; // all dwOffsets in aIndex array are relative to this
144 uint32_t dwReserved3
; // must be 0
145 avistdindex_entry
*aIndex
; // the actual frames
149 // Base Index Form 'indx'
150 typedef struct avisuperindex_chunk
{
152 uint32_t dwSize
; // size of this chunk
153 uint16_t wLongsPerEntry
; // size of each entry in aIndex array (must be 4*4 for us)
154 uint8_t bIndexSubType
; // future use. must be 0
155 uint8_t bIndexType
; // one of AVI_INDEX_* codes
156 uint32_t nEntriesInUse
; // index of first unused member in aIndex array
157 char dwChunkId
[4]; // fcc of what is indexed
158 uint32_t dwReserved
[3]; // meaning differs for each index type/subtype.
160 avisuperindex_entry
*aIndex
; // position of ix## chunks
161 avistdindex_chunk
*stdidx
; // the actual std indices
162 } avisuperindex_chunk
;
165 uint32_t CompressedBMHeight
;
166 uint32_t CompressedBMWidth
;
167 uint32_t ValidBMHeight
;
168 uint32_t ValidBMWidth
;
169 uint32_t ValidBMXOffset
;
170 uint32_t ValidBMYOffset
;
171 uint32_t VideoXOffsetInT
;
172 uint32_t VideoYValidStartLine
;
176 uint32_t VideoFormatToken
;
177 uint32_t VideoStandard
;
178 uint32_t dwVerticalRefreshRate
;
179 uint32_t dwHTotalInT
;
180 uint32_t dwVTotalInLines
;
181 uint32_t dwFrameAspectRatio
;
182 uint32_t dwFrameWidthInPixels
;
183 uint32_t dwFrameHeightInLines
;
184 uint32_t nbFieldPerFrame
;
185 VIDEO_FIELD_DESC FieldInfo
[2];
193 FORMAT_NTSC_CCIR_601
,
203 #define MAKE_AVI_ASPECT(a, b) (((a)<<16)|(b))
204 #define GET_AVI_ASPECT(a) ((float)((a)>>16)/(float)((a)&0xffff))
207 * Some macros to swap little endian structures read from an AVI file
208 * into machine endian format
210 #ifdef WORDS_BIGENDIAN
211 #define le2me_MainAVIHeader(h) { \
212 (h)->dwMicroSecPerFrame = le2me_32((h)->dwMicroSecPerFrame); \
213 (h)->dwMaxBytesPerSec = le2me_32((h)->dwMaxBytesPerSec); \
214 (h)->dwPaddingGranularity = le2me_32((h)->dwPaddingGranularity); \
215 (h)->dwFlags = le2me_32((h)->dwFlags); \
216 (h)->dwTotalFrames = le2me_32((h)->dwTotalFrames); \
217 (h)->dwInitialFrames = le2me_32((h)->dwInitialFrames); \
218 (h)->dwStreams = le2me_32((h)->dwStreams); \
219 (h)->dwSuggestedBufferSize = le2me_32((h)->dwSuggestedBufferSize); \
220 (h)->dwWidth = le2me_32((h)->dwWidth); \
221 (h)->dwHeight = le2me_32((h)->dwHeight); \
224 #define le2me_AVIStreamHeader(h) { \
225 (h)->fccType = le2me_32((h)->fccType); \
226 (h)->fccHandler = le2me_32((h)->fccHandler); \
227 (h)->dwFlags = le2me_32((h)->dwFlags); \
228 (h)->wPriority = le2me_16((h)->wPriority); \
229 (h)->wLanguage = le2me_16((h)->wLanguage); \
230 (h)->dwInitialFrames = le2me_32((h)->dwInitialFrames); \
231 (h)->dwScale = le2me_32((h)->dwScale); \
232 (h)->dwRate = le2me_32((h)->dwRate); \
233 (h)->dwStart = le2me_32((h)->dwStart); \
234 (h)->dwLength = le2me_32((h)->dwLength); \
235 (h)->dwSuggestedBufferSize = le2me_32((h)->dwSuggestedBufferSize); \
236 (h)->dwQuality = le2me_32((h)->dwQuality); \
237 (h)->dwSampleSize = le2me_32((h)->dwSampleSize); \
238 le2me_RECT(&(h)->rcFrame); \
240 #define le2me_RECT(h) { \
241 (h)->left = le2me_16((h)->left); \
242 (h)->top = le2me_16((h)->top); \
243 (h)->right = le2me_16((h)->right); \
244 (h)->bottom = le2me_16((h)->bottom); \
246 #define le2me_BITMAPINFOHEADER(h) { \
247 (h)->biSize = le2me_32((h)->biSize); \
248 (h)->biWidth = le2me_32((h)->biWidth); \
249 (h)->biHeight = le2me_32((h)->biHeight); \
250 (h)->biPlanes = le2me_16((h)->biPlanes); \
251 (h)->biBitCount = le2me_16((h)->biBitCount); \
252 (h)->biCompression = le2me_32((h)->biCompression); \
253 (h)->biSizeImage = le2me_32((h)->biSizeImage); \
254 (h)->biXPelsPerMeter = le2me_32((h)->biXPelsPerMeter); \
255 (h)->biYPelsPerMeter = le2me_32((h)->biYPelsPerMeter); \
256 (h)->biClrUsed = le2me_32((h)->biClrUsed); \
257 (h)->biClrImportant = le2me_32((h)->biClrImportant); \
259 #define le2me_WAVEFORMATEX(h) { \
260 (h)->wFormatTag = le2me_16((h)->wFormatTag); \
261 (h)->nChannels = le2me_16((h)->nChannels); \
262 (h)->nSamplesPerSec = le2me_32((h)->nSamplesPerSec); \
263 (h)->nAvgBytesPerSec = le2me_32((h)->nAvgBytesPerSec); \
264 (h)->nBlockAlign = le2me_16((h)->nBlockAlign); \
265 (h)->wBitsPerSample = le2me_16((h)->wBitsPerSample); \
266 (h)->cbSize = le2me_16((h)->cbSize); \
268 #define le2me_AVIINDEXENTRY(h) { \
269 (h)->ckid = le2me_32((h)->ckid); \
270 (h)->dwFlags = le2me_32((h)->dwFlags); \
271 (h)->dwChunkOffset = le2me_32((h)->dwChunkOffset); \
272 (h)->dwChunkLength = le2me_32((h)->dwChunkLength); \
274 #define le2me_AVISTDIDXCHUNK(h) {\
276 c = (h)->fcc[0]; (h)->fcc[0] = (h)->fcc[3]; (h)->fcc[3] = c; \
277 c = (h)->fcc[1]; (h)->fcc[1] = (h)->fcc[2]; (h)->fcc[2] = c; \
278 (h)->dwSize = le2me_32((h)->dwSize); \
279 (h)->wLongsPerEntry = le2me_16((h)->wLongsPerEntry); \
280 (h)->nEntriesInUse = le2me_32((h)->nEntriesInUse); \
281 c = (h)->dwChunkId[0]; (h)->dwChunkId[0] = (h)->dwChunkId[3]; (h)->dwChunkId[3] = c; \
282 c = (h)->dwChunkId[1]; (h)->dwChunkId[1] = (h)->dwChunkId[2]; (h)->dwChunkId[2] = c; \
283 (h)->qwBaseOffset = le2me_64((h)->qwBaseOffset); \
284 (h)->dwReserved3 = le2me_32((h)->dwReserved3); \
286 #define le2me_AVISTDIDXENTRY(h) {\
287 (h)->dwOffset = le2me_32((h)->dwOffset); \
288 (h)->dwSize = le2me_32((h)->dwSize); \
290 #define le2me_VideoPropHeader(h) { \
291 (h)->VideoFormatToken = le2me_32((h)->VideoFormatToken); \
292 (h)->VideoStandard = le2me_32((h)->VideoStandard); \
293 (h)->dwVerticalRefreshRate = le2me_32((h)->dwVerticalRefreshRate); \
294 (h)->dwHTotalInT = le2me_32((h)->dwHTotalInT); \
295 (h)->dwVTotalInLines = le2me_32((h)->dwVTotalInLines); \
296 (h)->dwFrameAspectRatio = le2me_32((h)->dwFrameAspectRatio); \
297 (h)->dwFrameWidthInPixels = le2me_32((h)->dwFrameWidthInPixels); \
298 (h)->dwFrameHeightInLines = le2me_32((h)->dwFrameHeightInLines); \
299 (h)->nbFieldPerFrame = le2me_32((h)->nbFieldPerFrame); \
301 #define le2me_VIDEO_FIELD_DESC(h) { \
302 (h)->CompressedBMHeight = le2me_32((h)->CompressedBMHeight); \
303 (h)->CompressedBMWidth = le2me_32((h)->CompressedBMWidth); \
304 (h)->ValidBMHeight = le2me_32((h)->ValidBMHeight); \
305 (h)->ValidBMWidth = le2me_32((h)->ValidBMWidth); \
306 (h)->ValidBMXOffset = le2me_32((h)->ValidBMXOffset); \
307 (h)->ValidBMYOffset = le2me_32((h)->ValidBMYOffset); \
308 (h)->VideoXOffsetInT = le2me_32((h)->VideoXOffsetInT); \
309 (h)->VideoYValidStartLine = le2me_32((h)->VideoYValidStartLine); \
313 #define le2me_MainAVIHeader(h) /**/
314 #define le2me_AVIStreamHeader(h) /**/
315 #define le2me_RECT(h) /**/
316 #define le2me_BITMAPINFOHEADER(h) /**/
317 #define le2me_WAVEFORMATEX(h) /**/
318 #define le2me_AVIINDEXENTRY(h) /**/
319 #define le2me_AVISTDIDXCHUNK(h) /**/
320 #define le2me_AVISTDIDXENTRY(h) /**/
321 #define le2me_VideoPropHeader(h) /**/
322 #define le2me_VIDEO_FIELD_DESC(h) /**/
332 off_t idx_offset
; // ennyit kell hozzaadni az index offset ertekekhez
333 // bps-based PTS stuff:
335 int audio_block_size
;
336 off_t audio_block_no
;
337 // interleaved PTS stuff:
338 int skip_video_frames
;
342 float pts_correction
;
343 unsigned int pts_corr_bytes
;
344 unsigned char pts_corrected
;
345 unsigned char pts_has_video
;
346 unsigned int numberofframes
;
347 avisuperindex_chunk
*suidx
;
352 #define AVI_PRIV ((avi_priv_t*)(demuxer->priv))
354 #define AVI_IDX_OFFSET(x) ((((uint64_t)(x)->dwFlags&0xffff0000)<<16)+(x)->dwChunkOffset)
356 #endif /* AVIHEADER_H */