1 /*****************************************************************************
2 * mkv.cpp : matroska demuxer
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: mkv.cpp,v 1.18 2003/08/01 00:05:07 gbazin 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 #include "matroska/KaxAttachements.h"
57 #include "matroska/KaxBlock.h"
58 #include "matroska/KaxBlockData.h"
59 #include "matroska/KaxChapters.h"
60 #include "matroska/KaxCluster.h"
61 #include "matroska/KaxClusterData.h"
62 #include "matroska/KaxContexts.h"
63 #include "matroska/KaxCues.h"
64 #include "matroska/KaxCuesData.h"
65 #include "matroska/KaxInfo.h"
66 #include "matroska/KaxInfoData.h"
67 #include "matroska/KaxSeekHead.h"
68 #include "matroska/KaxSegment.h"
69 #include "matroska/KaxTag.h"
70 #include "matroska/KaxTags.h"
71 #include "matroska/KaxTagMulti.h"
72 #include "matroska/KaxTracks.h"
73 #include "matroska/KaxTrackAudio.h"
74 #include "matroska/KaxTrackVideo.h"
75 #include "matroska/KaxTrackEntryData.h"
77 #include "ebml/StdIOCallback.h"
79 using namespace LIBMATROSKA_NAMESPACE;
83 /*****************************************************************************
85 *****************************************************************************/
86 static int Activate ( vlc_object_t * );
87 static void Deactivate( vlc_object_t * );
88 static int Demux ( input_thread_t * );
90 /*****************************************************************************
92 *****************************************************************************/
94 add_category_hint( N_("mkv-demuxer"), NULL, VLC_TRUE );
95 add_bool( "mkv-seek-percent", 1, NULL,
96 N_("Seek based on percent not time"),
97 N_("Seek based on percent not time"), VLC_TRUE );
99 set_description( _("mka/mkv stream demuxer" ) );
100 set_capability( "demux", 50 );
101 set_callbacks( Activate, Deactivate );
102 add_shortcut( "mka" );
103 add_shortcut( "mkv" );
107 /*****************************************************************************
109 *****************************************************************************/
110 class vlc_stream_io_callback: public IOCallback
113 input_thread_t *p_input;
117 vlc_stream_io_callback( input_thread_t * );
119 virtual uint32_t read ( void *p_buffer, size_t i_size);
120 virtual void setFilePointer ( int64_t i_offset, seek_mode mode = seek_beginning );
121 virtual size_t write ( const void *p_buffer, size_t i_size);
122 virtual uint64_t getFilePointer ( void );
123 virtual void close ( void );
126 /*****************************************************************************
128 *****************************************************************************/
132 EbmlParser( EbmlStream *es, EbmlElement *el_start );
137 EbmlElement *Get( void );
140 int GetLevel( void );
145 EbmlElement *m_el[6];
154 /*****************************************************************************
155 * Some functions to manipulate memory
156 *****************************************************************************/
157 #define GetWLE( p ) __GetWLE( (uint8_t*)p )
158 #define GetDWLE( p ) __GetDWLE( (uint8_t*)p )
159 #define GetFOURCC( p ) __GetFOURCC( (uint8_t*)p )
160 static uint16_t __GetWLE( uint8_t *p )
162 return (uint16_t)p[0] | ( ((uint16_t)p[1]) << 8 );
164 static uint32_t __GetDWLE( uint8_t *p )
166 return (uint32_t)p[0] | ( ((uint32_t)p[1]) << 8 ) |
167 ( ((uint32_t)p[2]) << 16 ) | ( ((uint32_t)p[3]) << 24 );
169 static vlc_fourcc_t __GetFOURCC( uint8_t *p )
171 return VLC_FOURCC( p[0], p[1], p[2], p[3] );
174 /*****************************************************************************
175 * definitions of structures and functions used by this plugins
176 *****************************************************************************/
180 vlc_bool_t b_default;
181 vlc_bool_t b_enabled;
185 uint8_t *p_extra_data;
190 vlc_fourcc_t i_codec;
192 uint64_t i_default_duration;
193 float f_timecodescale;
198 int i_display_height;
207 es_descriptor_t *p_es;
212 /* data to be send first */
214 uint8_t *p_data_init;
216 /* hack : it's for seek */
217 vlc_bool_t b_search_keyframe;
221 char *psz_codec_name;
222 char *psz_codec_settings;
223 char *psz_codec_info_url;
224 char *psz_codec_download_url;
241 vlc_stream_io_callback *in;
246 uint64_t i_timescale;
248 /* duration of the segment */
256 int64_t i_cues_position;
257 int64_t i_chapters_position;
258 int64_t i_tags_position;
272 char *psz_muxing_application;
273 char *psz_writing_application;
274 char *psz_segment_filename;
279 #define MKVD_TIMECODESCALE 1000000
281 static void IndexAppendCluster ( input_thread_t *p_input, KaxCluster *cluster );
282 static char *UTF8ToStr ( const UTFstring &u );
283 static void LoadCues ( input_thread_t *);
284 static void InformationsCreate ( input_thread_t *p_input );
286 /*****************************************************************************
287 * Activate: initializes matroska demux structures
288 *****************************************************************************/
289 static int Activate( vlc_object_t * p_this )
291 input_thread_t *p_input = (input_thread_t *)p_this;
296 vlc_bool_t b_audio_selected;
297 int i_spu_channel, i_audio_channel;
299 EbmlElement *el = NULL, *el1 = NULL, *el2 = NULL, *el3 = NULL, *el4 = NULL;
302 /* Initialize access plug-in structures. */
303 if( p_input->i_mtu == 0 )
306 p_input->i_bufsize = INPUT_DEFAULT_BUFSIZE;
309 /* Set the demux function */
310 p_input->pf_demux = Demux;
312 /* peek the begining */
313 if( input_Peek( p_input, &p_peek, 4 ) < 4 )
315 msg_Warn( p_input, "cannot peek" );
319 /* is a valid file */
320 if( p_peek[0] != 0x1a || p_peek[1] != 0x45 || p_peek[2] != 0xdf || p_peek[3] != 0xa3 )
322 msg_Warn( p_input, "matroska module discarded "
323 "(invalid header 0x%.2x%.2x%.2x%.2x)",
324 p_peek[0], p_peek[1], p_peek[2], p_peek[3] );
328 p_input->p_demux_data = p_sys = (demux_sys_t*)malloc( sizeof( demux_sys_t ) );
329 memset( p_sys, 0, sizeof( demux_sys_t ) );
331 p_sys->in = new vlc_stream_io_callback( p_input );
332 p_sys->es = new EbmlStream( *p_sys->in );
333 p_sys->f_duration = -1;
334 p_sys->i_timescale = MKVD_TIMECODESCALE;
336 p_sys->track = (mkv_track_t*)malloc( sizeof( mkv_track_t ) );
338 p_sys->i_cues_position = -1;
339 p_sys->i_chapters_position = -1;
340 p_sys->i_tags_position = -1;
342 p_sys->b_cues = VLC_FALSE;
344 p_sys->i_index_max = 1024;
345 p_sys->index = (mkv_index_t*)malloc( sizeof( mkv_index_t ) * p_sys->i_index_max );
347 p_sys->psz_muxing_application = NULL;
348 p_sys->psz_writing_application = NULL;
349 p_sys->psz_segment_filename = NULL;
350 p_sys->psz_title = NULL;
351 p_sys->psz_date_utc = NULL;;
353 if( p_sys->es == NULL )
355 msg_Err( p_input, "failed to create EbmlStream" );
360 /* Find the EbmlHead element */
361 el = p_sys->es->FindNextID(EbmlHead::ClassInfos, 0xFFFFFFFFL);
364 msg_Err( p_input, "cannot find EbmlHead" );
367 msg_Dbg( p_input, "EbmlHead" );
369 el->SkipData( *p_sys->es, el->Generic().Context );
373 el = p_sys->es->FindNextID( KaxSegment::ClassInfos, 0xFFFFFFFFL);
376 msg_Err( p_input, "cannot find KaxSegment" );
379 msg_Dbg( p_input, "+ Segment" );
380 p_sys->segment = (KaxSegment*)el;
381 p_sys->cluster = NULL;
383 p_sys->ep = new EbmlParser( p_sys->es, el );
385 while( ( el1 = p_sys->ep->Get() ) != NULL )
387 if( EbmlId( *el1 ) == KaxInfo::ClassInfos.GlobalId )
389 msg_Dbg( p_input, "| + Informations" );
392 while( ( el2 = p_sys->ep->Get() ) != NULL )
394 if( EbmlId( *el2 ) == KaxTimecodeScale::ClassInfos.GlobalId )
396 KaxTimecodeScale &tcs = *(KaxTimecodeScale*)el2;
398 tcs.ReadData( p_sys->es->I_O() );
399 p_sys->i_timescale = uint64(tcs);
401 msg_Dbg( p_input, "| | + TimecodeScale=%lld", p_sys->i_timescale );
403 else if( EbmlId( *el2 ) == KaxDuration::ClassInfos.GlobalId )
405 KaxDuration &dur = *(KaxDuration*)el2;
407 dur.ReadData( p_sys->es->I_O() );
408 p_sys->f_duration = float(dur);
410 msg_Dbg( p_input, "| | + Duration=%f", p_sys->f_duration );
412 else if( EbmlId( *el2 ) == KaxMuxingApp::ClassInfos.GlobalId )
414 KaxMuxingApp &mapp = *(KaxMuxingApp*)el2;
416 mapp.ReadData( p_sys->es->I_O() );
418 p_sys->psz_muxing_application = UTF8ToStr( UTFstring( mapp ) );
420 msg_Dbg( p_input, "| | + Muxing Application=%s", p_sys->psz_muxing_application );
422 else if( EbmlId( *el2 ) == KaxWritingApp::ClassInfos.GlobalId )
424 KaxWritingApp &wapp = *(KaxWritingApp*)el2;
426 wapp.ReadData( p_sys->es->I_O() );
428 p_sys->psz_writing_application = UTF8ToStr( UTFstring( wapp ) );
430 msg_Dbg( p_input, "| | + Wrinting Application=%s", p_sys->psz_writing_application );
432 else if( EbmlId( *el2 ) == KaxSegmentFilename::ClassInfos.GlobalId )
434 KaxSegmentFilename &sfn = *(KaxSegmentFilename*)el2;
436 sfn.ReadData( p_sys->es->I_O() );
438 p_sys->psz_segment_filename = UTF8ToStr( UTFstring( sfn ) );
440 msg_Dbg( p_input, "| | + Segment Filename=%s", p_sys->psz_segment_filename );
442 else if( EbmlId( *el2 ) == KaxTitle::ClassInfos.GlobalId )
444 KaxTitle &title = *(KaxTitle*)el2;
446 title.ReadData( p_sys->es->I_O() );
448 p_sys->psz_title = UTF8ToStr( UTFstring( title ) );
450 msg_Dbg( p_input, "| | + Title=%s", p_sys->psz_title );
453 else if( EbmlId( *el2 ) == KaxDateUTC::ClassInfos.GlobalId )
455 KaxDateUTC &date = *(KaxDateUTC*)el2;
460 date.ReadData( p_sys->es->I_O() );
462 i_date = date.GetEpochDate();
463 memset( buffer, 0, 256 );
464 if( gmtime_r( &i_date, &tmres ) &&
465 asctime_r( &tmres, buffer ) )
467 buffer[strlen( buffer)-1]= '\0';
468 p_sys->psz_date_utc = strdup( buffer );
469 msg_Dbg( p_input, "| | + Date=%s", p_sys->psz_date_utc );
475 msg_Dbg( p_input, "| | + Unknown (%s)", typeid(*el2).name() );
480 else if( EbmlId( *el1 ) == KaxTracks::ClassInfos.GlobalId )
482 msg_Dbg( p_input, "| + Tracks" );
485 while( ( el2 = p_sys->ep->Get() ) != NULL )
487 if( EbmlId( *el2 ) == KaxTrackEntry::ClassInfos.GlobalId )
489 msg_Dbg( p_input, "| | + Track Entry" );
492 p_sys->track = (mkv_track_t*)realloc( p_sys->track, sizeof( mkv_track_t ) * (p_sys->i_track + 1 ) );
493 #define tk p_sys->track[p_sys->i_track - 1]
494 memset( &tk, 0, sizeof( mkv_track_t ) );
495 tk.i_cat = UNKNOWN_ES;
496 tk.b_default = VLC_TRUE;
497 tk.b_enabled = VLC_TRUE;
498 tk.i_number = p_sys->i_track - 1;
500 tk.p_extra_data = NULL;
503 tk.psz_language = NULL;
504 tk.i_default_duration = 0;
505 tk.f_timecodescale = 1.0;
507 tk.b_inited = VLC_FALSE;
509 tk.p_data_init = NULL;
512 tk.psz_codec_name = NULL;
513 tk.psz_codec_settings = NULL;
514 tk.psz_codec_info_url = NULL;
515 tk.psz_codec_download_url = NULL;
519 while( ( el3 = p_sys->ep->Get() ) != NULL )
521 if( EbmlId( *el3 ) == KaxTrackNumber::ClassInfos.GlobalId )
523 KaxTrackNumber &tnum = *(KaxTrackNumber*)el3;
524 tnum.ReadData( p_sys->es->I_O() );
526 tk.i_number = uint32( tnum );
527 msg_Dbg( p_input, "| | | + Track Number=%u", uint32( tnum ) );
529 else if( EbmlId( *el3 ) == KaxTrackUID::ClassInfos.GlobalId )
531 KaxTrackUID &tuid = *(KaxTrackUID*)el3;
532 tuid.ReadData( p_sys->es->I_O() );
534 msg_Dbg( p_input, "| | | + Track UID=%u", uint32( tuid ) );
536 else if( EbmlId( *el3 ) == KaxTrackType::ClassInfos.GlobalId )
539 KaxTrackType &ttype = *(KaxTrackType*)el3;
540 ttype.ReadData( p_sys->es->I_O() );
541 switch( uint8(ttype) )
552 psz_type = "subtitle";
556 psz_type = "unknown";
557 tk.i_cat = UNKNOWN_ES;
561 msg_Dbg( p_input, "| | | + Track Type=%s", psz_type );
563 else if( EbmlId( *el3 ) == KaxTrackFlagEnabled::ClassInfos.GlobalId )
565 KaxTrackFlagEnabled &fenb = *(KaxTrackFlagEnabled*)el3;
566 fenb.ReadData( p_sys->es->I_O() );
568 tk.b_enabled = uint32( fenb );
569 msg_Dbg( p_input, "| | | + Track Enabled=%u", uint32( fenb ) );
571 else if( EbmlId( *el3 ) == KaxTrackFlagDefault::ClassInfos.GlobalId )
573 KaxTrackFlagDefault &fdef = *(KaxTrackFlagDefault*)el3;
574 fdef.ReadData( p_sys->es->I_O() );
576 tk.b_default = uint32( fdef );
577 msg_Dbg( p_input, "| | | + Track Default=%u", uint32( fdef ) );
579 else if( EbmlId( *el3 ) == KaxTrackFlagLacing::ClassInfos.GlobalId )
581 KaxTrackFlagLacing &lac = *(KaxTrackFlagLacing*)el3;
582 lac.ReadData( p_sys->es->I_O() );
584 msg_Dbg( p_input, "| | | + Track Lacing=%d", uint32( lac ) );
586 else if( EbmlId( *el3 ) == KaxTrackMinCache::ClassInfos.GlobalId )
588 KaxTrackMinCache &cmin = *(KaxTrackMinCache*)el3;
589 cmin.ReadData( p_sys->es->I_O() );
591 msg_Dbg( p_input, "| | | + Track MinCache=%d", uint32( cmin ) );
593 else if( EbmlId( *el3 ) == KaxTrackMaxCache::ClassInfos.GlobalId )
595 KaxTrackMaxCache &cmax = *(KaxTrackMaxCache*)el3;
596 cmax.ReadData( p_sys->es->I_O() );
598 msg_Dbg( p_input, "| | | + Track MaxCache=%d", uint32( cmax ) );
600 else if( EbmlId( *el3 ) == KaxTrackDefaultDuration::ClassInfos.GlobalId )
602 KaxTrackDefaultDuration &defd = *(KaxTrackDefaultDuration*)el3;
603 defd.ReadData( p_sys->es->I_O() );
605 tk.i_default_duration = uint64(defd);
606 msg_Dbg( p_input, "| | | + Track Default Duration=%lld", uint64(defd) );
608 else if( EbmlId( *el3 ) == KaxTrackTimecodeScale::ClassInfos.GlobalId )
610 KaxTrackTimecodeScale &ttcs = *(KaxTrackTimecodeScale*)el3;
611 ttcs.ReadData( p_sys->es->I_O() );
613 tk.f_timecodescale = float( ttcs );
614 msg_Dbg( p_input, "| | | + Track TimeCodeScale=%f", tk.f_timecodescale );
616 else if( EbmlId( *el3 ) == KaxTrackName::ClassInfos.GlobalId )
618 KaxTrackName &tname = *(KaxTrackName*)el3;
619 tname.ReadData( p_sys->es->I_O() );
621 tk.psz_name = UTF8ToStr( UTFstring( tname ) );
622 msg_Dbg( p_input, "| | | + Track Name=%s", tk.psz_name );
624 else if( EbmlId( *el3 ) == KaxTrackLanguage::ClassInfos.GlobalId )
626 KaxTrackLanguage &lang = *(KaxTrackLanguage*)el3;
628 lang.ReadData( p_sys->es->I_O() );
630 tk.psz_language = strdup( string( lang ).c_str() );
631 msg_Dbg( p_input, "| | | + Track Language=`%s'", string( lang ).c_str() );
633 else if( EbmlId( *el3 ) == KaxCodecID::ClassInfos.GlobalId )
635 KaxCodecID &codecid = *(KaxCodecID*)el3;
636 codecid.ReadData( p_sys->es->I_O() );
638 tk.psz_codec = strdup( string( codecid ).c_str() );
639 msg_Dbg( p_input, "| | | + Track CodecId=%s", string( codecid ).c_str() );
641 else if( EbmlId( *el3 ) == KaxCodecPrivate::ClassInfos.GlobalId )
643 KaxCodecPrivate &cpriv = *(KaxCodecPrivate*)el3;
644 cpriv.ReadData( p_sys->es->I_O() );
646 tk.i_extra_data = cpriv.GetSize();
647 if( tk.i_extra_data > 0 )
649 tk.p_extra_data = (uint8_t*)malloc( tk.i_extra_data );
650 memcpy( tk.p_extra_data, cpriv.GetBuffer(), tk.i_extra_data );
652 msg_Dbg( p_input, "| | | + Track CodecPrivate size=%lld", cpriv.GetSize() );
654 else if( EbmlId( *el3 ) == KaxCodecName::ClassInfos.GlobalId )
656 KaxCodecName &cname = *(KaxCodecName*)el3;
657 cname.ReadData( p_sys->es->I_O() );
659 tk.psz_codec_name = UTF8ToStr( UTFstring( cname ) );
660 msg_Dbg( p_input, "| | | + Track Codec Name=%s", tk.psz_codec_name );
662 else if( EbmlId( *el3 ) == KaxCodecSettings::ClassInfos.GlobalId )
664 KaxCodecSettings &cset = *(KaxCodecSettings*)el3;
665 cset.ReadData( p_sys->es->I_O() );
667 tk.psz_codec_settings = UTF8ToStr( UTFstring( cset ) );
668 msg_Dbg( p_input, "| | | + Track Codec Settings=%s", tk.psz_codec_settings );
670 else if( EbmlId( *el3 ) == KaxCodecInfoURL::ClassInfos.GlobalId )
672 KaxCodecInfoURL &ciurl = *(KaxCodecInfoURL*)el3;
673 ciurl.ReadData( p_sys->es->I_O() );
675 tk.psz_codec_info_url = strdup( string( ciurl ).c_str() );
676 msg_Dbg( p_input, "| | | + Track Codec Info URL=%s", tk.psz_codec_info_url );
678 else if( EbmlId( *el3 ) == KaxCodecDownloadURL::ClassInfos.GlobalId )
680 KaxCodecDownloadURL &cdurl = *(KaxCodecDownloadURL*)el3;
681 cdurl.ReadData( p_sys->es->I_O() );
683 tk.psz_codec_download_url = strdup( string( cdurl ).c_str() );
684 msg_Dbg( p_input, "| | | + Track Codec Info URL=%s", tk.psz_codec_download_url );
686 else if( EbmlId( *el3 ) == KaxCodecDecodeAll::ClassInfos.GlobalId )
688 KaxCodecDecodeAll &cdall = *(KaxCodecDecodeAll*)el3;
689 cdall.ReadData( p_sys->es->I_O() );
691 msg_Dbg( p_input, "| | | + Track Codec Decode All=%u <== UNUSED", uint8( cdall ) );
693 else if( EbmlId( *el3 ) == KaxTrackOverlay::ClassInfos.GlobalId )
695 KaxTrackOverlay &tovr = *(KaxTrackOverlay*)el3;
696 tovr.ReadData( p_sys->es->I_O() );
698 msg_Dbg( p_input, "| | | + Track Overlay=%u <== UNUSED", uint32( tovr ) );
700 else if( EbmlId( *el3 ) == KaxTrackVideo::ClassInfos.GlobalId )
702 msg_Dbg( p_input, "| | | + Track Video" );
705 tk.i_display_width = 0;
706 tk.i_display_height = 0;
711 while( ( el4 = p_sys->ep->Get() ) != NULL )
713 if( EbmlId( *el4 ) == KaxVideoFlagInterlaced::ClassInfos.GlobalId )
715 KaxVideoFlagInterlaced &fint = *(KaxVideoFlagInterlaced*)el4;
716 fint.ReadData( p_sys->es->I_O() );
718 msg_Dbg( p_input, "| | | | + Track Video Interlaced=%u", uint8( fint ) );
720 else if( EbmlId( *el4 ) == KaxVideoStereoMode::ClassInfos.GlobalId )
722 KaxVideoStereoMode &stereo = *(KaxVideoStereoMode*)el4;
723 stereo.ReadData( p_sys->es->I_O() );
725 msg_Dbg( p_input, "| | | | + Track Video Stereo Mode=%u", uint8( stereo ) );
727 else if( EbmlId( *el4 ) == KaxVideoPixelWidth::ClassInfos.GlobalId )
729 KaxVideoPixelWidth &vwidth = *(KaxVideoPixelWidth*)el4;
730 vwidth.ReadData( p_sys->es->I_O() );
732 tk.i_width = uint16( vwidth );
733 msg_Dbg( p_input, "| | | | + width=%d", uint16( vwidth ) );
735 else if( EbmlId( *el4 ) == KaxVideoPixelHeight::ClassInfos.GlobalId )
737 KaxVideoPixelWidth &vheight = *(KaxVideoPixelWidth*)el4;
738 vheight.ReadData( p_sys->es->I_O() );
740 tk.i_height = uint16( vheight );
741 msg_Dbg( p_input, "| | | | + height=%d", uint16( vheight ) );
743 else if( EbmlId( *el4 ) == KaxVideoDisplayWidth::ClassInfos.GlobalId )
745 KaxVideoDisplayWidth &vwidth = *(KaxVideoDisplayWidth*)el4;
746 vwidth.ReadData( p_sys->es->I_O() );
748 tk.i_display_width = uint16( vwidth );
749 msg_Dbg( p_input, "| | | | + display width=%d", uint16( vwidth ) );
751 else if( EbmlId( *el4 ) == KaxVideoDisplayHeight::ClassInfos.GlobalId )
753 KaxVideoDisplayWidth &vheight = *(KaxVideoDisplayWidth*)el4;
754 vheight.ReadData( p_sys->es->I_O() );
756 tk.i_display_height = uint16( vheight );
757 msg_Dbg( p_input, "| | | | + display height=%d", uint16( vheight ) );
759 else if( EbmlId( *el4 ) == KaxVideoFrameRate::ClassInfos.GlobalId )
761 KaxVideoFrameRate &vfps = *(KaxVideoFrameRate*)el4;
762 vfps.ReadData( p_sys->es->I_O() );
764 tk.f_fps = float( vfps );
765 msg_Dbg( p_input, " | | | + fps=%f", float( vfps ) );
767 else if( EbmlId( *el4 ) == KaxVideoDisplayUnit::ClassInfos.GlobalId )
769 KaxVideoDisplayUnit &vdmode = *(KaxVideoDisplayUnit*)el4;
770 vdmode.ReadData( p_sys->es->I_O() );
772 msg_Dbg( p_input, "| | | | + Track Video Display Unit=%s",
773 uint8( vdmode ) == 0 ? "pixels" : ( uint8( vdmode ) == 1 ? "centimeters": "inches" ) );
775 else if( EbmlId( *el4 ) == KaxVideoAspectRatio::ClassInfos.GlobalId )
777 KaxVideoAspectRatio &ratio = *(KaxVideoAspectRatio*)el4;
778 ratio.ReadData( p_sys->es->I_O() );
780 msg_Dbg( p_input, " | | | + Track Video Aspect Ratio Type=%u", uint8( ratio ) );
782 else if( EbmlId( *el4 ) == KaxVideoGamma::ClassInfos.GlobalId )
784 KaxVideoGamma &gamma = *(KaxVideoGamma*)el4;
785 gamma.ReadData( p_sys->es->I_O() );
787 msg_Dbg( p_input, " | | | + fps=%f", float( gamma ) );
791 msg_Dbg( p_input, "| | | | + Unknown (%s)", typeid(*el4).name() );
796 else if( EbmlId( *el3 ) == KaxTrackAudio::ClassInfos.GlobalId )
798 msg_Dbg( p_input, "| | | + Track Audio" );
801 tk.i_bitspersample = 0;
805 while( ( el4 = p_sys->ep->Get() ) != NULL )
807 if( EbmlId( *el4 ) == KaxAudioSamplingFreq::ClassInfos.GlobalId )
809 KaxAudioSamplingFreq &afreq = *(KaxAudioSamplingFreq*)el4;
810 afreq.ReadData( p_sys->es->I_O() );
812 tk.i_samplerate = (int)float( afreq );
813 msg_Dbg( p_input, "| | | | + afreq=%d", tk.i_samplerate );
815 else if( EbmlId( *el4 ) == KaxAudioChannels::ClassInfos.GlobalId )
817 KaxAudioChannels &achan = *(KaxAudioChannels*)el4;
818 achan.ReadData( p_sys->es->I_O() );
820 tk.i_channels = uint8( achan );
821 msg_Dbg( p_input, "| | | | + achan=%u", uint8( achan ) );
823 else if( EbmlId( *el4 ) == KaxAudioBitDepth::ClassInfos.GlobalId )
825 KaxAudioBitDepth &abits = *(KaxAudioBitDepth*)el4;
826 abits.ReadData( p_sys->es->I_O() );
828 tk.i_bitspersample = uint8( abits );
829 msg_Dbg( p_input, "| | | | + abits=%u", uint8( abits ) );
833 msg_Dbg( p_input, "| | | | + Unknown (%s)", typeid(*el4).name() );
840 msg_Dbg( p_input, "| | | + Unknown (%s)", typeid(*el3).name() );
847 msg_Dbg( p_input, "| | + Unknown (%s)", typeid(*el2).name() );
853 else if( EbmlId( *el1 ) == KaxSeekHead::ClassInfos.GlobalId )
855 msg_Dbg( p_input, "| + Seek head" );
857 while( ( el = p_sys->ep->Get() ) != NULL )
859 if( EbmlId( *el ) == KaxSeek::ClassInfos.GlobalId )
861 EbmlId id = EbmlVoid::ClassInfos.GlobalId;
864 //msg_Dbg( p_input, "| | + Seek" );
866 while( ( el = p_sys->ep->Get() ) != NULL )
868 if( EbmlId( *el ) == KaxSeekID::ClassInfos.GlobalId )
870 KaxSeekID &sid = *(KaxSeekID*)el;
872 sid.ReadData( p_sys->es->I_O() );
874 id = EbmlId( sid.GetBuffer(), sid.GetSize() );
876 else if( EbmlId( *el ) == KaxSeekPosition::ClassInfos.GlobalId )
878 KaxSeekPosition &spos = *(KaxSeekPosition*)el;
880 spos.ReadData( p_sys->es->I_O() );
882 i_pos = uint64( spos );
886 msg_Dbg( p_input, "| | | + Unknown (%s)", typeid(*el).name() );
893 if( id == KaxCues::ClassInfos.GlobalId )
895 msg_Dbg( p_input, "| | | = cues at %lld", i_pos );
896 p_sys->i_cues_position = p_sys->segment->GetGlobalPosition( i_pos );
898 else if( id == KaxChapters::ClassInfos.GlobalId )
900 msg_Dbg( p_input, "| | | = chapters at %lld", i_pos );
901 p_sys->i_chapters_position = p_sys->segment->GetGlobalPosition( i_pos );
903 else if( id == KaxTags::ClassInfos.GlobalId )
905 msg_Dbg( p_input, "| | | = tags at %lld", i_pos );
906 p_sys->i_tags_position = p_sys->segment->GetGlobalPosition( i_pos );
913 msg_Dbg( p_input, "| | + Unknown (%s)", typeid(*el).name() );
918 else if( EbmlId( *el1 ) == KaxCues::ClassInfos.GlobalId )
920 msg_Dbg( p_input, "| + Cues" );
922 else if( EbmlId( *el1 ) == KaxCluster::ClassInfos.GlobalId )
924 msg_Dbg( p_input, "| + Cluster" );
926 p_sys->cluster = (KaxCluster*)el1;
929 /* stop parsing the stream */
932 else if( EbmlId( *el1 ) == KaxAttachements::ClassInfos.GlobalId )
934 msg_Dbg( p_input, "| + Attachements FIXME TODO (but probably never supported)" );
936 else if( EbmlId( *el1 ) == KaxChapters::ClassInfos.GlobalId )
938 msg_Dbg( p_input, "| + Chapters FIXME TODO" );
940 else if( EbmlId( *el1 ) == KaxTag::ClassInfos.GlobalId )
942 msg_Dbg( p_input, "| + Tags FIXME TODO" );
946 msg_Dbg( p_input, "| + Unknown (%s)", typeid(*el1).name() );
950 if( p_sys->cluster == NULL )
952 msg_Err( p_input, "cannot find any cluster, damaged file ?" );
956 if( p_sys->i_chapters_position >= 0 )
958 msg_Warn( p_input, "chapters unsupported" );
961 /* *** Load the cue if found *** */
962 if( p_sys->i_cues_position >= 0 && p_input->stream.b_seekable )
967 if( !p_sys->b_cues || p_sys->i_index <= 0 )
969 msg_Warn( p_input, "no cues/empty cues found -> seek won't be precise" );
971 IndexAppendCluster( p_input, p_sys->cluster );
973 p_sys->b_cues = VLC_FALSE;
976 /* Create one program */
977 vlc_mutex_lock( &p_input->stream.stream_lock );
978 if( input_InitStream( p_input, 0 ) == -1)
980 vlc_mutex_unlock( &p_input->stream.stream_lock );
981 msg_Err( p_input, "cannot init stream" );
984 if( input_AddProgram( p_input, 0, 0) == NULL )
986 vlc_mutex_unlock( &p_input->stream.stream_lock );
987 msg_Err( p_input, "cannot add program" );
990 p_input->stream.p_selected_program = p_input->stream.pp_programs[0];
991 if( p_sys->f_duration > 1001.0 )
993 mtime_t i_duration = (mtime_t)( p_sys->f_duration / 1000.0 );
994 p_input->stream.i_mux_rate = p_input->stream.p_selected_area->i_size / 50 / i_duration;
998 p_input->stream.i_mux_rate = 0;
1000 vlc_mutex_unlock( &p_input->stream.stream_lock );
1003 msg_Dbg( p_input, "found %d es", p_sys->i_track );
1004 for( i_track = 0; i_track < p_sys->i_track; i_track++ )
1006 #define tk p_sys->track[i_track]
1007 if( tk.i_cat == UNKNOWN_ES )
1009 msg_Warn( p_input, "invalid track[%d, n=%d]", i_track, tk.i_number );
1013 tk.p_es = input_AddES( p_input,
1014 p_input->stream.p_selected_program,
1017 tk.psz_language, 0 );
1018 if( !strcmp( tk.psz_codec, "V_MS/VFW/FOURCC" ) )
1020 if( tk.i_extra_data < (int)sizeof( BITMAPINFOHEADER ) )
1022 msg_Err( p_input, "missing/invalid BITMAPINFOHEADER" );
1023 tk.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
1027 BITMAPINFOHEADER *p_bih = (BITMAPINFOHEADER*)tk.p_extra_data;
1029 p_bih->biSize = GetDWLE( &p_bih->biSize );
1030 p_bih->biWidth = GetDWLE( &p_bih->biWidth );
1031 p_bih->biHeight = GetDWLE( &p_bih->biHeight );
1032 p_bih->biPlanes = GetWLE( &p_bih->biPlanes );
1033 p_bih->biBitCount = GetWLE( &p_bih->biBitCount );
1034 p_bih->biCompression = GetFOURCC( &p_bih->biCompression );
1035 p_bih->biSizeImage = GetDWLE( &p_bih->biSizeImage );
1036 p_bih->biXPelsPerMeter = GetDWLE( &p_bih->biXPelsPerMeter );
1037 p_bih->biYPelsPerMeter = GetDWLE( &p_bih->biYPelsPerMeter );
1038 p_bih->biClrUsed = GetDWLE( &p_bih->biClrUsed );
1039 p_bih->biClrImportant = GetDWLE( &p_bih->biClrImportant );
1042 tk.i_codec = p_bih->biCompression;
1043 tk.p_es->p_bitmapinfoheader = p_bih;
1046 else if( !strcmp( tk.psz_codec, "V_MPEG1" ) ||
1047 !strcmp( tk.psz_codec, "V_MPEG2" ) )
1049 tk.i_codec = VLC_FOURCC( 'm', 'p', 'g', 'v' );
1051 else if( !strncmp( tk.psz_codec, "V_MPEG4", 7 ) )
1053 BITMAPINFOHEADER *p_bih;
1055 tk.i_extra_data = sizeof( BITMAPINFOHEADER );
1056 tk.p_extra_data = (uint8_t*)malloc( tk.i_extra_data );
1058 p_bih = (BITMAPINFOHEADER*)tk.p_extra_data;
1059 memset( p_bih, 0, sizeof( BITMAPINFOHEADER ) );
1060 p_bih->biSize = sizeof( BITMAPINFOHEADER );
1061 p_bih->biWidth = tk.i_width;
1062 p_bih->biHeight= tk.i_height;
1064 if( !strcmp( tk.psz_codec, "V_MPEG4/MS/V3" ) )
1066 tk.i_codec = VLC_FOURCC( 'D', 'I', 'V', '3' );
1070 tk.i_codec = VLC_FOURCC( 'm', 'p', '4', 'v' );
1073 else if( !strcmp( tk.psz_codec, "A_MS/ACM" ) )
1075 if( tk.i_extra_data < (int)sizeof( WAVEFORMATEX ) )
1077 msg_Err( p_input, "missing/invalid WAVEFORMATEX" );
1078 tk.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
1082 WAVEFORMATEX *p_wf = (WAVEFORMATEX*)tk.p_extra_data;
1084 p_wf->wFormatTag = GetWLE( &p_wf->wFormatTag );
1085 p_wf->nChannels = GetWLE( &p_wf->nChannels );
1086 p_wf->nSamplesPerSec = GetDWLE( &p_wf->nSamplesPerSec );
1087 p_wf->nAvgBytesPerSec = GetDWLE( &p_wf->nAvgBytesPerSec );
1088 p_wf->nBlockAlign = GetWLE( &p_wf->nBlockAlign );
1089 p_wf->wBitsPerSample = GetWLE( &p_wf->wBitsPerSample );
1090 p_wf->cbSize = GetWLE( &p_wf->cbSize );
1092 switch( p_wf->wFormatTag )
1094 case WAVE_FORMAT_PCM:
1095 tk.i_codec = VLC_FOURCC( 'a', 'r', 'a', 'w' );
1097 case WAVE_FORMAT_ADPCM:
1098 tk.i_codec = VLC_FOURCC( 'm', 's', 0x00, 0x02 );
1100 case WAVE_FORMAT_ALAW:
1101 tk.i_codec = VLC_FOURCC( 'a', 'l', 'a', 'w' );
1103 case WAVE_FORMAT_MULAW:
1104 tk.i_codec = VLC_FOURCC( 'm', 'l', 'a', 'w' );
1106 case WAVE_FORMAT_IMA_ADPCM:
1107 tk.i_codec = VLC_FOURCC( 'm', 's', 0x00, 0x11 );
1109 case WAVE_FORMAT_MPEG:
1110 case WAVE_FORMAT_MPEGLAYER3:
1111 tk.i_codec = VLC_FOURCC( 'm', 'p', 'g', 'a' );
1113 case WAVE_FORMAT_A52:
1114 tk.i_codec = VLC_FOURCC( 'a', '5', '2', ' ' );
1116 case WAVE_FORMAT_WMA1:
1117 tk.i_codec = VLC_FOURCC( 'w', 'm', 'a', '1' );
1119 case WAVE_FORMAT_WMA2:
1120 tk.i_codec = VLC_FOURCC( 'w', 'm', 'a', '2' );
1122 case WAVE_FORMAT_WMA3:
1123 tk.i_codec = VLC_FOURCC( 'w', 'm', 'a', '3' );
1126 msg_Err( p_input, "unknown wFormatTag=0x%x", p_wf->wFormatTag );
1127 tk.i_codec = VLC_FOURCC( 'm', 's', p_wf->wFormatTag >> 8, p_wf->wFormatTag&0xff );
1130 tk.p_es->p_waveformatex = p_wf;
1133 else if( !strcmp( tk.psz_codec, "A_MPEG/L3" ) ||
1134 !strcmp( tk.psz_codec, "A_MPEG/L2" ) ||
1135 !strcmp( tk.psz_codec, "A_MPEG/L1" ) )
1137 tk.i_codec = VLC_FOURCC( 'm', 'p', 'g', 'a' );
1139 else if( !strcmp( tk.psz_codec, "A_AC3" ) )
1141 tk.i_codec = VLC_FOURCC( 'a', '5', '2', ' ' );
1143 else if( !strcmp( tk.psz_codec, "A_DTS" ) )
1145 tk.i_codec = VLC_FOURCC( 'd', 't', 's', ' ' );
1147 else if( !strcmp( tk.psz_codec, "A_VORBIS" ) )
1149 tk.i_codec = VLC_FOURCC( 'v', 'o', 'r', 'b' );
1150 tk.i_data_init = tk.i_extra_data;
1151 tk.p_data_init = tk.p_extra_data;
1153 else if( !strncmp( tk.psz_codec, "A_AAC/MPEG2/", strlen( "A_AAC/MPEG2/" ) ) ||
1154 !strncmp( tk.psz_codec, "A_AAC/MPEG4/", strlen( "A_AAC/MPEG4/" ) ) )
1156 int i_profile, i_srate;
1157 static int i_sample_rates[] =
1159 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
1160 16000, 12000, 11025, 8000, 7350, 0, 0, 0
1164 tk.i_codec = VLC_FOURCC( 'm', 'p', '4', 'a' );
1165 /* create data for faad (MP4DecSpecificDescrTag)*/
1167 if( !strcmp( &tk.psz_codec[12], "MAIN" ) )
1171 else if( !strcmp( &tk.psz_codec[12], "LC" ) )
1175 else if( !strcmp( &tk.psz_codec[12], "SSR" ) )
1184 for( i_srate = 0; i_srate < 13; i_srate++ )
1186 if( i_sample_rates[i_srate] == tk.i_samplerate )
1191 msg_Dbg( p_input, "profile=%d srate=%d", i_profile, i_srate );
1193 tk.i_extra_data = sizeof( WAVEFORMATEX ) + 2;
1194 tk.p_extra_data = (uint8_t*)malloc( tk.i_extra_data );
1195 p_wf = (WAVEFORMATEX*)tk.p_extra_data;
1197 p_wf->wFormatTag = WAVE_FORMAT_UNKNOWN;
1198 p_wf->nChannels = tk.i_channels;
1199 p_wf->nSamplesPerSec = tk.i_samplerate;
1200 p_wf->nAvgBytesPerSec = 0;
1201 p_wf->nBlockAlign = 0;
1202 p_wf->wBitsPerSample = 0;
1205 tk.p_extra_data[sizeof( WAVEFORMATEX )+ 0] = ((i_profile + 1) << 3) | ((i_srate&0xe) >> 1);
1206 tk.p_extra_data[sizeof( WAVEFORMATEX )+ 1] = ((i_srate & 0x1) << 7) | (tk.i_channels << 3);
1208 tk.p_es->p_waveformatex = p_wf;
1210 else if( !strcmp( tk.psz_codec, "A_PCM/INT/BIG" ) ||
1211 !strcmp( tk.psz_codec, "A_PCM/INT/LIT" ) ||
1212 !strcmp( tk.psz_codec, "A_PCM/FLOAT/IEEE" ) )
1216 tk.i_extra_data = sizeof( WAVEFORMATEX );
1217 tk.p_extra_data = (uint8_t*)malloc( tk.i_extra_data );
1219 p_wf = (WAVEFORMATEX*)tk.p_extra_data;
1221 if( !strncmp( &tk.psz_codec[6], "INT", 3 ) )
1223 p_wf->wFormatTag = WAVE_FORMAT_PCM;
1227 p_wf->wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
1229 p_wf->nChannels = tk.i_channels;
1230 p_wf->nSamplesPerSec = tk.i_samplerate;
1231 p_wf->nAvgBytesPerSec = 0;
1232 p_wf->nBlockAlign = ( tk.i_bitspersample + 7 ) / 8 * tk.i_channels;
1233 p_wf->wBitsPerSample = tk.i_bitspersample;
1236 tk.p_es->p_waveformatex = p_wf;
1238 if( !strcmp( tk.psz_codec, "A_PCM/INT/BIG" ) )
1240 tk.i_codec = VLC_FOURCC( 't', 'w', 'o', 's' );
1244 tk.i_codec = VLC_FOURCC( 'a', 'r', 'a', 'w' );
1247 else if( !strcmp( tk.psz_codec, "S_TEXT/UTF8" ) )
1249 tk.i_codec = VLC_FOURCC( 's', 'u', 'b', 't' );
1252 else if( !strcmp( tk.psz_codec, "S_TEXT/SSA" ) )
1254 tk.i_codec = VLC_FOURCC( 's', 'u', 'b', 't' );
1259 msg_Err( p_input, "unknow codec id=`%s'", tk.psz_codec );
1260 tk.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
1263 tk.p_es->i_fourcc = tk.i_codec;
1267 /* select track all video, one audio, no spu TODO : improve */
1268 b_audio_selected = VLC_FALSE;
1269 i_audio_channel = 0;
1271 for( i_track = 0; i_track < p_sys->i_track; i_track++ )
1273 #define tk p_sys->track[i_track]
1277 vlc_mutex_lock( &p_input->stream.stream_lock );
1278 input_SelectES( p_input, tk.p_es );
1279 vlc_mutex_unlock( &p_input->stream.stream_lock );
1283 if( ( !b_audio_selected && config_GetInt( p_input, "audio-channel" ) < 0 ) ||
1284 i_audio_channel == config_GetInt( p_input, "audio-channel" ) )
1286 vlc_mutex_lock( &p_input->stream.stream_lock );
1287 input_SelectES( p_input, tk.p_es );
1288 vlc_mutex_unlock( &p_input->stream.stream_lock );
1290 b_audio_selected = tk.p_es->p_decoder_fifo ? VLC_TRUE : VLC_FALSE;
1295 if( i_spu_channel == config_GetInt( p_input, "spu-channel" ) )
1297 vlc_mutex_lock( &p_input->stream.stream_lock );
1298 input_SelectES( p_input, tk.p_es );
1299 vlc_mutex_unlock( &p_input->stream.stream_lock );
1307 if( !b_audio_selected )
1309 msg_Warn( p_input, "cannot find/select audio track" );
1312 /* add informations */
1313 InformationsCreate( p_input );
1321 return VLC_EGENERIC;
1324 /*****************************************************************************
1325 * Deactivate: frees unused data
1326 *****************************************************************************/
1327 static void Deactivate( vlc_object_t *p_this )
1329 input_thread_t *p_input = (input_thread_t *)p_this;
1330 demux_sys_t *p_sys = p_input->p_demux_data;
1334 for( i_track = 0; i_track < p_sys->i_track; i_track++ )
1336 #define tk p_sys->track[i_track]
1339 free( tk.psz_codec );
1341 if( tk.psz_language )
1343 free( tk.psz_language );
1347 free( p_sys->track );
1349 if( p_sys->psz_writing_application )
1351 free( p_sys->psz_writing_application );
1353 if( p_sys->psz_muxing_application )
1355 free( p_sys->psz_muxing_application );
1358 delete p_sys->segment;
1367 static int BlockGet( input_thread_t *p_input, KaxBlock **pp_block, int64_t *pi_ref1, int64_t *pi_ref2, int64_t *pi_duration )
1369 demux_sys_t *p_sys = p_input->p_demux_data;
1380 if( p_input->b_die )
1382 return VLC_EGENERIC;
1385 el = p_sys->ep->Get();
1386 i_level = p_sys->ep->GetLevel();
1388 if( el == NULL && *pp_block != NULL )
1390 /* update the index */
1391 #define idx p_sys->index[p_sys->i_index - 1]
1392 if( p_sys->i_index > 0 && idx.i_time == -1 )
1394 idx.i_time = (*pp_block)->GlobalTimecode() * (mtime_t) 1000 / p_sys->i_timescale;
1395 idx.b_key = *pi_ref1 == -1 ? VLC_TRUE : VLC_FALSE;
1403 if( p_sys->ep->GetLevel() > 1 )
1408 msg_Warn( p_input, "EOF" );
1409 return VLC_EGENERIC;
1415 if( EbmlId( *el ) == KaxCluster::ClassInfos.GlobalId )
1417 p_sys->cluster = (KaxCluster*)el;
1419 /* add it to the index */
1420 if( p_sys->i_index == 0 ||
1421 ( p_sys->i_index > 0 && p_sys->index[p_sys->i_index - 1].i_position < (int64_t)p_sys->cluster->GetElementPosition() ) )
1423 IndexAppendCluster( p_input, p_sys->cluster );
1428 else if( EbmlId( *el ) == KaxCues::ClassInfos.GlobalId )
1430 msg_Warn( p_input, "find KaxCues FIXME" );
1431 return VLC_EGENERIC;
1435 msg_Dbg( p_input, "unknown (%s)", typeid( el ).name() );
1438 else if( i_level == 2 )
1440 if( EbmlId( *el ) == KaxClusterTimecode::ClassInfos.GlobalId )
1442 KaxClusterTimecode &ctc = *(KaxClusterTimecode*)el;
1444 ctc.ReadData( p_sys->es->I_O() );
1445 p_sys->cluster->InitTimecode( uint64( ctc ), p_sys->i_timescale );
1447 else if( EbmlId( *el ) == KaxBlockGroup::ClassInfos.GlobalId )
1452 else if( i_level == 3 )
1454 if( EbmlId( *el ) == KaxBlock::ClassInfos.GlobalId )
1456 *pp_block = (KaxBlock*)el;
1458 (*pp_block)->ReadData( p_sys->es->I_O() );
1459 (*pp_block)->SetParent( *p_sys->cluster );
1463 else if( EbmlId( *el ) == KaxBlockDuration::ClassInfos.GlobalId )
1465 KaxBlockDuration &dur = *(KaxBlockDuration*)el;
1467 dur.ReadData( p_sys->es->I_O() );
1468 *pi_duration = uint64( dur );
1470 else if( EbmlId( *el ) == KaxReferenceBlock::ClassInfos.GlobalId )
1472 KaxReferenceBlock &ref = *(KaxReferenceBlock*)el;
1474 ref.ReadData( p_sys->es->I_O() );
1475 if( *pi_ref1 == -1 )
1477 *pi_ref1 = int64( ref );
1481 *pi_ref2 = int64( ref );
1487 msg_Err( p_input, "invalid level = %d", i_level );
1488 return VLC_EGENERIC;
1493 static pes_packet_t *MemToPES( input_thread_t *p_input, uint8_t *p_mem, int i_mem )
1495 pes_packet_t *p_pes;
1496 data_packet_t *p_data;
1498 if( ( p_pes = input_NewPES( p_input->p_method_data ) ) == NULL )
1503 p_data = input_NewPacket( p_input->p_method_data, i_mem);
1505 memcpy( p_data->p_payload_start, p_mem, i_mem );
1506 p_data->p_payload_end = p_data->p_payload_start + i_mem;
1508 p_pes->p_first = p_pes->p_last = p_data;
1509 p_pes->i_nb_data = 1;
1510 p_pes->i_pes_size = i_mem;
1515 static void BlockDecode( input_thread_t *p_input, KaxBlock *block, mtime_t i_pts, mtime_t i_duration )
1517 demux_sys_t *p_sys = p_input->p_demux_data;
1522 #define tk p_sys->track[i_track]
1523 for( i_track = 0; i_track < p_sys->i_track; i_track++ )
1525 if( tk.i_number == block->TrackNum() )
1531 if( i_track >= p_sys->i_track )
1533 msg_Err( p_input, "invalid track number=%d", block->TrackNum() );
1537 if( tk.p_es->p_decoder_fifo == NULL )
1539 tk.b_inited = VLC_FALSE;
1543 if( tk.i_cat == AUDIO_ES && p_input->stream.control.b_mute )
1548 /* First send init data */
1549 if( !tk.b_inited && tk.i_data_init > 0 )
1551 pes_packet_t *p_init;
1553 msg_Dbg( p_input, "sending header (%d bytes)", tk.i_data_init );
1555 if( tk.i_codec == VLC_FOURCC( 'v', 'o', 'r', 'b' ) )
1561 /* XXX hack split the 3 headers */
1562 if( tk.p_data_init[0] != 0x02 )
1564 msg_Err( p_input, "invalid vorbis header" );
1567 for( i = 0; i < 2; i++ )
1570 while( i_offset < tk.i_data_init )
1572 i_size[i] += tk.p_data_init[i_offset];
1573 if( tk.p_data_init[i_offset++] != 0xff )
1579 i_size[0] = __MIN( i_size[0], tk.i_data_init - i_offset );
1580 i_size[1] = __MIN( i_size[1], tk.i_data_init - i_offset - i_size[0] );
1581 i_size[2] = tk.i_data_init - i_offset - i_size[0] - i_size[1];
1583 p_init = MemToPES( p_input, &tk.p_data_init[i_offset], i_size[0] );
1586 input_DecodePES( tk.p_es->p_decoder_fifo, p_init );
1588 p_init = MemToPES( p_input, &tk.p_data_init[i_offset+i_size[0]], i_size[1] );
1591 input_DecodePES( tk.p_es->p_decoder_fifo, p_init );
1593 p_init = MemToPES( p_input, &tk.p_data_init[i_offset+i_size[0]+i_size[1]], i_size[2] );
1596 input_DecodePES( tk.p_es->p_decoder_fifo, p_init );
1601 p_init = MemToPES( p_input, tk.p_data_init, tk.i_data_init );
1604 input_DecodePES( tk.p_es->p_decoder_fifo, p_init );
1608 tk.b_inited = VLC_TRUE;
1611 for( i = 0; i < block->NumberFrames(); i++ )
1613 pes_packet_t *p_pes;
1614 DataBuffer &data = block->GetBuffer(i);
1616 p_pes = MemToPES( p_input, data.Buffer(), data.Size() );
1622 p_pes->i_pts = i_pts;
1623 p_pes->i_dts = i_pts;
1625 if( tk.i_cat == SPU_ES )
1627 if( i_duration > 0 )
1629 /* FIXME not sure about that */
1630 p_pes->i_dts += i_duration * 1000;// * (mtime_t) 1000 / p_sys->i_timescale;
1636 if( p_pes->p_first && p_pes->i_pes_size > 0 )
1638 p_pes->p_first->p_payload_end[-1] = '\0';
1642 input_DecodePES( tk.p_es->p_decoder_fifo, p_pes );
1644 /* use time stamp only for first block */
1651 static void Seek( input_thread_t *p_input, mtime_t i_date, int i_percent)
1653 demux_sys_t *p_sys = p_input->p_demux_data;
1656 int64_t i_block_duration;
1657 int64_t i_block_ref1;
1658 int64_t i_block_ref2;
1661 int i_track_skipping;
1664 msg_Dbg( p_input, "seek request to %lld (%d%%)", i_date, i_percent );
1665 if( i_date < 0 && i_percent < 0 )
1671 p_sys->ep = new EbmlParser( p_sys->es, p_sys->segment );
1672 p_sys->cluster = NULL;
1674 /* seek without index or without date */
1675 if( config_GetInt( p_input, "mkv-seek-percent" ) || !p_sys->b_cues || i_date < 0 )
1677 int64_t i_pos = i_percent * p_input->stream.p_selected_area->i_size / 100;
1679 msg_Dbg( p_input, "imprecise way of seeking" );
1680 for( i_index = 0; i_index < p_sys->i_index; i_index++ )
1682 if( p_sys->index[i_index].i_position >= i_pos)
1687 if( i_index == p_sys->i_index )
1692 p_sys->in->setFilePointer( p_sys->index[i_index].i_position, seek_beginning );
1694 if( p_sys->index[i_index].i_position < i_pos )
1698 msg_Warn( p_input, "searching for cluster, could take some time" );
1700 /* search a cluster */
1701 while( ( el = p_sys->ep->Get() ) != NULL )
1703 if( EbmlId( *el ) == KaxCluster::ClassInfos.GlobalId )
1705 KaxCluster *cluster = (KaxCluster*)el;
1707 /* add it to the index */
1708 IndexAppendCluster( p_input, cluster );
1710 if( (int64_t)cluster->GetElementPosition() >= i_pos )
1712 p_sys->cluster = cluster;
1722 for( i_index = 0; i_index < p_sys->i_index; i_index++ )
1724 if( p_sys->index[i_index].i_time >= i_date )
1735 msg_Dbg( p_input, "seek got %lld (%d%%)",
1736 p_sys->index[i_index].i_time, (int)(100 * p_sys->index[i_index].i_position /p_input->stream.p_selected_area->i_size ) );
1738 p_sys->in->setFilePointer( p_sys->index[i_index].i_position, seek_beginning );
1741 /* now parse until key frame */
1742 #define tk p_sys->track[i_track]
1743 i_track_skipping = 0;
1744 for( i_track = 0; i_track < p_sys->i_track; i_track++ )
1746 if( tk.i_cat == VIDEO_ES )
1748 tk.b_search_keyframe = VLC_TRUE;
1753 while( i_track_skipping > 0 )
1755 if( BlockGet( p_input, &block, &i_block_ref1, &i_block_ref2, &i_block_duration ) )
1757 msg_Warn( p_input, "cannot get block EOF?" );
1762 p_sys->i_pts = block->GlobalTimecode() * (mtime_t) 1000 / p_sys->i_timescale;
1764 for( i_track = 0; i_track < p_sys->i_track; i_track++ )
1766 if( tk.i_number == block->TrackNum() )
1772 if( i_track < p_sys->i_track )
1774 if( tk.i_cat == VIDEO_ES && i_block_ref1 == -1 && tk.b_search_keyframe )
1776 tk.b_search_keyframe = VLC_FALSE;
1779 if( tk.i_cat == VIDEO_ES && !tk.b_search_keyframe )
1781 BlockDecode( p_input, block, 0, 0 );
1790 /*****************************************************************************
1791 * Demux: reads and demuxes data packets
1792 *****************************************************************************
1793 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
1794 *****************************************************************************/
1795 static int Demux( input_thread_t * p_input )
1797 demux_sys_t *p_sys = p_input->p_demux_data;
1798 mtime_t i_start_pts;
1799 int i_block_count = 0;
1802 int64_t i_block_duration;
1803 int64_t i_block_ref1;
1804 int64_t i_block_ref2;
1806 if( p_input->stream.p_selected_program->i_synchro_state == SYNCHRO_REINIT )
1808 mtime_t i_duration = (mtime_t)( p_sys->f_duration / 1000 );
1809 mtime_t i_date = -1;
1812 if( i_duration > 0 )
1814 i_date = (mtime_t)1000000 *
1815 (mtime_t)i_duration*
1816 (mtime_t)p_sys->in->getFilePointer() /
1817 (mtime_t)p_input->stream.p_selected_area->i_size;
1819 if( p_input->stream.p_selected_area->i_size > 0 )
1821 i_percent = 100 * p_sys->in->getFilePointer() /
1822 p_input->stream.p_selected_area->i_size;
1825 Seek( p_input, i_date, i_percent);
1834 if( BlockGet( p_input, &block, &i_block_ref1, &i_block_ref2, &i_block_duration ) )
1836 msg_Warn( p_input, "cannot get block EOF?" );
1841 p_sys->i_pts = block->GlobalTimecode() * (mtime_t) 1000 / p_sys->i_timescale;
1843 if( p_sys->i_pts > 0 )
1845 input_ClockManageRef( p_input,
1846 p_input->stream.p_selected_program,
1847 p_sys->i_pts * 9 / 100 );
1850 i_pts = input_ClockGetTS( p_input,
1851 p_input->stream.p_selected_program,
1852 p_sys->i_pts * 9 / 100 );
1856 BlockDecode( p_input, block, i_pts, i_block_duration );
1861 if( i_start_pts == -1 )
1863 i_start_pts = p_sys->i_pts;
1865 else if( p_sys->i_pts > i_start_pts + (mtime_t)100000 || i_block_count > 5 )
1874 /*****************************************************************************
1876 *****************************************************************************/
1877 vlc_stream_io_callback::vlc_stream_io_callback( input_thread_t *p_input_ )
1882 uint32_t vlc_stream_io_callback::read( void *p_buffer, size_t i_size )
1884 data_packet_t *p_data;
1890 if( !i_size || mb_eof )
1897 i_count = input_SplitBuffer(p_input, &p_data, __MIN( i_size, 10240 ) );
1902 memcpy( p_buffer, p_data->p_payload_start, i_count );
1903 input_DeletePacket( p_input->p_method_data, p_data );
1905 (uint8_t*)p_buffer += i_count;
1913 void vlc_stream_io_callback::setFilePointer(int64_t i_offset, seek_mode mode )
1918 i_last = getFilePointer();
1920 vlc_mutex_lock( &p_input->stream.stream_lock );
1923 case seek_beginning:
1927 i_pos = p_input->stream.p_selected_area->i_size - i_offset;
1930 i_pos= i_last + i_offset;
1935 ( i_pos > p_input->stream.p_selected_area->i_size && p_input->stream.p_selected_area->i_size != 0 ) )
1937 msg_Err( p_input, "seeking to wrong place (i_pos=%lld)", i_pos );
1938 vlc_mutex_unlock( &p_input->stream.stream_lock );
1943 vlc_mutex_unlock( &p_input->stream.stream_lock );
1947 if( i_pos == i_last )
1952 msg_Dbg( p_input, "####################seek new=%lld old=%lld", i_pos, getFilePointer() );
1954 if( p_input->stream.b_seekable &&
1955 ( /*p_input->stream.i_method == INPUT_METHOD_FILE ||*/ i_pos < i_last || i_pos - i_last > p_input->i_bufsize / 4 ) )
1957 input_AccessReinit( p_input );
1958 p_input->pf_seek( p_input, i_pos );
1960 else if( i_pos > i_last )
1962 data_packet_t *p_data;
1963 int i_skip = i_pos - i_last;
1967 msg_Warn( p_input, "will skip %d bytes, slow", i_skip );
1974 i_read = input_SplitBuffer( p_input, &p_data,
1975 __MIN( 4096, i_skip ) );
1978 msg_Err( p_input, "seek failed" );
1984 input_DeletePacket( p_input->p_method_data, p_data );
1985 if( i_read == 0 && i_skip > 0 )
1987 msg_Err( p_input, "seek failed" );
1995 msg_Err( p_input, "cannot seek or emulate seek to %lld from %lld", i_pos, i_last );
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=%lld pos=%lld track=%d bnum=%d",
2225 idx.i_time, idx.i_position, idx.i_track, idx.i_block_number );
2228 if( p_sys->i_index >= p_sys->i_index_max )
2230 p_sys->i_index_max += 1024;
2231 p_sys->index = (mkv_index_t*)realloc( p_sys->index, sizeof( mkv_index_t ) * p_sys->i_index_max );
2237 msg_Dbg( p_input, " * Unknown (%s)", typeid(*el).name() );
2243 p_sys->b_cues = VLC_TRUE;
2245 msg_Dbg( p_input, "loading cues done." );
2246 p_sys->in->setFilePointer( i_sav_position, seek_beginning );
2249 static void LoadTags( input_thread_t *p_input )
2251 demux_sys_t *p_sys = p_input->p_demux_data;
2252 int64_t i_sav_position = p_sys->in->getFilePointer();
2254 EbmlElement *el, *tags;
2256 msg_Dbg( p_input, "loading tags" );
2257 p_sys->in->setFilePointer( p_sys->i_tags_position, seek_beginning );
2258 tags = p_sys->es->FindNextID( KaxTags::ClassInfos, 0xFFFFFFFFL);
2262 msg_Err( p_input, "cannot load tags (broken seekhead or file)" );
2266 msg_Dbg( p_input, "Tags" );
2267 ep = new EbmlParser( p_sys->es, tags );
2268 while( ( el = ep->Get() ) != NULL )
2270 if( EbmlId( *el ) == KaxTag::ClassInfos.GlobalId )
2272 msg_Dbg( p_input, "+ Tag" );
2274 while( ( el = ep->Get() ) != NULL )
2276 if( EbmlId( *el ) == KaxTagTargets::ClassInfos.GlobalId )
2278 msg_Dbg( p_input, "| + Targets" );
2280 while( ( el = ep->Get() ) != NULL )
2282 msg_Dbg( p_input, "| | + Unknown (%s)", typeid( *el ).name() );
2286 else if( EbmlId( *el ) == KaxTagGeneral::ClassInfos.GlobalId )
2288 msg_Dbg( p_input, "| + General" );
2290 while( ( el = ep->Get() ) != NULL )
2292 msg_Dbg( p_input, "| | + Unknown (%s)", typeid( *el ).name() );
2296 else if( EbmlId( *el ) == KaxTagGenres::ClassInfos.GlobalId )
2298 msg_Dbg( p_input, "| + Genres" );
2300 while( ( el = ep->Get() ) != NULL )
2302 msg_Dbg( p_input, "| | + Unknown (%s)", typeid( *el ).name() );
2306 else if( EbmlId( *el ) == KaxTagAudioSpecific::ClassInfos.GlobalId )
2308 msg_Dbg( p_input, "| + Audio Specific" );
2310 while( ( el = ep->Get() ) != NULL )
2312 msg_Dbg( p_input, "| | + Unknown (%s)", typeid( *el ).name() );
2316 else if( EbmlId( *el ) == KaxTagImageSpecific::ClassInfos.GlobalId )
2318 msg_Dbg( p_input, "| + Images Specific" );
2320 while( ( el = ep->Get() ) != NULL )
2322 msg_Dbg( p_input, "| | + Unknown (%s)", typeid( *el ).name() );
2326 else if( EbmlId( *el ) == KaxTagMultiComment::ClassInfos.GlobalId )
2328 msg_Dbg( p_input, "| + Multi Comment" );
2330 else if( EbmlId( *el ) == KaxTagMultiCommercial::ClassInfos.GlobalId )
2332 msg_Dbg( p_input, "| + Multi Commercial" );
2334 else if( EbmlId( *el ) == KaxTagMultiDate::ClassInfos.GlobalId )
2336 msg_Dbg( p_input, "| + Multi Date" );
2338 else if( EbmlId( *el ) == KaxTagMultiEntity::ClassInfos.GlobalId )
2340 msg_Dbg( p_input, "| + Multi Entity" );
2342 else if( EbmlId( *el ) == KaxTagMultiIdentifier::ClassInfos.GlobalId )
2344 msg_Dbg( p_input, "| + Multi Identifier" );
2346 else if( EbmlId( *el ) == KaxTagMultiLegal::ClassInfos.GlobalId )
2348 msg_Dbg( p_input, "| + Multi Legal" );
2350 else if( EbmlId( *el ) == KaxTagMultiTitle::ClassInfos.GlobalId )
2352 msg_Dbg( p_input, "| + Multi Title" );
2356 msg_Dbg( p_input, "| + Unknown (%s)", typeid( *el ).name() );
2363 msg_Dbg( p_input, "+ Unknown (%s)", typeid( *el ).name() );
2369 msg_Dbg( p_input, "loading tags done." );
2370 p_sys->in->setFilePointer( i_sav_position, seek_beginning );
2373 static void InformationsCreate( input_thread_t *p_input )
2375 demux_sys_t *p_sys = p_input->p_demux_data;
2376 input_info_category_t *p_cat;
2379 p_cat = input_InfoCategory( p_input, "Matroska" );
2380 if( p_sys->f_duration > 1000.1 )
2382 int64_t i_sec = (int64_t)p_sys->f_duration / 1000;
2386 m = ( i_sec / 60 ) % 60;
2389 input_AddInfo( p_cat, _("Duration"), "%d:%2.2d:%2.2d" , h, m, s );
2392 if( p_sys->psz_title )
2394 input_AddInfo( p_cat, _("Title"), "%s" ,p_sys->psz_title );
2396 if( p_sys->psz_date_utc )
2398 input_AddInfo( p_cat, _("Date UTC"), "%s" ,p_sys->psz_date_utc );
2400 if( p_sys->psz_segment_filename )
2402 input_AddInfo( p_cat, _("Segment Filename"), "%s" ,p_sys->psz_segment_filename );
2404 if( p_sys->psz_muxing_application )
2406 input_AddInfo( p_cat, _("Muxing Application"), "%s" ,p_sys->psz_muxing_application );
2408 if( p_sys->psz_writing_application )
2410 input_AddInfo( p_cat, _("Writing Application"), "%s" ,p_sys->psz_writing_application );
2412 input_AddInfo( p_cat, _("Number of streams"), "%d" , p_sys->i_track );
2414 for( i_track = 0; i_track < p_sys->i_track; i_track++ )
2416 char psz_cat[strlen( "Stream " ) + 10];
2417 #define tk p_sys->track[i_track]
2419 sprintf( psz_cat, "Stream %d", i_track );
2420 p_cat = input_InfoCategory( p_input, psz_cat);
2423 input_AddInfo( p_cat, _("Name"), "%s", tk.psz_name );
2425 if( tk.psz_codec_name )
2427 input_AddInfo( p_cat, _("Codec Name"), "%s", tk.psz_codec_name );
2429 if( tk.psz_codec_settings )
2431 input_AddInfo( p_cat, _("Codec Setting"), "%s", tk.psz_codec_settings );
2433 if( tk.psz_codec_info_url )
2435 input_AddInfo( p_cat, _("Codec Info"), "%s", tk.psz_codec_info_url );
2437 if( tk.psz_codec_download_url )
2439 input_AddInfo( p_cat, _("Codec Download"), "%s", tk.psz_codec_download_url );
2445 input_AddInfo( p_cat, _("Type"), _("Audio") );
2446 input_AddInfo( p_cat, _("Codec"), "%.4s (%s)", (char*)&tk.i_codec, tk.psz_codec );
2447 if( tk.i_channels > 0 )
2449 input_AddInfo( p_cat, _("Channels"), "%d", tk.i_channels );
2451 if( tk.i_samplerate > 0 )
2453 input_AddInfo( p_cat, _("Sample Rate"), "%d", tk.i_samplerate );
2455 if( tk.i_bitspersample )
2457 input_AddInfo( p_cat, _("Bits Per Sample"), "%d", tk.i_bitspersample );
2461 input_AddInfo( p_cat, _("Type"), _("Video") );
2462 input_AddInfo( p_cat, _("Codec"), "%.4s (%s)", (char*)&tk.i_codec, tk.psz_codec );
2463 if( tk.i_width > 0 && tk.i_height )
2465 input_AddInfo( p_cat, _("Resolution"), "%dx%d", tk.i_width, tk.i_height );
2467 if( tk.i_display_width > 0 && tk.i_display_height )
2469 input_AddInfo( p_cat, _("Display Resolution"), "%dx%d", tk.i_display_width, tk.i_display_height );
2471 if( tk.f_fps > 0.1 )
2473 input_AddInfo( p_cat, _("Frame Per Second"), "%.3f", tk.f_fps );
2477 input_AddInfo( p_cat, _("Type"), _("Subtitle") );
2478 input_AddInfo( p_cat, _("Codec"), "%s", tk.psz_codec );
2484 if( p_sys->i_tags_position >= 0 && p_input->stream.b_seekable )
2486 LoadTags( p_input );
2491 /*****************************************************************************
2493 *****************************************************************************/
2495 static void IndexAppendCluster( input_thread_t *p_input, KaxCluster *cluster )
2497 demux_sys_t *p_sys = p_input->p_demux_data;
2499 #define idx p_sys->index[p_sys->i_index]
2501 idx.i_block_number= -1;
2502 idx.i_position = cluster->GetElementPosition();
2504 idx.b_key = VLC_TRUE;
2507 if( p_sys->i_index >= p_sys->i_index_max )
2509 p_sys->i_index_max += 1024;
2510 p_sys->index = (mkv_index_t*)realloc( p_sys->index, sizeof( mkv_index_t ) * p_sys->i_index_max );
2515 static char * UTF8ToStr( const UTFstring &u )
2524 p = dst = (char*)malloc( i_src + 1);