codecs.h 13.3 KB
Newer Older
gbazin's avatar
 
gbazin committed
1 2 3
/*****************************************************************************
 * codecs.h: codec related structures needed by the demuxers and decoders
 *****************************************************************************
4
 * Copyright (C) 1999-2001 the VideoLAN team
hartman's avatar
hartman committed
5
 * $Id$
gbazin's avatar
 
gbazin committed
6
 *
7
 * Author: Gildas Bazin <gbazin@videolan.org>
gbazin's avatar
 
gbazin committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

#ifndef _VLC_CODECS_H
#define _VLC_CODECS_H 1

/* Structures exported to the demuxers and decoders */

gbazin's avatar
 
gbazin committed
29 30 31 32 33 34 35 36 37 38 39
#if !(defined _GUID_DEFINED || defined GUID_DEFINED)
#define GUID_DEFINED
typedef struct _GUID
{
    uint32_t Data1;
    uint16_t Data2;
    uint16_t Data3;
    uint8_t  Data4[8];
} GUID, *REFGUID, *LPGUID;
#endif /* GUID_DEFINED */

gbazin's avatar
 
gbazin committed
40 41
#ifndef _WAVEFORMATEX_
#define _WAVEFORMATEX_
42 43 44 45 46
typedef struct
#ifdef HAVE_ATTRIBUTE_PACKED
    __attribute__((__packed__))
#endif
_WAVEFORMATEX {
gbazin's avatar
 
gbazin committed
47 48 49 50 51 52 53 54 55 56
    uint16_t   wFormatTag;
    uint16_t   nChannels;
    uint32_t   nSamplesPerSec;
    uint32_t   nAvgBytesPerSec;
    uint16_t   nBlockAlign;
    uint16_t   wBitsPerSample;
    uint16_t   cbSize;
} WAVEFORMATEX, *PWAVEFORMATEX, *NPWAVEFORMATEX, *LPWAVEFORMATEX;
#endif /* _WAVEFORMATEX_ */

gbazin's avatar
 
gbazin committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
#ifndef _WAVEFORMATEXTENSIBLE_
#define _WAVEFORMATEXTENSIBLE_
typedef struct
#ifdef HAVE_ATTRIBUTE_PACKED
    __attribute__((__packed__))
#endif
_WAVEFORMATEXTENSIBLE {
    WAVEFORMATEX Format;
    union {
        uint16_t wValidBitsPerSample;
        uint16_t wSamplesPerBlock;
        uint16_t wReserved;
    } Samples;
    uint32_t     dwChannelMask;
    GUID SubFormat;
} WAVEFORMATEXTENSIBLE, *PWAVEFORMATEXTENSIBLE;
#endif /* _WAVEFORMATEXTENSIBLE_ */

#ifndef _WAVEHEADER_
#define _WAVEHEADER_
typedef struct
#ifdef HAVE_ATTRIBUTE_PACKED
    __attribute__((__packed__))
#endif
_WAVEHEADER {
    uint32_t MainChunkID;
    uint32_t Length;
    uint32_t ChunkTypeID;
    uint32_t SubChunkID;
    uint32_t SubChunkLength;
    uint16_t Format;
    uint16_t Modus;
    uint32_t SampleFreq;
    uint32_t BytesPerSec;
    uint16_t BytesPerSample;
    uint16_t BitsPerSample;
    uint32_t DataChunkID;
    uint32_t DataLength;
} WAVEHEADER;
#endif /* _WAVEHEADER_ */

gbazin's avatar
 
gbazin committed
98
#if !defined(_BITMAPINFOHEADER_) && !defined(WIN32)
gbazin's avatar
 
gbazin committed
99
#define _BITMAPINFOHEADER_
100 101 102 103
typedef struct
#ifdef HAVE_ATTRIBUTE_PACKED
    __attribute__((__packed__))
#endif
gbazin's avatar
 
