subassconvert: do not escape likely ASS override tags
[mplayer.git] / libmpdemux / aviheader.h
blob8d226606defbc55876fa5aac8b8572d4cc822ed4
1 /*
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>
23 #include <stdint.h>
24 #include "config.h" /* get correct definition of HAVE_BIGENDIAN */
25 #include "libavutil/common.h"
26 #include "mpbswap.h"
28 #ifndef mmioFOURCC
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 ) )
32 #endif
34 /* Macro to make a TWOCC out of two characters */
35 #ifndef aviTWOCC
36 #define aviTWOCC(ch0, ch1) ((uint16_t)(uint8_t)(ch0) | ((uint16_t)(uint8_t)(ch1) << 8))
37 #endif
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
82 typedef struct
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
87 // size; normally 2K.
88 uint32_t dwFlags; // the ever-present flags
89 uint32_t dwTotalFrames; // # frames in file
90 uint32_t dwInitialFrames;
91 uint32_t dwStreams;
92 uint32_t dwSuggestedBufferSize;
94 uint32_t dwWidth;
95 uint32_t dwHeight;
97 uint32_t dwReserved[4];
98 } MainAVIHeader;
100 typedef struct rectangle_t {
101 short left;
102 short top;
103 short right;
104 short bottom;
105 } rectangle_t;
107 typedef struct {
108 uint32_t fccType;
109 uint32_t fccHandler;
110 uint32_t dwFlags; /* Contains AVITF_* flags */
111 uint16_t wPriority;
112 uint16_t wLanguage;
113 uint32_t dwInitialFrames;
114 uint32_t dwScale;
115 uint32_t dwRate; /* dwRate / dwScale == samples/second */
116 uint32_t dwStart;
117 uint32_t dwLength; /* In units above... */
118 uint32_t dwSuggestedBufferSize;
119 uint32_t dwQuality;
120 uint32_t dwSampleSize;
121 rectangle_t rcFrame;
122 } AVIStreamHeader;
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 #ifndef FOURCC_RIFF
132 #define FOURCC_RIFF mmioFOURCC('R', 'I', 'F', 'F')
133 #define FOURCC_LIST mmioFOURCC('L', 'I', 'S', 'T')
134 #endif
136 typedef struct
138 uint32_t ckid;
139 uint32_t dwFlags;
140 uint32_t dwChunkOffset; // Position of chunk
141 uint32_t dwChunkLength; // Length of chunk
142 } AVIINDEXENTRY;
145 typedef struct avisuperindex_entry {
146 uint64_t qwOffset; // absolute file offset
147 uint32_t dwSize; // size of index chunk at this offset
148 uint32_t dwDuration; // time span in stream ticks
149 } avisuperindex_entry;
151 typedef struct avistdindex_entry {
152 uint32_t dwOffset; // qwBaseOffset + this is absolute file offset
153 uint32_t dwSize; // bit 31 is set if this is NOT a keyframe
154 } avistdindex_entry;
156 // Standard index
157 typedef struct __attribute__((packed)) avistdindex_chunk {
158 char fcc[4]; // ix##
159 uint32_t dwSize; // size of this chunk
160 uint16_t wLongsPerEntry; // must be sizeof(aIndex[0])/sizeof(DWORD)
161 uint8_t bIndexSubType; // must be 0
162 uint8_t bIndexType; // must be AVI_INDEX_OF_CHUNKS
163 uint32_t nEntriesInUse; // first unused entry
164 char dwChunkId[4]; // '##dc' or '##db' or '##wb' etc..
165 uint64_t qwBaseOffset; // all dwOffsets in aIndex array are relative to this
166 uint32_t dwReserved3; // must be 0
167 avistdindex_entry *aIndex; // the actual frames
168 } avistdindex_chunk;
171 // Base Index Form 'indx'
172 typedef struct avisuperindex_chunk {
173 char fcc[4];
174 uint32_t dwSize; // size of this chunk
175 uint16_t wLongsPerEntry; // size of each entry in aIndex array (must be 4*4 for us)
176 uint8_t bIndexSubType; // future use. must be 0
177 uint8_t bIndexType; // one of AVI_INDEX_* codes
178 uint32_t nEntriesInUse; // index of first unused member in aIndex array
179 char dwChunkId[4]; // fcc of what is indexed
180 uint32_t dwReserved[3]; // meaning differs for each index type/subtype.
181 // 0 if unused
182 avisuperindex_entry *aIndex; // position of ix## chunks
183 avistdindex_chunk *stdidx; // the actual std indices
184 } avisuperindex_chunk;
186 typedef struct {
187 uint32_t CompressedBMHeight;
188 uint32_t CompressedBMWidth;
189 uint32_t ValidBMHeight;
190 uint32_t ValidBMWidth;
191 uint32_t ValidBMXOffset;
192 uint32_t ValidBMYOffset;
193 uint32_t VideoXOffsetInT;
194 uint32_t VideoYValidStartLine;
195 } VIDEO_FIELD_DESC;
197 typedef struct {
198 uint32_t VideoFormatToken;
199 uint32_t VideoStandard;
200 uint32_t dwVerticalRefreshRate;
201 uint32_t dwHTotalInT;
202 uint32_t dwVTotalInLines;
203 uint32_t dwFrameAspectRatio;
204 uint32_t dwFrameWidthInPixels;
205 uint32_t dwFrameHeightInLines;
206 uint32_t nbFieldPerFrame;
207 VIDEO_FIELD_DESC FieldInfo[2];
208 } VideoPropHeader;
210 typedef enum {
211 FORMAT_UNKNOWN,
212 FORMAT_PAL_SQUARE,
213 FORMAT_PAL_CCIR_601,
214 FORMAT_NTSC_SQUARE,
215 FORMAT_NTSC_CCIR_601,
216 } VIDEO_FORMAT;
218 typedef enum {
219 STANDARD_UNKNOWN,
220 STANDARD_PAL,
221 STANDARD_NTSC,
222 STANDARD_SECAM
223 } VIDEO_STANDARD;
225 #define MAKE_AVI_ASPECT(a, b) (((a)<<16)|(b))
226 #define GET_AVI_ASPECT(a) ((float)((a)>>16)/(float)((a)&0xffff))
229 * Some macros to swap little endian structures read from an AVI file
230 * into machine endian format
232 #if HAVE_BIGENDIAN
233 #define le2me_MainAVIHeader(h) { \
234 (h)->dwMicroSecPerFrame = le2me_32((h)->dwMicroSecPerFrame); \
235 (h)->dwMaxBytesPerSec = le2me_32((h)->dwMaxBytesPerSec); \
236 (h)->dwPaddingGranularity = le2me_32((h)->dwPaddingGranularity); \
237 (h)->dwFlags = le2me_32((h)->dwFlags); \
238 (h)->dwTotalFrames = le2me_32((h)->dwTotalFrames); \
239 (h)->dwInitialFrames = le2me_32((h)->dwInitialFrames); \
240 (h)->dwStreams = le2me_32((h)->dwStreams); \
241 (h)->dwSuggestedBufferSize = le2me_32((h)->dwSuggestedBufferSize); \
242 (h)->dwWidth = le2me_32((h)->dwWidth); \
243 (h)->dwHeight = le2me_32((h)->dwHeight); \
246 #define le2me_AVIStreamHeader(h) { \
247 (h)->fccType = le2me_32((h)->fccType); \
248 (h)->fccHandler = le2me_32((h)->fccHandler); \
249 (h)->dwFlags = le2me_32((h)->dwFlags); \
250 (h)->wPriority = le2me_16((h)->wPriority); \
251 (h)->wLanguage = le2me_16((h)->wLanguage); \
252 (h)->dwInitialFrames = le2me_32((h)->dwInitialFrames); \
253 (h)->dwScale = le2me_32((h)->dwScale); \
254 (h)->dwRate = le2me_32((h)->dwRate); \
255 (h)->dwStart = le2me_32((h)->dwStart); \
256 (h)->dwLength = le2me_32((h)->dwLength); \
257 (h)->dwSuggestedBufferSize = le2me_32((h)->dwSuggestedBufferSize); \
258 (h)->dwQuality = le2me_32((h)->dwQuality); \
259 (h)->dwSampleSize = le2me_32((h)->dwSampleSize); \
260 le2me_RECT(&(h)->rcFrame); \
262 #define le2me_RECT(h) { \
263 (h)->left = le2me_16((h)->left); \
264 (h)->top = le2me_16((h)->top); \
265 (h)->right = le2me_16((h)->right); \
266 (h)->bottom = le2me_16((h)->bottom); \
268 #define le2me_BITMAPINFOHEADER(h) { \
269 (h)->biSize = le2me_32((h)->biSize); \
270 (h)->biWidth = le2me_32((h)->biWidth); \
271 (h)->biHeight = le2me_32((h)->biHeight); \
272 (h)->biPlanes = le2me_16((h)->biPlanes); \
273 (h)->biBitCount = le2me_16((h)->biBitCount); \
274 (h)->biCompression = le2me_32((h)->biCompression); \
275 (h)->biSizeImage = le2me_32((h)->biSizeImage); \
276 (h)->biXPelsPerMeter = le2me_32((h)->biXPelsPerMeter); \
277 (h)->biYPelsPerMeter = le2me_32((h)->biYPelsPerMeter); \
278 (h)->biClrUsed = le2me_32((h)->biClrUsed); \
279 (h)->biClrImportant = le2me_32((h)->biClrImportant); \
281 #define le2me_WAVEFORMATEX(h) { \
282 (h)->wFormatTag = le2me_16((h)->wFormatTag); \
283 (h)->nChannels = le2me_16((h)->nChannels); \
284 (h)->nSamplesPerSec = le2me_32((h)->nSamplesPerSec); \
285 (h)->nAvgBytesPerSec = le2me_32((h)->nAvgBytesPerSec); \
286 (h)->nBlockAlign = le2me_16((h)->nBlockAlign); \
287 (h)->wBitsPerSample = le2me_16((h)->wBitsPerSample); \
288 (h)->cbSize = le2me_16((h)->cbSize); \
290 #define le2me_AVIINDEXENTRY(h) { \
291 (h)->ckid = le2me_32((h)->ckid); \
292 (h)->dwFlags = le2me_32((h)->dwFlags); \
293 (h)->dwChunkOffset = le2me_32((h)->dwChunkOffset); \
294 (h)->dwChunkLength = le2me_32((h)->dwChunkLength); \
296 #define le2me_AVISTDIDXCHUNK(h) {\
297 char c; \
298 c = (h)->fcc[0]; (h)->fcc[0] = (h)->fcc[3]; (h)->fcc[3] = c; \
299 c = (h)->fcc[1]; (h)->fcc[1] = (h)->fcc[2]; (h)->fcc[2] = c; \
300 (h)->dwSize = le2me_32((h)->dwSize); \
301 (h)->wLongsPerEntry = le2me_16((h)->wLongsPerEntry); \
302 (h)->nEntriesInUse = le2me_32((h)->nEntriesInUse); \
303 c = (h)->dwChunkId[0]; (h)->dwChunkId[0] = (h)->dwChunkId[3]; (h)->dwChunkId[3] = c; \
304 c = (h)->dwChunkId[1]; (h)->dwChunkId[1] = (h)->dwChunkId[2]; (h)->dwChunkId[2] = c; \
305 (h)->qwBaseOffset = le2me_64((h)->qwBaseOffset); \
306 (h)->dwReserved3 = le2me_32((h)->dwReserved3); \
308 #define le2me_AVISTDIDXENTRY(h) {\
309 (h)->dwOffset = le2me_32((h)->dwOffset); \
310 (h)->dwSize = le2me_32((h)->dwSize); \
312 #define le2me_VideoPropHeader(h) { \
313 (h)->VideoFormatToken = le2me_32((h)->VideoFormatToken); \
314 (h)->VideoStandard = le2me_32((h)->VideoStandard); \
315 (h)->dwVerticalRefreshRate = le2me_32((h)->dwVerticalRefreshRate); \
316 (h)->dwHTotalInT = le2me_32((h)->dwHTotalInT); \
317 (h)->dwVTotalInLines = le2me_32((h)->dwVTotalInLines); \
318 (h)->dwFrameAspectRatio = le2me_32((h)->dwFrameAspectRatio); \
319 (h)->dwFrameWidthInPixels = le2me_32((h)->dwFrameWidthInPixels); \
320 (h)->dwFrameHeightInLines = le2me_32((h)->dwFrameHeightInLines); \
321 (h)->nbFieldPerFrame = le2me_32((h)->nbFieldPerFrame); \
323 #define le2me_VIDEO_FIELD_DESC(h) { \
324 (h)->CompressedBMHeight = le2me_32((h)->CompressedBMHeight); \
325 (h)->CompressedBMWidth = le2me_32((h)->CompressedBMWidth); \
326 (h)->ValidBMHeight = le2me_32((h)->ValidBMHeight); \
327 (h)->ValidBMWidth = le2me_32((h)->ValidBMWidth); \
328 (h)->ValidBMXOffset = le2me_32((h)->ValidBMXOffset); \
329 (h)->ValidBMYOffset = le2me_32((h)->ValidBMYOffset); \
330 (h)->VideoXOffsetInT = le2me_32((h)->VideoXOffsetInT); \
331 (h)->VideoYValidStartLine = le2me_32((h)->VideoYValidStartLine); \
334 #else
335 #define le2me_MainAVIHeader(h) /**/
336 #define le2me_AVIStreamHeader(h) /**/
337 #define le2me_RECT(h) /**/
338 #define le2me_BITMAPINFOHEADER(h) /**/
339 #define le2me_WAVEFORMATEX(h) /**/
340 #define le2me_AVIINDEXENTRY(h) /**/
341 #define le2me_AVISTDIDXCHUNK(h) /**/
342 #define le2me_AVISTDIDXENTRY(h) /**/
343 #define le2me_VideoPropHeader(h) /**/
344 #define le2me_VIDEO_FIELD_DESC(h) /**/
345 #endif
347 typedef struct {
348 // index stuff:
349 void* idx;
350 int idx_size;
351 off_t idx_pos;
352 off_t idx_pos_a;
353 off_t idx_pos_v;
354 off_t idx_offset; // ennyit kell hozzaadni az index offset ertekekhez
355 // bps-based PTS stuff:
356 int video_pack_no;
357 int audio_block_size;
358 off_t audio_block_no;
359 // interleaved PTS stuff:
360 int skip_video_frames;
361 int audio_streams;
362 float avi_audio_pts;
363 float avi_video_pts;
364 float pts_correction;
365 unsigned int pts_corr_bytes;
366 unsigned char pts_corrected;
367 unsigned char pts_has_video;
368 unsigned int numberofframes;
369 avisuperindex_chunk *suidx;
370 int suidx_size;
371 int isodml;
372 int warned_unaligned;
373 } avi_priv_t;
375 #define AVI_PRIV ((avi_priv_t*)(demuxer->priv))
377 #define AVI_IDX_OFFSET(x) ((((uint64_t)(x)->dwFlags&0xffff0000)<<16)+(x)->dwChunkOffset)
379 struct demuxer;
380 void read_avi_header(struct demuxer *demuxer, int index_mode);
382 #endif /* MPLAYER_AVIHEADER_H */