playlist_pls: fix use after free (can be triggered by some invalid shoutcast playlist...
[vlc/asuraparaju-public.git] / include / vlc_codecs.h
blobd3a5a555da754f2761e6e9d74717147888533486
1 /*****************************************************************************
2 * codecs.h: codec related structures needed by the demuxers and decoders
3 *****************************************************************************
4 * Copyright (C) 1999-2001 the VideoLAN team
5 * $Id$
7 * Author: Gildas Bazin <gbazin@videolan.org>
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.
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.
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 *****************************************************************************/
24 #ifndef VLC_CODECS_H
25 #define VLC_CODECS_H 1
27 #include <vlc_fourcc.h>
28 /**
29 * \file
30 * This file defines codec related structures needed by the demuxers and decoders
33 /* Structures exported to the demuxers and decoders */
35 #if !(defined _GUID_DEFINED || defined GUID_DEFINED)
36 #define GUID_DEFINED
37 typedef struct _GUID
39 uint32_t Data1;
40 uint16_t Data2;
41 uint16_t Data3;
42 uint8_t Data4[8];
43 } GUID, *REFGUID, *LPGUID;
44 #endif /* GUID_DEFINED */
46 #ifdef HAVE_ATTRIBUTE_PACKED
47 # define ATTR_PACKED __attribute__((__packed__))
48 #elif defined(__SUNPRO_C)
49 # pragma pack(1)
50 # define ATTR_PACKED
51 #else
52 # error FIXME
53 #endif
55 #ifndef _WAVEFORMATEX_
56 #define _WAVEFORMATEX_
57 typedef struct
58 ATTR_PACKED
59 _WAVEFORMATEX {
60 uint16_t wFormatTag;
61 uint16_t nChannels;
62 uint32_t nSamplesPerSec;
63 uint32_t nAvgBytesPerSec;
64 uint16_t nBlockAlign;
65 uint16_t wBitsPerSample;
66 uint16_t cbSize;
67 } WAVEFORMATEX, *PWAVEFORMATEX, *NPWAVEFORMATEX, *LPWAVEFORMATEX;
68 #endif /* _WAVEFORMATEX_ */
70 #ifndef _WAVEFORMATEXTENSIBLE_
71 #define _WAVEFORMATEXTENSIBLE_
72 typedef struct
73 ATTR_PACKED
74 _WAVEFORMATEXTENSIBLE {
75 WAVEFORMATEX Format;
76 union {
77 uint16_t wValidBitsPerSample;
78 uint16_t wSamplesPerBlock;
79 uint16_t wReserved;
80 } Samples;
81 uint32_t dwChannelMask;
82 GUID SubFormat;
83 } WAVEFORMATEXTENSIBLE, *PWAVEFORMATEXTENSIBLE;
84 #endif /* _WAVEFORMATEXTENSIBLE_ */
86 #ifndef _WAVEHEADER_
87 #define _WAVEHEADER_
88 typedef struct
89 ATTR_PACKED
90 _WAVEHEADER {
91 uint32_t MainChunkID;
92 uint32_t Length;
93 uint32_t ChunkTypeID;
94 uint32_t SubChunkID;
95 uint32_t SubChunkLength;
96 uint16_t Format;
97 uint16_t Modus;
98 uint32_t SampleFreq;
99 uint32_t BytesPerSec;
100 uint16_t BytesPerSample;
101 uint16_t BitsPerSample;
102 uint32_t DataChunkID;
103 uint32_t DataLength;
104 } WAVEHEADER;
105 #endif /* _WAVEHEADER_ */
107 #if !defined(_BITMAPINFOHEADER_) && !defined(WIN32)
108 #define _BITMAPINFOHEADER_
109 typedef struct
110 ATTR_PACKED
112 uint32_t biSize;
113 uint32_t biWidth;
114 uint32_t biHeight;
115 uint16_t biPlanes;
116 uint16_t biBitCount;
117 uint32_t biCompression;
118 uint32_t biSizeImage;
119 uint32_t biXPelsPerMeter;
120 uint32_t biYPelsPerMeter;
121 uint32_t biClrUsed;
122 uint32_t biClrImportant;
123 } BITMAPINFOHEADER, *PBITMAPINFOHEADER, *LPBITMAPINFOHEADER;
125 typedef struct
126 ATTR_PACKED
128 BITMAPINFOHEADER bmiHeader;
129 int bmiColors[1];
130 } BITMAPINFO, *LPBITMAPINFO;
131 #endif
133 #ifndef _RECT32_
134 #define _RECT32_
135 typedef struct
136 ATTR_PACKED
138 int left, top, right, bottom;
139 } RECT32;
140 #endif
142 #ifndef _REFERENCE_TIME_
143 #define _REFERENCE_TIME_
144 typedef int64_t REFERENCE_TIME;
145 #endif
147 #ifndef _VIDEOINFOHEADER_
148 #define _VIDEOINFOHEADER_
149 typedef struct
150 ATTR_PACKED
152 RECT32 rcSource;
153 RECT32 rcTarget;
154 uint32_t dwBitRate;
155 uint32_t dwBitErrorRate;
156 REFERENCE_TIME AvgTimePerFrame;
157 BITMAPINFOHEADER bmiHeader;
158 } VIDEOINFOHEADER;
159 #endif
161 #ifndef _RGBQUAD_
162 #define _RGBQUAD_
163 typedef struct
164 ATTR_PACKED
166 uint8_t rgbBlue;
167 uint8_t rgbGreen;
168 uint8_t rgbRed;
169 uint8_t rgbReserved;
170 } RGBQUAD1;
171 #endif
173 #ifndef _TRUECOLORINFO_
174 #define _TRUECOLORINFO_
175 typedef struct
176 ATTR_PACKED
178 uint32_t dwBitMasks[3];
179 RGBQUAD1 bmiColors[256];
180 } TRUECOLORINFO;
181 #endif
183 #ifndef _VIDEOINFO_
184 #define _VIDEOINFO_
185 typedef struct
186 ATTR_PACKED
188 RECT32 rcSource;
189 RECT32 rcTarget;
190 uint32_t dwBitRate;
191 uint32_t dwBitErrorRate;
192 REFERENCE_TIME AvgTimePerFrame;
193 BITMAPINFOHEADER bmiHeader;
195 union
197 RGBQUAD1 bmiColors[256]; /* Colour palette */
198 uint32_t dwBitMasks[3]; /* True colour masks */
199 TRUECOLORINFO TrueColorInfo; /* Both of the above */
202 } VIDEOINFO;
203 #endif
205 #if defined(__SUNPRO_C)
206 # pragma pack()
207 #endif
209 /* WAVE format wFormatTag IDs */
210 #define WAVE_FORMAT_UNKNOWN 0x0000 /* Microsoft Corporation */
211 #define WAVE_FORMAT_PCM 0x0001 /* Microsoft Corporation */
212 #define WAVE_FORMAT_ADPCM 0x0002 /* Microsoft Corporation */
213 #define WAVE_FORMAT_IEEE_FLOAT 0x0003 /* Microsoft Corporation */
214 #define WAVE_FORMAT_ALAW 0x0006 /* Microsoft Corporation */
215 #define WAVE_FORMAT_MULAW 0x0007 /* Microsoft Corporation */
216 #define WAVE_FORMAT_DTS_MS 0x0008 /* Microsoft Corporation */
217 #define WAVE_FORMAT_WMAS 0x000a /* WMA 9 Speech */
218 #define WAVE_FORMAT_IMA_ADPCM 0x0011 /* Intel Corporation */
219 #define WAVE_FORMAT_TRUESPEECH 0x0022 /* TrueSpeech */
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 */
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 #define WAVE_FORMAT_FFMPEG_AAC 0x706D
237 /* Need to check these */
238 #define WAVE_FORMAT_DK3 0x0061
239 #define WAVE_FORMAT_DK4 0x0062
241 /* At least FFmpeg use that ID: from libavformat/riff.c ('Vo' == 0x566f)
242 * { CODEC_ID_VORBIS, ('V'<<8)+'o' }, //HACK/FIXME, does vorbis in WAV/AVI have an (in)official id?
244 #define WAVE_FORMAT_VORBIS 0x566f
246 /* It seems that these IDs are used by braindead & obsolete VorbisACM encoder
247 * (Windows only)
248 * A few info is available except VorbisACM source (remember, Windows only)
249 * (available on http://svn.xiph.org), but it seems that vo3+ at least is
250 * made of Vorbis data encapsulated in Ogg container...
252 #define WAVE_FORMAT_VORB_1 0x674f
253 #define WAVE_FORMAT_VORB_2 0x6750
254 #define WAVE_FORMAT_VORB_3 0x6751
255 #define WAVE_FORMAT_VORB_1PLUS 0x676f
256 #define WAVE_FORMAT_VORB_2PLUS 0x6770
257 #define WAVE_FORMAT_VORB_3PLUS 0x6771
259 #define WAVE_FORMAT_SPEEX 0xa109 /* Speex audio */
262 #if !defined(WAVE_FORMAT_EXTENSIBLE)
263 #define WAVE_FORMAT_EXTENSIBLE 0xFFFE /* Microsoft */
264 #endif
266 /* GUID SubFormat IDs */
267 /* We need both b/c const variables are not compile-time constants in C, giving
268 * us an error if we use the const GUID in an enum */
270 #ifndef _KSDATAFORMAT_SUBTYPE_PCM_
271 #define _KSDATAFORMAT_SUBTYPE_PCM_ {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}}
272 static const GUID VLC_KSDATAFORMAT_SUBTYPE_PCM = {0xE923AABF, 0xCB58, 0x4471, {0xA1, 0x19, 0xFF, 0xFA, 0x01, 0xE4, 0xCE, 0x62}};
273 #define KSDATAFORMAT_SUBTYPE_PCM VLC_KSDATAFORMAT_SUBTYPE_PCM
274 #endif
276 #ifndef _KSDATAFORMAT_SUBTYPE_UNKNOWN_
277 #define _KSDATAFORMAT_SUBTYPE_UNKNOWN_ {0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}
278 static const GUID VLC_KSDATAFORMAT_SUBTYPE_UNKNOWN = {0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
279 #define KSDATAFORMAT_SUBTYPE_UNKNOWN VLC_KSDATAFORMAT_SUBTYPE_UNKNOWN
280 #endif
282 /* Microsoft speaker definitions */
283 #define WAVE_SPEAKER_FRONT_LEFT 0x1
284 #define WAVE_SPEAKER_FRONT_RIGHT 0x2
285 #define WAVE_SPEAKER_FRONT_CENTER 0x4
286 #define WAVE_SPEAKER_LOW_FREQUENCY 0x8
287 #define WAVE_SPEAKER_BACK_LEFT 0x10
288 #define WAVE_SPEAKER_BACK_RIGHT 0x20
289 #define WAVE_SPEAKER_FRONT_LEFT_OF_CENTER 0x40
290 #define WAVE_SPEAKER_FRONT_RIGHT_OF_CENTER 0x80
291 #define WAVE_SPEAKER_BACK_CENTER 0x100
292 #define WAVE_SPEAKER_SIDE_LEFT 0x200
293 #define WAVE_SPEAKER_SIDE_RIGHT 0x400
294 #define WAVE_SPEAKER_TOP_CENTER 0x800
295 #define WAVE_SPEAKER_TOP_FRONT_LEFT 0x1000
296 #define WAVE_SPEAKER_TOP_FRONT_CENTER 0x2000
297 #define WAVE_SPEAKER_TOP_FRONT_RIGHT 0x4000
298 #define WAVE_SPEAKER_TOP_BACK_LEFT 0x8000
299 #define WAVE_SPEAKER_TOP_BACK_CENTER 0x10000
300 #define WAVE_SPEAKER_TOP_BACK_RIGHT 0x20000
301 #define WAVE_SPEAKER_RESERVED 0x80000000
303 static const struct
305 uint16_t i_tag;
306 vlc_fourcc_t i_fourcc;
307 const char *psz_name;
309 wave_format_tag_to_fourcc[] =
311 { WAVE_FORMAT_PCM, VLC_FOURCC( 'a', 'r', 'a', 'w' ), "Raw audio" },
312 { WAVE_FORMAT_ADPCM, VLC_CODEC_ADPCM_MS, "ADPCM" },
313 { WAVE_FORMAT_IEEE_FLOAT, VLC_FOURCC( 'a', 'f', 'l', 't' ), "IEEE Float audio" },
314 { WAVE_FORMAT_ALAW, VLC_CODEC_ALAW, "A-Law" },
315 { WAVE_FORMAT_MULAW, VLC_CODEC_MULAW, "Mu-Law" },
316 { WAVE_FORMAT_IMA_ADPCM, VLC_CODEC_ADPCM_IMA_WAV, "Ima-ADPCM" },
317 { WAVE_FORMAT_TRUESPEECH, VLC_FOURCC(0x22, 0x0, 0x0, 0x0 ), "Truespeech" },
318 { WAVE_FORMAT_GSM610, VLC_CODEC_GSM_MS, "Microsoft WAV GSM" },
319 { WAVE_FORMAT_G726, VLC_CODEC_ADPCM_G726, "G.726 ADPCM" },
320 { WAVE_FORMAT_MPEGLAYER3, VLC_CODEC_MPGA, "Mpeg Audio" },
321 { WAVE_FORMAT_MPEG, VLC_CODEC_MPGA, "Mpeg Audio" },
322 { WAVE_FORMAT_A52, VLC_CODEC_A52, "A/52" },
323 { WAVE_FORMAT_WMA1, VLC_CODEC_WMA1, "Window Media Audio v1" },
324 { WAVE_FORMAT_WMA2, VLC_CODEC_WMA2, "Window Media Audio v2" },
325 { WAVE_FORMAT_WMAP, VLC_CODEC_WMAP, "Window Media Audio 9 Professional" },
326 { WAVE_FORMAT_WMAL, VLC_CODEC_WMAL, "Window Media Audio 9 Lossless" },
327 { WAVE_FORMAT_WMAS, VLC_CODEC_WMAS, "Window Media Audio 9 Speech" },
328 { WAVE_FORMAT_DK3, VLC_FOURCC( 'm', 's', 0x00,0x61), "Duck DK3" },
329 { WAVE_FORMAT_DK4, VLC_FOURCC( 'm', 's', 0x00,0x62), "Duck DK4" },
330 { WAVE_FORMAT_DTS, VLC_CODEC_DTS, "DTS Coherent Acoustics" },
331 { WAVE_FORMAT_DTS_MS, VLC_CODEC_DTS, "DTS Coherent Acoustics" },
332 { WAVE_FORMAT_DIVIO_AAC, VLC_CODEC_MP4A, "MPEG-4 Audio (Divio)" },
333 { WAVE_FORMAT_AAC, VLC_CODEC_MP4A, "MPEG-4 Audio" },
334 { WAVE_FORMAT_FFMPEG_AAC, VLC_CODEC_MP4A, "MPEG-4 Audio" },
335 { WAVE_FORMAT_VORBIS, VLC_CODEC_VORBIS, "Vorbis Audio" },
336 { WAVE_FORMAT_VORB_1, VLC_FOURCC( 'v', 'o', 'r', '1' ), "Vorbis 1 Audio" },
337 { WAVE_FORMAT_VORB_1PLUS, VLC_FOURCC( 'v', 'o', '1', '+' ), "Vorbis 1+ Audio" },
338 { WAVE_FORMAT_VORB_2, VLC_FOURCC( 'v', 'o', 'r', '2' ), "Vorbis 2 Audio" },
339 { WAVE_FORMAT_VORB_2PLUS, VLC_FOURCC( 'v', 'o', '2', '+' ), "Vorbis 2+ Audio" },
340 { WAVE_FORMAT_VORB_3, VLC_FOURCC( 'v', 'o', 'r', '3' ), "Vorbis 3 Audio" },
341 { WAVE_FORMAT_VORB_3PLUS, VLC_FOURCC( 'v', 'o', '3', '+' ), "Vorbis 3+ Audio" },
342 { WAVE_FORMAT_SPEEX, VLC_CODEC_SPEEX, "Speex Audio" },
343 { WAVE_FORMAT_UNKNOWN, VLC_FOURCC( 'u', 'n', 'd', 'f' ), "Unknown" }
346 static inline void wf_tag_to_fourcc( uint16_t i_tag, vlc_fourcc_t *fcc,
347 const char **ppsz_name )
349 int i;
350 for( i = 0; wave_format_tag_to_fourcc[i].i_tag != 0; i++ )
352 if( wave_format_tag_to_fourcc[i].i_tag == i_tag ) break;
354 if( fcc ) *fcc = wave_format_tag_to_fourcc[i].i_fourcc;
355 if( ppsz_name ) *ppsz_name = wave_format_tag_to_fourcc[i].psz_name;
358 static inline void fourcc_to_wf_tag( vlc_fourcc_t fcc, uint16_t *pi_tag )
360 int i;
361 for( i = 0; wave_format_tag_to_fourcc[i].i_tag != 0; i++ )
363 if( wave_format_tag_to_fourcc[i].i_fourcc == fcc ) break;
365 if( pi_tag ) *pi_tag = wave_format_tag_to_fourcc[i].i_tag;
368 /* If wFormatTag is WAVEFORMATEXTENSIBLE, we must look at the SubFormat tag
369 * to determine the actual format. Microsoft has stopped giving out wFormatTag
370 * assignments in lieu of letting 3rd parties generate their own GUIDs
372 static const struct
374 GUID guid_tag;
375 vlc_fourcc_t i_fourcc;
376 const char *psz_name;
378 sub_format_tag_to_fourcc[] =
380 { _KSDATAFORMAT_SUBTYPE_PCM_, VLC_FOURCC( 'p', 'c', 'm', ' ' ), "PCM" },
381 { _KSDATAFORMAT_SUBTYPE_UNKNOWN_, VLC_FOURCC( 'u', 'n', 'd', 'f' ), "Unknown" }
384 /* compares two GUIDs, returns 1 if identical, 0 otherwise */
385 static inline int guidcmp( const GUID *s1, const GUID *s2 )
387 return( s1->Data1 == s2->Data1 && s1->Data2 == s2->Data2 &&
388 s1->Data3 == s2->Data3 && !memcmp( s1->Data4, s2->Data4, 8 ) );
391 static inline void sf_tag_to_fourcc( GUID *guid_tag,
392 vlc_fourcc_t *fcc, const char **ppsz_name )
394 int i;
396 for( i = 0; !guidcmp( &sub_format_tag_to_fourcc[i].guid_tag,
397 &KSDATAFORMAT_SUBTYPE_UNKNOWN ); i++ )
399 if( guidcmp( &sub_format_tag_to_fourcc[i].guid_tag, guid_tag ) ) break;
401 if( fcc ) *fcc = sub_format_tag_to_fourcc[i].i_fourcc;
402 if( ppsz_name ) *ppsz_name = sub_format_tag_to_fourcc[i].psz_name;
405 #endif /* "codecs.h" */