[vlc-devel] [PATCH] Initialize codecs after track parsing and not before the selection.

Denis Charmet typx at dinauz.org
Fri Dec 28 19:34:24 CET 2012


This avoid leaks at segment changes.
---
 modules/demux/mkv/matroska_segment.cpp       |  467 -----------------------
 modules/demux/mkv/matroska_segment.hpp       |    1 +
 modules/demux/mkv/matroska_segment_parse.cpp |  521 ++++++++++++++++++++++++--
 3 files changed, 499 insertions(+), 490 deletions(-)

diff --git a/modules/demux/mkv/matroska_segment.cpp b/modules/demux/mkv/matroska_segment.cpp
index 3d334f2..ea0e9f7 100644
--- a/modules/demux/mkv/matroska_segment.cpp
+++ b/modules/demux/mkv/matroska_segment.cpp
@@ -28,19 +28,6 @@
 #include "util.hpp"
 #include "Ebml_parser.hpp"
 
-extern "C" {
-#include "../vobsub.h"
-}
-
-#include <vlc_codecs.h>
-
-/* GetFourCC helper */
-#define GetFOURCC( p )  __GetFOURCC( (uint8_t*)p )
-static vlc_fourcc_t __GetFOURCC( uint8_t *p )
-{
-    return VLC_FOURCC( p[0], p[1], p[2], p[3] );
-}
-
 matroska_segment_c::matroska_segment_c( demux_sys_t & demuxer, EbmlStream & estream )
     :segment(NULL)
     ,es(estream)
@@ -1027,15 +1014,6 @@ int matroska_segment_c::BlockFindTrackIndex( size_t *pi_track,
     return VLC_SUCCESS;
 }
 
-static inline void fill_extra_data( mkv_track_t *p_tk, unsigned int offset )
-{
-    if(p_tk->i_extra_data <= offset) return;
-    p_tk->fmt.i_extra = p_tk->i_extra_data - offset;
-    p_tk->fmt.p_extra = xmalloc( p_tk->fmt.i_extra );
-    if(!p_tk->fmt.p_extra) { p_tk->fmt.i_extra = 0; return; };
-    memcpy( p_tk->fmt.p_extra, p_tk->p_extra_data + offset, p_tk->fmt.i_extra );
-}
-
 bool matroska_segment_c::Select( mtime_t i_start_time )
 {
     /* add all es */
@@ -1077,451 +1055,6 @@ bool matroska_segment_c::Select( mtime_t i_start_time )
             p_tk->b_default = true;
             b_has_default_audio = true;
         }