gbazin committed
104 105 106 107 108 109 110 111 112 113 114 115 116
{
    uint32_t   biSize;
    uint32_t   biWidth;
    uint32_t   biHeight;
    uint16_t   biPlanes;
    uint16_t   biBitCount;
    uint32_t   biCompression;
    uint32_t   biSizeImage;
    uint32_t   biXPelsPerMeter;
    uint32_t   biYPelsPerMeter;
    uint32_t   biClrUsed;
    uint32_t   biClrImportant;
} BITMAPINFOHEADER, *PBITMAPINFOHEADER, *LPBITMAPINFOHEADER;
117 118 119 120 121 122

typedef struct
#ifdef HAVE_ATTRIBUTE_PACKED
    __attribute__((__packed__))
#endif
{
gbazin's avatar
 
gbazin committed
123 124 125 126 127
    BITMAPINFOHEADER bmiHeader;
    int        bmiColors[1];
} BITMAPINFO, *LPBITMAPINFO;
#endif

128 129
#ifndef _RECT32_
#define _RECT32_
130
typedef struct
131 132 133 134 135 136
#ifdef HAVE_ATTRIBUTE_PACKED
    __attribute__((__packed__))
#endif
{
    int left, top, right, bottom;
} RECT32;
137
#endif
138

139 140
#ifndef _REFERENCE_TIME_
#define _REFERENCE_TIME_
141
typedef int64_t REFERENCE_TIME;
142
#endif
143

144 145
#ifndef _VIDEOINFOHEADER_
#define _VIDEOINFOHEADER_
146 147 148 149
typedef struct
#ifdef HAVE_ATTRIBUTE_PACKED
    __attribute__((__packed__))
#endif
150
{
151 152 153 154 155 156 157
    RECT32            rcSource;
    RECT32            rcTarget;
    uint32_t          dwBitRate;
    uint32_t          dwBitErrorRate;
    REFERENCE_TIME    AvgTimePerFrame;
    BITMAPINFOHEADER  bmiHeader;
} VIDEOINFOHEADER;
158
#endif
159

160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
#ifndef _RGBQUAD_
#define _RGBQUAD_
typedef struct
#ifdef HAVE_ATTRIBUTE_PACKED
    __attribute__((__packed__))
#endif
{
    uint8_t rgbBlue;
    uint8_t rgbGreen;
    uint8_t rgbRed;
    uint8_t rgbReserved;
} RGBQUAD1;
#endif

#ifndef _TRUECOLORINFO_
#define _TRUECOLORINFO_
typedef struct
#ifdef HAVE_ATTRIBUTE_PACKED
    __attribute__((__packed__))
#endif
{
    uint32_t dwBitMasks[3];
    RGBQUAD1 bmiColors[256];
} TRUECOLORINFO;
#endif

#ifndef _VIDEOINFO_
#define _VIDEOINFO_
typedef struct
#ifdef HAVE_ATTRIBUTE_PACKED
    __attribute__((__packed__))
#endif
{
    RECT32            rcSource;
    RECT32            rcTarget;
    uint32_t          dwBitRate;
    uint32_t          dwBitErrorRate;
    REFERENCE_TIME    AvgTimePerFrame;
    BITMAPINFOHEADER  bmiHeader;

    union
    {
        RGBQUAD1 bmiColors[256]; /* Colour palette */
        uint32_t dwBitMasks[3]; /* True colour masks */
        TRUECOLORINFO TrueColorInfo; /* Both of the above */
    };

} VIDEOINFO;
#endif

gbazin's avatar
 
gbazin committed
210
/* WAVE format wFormatTag IDs */
hartman's avatar
hartman committed
211 212 213 214 215 216
#define WAVE_FORMAT_UNKNOWN             0x0000 /* Microsoft Corporation */
#define WAVE_FORMAT_PCM                 0x0001 /* Microsoft Corporation */
#define WAVE_FORMAT_ADPCM               0x0002 /* Microsoft Corporation */
#define WAVE_FORMAT_IEEE_FLOAT          0x0003 /* Microsoft Corporation */
#define WAVE_FORMAT_ALAW                0x0006 /* Microsoft Corporation */
#define WAVE_FORMAT_MULAW               0x0007 /* Microsoft Corporation */
hartman's avatar
hartman committed
217
#define WAVE_FORMAT_DTS_MS              0x0008 /* Microsoft Corporation */
hartman's avatar
hartman committed
218 219 220
#define WAVE_FORMAT_IMA_ADPCM           0x0011 /* Intel Corporation */
#define WAVE_FORMAT_GSM610              0x0031 /* Microsoft Corporation */
#define WAVE_FORMAT_MSNAUDIO            0x0032 /* Microsoft Corporation */
hartman's avatar
hartman committed
221
#define WAVE_FORMAT_G726                0x0045 /* ITU-T standard  */
hartman's avatar
hartman committed
222 223 224
#define WAVE_FORMAT_MPEG                0x0050 /* Microsoft Corporation */
#define WAVE_FORMAT_MPEGLAYER3          0x0055 /* ISO/MPEG Layer3 Format Tag */
#define WAVE_FORMAT_DOLBY_AC3_SPDIF     0x0092 /* Sonic Foundry */
gbazin's avatar
 
