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