]> git.sesse.net Git - vlc/blob - include/vlc_codecs.h
A bit of headers cleanup
[vlc] / include / vlc_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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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_WMAS                0x000a /* WMA 9 Speech */
219 #define WAVE_FORMAT_IMA_ADPCM           0x0011 /* Intel Corporation */
220 #define WAVE_FORMAT_GSM610              0x0031 /* Microsoft Corporation */
221 #define WAVE_FORMAT_MSNAUDIO            0x0032 /* Microsoft Corporation */
222 #define WAVE_FORMAT_G726                0x0045 /* ITU-T standard  */
223 #define WAVE_FORMAT_MPEG                0x0050 /* Microsoft Corporation */
224 #define WAVE_FORMAT_MPEGLAYER3          0x0055 /* ISO/MPEG Layer3 Format Tag */
225 #define WAVE_FORMAT_DOLBY_AC3_SPDIF     0x0092 /* Sonic Foundry */
226
227 #define WAVE_FORMAT_A52                 0x2000
228 #define WAVE_FORMAT_DTS                 0x2001
229 #define WAVE_FORMAT_WMA1                0x0160 /* WMA version 1 */
230 #define WAVE_FORMAT_WMA2                0x0161 /* WMA (v2) 7, 8, 9 Series */
231 #define WAVE_FORMAT_WMAP                0x0162 /* WMA 9 Professional */
232 #define WAVE_FORMAT_WMAL                0x0163 /* WMA 9 Lossless */
233 #define WAVE_FORMAT_DIVIO_AAC           0x4143
234 #define WAVE_FORMAT_AAC                 0x00FF
235
236 /* Need to check these */
237 #define WAVE_FORMAT_DK3                 0x0061
238 #define WAVE_FORMAT_DK4                 0x0062
239
240 #define WAVE_FORMAT_VORB_1              0x674f
241 #define WAVE_FORMAT_VORB_1PLUS          0x676f
242 #define WAVE_FORMAT_VORB_2              0x6750
243 #define WAVE_FORMAT_VORB_2PLUS          0x6770
244 #define WAVE_FORMAT_VORB_3              0x6751
245 #define WAVE_FORMAT_VORB_3PLUS          0x6771
246 #define WAVE_FORMAT_SPEEX               0xa109 /* Speex audio */
247
248
249 #if !defined(WAVE_FORMAT_EXTENSIBLE)
250 #define WAVE_FORMAT_EXTENSIBLE          0xFFFE /* Microsoft */
251 #endif
252
253 /* GUID SubFormat IDs */
254 /* We need both b/c const variables are not compile-time constants in C, giving
255  * us an error if we use the const GUID in an enum */
256
257 #ifndef _KSDATAFORMAT_SUBTYPE_PCM_
258 #define _KSDATAFORMAT_SUBTYPE_PCM_ {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}}
259 static const GUID VLC_KSDATAFORMAT_SUBTYPE_PCM = {0xE923AABF, 0xCB58, 0x4471, {0xA1, 0x19, 0xFF, 0xFA, 0x01, 0xE4, 0xCE, 0x62}};
260 #define KSDATAFORMAT_SUBTYPE_PCM VLC_KSDATAFORMAT_SUBTYPE_PCM
261 #endif
262
263 #ifndef _KSDATAFORMAT_SUBTYPE_UNKNOWN_ 
264 #define _KSDATAFORMAT_SUBTYPE_UNKNOWN_ {0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}
265 static const GUID VLC_KSDATAFORMAT_SUBTYPE_UNKNOWN = {0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
266 #define KSDATAFORMAT_SUBTYPE_UNKNOWN VLC_KSDATAFORMAT_SUBTYPE_UNKNOWN
267 #endif
268
269 /* Microsoft speaker definitions */
270 #define WAVE_SPEAKER_FRONT_LEFT             0x1
271 #define WAVE_SPEAKER_FRONT_RIGHT            0x2
272 #define WAVE_SPEAKER_FRONT_CENTER           0x4
273 #define WAVE_SPEAKER_LOW_FREQUENCY          0x8
274 #define WAVE_SPEAKER_BACK_LEFT              0x10
275 #define WAVE_SPEAKER_BACK_RIGHT             0x20
276 #define WAVE_SPEAKER_FRONT_LEFT_OF_CENTER   0x40
277 #define WAVE_SPEAKER_FRONT_RIGHT_OF_CENTER  0x80
278 #define WAVE_SPEAKER_BACK_CENTER            0x100
279 #define WAVE_SPEAKER_SIDE_LEFT              0x200
280 #define WAVE_SPEAKER_SIDE_RIGHT             0x400
281 #define WAVE_SPEAKER_TOP_CENTER             0x800
282 #define WAVE_SPEAKER_TOP_FRONT_LEFT         0x1000
283 #define WAVE_SPEAKER_TOP_FRONT_CENTER       0x2000
284 #define WAVE_SPEAKER_TOP_FRONT_RIGHT        0x4000
285 #define WAVE_SPEAKER_TOP_BACK_LEFT          0x8000
286 #define WAVE_SPEAKER_TOP_BACK_CENTER        0x10000
287 #define WAVE_SPEAKER_TOP_BACK_RIGHT         0x20000
288 #define WAVE_SPEAKER_RESERVED               0x80000000
289
290 static struct
291 {
292     uint16_t     i_tag;
293     vlc_fourcc_t i_fourcc;
294     const char  *psz_name;
295 }
296 wave_format_tag_to_fourcc[] =
297 {
298     { WAVE_FORMAT_PCM,        VLC_FOURCC( 'a', 'r', 'a', 'w' ), "Raw audio" },
299     { WAVE_FORMAT_ADPCM,      VLC_FOURCC( 'm', 's', 0x00,0x02), "ADPCM" },
300     { WAVE_FORMAT_IEEE_FLOAT, VLC_FOURCC( 'a', 'f', 'l', 't' ), "IEEE Float audio" },
301     { WAVE_FORMAT_ALAW,       VLC_FOURCC( 'a', 'l', 'a', 'w' ), "A-Law" },
302     { WAVE_FORMAT_MULAW,      VLC_FOURCC( 'm', 'l', 'a', 'w' ), "Mu-Law" },
303     { WAVE_FORMAT_IMA_ADPCM,  VLC_FOURCC( 'm', 's', 0x00,0x11), "Ima-ADPCM" },
304     { WAVE_FORMAT_G726,       VLC_FOURCC( 'g', '7', '2', '6' ), "G.726 ADPCM" },
305     { WAVE_FORMAT_MPEGLAYER3, VLC_FOURCC( 'm', 'p', 'g', 'a' ), "Mpeg Audio" },
306     { WAVE_FORMAT_MPEG,       VLC_FOURCC( 'm', 'p', 'g', 'a' ), "Mpeg Audio" },
307     { WAVE_FORMAT_A52,        VLC_FOURCC( 'a', '5', '2', ' ' ), "A/52" },
308     { WAVE_FORMAT_WMA1,       VLC_FOURCC( 'w', 'm', 'a', '1' ), "Window Media Audio v1" },
309     { WAVE_FORMAT_WMA2,       VLC_FOURCC( 'w', 'm', 'a', '2' ), "Window Media Audio v2" },
310     { WAVE_FORMAT_WMA2,       VLC_FOURCC( 'w', 'm', 'a', ' ' ), "Window Media Audio v2" },
311     { WAVE_FORMAT_WMAP,       VLC_FOURCC( 'w', 'm', 'a', 'p' ), "Window Media Audio 9 Professional" },
312     { WAVE_FORMAT_WMAL,       VLC_FOURCC( 'w', 'm', 'a', 'l' ), "Window Media Audio 9 Lossless" },
313     { WAVE_FORMAT_WMAS,       VLC_FOURCC( 'w', 'm', 'a', 's' ), "Window Media Audio 9 Speech" },
314     { WAVE_FORMAT_DK3,        VLC_FOURCC( 'm', 's', 0x00,0x61), "Duck DK3" },
315     { WAVE_FORMAT_DK4,        VLC_FOURCC( 'm', 's', 0x00,0x62), "Duck DK4" },
316     { WAVE_FORMAT_DTS,        VLC_FOURCC( 'd', 't', 's', ' ' ), "DTS Coherent Acoustics" },
317     { WAVE_FORMAT_DTS_MS,     VLC_FOURCC( 'd', 't', 's', ' ' ), "DTS Coherent Acoustics" },
318     { WAVE_FORMAT_DIVIO_AAC,  VLC_FOURCC( 'm', 'p', '4', 'a' ), "MPEG-4 Audio (Divio)" },
319     { WAVE_FORMAT_AAC,        VLC_FOURCC( 'm', 'p', '4', 'a' ), "MPEG-4 Audio" },
320     { WAVE_FORMAT_VORB_1,     VLC_FOURCC( 'v', 'o', 'r', '1' ), "Vorbis 1 Audio" },
321     { WAVE_FORMAT_VORB_1PLUS, VLC_FOURCC( 'v', 'o', '1', '+' ), "Vorbis 1+ Audio" },
322     { WAVE_FORMAT_VORB_2,     VLC_FOURCC( 'v', 'o', 'r', '2' ), "Vorbis 2 Audio" },
323     { WAVE_FORMAT_VORB_2PLUS, VLC_FOURCC( 'v', 'o', '2', '+' ), "Vorbis 2+ Audio" },
324     { WAVE_FORMAT_VORB_3,     VLC_FOURCC( 'v', 'o', 'r', '3' ), "Vorbis 3 Audio" },
325     { WAVE_FORMAT_VORB_3PLUS, VLC_FOURCC( 'v', 'o', '3', '+' ), "Vorbis 3+ Audio" },
326     { WAVE_FORMAT_SPEEX,      VLC_FOURCC( 's', 'p', 'x', ' ' ), "Speex Audio" },
327     { WAVE_FORMAT_UNKNOWN,    VLC_FOURCC( 'u', 'n', 'd', 'f' ), "Unknown" }
328 };
329
330 static inline void wf_tag_to_fourcc( uint16_t i_tag, vlc_fourcc_t *fcc,
331                                      const char **ppsz_name )
332 {
333     int i;
334     for( i = 0; wave_format_tag_to_fourcc[i].i_tag != 0; i++ )
335     {
336         if( wave_format_tag_to_fourcc[i].i_tag == i_tag ) break;
337     }
338     if( fcc ) *fcc = wave_format_tag_to_fourcc[i].i_fourcc;
339     if( ppsz_name ) *ppsz_name = wave_format_tag_to_fourcc[i].psz_name;
340 }
341
342 static inline void fourcc_to_wf_tag( vlc_fourcc_t fcc, uint16_t *pi_tag )
343 {
344     int i;
345     for( i = 0; wave_format_tag_to_fourcc[i].i_tag != 0; i++ )
346     {
347         if( wave_format_tag_to_fourcc[i].i_fourcc == fcc ) break;
348     }
349     if( pi_tag ) *pi_tag = wave_format_tag_to_fourcc[i].i_tag;
350 }
351
352 /* If wFormatTag is WAVEFORMATEXTENSIBLE, we must look at the SubFormat tag
353  * to determine the actual format.  Microsoft has stopped giving out wFormatTag
354  * assignments in lieu of letting 3rd parties generate their own GUIDs
355  */
356 static struct
357 {
358     GUID         guid_tag;
359     vlc_fourcc_t i_fourcc;
360     const char  *psz_name;
361 }
362 sub_format_tag_to_fourcc[] =
363 {
364     { _KSDATAFORMAT_SUBTYPE_PCM_, VLC_FOURCC( 'p', 'c', 'm', ' ' ), "PCM" },
365     { _KSDATAFORMAT_SUBTYPE_UNKNOWN_, VLC_FOURCC( 'u', 'n', 'd', 'f' ), "Unknown" }
366 };
367
368 /* compares two GUIDs, returns 1 if identical, 0 otherwise */
369 static inline int guidcmp( const GUID *s1, const GUID *s2 )
370 {
371     return( s1->Data1 == s2->Data1 && s1->Data2 == s2->Data2 &&
372             s1->Data3 == s2->Data3 && !memcmp( s1->Data4, s2->Data4, 8 ) );
373 }
374
375 static inline void sf_tag_to_fourcc( GUID *guid_tag,
376                                      vlc_fourcc_t *fcc, const char **ppsz_name )
377 {
378     int i;
379
380     for( i = 0; !guidcmp( &sub_format_tag_to_fourcc[i].guid_tag, 
381                           &KSDATAFORMAT_SUBTYPE_UNKNOWN ); i++ )
382     {
383         if( guidcmp( &sub_format_tag_to_fourcc[i].guid_tag, guid_tag ) ) break;
384     }
385     if( fcc ) *fcc = sub_format_tag_to_fourcc[i].i_fourcc;
386     if( ppsz_name ) *ppsz_name = sub_format_tag_to_fourcc[i].psz_name;
387 }
388
389 /**
390  * Structure to hold information concerning subtitles.
391  * Used between demuxers and decoders of subtitles.
392  */
393 typedef struct es_sys_t
394 {
395     char               *psz_header; /* for 'ssa ' and 'subt' */
396
397     /* for spudec */
398     unsigned int        i_orig_height;
399     unsigned int        i_orig_width;
400     unsigned int        i_origin_x;
401     unsigned int        i_origin_y;
402     unsigned int        i_scale_h;
403     unsigned int        i_scale_v;
404     unsigned int        i_alpha;
405     vlc_bool_t          b_smooth;
406     mtime_t             i_fade_in;
407     mtime_t             i_fade_out;
408     unsigned int        i_align;
409     mtime_t             i_time_offset;
410     vlc_bool_t          b_forced_subs;
411     unsigned int        palette[16];
412     unsigned int        colors[4];
413
414 } subtitle_data_t;
415
416 #endif /* "codecs.h" */