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