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

Generated on Sat Nov 21 08:05:14 2009 for VLC by  doxygen 1.5.6