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