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