-
-        if( !strcmp( p_tk->psz_codec, "V_MS/VFW/FOURCC" ) )
-        {
-            if( p_tk->i_extra_data < (int)sizeof( VLC_BITMAPINFOHEADER ) )
-            {
-                msg_Err( &sys.demuxer, "missing/invalid VLC_BITMAPINFOHEADER" );
-                p_tk->fmt.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
-            }
-            else
-            {
-                VLC_BITMAPINFOHEADER *p_bih = (VLC_BITMAPINFOHEADER*)p_tk->p_extra_data;
-
-                p_tk->fmt.video.i_width = GetDWLE( &p_bih->biWidth );
-                p_tk->fmt.video.i_height= GetDWLE( &p_bih->biHeight );
-                p_tk->fmt.i_codec       = GetFOURCC( &p_bih->biCompression );
-
-                p_tk->fmt.i_extra       = GetDWLE( &p_bih->biSize ) - sizeof( VLC_BITMAPINFOHEADER );
-                if( p_tk->fmt.i_extra > 0 )
-                {
-                    /* Very unlikely yet possible: bug #5659*/
-                    size_t maxlen = p_tk->i_extra_data - sizeof( VLC_BITMAPINFOHEADER );
-                    p_tk->fmt.i_extra = ( (unsigned)p_tk->fmt.i_extra < maxlen )?
-                        p_tk->fmt.i_extra : maxlen;
-
-                    p_tk->fmt.p_extra = xmalloc( p_tk->fmt.i_extra );
-                    memcpy( p_tk->fmt.p_extra, &p_bih[1], p_tk->fmt.i_extra );
-                }
-            }
-            p_tk->b_dts_only = true;
-        }
-        else if( !strcmp( p_tk->psz_codec, "V_MPEG1" ) ||
-                 !strcmp( p_tk->psz_codec, "V_MPEG2" ) )
-        {
-            p_tk->fmt.i_codec = VLC_CODEC_MPGV;
-            if( p_tk->i_extra_data )
-                fill_extra_data( p_tk, 0 );
-        }
-        else if( !strncmp( p_tk->psz_codec, "V_THEORA", 8 ) )
-        {
-            p_tk->fmt.i_codec = VLC_CODEC_THEORA;
-            fill_extra_data( p_tk, 0 );
-            p_tk->b_pts_only = true;
-        }
-        else if( !strncmp( p_tk->psz_codec, "V_REAL/RV", 9 ) )
-        {
-            uint8_t *p = p_tk->p_extra_data;
-
-            if( !strcmp( p_tk->psz_codec, "V_REAL/RV10" ) )
-                p_fmt->i_codec = VLC_CODEC_RV10;
-            else if( !strcmp( p_tk->psz_codec, "V_REAL/RV20" ) )
-                p_fmt->i_codec = VLC_CODEC_RV20;
-            else if( !strcmp( p_tk->psz_codec, "V_REAL/RV30" ) )
-                p_fmt->i_codec = VLC_CODEC_RV30;
-            else if( !strcmp( p_tk->psz_codec, "V_REAL/RV40" ) )
-                p_fmt->i_codec = VLC_CODEC_RV40;
-
-            /* Extract the framerate from the header */
-            if( p_tk->i_extra_data >= 26 &&
-                p[4] == 'V' && p[5] == 'I' && p[6] == 'D' && p[7] == 'O' &&
-                p[8] == 'R' && p[9] == 'V' &&
-                (p[10] == '3' || p[10] == '4') && p[11] == '0' )
-            {
-                p_tk->fmt.video.i_frame_rate =
-                    p[22] << 24 | p[23] << 16 | p[24] << 8 | p[25] << 0;
-                p_tk->fmt.video.i_frame_rate_base = 65536;
-            }
-
-            fill_extra_data( p_tk, 26 );
-            p_tk->b_dts_only = true;
-        }
-        else if( !strncmp( p_tk->psz_codec, "V_DIRAC", 7 ) )
-        {
-            p_tk->fmt.i_codec = VLC_CODEC_DIRAC;
-        }
-        else if( !strncmp( p_tk->psz_codec, "V_VP8", 5 ) )
-        {
-            p_tk->fmt.i_codec = VLC_CODEC_VP8;
-            p_tk->b_pts_only = true;
-        }
-        else if( !strncmp( p_tk->psz_codec, "V_MPEG4", 7 ) )
-        {
-            if( !strcmp( p_tk->psz_codec, "V_MPEG4/MS/V3" ) )
-            {
-                p_tk->fmt.i_codec = VLC_CODEC_DIV3;
-            }
-            else if( !strncmp( p_tk->psz_codec, "V_MPEG4/ISO", 11 ) )
-            {
-                /* A MPEG 4 codec, SP, ASP, AP or AVC */
-                if( !strcmp( p_tk->psz_codec, "V_MPEG4/ISO/AVC" ) )
-                    p_tk->fmt.i_codec = VLC_FOURCC( 'a', 'v', 'c', '1' );
-                else
-                    p_tk->fmt.i_codec = VLC_CODEC_MP4V;
-                fill_extra_data( p_tk, 0 );
-            }
-        }
-        else if( !strcmp( p_tk->psz_codec, "V_QUICKTIME" ) )
-        {
-            MP4_Box_t *p_box = (MP4_Box_t*)xmalloc( sizeof( MP4_Box_t ) );
-            stream_t *p_mp4_stream = stream_MemoryNew( VLC_OBJECT(&sys.demuxer),
-                                                       p_tk->p_extra_data,
-                                                       p_tk->i_extra_data,
-                                                       true );
-            if( MP4_ReadBoxCommon( p_mp4_stream, p_box ) &&
-                MP4_ReadBox_sample_vide( p_mp4_stream, p_box ) )
-            {
-                p_tk->fmt.i_codec = p_box->i_type;
-                p_tk->fmt.video.i_width = p_box->data.p_sample_vide->i_width;
-                p_tk->fmt.video.i_height = p_box->data.p_sample_vide->i_height;
-                p_tk->fmt.i_extra = p_box->data.p_sample_vide->i_qt_image_description;
-                p_tk->fmt.p_extra = xmalloc( p_tk->fmt.i_extra );
-                memcpy( p_tk->fmt.p_extra, p_box->data.p_sample_vide->p_qt_image_description, p_tk->fmt.i_extra );
-                MP4_FreeBox_sample_vide( p_box );
-            }
-            else
-            {
-                free( p_box );
-            }
-            stream_Delete( p_mp4_stream );
-        }
-        else if( !strcmp( p_tk->psz_codec, "V_MJPEG" ) )
-        {
-            p_tk->fmt.i_codec = VLC_CODEC_MJPG;
-        }
-        else if( !strcmp( p_tk->psz_codec, "A_MS/ACM" ) )
-        {
-            if( p_tk->i_extra_data < (int)sizeof( WAVEFORMATEX ) )
-            {
-                msg_Err( &sys.demuxer, "missing/invalid WAVEFORMATEX" );
-                p_tk->fmt.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
-            }
-            else
-            {
-                WAVEFORMATEX *p_wf = (WAVEFORMATEX*)p_tk->p_extra_data;
-
-                wf_tag_to_fourcc( GetWLE( &p_wf->wFormatTag ), &p_tk->fmt.i_codec, NULL );
-
-                if( p_tk->fmt.i_codec == VLC_FOURCC( 'u', 'n', 'd', 'f' ) )
-                    msg_Err( &sys.demuxer, "Unrecognized wf tag: 0x%x", GetWLE( &p_wf->wFormatTag ) );
-                p_tk->fmt.audio.i_channels   = GetWLE( &p_wf->nChannels );
-                p_tk->fmt.audio.i_rate = GetDWLE( &p_wf->nSamplesPerSec );
-                p_tk->fmt.i_bitrate    = GetDWLE( &p_wf->nAvgBytesPerSec ) * 8;
-                p_tk->fmt.audio.i_blockalign = GetWLE( &p_wf->nBlockAlign );;
-                p_tk->fmt.audio.i_bitspersample = GetWLE( &p_wf->wBitsPerSample );
-
-                p_tk->fmt.i_extra            = GetWLE( &p_wf->cbSize );
-                if( p_tk->fmt.i_extra > 0 )
-                {
-                    p_tk->fmt.p_extra = xmalloc( p_tk->fmt.i_extra );
-                    memcpy( p_tk->fmt.p_extra, &p_wf[1], p_tk->fmt.i_extra );
-                }
-            }
-        }
-        else if( !strcmp( p_tk->psz_codec, "A_MPEG/L3" ) ||
-                 !strcmp( p_tk->psz_codec, "A_MPEG/L2" ) ||
-                 !strcmp( p_tk->psz_codec, "A_MPEG/L1" ) )
-        {
-            p_tk->fmt.i_codec = VLC_CODEC_MPGA;
-        }
-        else if( !strcmp( p_tk->psz_codec, "A_AC3" ) )
-        {
-            p_tk->fmt.i_codec = VLC_CODEC_A52;
-        }
-        else if( !strcmp( p_tk->psz_codec, "A_EAC3" ) )
-        {
-            p_tk->fmt.i_codec = VLC_CODEC_EAC3;
-        }
-        else if( !strcmp( p_tk->psz_codec, "A_DTS" ) )
-        {
-            p_tk->fmt.i_codec = VLC_CODEC_DTS;
-        }
-        else if( !strcmp( p_tk->psz_codec, "A_MLP" ) )
-        {
-            p_tk->fmt.i_codec = VLC_CODEC_MLP;
-        }
-        else if( !strcmp( p_tk->psz_codec, "A_TRUEHD" ) )
-        {
-            /* FIXME when more samples arrive */
-            p_tk->fmt.i_codec = VLC_CODEC_TRUEHD;
-            p_fmt->b_packetized = false;
-        }
-        else if( !strcmp( p_tk->psz_codec, "A_FLAC" ) )
-        {
-            p_tk->fmt.i_codec = VLC_CODEC_FLAC;
-            fill_extra_data( p_tk, 0 );
-        }
-        else if( !strcmp( p_tk->psz_codec, "A_VORBIS" ) )
-        {
-            p_tk->fmt.i_codec = VLC_CODEC_VORBIS;
-            fill_extra_data( p_tk, 0 );
-        }
-        else if( !strncmp( p_tk->psz_codec, "A_AAC/MPEG2/", strlen( "A_AAC/MPEG2/" ) ) ||
-                 !strncmp( p_tk->psz_codec, "A_AAC/MPEG4/", strlen( "A_AAC/MPEG4/" ) ) )
-        {
-            int i_profile, i_srate, sbr = 0;
-            static const unsigned int i_sample_rates[] =
-            {
-                    96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
-                    16000, 12000, 11025,  8000,  7350,     0,     0,     0
-            };
-
-            p_tk->fmt.i_codec = VLC_CODEC_MP4A;
-            /* create data for faad (MP4DecSpecificDescrTag)*/
-
-            if( !strcmp( &p_tk->psz_codec[12], "MAIN" ) )
-            {
-                i_profile = 0;
-            }
-            else if( !strcmp( &p_tk->psz_codec[12], "LC" ) )
-            {
-                i_profile = 1;
-            }
-            else if( !strcmp( &p_tk->psz_codec[12], "SSR" ) )
-            {
-                i_profile = 2;
-            }
-            else if( !strcmp( &p_tk->psz_codec[12], "LC/SBR" ) )
-            {
-                i_profile = 1;
-                sbr = 1;
-            }
-            else
-            {
-                i_profile = 3;
-            }
-
-            for( i_srate = 0; i_srate < 13; i_srate++ )
-            {
-                if( i_sample_rates[i_srate] == p_tk->i_original_rate )
-                {
-                    break;
-                }
-            }
-            msg_Dbg( &sys.demuxer, "profile=%d srate=%d", i_profile, i_srate );
-
-            p_tk->fmt.i_extra = sbr ? 5 : 2;
-            p_tk->fmt.p_extra = xmalloc( p_tk->fmt.i_extra );
-            ((uint8_t*)p_tk->fmt.p_extra)[0] = ((i_profile + 1) << 3) | ((i_srate&0xe) >> 1);
-            ((uint8_t*)p_tk->fmt.p_extra)[1] = ((i_srate & 0x1) << 7) | (p_tk->fmt.audio.i_channels << 3);
-            if (sbr != 0)
-            {
-                int syncExtensionType = 0x2B7;
-                int iDSRI;
-                for (iDSRI=0; iDSRI<13; iDSRI++)
-                    if( i_sample_rates[iDSRI] == p_tk->fmt.audio.i_rate )
-                        break;
-                ((uint8_t*)p_tk->fmt.p_extra)[2] = (syncExtensionType >> 3) & 0xFF;
-                ((uint8_t*)p_tk->fmt.p_extra)[3] = ((syncExtensionType & 0x7) << 5) | 5;
-                ((uint8_t*)p_tk->fmt.p_extra)[4] = ((1 & 0x1) << 7) | (iDSRI << 3);
-            }
-        }
-        else if( !strcmp( p_tk->psz_codec, "A_AAC" ) )
-        {
-            p_tk->fmt.i_codec = VLC_CODEC_MP4A;
-            fill_extra_data( p_tk, 0 );
-        }
-        else if( !strcmp( p_tk->psz_codec, "A_WAVPACK4" ) )
-        {
-            p_tk->fmt.i_codec = VLC_CODEC_WAVPACK;
-            fill_extra_data( p_tk, 0 );
-        }
-        else if( !strcmp( p_tk->psz_codec, "A_TTA1" ) )
-        {
-            p_fmt->i_codec = VLC_CODEC_TTA;
-            if( p_tk->i_extra_data > 0 )
-            {
-              fill_extra_data( p_tk, 0 );
-            }
-            else
-            {
-                p_fmt->i_extra = 30;
-                p_fmt->p_extra = xmalloc( p_fmt->i_extra );
-                uint8_t *p_extra = (uint8_t*)p_fmt->p_extra;
-                memcpy( &p_extra[ 0], "TTA1", 4 );
-                SetWLE( &p_extra[ 4], 1 );
-                SetWLE( &p_extra[ 6], p_fmt->audio.i_channels );
-                SetWLE( &p_extra[ 8], p_fmt->audio.i_bitspersample );
-                SetDWLE( &p_extra[10], p_fmt->audio.i_rate );
-                SetDWLE( &p_extra[14], 0xffffffff );
-                memset( &p_extra[18], 0, 30  - 18 );
-            }
-        }
-        else if( !strcmp( p_tk->psz_codec, "A_PCM/INT/BIG" ) ||
-                 !strcmp( p_tk->psz_codec, "A_PCM/INT/LIT" ) ||
-                 !strcmp( p_tk->psz_codec, "A_PCM/FLOAT/IEEE" ) )
-        {
-            if( !strcmp( p_tk->psz_codec, "A_PCM/INT/BIG" ) )
-            {
-                p_tk->fmt.i_codec = VLC_FOURCC( 't', 'w', 'o', 's' );
-            }
-            else
-            {
-                p_tk->fmt.i_codec = VLC_FOURCC( 'a', 'r', 'a', 'w' );
-            }
-            p_tk->fmt.audio.i_blockalign = ( p_tk->fmt.audio.i_bitspersample + 7 ) / 8 * p_tk->fmt.audio.i_channels;
-        }
-        else if( !strncmp( p_tk->psz_codec, "A_REAL/", 7 ) )
-        {
-            if( !strcmp( p_tk->psz_codec, "A_REAL/14_4" ) )
-            {
-                p_fmt->i_codec = VLC_CODEC_RA_144;
-                p_fmt->audio.i_channels = 1;
-                p_fmt->audio.i_rate = 8000;
-                p_fmt->audio.i_blockalign = 0x14;
-            }
-            else if( p_tk->i_extra_data > 28 )
-            {
-                uint8_t *p = p_tk->p_extra_data;
-                if( memcmp( p, ".ra", 3 ) ) {
-                    msg_Err( &sys.demuxer, "Invalid Real ExtraData 0x%4.4s", (char *)p );
-                    p_tk->fmt.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
-                }
-                else
-                {
-                    real_audio_private * priv = (real_audio_private*) p_tk->p_extra_data;
-                    if( !strcmp( p_tk->psz_codec, "A_REAL/COOK" ) )
-                    {
-                        p_tk->fmt.i_codec = VLC_CODEC_COOK;
-                        p_tk->fmt.audio.i_blockalign = hton16(priv->sub_packet_size);
-                    }
-                    else if( !strcmp( p_tk->psz_codec, "A_REAL/ATRC" ) )
-                        p_tk->fmt.i_codec = VLC_CODEC_ATRAC3;
-                    else if( !strcmp( p_tk->psz_codec, "A_REAL/28_8" ) )
-                        p_tk->fmt.i_codec = VLC_CODEC_RA_288;
-                    /* FIXME RALF and SIPR */
-                    uint16_t version = (uint16_t) hton16(priv->version);
-                    p_tk->p_sys =
-                        new Cook_PrivateTrackData( hton16(priv->sub_packet_h),
-                                                   hton16(priv->frame_size),
-                                                   hton16(priv->sub_packet_size));
-                    if( unlikely( !p_tk->p_sys ) )
-                        continue;
-
-                    if( unlikely( p_tk->p_sys->Init() ) )
-                        continue;
-
-                    if( version == 4 )
-                    {
-                        real_audio_private_v4 * v4 = (real_audio_private_v4*) priv;
-                        p_tk->fmt.audio.i_channels = hton16(v4->channels);
-                        p_tk->fmt.audio.i_bitspersample = hton16(v4->sample_size);
-                        p_tk->fmt.audio.i_rate = hton16(v4->sample_rate);
-                    }
-                    else if( version == 5 )
-                    {
-                        real_audio_private_v5 * v5 = (real_audio_private_v5*) priv;
-                        p_tk->fmt.audio.i_channels = hton16(v5->channels);
-                        p_tk->fmt.audio.i_bitspersample = hton16(v5->sample_size);
-                        p_tk->fmt.audio.i_rate = hton16(v5->sample_rate);
-                    }
-                    msg_Dbg(&sys.demuxer, "%d channels %d bits %d Hz",p_tk->fmt.audio.i_channels, p_tk->fmt.audio.i_bitspersample, p_tk->fmt.audio.i_rate);
-
-                    fill_extra_data( p_tk, p_tk->fmt.i_codec == VLC_CODEC_RA_288 ? 0 : 78);
-                }
-            }
-        }
-        else if( !strcmp( p_tk->psz_codec, "S_KATE" ) )
-        {
-            p_tk->fmt.i_codec = VLC_CODEC_KATE;
-            p_tk->fmt.subs.psz_encoding = strdup( "UTF-8" );
-
-            fill_extra_data( p_tk, 0 );
-        }
-        else if( !strcmp( p_tk->psz_codec, "S_TEXT/ASCII" ) )
-        {
-            p_fmt->i_codec = VLC_CODEC_SUBT;
-            p_fmt->subs.psz_encoding = strdup( "ASCII" );
-        }
-        else if( !strcmp( p_tk->psz_codec, "S_TEXT/UTF8" ) )
-        {
-            p_tk->fmt.i_codec = VLC_CODEC_SUBT;
-            p_tk->fmt.subs.psz_encoding = strdup( "UTF-8" );
-        }
-        else if( !strcmp( p_tk->psz_codec, "S_TEXT/USF" ) )
-        {
-            p_tk->fmt.i_codec = VLC_FOURCC( 'u', 's', 'f', ' ' );
-            p_tk->fmt.subs.psz_encoding = strdup( "UTF-8" );
-            if( p_tk->i_extra_data )
-                fill_extra_data( p_tk, 0 );
-        }
-        else if( !strcmp( p_tk->psz_codec, "S_TEXT/SSA" ) ||
-                 !strcmp( p_tk->psz_codec, "S_TEXT/ASS" ) ||
-                 !strcmp( p_tk->psz_codec, "S_SSA" ) ||
-                 !strcmp( p_tk->psz_codec, "S_ASS" ))
-        {
-            p_tk->fmt.i_codec = VLC_CODEC_SSA;
-            p_tk->fmt.subs.psz_encoding = strdup( "UTF-8" );
-            if( p_tk->i_extra_data )
-                fill_extra_data( p_tk, 0 );
-        }
-        else if( !strcmp( p_tk->psz_codec, "S_VOBSUB" ) )
-        {
-            p_tk->fmt.i_codec = VLC_CODEC_SPU;
-            if( p_tk->i_extra_data )
-            {
-                char *psz_start;
-                char *psz_buf = (char *)malloc( p_tk->i_extra_data + 1);
-                if( psz_buf != NULL )
-                {
-                    memcpy( psz_buf, p_tk->p_extra_data , p_tk->i_extra_data );
-                    psz_buf[p_tk->i_extra_data] = '\0';
-
-                    psz_start = strstr( psz_buf, "size:" );
-                    if( psz_start &&
-                        vobsub_size_parse( psz_start,
-                                           &p_tk->fmt.subs.spu.i_original_frame_width,
-                                           &p_tk->fmt.subs.spu.i_original_frame_height ) == VLC_SUCCESS )
-                    {
-                        msg_Dbg( &sys.demuxer, "original frame size vobsubs: %dx%d",
-                                 p_tk->fmt.subs.spu.i_original_frame_width,
-                                 p_tk->fmt.subs.spu.i_original_frame_height );
-                    }
-                    else
-                    {
-                        msg_Warn( &sys.demuxer, "reading original frame size for vobsub failed" );
-                    }
-
-                    psz_start = strstr( psz_buf, "palette:" );
-                    if( psz_start &&
-                        vobsub_palette_parse( psz_start, &p_tk->fmt.subs.spu.palette[1] ) == VLC_SUCCESS )
-                    {
-                        p_tk->fmt.subs.spu.palette[0] =  0xBeef;
-                        msg_Dbg( &sys.demuxer, "vobsub palette read" );
-                    }
-                    else
-                    {
-                        msg_Warn( &sys.demuxer, "reading original palette failed" );
-                    }
-                    free( psz_buf );
-                }
-            }
-        }
-        else if( !strcmp( p_tk->psz_codec, "S_HDMV/PGS" ) )
-        {
-            p_tk->fmt.i_codec = VLC_CODEC_BD_PG;
-        }
-        else if( !strcmp( p_tk->psz_codec, "B_VOBBTN" ) )
-        {
-            p_tk->fmt.i_cat = NAV_ES;
-            continue;
-        }
-        else
-        {
-            msg_Err( &sys.demuxer, "unknown codec id=`%s'", p_tk->psz_codec );
-            p_tk->fmt.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
-        }
         if( unlikely( !p_tk->b_enabled ) )
             p_tk->fmt.i_priority = -2;
         else if( p_tk->b_forced )
