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