gbazin committed
225

Sam Hocevar's avatar
Sam Hocevar committed
226
#define WAVE_FORMAT_A52                 0x2000
hartman's avatar
hartman committed
227
#define WAVE_FORMAT_DTS                 0x2001
228 229 230 231
#define WAVE_FORMAT_WMA1                0x0160 /* WMA version 1 */
#define WAVE_FORMAT_WMA2                0x0161 /* WMA (v2) 7, 8, 9 Series */
#define WAVE_FORMAT_WMAP                0x0162 /* WMA 9 Professional */
#define WAVE_FORMAT_WMAL                0x0163 /* WMA 9 Lossless */
232
#define WAVE_FORMAT_DIVIO_AAC           0x4143
233
#define WAVE_FORMAT_AAC                 0x00FF
gbazin's avatar
 
gbazin committed
234

235
/* Need to check these */
Sam Hocevar's avatar
Sam Hocevar committed
236 237
#define WAVE_FORMAT_DK3                 0x0061
#define WAVE_FORMAT_DK4                 0x0062
238

gbazin's avatar
 
gbazin committed
239
#if !defined(WAVE_FORMAT_EXTENSIBLE)
gbazin's avatar
 
gbazin committed
240
#define WAVE_FORMAT_EXTENSIBLE          0xFFFE /* Microsoft */
gbazin's avatar
 
gbazin committed
241 242
#endif

243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
/* GUID SubFormat IDs */
/* We need both b/c const variables are not compile-time constants in C, giving
 * us an error if we use the const GUID in an enum */

#ifndef _KSDATAFORMAT_SUBTYPE_PCM_
#define _KSDATAFORMAT_SUBTYPE_PCM_ {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}}
static const GUID VLC_KSDATAFORMAT_SUBTYPE_PCM = {0xE923AABF, 0xCB58, 0x4471, {0xA1, 0x19, 0xFF, 0xFA, 0x01, 0xE4, 0xCE, 0x62}};
#define KSDATAFORMAT_SUBTYPE_PCM VLC_KSDATAFORMAT_SUBTYPE_PCM
#endif