diff --git a/modules/demux/mkv/matroska_segment.hpp b/modules/demux/mkv/matroska_segment.hpp
index 9bd4297..a36a73e 100644
--- a/modules/demux/mkv/matroska_segment.hpp
+++ b/modules/demux/mkv/matroska_segment.hpp
@@ -161,6 +161,7 @@ private:
     void ParseCluster( bool b_update_start_time = true );
     SimpleTag * ParseSimpleTags( KaxTagSimple *tag, int level = 50 );
     void IndexAppendCluster( KaxCluster *cluster );
+    int32_t TrackInit( mkv_track_t * p_tk );
 };
 
 
diff --git a/modules/demux/mkv/matroska_segment_parse.cpp b/modules/demux/mkv/matroska_segment_parse.cpp
index d0f8368..ecdd129 100644
--- a/modules/demux/mkv/matroska_segment_parse.cpp
+++ b/modules/demux/mkv/matroska_segment_parse.cpp
@@ -21,17 +21,35 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
-
+#include "mkv.hpp"
 #include "matroska_segment.hpp"
-
 #include "chapters.hpp"
-
 #include "demux.hpp"
-
 #include "Ebml_parser.hpp"
-
 #include "util.hpp"
 
+extern "C" {
+#include "../vobsub.h"
+}
+
+#include <vlc_codecs.h>
+
+/* GetFourCC helper */
+#define GetFOURCC( p )  __GetFOURCC( (uint8_t*)p )
+static vlc_fourcc_t __GetFOURCC( uint8_t *p )
+{
+    return VLC_FOURCC( p[0], p[1], p[2], p[3] );
+}
+
+static inline void fill_extra_data( mkv_track_t *p_tk, unsigned int offset )
+{
+    if(p_tk->i_extra_data <= offset) return;
+    p_tk->fmt.i_extra = p_tk->i_extra_data - offset;
+    p_tk->fmt.p_extra = xmalloc( p_tk->fmt.i_extra );
+    if(!p_tk->fmt.p_extra) { p_tk->fmt.i_extra = 0; return; };
+    memcpy( p_tk->fmt.p_extra, p_tk->p_extra_data + offset, p_tk->fmt.i_extra );
+}
+
 /*****************************************************************************
  * Some functions to manipulate memory
  *****************************************************************************/
