]> git.sesse.net Git - vlc/blob - include/codecs.h
mkv.cpp: add some debugging messages for the users and tests for unsupported tracks
[vlc] / include / codecs.h
1 /*****************************************************************************
2  * codecs.h: codec related structures needed by the demuxers and decoders
3  *****************************************************************************
4  * Copyright (C) 1999-2001 the VideoLAN team
5  * $Id$
6  *
7  * Author: Gildas Bazin <gbazin@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 #ifndef _VLC_CODECS_H
25 #define _VLC_CODECS_H 1
26
27 /* Structures exported to the demuxers and decoders */
28
29 #if !(defined _GUID_DEFINED || defined GUID_DEFINED)
30 #define GUID_DEFINED
31 typedef struct _GUID
32 {
33     uint32_t Data1;
34     uint16_t Data2;
35     uint16_t Data3;
36     uint8_t  Data4[8];
37 } GUID, *REFGUID, *LPGUID;
38 #endif /* GUID_DEFINED */
39
40 #ifndef _WAVEFORMATEX_
41 #define _WAVEFORMATEX_
42 typedef struct
43 #ifdef HAVE_ATTRIBUTE_PACKED
44     __attribute__((__packed__))
45 #endif
46 _WAVEFORMATEX {
47     uint16_t   wFormatTag;
48     uint16_t   nChannels;
49     uint32_t   nSamplesPerSec;
50     uint32_t   nAvgBytesPerSec;
51     uint16_t   nBlockAlign;
52     uint16_t   wBitsPerSample;
53     uint16_t   cbSize;
54 } WAVEFORMATEX, *PWAVEFORMATEX, *NPWAVEFORMATEX, *LPWAVEFORMATEX;
55 #endif /* _WAVEFORMATEX_ */
56
57 #ifndef _WAVEFORMATEXTENSIBLE_
58 #define _WAVEFORMATEXTENSIBLE_
59 typedef struct
60 #ifdef HAVE_ATTRIBUTE_PACKED
61     __attribute__((__packed__))
62 #endif
63 _WAVEFORMATEXTENSIBLE {
64     WAVEFORMATEX Format;
65     union {
66         uint16_t wValidBitsPerSample;
67         uint16_t wSamplesPerBlock;
68         uint16_t wReserved;
69     } Samples;
70     uint32_t     dwChannelMask;
71     GUID SubFormat;
72 } WAVEFORMATEXTENSIBLE, *PWAVEFORMATEXTENSIBLE;
73 #endif /* _WAVEFORMATEXTENSIBLE_ */
74
75 #ifndef _WAVEHEADER_
76 #define _WAVEHEADER_
77 typedef struct
78 #ifdef HAVE_ATTRIBUTE_PACKED
79     __attribute__((__packed__))
80 #endif
81 _WAVEHEADER {
82     uint32_t MainChunkID;
83     uint32_t Length;
84     uint32_t ChunkTypeID;
85     uint32_t SubChunkID;
86     uint32_t SubChunkLength;
87     uint16_t Format;
88     uint16_t Modus;
89     uint32_t SampleFreq;
90     uint32_t BytesPerSec;
91     uint16_t BytesPerSample;
92     uint16_t BitsPerSample;
93     uint32_t DataChunkID;
94     uint32_t DataLength;
95 } WAVEHEADER;
96 #endif /* _WAVEHEADER_ */
97
98 #if !defined(_BITMAPINFOHEADER_) && !defined(WIN32)
99 #define _BITMAPINFOHEADER_
100 typedef struct
101 #ifdef HAVE_ATTRIBUTE_PACKED
102     __attribute__((__packed__))
103 #endif
104 {
105     uint32_t   biSize;
106     uint32_t   biWidth;
107     uint32_t   biHeight;
108     uint16_t   biPlanes;
109     uint16_t   biBitCount;
110     uint32_t   biCompression;
111     uint32_t   biSizeImage;
112     uint32_t   biXPelsPerMeter;
113     uint32_t   biYPelsPerMeter;
114     uint32_t   biClrUsed;
115     uint32_t   biClrImportant;
116 } BITMAPINFOHEADER, *PBITMAPINFOHEADER, *LPBITMAPINFOHEADER;
117
118 typedef struct
119 #ifdef HAVE_ATTRIBUTE_PACKED
120     __attribute__((__packed__))
121 #endif
122 {
123     BITMAPINFOHEADER bmiHeader;
124     int        bmiColors[1];
125 } BITMAPINFO, *LPBITMAPINFO;
126 #endif
127
128 #ifndef _RECT32_
129 #define _RECT32_
130 typedef struct
131 #ifdef HAVE_ATTRIBUTE_PACKED
132     __attribute__((__packed__))
133 #endif
134 {
135     int left, top, right, bottom;
136 } RECT32;
137 #endif
138
139 #ifndef _REFERENCE_TIME_
140 #define _REFERENCE_TIME_
141 typedef int64_t REFERENCE_TIME;
142 #endif
143
144 #ifndef _VIDEOINFOHEADER_
145 #define _VIDEOINFOHEADER_
146 typedef struct
147 #ifdef HAVE_ATTRIBUTE_PACKED
148     __attribute__((__packed__))
149 #endif
150 {
151     RECT32            rcSource;
152     RECT32            rcTarget;
153     uint32_t          dwBitRate;
154     uint32_t          dwBitErrorRate;
155     REFERENCE_TIME    AvgTimePerFrame;
156     BITMAPINFOHEADER  bmiHeader;
157 } VIDEOINFOHEADER;
158 #endif
159
160 #ifndef _RGBQUAD_
161 #define _RGBQUAD_
162 typedef struct
163 #ifdef HAVE_ATTRIBUTE_PACKED
164     __attribute__((__packed__))
165 #endif
166 {
167     uint8_t rgbBlue;
168     uint8_t rgbGreen;
169     uint8_t rgbRed;
170     uint8_t rgbReserved;
171 } RGBQUAD1;
172 #endif
173
174 #ifndef _TRUECOLORINFO_
175 #define _TRUECOLORINFO_
176 typedef struct
177 #ifdef HAVE_ATTRIBUTE_PACKED
178     __attribute__((__packed__))
179 #endif
180 {
181     uint32_t dwBitMasks[3];
182     RGBQUAD1 bmiColors[256];
183 } TRUECOLORINFO;
184 #endif
185
186 #ifndef _VIDEOINFO_
187 #define _VIDEOINFO_
188 typedef struct
189 #ifdef HAVE_ATTRIBUTE_PACKED
190     __attribute__((__packed__))
191 #endif
192 {
193     RECT32            rcSource;
194     RECT32            rcTarget;
195     uint32_t          dwBitRate;
196     uint32_t          dwBitErrorRate;
197     REFERENCE_TIME    AvgTimePerFrame;
198     BITMAPINFOHEADER  bmiHeader;
199
200     union
201     {
202         RGBQUAD1 bmiColors[256]; /* Colour palette */
203         uint32_t dwBitMasks[3]; /* True colour masks */
204         TRUECOLORINFO TrueColorInfo; /* Both of the above */
205     };
206
207 } VIDEOINFO;
208 #endif
209
210 /* WAVE format wFormatTag IDs */
211 #define WAVE_FORMAT_UNKNOWN             0x0000 /* Microsoft Corporation */
212 #define WAVE_FORMAT_PCM                 0x0001 /* Microsoft Corporation */
213 #define WAVE_FORMAT_ADPCM               0x0002 /* Microsoft Corporation */
214 #define WAVE_FORMAT_IEEE_FLOAT          0x0003 /* Microsoft Corporation */
215 #define WAVE_FORMAT_ALAW                0x0006 /* Microsoft Corporation */
216 #define WAVE_FORMAT_MULAW               0x0007 /* Microsoft Corporation */
217 #define WAVE_FORMAT_DTS_MS              0x0008 /* Microsoft Corporation */
218 #define WAVE_FORMAT_IMA_ADPCM           0x0011 /* Intel Corporation */
219 #define WAVE_FORMAT_GSM610              0x0031 /* Microsoft Corporation */
220 #define WAVE_FORMAT_MSNAUDIO            0x0032 /* Microsoft Corporation */
221 #define WAVE_FORMAT_G726                0x0045 /* ITU-T standard  */
222 #define WAVE_FORMAT_MPEG                0x0050 /* Microsoft Corporation */
223 #define WAVE_FORMAT_MPEGLAYER3          0x0055 /* ISO/MPEG Layer3 Format Tag */
224 #define WAVE_FORMAT_DOLBY_AC3_SPDIF     0x0092 /* Sonic Foundry */
225
226 #define WAVE_FORMAT_A52                 0x2000
227 #define WAVE_FORMAT_DTS                 0x2001
228 #define WAVE_FORMAT_WMA1                0x0160 /* WMA version 1 */
229 #define WAVE_FORMAT_WMA2                0x0161 /* WMA (v2) 7, 8, 9 Series */
230 #define WAVE_FORMAT_WMAP                0x0162 /* WMA 9 Professional */
231 #define WAVE_FORMAT_WMAL                0x0163 /* WMA 9 Lossless */
232 #define WAVE_FORMAT_DIVIO_AAC           0x4143
233 #define WAVE_FORMAT_AAC                 0x00FF
234
235 /* Need to check these */
236 #define WAVE_FORMAT_DK3                 0x0061
237 #define WAVE_FORMAT_DK4                 0x0062
238
239 #define WAVE_FORMAT_VORB_1              0x674f
240 #define WAVE_FORMAT_VORB_1PLUS          0x676f
241 #define WAVE_FORMAT_VORB_2              0x6750
242 #define WAVE_FORMAT_VORB_2PLUS          0x6770
243 #define WAVE_FORMAT_VORB_3              0x6751
244 #define WAVE_FORMAT_VORB_3PLUS          0x6771
245
246
247 #if !defined(WAVE_FORMAT_EXTENSIBLE)
248 #define WAVE_FORMAT_EXTENSIBLE          0xFFFE /* Microsoft */
249 #endif
250
251 /* GUID SubFormat IDs */
252 /* We need both b/c const variables are not compile-time constants in C, giving
253  * us an error if we use the const GUID in an enum */
254
255 #ifndef _KSDATAFORMAT_SUBTYPE_PCM_
256 #define _KSDATAFORMAT_SUBTYPE_PCM_ {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}}
257 static const GUID VLC_KSDATAFORMAT_SUBTYPE_PCM = {0xE923AABF, 0xCB58, 0x4471, {0xA1, 0x19, 0xFF, 0xFA, 0x01, 0xE4, 0xCE, 0x62}};
258 #define KSDATAFORMAT_SUBTYPE_PCM VLC_KSDATAFORMAT_SUBTYPE_PCM
259 #endif
260
261 #ifndef _KSDATAFORMAT_SUBTYPE_UNKNOWN_ 
262 #define _KSDATAFORMAT_SUBTYPE_UNKNOWN_ {0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}
263 static const GUID VLC_KSDATAFORMAT_SUBTYPE_UNKNOWN = {0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
264 #define KSDATAFORMAT_SUBTYPE_UNKNOWN VLC_KSDATAFORMAT_SUBTYPE_UNKNOWN
265 #endif
266
267 /* Microsoft speaker definitions */
268 #define WAVE_SPEAKER_FRONT_LEFT             0x1
269 #define WAVE_SPEAKER_FRONT_RIGHT            0x2
270 #define WAVE_SPEAKER_FRONT_CENTER           0x4
271 #define WAVE_SPEAKER_LOW_FREQUENCY          0x8
272 #define WAVE_SPEAKER_BACK_LEFT              0x10
273 #define WAVE_SPEAKER_BACK_RIGHT             0x20
274 #define WAVE_SPEAKER_FRONT_LEFT_OF_CENTER   0x40
275 #define WAVE_SPEAKER_FRONT_RIGHT_OF_CENTER  0x80
276 #define WAVE_SPEAKER_BACK_CENTER            0x100
277 #define WAVE_SPEAKER_SIDE_LEFT              0x200
278 #define WAVE_SPEAKER_SIDE_RIGHT             0x400
279 #define WAVE_SPEAKER_TOP_CENTER             0x800
280 #define WAVE_SPEAKER_TOP_FRONT_LEFT         0x1000
281 #define WAVE_SPEAKER_TOP_FRONT_CENTER       0x2000
282 #define WAVE_SPEAKER_TOP_FRONT_RIGHT        0x4000
283 #define WAVE_SPEAKER_TOP_BACK_LEFT          0x8000
284 #define WAVE_SPEAKER_TOP_BACK_CENTER        0x10000
285 #define WAVE_SPEAKER_TOP_BACK_RIGHT         0x20000
286 #define WAVE_SPEAKER_RESERVED               0x80000000
287
288 static struct
289 {
290     uint16_t     i_tag;
291     vlc_fourcc_t i_fourcc;
292     char         *psz_name;
293 }
294 wave_format_tag_to_fourcc[] =
295 {
296     { WAVE_FORMAT_PCM,        VLC_FOURCC( 'a', 'r', 'a', 'w' ), "Raw audio" },
297     { WAVE_FORMAT_ADPCM,      VLC_FOURCC( 'm', 's', 0x00,0x02), "Adpcm" },
298     { WAVE_FORMAT_IEEE_FLOAT, VLC_FOURCC( 'a', 'f', 'l', 't' ), "IEEE Float audio" },
299     { WAVE_FORMAT_ALAW,       VLC_FOURCC( 'a', 'l', 'a', 'w' ), "A-Law" },
300     { WAVE_FORMAT_MULAW,      VLC_FOURCC( 'm', 'l', 'a', 'w' ), "Mu-Law" },
301     { WAVE_FORMAT_IMA_ADPCM,  VLC_FOURCC( 'm', 's', 0x00,0x11), "Ima-Adpcm" },
302     { WAVE_FORMAT_G726,       VLC_FOURCC( 'g', '7', '2', '6' ), "G.726 Adpcm" },
303     { WAVE_FORMAT_MPEGLAYER3, VLC_FOURCC( 'm', 'p', 'g', 'a' ), "Mpeg Audio" },
304     { WAVE_FORMAT_MPEG,       VLC_FOURCC( 'm', 'p', 'g', 'a' ), "Mpeg Audio" },
305     { WAVE_FORMAT_A52,        VLC_FOURCC( 'a', '5', '2', ' ' ), "A/52" },
306     { WAVE_FORMAT_WMA1,       VLC_FOURCC( 'w', 'm', 'a', '1' ), "Window Media Audio v1" },
307     { WAVE_FORMAT_WMA2,       VLC_FOURCC( 'w', 'm', 'a', '2' ), "Window Media Audio v2" },
308     { WAVE_FORMAT_WMA2,       VLC_FOURCC( 'w', 'm', 'a', ' ' ), "Window Media Audio v2" },
309     { WAVE_FORMAT_WMAP,       VLC_FOURCC( 'w', 'm', 'a', 'p' ), "Window Media Audio 9 Professional" },
310     { WAVE_FORMAT_WMAL,       VLC_FOURCC( 'w', 'm', 'a', 'l' ), "Window Media Audio 9 Lossless" },
311     { WAVE_FORMAT_DK3,        VLC_FOURCC( 'm', 's', 0x00,0x61), "Duck DK3" },
312     { WAVE_FORMAT_DK4,        VLC_FOURCC( 'm', 's', 0x00,0x62), "Duck DK4" },
313     { WAVE_FORMAT_DTS,        VLC_FOURCC( 'd', 't', 's', ' ' ), "DTS Coherent Acoustics" },
314     { WAVE_FORMAT_DTS_MS,     VLC_FOURCC( 'd', 't', 's', ' ' ), "DTS Coherent Acoustics" },
315     { WAVE_FORMAT_DIVIO_AAC,  VLC_FOURCC( 'm', 'p', '4', 'a' ), "MPEG-4 Audio (Divio)" },
316     { WAVE_FORMAT_AAC,        VLC_FOURCC( 'm', 'p', '4', 'a' ), "MPEG-4 Audio" },
317     { WAVE_FORMAT_VORB_1,     VLC_FOURCC( 'v', 'o', 'r', '1' ), "Vorbis 1 Audio" },
318     { WAVE_FORMAT_VORB_1PLUS, VLC_FOURCC( 'v', 'o', '1', '+' ), "Vorbis 1+ Audio" },
319     { WAVE_FORMAT_VORB_2,     VLC_FOURCC( 'v', 'o', 'r', '2' ), "Vorbis 2 Audio" },
320     { WAVE_FORMAT_VORB_2PLUS, VLC_FOURCC( 'v', 'o', '2', '+' ), "Vorbis 2+ Audio" },
321     { WAVE_FORMAT_VORB_3,     VLC_FOURCC( 'v', 'o', 'r', '3' ), "Vorbis 3 Audio" },
322     { WAVE_FORMAT_VORB_3PLUS, VLC_FOURCC( 'v', 'o', '3', '+' ), "Vorbis 3+ Audio" },
323     { WAVE_FORMAT_UNKNOWN,    VLC_FOURCC( 'u', 'n', 'd', 'f' ), "Unknown" }
324 };
325
326 static inline void wf_tag_to_fourcc( uint16_t i_tag, vlc_fourcc_t *fcc,
327                                      char **ppsz_name )
328 {
329     int i;
330     for( i = 0; wave_format_tag_to_fourcc[i].i_tag != 0; i++ )
331     {
332         if( wave_format_tag_to_fourcc[i].i_tag == i_tag ) break;
333     }
334     if( fcc ) *fcc = wave_format_tag_to_fourcc[i].i_fourcc;
335     if( ppsz_name ) *ppsz_name = wave_format_tag_to_fourcc[i].psz_name;
336 }
337
338 static inline void fourcc_to_wf_tag( vlc_fourcc_t fcc, uint16_t *pi_tag )
339 {
340     int i;
341     for( i = 0; wave_format_tag_to_fourcc[i].i_tag != 0; i++ )
342     {
343         if( wave_format_tag_to_fourcc[i].i_fourcc == fcc ) break;
344     }
345     if( pi_tag ) *pi_tag = wave_format_tag_to_fourcc[i].i_tag;
346 }
347
348 /* If wFormatTag is WAVEFORMATEXTENSIBLE, we must look at the SubFormat tag
349  * to determine the actual format.  Microsoft has stopped giving out wFormatTag
350  * assignments in lieu of letting 3rd parties generate their own GUIDs
351  */
352 static struct
353 {
354     GUID         guid_tag;
355     vlc_fourcc_t i_fourcc;
356     char         *psz_name;
357 }
358 sub_format_tag_to_fourcc[] =
359 {
360     { _KSDATAFORMAT_SUBTYPE_PCM_, VLC_FOURCC( 'p', 'c', 'm', ' ' ), "PCM" },
361     { _KSDATAFORMAT_SUBTYPE_UNKNOWN_, VLC_FOURCC( 'u', 'n', 'd', 'f' ), "Unknown" }
362 };
363
364 /* compares two GUIDs, returns 1 if identical, 0 otherwise */
365 static inline int guidcmp( const GUID *s1, const GUID *s2 )
366 {
367     return( s1->Data1 == s2->Data1 && s1->Data2 == s2->Data2 &&
368             s1->Data3 == s2->Data3 && !memcmp( s1->Data4, s2->Data4, 8 ) );
369 }
370
371 static inline void sf_tag_to_fourcc( GUID *guid_tag,
372                                      vlc_fourcc_t *fcc, char **ppsz_name )
373 {
374     int i;
375
376     for( i = 0; !guidcmp( &sub_format_tag_to_fourcc[i].guid_tag, 
377                           &KSDATAFORMAT_SUBTYPE_UNKNOWN ); i++ )
378     {
379         if( guidcmp( &sub_format_tag_to_fourcc[i].guid_tag, guid_tag ) ) break;
380     }
381     if( fcc ) *fcc = sub_format_tag_to_fourcc[i].i_fourcc;
382     if( ppsz_name ) *ppsz_name = sub_format_tag_to_fourcc[i].psz_name;
383 }
384
385 /**
386  * Structure to hold information concerning subtitles.
387  * Used between demuxers and decoders of subtitles.
388  */
389 typedef struct es_sys_t
390 {
391     char        *psz_header; /* for 'ssa ' and 'subt' */
392
393     /* for spudec */
394     unsigned int        i_orig_height;
395     unsigned int        i_orig_width;
396     unsigned int        i_origin_x;
397     unsigned int        i_origin_y;
398     unsigned int        i_scale_h;
399     unsigned int        i_scale_v;
400     unsigned int        i_alpha;
401     vlc_bool_t          b_smooth;
402     mtime_t             i_fade_in;
403     mtime_t             i_fade_out;
404     unsigned int        i_align;
405     mtime_t             i_time_offset;
406     vlc_bool_t          b_forced_subs;
407     unsigned int        palette[16];
408     unsigned int        colors[4];
409
410 } subtitle_data_t;
411
412 #endif /* "codecs.h" */