1 /*****************************************************************************
2 * mkv.cpp : matroska demuxer
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: mkv.cpp,v 1.21 2003/08/17 23:02:52 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 switch( p_wf->wFormatTag )
1092 case WAVE_FORMAT_PCM:
1093 tk.i_codec = VLC_FOURCC( 'a', 'r', 'a', 'w' );
1095 case WAVE_FORMAT_ADPCM:
1096 tk.i_codec = VLC_FOURCC( 'm', 's', 0x00, 0x02 );
1098 case WAVE_FORMAT_ALAW:
1099 tk.i_codec = VLC_FOURCC( 'a', 'l', 'a', 'w' );
1101 case WAVE_FORMAT_MULAW:
1102 tk.i_codec = VLC_FOURCC( 'm', 'l', 'a', 'w' );
1104 case WAVE_FORMAT_IMA_ADPCM:
1105 tk.i_codec = VLC_FOURCC( 'm', 's', 0x00, 0x11 );
1107 case WAVE_FORMAT_MPEG:
1108 case WAVE_FORMAT_MPEGLAYER3:
1109 tk.i_codec = VLC_FOURCC( 'm', 'p', 'g', 'a' );
1111 case WAVE_FORMAT_A52:
1112 tk.i_codec = VLC_FOURCC( 'a', '5', '2', ' ' );
1114 case WAVE_FORMAT_WMA1:
1115 tk.i_codec = VLC_FOURCC( 'w', 'm', 'a', '1' );
1117 case WAVE_FORMAT_WMA2:
1118 tk.i_codec = VLC_FOURCC( 'w', 'm', 'a', '2' );
1120 case WAVE_FORMAT_WMA3:
1121 tk.i_codec = VLC_FOURCC( 'w', 'm', 'a', '3' );
1124 msg_Err( p_input, "unknown wFormatTag=0x%x", p_wf->wFormatTag );
1125 tk.i_codec = VLC_FOURCC( 'm', 's', p_wf->wFormatTag >> 8, p_wf->wFormatTag&0xff );
1128 tk.p_es->p_waveformatex = p_wf;
1131 else if( !strcmp( tk.psz_codec, "A_MPEG/L3" ) ||
1132 !strcmp( tk.psz_codec, "A_MPEG/L2" ) ||
1133 !strcmp( tk.psz_codec, "A_MPEG/L1" ) )
1135 tk.i_codec = VLC_FOURCC( 'm', 'p', 'g', 'a' );
1137 else if( !strcmp( tk.psz_codec, "A_AC3" ) )
1139 tk.i_codec = VLC_FOURCC( 'a', '5', '2', ' ' );
1141 else if( !strcmp( tk.psz_codec, "A_DTS" ) )
1143 tk.i_codec = VLC_FOURCC( 'd', 't', 's', ' ' );
1145 else if( !strcmp( tk.psz_codec, "A_VORBIS" ) )
1147 tk.i_codec = VLC_FOURCC( 'v', 'o', 'r', 'b' );
1148 tk.i_data_init = tk.i_extra_data;
1149 tk.p_data_init = tk.p_extra_data;
1151 else if( !strncmp( tk.psz_codec, "A_AAC/MPEG2/", strlen( "A_AAC/MPEG2/" ) ) ||
1152 !strncmp( tk.psz_codec, "A_AAC/MPEG4/", strlen( "A_AAC/MPEG4/" ) ) )
1154 int i_profile, i_srate;
1155 static int i_sample_rates[] =
1157 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
1158 16000, 12000, 11025, 8000, 7350, 0, 0, 0
1162 tk.i_codec = VLC_FOURCC( 'm', 'p', '4', 'a' );
1163 /* create data for faad (MP4DecSpecificDescrTag)*/
1165 if( !strcmp( &tk.psz_codec[12], "MAIN" ) )
1169 else if( !strcmp( &tk.psz_codec[12], "LC" ) )
1173 else if( !strcmp( &tk.psz_codec[12], "SSR" ) )
1182 for( i_srate = 0; i_srate < 13; i_srate++ )
1184 if( i_sample_rates[i_srate] == tk.i_samplerate )
1189 msg_Dbg( p_input, "profile=%d srate=%d", i_profile, i_srate );
1191 tk.i_extra_data = sizeof( WAVEFORMATEX ) + 2;
1192 tk.p_extra_data = (uint8_t*)malloc( tk.i_extra_data );
1193 p_wf = (WAVEFORMATEX*)tk.p_extra_data;
1195 p_wf->wFormatTag = WAVE_FORMAT_UNKNOWN;
1196 p_wf->nChannels = tk.i_channels;
1197 p_wf->nSamplesPerSec = tk.i_samplerate;
1198 p_wf->nAvgBytesPerSec = 0;
1199 p_wf->nBlockAlign = 0;
1200 p_wf->wBitsPerSample = 0;
1203 tk.p_extra_data[sizeof( WAVEFORMATEX )+ 0] = ((i_profile + 1) << 3) | ((i_srate&0xe) >> 1);
1204 tk.p_extra_data[sizeof( WAVEFORMATEX )+ 1] = ((i_srate & 0x1) << 7) | (tk.i_channels << 3);
1206 tk.p_es->p_waveformatex = p_wf;
1208 else if( !strcmp( tk.psz_codec, "A_PCM/INT/BIG" ) ||
1209 !strcmp( tk.psz_codec, "A_PCM/INT/LIT" ) ||
1210 !strcmp( tk.psz_codec, "A_PCM/FLOAT/IEEE" ) )
1214 tk.i_extra_data = sizeof( WAVEFORMATEX );
1215 tk.p_extra_data = (uint8_t*)malloc( tk.i_extra_data );
1217 p_wf = (WAVEFORMATEX*)tk.p_extra_data;
1219 if( !strncmp( &tk.psz_codec[6], "INT", 3 ) )
1221 p_wf->wFormatTag = WAVE_FORMAT_PCM;
1225 p_wf->wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
1227 p_wf->nChannels = tk.i_channels;
1228 p_wf->nSamplesPerSec = tk.i_samplerate;
1229 p_wf->nAvgBytesPerSec = 0;
1230 p_wf->nBlockAlign = ( tk.i_bitspersample + 7 ) / 8 * tk.i_channels;
1231 p_wf->wBitsPerSample = tk.i_bitspersample;
1234 tk.p_es->p_waveformatex = p_wf;
1236 if( !strcmp( tk.psz_codec, "A_PCM/INT/BIG" ) )
1238 tk.i_codec = VLC_FOURCC( 't', 'w', 'o', 's' );
1242 tk.i_codec = VLC_FOURCC( 'a', 'r', 'a', 'w' );
1245 else if( !strcmp( tk.psz_codec, "S_TEXT/UTF8" ) )
1247 tk.i_codec = VLC_FOURCC( 's', 'u', 'b', 't' );
1250 else if( !strcmp( tk.psz_codec, "S_TEXT/SSA" ) )
1252 tk.i_codec = VLC_FOURCC( 's', 'u', 'b', 't' );
1257 msg_Err( p_input, "unknow codec id=`%s'", tk.psz_codec );
1258 tk.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
1261 tk.p_es->i_fourcc = tk.i_codec;
1265 /* select track all video, one audio, no spu TODO : improve */
1266 b_audio_selected = VLC_FALSE;
1267 i_audio_channel = 0;
1269 for( i_track = 0; i_track < p_sys->i_track; i_track++ )
1271 #define tk p_sys->track[i_track]
1275 vlc_mutex_lock( &p_input->stream.stream_lock );
1276 input_SelectES( p_input, tk.p_es );
1277 vlc_mutex_unlock( &p_input->stream.stream_lock );
1281 if( ( !b_audio_selected && config_GetInt( p_input, "audio-channel" ) < 0 ) ||
1282 i_audio_channel == config_GetInt( p_input, "audio-channel" ) )
1284 vlc_mutex_lock( &p_input->stream.stream_lock );
1285 input_SelectES( p_input, tk.p_es );
1286 vlc_mutex_unlock( &p_input->stream.stream_lock );
1288 b_audio_selected = tk.p_es->p_decoder_fifo ? VLC_TRUE : VLC_FALSE;
1293 if( i_spu_channel == config_GetInt( p_input, "spu-channel" ) )
1295 vlc_mutex_lock( &p_input->stream.stream_lock );
1296 input_SelectES( p_input, tk.p_es );
1297 vlc_mutex_unlock( &p_input->stream.stream_lock );
1305 if( !b_audio_selected )
1307 msg_Warn( p_input, "cannot find/select audio track" );
1310 /* add informations */
1311 InformationsCreate( p_input );
1319 return VLC_EGENERIC;
1322 /*****************************************************************************
1323 * Deactivate: frees unused data
1324 *****************************************************************************/
1325 static void Deactivate( vlc_object_t *p_this )
1327 input_thread_t *p_input = (input_thread_t *)p_this;
1328 demux_sys_t *p_sys = p_input->p_demux_data;
1332 for( i_track = 0; i_track < p_sys->i_track; i_track++ )
1334 #define tk p_sys->track[i_track]
1337 free( tk.psz_codec );
1339 if( tk.psz_language )
1341 free( tk.psz_language );
1345 free( p_sys->track );
1347 if( p_sys->psz_writing_application )
1349 free( p_sys->psz_writing_application );
1351 if( p_sys->psz_muxing_application )
1353 free( p_sys->psz_muxing_application );
1356 delete p_sys->segment;
1365 static int BlockGet( input_thread_t *p_input, KaxBlock **pp_block, int64_t *pi_ref1, int64_t *pi_ref2, int64_t *pi_duration )
1367 demux_sys_t *p_sys = p_input->p_demux_data;
1378 if( p_input->b_die )
1380 return VLC_EGENERIC;
1383 el = p_sys->ep->Get();
1384 i_level = p_sys->ep->GetLevel();
1386 if( el == NULL && *pp_block != NULL )
1388 /* update the index */
1389 #define idx p_sys->index[p_sys->i_index - 1]
1390 if( p_sys->i_index > 0 && idx.i_time == -1 )
1392 idx.i_time = (*pp_block)->GlobalTimecode() * (mtime_t) 1000 / p_sys->i_timescale;
1393 idx.b_key = *pi_ref1 == -1 ? VLC_TRUE : VLC_FALSE;
1401 if( p_sys->ep->GetLevel() > 1 )
1406 msg_Warn( p_input, "EOF" );
1407 return VLC_EGENERIC;
1413 if( EbmlId( *el ) == KaxCluster::ClassInfos.GlobalId )
1415 p_sys->cluster = (KaxCluster*)el;
1417 /* add it to the index */
1418 if( p_sys->i_index == 0 ||
1419 ( p_sys->i_index > 0 && p_sys->index[p_sys->i_index - 1].i_position < (int64_t)p_sys->cluster->GetElementPosition() ) )
1421 IndexAppendCluster( p_input, p_sys->cluster );
1426 else if( EbmlId( *el ) == KaxCues::ClassInfos.GlobalId )
1428 msg_Warn( p_input, "find KaxCues FIXME" );
1429 return VLC_EGENERIC;
1433 msg_Dbg( p_input, "unknown (%s)", typeid( el ).name() );
1436 else if( i_level == 2 )
1438 if( EbmlId( *el ) == KaxClusterTimecode::ClassInfos.GlobalId )
1440 KaxClusterTimecode &ctc = *(KaxClusterTimecode*)el;
1442 ctc.ReadData( p_sys->es->I_O() );
1443 p_sys->cluster->InitTimecode( uint64( ctc ), p_sys->i_timescale );
1445 else if( EbmlId( *el ) == KaxBlockGroup::ClassInfos.GlobalId )
1450 else if( i_level == 3 )
1452 if( EbmlId( *el ) == KaxBlock::ClassInfos.GlobalId )
1454 *pp_block = (KaxBlock*)el;
1456 (*pp_block)->ReadData( p_sys->es->I_O() );
1457 (*pp_block)->SetParent( *p_sys->cluster );
1461 else if( EbmlId( *el ) == KaxBlockDuration::ClassInfos.GlobalId )
1463 KaxBlockDuration &dur = *(KaxBlockDuration*)el;
1465 dur.ReadData( p_sys->es->I_O() );
1466 *pi_duration = uint64( dur );
1468 else if( EbmlId( *el ) == KaxReferenceBlock::ClassInfos.GlobalId )
1470 KaxReferenceBlock &ref = *(KaxReferenceBlock*)el;
1472 ref.ReadData( p_sys->es->I_O() );
1473 if( *pi_ref1 == -1 )
1475 *pi_ref1 = int64( ref );
1479 *pi_ref2 = int64( ref );
1485 msg_Err( p_input, "invalid level = %d", i_level );
1486 return VLC_EGENERIC;
1491 static pes_packet_t *MemToPES( input_thread_t *p_input, uint8_t *p_mem, int i_mem )
1493 pes_packet_t *p_pes;
1494 data_packet_t *p_data;
1496 if( ( p_pes = input_NewPES( p_input->p_method_data ) ) == NULL )
1501 p_data = input_NewPacket( p_input->p_method_data, i_mem);
1503 memcpy( p_data->p_payload_start, p_mem, i_mem );
1504 p_data->p_payload_end = p_data->p_payload_start + i_mem;
1506 p_pes->p_first = p_pes->p_last = p_data;
1507 p_pes->i_nb_data = 1;
1508 p_pes->i_pes_size = i_mem;
1513 static void BlockDecode( input_thread_t *p_input, KaxBlock *block, mtime_t i_pts, mtime_t i_duration )
1515 demux_sys_t *p_sys = p_input->p_demux_data;
1520 #define tk p_sys->track[i_track]
1521 for( i_track = 0; i_track < p_sys->i_track; i_track++ )
1523 if( tk.i_number == block->TrackNum() )
1529 if( i_track >= p_sys->i_track )
1531 msg_Err( p_input, "invalid track number=%d", block->TrackNum() );
1535 if( tk.p_es->p_decoder_fifo == NULL )
1537 tk.b_inited = VLC_FALSE;
1541 if( tk.i_cat == AUDIO_ES && p_input->stream.control.b_mute )
1546 /* First send init data */
1547 if( !tk.b_inited && tk.i_data_init > 0 )
1549 pes_packet_t *p_init;
1551 msg_Dbg( p_input, "sending header (%d bytes)", tk.i_data_init );
1553 if( tk.i_codec == VLC_FOURCC( 'v', 'o', 'r', 'b' ) )
1559 /* XXX hack split the 3 headers */
1560 if( tk.p_data_init[0] != 0x02 )
1562 msg_Err( p_input, "invalid vorbis header" );
1565 for( i = 0; i < 2; i++ )
1568 while( i_offset < tk.i_data_init )
1570 i_size[i] += tk.p_data_init[i_offset];
1571 if( tk.p_data_init[i_offset++] != 0xff )
1577 i_size[0] = __MIN( i_size[0], tk.i_data_init - i_offset );
1578 i_size[1] = __MIN( i_size[1], tk.i_data_init - i_offset - i_size[0] );
1579 i_size[2] = tk.i_data_init - i_offset - i_size[0] - i_size[1];
1581 p_init = MemToPES( p_input, &tk.p_data_init[i_offset], i_size[0] );
1584 input_DecodePES( tk.p_es->p_decoder_fifo, p_init );
1586 p_init = MemToPES( p_input, &tk.p_data_init[i_offset+i_size[0]], i_size[1] );
1589 input_DecodePES( tk.p_es->p_decoder_fifo, p_init );
1591 p_init = MemToPES( p_input, &tk.p_data_init[i_offset+i_size[0]+i_size[1]], i_size[2] );
1594 input_DecodePES( tk.p_es->p_decoder_fifo, p_init );
1599 p_init = MemToPES( p_input, tk.p_data_init, tk.i_data_init );
1602 input_DecodePES( tk.p_es->p_decoder_fifo, p_init );
1606 tk.b_inited = VLC_TRUE;
1609 for( i = 0; i < block->NumberFrames(); i++ )
1611 pes_packet_t *p_pes;
1612 DataBuffer &data = block->GetBuffer(i);
1614 p_pes = MemToPES( p_input, data.Buffer(), data.Size() );
1620 p_pes->i_pts = i_pts;
1621 p_pes->i_dts = i_pts;
1623 if( tk.i_cat == SPU_ES )
1625 if( i_duration > 0 )
1627 /* FIXME not sure about that */
1628 p_pes->i_dts += i_duration * 1000;// * (mtime_t) 1000 / p_sys->i_timescale;
1634 if( p_pes->p_first && p_pes->i_pes_size > 0 )
1636 p_pes->p_first->p_payload_end[-1] = '\0';
1640 input_DecodePES( tk.p_es->p_decoder_fifo, p_pes );
1642 /* use time stamp only for first block */
1649 static void Seek( input_thread_t *p_input, mtime_t i_date, int i_percent)
1651 demux_sys_t *p_sys = p_input->p_demux_data;
1654 int64_t i_block_duration;
1655 int64_t i_block_ref1;
1656 int64_t i_block_ref2;
1659 int i_track_skipping;
1662 msg_Dbg( p_input, "seek request to "I64Fd" (%d%%)", i_date, i_percent );
1663 if( i_date < 0 && i_percent < 0 )
1669 p_sys->ep = new EbmlParser( p_sys->es, p_sys->segment );
1670 p_sys->cluster = NULL;
1672 /* seek without index or without date */
1673 if( config_GetInt( p_input, "mkv-seek-percent" ) || !p_sys->b_cues || i_date < 0 )
1675 int64_t i_pos = i_percent * p_input->stream.p_selected_area->i_size / 100;
1677 msg_Dbg( p_input, "imprecise way of seeking" );
1678 for( i_index = 0; i_index < p_sys->i_index; i_index++ )
1680 if( p_sys->index[i_index].i_position >= i_pos)
1685 if( i_index == p_sys->i_index )
1690 p_sys->in->setFilePointer( p_sys->index[i_index].i_position, seek_beginning );
1692 if( p_sys->index[i_index].i_position < i_pos )
1696 msg_Warn( p_input, "searching for cluster, could take some time" );
1698 /* search a cluster */
1699 while( ( el = p_sys->ep->Get() ) != NULL )
1701 if( EbmlId( *el ) == KaxCluster::ClassInfos.GlobalId )
1703 KaxCluster *cluster = (KaxCluster*)el;
1705 /* add it to the index */
1706 IndexAppendCluster( p_input, cluster );
1708 if( (int64_t)cluster->GetElementPosition() >= i_pos )
1710 p_sys->cluster = cluster;
1720 for( i_index = 0; i_index < p_sys->i_index; i_index++ )
1722 if( p_sys->index[i_index].i_time >= i_date )
1733 msg_Dbg( p_input, "seek got "I64Fd" (%d%%)",
1734 p_sys->index[i_index].i_time, (int)(100 * p_sys->index[i_index].i_position /p_input->stream.p_selected_area->i_size ) );
1736 p_sys->in->setFilePointer( p_sys->index[i_index].i_position, seek_beginning );
1739 /* now parse until key frame */
1740 #define tk p_sys->track[i_track]
1741 i_track_skipping = 0;
1742 for( i_track = 0; i_track < p_sys->i_track; i_track++ )
1744 if( tk.i_cat == VIDEO_ES )
1746 tk.b_search_keyframe = VLC_TRUE;
1751 while( i_track_skipping > 0 )
1753 if( BlockGet( p_input, &block, &i_block_ref1, &i_block_ref2, &i_block_duration ) )
1755 msg_Warn( p_input, "cannot get block EOF?" );
1760 p_sys->i_pts = block->GlobalTimecode() * (mtime_t) 1000 / p_sys->i_timescale;
1762 for( i_track = 0; i_track < p_sys->i_track; i_track++ )
1764 if( tk.i_number == block->TrackNum() )
1770 if( i_track < p_sys->i_track )
1772 if( tk.i_cat == VIDEO_ES && i_block_ref1 == -1 && tk.b_search_keyframe )
1774 tk.b_search_keyframe = VLC_FALSE;
1777 if( tk.i_cat == VIDEO_ES && !tk.b_search_keyframe )
1779 BlockDecode( p_input, block, 0, 0 );
1788 /*****************************************************************************
1789 * Demux: reads and demuxes data packets
1790 *****************************************************************************
1791 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
1792 *****************************************************************************/
1793 static int Demux( input_thread_t * p_input )
1795 demux_sys_t *p_sys = p_input->p_demux_data;
1796 mtime_t i_start_pts;
1797 int i_block_count = 0;
1800 int64_t i_block_duration;
1801 int64_t i_block_ref1;
1802 int64_t i_block_ref2;
1804 if( p_input->stream.p_selected_program->i_synchro_state == SYNCHRO_REINIT )
1806 mtime_t i_duration = (mtime_t)( p_sys->f_duration / 1000 );
1807 mtime_t i_date = -1;
1810 if( i_duration > 0 )
1812 i_date = (mtime_t)1000000 *
1813 (mtime_t)i_duration*
1814 (mtime_t)p_sys->in->getFilePointer() /
1815 (mtime_t)p_input->stream.p_selected_area->i_size;
1817 if( p_input->stream.p_selected_area->i_size > 0 )
1819 i_percent = 100 * p_sys->in->getFilePointer() /
1820 p_input->stream.p_selected_area->i_size;
1823 Seek( p_input, i_date, i_percent);
1832 if( BlockGet( p_input, &block, &i_block_ref1, &i_block_ref2, &i_block_duration ) )
1834 msg_Warn( p_input, "cannot get block EOF?" );
1839 p_sys->i_pts = block->GlobalTimecode() * (mtime_t) 1000 / p_sys->i_timescale;
1841 if( p_sys->i_pts > 0 )
1843 input_ClockManageRef( p_input,
1844 p_input->stream.p_selected_program,
1845 p_sys->i_pts * 9 / 100 );
1848 i_pts = input_ClockGetTS( p_input,
1849 p_input->stream.p_selected_program,
1850 p_sys->i_pts * 9 / 100 );
1854 BlockDecode( p_input, block, i_pts, i_block_duration );
1859 if( i_start_pts == -1 )
1861 i_start_pts = p_sys->i_pts;
1863 else if( p_sys->i_pts > i_start_pts + (mtime_t)100000 || i_block_count > 5 )
1872 /*****************************************************************************
1874 *****************************************************************************/
1875 vlc_stream_io_callback::vlc_stream_io_callback( input_thread_t *p_input_ )
1880 uint32_t vlc_stream_io_callback::read( void *p_buffer, size_t i_size )
1882 data_packet_t *p_data;
1888 if( !i_size || mb_eof )
1895 i_count = input_SplitBuffer(p_input, &p_data, __MIN( i_size, 10240 ) );
1900 memcpy( p_buffer, p_data->p_payload_start, i_count );
1901 input_DeletePacket( p_input->p_method_data, p_data );
1903 (uint8_t*)p_buffer += i_count;
1911 void vlc_stream_io_callback::setFilePointer(int64_t i_offset, seek_mode mode )
1916 i_last = getFilePointer();
1918 vlc_mutex_lock( &p_input->stream.stream_lock );
1921 case seek_beginning:
1925 i_pos = p_input->stream.p_selected_area->i_size - i_offset;
1928 i_pos= i_last + i_offset;
1933 ( i_pos > p_input->stream.p_selected_area->i_size && p_input->stream.p_selected_area->i_size != 0 ) )
1935 msg_Err( p_input, "seeking to wrong place (i_pos="I64Fd")", i_pos );
1936 vlc_mutex_unlock( &p_input->stream.stream_lock );
1941 vlc_mutex_unlock( &p_input->stream.stream_lock );
1945 if( i_pos == i_last )
1950 msg_Dbg( p_input, "####################seek new="I64Fd" old="I64Fd,
1951 i_pos, getFilePointer() );
1953 if( p_input->stream.b_seekable &&
1954 ( /*p_input->stream.i_method == INPUT_METHOD_FILE ||*/ i_pos < i_last || i_pos - i_last > p_input->i_bufsize / 4 ) )
1956 input_AccessReinit( p_input );
1957 p_input->pf_seek( p_input, i_pos );
1959 else if( i_pos > i_last )
1961 data_packet_t *p_data;
1962 int i_skip = i_pos - i_last;
1966 msg_Warn( p_input, "will skip %d bytes, slow", i_skip );
1973 i_read = input_SplitBuffer( p_input, &p_data,
1974 __MIN( 4096, i_skip ) );
1977 msg_Err( p_input, "seek failed" );
1983 input_DeletePacket( p_input->p_method_data, p_data );
1984 if( i_read == 0 && i_skip > 0 )
1986 msg_Err( p_input, "seek failed" );
1994 msg_Err( p_input, "cannot seek or emulate seek to "I64Fd" from "I64Fd,
1999 size_t vlc_stream_io_callback::write( const void *p_buffer, size_t i_size )
2003 uint64_t vlc_stream_io_callback::getFilePointer( void )
2007 vlc_mutex_lock( &p_input->stream.stream_lock );
2008 i_pos= p_input->stream.p_selected_area->i_tell;
2009 vlc_mutex_unlock( &p_input->stream.stream_lock );
2013 void vlc_stream_io_callback::close( void )
2019 /*****************************************************************************
2020 * Ebml Stream parser
2021 *****************************************************************************/
2022 EbmlParser::EbmlParser( EbmlStream *es, EbmlElement *el_start )
2030 for( i = 1; i < 6; i++ )
2036 mb_keep = VLC_FALSE;
2039 EbmlParser::~EbmlParser( void )
2043 for( i = 1; i < mi_level; i++ )
2049 mb_keep = VLC_FALSE;
2053 void EbmlParser::Up( void )
2055 if( mi_user_level == mi_level )
2057 fprintf( stderr," arrrrrrrrrrrrrg Up cannot escape itself\n" );
2063 void EbmlParser::Down( void )
2069 void EbmlParser::Keep( void )
2074 int EbmlParser::GetLevel( void )
2076 return mi_user_level;
2079 EbmlElement *EbmlParser::Get( void )
2083 if( mi_user_level != mi_level )
2089 EbmlElement *ret = m_got;
2095 if( m_el[mi_level] )
2097 m_el[mi_level]->SkipData( *m_es, m_el[mi_level]->Generic().Context );
2100 delete m_el[mi_level];
2102 mb_keep = VLC_FALSE;
2105 m_el[mi_level] = m_es->FindNextElement( m_el[mi_level - 1]->Generic().Context, i_ulev, 0xFFFFFFFFL, true, 1 );
2116 delete m_el[mi_level - 1];
2117 m_got = m_el[mi_level -1] = m_el[mi_level];
2118 m_el[mi_level] = NULL;
2125 else if( m_el[mi_level] == NULL )
2127 fprintf( stderr," m_el[mi_level] == NULL\n" );
2130 return m_el[mi_level];
2134 /*****************************************************************************
2136 * * LoadCues : load the cues element and update index
2138 * * LoadTags : load ... the tags element
2140 * * InformationsCreate : create all informations, load tags if present
2142 *****************************************************************************/
2143 static void LoadCues( input_thread_t *p_input )
2145 demux_sys_t *p_sys = p_input->p_demux_data;
2146 int64_t i_sav_position = p_sys->in->getFilePointer();
2148 EbmlElement *el, *cues;
2150 msg_Dbg( p_input, "loading cues" );
2151 p_sys->in->setFilePointer( p_sys->i_cues_position, seek_beginning );
2152 cues = p_sys->es->FindNextID( KaxCues::ClassInfos, 0xFFFFFFFFL);
2156 msg_Err( p_input, "cannot load cues (broken seekhead or file)" );
2160 ep = new EbmlParser( p_sys->es, cues );
2161 while( ( el = ep->Get() ) != NULL )
2163 if( EbmlId( *el ) == KaxCuePoint::ClassInfos.GlobalId )
2165 #define idx p_sys->index[p_sys->i_index]
2168 idx.i_block_number= -1;
2169 idx.i_position = -1;
2171 idx.b_key = VLC_TRUE;
2174 while( ( el = ep->Get() ) != NULL )
2176 if( EbmlId( *el ) == KaxCueTime::ClassInfos.GlobalId )
2178 KaxCueTime &ctime = *(KaxCueTime*)el;
2180 ctime.ReadData( p_sys->es->I_O() );
2182 idx.i_time = uint64( ctime ) * (mtime_t)1000000000 / p_sys->i_timescale;
2184 else if( EbmlId( *el ) == KaxCueTrackPositions::ClassInfos.GlobalId )
2187 while( ( el = ep->Get() ) != NULL )
2189 if( EbmlId( *el ) == KaxCueTrack::ClassInfos.GlobalId )
2191 KaxCueTrack &ctrack = *(KaxCueTrack*)el;
2193 ctrack.ReadData( p_sys->es->I_O() );
2194 idx.i_track = uint16( ctrack );
2196 else if( EbmlId( *el ) == KaxCueClusterPosition::ClassInfos.GlobalId )
2198 KaxCueClusterPosition &ccpos = *(KaxCueClusterPosition*)el;
2200 ccpos.ReadData( p_sys->es->I_O() );
2201 idx.i_position = p_sys->segment->GetGlobalPosition( uint64( ccpos ) );
2203 else if( EbmlId( *el ) == KaxCueBlockNumber::ClassInfos.GlobalId )
2205 KaxCueBlockNumber &cbnum = *(KaxCueBlockNumber*)el;
2207 cbnum.ReadData( p_sys->es->I_O() );
2208 idx.i_block_number = uint32( cbnum );
2212 msg_Dbg( p_input, " * Unknown (%s)", typeid(*el).name() );
2219 msg_Dbg( p_input, " * Unknown (%s)", typeid(*el).name() );
2224 msg_Dbg( p_input, " * added time="I64Fd" pos="I64Fd
2225 " track=%d bnum=%d", idx.i_time, idx.i_position,
2226 idx.i_track, idx.i_block_number );
2229 if( p_sys->i_index >= p_sys->i_index_max )
2231 p_sys->i_index_max += 1024;
2232 p_sys->index = (mkv_index_t*)realloc( p_sys->index, sizeof( mkv_index_t ) * p_sys->i_index_max );
2238 msg_Dbg( p_input, " * Unknown (%s)", typeid(*el).name() );
2244 p_sys->b_cues = VLC_TRUE;
2246 msg_Dbg( p_input, "loading cues done." );
2247 p_sys->in->setFilePointer( i_sav_position, seek_beginning );
2250 static void LoadTags( input_thread_t *p_input )
2252 demux_sys_t *p_sys = p_input->p_demux_data;
2253 int64_t i_sav_position = p_sys->in->getFilePointer();
2255 EbmlElement *el, *tags;
2257 msg_Dbg( p_input, "loading tags" );
2258 p_sys->in->setFilePointer( p_sys->i_tags_position, seek_beginning );
2259 tags = p_sys->es->FindNextID( KaxTags::ClassInfos, 0xFFFFFFFFL);
2263 msg_Err( p_input, "cannot load tags (broken seekhead or file)" );
2267 msg_Dbg( p_input, "Tags" );
2268 ep = new EbmlParser( p_sys->es, tags );
2269 while( ( el = ep->Get() ) != NULL )
2271 if( EbmlId( *el ) == KaxTag::ClassInfos.GlobalId )
2273 msg_Dbg( p_input, "+ Tag" );
2275 while( ( el = ep->Get() ) != NULL )
2277 if( EbmlId( *el ) == KaxTagTargets::ClassInfos.GlobalId )
2279 msg_Dbg( p_input, "| + Targets" );
2281 while( ( el = ep->Get() ) != NULL )
2283 msg_Dbg( p_input, "| | + Unknown (%s)", typeid( *el ).name() );
2287 else if( EbmlId( *el ) == KaxTagGeneral::ClassInfos.GlobalId )
2289 msg_Dbg( p_input, "| + General" );
2291 while( ( el = ep->Get() ) != NULL )
2293 msg_Dbg( p_input, "| | + Unknown (%s)", typeid( *el ).name() );
2297 else if( EbmlId( *el ) == KaxTagGenres::ClassInfos.GlobalId )
2299 msg_Dbg( p_input, "| + Genres" );
2301 while( ( el = ep->Get() ) != NULL )
2303 msg_Dbg( p_input, "| | + Unknown (%s)", typeid( *el ).name() );
2307 else if( EbmlId( *el ) == KaxTagAudioSpecific::ClassInfos.GlobalId )
2309 msg_Dbg( p_input, "| + Audio Specific" );
2311 while( ( el = ep->Get() ) != NULL )
2313 msg_Dbg( p_input, "| | + Unknown (%s)", typeid( *el ).name() );
2317 else if( EbmlId( *el ) == KaxTagImageSpecific::ClassInfos.GlobalId )
2319 msg_Dbg( p_input, "| + Images Specific" );
2321 while( ( el = ep->Get() ) != NULL )
2323 msg_Dbg( p_input, "| | + Unknown (%s)", typeid( *el ).name() );
2327 else if( EbmlId( *el ) == KaxTagMultiComment::ClassInfos.GlobalId )
2329 msg_Dbg( p_input, "| + Multi Comment" );
2331 else if( EbmlId( *el ) == KaxTagMultiCommercial::ClassInfos.GlobalId )
2333 msg_Dbg( p_input, "| + Multi Commercial" );
2335 else if( EbmlId( *el ) == KaxTagMultiDate::ClassInfos.GlobalId )
2337 msg_Dbg( p_input, "| + Multi Date" );
2339 else if( EbmlId( *el ) == KaxTagMultiEntity::ClassInfos.GlobalId )
2341 msg_Dbg( p_input, "| + Multi Entity" );
2343 else if( EbmlId( *el ) == KaxTagMultiIdentifier::ClassInfos.GlobalId )
2345 msg_Dbg( p_input, "| + Multi Identifier" );
2347 else if( EbmlId( *el ) == KaxTagMultiLegal::ClassInfos.GlobalId )
2349 msg_Dbg( p_input, "| + Multi Legal" );
2351 else if( EbmlId( *el ) == KaxTagMultiTitle::ClassInfos.GlobalId )
2353 msg_Dbg( p_input, "| + Multi Title" );
2357 msg_Dbg( p_input, "| + Unknown (%s)", typeid( *el ).name() );
2364 msg_Dbg( p_input, "+ Unknown (%s)", typeid( *el ).name() );
2370 msg_Dbg( p_input, "loading tags done." );
2371 p_sys->in->setFilePointer( i_sav_position, seek_beginning );
2374 static void InformationsCreate( input_thread_t *p_input )
2376 demux_sys_t *p_sys = p_input->p_demux_data;
2377 input_info_category_t *p_cat;
2380 p_cat = input_InfoCategory( p_input, "Matroska" );
2381 if( p_sys->f_duration > 1000.1 )
2383 int64_t i_sec = (int64_t)p_sys->f_duration / 1000;
2387 m = ( i_sec / 60 ) % 60;
2390 input_AddInfo( p_cat, _("Duration"), "%d:%2.2d:%2.2d" , h, m, s );
2393 if( p_sys->psz_title )
2395 input_AddInfo( p_cat, _("Title"), "%s" ,p_sys->psz_title );
2397 if( p_sys->psz_date_utc )
2399 input_AddInfo( p_cat, _("Date UTC"), "%s" ,p_sys->psz_date_utc );
2401 if( p_sys->psz_segment_filename )
2403 input_AddInfo( p_cat, _("Segment Filename"), "%s" ,p_sys->psz_segment_filename );
2405 if( p_sys->psz_muxing_application )
2407 input_AddInfo( p_cat, _("Muxing Application"), "%s" ,p_sys->psz_muxing_application );
2409 if( p_sys->psz_writing_application )
2411 input_AddInfo( p_cat, _("Writing Application"), "%s" ,p_sys->psz_writing_application );
2413 input_AddInfo( p_cat, _("Number of streams"), "%d" , p_sys->i_track );
2415 for( i_track = 0; i_track < p_sys->i_track; i_track++ )
2417 char psz_cat[strlen( "Stream " ) + 10];
2418 #define tk p_sys->track[i_track]
2420 sprintf( psz_cat, "Stream %d", i_track );
2421 p_cat = input_InfoCategory( p_input, psz_cat);
2424 input_AddInfo( p_cat, _("Name"), "%s", tk.psz_name );
2426 if( tk.psz_codec_name )
2428 input_AddInfo( p_cat, _("Codec Name"), "%s", tk.psz_codec_name );
2430 if( tk.psz_codec_settings )
2432 input_AddInfo( p_cat, _("Codec Setting"), "%s", tk.psz_codec_settings );
2434 if( tk.psz_codec_info_url )
2436 input_AddInfo( p_cat, _("Codec Info"), "%s", tk.psz_codec_info_url );
2438 if( tk.psz_codec_download_url )
2440 input_AddInfo( p_cat, _("Codec Download"), "%s", tk.psz_codec_download_url );
2446 input_AddInfo( p_cat, _("Type"), _("Audio") );
2447 input_AddInfo( p_cat, _("Codec"), "%.4s (%s)", (char*)&tk.i_codec, tk.psz_codec );
2448 if( tk.i_channels > 0 )
2450 input_AddInfo( p_cat, _("Channels"), "%d", tk.i_channels );
2452 if( tk.i_samplerate > 0 )
2454 input_AddInfo( p_cat, _("Sample Rate"), "%d", tk.i_samplerate );
2456 if( tk.i_bitspersample )
2458 input_AddInfo( p_cat, _("Bits Per Sample"), "%d", tk.i_bitspersample );
2462 input_AddInfo( p_cat, _("Type"), _("Video") );
2463 input_AddInfo( p_cat, _("Codec"), "%.4s (%s)", (char*)&tk.i_codec, tk.psz_codec );
2464 if( tk.i_width > 0 && tk.i_height )
2466 input_AddInfo( p_cat, _("Resolution"), "%dx%d", tk.i_width, tk.i_height );
2468 if( tk.i_display_width > 0 && tk.i_display_height )
2470 input_AddInfo( p_cat, _("Display Resolution"), "%dx%d", tk.i_display_width, tk.i_display_height );
2472 if( tk.f_fps > 0.1 )
2474 input_AddInfo( p_cat, _("Frame Per Second"), "%.3f", tk.f_fps );
2478 input_AddInfo( p_cat, _("Type"), _("Subtitle") );
2479 input_AddInfo( p_cat, _("Codec"), "%s", tk.psz_codec );
2485 if( p_sys->i_tags_position >= 0 && p_input->stream.b_seekable )
2487 LoadTags( p_input );
2492 /*****************************************************************************
2494 *****************************************************************************/
2496 static void IndexAppendCluster( input_thread_t *p_input, KaxCluster *cluster )
2498 demux_sys_t *p_sys = p_input->p_demux_data;
2500 #define idx p_sys->index[p_sys->i_index]
2502 idx.i_block_number= -1;
2503 idx.i_position = cluster->GetElementPosition();
2505 idx.b_key = VLC_TRUE;
2508 if( p_sys->i_index >= p_sys->i_index_max )
2510 p_sys->i_index_max += 1024;
2511 p_sys->index = (mkv_index_t*)realloc( p_sys->index, sizeof( mkv_index_t ) * p_sys->i_index_max );
2516 static char * UTF8ToStr( const UTFstring &u )
2525 p = dst = (char*)malloc( i_src + 1);