vlc_codecs.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * codecs.h: codec related structures needed by the demuxers and decoders
00003  *****************************************************************************
00004  * Copyright (C) 1999-2001 the VideoLAN team
00005  * $Id$
00006  *
00007  * Author: Gildas Bazin <gbazin@videolan.org>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00022  *****************************************************************************/
00023 
00024 #ifndef VLC_CODECS_H
00025 #define VLC_CODECS_H 1
00026 
00027 #ifdef HAVE_ATTRIBUTE_PACKED
00028 #   define ATTR_PACKED __attribute__((__packed__))
00029 #else
00030 #   error FIXME
00031 #endif
00032 
00033 /* Structures exported to the demuxers and decoders */
00034 
00035 #if !(defined _GUID_DEFINED || defined GUID_DEFINED)
00036 #define GUID_DEFINED
00037 typedef struct _GUID
00038 {
00039     uint32_t Data1;
00040     uint16_t Data2;
00041     uint16_t Data3;
00042     uint8_t  Data4[8];
00043 } GUID, *REFGUID, *LPGUID;
00044 #endif /* GUID_DEFINED */
00045 
00046 #ifndef _WAVEFORMATEX_
00047 #define _WAVEFORMATEX_
00048 typedef struct
00049 ATTR_PACKED
00050 _WAVEFORMATEX {
00051     uint16_t   wFormatTag;
00052     uint16_t   nChannels;
00053     uint32_t   nSamplesPerSec;
00054     uint32_t   nAvgBytesPerSec;
00055     uint16_t   nBlockAlign;
00056     uint16_t   wBitsPerSample;
00057     uint16_t   cbSize;
00058 } WAVEFORMATEX, *PWAVEFORMATEX, *NPWAVEFORMATEX, *LPWAVEFORMATEX;
00059 #endif /* _WAVEFORMATEX_ */
00060 
00061 #ifndef _WAVEFORMATEXTENSIBLE_
00062 #define _WAVEFORMATEXTENSIBLE_
00063 typedef struct
00064 ATTR_PACKED
00065 _WAVEFORMATEXTENSIBLE {
00066     WAVEFORMATEX Format;
00067     union {
00068         uint16_t wValidBitsPerSample;
00069         uint16_t wSamplesPerBlock;
00070         uint16_t wReserved;
00071     } Samples;
00072     uint32_t     dwChannelMask;
00073     GUID SubFormat;
00074 } WAVEFORMATEXTENSIBLE, *PWAVEFORMATEXTENSIBLE;
00075 #endif /* _WAVEFORMATEXTENSIBLE_ */
00076 
00077 #ifndef _WAVEHEADER_
00078 #define _WAVEHEADER_
00079 typedef struct
00080 ATTR_PACKED
00081 _WAVEHEADER {
00082     uint32_t MainChunkID;
00083     uint32_t Length;
00084     uint32_t ChunkTypeID;
00085     uint32_t SubChunkID;
00086     uint32_t SubChunkLength;
00087     uint16_t Format;
00088     uint16_t Modus;
00089     uint32_t SampleFreq;
00090     uint32_t BytesPerSec;
00091     uint16_t BytesPerSample;
00092     uint16_t BitsPerSample;
00093     uint32_t DataChunkID;
00094     uint32_t DataLength;
00095 } WAVEHEADER;
00096 #endif /* _WAVEHEADER_ */
00097 
00098 #if !defined(_BITMAPINFOHEADER_) && !defined(WIN32)
00099 #define _BITMAPINFOHEADER_
00100 typedef struct
00101 ATTR_PACKED
00102 {
00103     uint32_t   biSize;
00104     uint32_t   biWidth;
00105     uint32_t   biHeight;
00106     uint16_t   biPlanes;
00107     uint16_t   biBitCount;
00108     uint32_t   biCompression;
00109     uint32_t   biSizeImage;
00110     uint32_t   biXPelsPerMeter;
00111     uint32_t   biYPelsPerMeter;
00112     uint32_t   biClrUsed;
00113     uint32_t   biClrImportant;
00114 } BITMAPINFOHEADER, *PBITMAPINFOHEADER, *LPBITMAPINFOHEADER;
00115 
00116 typedef struct
00117 ATTR_PACKED
00118 {
00119     BITMAPINFOHEADER bmiHeader;
00120     int        bmiColors[1];
00121 } BITMAPINFO, *LPBITMAPINFO;
00122 #endif
00123 
00124 #ifndef _RECT32_
00125 #define _RECT32_
00126 typedef struct
00127 ATTR_PACKED
00128 {
00129     int left, top, right, bottom;
00130 } RECT32;
00131 #endif
00132 
00133 #ifndef _REFERENCE_TIME_
00134 #define _REFERENCE_TIME_
00135 typedef int64_t REFERENCE_TIME;
00136 #endif
00137 
00138 #ifndef _VIDEOINFOHEADER_
00139 #define _VIDEOINFOHEADER_
00140 typedef struct
00141 ATTR_PACKED
00142 {
00143     RECT32            rcSource;
00144     RECT32            rcTarget;
00145     uint32_t          dwBitRate;
00146     uint32_t          dwBitErrorRate;
00147     REFERENCE_TIME    AvgTimePerFrame;
00148     BITMAPINFOHEADER  bmiHeader;
00149 } VIDEOINFOHEADER;
00150 #endif
00151 
00152 #ifndef _RGBQUAD_
00153 #define _RGBQUAD_
00154 typedef struct
00155 ATTR_PACKED
00156 {
00157     uint8_t rgbBlue;
00158     uint8_t rgbGreen;
00159     uint8_t rgbRed;
00160     uint8_t rgbReserved;
00161 } RGBQUAD1;
00162 #endif
00163 
00164 #ifndef _TRUECOLORINFO_
00165 #define _TRUECOLORINFO_
00166 typedef struct
00167 ATTR_PACKED
00168 {
00169     uint32_t dwBitMasks[3];
00170     RGBQUAD1 bmiColors[256];
00171 } TRUECOLORINFO;
00172 #endif
00173 
00174 #ifndef _VIDEOINFO_
00175 #define _VIDEOINFO_
00176 typedef struct
00177 ATTR_PACKED
00178 {
00179     RECT32            rcSource;
00180     RECT32            rcTarget;
00181     uint32_t          dwBitRate;
00182     uint32_t          dwBitErrorRate;
00183     REFERENCE_TIME    AvgTimePerFrame;
00184     BITMAPINFOHEADER  bmiHeader;
00185 
00186     union
00187     {
00188         RGBQUAD1 bmiColors[256]; /* Colour palette */
00189         uint32_t dwBitMasks[3]; /* True colour masks */
00190         TRUECOLORINFO TrueColorInfo; /* Both of the above */
00191     };
00192 
00193 } VIDEOINFO;
00194 #endif
00195 
00196 /* WAVE format wFormatTag IDs */
00197 #define WAVE_FORMAT_UNKNOWN             0x0000 /* Microsoft Corporation */
00198 #define WAVE_FORMAT_PCM                 0x0001 /* Microsoft Corporation */
00199 #define WAVE_FORMAT_ADPCM               0x0002 /* Microsoft Corporation */
00200 #define WAVE_FORMAT_IEEE_FLOAT          0x0003 /* Microsoft Corporation */
00201 #define WAVE_FORMAT_ALAW                0x0006 /* Microsoft Corporation */
00202 #define WAVE_FORMAT_MULAW               0x0007 /* Microsoft Corporation */
00203 #define WAVE_FORMAT_DTS_MS              0x0008 /* Microsoft Corporation */
00204 #define WAVE_FORMAT_WMAS                0x000a /* WMA 9 Speech */
00205 #define WAVE_FORMAT_IMA_ADPCM           0x0011 /* Intel Corporation */
00206 #define WAVE_FORMAT_GSM610              0x0031 /* Microsoft Corporation */
00207 #define WAVE_FORMAT_MSNAUDIO            0x0032 /* Microsoft Corporation */
00208 #define WAVE_FORMAT_G726                0x0045 /* ITU-T standard  */
00209 #define WAVE_FORMAT_MPEG                0x0050 /* Microsoft Corporation */
00210 #define WAVE_FORMAT_MPEGLAYER3          0x0055 /* ISO/MPEG Layer3 Format Tag */
00211 #define WAVE_FORMAT_DOLBY_AC3_SPDIF     0x0092 /* Sonic Foundry */
00212 
00213 #define WAVE_FORMAT_A52                 0x2000
00214 #define WAVE_FORMAT_DTS                 0x2001
00215 #define WAVE_FORMAT_WMA1                0x0160 /* WMA version 1 */
00216 #define WAVE_FORMAT_WMA2                0x0161 /* WMA (v2) 7, 8, 9 Series */
00217 #define WAVE_FORMAT_WMAP                0x0162 /* WMA 9 Professional */
00218 #define WAVE_FORMAT_WMAL                0x0163 /* WMA 9 Lossless */
00219 #define WAVE_FORMAT_DIVIO_AAC           0x4143
00220 #define WAVE_FORMAT_AAC                 0x00FF
00221 #define WAVE_FORMAT_FFMPEG_AAC          0x706D
00222 
00223 /* Need to check these */
00224 #define WAVE_FORMAT_DK3                 0x0061
00225 #define WAVE_FORMAT_DK4                 0x0062
00226 
00227 /* At least FFmpeg use that ID: from libavformat/riff.c ('Vo' == 0x566f)
00228  * { CODEC_ID_VORBIS, ('V'<<8)+'o' }, //HACK/FIXME, does vorbis in WAV/AVI have an (in)official id?
00229  */
00230 #define WAVE_FORMAT_VORBIS              0x566f
00231 
00232 /* It seems that these IDs are used by braindead & obsolete VorbisACM encoder
00233  * (Windows only)
00234  * A few info is available except VorbisACM source (remember, Windows only)
00235  * (available on http://svn.xiph.org), but it seems that vo3+ at least is
00236  * made of Vorbis data encapsulated in Ogg container...
00237  */
00238 #define WAVE_FORMAT_VORB_1              0x674f
00239 #define WAVE_FORMAT_VORB_2              0x6750
00240 #define WAVE_FORMAT_VORB_3              0x6751
00241 #define WAVE_FORMAT_VORB_1PLUS          0x676f
00242 #define WAVE_FORMAT_VORB_2PLUS          0x6770
00243 #define WAVE_FORMAT_VORB_3PLUS          0x6771
00244 
00245 #define WAVE_FORMAT_SPEEX               0xa109 /* Speex audio */
00246 
00247 
00248 #if !defined(WAVE_FORMAT_EXTENSIBLE)
00249 #define WAVE_FORMAT_EXTENSIBLE          0xFFFE /* Microsoft */
00250 #endif
00251 
00252 /* GUID SubFormat IDs */
00253 /* We need both b/c const variables are not compile-time constants in C, giving
00254  * us an error if we use the const GUID in an enum */
00255 
00256 #ifndef _KSDATAFORMAT_SUBTYPE_PCM_
00257 #define _KSDATAFORMAT_SUBTYPE_PCM_ {0x00000001, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}}
00258 static const GUID VLC_KSDATAFORMAT_SUBTYPE_PCM = {0xE923AABF, 0xCB58, 0x4471, {0xA1, 0x19, 0xFF, 0xFA, 0x01, 0xE4, 0xCE, 0x62}};
00259 #define KSDATAFORMAT_SUBTYPE_PCM VLC_KSDATAFORMAT_SUBTYPE_PCM
00260 #endif
00261 
00262 #ifndef _KSDATAFORMAT_SUBTYPE_UNKNOWN_
00263 #define _KSDATAFORMAT_SUBTYPE_UNKNOWN_ {0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}
00264 static const GUID VLC_KSDATAFORMAT_SUBTYPE_UNKNOWN = {0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
00265 #define KSDATAFORMAT_SUBTYPE_UNKNOWN VLC_KSDATAFORMAT_SUBTYPE_UNKNOWN
00266 #endif
00267 
00268 /* Microsoft speaker definitions */
00269 #define WAVE_SPEAKER_FRONT_LEFT             0x1
00270 #define WAVE_SPEAKER_FRONT_RIGHT            0x2
00271 #define WAVE_SPEAKER_FRONT_CENTER           0x4
00272 #define WAVE_SPEAKER_LOW_FREQUENCY          0x8
00273 #define WAVE_SPEAKER_BACK_LEFT              0x10
00274 #define WAVE_SPEAKER_BACK_RIGHT             0x20
00275 #define WAVE_SPEAKER_FRONT_LEFT_OF_CENTER   0x40
00276 #define WAVE_SPEAKER_FRONT_RIGHT_OF_CENTER  0x80
00277 #define WAVE_SPEAKER_BACK_CENTER            0x100
00278 #define WAVE_SPEAKER_SIDE_LEFT              0x200
00279 #define WAVE_SPEAKER_SIDE_RIGHT             0x400
00280 #define WAVE_SPEAKER_TOP_CENTER             0x800
00281 #define WAVE_SPEAKER_TOP_FRONT_LEFT         0x1000
00282 #define WAVE_SPEAKER_TOP_FRONT_CENTER       0x2000
00283 #define WAVE_SPEAKER_TOP_FRONT_RIGHT        0x4000
00284 #define WAVE_SPEAKER_TOP_BACK_LEFT          0x8000
00285 #define WAVE_SPEAKER_TOP_BACK_CENTER        0x10000
00286 #define WAVE_SPEAKER_TOP_BACK_RIGHT         0x20000
00287 #define WAVE_SPEAKER_RESERVED               0x80000000
00288 
00289 static const struct
00290 {
00291     uint16_t     i_tag;
00292     vlc_fourcc_t i_fourcc;
00293     const char  *psz_name;
00294 }
00295 wave_format_tag_to_fourcc[] =
00296 {
00297     { WAVE_FORMAT_PCM,        VLC_FOURCC( 'a', 'r', 'a', 'w' ), "Raw audio" },
00298     { WAVE_FORMAT_ADPCM,      VLC_FOURCC( 'm', 's', 0x00,0x02), "ADPCM" },
00299     { WAVE_FORMAT_IEEE_FLOAT, VLC_FOURCC( 'a', 'f', 'l', 't' ), "IEEE Float audio" },
00300     { WAVE_FORMAT_ALAW,       VLC_FOURCC( 'a', 'l', 'a', 'w' ), "A-Law" },
00301     { WAVE_FORMAT_MULAW,      VLC_FOURCC( 'm', 'l', 'a', 'w' ), "Mu-Law" },
00302     { WAVE_FORMAT_IMA_ADPCM,  VLC_FOURCC( 'm', 's', 0x00,0x11), "Ima-ADPCM" },
00303     { WAVE_FORMAT_G726,       VLC_FOURCC( 'g', '7', '2', '6' ), "G.726 ADPCM" },
00304     { WAVE_FORMAT_MPEGLAYER3, VLC_FOURCC( 'm', 'p', 'g', 'a' ), "Mpeg Audio" },
00305     { WAVE_FORMAT_MPEG,       VLC_FOURCC( 'm', 'p', 'g', 'a' ), "Mpeg Audio" },
00306     { WAVE_FORMAT_A52,        VLC_FOURCC( 'a', '5', '2', ' ' ), "A/52" },
00307     { WAVE_FORMAT_WMA1,       VLC_FOURCC( 'w', 'm', 'a', '1' ), "Window Media Audio v1" },
00308     { WAVE_FORMAT_WMA2,       VLC_FOURCC( 'w', 'm', 'a', '2' ), "Window Media Audio v2" },
00309     { WAVE_FORMAT_WMA2,       VLC_FOURCC( 'w', 'm', 'a', ' ' ), "Window Media Audio v2" },
00310     { WAVE_FORMAT_WMAP,       VLC_FOURCC( 'w', 'm', 'a', 'p' ), "Window Media Audio 9 Professional" },
00311     { WAVE_FORMAT_WMAL,       VLC_FOURCC( 'w', 'm', 'a', 'l' ), "Window Media Audio 9 Lossless" },
00312     { WAVE_FORMAT_WMAS,       VLC_FOURCC( 'w', 'm', 'a', 's' ), "Window Media Audio 9 Speech" },
00313     { WAVE_FORMAT_DK3,        VLC_FOURCC( 'm', 's', 0x00,0x61), "Duck DK3" },
00314     { WAVE_FORMAT_DK4,        VLC_FOURCC( 'm', 's', 0x00,0x62), "Duck DK4" },
00315     { WAVE_FORMAT_DTS,        VLC_FOURCC( 'd', 't', 's', ' ' ), "DTS Coherent Acoustics" },
00316     { WAVE_FORMAT_DTS_MS,     VLC_FOURCC( 'd', 't', 's', ' ' ), "DTS Coherent Acoustics" },
00317     { WAVE_FORMAT_DIVIO_AAC,  VLC_FOURCC( 'm', 'p', '4', 'a' ), "MPEG-4 Audio (Divio)" },
00318     { WAVE_FORMAT_AAC,        VLC_FOURCC( 'm', 'p', '4', 'a' ), "MPEG-4 Audio" },
00319     { WAVE_FORMAT_FFMPEG_AAC, VLC_FOURCC( 'm', 'p', '4', 'a' ), "MPEG-4 Audio" },
00320     { WAVE_FORMAT_VORBIS,     VLC_FOURCC( 'v', 'o', 'r', 'b' ), "Vorbis Audio" },
00321     { WAVE_FORMAT_VORB_1,     VLC_FOURCC( 'v', 'o', 'r', '1' ), "Vorbis 1 Audio" },
00322     { WAVE_FORMAT_VORB_1PLUS, VLC_FOURCC( 'v', 'o', '1', '+' ), "Vorbis 1+ Audio" },
00323     { WAVE_FORMAT_VORB_2,     VLC_FOURCC( 'v', 'o', 'r', '2' ), "Vorbis 2 Audio" },
00324     { WAVE_FORMAT_VORB_2PLUS, VLC_FOURCC( 'v', 'o', '2', '+' ), "Vorbis 2+ Audio" },
00325     { WAVE_FORMAT_VORB_3,     VLC_FOURCC( 'v', 'o', 'r', '3' ), "Vorbis 3 Audio" },
00326     { WAVE_FORMAT_VORB_3PLUS, VLC_FOURCC( 'v', 'o', '3', '+' ), "Vorbis 3+ Audio" },
00327     { WAVE_FORMAT_SPEEX,      VLC_FOURCC( 's', 'p', 'x', ' ' ), "Speex Audio" },
00328     { WAVE_FORMAT_UNKNOWN,    VLC_FOURCC( 'u', 'n', 'd', 'f' ), "Unknown" }
00329 };
00330 
00331 static inline void wf_tag_to_fourcc( uint16_t i_tag, vlc_fourcc_t *fcc,
00332                                      const char **ppsz_name )
00333 {
00334     int i;
00335     for( i = 0; wave_format_tag_to_fourcc[i].i_tag != 0; i++ )
00336     {
00337         if( wave_format_tag_to_fourcc[i].i_tag == i_tag ) break;
00338     }
00339     if( fcc ) *fcc = wave_format_tag_to_fourcc[i].i_fourcc;
00340     if( ppsz_name ) *ppsz_name = wave_format_tag_to_fourcc[i].psz_name;
00341 }
00342 
00343 static inline void fourcc_to_wf_tag( vlc_fourcc_t fcc, uint16_t *pi_tag )
00344 {
00345     int i;
00346     for( i = 0; wave_format_tag_to_fourcc[i].i_tag != 0; i++ )
00347     {
00348         if( wave_format_tag_to_fourcc[i].i_fourcc == fcc ) break;
00349     }
00350     if( pi_tag ) *pi_tag = wave_format_tag_to_fourcc[i].i_tag;
00351 }
00352 
00353 /* If wFormatTag is WAVEFORMATEXTENSIBLE, we must look at the SubFormat tag
00354  * to determine the actual format.  Microsoft has stopped giving out wFormatTag
00355  * assignments in lieu of letting 3rd parties generate their own GUIDs
00356  */
00357 static const struct
00358 {
00359     GUID         guid_tag;
00360     vlc_fourcc_t i_fourcc;
00361     const char  *psz_name;
00362 }
00363 sub_format_tag_to_fourcc[] =
00364 {
00365     { _KSDATAFORMAT_SUBTYPE_PCM_, VLC_FOURCC( 'p', 'c', 'm', ' ' ), "PCM" },
00366     { _KSDATAFORMAT_SUBTYPE_UNKNOWN_, VLC_FOURCC( 'u', 'n', 'd', 'f' ), "Unknown" }
00367 };
00368 
00369 /* compares two GUIDs, returns 1 if identical, 0 otherwise */
00370 static inline int guidcmp( const GUID *s1, const GUID *s2 )
00371 {
00372     return( s1->Data1 == s2->Data1 && s1->Data2 == s2->Data2 &&
00373             s1->Data3 == s2->Data3 && !memcmp( s1->Data4, s2->Data4, 8 ) );
00374 }
00375 
00376 static inline void sf_tag_to_fourcc( GUID *guid_tag,
00377                                      vlc_fourcc_t *fcc, const char **ppsz_name )
00378 {
00379     int i;
00380 
00381     for( i = 0; !guidcmp( &sub_format_tag_to_fourcc[i].guid_tag,
00382                           &KSDATAFORMAT_SUBTYPE_UNKNOWN ); i++ )
00383     {
00384         if( guidcmp( &sub_format_tag_to_fourcc[i].guid_tag, guid_tag ) ) break;
00385     }
00386     if( fcc ) *fcc = sub_format_tag_to_fourcc[i].i_fourcc;
00387     if( ppsz_name ) *ppsz_name = sub_format_tag_to_fourcc[i].psz_name;
00388 }
00389 
00390 /**
00391  * Structure to hold information concerning subtitles.
00392  * Used between demuxers and decoders of subtitles.
00393  */
00394 typedef struct es_sys_t
00395 {
00396     char               *psz_header; /* for 'ssa ' and 'subt' */
00397 
00398     /* for spudec */
00399     unsigned int        i_orig_height;
00400     unsigned int        i_orig_width;
00401     unsigned int        i_origin_x;
00402     unsigned int        i_origin_y;
00403     unsigned int        i_scale_h;
00404     unsigned int        i_scale_v;
00405     unsigned int        i_alpha;
00406     bool          b_smooth;
00407     mtime_t             i_fade_in;
00408     mtime_t             i_fade_out;
00409     unsigned int        i_align;
00410     mtime_t             i_time_offset;
00411     bool          b_forced_subs;
00412     unsigned int        palette[16];
00413     unsigned int        colors[4];
00414 
00415 } subtitle_data_t;
00416 
00417 #endif /* "codecs.h" */

Generated on Wed Aug 13 08:02:37 2008 for VLC by  doxygen 1.5.1