1 /*****************************************************************************
2 * mkv.cpp : matroska demuxer
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: mkv.cpp,v 1.22 2003/08/18 00:17:44 fenrir Exp $
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
32 # include <time.h> /* time() */
35 #include <vlc/input.h>
37 #include <codecs.h> /* BITMAPINFOHEADER, WAVEFORMATEX */
47 /* libebml and matroska */
48 #include "ebml/EbmlHead.h"
49 #include "ebml/EbmlSubHead.h"
50 #include "ebml/EbmlStream.h"
51 #include "ebml/EbmlContexts.h"
52 #include "ebml/EbmlVersion.h"
53 #include "ebml/EbmlVoid.h"
55 #include "matroska/FileKax.h"
56 #ifdef HAVE_MATROSKA_KAXATTACHMENTS_H
57 #include "matroska/KaxAttachments.h"
59 #include "matroska/KaxAttachements.h"
61 #include "matroska/KaxBlock.h"
62 #include "matroska/KaxBlockData.h"
63 #include "matroska/KaxChapters.h"
64 #include "matroska/KaxCluster.h"
65 #include "matroska/KaxClusterData.h"
66 #include "matroska/KaxContexts.h"
67 #include "matroska/KaxCues.h"
68 #include "matroska/KaxCuesData.h"
69 #include "matroska/KaxInfo.h"
70 #include "matroska/KaxInfoData.h"
71 #include "matroska/KaxSeekHead.h"
72 #include "matroska/KaxSegment.h"
73 #include "matroska/KaxTag.h"
74 #include "matroska/KaxTags.h"
75 #include "matroska/KaxTagMulti.h"
76 #include "matroska/KaxTracks.h"
77 #include "matroska/KaxTrackAudio.h"
78 #include "matroska/KaxTrackVideo.h"
79 #include "matroska/KaxTrackEntryData.h"
81 #include "ebml/StdIOCallback.h"
83 using namespace LIBMATROSKA_NAMESPACE;
87 /*****************************************************************************
89 *****************************************************************************/
90 static int Activate ( vlc_object_t * );
91 static void Deactivate( vlc_object_t * );
92 static int Demux ( input_thread_t * );
94 /*****************************************************************************
96 *****************************************************************************/
98 add_category_hint( N_("mkv-demuxer"), NULL, VLC_TRUE );
99 add_bool( "mkv-seek-percent", 1, NULL,
100 N_("Seek based on percent not time"),
101 N_("Seek based on percent not time"), VLC_TRUE );
103 set_description( _("mka/mkv stream demuxer" ) );
104 set_capability( "demux", 50 );
105 set_callbacks( Activate, Deactivate );
106 add_shortcut( "mka" );
107 add_shortcut( "mkv" );
111 /*****************************************************************************
113 *****************************************************************************/
114 class vlc_stream_io_callback: public IOCallback
117 input_thread_t *p_input;
121 vlc_stream_io_callback( input_thread_t * );
123 virtual uint32_t read ( void *p_buffer, size_t i_size);
124 virtual void setFilePointer ( int64_t i_offset, seek_mode mode = seek_beginning );
125 virtual size_t write ( const void *p_buffer, size_t i_size);
126 virtual uint64_t getFilePointer ( void );
127 virtual void close ( void );
130 /*****************************************************************************
132 *****************************************************************************/
136 EbmlParser( EbmlStream *es, EbmlElement *el_start );
141 EbmlElement *Get( void );
144 int GetLevel( void );
149 EbmlElement *m_el[6];
158 /*****************************************************************************
159 * Some functions to manipulate memory
160 *****************************************************************************/
161 #define GetFOURCC( p ) __GetFOURCC( (uint8_t*)p )
162 static vlc_fourcc_t __GetFOURCC( uint8_t *p )
164 return VLC_FOURCC( p[0], p[1], p[2], p[3] );
167 /*****************************************************************************
168 * definitions of structures and functions used by this plugins
169 *****************************************************************************/
173 vlc_bool_t b_default;
174 vlc_bool_t b_enabled;
178 uint8_t *p_extra_data;
183 vlc_fourcc_t i_codec;
185 uint64_t i_default_duration;
186 float f_timecodescale;
191 int i_display_height;
200 es_descriptor_t *p_es;
205 /* data to be send first */
207 uint8_t *p_data_init;
209 /* hack : it's for seek */
210 vlc_bool_t b_search_keyframe;
214 char *psz_codec_name;
215 char *psz_codec_settings;
216 char *psz_codec_info_url;
217 char *psz_codec_download_url;
234 vlc_stream_io_callback *in;
239 uint64_t i_timescale;
241 /* duration of the segment */
249 int64_t i_cues_position;
250 int64_t i_chapters_position;
251 int64_t i_tags_position;
265 char *psz_muxing_application;
266 char *psz_writing_application;
267 char *psz_segment_filename;
272 #define MKVD_TIMECODESCALE 1000000
274 static void IndexAppendCluster ( input_thread_t *p_input, KaxCluster *cluster );
275 static char *UTF8ToStr ( const UTFstring &u );
276 static void LoadCues ( input_thread_t *);
277 static void InformationsCreate ( input_thread_t *p_input );
279 /*****************************************************************************
280 * Activate: initializes matroska demux structures
281 *****************************************************************************/
282 static int Activate( vlc_object_t * p_this )
284 input_thread_t *p_input = (input_thread_t *)p_this;
289 vlc_bool_t b_audio_selected;
290 int i_spu_channel, i_audio_channel;
292 EbmlElement *el = NULL, *el1 = NULL, *el2 = NULL, *el3 = NULL, *el4 = NULL;
295 /* Initialize access plug-in structures. */
296 if( p_input->i_mtu == 0 )
299 p_input->i_bufsize = INPUT_DEFAULT_BUFSIZE;
302 /* Set the demux function */
303 p_input->pf_demux = Demux;
305 /* peek the begining */
306 if( input_Peek( p_input, &p_peek, 4 ) < 4 )
308 msg_Warn( p_input, "cannot peek" );
312 /* is a valid file */
313 if( p_peek[0] != 0x1a || p_peek[1] != 0x45 || p_peek[2] != 0xdf || p_peek[3] != 0xa3 )
315 msg_Warn( p_input, "matroska module discarded "
316 "(invalid header 0x%.2x%.2x%.2x%.2x)",
317 p_peek[0], p_peek[1], p_peek[2], p_peek[3] );
321 p_input->p_demux_data = p_sys = (demux_sys_t*)malloc( sizeof( demux_sys_t ) );
322 memset( p_sys, 0, sizeof( demux_sys_t ) );
324 p_sys->in = new vlc_stream_io_callback( p_input );
325 p_sys->es = new EbmlStream( *p_sys->in );
326 p_sys->f_duration = -1;
327 p_sys->i_timescale = MKVD_TIMECODESCALE;
329 p_sys->track = (mkv_track_t*)malloc( sizeof( mkv_track_t ) );
331 p_sys->i_cues_position = -1;
332 p_sys->i_chapters_position = -1;
333 p_sys->i_tags_position = -1;
335 p_sys->b_cues = VLC_FALSE;
337 p_sys->i_index_max = 1024;
338 p_sys->index = (mkv_index_t*)malloc( sizeof( mkv_index_t ) * p_sys->i_index_max );
340 p_sys->psz_muxing_application = NULL;
341 p_sys->psz_writing_application = NULL;
342 p_sys->psz_segment_filename = NULL;
343 p_sys->psz_title = NULL;
344 p_sys->psz_date_utc = NULL;;
346 if( p_sys->es == NULL )
348 msg_Err( p_input, "failed to create EbmlStream" );
353 /* Find the EbmlHead element */
354 el = p_sys->es->FindNextID(EbmlHead::ClassInfos, 0xFFFFFFFFL);
357 msg_Err( p_input, "cannot find EbmlHead" );
360 msg_Dbg( p_input, "EbmlHead" );
362 el->SkipData( *p_sys->es, el->Generic().Context );
366 el = p_sys->es->FindNextID( KaxSegment::ClassInfos, 0xFFFFFFFFL);
369 msg_Err( p_input, "cannot find KaxSegment" );
372 msg_Dbg( p_input, "+ Segment" );
373 p_sys->segment = (KaxSegment*)el;
374 p_sys->cluster = NULL;
376 p_sys->ep = new EbmlParser( p_sys->es, el );
378 while( ( el1 = p_sys->ep->Get() ) != NULL )
380 if( EbmlId( *el1 ) == KaxInfo::ClassInfos.GlobalId )
382 msg_Dbg( p_input, "| + Informations" );
385 while( ( el2 = p_sys->ep->Get() ) != NULL )
387 if( EbmlId( *el2 ) == KaxTimecodeScale::ClassInfos.GlobalId )
389 KaxTimecodeScale &tcs = *(KaxTimecodeScale*)el2;
391 tcs.ReadData( p_sys->es->I_O() );
392 p_sys->i_timescale = uint64(tcs);
394 msg_Dbg( p_input, "| | + TimecodeScale="I64Fd,
395 p_sys->i_timescale );
397 else if( EbmlId( *el2 ) == KaxDuration::ClassInfos.GlobalId )
399 KaxDuration &dur = *(KaxDuration*)el2;
401 dur.ReadData( p_sys->es->I_O() );
402 p_sys->f_duration = float(dur);
404 msg_Dbg( p_input, "| | + Duration=%f", p_sys->f_duration );
406 else if( EbmlId( *el2 ) == KaxMuxingApp::ClassInfos.GlobalId )
408 KaxMuxingApp &mapp = *(KaxMuxingApp*)el2;
410 mapp.ReadData( p_sys->es->I_O() );
412 p_sys->psz_muxing_application = UTF8ToStr( UTFstring( mapp ) );
414 msg_Dbg( p_input, "| | + Muxing Application=%s", p_sys->psz_muxing_application );
416 else if( EbmlId( *el2 ) == KaxWritingApp::ClassInfos.GlobalId )
418 KaxWritingApp &wapp = *(KaxWritingApp*)el2;
420 wapp.ReadData( p_sys->es->I_O() );
422 p_sys->psz_writing_application = UTF8ToStr( UTFstring( wapp ) );
424 msg_Dbg( p_input, "| | + Wrinting Application=%s", p_sys->psz_writing_application );
426 else if( EbmlId( *el2 ) == KaxSegmentFilename::ClassInfos.GlobalId )
428 KaxSegmentFilename &sfn = *(KaxSegmentFilename*)el2;
430 sfn.ReadData( p_sys->es->I_O() );
432 p_sys->psz_segment_filename = UTF8ToStr( UTFstring( sfn ) );
434 msg_Dbg( p_input, "| | + Segment Filename=%s", p_sys->psz_segment_filename );
436 else if( EbmlId( *el2 ) == KaxTitle::ClassInfos.GlobalId )
438 KaxTitle &title = *(KaxTitle*)el2;
440 title.ReadData( p_sys->es->I_O() );
442 p_sys->psz_title = UTF8ToStr( UTFstring( title ) );
444 msg_Dbg( p_input, "| | + Title=%s", p_sys->psz_title );
447 else if( EbmlId( *el2 ) == KaxDateUTC::ClassInfos.GlobalId )
449 KaxDateUTC &date = *(KaxDateUTC*)el2;
454 date.ReadData( p_sys->es->I_O() );
456 i_date = date.GetEpochDate();
457 memset( buffer, 0, 256 );
458 if( gmtime_r( &i_date, &tmres ) &&
459 asctime_r( &tmres, buffer ) )
461 buffer[strlen( buffer)-1]= '\0';
462 p_sys->psz_date_utc = strdup( buffer );
463 msg_Dbg( p_input, "| | + Date=%s", p_sys->psz_date_utc );
469 msg_Dbg( p_input, "| | + Unknown (%s)", typeid(*el2).name() );
474 else if( EbmlId( *el1 ) == KaxTracks::ClassInfos.GlobalId )
476 msg_Dbg( p_input, "| + Tracks" );
479 while( ( el2 = p_sys->ep->Get() ) != NULL )
481 if( EbmlId( *el2 ) == KaxTrackEntry::ClassInfos.GlobalId )
483 msg_Dbg( p_input, "| | + Track Entry" );
486 p_sys->track = (mkv_track_t*)realloc( p_sys->track, sizeof( mkv_track_t ) * (p_sys->i_track + 1 ) );
487 #define tk p_sys->track[p_sys->i_track - 1]
488 memset( &tk, 0, sizeof( mkv_track_t ) );
489 tk.i_cat = UNKNOWN_ES;
490 tk.b_default = VLC_TRUE;
491 tk.b_enabled = VLC_TRUE;
492 tk.i_number = p_sys->i_track - 1;
494 tk.p_extra_data = NULL;
497 tk.psz_language = NULL;
498 tk.i_default_duration = 0;
499 tk.f_timecodescale = 1.0;
501 tk.b_inited = VLC_FALSE;
503 tk.p_data_init = NULL;
506 tk.psz_codec_name = NULL;
507 tk.psz_codec_settings = NULL;
508 tk.psz_codec_info_url = NULL;
509 tk.psz_codec_download_url = NULL;
513 while( ( el3 = p_sys->ep->Get() ) != NULL )
515 if( EbmlId( *el3 ) == KaxTrackNumber::ClassInfos.GlobalId )
517 KaxTrackNumber &tnum = *(KaxTrackNumber*)el3;
518 tnum.ReadData( p_sys->es->I_O() );
520 tk.i_number = uint32( tnum );
521 msg_Dbg( p_input, "| | | + Track Number=%u", uint32( tnum ) );
523 else if( EbmlId( *el3 ) == KaxTrackUID::ClassInfos.GlobalId )
525 KaxTrackUID &tuid = *(KaxTrackUID*)el3;
526 tuid.ReadData( p_sys->es->I_O() );
528 msg_Dbg( p_input, "| | | + Track UID=%u", uint32( tuid ) );
530 else if( EbmlId( *el3 ) == KaxTrackType::ClassInfos.GlobalId )
533 KaxTrackType &ttype = *(KaxTrackType*)el3;
534 ttype.ReadData( p_sys->es->I_O() );
535 switch( uint8(ttype) )
546 psz_type = "subtitle";
550 psz_type = "unknown";
551 tk.i_cat = UNKNOWN_ES;
555 msg_Dbg( p_input, "| | | + Track Type=%s", psz_type );
557 else if( EbmlId( *el3 ) == KaxTrackFlagEnabled::ClassInfos.GlobalId )
559 KaxTrackFlagEnabled &fenb = *(KaxTrackFlagEnabled*)el3;
560 fenb.ReadData( p_sys->es->I_O() );
562 tk.b_enabled = uint32( fenb );
563 msg_Dbg( p_input, "| | | + Track Enabled=%u", uint32( fenb ) );
565 else if( EbmlId( *el3 ) == KaxTrackFlagDefault::ClassInfos.GlobalId )
567 KaxTrackFlagDefault &fdef = *(KaxTrackFlagDefault*)el3;
568 fdef.ReadData( p_sys->es->I_O() );
570 tk.b_default = uint32( fdef );
571 msg_Dbg( p_input, "| | | + Track Default=%u", uint32( fdef ) );
573 else if( EbmlId( *el3 ) == KaxTrackFlagLacing::ClassInfos.GlobalId )
575 KaxTrackFlagLacing &lac = *(KaxTrackFlagLacing*)el3;
576 lac.ReadData( p_sys->es->I_O() );
578 msg_Dbg( p_input, "| | | + Track Lacing=%d", uint32( lac ) );
580 else if( EbmlId( *el3 ) == KaxTrackMinCache::ClassInfos.GlobalId )
582 KaxTrackMinCache &cmin = *(KaxTrackMinCache*)el3;
583 cmin.ReadData( p_sys->es->I_O() );
585 msg_Dbg( p_input, "| | | + Track MinCache=%d", uint32( cmin ) );
587 else if( EbmlId( *el3 ) == KaxTrackMaxCache::ClassInfos.GlobalId )
589 KaxTrackMaxCache &cmax = *(KaxTrackMaxCache*)el3;
590 cmax.ReadData( p_sys->es->I_O() );
592 msg_Dbg( p_input, "| | | + Track MaxCache=%d", uint32( cmax ) );
594 else if( EbmlId( *el3 ) == KaxTrackDefaultDuration::ClassInfos.GlobalId )
596 KaxTrackDefaultDuration &defd = *(KaxTrackDefaultDuration*)el3;
597 defd.ReadData( p_sys->es->I_O() );
599 tk.i_default_duration = uint64(defd);
600 msg_Dbg( p_input, "| | | + Track Default Duration="I64Fd, uint64(defd) );
602 else if( EbmlId( *el3 ) == KaxTrackTimecodeScale::ClassInfos.GlobalId )
604 KaxTrackTimecodeScale &ttcs = *(KaxTrackTimecodeScale*)el3;
605 ttcs.ReadData( p_sys->es->I_O() );
607 tk.f_timecodescale = float( ttcs );
608 msg_Dbg( p_input, "| | | + Track TimeCodeScale=%f", tk.f_timecodescale );
610 else if( EbmlId( *el3 ) == KaxTrackName::ClassInfos.GlobalId )
612 KaxTrackName &tname = *(KaxTrackName*)el3;
613 tname.ReadData( p_sys->es->I_O() );
615 tk.psz_name = UTF8ToStr( UTFstring( tname ) );
616 msg_Dbg( p_input, "| | | + Track Name=%s", tk.psz_name );
618 else if( EbmlId( *el3 ) == KaxTrackLanguage::ClassInfos.GlobalId )
620 KaxTrackLanguage &lang = *(KaxTrackLanguage*)el3;
622 lang.ReadData( p_sys->es->I_O() );
624 tk.psz_language = strdup( string( lang ).c_str() );
625 msg_Dbg( p_input, "| | | + Track Language=`%s'", string( lang ).c_str() );
627 else if( EbmlId( *el3 ) == KaxCodecID::ClassInfos.GlobalId )
629 KaxCodecID &codecid = *(KaxCodecID*)el3;
630 codecid.ReadData( p_sys->es->I_O() );
632 tk.psz_codec = strdup( string( codecid ).c_str() );
633 msg_Dbg( p_input, "| | | + Track CodecId=%s", string( codecid ).c_str() );
635 else if( EbmlId( *el3 ) == KaxCodecPrivate::ClassInfos.GlobalId )
637 KaxCodecPrivate &cpriv = *(KaxCodecPrivate*)el3;
638 cpriv.ReadData( p_sys->es->I_O() );
640 tk.i_extra_data = cpriv.GetSize();
641 if( tk.i_extra_data > 0 )
643 tk.p_extra_data = (uint8_t*)malloc( tk.i_extra_data );
644 memcpy( tk.p_extra_data, cpriv.GetBuffer(), tk.i_extra_data );
646 msg_Dbg( p_input, "| | | + Track CodecPrivate size="I64Fd, cpriv.GetSize() );
648 else if( EbmlId( *el3 ) == KaxCodecName::ClassInfos.GlobalId )
650 KaxCodecName &cname = *(KaxCodecName*)el3;
651 cname.ReadData( p_sys->es->I_O() );
653 tk.psz_codec_name = UTF8ToStr( UTFstring( cname ) );
654 msg_Dbg( p_input, "| | | + Track Codec Name=%s", tk.psz_codec_name );
656 else if( EbmlId( *el3 ) == KaxCodecSettings::ClassInfos.GlobalId )
658 KaxCodecSettings &cset = *(KaxCodecSettings*)el3;
659 cset.ReadData( p_sys->es->I_O() );
661 tk.psz_codec_settings = UTF8ToStr( UTFstring( cset ) );
662 msg_Dbg( p_input, "| | | + Track Codec Settings=%s", tk.psz_codec_settings );
664 else if( EbmlId( *el3 ) == KaxCodecInfoURL::ClassInfos.GlobalId )
666 KaxCodecInfoURL &ciurl = *(KaxCodecInfoURL*)el3;
667 ciurl.ReadData( p_sys->es->I_O() );
669 tk.psz_codec_info_url = strdup( string( ciurl ).c_str() );
670 msg_Dbg( p_input, "| | | + Track Codec Info URL=%s", tk.psz_codec_info_url );
672 else if( EbmlId( *el3 ) == KaxCodecDownloadURL::ClassInfos.GlobalId )
674 KaxCodecDownloadURL &cdurl = *(KaxCodecDownloadURL*)el3;
675 cdurl.ReadData( p_sys->es->I_O() );
677 tk.psz_codec_download_url = strdup( string( cdurl ).c_str() );
678 msg_Dbg( p_input, "| | | + Track Codec Info URL=%s", tk.psz_codec_download_url );
680 else if( EbmlId( *el3 ) == KaxCodecDecodeAll::ClassInfos.GlobalId )
682 KaxCodecDecodeAll &cdall = *(KaxCodecDecodeAll*)el3;
683 cdall.ReadData( p_sys->es->I_O() );
685 msg_Dbg( p_input, "| | | + Track Codec Decode All=%u <== UNUSED", uint8( cdall ) );
687 else if( EbmlId( *el3 ) == KaxTrackOverlay::ClassInfos.GlobalId )
689 KaxTrackOverlay &tovr = *(KaxTrackOverlay*)el3;
690 tovr.ReadData( p_sys->es->I_O() );
692 msg_Dbg( p_input, "| | | + Track Overlay=%u <== UNUSED", uint32( tovr ) );
694 else if( EbmlId( *el3 ) == KaxTrackVideo::ClassInfos.GlobalId )
696 msg_Dbg( p_input, "| | | + Track Video" );
699 tk.i_display_width = 0;
700 tk.i_display_height = 0;
705 while( ( el4 = p_sys->ep->Get() ) != NULL )
707 if( EbmlId( *el4 ) == KaxVideoFlagInterlaced::ClassInfos.GlobalId )
709 KaxVideoFlagInterlaced &fint = *(KaxVideoFlagInterlaced*)el4;
710 fint.ReadData( p_sys->es->I_O() );
712 msg_Dbg( p_input, "| | | | + Track Video Interlaced=%u", uint8( fint ) );
714 else if( EbmlId( *el4 ) == KaxVideoStereoMode::ClassInfos.GlobalId )
716 KaxVideoStereoMode &stereo = *(KaxVideoStereoMode*)el4;
717 stereo.ReadData( p_sys->es->I_O() );
719 msg_Dbg( p_input, "| | | | + Track Video Stereo Mode=%u", uint8( stereo ) );
721 else if( EbmlId( *el4 ) == KaxVideoPixelWidth::ClassInfos.GlobalId )
723 KaxVideoPixelWidth &vwidth = *(KaxVideoPixelWidth*)el4;
724 vwidth.ReadData( p_sys->es->I_O() );
726 tk.i_width = uint16( vwidth );
727 msg_Dbg( p_input, "| | | | + width=%d", uint16( vwidth ) );
729 else if( EbmlId( *el4 ) == KaxVideoPixelHeight::ClassInfos.GlobalId )
731 KaxVideoPixelWidth &vheight = *(KaxVideoPixelWidth*)el4;
732 vheight.ReadData( p_sys->es->I_O() );
734 tk.i_height = uint16( vheight );
735 msg_Dbg( p_input, "| | | | + height=%d", uint16( vheight ) );
737 else if( EbmlId( *el4 ) == KaxVideoDisplayWidth::ClassInfos.GlobalId )
739 KaxVideoDisplayWidth &vwidth = *(KaxVideoDisplayWidth*)el4;
740 vwidth.ReadData( p_sys->es->I_O() );
742 tk.i_display_width = uint16( vwidth );
743 msg_Dbg( p_input, "| | | | + display width=%d", uint16( vwidth ) );
745 else if( EbmlId( *el4 ) == KaxVideoDisplayHeight::ClassInfos.GlobalId )
747 KaxVideoDisplayWidth &vheight = *(KaxVideoDisplayWidth*)el4;
748 vheight.ReadData( p_sys->es->I_O() );
750 tk.i_display_height = uint16( vheight );
751 msg_Dbg( p_input, "| | | | + display height=%d", uint16( vheight ) );
753 else if( EbmlId( *el4 ) == KaxVideoFrameRate::ClassInfos.GlobalId )
755 KaxVideoFrameRate &vfps = *(KaxVideoFrameRate*)el4;
756 vfps.ReadData( p_sys->es->I_O() );
758 tk.f_fps = float( vfps );
759 msg_Dbg( p_input, " | | | + fps=%f", float( vfps ) );
761 else if( EbmlId( *el4 ) == KaxVideoDisplayUnit::ClassInfos.GlobalId )
763 KaxVideoDisplayUnit &vdmode = *(KaxVideoDisplayUnit*)el4;
764 vdmode.ReadData( p_sys->es->I_O() );
766 msg_Dbg( p_input, "| | | | + Track Video Display Unit=%s",
767 uint8( vdmode ) == 0 ? "pixels" : ( uint8( vdmode ) == 1 ? "centimeters": "inches" ) );
769 else if( EbmlId( *el4 ) == KaxVideoAspectRatio::ClassInfos.GlobalId )
771 KaxVideoAspectRatio &ratio = *(KaxVideoAspectRatio*)el4;
772 ratio.ReadData( p_sys->es->I_O() );
774 msg_Dbg( p_input, " | | | + Track Video Aspect Ratio Type=%u", uint8( ratio ) );
776 else if( EbmlId( *el4 ) == KaxVideoGamma::ClassInfos.GlobalId )
778 KaxVideoGamma &gamma = *(KaxVideoGamma*)el4;
779 gamma.ReadData( p_sys->es->I_O() );
781 msg_Dbg( p_input, " | | | + fps=%f", float( gamma ) );
785 msg_Dbg( p_input, "| | | | + Unknown (%s)", typeid(*el4).name() );
790 else if( EbmlId( *el3 ) == KaxTrackAudio::ClassInfos.GlobalId )
792 msg_Dbg( p_input, "| | | + Track Audio" );
795 tk.i_bitspersample = 0;
799 while( ( el4 = p_sys->ep->Get() ) != NULL )
801 if( EbmlId( *el4 ) == KaxAudioSamplingFreq::ClassInfos.GlobalId )
803 KaxAudioSamplingFreq &afreq = *(KaxAudioSamplingFreq*)el4;
804 afreq.ReadData( p_sys->es->I_O() );
806 tk.i_samplerate = (int)float( afreq );
807 msg_Dbg( p_input, "| | | | + afreq=%d", tk.i_samplerate );
809 else if( EbmlId( *el4 ) == KaxAudioChannels::ClassInfos.GlobalId )
811 KaxAudioChannels &achan = *(KaxAudioChannels*)el4;
812 achan.ReadData( p_sys->es->I_O() );
814 tk.i_channels = uint8( achan );
815 msg_Dbg( p_input, "| | | | + achan=%u", uint8( achan ) );
817 else if( EbmlId( *el4 ) == KaxAudioBitDepth::ClassInfos.GlobalId )
819 KaxAudioBitDepth &abits = *(KaxAudioBitDepth*)el4;
820 abits.ReadData( p_sys->es->I_O() );
822 tk.i_bitspersample = uint8( abits );
823 msg_Dbg( p_input, "| | | | + abits=%u", uint8( abits ) );
827 msg_Dbg( p_input, "| | | | + Unknown (%s)", typeid(*el4).name() );
834 msg_Dbg( p_input, "| | | + Unknown (%s)", typeid(*el3).name() );
841 msg_Dbg( p_input, "| | + Unknown (%s)", typeid(*el2).name() );
847 else if( EbmlId( *el1 ) == KaxSeekHead::ClassInfos.GlobalId )
849 msg_Dbg( p_input, "| + Seek head" );
851 while( ( el = p_sys->ep->Get() ) != NULL )
853 if( EbmlId( *el ) == KaxSeek::ClassInfos.GlobalId )
855 EbmlId id = EbmlVoid::ClassInfos.GlobalId;
858 //msg_Dbg( p_input, "| | + Seek" );
860 while( ( el = p_sys->ep->Get() ) != NULL )
862 if( EbmlId( *el ) == KaxSeekID::ClassInfos.GlobalId )
864 KaxSeekID &sid = *(KaxSeekID*)el;
866 sid.ReadData( p_sys->es->I_O() );
868 id = EbmlId( sid.GetBuffer(), sid.GetSize() );
870 else if( EbmlId( *el ) == KaxSeekPosition::ClassInfos.GlobalId )
872 KaxSeekPosition &spos = *(KaxSeekPosition*)el;
874 spos.ReadData( p_sys->es->I_O() );
876 i_pos = uint64( spos );
880 msg_Dbg( p_input, "| | | + Unknown (%s)", typeid(*el).name() );
887 if( id == KaxCues::ClassInfos.GlobalId )
889 msg_Dbg( p_input, "| | | = cues at "I64Fd, i_pos );
890 p_sys->i_cues_position = p_sys->segment->GetGlobalPosition( i_pos );
892 else if( id == KaxChapters::ClassInfos.GlobalId )
894 msg_Dbg( p_input, "| | | = chapters at "I64Fd, i_pos );
895 p_sys->i_chapters_position = p_sys->segment->GetGlobalPosition( i_pos );
897 else if( id == KaxTags::ClassInfos.GlobalId )
899 msg_Dbg( p_input, "| | | = tags at "I64Fd, i_pos );
900 p_sys->i_tags_position = p_sys->segment->GetGlobalPosition( i_pos );
907 msg_Dbg( p_input, "| | + Unknown (%s)", typeid(*el).name() );
912 else if( EbmlId( *el1 ) == KaxCues::ClassInfos.GlobalId )
914 msg_Dbg( p_input, "| + Cues" );
916 else if( EbmlId( *el1 ) == KaxCluster::ClassInfos.GlobalId )
918 msg_Dbg( p_input, "| + Cluster" );
920 p_sys->cluster = (KaxCluster*)el1;
923 /* stop parsing the stream */
926 #ifdef HAVE_MATROSKA_KAXATTACHMENTS_H
927 else if( EbmlId( *el1 ) == KaxAttachments::ClassInfos.GlobalId )
929 else if( EbmlId( *el1 ) == KaxAttachements::ClassInfos.GlobalId )
932 msg_Dbg( p_input, "| + Attachments FIXME TODO (but probably never supported)" );
934 else if( EbmlId( *el1 ) == KaxChapters::ClassInfos.GlobalId )
936 msg_Dbg( p_input, "| + Chapters FIXME TODO" );
938 else if( EbmlId( *el1 ) == KaxTag::ClassInfos.GlobalId )
940 msg_Dbg( p_input, "| + Tags FIXME TODO" );
944 msg_Dbg( p_input, "| + Unknown (%s)", typeid(*el1).name() );
948 if( p_sys->cluster == NULL )
950 msg_Err( p_input, "cannot find any cluster, damaged file ?" );
954 if( p_sys->i_chapters_position >= 0 )
956 msg_Warn( p_input, "chapters unsupported" );
959 /* *** Load the cue if found *** */
960 if( p_sys->i_cues_position >= 0 && p_input->stream.b_seekable )
965 if( !p_sys->b_cues || p_sys->i_index <= 0 )
967 msg_Warn( p_input, "no cues/empty cues found -> seek won't be precise" );
969 IndexAppendCluster( p_input, p_sys->cluster );
971 p_sys->b_cues = VLC_FALSE;
974 /* Create one program */
975 vlc_mutex_lock( &p_input->stream.stream_lock );
976 if( input_InitStream( p_input, 0 ) == -1)
978 vlc_mutex_unlock( &p_input->stream.stream_lock );
979 msg_Err( p_input, "cannot init stream" );
982 if( input_AddProgram( p_input, 0, 0) == NULL )
984 vlc_mutex_unlock( &p_input->stream.stream_lock );
985 msg_Err( p_input, "cannot add program" );
988 p_input->stream.p_selected_program = p_input->stream.pp_programs[0];
989 if( p_sys->f_duration > 1001.0 )
991 mtime_t i_duration = (mtime_t)( p_sys->f_duration / 1000.0 );
992 p_input->stream.i_mux_rate = p_input->stream.p_selected_area->i_size / 50 / i_duration;
996 p_input->stream.i_mux_rate = 0;
998 vlc_mutex_unlock( &p_input->stream.stream_lock );
1001 msg_Dbg( p_input, "found %d es", p_sys->i_track );
1002 for( i_track = 0; i_track < p_sys->i_track; i_track++ )
1004 #define tk p_sys->track[i_track]
1005 if( tk.i_cat == UNKNOWN_ES )
1007 msg_Warn( p_input, "invalid track[%d, n=%d]", i_track, tk.i_number );
1011 tk.p_es = input_AddES( p_input,
1012 p_input->stream.p_selected_program,
1015 tk.psz_language, 0 );
1016 if( !strcmp( tk.psz_codec, "V_MS/VFW/FOURCC" ) )
1018 if( tk.i_extra_data < (int)sizeof( BITMAPINFOHEADER ) )
1020 msg_Err( p_input, "missing/invalid BITMAPINFOHEADER" );
1021 tk.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
1025 BITMAPINFOHEADER *p_bih = (BITMAPINFOHEADER*)tk.p_extra_data;
1027 p_bih->biSize = GetDWLE( &p_bih->biSize );
1028 p_bih->biWidth = GetDWLE( &p_bih->biWidth );
1029 p_bih->biHeight = GetDWLE( &p_bih->biHeight );
1030 p_bih->biPlanes = GetWLE( &p_bih->biPlanes );
1031 p_bih->biBitCount = GetWLE( &p_bih->biBitCount );
1032 p_bih->biCompression = GetFOURCC( &p_bih->biCompression );
1033 p_bih->biSizeImage = GetDWLE( &p_bih->biSizeImage );
1034 p_bih->biXPelsPerMeter = GetDWLE( &p_bih->biXPelsPerMeter );
1035 p_bih->biYPelsPerMeter = GetDWLE( &p_bih->biYPelsPerMeter );
1036 p_bih->biClrUsed = GetDWLE( &p_bih->biClrUsed );
1037 p_bih->biClrImportant = GetDWLE( &p_bih->biClrImportant );
1040 tk.i_codec = p_bih->biCompression;
1041 tk.p_es->p_bitmapinfoheader = p_bih;
1044 else if( !strcmp( tk.psz_codec, "V_MPEG1" ) ||
1045 !strcmp( tk.psz_codec, "V_MPEG2" ) )
1047 tk.i_codec = VLC_FOURCC( 'm', 'p', 'g', 'v' );
1049 else if( !strncmp( tk.psz_codec, "V_MPEG4", 7 ) )
1051 BITMAPINFOHEADER *p_bih;
1053 tk.i_extra_data = sizeof( BITMAPINFOHEADER );
1054 tk.p_extra_data = (uint8_t*)malloc( tk.i_extra_data );
1056 p_bih = (BITMAPINFOHEADER*)tk.p_extra_data;
1057 memset( p_bih, 0, sizeof( BITMAPINFOHEADER ) );
1058 p_bih->biSize = sizeof( BITMAPINFOHEADER );
1059 p_bih->biWidth = tk.i_width;
1060 p_bih->biHeight= tk.i_height;
1062 if( !strcmp( tk.psz_codec, "V_MPEG4/MS/V3" ) )
1064 tk.i_codec = VLC_FOURCC( 'D', 'I', 'V', '3' );
1068 tk.i_codec = VLC_FOURCC( 'm', 'p', '4', 'v' );
1071 else if( !strcmp( tk.psz_codec, "A_MS/ACM" ) )
1073 if( tk.i_extra_data < (int)sizeof( WAVEFORMATEX ) )
1075 msg_Err( p_input, "missing/invalid WAVEFORMATEX" );
1076 tk.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
1080 WAVEFORMATEX *p_wf = (WAVEFORMATEX*)tk.p_extra_data;
1082 p_wf->wFormatTag = GetWLE( &p_wf->wFormatTag );
1083 p_wf->nChannels = GetWLE( &p_wf->nChannels );
1084 p_wf->nSamplesPerSec = GetDWLE( &p_wf->nSamplesPerSec );
1085 p_wf->nAvgBytesPerSec = GetDWLE( &p_wf->nAvgBytesPerSec );
1086 p_wf->nBlockAlign = GetWLE( &p_wf->nBlockAlign );
1087 p_wf->wBitsPerSample = GetWLE( &p_wf->wBitsPerSample );
1088 p_wf->cbSize = GetWLE( &p_wf->cbSize );
1090 wf_tag_to_fourcc( p_wf->wFormatTag, &tk.i_codec, NULL );
1091 tk.p_es->p_waveformatex = p_wf;
1094 else if( !strcmp( tk.psz_codec, "A_MPEG/L3" ) ||
1095 !strcmp( tk.psz_codec, "A_MPEG/L2" ) ||
1096 !strcmp( tk.psz_codec, "A_MPEG/L1" ) )
1098 tk.i_codec = VLC_FOURCC( 'm', 'p', 'g', 'a' );
1100 else if( !strcmp( tk.psz_codec, "A_AC3" ) )
1102 tk.i_codec = VLC_FOURCC( 'a', '5', '2', ' ' );
1104 else if( !strcmp( tk.psz_codec, "A_DTS" ) )
1106 tk.i_codec = VLC_FOURCC( 'd', 't', 's', ' ' );
1108 else if( !strcmp( tk.psz_codec, "A_VORBIS" ) )
1110 tk.i_codec = VLC_FOURCC( 'v', 'o', 'r', 'b' );
1111 tk.i_data_init = tk.i_extra_data;
1112 tk.p_data_init = tk.p_extra_data;
1114 else if( !strncmp( tk.psz_codec, "A_AAC/MPEG2/", strlen( "A_AAC/MPEG2/" ) ) ||
1115 !strncmp( tk.psz_codec, "A_AAC/MPEG4/", strlen( "A_AAC/MPEG4/" ) ) )
1117 int i_profile, i_srate;
1118 static int i_sample_rates[] =
1120 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
1121 16000, 12000, 11025, 8000, 7350, 0, 0, 0
1125 tk.i_codec = VLC_FOURCC( 'm', 'p', '4', 'a' );
1126 /* create data for faad (MP4DecSpecificDescrTag)*/
1128 if( !strcmp( &tk.psz_codec[12], "MAIN" ) )
1132 else if( !strcmp( &tk.psz_codec[12], "LC" ) )
1136 else if( !strcmp( &tk.psz_codec[12], "SSR" ) )
1145 for( i_srate = 0; i_srate < 13; i_srate++ )
1147 if( i_sample_rates[i_srate] == tk.i_samplerate )
1152 msg_Dbg( p_input, "profile=%d srate=%d", i_profile, i_srate );
1154 tk.i_extra_data = sizeof( WAVEFORMATEX ) + 2;
1155 tk.p_extra_data = (uint8_t*)malloc( tk.i_extra_data );
1156 p_wf = (WAVEFORMATEX*)tk.p_extra_data;
1158 p_wf->wFormatTag = WAVE_FORMAT_UNKNOWN;
1159 p_wf->nChannels = tk.i_channels;
1160 p_wf->nSamplesPerSec = tk.i_samplerate;
1161 p_wf->nAvgBytesPerSec = 0;
1162 p_wf->nBlockAlign = 0;
1163 p_wf->wBitsPerSample = 0;
1166 tk.p_extra_data[sizeof( WAVEFORMATEX )+ 0] = ((i_profile + 1) << 3) | ((i_srate&0xe) >> 1);
1167 tk.p_extra_data[sizeof( WAVEFORMATEX )+ 1] = ((i_srate & 0x1) << 7) | (tk.i_channels << 3);
1169 tk.p_es->p_waveformatex = p_wf;
1171 else if( !strcmp( tk.psz_codec, "A_PCM/INT/BIG" ) ||
1172 !strcmp( tk.psz_codec, "A_PCM/INT/LIT" ) ||
1173 !strcmp( tk.psz_codec, "A_PCM/FLOAT/IEEE" ) )
1177 tk.i_extra_data = sizeof( WAVEFORMATEX );
1178 tk.p_extra_data = (uint8_t*)malloc( tk.i_extra_data );
1180 p_wf = (WAVEFORMATEX*)tk.p_extra_data;
1182 if( !strncmp( &tk.psz_codec[6], "INT", 3 ) )
1184 p_wf->wFormatTag = WAVE_FORMAT_PCM;
1188 p_wf->wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
1190 p_wf->nChannels = tk.i_channels;
1191 p_wf->nSamplesPerSec = tk.i_samplerate;
1192 p_wf->nAvgBytesPerSec = 0;
1193 p_wf->nBlockAlign = ( tk.i_bitspersample + 7 ) / 8 * tk.i_channels;
1194 p_wf->wBitsPerSample = tk.i_bitspersample;
1197 tk.p_es->p_waveformatex = p_wf;
1199 if( !strcmp( tk.psz_codec, "A_PCM/INT/BIG" ) )
1201 tk.i_codec = VLC_FOURCC( 't', 'w', 'o', 's' );
1205 tk.i_codec = VLC_FOURCC( 'a', 'r', 'a', 'w' );
1208 else if( !strcmp( tk.psz_codec, "S_TEXT/UTF8" ) )
1210 tk.i_codec = VLC_FOURCC( 's', 'u', 'b', 't' );
1213 else if( !strcmp( tk.psz_codec, "S_TEXT/SSA" ) )
1215 tk.i_codec = VLC_FOURCC( 's', 'u', 'b', 't' );
1220 msg_Err( p_input, "unknow codec id=`%s'", tk.psz_codec );
1221 tk.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
1224 tk.p_es->i_fourcc = tk.i_codec;
1228 /* select track all video, one audio, no spu TODO : improve */
1229 b_audio_selected = VLC_FALSE;
1230 i_audio_channel = 0;
1232 for( i_track = 0; i_track < p_sys->i_track; i_track++ )
1234 #define tk p_sys->track[i_track]
1238 vlc_mutex_lock( &p_input->stream.stream_lock );
1239 input_SelectES( p_input, tk.p_es );
1240 vlc_mutex_unlock( &p_input->stream.stream_lock );
1244 if( ( !b_audio_selected && config_GetInt( p_input, "audio-channel" ) < 0 ) ||
1245 i_audio_channel == config_GetInt( p_input, "audio-channel" ) )
1247 vlc_mutex_lock( &p_input->stream.stream_lock );
1248 input_SelectES( p_input, tk.p_es );
1249 vlc_mutex_unlock( &p_input->stream.stream_lock );
1251 b_audio_selected = tk.p_es->p_decoder_fifo ? VLC_TRUE : VLC_FALSE;
1256 if( i_spu_channel == config_GetInt( p_input, "spu-channel" ) )
1258 vlc_mutex_lock( &p_input->stream.stream_lock );
1259 input_SelectES( p_input, tk.p_es );
1260 vlc_mutex_unlock( &p_input->stream.stream_lock );
1268 if( !b_audio_selected )
1270 msg_Warn( p_input, "cannot find/select audio track" );
1273 /* add informations */
1274 InformationsCreate( p_input );
1282 return VLC_EGENERIC;
1285 /*****************************************************************************
1286 * Deactivate: frees unused data
1287 *****************************************************************************/
1288 static void Deactivate( vlc_object_t *p_this )
1290 input_thread_t *p_input = (input_thread_t *)p_this;
1291 demux_sys_t *p_sys = p_input->p_demux_data;
1295 for( i_track = 0; i_track < p_sys->i_track; i_track++ )
1297 #define tk p_sys->track[i_track]
1300 free( tk.psz_codec );
1302 if( tk.psz_language )
1304 free( tk.psz_language );
1308 free( p_sys->track );
1310 if( p_sys->psz_writing_application )
1312 free( p_sys->psz_writing_application );
1314 if( p_sys->psz_muxing_application )
1316 free( p_sys->psz_muxing_application );
1319 delete p_sys->segment;
1328 static int BlockGet( input_thread_t *p_input, KaxBlock **pp_block, int64_t *pi_ref1, int64_t *pi_ref2, int64_t *pi_duration )
1330 demux_sys_t *p_sys = p_input->p_demux_data;
1341 if( p_input->b_die )
1343 return VLC_EGENERIC;
1346 el = p_sys->ep->Get();
1347 i_level = p_sys->ep->GetLevel();
1349 if( el == NULL && *pp_block != NULL )
1351 /* update the index */
1352 #define idx p_sys->index[p_sys->i_index - 1]
1353 if( p_sys->i_index > 0 && idx.i_time == -1 )
1355 idx.i_time = (*pp_block)->GlobalTimecode() * (mtime_t) 1000 / p_sys->i_timescale;
1356 idx.b_key = *pi_ref1 == -1 ? VLC_TRUE : VLC_FALSE;
1364 if( p_sys->ep->GetLevel() > 1 )
1369 msg_Warn( p_input, "EOF" );
1370 return VLC_EGENERIC;
1376 if( EbmlId( *el ) == KaxCluster::ClassInfos.GlobalId )
1378 p_sys->cluster = (KaxCluster*)el;
1380 /* add it to the index */
1381 if( p_sys->i_index == 0 ||
1382 ( p_sys->i_index > 0 && p_sys->index[p_sys->i_index - 1].i_position < (int64_t)p_sys->cluster->GetElementPosition() ) )
1384 IndexAppendCluster( p_input, p_sys->cluster );
1389 else if( EbmlId( *el ) == KaxCues::ClassInfos.GlobalId )
1391 msg_Warn( p_input, "find KaxCues FIXME" );
1392 return VLC_EGENERIC;
1396 msg_Dbg( p_input, "unknown (%s)", typeid( el ).name() );
1399 else if( i_level == 2 )
1401 if( EbmlId( *el ) == KaxClusterTimecode::ClassInfos.GlobalId )
1403 KaxClusterTimecode &ctc = *(KaxClusterTimecode*)el;
1405 ctc.ReadData( p_sys->es->I_O() );
1406 p_sys->cluster->InitTimecode( uint64( ctc ), p_sys->i_timescale );
1408 else if( EbmlId( *el ) == KaxBlockGroup::ClassInfos.GlobalId )
1413 else if( i_level == 3 )
1415 if( EbmlId( *el ) == KaxBlock::ClassInfos.GlobalId )
1417 *pp_block = (KaxBlock*)el;
1419 (*pp_block)->ReadData( p_sys->es->I_O() );
1420 (*pp_block)->SetParent( *p_sys->cluster );
1424 else if( EbmlId( *el ) == KaxBlockDuration::ClassInfos.GlobalId )
1426 KaxBlockDuration &dur = *(KaxBlockDuration*)el;
1428 dur.ReadData( p_sys->es->I_O() );
1429 *pi_duration = uint64( dur );
1431 else if( EbmlId( *el ) == KaxReferenceBlock::ClassInfos.GlobalId )
1433 KaxReferenceBlock &ref = *(KaxReferenceBlock*)el;
1435 ref.ReadData( p_sys->es->I_O() );
1436 if( *pi_ref1 == -1 )
1438 *pi_ref1 = int64( ref );
1442 *pi_ref2 = int64( ref );
1448 msg_Err( p_input, "invalid level = %d", i_level );
1449 return VLC_EGENERIC;
1454 static pes_packet_t *MemToPES( input_thread_t *p_input, uint8_t *p_mem, int i_mem )
1456 pes_packet_t *p_pes;
1457 data_packet_t *p_data;
1459 if( ( p_pes = input_NewPES( p_input->p_method_data ) ) == NULL )
1464 p_data = input_NewPacket( p_input->p_method_data, i_mem);
1466 memcpy( p_data->p_payload_start, p_mem, i_mem );
1467 p_data->p_payload_end = p_data->p_payload_start + i_mem;
1469 p_pes->p_first = p_pes->p_last = p_data;
1470 p_pes->i_nb_data = 1;
1471 p_pes->i_pes_size = i_mem;
1476 static void BlockDecode( input_thread_t *p_input, KaxBlock *block, mtime_t i_pts, mtime_t i_duration )
1478 demux_sys_t *p_sys = p_input->p_demux_data;
1483 #define tk p_sys->track[i_track]
1484 for( i_track = 0; i_track < p_sys->i_track; i_track++ )
1486 if( tk.i_number == block->TrackNum() )
1492 if( i_track >= p_sys->i_track )
1494 msg_Err( p_input, "invalid track number=%d", block->TrackNum() );
1498 if( tk.p_es->p_decoder_fifo == NULL )
1500 tk.b_inited = VLC_FALSE;
1504 if( tk.i_cat == AUDIO_ES && p_input->stream.control.b_mute )
1509 /* First send init data */
1510 if( !tk.b_inited && tk.i_data_init > 0 )
1512 pes_packet_t *p_init;
1514 msg_Dbg( p_input, "sending header (%d bytes)", tk.i_data_init );
1516 if( tk.i_codec == VLC_FOURCC( 'v', 'o', 'r', 'b' ) )
1522 /* XXX hack split the 3 headers */
1523 if( tk.p_data_init[0] != 0x02 )
1525 msg_Err( p_input, "invalid vorbis header" );
1528 for( i = 0; i < 2; i++ )
1531 while( i_offset < tk.i_data_init )
1533 i_size[i] += tk.p_data_init[i_offset];
1534 if( tk.p_data_init[i_offset++] != 0xff )
1540 i_size[0] = __MIN( i_size[0], tk.i_data_init - i_offset );
1541 i_size[1] = __MIN( i_size[1], tk.i_data_init - i_offset - i_size[0] );
1542 i_size[2] = tk.i_data_init - i_offset - i_size[0] - i_size[1];
1544 p_init = MemToPES( p_input, &tk.p_data_init[i_offset], i_size[0] );
1547 input_DecodePES( tk.p_es->p_decoder_fifo, p_init );
1549 p_init = MemToPES( p_input, &tk.p_data_init[i_offset+i_size[0]], i_size[1] );
1552 input_DecodePES( tk.p_es->p_decoder_fifo, p_init );
1554 p_init = MemToPES( p_input, &tk.p_data_init[i_offset+i_size[0]+i_size[1]], i_size[2] );
1557 input_DecodePES( tk.p_es->p_decoder_fifo, p_init );
1562 p_init = MemToPES( p_input, tk.p_data_init, tk.i_data_init );
1565 input_DecodePES( tk.p_es->p_decoder_fifo, p_init );
1569 tk.b_inited = VLC_TRUE;
1572 for( i = 0; i < block->NumberFrames(); i++ )
1574 pes_packet_t *p_pes;
1575 DataBuffer &data = block->GetBuffer(i);
1577 p_pes = MemToPES( p_input, data.Buffer(), data.Size() );
1583 p_pes->i_pts = i_pts;
1584 p_pes->i_dts = i_pts;
1586 if( tk.i_cat == SPU_ES )
1588 if( i_duration > 0 )
1590 /* FIXME not sure about that */
1591 p_pes->i_dts += i_duration * 1000;// * (mtime_t) 1000 / p_sys->i_timescale;
1597 if( p_pes->p_first && p_pes->i_pes_size > 0 )
1599 p_pes->p_first->p_payload_end[-1] = '\0';
1603 input_DecodePES( tk.p_es->p_decoder_fifo, p_pes );
1605 /* use time stamp only for first block */
1612 static void Seek( input_thread_t *p_input, mtime_t i_date, int i_percent)
1614 demux_sys_t *p_sys = p_input->p_demux_data;
1617 int64_t i_block_duration;
1618 int64_t i_block_ref1;
1619 int64_t i_block_ref2;
1622 int i_track_skipping;
1625 msg_Dbg( p_input, "seek request to "I64Fd" (%d%%)", i_date, i_percent );
1626 if( i_date < 0 && i_percent < 0 )
1632 p_sys->ep = new EbmlParser( p_sys->es, p_sys->segment );
1633 p_sys->cluster = NULL;
1635 /* seek without index or without date */
1636 if( config_GetInt( p_input, "mkv-seek-percent" ) || !p_sys->b_cues || i_date < 0 )
1638 int64_t i_pos = i_percent * p_input->stream.p_selected_area->i_size / 100;
1640 msg_Dbg( p_input, "imprecise way of seeking" );
1641 for( i_index = 0; i_index < p_sys->i_index; i_index++ )
1643 if( p_sys->index[i_index].i_position >= i_pos)
1648 if( i_index == p_sys->i_index )
1653 p_sys->in->setFilePointer( p_sys->index[i_index].i_position, seek_beginning );
1655 if( p_sys->index[i_index].i_position < i_pos )
1659 msg_Warn( p_input, "searching for cluster, could take some time" );
1661 /* search a cluster */
1662 while( ( el = p_sys->ep->Get() ) != NULL )
1664 if( EbmlId( *el ) == KaxCluster::ClassInfos.GlobalId )
1666 KaxCluster *cluster = (KaxCluster*)el;
1668 /* add it to the index */
1669 IndexAppendCluster( p_input, cluster );
1671 if( (int64_t)cluster->GetElementPosition() >= i_pos )
1673 p_sys->cluster = cluster;
1683 for( i_index = 0; i_index < p_sys->i_index; i_index++ )
1685 if( p_sys->index[i_index].i_time >= i_date )
1696 msg_Dbg( p_input, "seek got "I64Fd" (%d%%)",
1697 p_sys->index[i_index].i_time, (int)(100 * p_sys->index[i_index].i_position /p_input->stream.p_selected_area->i_size ) );
1699 p_sys->in->setFilePointer( p_sys->index[i_index].i_position, seek_beginning );
1702 /* now parse until key frame */
1703 #define tk p_sys->track[i_track]
1704 i_track_skipping = 0;
1705 for( i_track = 0; i_track < p_sys->i_track; i_track++ )
1707 if( tk.i_cat == VIDEO_ES )
1709 tk.b_search_keyframe = VLC_TRUE;
1714 while( i_track_skipping > 0 )
1716 if( BlockGet( p_input, &block, &i_block_ref1, &i_block_ref2, &i_block_duration ) )
1718 msg_Warn( p_input, "cannot get block EOF?" );
1723 p_sys->i_pts = block->GlobalTimecode() * (mtime_t) 1000 / p_sys->i_timescale;
1725 for( i_track = 0; i_track < p_sys->i_track; i_track++ )
1727 if( tk.i_number == block->TrackNum() )
1733 if( i_track < p_sys->i_track )
1735 if( tk.i_cat == VIDEO_ES && i_block_ref1 == -1 && tk.b_search_keyframe )
1737 tk.b_search_keyframe = VLC_FALSE;
1740 if( tk.i_cat == VIDEO_ES && !tk.b_search_keyframe )
1742 BlockDecode( p_input, block, 0, 0 );
1751 /*****************************************************************************
1752 * Demux: reads and demuxes data packets
1753 *****************************************************************************
1754 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
1755 *****************************************************************************/
1756 static int Demux( input_thread_t * p_input )
1758 demux_sys_t *p_sys = p_input->p_demux_data;
1759 mtime_t i_start_pts;
1760 int i_block_count = 0;
1763 int64_t i_block_duration;
1764 int64_t i_block_ref1;
1765 int64_t i_block_ref2;
1767 if( p_input->stream.p_selected_program->i_synchro_state == SYNCHRO_REINIT )
1769 mtime_t i_duration = (mtime_t)( p_sys->f_duration / 1000 );
1770 mtime_t i_date = -1;
1773 if( i_duration > 0 )
1775 i_date = (mtime_t)1000000 *
1776 (mtime_t)i_duration*
1777 (mtime_t)p_sys->in->getFilePointer() /
1778 (mtime_t)p_input->stream.p_selected_area->i_size;
1780 if( p_input->stream.p_selected_area->i_size > 0 )
1782 i_percent = 100 * p_sys->in->getFilePointer() /
1783 p_input->stream.p_selected_area->i_size;
1786 Seek( p_input, i_date, i_percent);
1795 if( BlockGet( p_input, &block, &i_block_ref1, &i_block_ref2, &i_block_duration ) )
1797 msg_Warn( p_input, "cannot get block EOF?" );
1802 p_sys->i_pts = block->GlobalTimecode() * (mtime_t) 1000 / p_sys->i_timescale;
1804 if( p_sys->i_pts > 0 )
1806 input_ClockManageRef( p_input,
1807 p_input->stream.p_selected_program,
1808 p_sys->i_pts * 9 / 100 );
1811 i_pts = input_ClockGetTS( p_input,
1812 p_input->stream.p_selected_program,
1813 p_sys->i_pts * 9 / 100 );
1817 BlockDecode( p_input, block, i_pts, i_block_duration );
1822 if( i_start_pts == -1 )
1824 i_start_pts = p_sys->i_pts;
1826 else if( p_sys->i_pts > i_start_pts + (mtime_t)100000 || i_block_count > 5 )
1835 /*****************************************************************************
1837 *****************************************************************************/
1838 vlc_stream_io_callback::vlc_stream_io_callback( input_thread_t *p_input_ )
1843 uint32_t vlc_stream_io_callback::read( void *p_buffer, size_t i_size )
1845 data_packet_t *p_data;
1851 if( !i_size || mb_eof )
1858 i_count = input_SplitBuffer(p_input, &p_data, __MIN( i_size, 10240 ) );
1863 memcpy( p_buffer, p_data->p_payload_start, i_count );
1864 input_DeletePacket( p_input->p_method_data, p_data );
1866 (uint8_t*)p_buffer += i_count;
1874 void vlc_stream_io_callback::setFilePointer(int64_t i_offset, seek_mode mode )
1879 i_last = getFilePointer();
1881 vlc_mutex_lock( &p_input->stream.stream_lock );
1884 case seek_beginning:
1888 i_pos = p_input->stream.p_selected_area->i_size - i_offset;
1891 i_pos= i_last + i_offset;
1896 ( i_pos > p_input->stream.p_selected_area->i_size && p_input->stream.p_selected_area->i_size != 0 ) )
1898 msg_Err( p_input, "seeking to wrong place (i_pos="I64Fd")", i_pos );
1899 vlc_mutex_unlock( &p_input->stream.stream_lock );
1904 vlc_mutex_unlock( &p_input->stream.stream_lock );
1908 if( i_pos == i_last )
1913 msg_Dbg( p_input, "####################seek new="I64Fd" old="I64Fd,
1914 i_pos, getFilePointer() );
1916 if( p_input->stream.b_seekable &&
1917 ( /*p_input->stream.i_method == INPUT_METHOD_FILE ||*/ i_pos < i_last || i_pos - i_last > p_input->i_bufsize / 4 ) )
1919 input_AccessReinit( p_input );
1920 p_input->pf_seek( p_input, i_pos );
1922 else if( i_pos > i_last )
1924 data_packet_t *p_data;
1925 int i_skip = i_pos - i_last;
1929 msg_Warn( p_input, "will skip %d bytes, slow", i_skip );
1936 i_read = input_SplitBuffer( p_input, &p_data,
1937 __MIN( 4096, i_skip ) );
1940 msg_Err( p_input, "seek failed" );
1946 input_DeletePacket( p_input->p_method_data, p_data );
1947 if( i_read == 0 && i_skip > 0 )
1949 msg_Err( p_input, "seek failed" );
1957 msg_Err( p_input, "cannot seek or emulate seek to "I64Fd" from "I64Fd,
1962 size_t vlc_stream_io_callback::write( const void *p_buffer, size_t i_size )
1966 uint64_t vlc_stream_io_callback::getFilePointer( void )
1970 vlc_mutex_lock( &p_input->stream.stream_lock );
1971 i_pos= p_input->stream.p_selected_area->i_tell;
1972 vlc_mutex_unlock( &p_input->stream.stream_lock );
1976 void vlc_stream_io_callback::close( void )
1982 /*****************************************************************************
1983 * Ebml Stream parser
1984 *****************************************************************************/
1985 EbmlParser::EbmlParser( EbmlStream *es, EbmlElement *el_start )
1993 for( i = 1; i < 6; i++ )
1999 mb_keep = VLC_FALSE;
2002 EbmlParser::~EbmlParser( void )
2006 for( i = 1; i < mi_level; i++ )
2012 mb_keep = VLC_FALSE;
2016 void EbmlParser::Up( void )
2018 if( mi_user_level == mi_level )
2020 fprintf( stderr," arrrrrrrrrrrrrg Up cannot escape itself\n" );
2026 void EbmlParser::Down( void )
2032 void EbmlParser::Keep( void )
2037 int EbmlParser::GetLevel( void )
2039 return mi_user_level;
2042 EbmlElement *EbmlParser::Get( void )
2046 if( mi_user_level != mi_level )
2052 EbmlElement *ret = m_got;
2058 if( m_el[mi_level] )
2060 m_el[mi_level]->SkipData( *m_es, m_el[mi_level]->Generic().Context );
2063 delete m_el[mi_level];
2065 mb_keep = VLC_FALSE;
2068 m_el[mi_level] = m_es->FindNextElement( m_el[mi_level - 1]->Generic().Context, i_ulev, 0xFFFFFFFFL, true, 1 );
2079 delete m_el[mi_level - 1];
2080 m_got = m_el[mi_level -1] = m_el[mi_level];
2081 m_el[mi_level] = NULL;
2088 else if( m_el[mi_level] == NULL )
2090 fprintf( stderr," m_el[mi_level] == NULL\n" );
2093 return m_el[mi_level];
2097 /*****************************************************************************
2099 * * LoadCues : load the cues element and update index
2101 * * LoadTags : load ... the tags element
2103 * * InformationsCreate : create all informations, load tags if present
2105 *****************************************************************************/
2106 static void LoadCues( input_thread_t *p_input )
2108 demux_sys_t *p_sys = p_input->p_demux_data;
2109 int64_t i_sav_position = p_sys->in->getFilePointer();
2111 EbmlElement *el, *cues;
2113 msg_Dbg( p_input, "loading cues" );
2114 p_sys->in->setFilePointer( p_sys->i_cues_position, seek_beginning );
2115 cues = p_sys->es->FindNextID( KaxCues::ClassInfos, 0xFFFFFFFFL);
2119 msg_Err( p_input, "cannot load cues (broken seekhead or file)" );
2123 ep = new EbmlParser( p_sys->es, cues );
2124 while( ( el = ep->Get() ) != NULL )
2126 if( EbmlId( *el ) == KaxCuePoint::ClassInfos.GlobalId )
2128 #define idx p_sys->index[p_sys->i_index]
2131 idx.i_block_number= -1;
2132 idx.i_position = -1;
2134 idx.b_key = VLC_TRUE;
2137 while( ( el = ep->Get() ) != NULL )
2139 if( EbmlId( *el ) == KaxCueTime::ClassInfos.GlobalId )
2141 KaxCueTime &ctime = *(KaxCueTime*)el;
2143 ctime.ReadData( p_sys->es->I_O() );
2145 idx.i_time = uint64( ctime ) * (mtime_t)1000000000 / p_sys->i_timescale;
2147 else if( EbmlId( *el ) == KaxCueTrackPositions::ClassInfos.GlobalId )
2150 while( ( el = ep->Get() ) != NULL )
2152 if( EbmlId( *el ) == KaxCueTrack::ClassInfos.GlobalId )
2154 KaxCueTrack &ctrack = *(KaxCueTrack*)el;
2156 ctrack.ReadData( p_sys->es->I_O() );
2157 idx.i_track = uint16( ctrack );
2159 else if( EbmlId( *el ) == KaxCueClusterPosition::ClassInfos.GlobalId )
2161 KaxCueClusterPosition &ccpos = *(KaxCueClusterPosition*)el;
2163 ccpos.ReadData( p_sys->es->I_O() );
2164 idx.i_position = p_sys->segment->GetGlobalPosition( uint64( ccpos ) );
2166 else if( EbmlId( *el ) == KaxCueBlockNumber::ClassInfos.GlobalId )
2168 KaxCueBlockNumber &cbnum = *(KaxCueBlockNumber*)el;
2170 cbnum.ReadData( p_sys->es->I_O() );
2171 idx.i_block_number = uint32( cbnum );
2175 msg_Dbg( p_input, " * Unknown (%s)", typeid(*el).name() );
2182 msg_Dbg( p_input, " * Unknown (%s)", typeid(*el).name() );
2187 msg_Dbg( p_input, " * added time="I64Fd" pos="I64Fd
2188 " track=%d bnum=%d", idx.i_time, idx.i_position,
2189 idx.i_track, idx.i_block_number );
2192 if( p_sys->i_index >= p_sys->i_index_max )
2194 p_sys->i_index_max += 1024;
2195 p_sys->index = (mkv_index_t*)realloc( p_sys->index, sizeof( mkv_index_t ) * p_sys->i_index_max );
2201 msg_Dbg( p_input, " * Unknown (%s)", typeid(*el).name() );
2207 p_sys->b_cues = VLC_TRUE;
2209 msg_Dbg( p_input, "loading cues done." );
2210 p_sys->in->setFilePointer( i_sav_position, seek_beginning );
2213 static void LoadTags( input_thread_t *p_input )
2215 demux_sys_t *p_sys = p_input->p_demux_data;
2216 int64_t i_sav_position = p_sys->in->getFilePointer();
2218 EbmlElement *el, *tags;
2220 msg_Dbg( p_input, "loading tags" );
2221 p_sys->in->setFilePointer( p_sys->i_tags_position, seek_beginning );
2222 tags = p_sys->es->FindNextID( KaxTags::ClassInfos, 0xFFFFFFFFL);
2226 msg_Err( p_input, "cannot load tags (broken seekhead or file)" );
2230 msg_Dbg( p_input, "Tags" );
2231 ep = new EbmlParser( p_sys->es, tags );
2232 while( ( el = ep->Get() ) != NULL )
2234 if( EbmlId( *el ) == KaxTag::ClassInfos.GlobalId )
2236 msg_Dbg( p_input, "+ Tag" );
2238 while( ( el = ep->Get() ) != NULL )
2240 if( EbmlId( *el ) == KaxTagTargets::ClassInfos.GlobalId )
2242 msg_Dbg( p_input, "| + Targets" );
2244 while( ( el = ep->Get() ) != NULL )
2246 msg_Dbg( p_input, "| | + Unknown (%s)", typeid( *el ).name() );
2250 else if( EbmlId( *el ) == KaxTagGeneral::ClassInfos.GlobalId )
2252 msg_Dbg( p_input, "| + General" );
2254 while( ( el = ep->Get() ) != NULL )
2256 msg_Dbg( p_input, "| | + Unknown (%s)", typeid( *el ).name() );
2260 else if( EbmlId( *el ) == KaxTagGenres::ClassInfos.GlobalId )
2262 msg_Dbg( p_input, "| + Genres" );
2264 while( ( el = ep->Get() ) != NULL )
2266 msg_Dbg( p_input, "| | + Unknown (%s)", typeid( *el ).name() );
2270 else if( EbmlId( *el ) == KaxTagAudioSpecific::ClassInfos.GlobalId )
2272 msg_Dbg( p_input, "| + Audio Specific" );
2274 while( ( el = ep->Get() ) != NULL )
2276 msg_Dbg( p_input, "| | + Unknown (%s)", typeid( *el ).name() );
2280 else if( EbmlId( *el ) == KaxTagImageSpecific::ClassInfos.GlobalId )
2282 msg_Dbg( p_input, "| + Images Specific" );
2284 while( ( el = ep->Get() ) != NULL )
2286 msg_Dbg( p_input, "| | + Unknown (%s)", typeid( *el ).name() );
2290 else if( EbmlId( *el ) == KaxTagMultiComment::ClassInfos.GlobalId )
2292 msg_Dbg( p_input, "| + Multi Comment" );
2294 else if( EbmlId( *el ) == KaxTagMultiCommercial::ClassInfos.GlobalId )
2296 msg_Dbg( p_input, "| + Multi Commercial" );
2298 else if( EbmlId( *el ) == KaxTagMultiDate::ClassInfos.GlobalId )
2300 msg_Dbg( p_input, "| + Multi Date" );
2302 else if( EbmlId( *el ) == KaxTagMultiEntity::ClassInfos.GlobalId )
2304 msg_Dbg( p_input, "| + Multi Entity" );
2306 else if( EbmlId( *el ) == KaxTagMultiIdentifier::ClassInfos.GlobalId )
2308 msg_Dbg( p_input, "| + Multi Identifier" );
2310 else if( EbmlId( *el ) == KaxTagMultiLegal::ClassInfos.GlobalId )
2312 msg_Dbg( p_input, "| + Multi Legal" );
2314 else if( EbmlId( *el ) == KaxTagMultiTitle::ClassInfos.GlobalId )
2316 msg_Dbg( p_input, "| + Multi Title" );
2320 msg_Dbg( p_input, "| + Unknown (%s)", typeid( *el ).name() );
2327 msg_Dbg( p_input, "+ Unknown (%s)", typeid( *el ).name() );
2333 msg_Dbg( p_input, "loading tags done." );
2334 p_sys->in->setFilePointer( i_sav_position, seek_beginning );
2337 static void InformationsCreate( input_thread_t *p_input )
2339 demux_sys_t *p_sys = p_input->p_demux_data;
2340 input_info_category_t *p_cat;
2343 p_cat = input_InfoCategory( p_input, "Matroska" );
2344 if( p_sys->f_duration > 1000.1 )
2346 int64_t i_sec = (int64_t)p_sys->f_duration / 1000;
2350 m = ( i_sec / 60 ) % 60;
2353 input_AddInfo( p_cat, _("Duration"), "%d:%2.2d:%2.2d" , h, m, s );
2356 if( p_sys->psz_title )
2358 input_AddInfo( p_cat, _("Title"), "%s" ,p_sys->psz_title );
2360 if( p_sys->psz_date_utc )
2362 input_AddInfo( p_cat, _("Date UTC"), "%s" ,p_sys->psz_date_utc );
2364 if( p_sys->psz_segment_filename )
2366 input_AddInfo( p_cat, _("Segment Filename"), "%s" ,p_sys->psz_segment_filename );
2368 if( p_sys->psz_muxing_application )
2370 input_AddInfo( p_cat, _("Muxing Application"), "%s" ,p_sys->psz_muxing_application );
2372 if( p_sys->psz_writing_application )
2374 input_AddInfo( p_cat, _("Writing Application"), "%s" ,p_sys->psz_writing_application );
2376 input_AddInfo( p_cat, _("Number of streams"), "%d" , p_sys->i_track );
2378 for( i_track = 0; i_track < p_sys->i_track; i_track++ )
2380 char psz_cat[strlen( "Stream " ) + 10];
2381 #define tk p_sys->track[i_track]
2383 sprintf( psz_cat, "Stream %d", i_track );
2384 p_cat = input_InfoCategory( p_input, psz_cat);
2387 input_AddInfo( p_cat, _("Name"), "%s", tk.psz_name );
2389 if( tk.psz_codec_name )
2391 input_AddInfo( p_cat, _("Codec Name"), "%s", tk.psz_codec_name );
2393 if( tk.psz_codec_settings )
2395 input_AddInfo( p_cat, _("Codec Setting"), "%s", tk.psz_codec_settings );
2397 if( tk.psz_codec_info_url )
2399 input_AddInfo( p_cat, _("Codec Info"), "%s", tk.psz_codec_info_url );
2401 if( tk.psz_codec_download_url )
2403 input_AddInfo( p_cat, _("Codec Download"), "%s", tk.psz_codec_download_url );
2409 input_AddInfo( p_cat, _("Type"), _("Audio") );
2410 input_AddInfo( p_cat, _("Codec"), "%.4s (%s)", (char*)&tk.i_codec, tk.psz_codec );
2411 if( tk.i_channels > 0 )
2413 input_AddInfo( p_cat, _("Channels"), "%d", tk.i_channels );
2415 if( tk.i_samplerate > 0 )
2417 input_AddInfo( p_cat, _("Sample Rate"), "%d", tk.i_samplerate );
2419 if( tk.i_bitspersample )
2421 input_AddInfo( p_cat, _("Bits Per Sample"), "%d", tk.i_bitspersample );
2425 input_AddInfo( p_cat, _("Type"), _("Video") );
2426 input_AddInfo( p_cat, _("Codec"), "%.4s (%s)", (char*)&tk.i_codec, tk.psz_codec );
2427 if( tk.i_width > 0 && tk.i_height )
2429 input_AddInfo( p_cat, _("Resolution"), "%dx%d", tk.i_width, tk.i_height );
2431 if( tk.i_display_width > 0 && tk.i_display_height )
2433 input_AddInfo( p_cat, _("Display Resolution"), "%dx%d", tk.i_display_width, tk.i_display_height );
2435 if( tk.f_fps > 0.1 )
2437 input_AddInfo( p_cat, _("Frame Per Second"), "%.3f", tk.f_fps );
2441 input_AddInfo( p_cat, _("Type"), _("Subtitle") );
2442 input_AddInfo( p_cat, _("Codec"), "%s", tk.psz_codec );
2448 if( p_sys->i_tags_position >= 0 && p_input->stream.b_seekable )
2450 LoadTags( p_input );
2455 /*****************************************************************************
2457 *****************************************************************************/
2459 static void IndexAppendCluster( input_thread_t *p_input, KaxCluster *cluster )
2461 demux_sys_t *p_sys = p_input->p_demux_data;
2463 #define idx p_sys->index[p_sys->i_index]
2465 idx.i_block_number= -1;
2466 idx.i_position = cluster->GetElementPosition();
2468 idx.b_key = VLC_TRUE;
2471 if( p_sys->i_index >= p_sys->i_index_max )
2473 p_sys->i_index_max += 1024;
2474 p_sys->index = (mkv_index_t*)realloc( p_sys->index, sizeof( mkv_index_t ) * p_sys->i_index_max );
2479 static char * UTF8ToStr( const UTFstring &u )
2488 p = dst = (char*)malloc( i_src + 1);