@@ -667,6 +685,13 @@ void matroska_segment_c::ParseTrackEntry( KaxTrackEntry *m )
             zlib_decompress_extra( &sys.demuxer, tk) )
             return;
 #endif
+        if( TrackInit( tk ) )
+        {
+            msg_Err(&sys.demuxer, "Couldn't init track %d", tk->i_number );
+            free(tk->p_extra_data);
+            delete tk;
+            return;
+        }
 
         tracks.push_back( tk );
     }
@@ -896,11 +921,11 @@ void matroska_segment_c::ParseChapterAtom( int i_level, KaxChapterAtom *ca, chap
             chapters.p_segment_edition_uid = new KaxChapterSegmentEditionUID( *static_cast<KaxChapterSegmentEditionUID*>(l) );
             msg_Dbg( &sys.demuxer, "|   |   |   |   + ChapterSegmentEditionUID= %u",
 #if LIBMATROSKA_VERSION < 0x010300
-            *(uint32*)chapters.p_segment_edition_uid->GetBuffer()
+                     *(uint32*)chapters.p_segment_edition_uid->GetBuffer()
 #else
-            *(uint32*)chapters.p_segment_edition_uid
+                     *(uint32*)chapters.p_segment_edition_uid
 #endif
-            );
+                   );
         }
         else if( MKV_IS_ID( l, KaxChapterTimeStart ) )
         {
@@ -1024,26 +1049,26 @@ void matroska_segment_c::ParseAttachments( KaxAttachments *attachments )
         std::string attached_filename(psz_tmp_utf8);
         free(psz_tmp_utf8);
         attachment_c *new_attachment = new attachment_c( attached_filename,
-                                                        GetChild<KaxMimeType>( *attachedFile ),
-                                                        img_data.GetSize() );
+                                                         GetChild<KaxMimeType>( *attachedFile ),
+                                                         img_data.GetSize() );
 
         msg_Dbg( &sys.demuxer, "|   |   - %s (%s)", new_attachment->fileName(), new_attachment->mimeType() );
 
         if( new_attachment->init() )
         {
-             memcpy( new_attachment->p_data, img_data.GetBuffer(), img_data.GetSize() );
-             sys.stored_attachments.push_back( new_attachment );
-             if( !strncmp( new_attachment->mimeType(), "image/", 6 ) )
-             {
-                 char *psz_url;
-                 if( asprintf( &psz_url, "attachment://%s",
-                             new_attachment->fileName() ) == -1 )
-                     continue;
-                 if( !sys.meta )
-                     sys.meta = vlc_meta_New();
-                 vlc_meta_SetArtURL( sys.meta, psz_url );
-                 free( psz_url );
-             }
+            memcpy( new_attachment->p_data, img_data.GetBuffer(), img_data.GetSize() );
+            sys.stored_attachments.push_back( new_attachment );
+            if( !strncmp( new_attachment->mimeType(), "image/", 6 ) )
+            {
+                char *psz_url;
+                if( asprintf( &psz_url, "attachment://%s",
+                              new_attachment->fileName() ) == -1 )
+                    continue;
+                if( !sys.meta )
+                    sys.meta = vlc_meta_New();
+                vlc_meta_SetArtURL( sys.meta, psz_url );
+                free( psz_url );
+            }
         }
         else
         {
@@ -1143,3 +1168,453 @@ void matroska_segment_c::ParseCluster( bool b_update_start_time )
         i_start_time = cluster->GlobalTimecode() / 1000;
 }
 