#ifndef _KSDATAFORMAT_SUBTYPE_UNKNOWN_ 
#define _KSDATAFORMAT_SUBTYPE_UNKNOWN_ {0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}
static const GUID VLC_KSDATAFORMAT_SUBTYPE_UNKNOWN = {0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
#define KSDATAFORMAT_SUBTYPE_UNKNOWN VLC_KSDATAFORMAT_SUBTYPE_UNKNOWN
#endif

gbazin's avatar
 
gbazin committed
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
/* Microsoft speaker definitions */
#define WAVE_SPEAKER_FRONT_LEFT             0x1
#define WAVE_SPEAKER_FRONT_RIGHT            0x2
#define WAVE_SPEAKER_FRONT_CENTER           0x4
#define WAVE_SPEAKER_LOW_FREQUENCY          0x8
#define WAVE_SPEAKER_BACK_LEFT              0x10
#define WAVE_SPEAKER_BACK_RIGHT             0x20
#define WAVE_SPEAKER_FRONT_LEFT_OF_CENTER   0x40
#define WAVE_SPEAKER_FRONT_RIGHT_OF_CENTER  0x80
#define WAVE_SPEAKER_BACK_CENTER            0x100
#define WAVE_SPEAKER_SIDE_LEFT              0x200
#define WAVE_SPEAKER_SIDE_RIGHT             0x400
#define WAVE_SPEAKER_TOP_CENTER             0x800
#define WAVE_SPEAKER_TOP_FRONT_LEFT         0x1000
#define WAVE_SPEAKER_TOP_FRONT_CENTER       0x2000
#define WAVE_SPEAKER_TOP_FRONT_RIGHT        0x4000
#define WAVE_SPEAKER_TOP_BACK_LEFT          0x8000
#define WAVE_SPEAKER_TOP_BACK_CENTER        0x10000
#define WAVE_SPEAKER_TOP_BACK_RIGHT         0x20000
#define WAVE_SPEAKER_RESERVED               0x80000000

280 281 282 283 284 285 286 287 288 289
static struct
{
    uint16_t     i_tag;
    vlc_fourcc_t i_fourcc;
    char         *psz_name;
}
wave_format_tag_to_fourcc[] =
{
    { WAVE_FORMAT_PCM,      VLC_FOURCC( 'a', 'r', 'a', 'w' ), "Raw audio" },
    { WAVE_FORMAT_ADPCM,    VLC_FOURCC( 'm', 's', 0x00,0x02), "Adpcm" },
gbazin's avatar
 
gbazin committed
290
    { WAVE_FORMAT_IEEE_FLOAT, VLC_FOURCC( 'a', 'f', 'l', 't' ), "IEEE Float audio" },
291 292 293
    { WAVE_FORMAT_ALAW,     VLC_FOURCC( 'a', 'l', 'a', 'w' ), "A-Law" },
    { WAVE_FORMAT_MULAW,    VLC_FOURCC( 'm', 'l', 'a', 'w' ), "Mu-Law" },
    { WAVE_FORMAT_IMA_ADPCM,VLC_FOURCC( 'm', 's', 0x00,0x11), "Ima-Adpcm" },
hartman's avatar
hartman committed
294
    { WAVE_FORMAT_G726,     VLC_FOURCC( 'g', '7', '2', '6' ), "G.726 Adpcm" },
295 296 297
    { WAVE_FORMAT_MPEGLAYER3,VLC_FOURCC('m', 'p', 'g', 'a' ), "Mpeg Audio" },
    { WAVE_FORMAT_MPEG,     VLC_FOURCC( 'm', 'p', 'g', 'a' ), "Mpeg Audio" },
    { WAVE_FORMAT_A52,      VLC_FOURCC( 'a', '5', '2', ' ' ), "A/52" },
298 299 300 301 302
    { WAVE_FORMAT_WMA1,     VLC_FOURCC( 'w', 'm', 'a', '1' ), "Window Media Audio v1" },
    { WAVE_FORMAT_WMA2,     VLC_FOURCC( 'w', 'm', 'a', '2' ), "Window Media Audio v2" },
    { WAVE_FORMAT_WMA2,     VLC_FOURCC( 'w', 'm', 'a', ' ' ), "Window Media Audio v2" },
    { WAVE_FORMAT_WMAP,     VLC_FOURCC( 'w', 'm', 'a', 'p' ), "Window Media Audio 9 Professional" },
    { WAVE_FORMAT_WMAL,     VLC_FOURCC( 'w', 'm', 'a', 'l' ), "Window Media Audio 9 Lossless" },
303 304
    { WAVE_FORMAT_DK3,      VLC_FOURCC( 'm', 's', 0x00,0x61), "Duck DK3" },
    { WAVE_FORMAT_DK4,      VLC_FOURCC( 'm', 's', 0x00,0x62), "Duck DK4" },
hartman's avatar
hartman committed
305 306
    { WAVE_FORMAT_DTS,      VLC_FOURCC( 'd', 't', 's', ' ' ), "DTS Coherent Acoustics" },
    { WAVE_FORMAT_DTS_MS,   VLC_FOURCC( 'd', 't', 's', ' ' ), "DTS Coherent Acoustics" },
307
    { WAVE_FORMAT_DIVIO_AAC,VLC_FOURCC( 'm', 'p', '4', 'a' ), "MPEG-4 Audio (Divio)" },
308
    { WAVE_FORMAT_AAC,      VLC_FOURCC( 'm', 'p', '4', 'a' ), "MPEG-4 Audio" },
309 310 311
    { WAVE_FORMAT_UNKNOWN,  VLC_FOURCC( 'u', 'n', 'd', 'f' ), "Unknown" }
};

312 313
static inline void wf_tag_to_fourcc( uint16_t i_tag, vlc_fourcc_t *fcc,
                                     char **ppsz_name )
314 315 316 317
{
    int i;
    for( i = 0; wave_format_tag_to_fourcc[i].i_tag != 0; i++ )
    {
318
        if( wave_format_tag_to_fourcc[i].i_tag == i_tag ) break;
319
    }
320 321 322 323 324 325 326 327
    if( fcc ) *fcc = wave_format_tag_to_fourcc[i].i_fourcc;
    if( ppsz_name ) *ppsz_name = wave_format_tag_to_fourcc[i].psz_name;
}

static inline void fourcc_to_wf_tag( vlc_fourcc_t fcc, uint16_t *pi_tag )
{
    int i;
    for( i = 0; wave_format_tag_to_fourcc[i].i_tag != 0; i++ )
328
    {
329
        if( wave_format_tag_to_fourcc[i].i_fourcc == fcc ) break;
330
    }
331
    if( pi_tag ) *pi_tag = wave_format_tag_to_fourcc[i].i_tag;
332 333
}

334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
/* If wFormatTag is WAVEFORMATEXTENSIBLE, we must look at the SubFormat tag
 * to determine the actual format.  Microsoft has stopped giving out wFormatTag
 * assignments in lieu of letting 3rd parties generate their own GUIDs
 */
static struct
{
    GUID         guid_tag;
    vlc_fourcc_t i_fourcc;
    char         *psz_name;
}
sub_format_tag_to_fourcc[] =
{
    { _KSDATAFORMAT_SUBTYPE_PCM_, VLC_FOURCC( 'p', 'c', 'm', ' ' ), "PCM" },
    { _KSDATAFORMAT_SUBTYPE_UNKNOWN_, VLC_FOURCC( 'u', 'n', 'd', 'f' ), "Unknown" }
};

/* compares two GUIDs, returns 1 if identical, 0 otherwise */
static inline int guidcmp( const GUID *s1, const GUID *s2 )
{
    return( s1->Data1 == s2->Data1 && s1->Data2 == s2->Data2 &&
            s1->Data3 == s2->Data3 && !memcmp( s1->Data4, s2->Data4, 8 ) );
}

static inline void sf_tag_to_fourcc( GUID *guid_tag,
                                     vlc_fourcc_t *fcc, char **ppsz_name )
{
    int i;

    for( i = 0; !guidcmp( &sub_format_tag_to_fourcc[i].guid_tag, 
                          &KSDATAFORMAT_SUBTYPE_UNKNOWN ); i++ )
    {
        if( guidcmp( &sub_format_tag_to_fourcc[i].guid_tag, guid_tag ) ) break;
    }
    if( fcc ) *fcc = sub_format_tag_to_fourcc[i].i_fourcc;
    if( ppsz_name ) *ppsz_name = sub_format_tag_to_fourcc[i].psz_name;
}

371 372 373 374 375 376 377
/**
 * Structure to hold information concerning subtitles.
 * Used between demuxers and decoders of subtitles.
 */
typedef struct es_sys_t
{
    char        *psz_header; /* for 'ssa ' and 'subt' */
zorglub's avatar
zorglub committed
378

379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
    /* for spudec */
    unsigned int        i_orig_height;
    unsigned int        i_orig_width;
    unsigned int        i_origin_x;
    unsigned int        i_origin_y;
    unsigned int        i_scale_h;
    unsigned int        i_scale_v;
    unsigned int        i_alpha;
    vlc_bool_t          b_smooth;
    mtime_t             i_fade_in;
    mtime_t             i_fade_out;
    unsigned int        i_align;
    mtime_t             i_time_offset;
    vlc_bool_t          b_forced_subs;
    unsigned int        palette[16];
    unsigned int        colors[4];
395

396
} subtitle_data_t;
397

gbazin's avatar
 
gbazin committed
398
#endif /* "codecs.h" */