+
+int32_t matroska_segment_c::TrackInit( mkv_track_t * p_tk )
+{
+    es_format_t *p_fmt = &p_tk->fmt;
+    if( !strcmp( p_tk->psz_codec, "V_MS/VFW/FOURCC" ) )
+    {
+        if( p_tk->i_extra_data < (int)sizeof( VLC_BITMAPINFOHEADER ) )
+        {
+            msg_Err( &sys.demuxer, "missing/invalid VLC_BITMAPINFOHEADER" );
+            p_tk->fmt.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
+        }
+        else
+        {
+            VLC_BITMAPINFOHEADER *p_bih = (VLC_BITMAPINFOHEADER*)p_tk->p_extra_data;
+
+            p_tk->fmt.video.i_width = GetDWLE( &p_bih->biWidth );
+            p_tk->fmt.video.i_height= GetDWLE( &p_bih->biHeight );
+            p_tk->fmt.i_codec       = GetFOURCC( &p_bih->biCompression );
+
+            p_tk->fmt.i_extra       = GetDWLE( &p_bih->biSize ) - sizeof( VLC_BITMAPINFOHEADER );
+            if( p_tk->fmt.i_extra > 0 )
+            {
+                /* Very unlikely yet possible: bug #5659*/
+                size_t maxlen = p_tk->i_extra_data - sizeof( VLC_BITMAPINFOHEADER );
+                p_tk->fmt.i_extra = ( (unsigned)p_tk->fmt.i_extra < maxlen )?
+                    p_tk->fmt.i_extra : maxlen;
+
+                p_tk->fmt.p_extra = xmalloc( p_tk->fmt.i_extra );
+                memcpy( p_tk->fmt.p_extra, &p_bih[1], p_tk->fmt.i_extra );
+            }
+        }
+        p_tk->b_dts_only = true;
+    }
+    else if( !strcmp( p_tk->psz_codec, "V_MPEG1" ) ||
+             !strcmp( p_tk->psz_codec, "V_MPEG2" ) )
+    {
+        p_tk->fmt.i_codec = VLC_CODEC_MPGV;
+        if( p_tk->i_extra_data )
+            fill_extra_data( p_tk, 0 );
+    }
+    else if( !strncmp( p_tk->psz_codec, "V_THEORA", 8 ) )
+    {
+        p_tk->fmt.i_codec = VLC_CODEC_THEORA;
+        fill_extra_data( p_tk, 0 );
+        p_tk->b_pts_only = true;
+    }
+    else if( !strncmp( p_tk->psz_codec, "V_REAL/RV", 9 ) )
+    {
+        uint8_t *p = p_tk->p_extra_data;
+
+        if( !strcmp( p_tk->psz_codec, "V_REAL/RV10" ) )
+            p_fmt->i_codec = VLC_CODEC_RV10;
+        else if( !strcmp( p_tk->psz_codec, "V_REAL/RV20" ) )
+            p_fmt->i_codec = VLC_CODEC_RV20;
+        else if( !strcmp( p_tk->psz_codec, "V_REAL/RV30" ) )
+            p_fmt->i_codec = VLC_CODEC_RV30;
+        else if( !strcmp( p_tk->psz_codec, "V_REAL/RV40" ) )
+            p_fmt->i_codec = VLC_CODEC_RV40;
+
+        /* Extract the framerate from the header */
+        if( p_tk->i_extra_data >= 26 &&
+            p[4] == 'V' && p[5] == 'I' && p[6] == 'D' && p[7] == 'O' &&
+            p[8] == 'R' && p[9] == 'V' &&
+            (p[10] == '3' || p[10] == '4') && p[11] == '0' )
+        {
+            p_tk->fmt.video.i_frame_rate =
+                p[22] << 24 | p[23] << 16 | p[24] << 8 | p[25] << 0;
+            p_tk->fmt.video.i_frame_rate_base = 65536;
+        }
+
+        fill_extra_data( p_tk, 26 );
+        p_tk->b_dts_only = true;
+    }
+    else if( !strncmp( p_tk->psz_codec, "V_DIRAC", 7 ) )
+    {
+        p_tk->fmt.i_codec = VLC_CODEC_DIRAC;
+    }
+    else if( !strncmp( p_tk->psz_codec, "V_VP8", 5 ) )
+    {
+        p_tk->fmt.i_codec = VLC_CODEC_VP8;
+        p_tk->b_pts_only = true;
+    }
+    else if( !strncmp( p_tk->psz_codec, "V_MPEG4", 7 ) )
+    {
+        if( !strcmp( p_tk->psz_codec, "V_MPEG4/MS/V3" ) )
+        {
+            p_tk->fmt.i_codec = VLC_CODEC_DIV3;
+        }
+        else if( !strncmp( p_tk->psz_codec, "V_MPEG4/ISO", 11 ) )
+        {
+            /* A MPEG 4 codec, SP, ASP, AP or AVC */
+            if( !strcmp( p_tk->psz_codec, "V_MPEG4/ISO/AVC" ) )
+                p_tk->fmt.i_codec = VLC_FOURCC( 'a', 'v', 'c', '1' );
+            else
+                p_tk->fmt.i_codec = VLC_CODEC_MP4V;
+            fill_extra_data( p_tk, 0 );
+        }
+    }
+    else if( !strcmp( p_tk->psz_codec, "V_QUICKTIME" ) )
+    {
+        MP4_Box_t *p_box = (MP4_Box_t*)xmalloc( sizeof( MP4_Box_t ) );
+        stream_t *p_mp4_stream = stream_MemoryNew( VLC_OBJECT(&sys.demuxer),
+                                                   p_tk->p_extra_data,
+                                                   p_tk->i_extra_data,
+                                                   true );
+        if( MP4_ReadBoxCommon( p_mp4_stream, p_box ) &&
+            MP4_ReadBox_sample_vide( p_mp4_stream, p_box ) )
+        {
+            p_tk->fmt.i_codec = p_box->i_type;
+            p_tk->fmt.video.i_width = p_box->data.p_sample_vide->i_width;
+            p_tk->fmt.video.i_height = p_box->data.p_sample_vide->i_height;
+            p_tk->fmt.i_extra = p_box->data.p_sample_vide->i_qt_image_description;
+            p_tk->fmt.p_extra = xmalloc( p_tk->fmt.i_extra );
+            memcpy( p_tk->fmt.p_extra, p_box->data.p_sample_vide->p_qt_image_description, p_tk->fmt.i_extra );
+            MP4_FreeBox_sample_vide( p_box );
+        }
+        else
+        {
+            free( p_box );
+        }
+        stream_Delete( p_mp4_stream );
+    }
+    else if( !strcmp( p_tk->psz_codec, "V_MJPEG" ) )
+    {
+        p_tk->fmt.i_codec = VLC_CODEC_MJPG;
+    }
+    else if( !strcmp( p_tk->psz_codec, "A_MS/ACM" ) )
+    {
+        if( p_tk->i_extra_data < (int)sizeof( WAVEFORMATEX ) )
+        {
+            msg_Err( &sys.demuxer, "missing/invalid WAVEFORMATEX" );
+            p_tk->fmt.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
+        }
+        else
+        {
+            WAVEFORMATEX *p_wf = (WAVEFORMATEX*)p_tk->p_extra_data;
+
+            wf_tag_to_fourcc( GetWLE( &p_wf->wFormatTag ), &p_tk->fmt.i_codec, NULL );
+
+            if( p_tk->fmt.i_codec == VLC_FOURCC( 'u', 'n', 'd', 'f' ) )
+                msg_Err( &sys.demuxer, "Unrecognized wf tag: 0x%x", GetWLE( &p_wf->wFormatTag ) );
+            p_tk->fmt.audio.i_channels   = GetWLE( &p_wf->nChannels );
+            p_tk->fmt.audio.i_rate = GetDWLE( &p_wf->nSamplesPerSec );
+            p_tk->fmt.i_bitrate    = GetDWLE( &p_wf->nAvgBytesPerSec ) * 8;
+            p_tk->fmt.audio.i_blockalign = GetWLE( &p_wf->nBlockAlign );;
+            p_tk->fmt.audio.i_bitspersample = GetWLE( &p_wf->wBitsPerSample );
+
+            p_tk->fmt.i_extra            = GetWLE( &p_wf->cbSize );
+            if( p_tk->fmt.i_extra > 0 )
+            {
+                p_tk->fmt.p_extra = xmalloc( p_tk->fmt.i_extra );
+                memcpy( p_tk->fmt.p_extra, &p_wf[1], p_tk->fmt.i_extra );
+            }
+        }
+    }
+    else if( !strcmp( p_tk->psz_codec, "A_MPEG/L3" ) ||
+             !strcmp( p_tk->psz_codec, "A_MPEG/L2" ) ||
+             !strcmp( p_tk->psz_codec, "A_MPEG/L1" ) )
+    {
+        p_tk->fmt.i_codec = VLC_CODEC_MPGA;
+    }
+    else if( !strcmp( p_tk->psz_codec, "A_AC3" ) )
+    {
+        p_tk->fmt.i_codec = VLC_CODEC_A52;
+    }
+    else if( !strcmp( p_tk->psz_codec, "A_EAC3" ) )
+    {
+        p_tk->fmt.i_codec = VLC_CODEC_EAC3;
+    }
+    else if( !strcmp( p_tk->psz_codec, "A_DTS" ) )
+    {
+        p_tk->fmt.i_codec = VLC_CODEC_DTS;
+    }
+    else if( !strcmp( p_tk->psz_codec, "A_MLP" ) )
+    {
+        p_tk->fmt.i_codec = VLC_CODEC_MLP;
+    }
+    else if( !strcmp( p_tk->psz_codec, "A_TRUEHD" ) )
+    {
+        /* FIXME when more samples arrive */
+        p_tk->fmt.i_codec = VLC_CODEC_TRUEHD;
+        p_fmt->b_packetized = false;
+    }
+    else if( !strcmp( p_tk->psz_codec, "A_FLAC" ) )
+    {
+        p_tk->fmt.i_codec = VLC_CODEC_FLAC;
+        fill_extra_data( p_tk, 0 );
+    }
+    else if( !strcmp( p_tk->psz_codec, "A_VORBIS" ) )
+    {
+        p_tk->fmt.i_codec = VLC_CODEC_VORBIS;
+        fill_extra_data( p_tk, 0 );
+    }
+    else if( !strncmp( p_tk->psz_codec, "A_AAC/MPEG2/", strlen( "A_AAC/MPEG2/" ) ) ||
+             !strncmp( p_tk->psz_codec, "A_AAC/MPEG4/", strlen( "A_AAC/MPEG4/" ) ) )
+    {
+        int i_profile, i_srate, sbr = 0;
+        static const unsigned int i_sample_rates[] =
+        {
+            96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
+            16000, 12000, 11025,  8000,  7350,     0,     0,     0
+        };
+
+        p_tk->fmt.i_codec = VLC_CODEC_MP4A;
+        /* create data for faad (MP4DecSpecificDescrTag)*/
+
+        if( !strcmp( &p_tk->psz_codec[12], "MAIN" ) )
+        {
+            i_profile = 0;
+        }
+        else if( !strcmp( &p_tk->psz_codec[12], "LC" ) )
+        {
+            i_profile = 1;
+        }
+        else if( !strcmp( &p_tk->psz_codec[12], "SSR" ) )
+        {
+            i_profile = 2;
+        }
+        else if( !strcmp( &p_tk->psz_codec[12], "LC/SBR" ) )
+        {
+            i_profile = 1;
+            sbr = 1;
+        }
+        else
+        {
+            i_profile = 3;
+        }
+
+        for( i_srate = 0; i_srate < 13; i_srate++ )
+        {
+            if( i_sample_rates[i_srate] == p_tk->i_original_rate )
+            {
+                break;
+            }
+        }
+        msg_Dbg( &sys.demuxer, "profile=%d srate=%d", i_profile, i_srate );
+
+        p_tk->fmt.i_extra = sbr ? 5 : 2;
+        p_tk->fmt.p_extra = xmalloc( p_tk->fmt.i_extra );
+        ((uint8_t*)p_tk->fmt.p_extra)[0] = ((i_profile + 1) << 3) | ((i_srate&0xe) >> 1);
+        ((uint8_t*)p_tk->fmt.p_extra)[1] = ((i_srate & 0x1) << 7) | (p_tk->fmt.audio.i_channels << 3);
+        if (sbr != 0)
+        {
+            int syncExtensionType = 0x2B7;
+            int iDSRI;
+            for (iDSRI=0; iDSRI<13; iDSRI++)
+                if( i_sample_rates[iDSRI] == p_tk->fmt.audio.i_rate )
+                    break;
+            ((uint8_t*)p_tk->fmt.p_extra)[2] = (syncExtensionType >> 3) & 0xFF;
+            ((uint8_t*)p_tk->fmt.p_extra)[3] = ((syncExtensionType & 0x7) << 5) | 5;
+            ((uint8_t*)p_tk->fmt.p_extra)[4] = ((1 & 0x1) << 7) | (iDSRI << 3);
+        }
+    }
+    else if( !strcmp( p_tk->psz_codec, "A_AAC" ) )
+    {
+        p_tk->fmt.i_codec = VLC_CODEC_MP4A;
+        fill_extra_data( p_tk, 0 );
+    }
+    else if( !strcmp( p_tk->psz_codec, "A_WAVPACK4" ) )
+    {
+        p_tk->fmt.i_codec = VLC_CODEC_WAVPACK;
+        fill_extra_data( p_tk, 0 );
+    }
+    else if( !strcmp( p_tk->psz_codec, "A_TTA1" ) )
+    {
+        p_fmt->i_codec = VLC_CODEC_TTA;
+        if( p_tk->i_extra_data > 0 )
+        {
+            fill_extra_data( p_tk, 0 );
+        }
+        else
+        {
+            p_fmt->i_extra = 30;
+            p_fmt->p_extra = xmalloc( p_fmt->i_extra );
+            uint8_t *p_extra = (uint8_t*)p_fmt->p_extra;
+            memcpy( &p_extra[ 0], "TTA1", 4 );
+            SetWLE( &p_extra[ 4], 1 );
+            SetWLE( &p_extra[ 6], p_fmt->audio.i_channels );
+            SetWLE( &p_extra[ 8], p_fmt->audio.i_bitspersample );
+            SetDWLE( &p_extra[10], p_fmt->audio.i_rate );
+            SetDWLE( &p_extra[14], 0xffffffff );
+            memset( &p_extra[18], 0, 30  - 18 );
+        }
+    }
+    else if( !strcmp( p_tk->psz_codec, "A_PCM/INT/BIG" ) ||
+             !strcmp( p_tk->psz_codec, "A_PCM/INT/LIT" ) ||
+             !strcmp( p_tk->psz_codec, "A_PCM/FLOAT/IEEE" ) )
+    {
+        if( !strcmp( p_tk->psz_codec, "A_PCM/INT/BIG" ) )
+        {
+            p_tk->fmt.i_codec = VLC_FOURCC( 't', 'w', 'o', 's' );
+        }
+        else
+        {
+            p_tk->fmt.i_codec = VLC_FOURCC( 'a', 'r', 'a', 'w' );
+        }
+        p_tk->fmt.audio.i_blockalign = ( p_tk->fmt.audio.i_bitspersample + 7 ) / 8 * p_tk->fmt.audio.i_channels;
+    }
+    else if( !strncmp( p_tk->psz_codec, "A_REAL/", 7 ) )
+    {
+        if( !strcmp( p_tk->psz_codec, "A_REAL/14_4" ) )
+        {
+            p_fmt->i_codec = VLC_CODEC_RA_144;
+            p_fmt->audio.i_channels = 1;
+            p_fmt->audio.i_rate = 8000;
+            p_fmt->audio.i_blockalign = 0x14;
+        }
+        else if( p_tk->i_extra_data > 28 )
+        {
+            uint8_t *p = p_tk->p_extra_data;
+            if( memcmp( p, ".ra", 3 ) ) {
+                msg_Err( &sys.demuxer, "Invalid Real ExtraData 0x%4.4s", (char *)p );
+                p_tk->fmt.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
+            }
+            else
+            {
+                real_audio_private * priv = (real_audio_private*) p_tk->p_extra_data;
+                if( !strcmp( p_tk->psz_codec, "A_REAL/COOK" ) )
+                {
+                    p_tk->fmt.i_codec = VLC_CODEC_COOK;
+                    p_tk->fmt.audio.i_blockalign = hton16(priv->sub_packet_size);
+                }
+                else if( !strcmp( p_tk->psz_codec, "A_REAL/ATRC" ) )
+                    p_tk->fmt.i_codec = VLC_CODEC_ATRAC3;
+                else if( !strcmp( p_tk->psz_codec, "A_REAL/28_8" ) )
+                    p_tk->fmt.i_codec = VLC_CODEC_RA_288;
+                /* FIXME RALF and SIPR */
+                uint16_t version = (uint16_t) hton16(priv->version);
+                p_tk->p_sys =
+                    new Cook_PrivateTrackData( hton16(priv->sub_packet_h),
+                                               hton16(priv->frame_size),
+                                               hton16(priv->sub_packet_size));
+                if( unlikely( !p_tk->p_sys ) )
+                    return 1;
+
+                if( unlikely( p_tk->p_sys->Init() ) )
+                    return 1;
+
+                if( version == 4 )
+                {
+                    real_audio_private_v4 * v4 = (real_audio_private_v4*) priv;
+                    p_tk->fmt.audio.i_channels = hton16(v4->channels);
+                    p_tk->fmt.audio.i_bitspersample = hton16(v4->sample_size);
+                    p_tk->fmt.audio.i_rate = hton16(v4->sample_rate);
+                }
+                else if( version == 5 )
+                {
+                    real_audio_private_v5 * v5 = (real_audio_private_v5*) priv;
+                    p_tk->fmt.audio.i_channels = hton16(v5->channels);
+                    p_tk->fmt.audio.i_bitspersample = hton16(v5->sample_size);
+                    p_tk->fmt.audio.i_rate = hton16(v5->sample_rate);
+                }
+                msg_Dbg(&sys.demuxer, "%d channels %d bits %d Hz",p_tk->fmt.audio.i_channels, p_tk->fmt.audio.i_bitspersample, p_tk->fmt.audio.i_rate);
+
+                fill_extra_data( p_tk, p_tk->fmt.i_codec == VLC_CODEC_RA_288 ? 0 : 78);
+            }
+        }
+    }
+    else if( !strcmp( p_tk->psz_codec, "S_KATE" ) )
+    {
+        p_tk->fmt.i_codec = VLC_CODEC_KATE;
+        p_tk->fmt.subs.psz_encoding = strdup( "UTF-8" );
+
+        fill_extra_data( p_tk, 0 );
+    }
+    else if( !strcmp( p_tk->psz_codec, "S_TEXT/ASCII" ) )
+    {
+        p_fmt->i_codec = VLC_CODEC_SUBT;
+        p_fmt->subs.psz_encoding = strdup( "ASCII" );
+    }
+    else if( !strcmp( p_tk->psz_codec, "S_TEXT/UTF8" ) )
+    {
+        p_tk->fmt.i_codec = VLC_CODEC_SUBT;
+        p_tk->fmt.subs.psz_encoding = strdup( "UTF-8" );
+    }
+    else if( !strcmp( p_tk->psz_codec, "S_TEXT/USF" ) )
+    {
+        p_tk->fmt.i_codec = VLC_FOURCC( 'u', 's', 'f', ' ' );
+        p_tk->fmt.subs.psz_encoding = strdup( "UTF-8" );
+        if( p_tk->i_extra_data )
+            fill_extra_data( p_tk, 0 );
+    }
+    else if( !strcmp( p_tk->psz_codec, "S_TEXT/SSA" ) ||
+             !strcmp( p_tk->psz_codec, "S_TEXT/ASS" ) ||
+             !strcmp( p_tk->psz_codec, "S_SSA" ) ||
+             !strcmp( p_tk->psz_codec, "S_ASS" ))
+    {
+        p_tk->fmt.i_codec = VLC_CODEC_SSA;
+        p_tk->fmt.subs.psz_encoding = strdup( "UTF-8" );
+        if( p_tk->i_extra_data )
+            fill_extra_data( p_tk, 0 );
+    }
+    else if( !strcmp( p_tk->psz_codec, "S_VOBSUB" ) )
+    {
+        p_tk->fmt.i_codec = VLC_CODEC_SPU;
+        if( p_tk->i_extra_data )
+        {
+            char *psz_start;
+            char *psz_buf = (char *)malloc( p_tk->i_extra_data + 1);
+            if( psz_buf != NULL )
+            {
+                memcpy( psz_buf, p_tk->p_extra_data , p_tk->i_extra_data );
+                psz_buf[p_tk->i_extra_data] = '\0';
+
+                psz_start = strstr( psz_buf, "size:" );
+                if( psz_start &&
+                    vobsub_size_parse( psz_start,
+                                       &p_tk->fmt.subs.spu.i_original_frame_width,
+                                       &p_tk->fmt.subs.spu.i_original_frame_height ) == VLC_SUCCESS )
+                {
+                    msg_Dbg( &sys.demuxer, "original frame size vobsubs: %dx%d",
+                             p_tk->fmt.subs.spu.i_original_frame_width,
+                             p_tk->fmt.subs.spu.i_original_frame_height );
+                }
+                else
+                {
+                    msg_Warn( &sys.demuxer, "reading original frame size for vobsub failed" );
+                    return 1;
+                }
+
+                psz_start = strstr( psz_buf, "palette:" );
+                if( psz_start &&
+                    vobsub_palette_parse( psz_start, &p_tk->fmt.subs.spu.palette[1] ) == VLC_SUCCESS )
+                {
+                    p_tk->fmt.subs.spu.palette[0] =  0xBeef;
+                    msg_Dbg( &sys.demuxer, "vobsub palette read" );
+                }
+                else
+                {
+                    msg_Warn( &sys.demuxer, "reading original palette failed" );
+                }
+                free( psz_buf );
+            }
+        }
+    }
+    else if( !strcmp( p_tk->psz_codec, "S_HDMV/PGS" ) )
+    {
+        p_tk->fmt.i_codec = VLC_CODEC_BD_PG;
+    }
+    else if( !strcmp( p_tk->psz_codec, "B_VOBBTN" ) )
+    {
+        p_tk->fmt.i_cat = NAV_ES;
+    }
+    else
+    {
+        msg_Err( &sys.demuxer, "unknown codec id=`%s'", p_tk->psz_codec );
+        p_tk->fmt.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
+    }
+    return 0;
+}
-- 
1.7.10.4




More information about the vlc-devel mailing list