1 /*****************************************************************************
2 * matroska_segment.cpp : matroska demuxer
3 *****************************************************************************
4 * Copyright (C) 2003-2010 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * Steve Lhomme <steve.lhomme@free.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #include "matroska_segment.hpp"
27 #include "chapters.hpp"
31 #include "Ebml_parser.hpp"
34 #include "../vobsub.h"
37 #include <vlc_codecs.h>
39 /* GetFourCC helper */
40 #define GetFOURCC( p ) __GetFOURCC( (uint8_t*)p )
41 static vlc_fourcc_t __GetFOURCC( uint8_t *p )
43 return VLC_FOURCC( p[0], p[1], p[2], p[3] );
46 matroska_segment_c::matroska_segment_c( demux_sys_t & demuxer, EbmlStream & estream )
49 ,i_timescale(MKVD_TIMECODESCALE)
53 ,i_seekhead_position(-1)
55 ,i_tracks_position(-1)
57 ,i_chapters_position(-1)
59 ,i_attachments_position(-1)
65 ,p_prev_segment_uid(NULL)
66 ,p_next_segment_uid(NULL)
70 ,psz_muxing_application(NULL)
71 ,psz_writing_application(NULL)
72 ,psz_segment_filename(NULL)
80 p_indexes = (mkv_index_t*)malloc( sizeof( mkv_index_t ) * i_index_max );
83 matroska_segment_c::~matroska_segment_c()
85 for( size_t i_track = 0; i_track < tracks.size(); i_track++ )
87 delete tracks[i_track]->p_compression_data;
88 es_format_Clean( &tracks[i_track]->fmt );
89 free( tracks[i_track]->p_extra_data );
90 free( tracks[i_track]->psz_codec );
91 delete tracks[i_track];
94 free( psz_writing_application );
95 free( psz_muxing_application );
96 free( psz_segment_filename );
103 delete p_segment_uid;
104 delete p_prev_segment_uid;
105 delete p_next_segment_uid;
107 vlc_delete_all( stored_editions );
108 vlc_delete_all( translations );
109 vlc_delete_all( families );
113 /*****************************************************************************
115 *****************************************************************************
116 * * LoadCues : load the cues element and update index
117 * * LoadTags : load ... the tags element
118 * * InformationCreate : create all information, load tags if present
119 *****************************************************************************/
120 void matroska_segment_c::LoadCues( KaxCues *cues )
127 msg_Err( &sys.demuxer, "There can be only 1 Cues per section." );
131 ep = new EbmlParser( &es, cues, &sys.demuxer );
132 while( ( el = ep->Get() ) != NULL )
134 if( MKV_IS_ID( el, KaxCuePoint ) )
136 #define idx p_indexes[i_index]
139 idx.i_block_number= -1;
145 while( ( el = ep->Get() ) != NULL )
147 if( MKV_IS_ID( el, KaxCueTime ) )
149 KaxCueTime &ctime = *(KaxCueTime*)el;
151 ctime.ReadData( es.I_O() );
153 idx.i_time = uint64( ctime ) * i_timescale / (mtime_t)1000;
155 else if( MKV_IS_ID( el, KaxCueTrackPositions ) )
158 while( ( el = ep->Get() ) != NULL )
160 if( MKV_IS_ID( el, KaxCueTrack ) )
162 KaxCueTrack &ctrack = *(KaxCueTrack*)el;
164 ctrack.ReadData( es.I_O() );
165 idx.i_track = uint16( ctrack );
167 else if( MKV_IS_ID( el, KaxCueClusterPosition ) )
169 KaxCueClusterPosition &ccpos = *(KaxCueClusterPosition*)el;
171 ccpos.ReadData( es.I_O() );
172 idx.i_position = segment->GetGlobalPosition( uint64( ccpos ) );
174 else if( MKV_IS_ID( el, KaxCueBlockNumber ) )
176 KaxCueBlockNumber &cbnum = *(KaxCueBlockNumber*)el;
178 cbnum.ReadData( es.I_O() );
179 idx.i_block_number = uint32( cbnum );
183 msg_Dbg( &sys.demuxer, " * Unknown (%s)", typeid(*el).name() );
190 msg_Dbg( &sys.demuxer, " * Unknown (%s)", typeid(*el).name() );
196 msg_Dbg( &sys.demuxer, " * added time=%"PRId64" pos=%"PRId64
197 " track=%d bnum=%d", idx.i_time, idx.i_position,
198 idx.i_track, idx.i_block_number );
202 if( i_index >= i_index_max )
205 p_indexes = (mkv_index_t*)xrealloc( p_indexes,
206 sizeof( mkv_index_t ) * i_index_max );
212 msg_Dbg( &sys.demuxer, " * Unknown (%s)", typeid(*el).name() );
217 msg_Dbg( &sys.demuxer, "| - loading cues done." );
221 #define PARSE_TAG( type ) \
223 msg_Dbg( &sys.demuxer, "| + " type ); \
225 while( ( el = ep->Get() ) != NULL ) \
227 msg_Dbg( &sys.demuxer, "| | + Unknown (%s)", typeid( *el ).name() ); \
229 ep->Up(); } while( 0 )
231 static const struct {
232 vlc_meta_type_t type;
234 } metadata_map[] = { {vlc_meta_Title, "TITLE"},
235 {vlc_meta_Artist, "ARTIST"},
236 {vlc_meta_Genre, "GENRE"},
237 {vlc_meta_Copyright, "COPYRIGHT"},
238 {vlc_meta_Description, "DESCRIPTION"},
239 {vlc_meta_Publisher, "PUBLISHER"},
240 {vlc_meta_URL, "URL"},
241 {vlc_meta_TrackNumber, "PART_NUMBER"},
242 {vlc_meta_Date, "DATE_RELEASE"},
243 {vlc_meta_Title, NULL},
246 void matroska_segment_c::ParseSimpleTags( KaxTagSimple *tag )
249 EbmlParser *ep = new EbmlParser( &es, tag, &sys.demuxer );
250 char *k = NULL, *v = NULL;
253 sys.meta = vlc_meta_New();
255 msg_Dbg( &sys.demuxer, "| + Simple Tag ");
256 while( ( el = ep->Get() ) != NULL )
258 if( MKV_IS_ID( el, KaxTagName ) )
260 KaxTagName &key = *(KaxTagName*)el;
261 key.ReadData( es.I_O(), SCOPE_ALL_DATA );
262 k = strdup( UTFstring( key ).GetUTF8().c_str() );
264 if( MKV_IS_ID( el, KaxTagString ) )
266 KaxTagString &value = *(KaxTagString*)el;
267 value.ReadData( es.I_O(), SCOPE_ALL_DATA );
268 v = strdup( UTFstring( value ).GetUTF8().c_str() );
275 msg_Warn( &sys.demuxer, "Invalid MKV SimpleTag found.");
279 for( int i = 0; metadata_map[i].key; i++ )
281 if( !strcmp( k, metadata_map[i].key ) )
283 vlc_meta_Set( sys.meta, metadata_map[i].type, v );
287 vlc_meta_AddExtra( sys.meta, k, v );
294 void matroska_segment_c::LoadTags( KaxTags *tags )
296 /* Master elements */
297 EbmlParser *ep = new EbmlParser( &es, tags, &sys.demuxer );
300 while( ( el = ep->Get() ) != NULL )
302 if( MKV_IS_ID( el, KaxTag ) )
304 msg_Dbg( &sys.demuxer, "+ Tag" );
306 while( ( el = ep->Get() ) != NULL )
308 if( MKV_IS_ID( el, KaxTagTargets ) )
309 PARSE_TAG( "Targets" );
310 #if 0 // not valid anymore
311 else if( MKV_IS_ID( el, KaxTagGeneral ) )
312 PARSE_TAG( "General" );
313 else if( MKV_IS_ID( el, KaxTagGenres ) )
314 PARSE_TAG( "Genres" );
315 else if( MKV_IS_ID( el, KaxTagAudioSpecific ) )
316 PARSE_TAG( "Audio Specific" );
317 else if( MKV_IS_ID( el, KaxTagImageSpecific ) )
318 PARSE_TAG( "Images Specific" );
319 else if( MKV_IS_ID( el, KaxTagMultiComment ) )
321 msg_Dbg( &sys.demuxer, "| + Multi Comment" );
323 else if( MKV_IS_ID( el, KaxTagMultiCommercial ) )
325 msg_Dbg( &sys.demuxer, "| + Multi Commercial" );
327 else if( MKV_IS_ID( el, KaxTagMultiDate ) )
329 msg_Dbg( &sys.demuxer, "| + Multi Date" );
331 else if( MKV_IS_ID( el, KaxTagMultiEntity ) )
333 msg_Dbg( &sys.demuxer, "| + Multi Entity" );
335 else if( MKV_IS_ID( el, KaxTagMultiIdentifier ) )
337 msg_Dbg( &sys.demuxer, "| + Multi Identifier" );
339 else if( MKV_IS_ID( el, KaxTagMultiLegal ) )
341 msg_Dbg( &sys.demuxer, "| + Multi Legal" );
343 else if( MKV_IS_ID( el, KaxTagMultiTitle ) )
345 msg_Dbg( &sys.demuxer, "| + Multi Title" );
348 else if( MKV_IS_ID( el, KaxTagSimple ) )
349 ParseSimpleTags( static_cast<KaxTagSimple*>( el ) );
352 msg_Dbg( &sys.demuxer, "| + LoadTag Unknown (%s)", typeid( *el ).name() );
359 msg_Dbg( &sys.demuxer, "+ Unknown (%s)", typeid( *el ).name() );
364 msg_Dbg( &sys.demuxer, "loading tags done." );
368 /*****************************************************************************
370 *****************************************************************************/
371 void matroska_segment_c::InformationCreate( )
374 sys.meta = vlc_meta_New();
378 vlc_meta_SetTitle( sys.meta, psz_title );
382 vlc_meta_SetDate( sys.meta, psz_date_utc );
385 if( psz_segment_filename )
387 fprintf( stderr, "***** WARNING: Unhandled meta - Use custom\n" );
389 if( psz_muxing_application )
391 fprintf( stderr, "***** WARNING: Unhandled meta - Use custom\n" );
393 if( psz_writing_application )
395 fprintf( stderr, "***** WARNING: Unhandled meta - Use custom\n" );
398 for( size_t i_track = 0; i_track < tracks.size(); i_track++ )
400 // mkv_track_t *tk = tracks[i_track];
401 // vlc_meta_t *mtk = vlc_meta_New();
402 fprintf( stderr, "***** WARNING: Unhandled child meta\n");
406 if( i_tags_position >= 0 )
410 stream_Control( sys.demuxer.s, STREAM_CAN_FASTSEEK, &b_seekable );
420 /*****************************************************************************
422 *****************************************************************************/
424 void matroska_segment_c::IndexAppendCluster( KaxCluster *cluster )
426 #define idx p_indexes[i_index]
428 idx.i_block_number= -1;
429 idx.i_position = cluster->GetElementPosition();
430 idx.i_time = cluster->GlobalTimecode()/ (mtime_t) 1000;
434 if( i_index >= i_index_max )
437 p_indexes = (mkv_index_t*)xrealloc( p_indexes,
438 sizeof( mkv_index_t ) * i_index_max );
443 bool matroska_segment_c::PreloadFamily( const matroska_segment_c & of_segment )
448 for (size_t i=0; i<families.size(); i++)
450 for (size_t j=0; j<of_segment.families.size(); j++)
452 if ( *(families[i]) == *(of_segment.families[j]) )
460 bool matroska_segment_c::CompareSegmentUIDs( const matroska_segment_c * p_item_a, const matroska_segment_c * p_item_b )
464 if ( p_item_a == NULL || p_item_b == NULL )
467 p_tmp = (EbmlBinary *)p_item_a->p_segment_uid;
468 if ( p_item_b->p_prev_segment_uid != NULL
469 && *p_tmp == *p_item_b->p_prev_segment_uid )
472 p_tmp = (EbmlBinary *)p_item_a->p_next_segment_uid;
476 if ( p_item_b->p_segment_uid != NULL
477 && *p_tmp == *p_item_b->p_segment_uid )
480 if ( p_item_b->p_prev_segment_uid != NULL
481 && *p_tmp == *p_item_b->p_prev_segment_uid )
487 bool matroska_segment_c::Preload( )
492 EbmlElement *el = NULL;
494 ep->Reset( &sys.demuxer );
496 while( ( el = ep->Get() ) != NULL )
498 if( MKV_IS_ID( el, KaxSeekHead ) )
500 /* Multiple allowed */
501 /* We bail at 10, to prevent possible recursion */
502 msg_Dbg( &sys.demuxer, "| + Seek head" );
503 if( i_seekhead_count < 10 )
505 i_seekhead_position = (int64_t) es.I_O().getFilePointer();
506 ParseSeekHead( static_cast<KaxSeekHead*>( el ) );
509 else if( MKV_IS_ID( el, KaxInfo ) )
511 /* Multiple allowed, mandatory */
512 msg_Dbg( &sys.demuxer, "| + Information" );
513 if( i_info_position < 0 ) // FIXME
514 ParseInfo( static_cast<KaxInfo*>( el ) );
515 i_info_position = (int64_t) es.I_O().getFilePointer();
517 else if( MKV_IS_ID( el, KaxTracks ) )
519 /* Multiple allowed */
520 msg_Dbg( &sys.demuxer, "| + Tracks" );
521 if( i_tracks_position < 0 ) // FIXME
522 ParseTracks( static_cast<KaxTracks*>( el ) );
523 if ( tracks.size() == 0 )
525 msg_Err( &sys.demuxer, "No tracks supported" );
528 i_tracks_position = (int64_t) es.I_O().getFilePointer();
530 else if( MKV_IS_ID( el, KaxCues ) )
532 msg_Dbg( &sys.demuxer, "| + Cues" );
533 if( i_cues_position < 0 )
534 LoadCues( static_cast<KaxCues*>( el ) );
535 i_cues_position = (int64_t) es.I_O().getFilePointer();
537 else if( MKV_IS_ID( el, KaxCluster ) )
539 msg_Dbg( &sys.demuxer, "| + Cluster" );
541 cluster = (KaxCluster*)el;
543 i_cluster_pos = i_start_pos = cluster->GetElementPosition();
547 /* stop pre-parsing the stream */
550 else if( MKV_IS_ID( el, KaxAttachments ) )
552 msg_Dbg( &sys.demuxer, "| + Attachments" );
553 if( i_attachments_position < 0 )
554 ParseAttachments( static_cast<KaxAttachments*>( el ) );
555 i_attachments_position = (int64_t) es.I_O().getFilePointer();
557 else if( MKV_IS_ID( el, KaxChapters ) )
559 msg_Dbg( &sys.demuxer, "| + Chapters" );
560 if( i_chapters_position < 0 )
561 ParseChapters( static_cast<KaxChapters*>( el ) );
562 i_chapters_position = (int64_t) es.I_O().getFilePointer();
564 else if( MKV_IS_ID( el, KaxTag ) )
566 msg_Dbg( &sys.demuxer, "| + Tags" );
567 /*FIXME if( i_tags_position < 0)
568 LoadTags( static_cast<KaxTags*>( el ) );*/
569 i_tags_position = (int64_t) es.I_O().getFilePointer();
571 else if( MKV_IS_ID( el, EbmlVoid ) )
572 msg_Dbg( &sys.demuxer, "| + Void" );
574 msg_Dbg( &sys.demuxer, "| + Preload Unknown (%s)", typeid(*el).name() );
582 /* Here we try to load elements that were found in Seek Heads, but not yet parsed */
583 bool matroska_segment_c::LoadSeekHeadItem( const EbmlCallbacks & ClassInfos, int64_t i_element_position )
585 int64_t i_sav_position = (int64_t)es.I_O().getFilePointer();
588 es.I_O().setFilePointer( i_element_position, seek_beginning );
589 el = es.FindNextID( ClassInfos, 0xFFFFFFFFL);
593 msg_Err( &sys.demuxer, "cannot load some cues/chapters/tags etc. (broken seekhead or file)" );
594 es.I_O().setFilePointer( i_sav_position, seek_beginning );
598 if( MKV_IS_ID( el, KaxSeekHead ) )
600 /* Multiple allowed */
601 msg_Dbg( &sys.demuxer, "| + Seek head" );
602 if( i_seekhead_count < 10 )
604 i_seekhead_position = i_element_position;
605 ParseSeekHead( static_cast<KaxSeekHead*>( el ) );
608 else if( MKV_IS_ID( el, KaxInfo ) ) // FIXME
610 /* Multiple allowed, mandatory */
611 msg_Dbg( &sys.demuxer, "| + Information" );
612 if( i_info_position < 0 )
613 ParseInfo( static_cast<KaxInfo*>( el ) );
614 i_info_position = i_element_position;
616 else if( MKV_IS_ID( el, KaxTracks ) ) // FIXME
618 /* Multiple allowed */
619 msg_Dbg( &sys.demuxer, "| + Tracks" );
620 if( i_tracks_position < 0 )
621 ParseTracks( static_cast<KaxTracks*>( el ) );
622 if ( tracks.size() == 0 )
624 msg_Err( &sys.demuxer, "No tracks supported" );
626 es.I_O().setFilePointer( i_sav_position, seek_beginning );
629 i_tracks_position = i_element_position;
631 else if( MKV_IS_ID( el, KaxCues ) )
633 msg_Dbg( &sys.demuxer, "| + Cues" );
634 if( i_cues_position < 0 )
635 LoadCues( static_cast<KaxCues*>( el ) );
636 i_cues_position = i_element_position;
638 else if( MKV_IS_ID( el, KaxAttachments ) )
640 msg_Dbg( &sys.demuxer, "| + Attachments" );
641 if( i_attachments_position < 0 )
642 ParseAttachments( static_cast<KaxAttachments*>( el ) );
643 i_attachments_position = i_element_position;
645 else if( MKV_IS_ID( el, KaxChapters ) )
647 msg_Dbg( &sys.demuxer, "| + Chapters" );
648 if( i_chapters_position < 0 )
649 ParseChapters( static_cast<KaxChapters*>( el ) );
650 i_chapters_position = i_element_position;
652 else if( MKV_IS_ID( el, KaxTags ) )
654 msg_Dbg( &sys.demuxer, "| + Tags" );
655 if( i_tags_position < 0 )
656 LoadTags( static_cast<KaxTags*>( el ) );
657 i_tags_position = i_element_position;
661 msg_Dbg( &sys.demuxer, "| + LoadSeekHeadItem Unknown (%s)", typeid(*el).name() );
665 es.I_O().setFilePointer( i_sav_position, seek_beginning );
671 spoint(unsigned int tk, mtime_t date, int64_t pos, int64_t cpos):
672 i_track(tk),i_date(date), i_seek_pos(pos),
673 i_cluster_pos(cpos), p_next(NULL){}
674 unsigned int i_track;
677 int64_t i_cluster_pos;
681 void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_global_position )
684 KaxSimpleBlock *simpleblock;
685 int64_t i_block_duration;
687 int64_t i_seek_position = i_start_pos;
688 int64_t i_seek_time = i_start_time;
690 spoint *p_first = NULL;
691 spoint *p_last = NULL;
693 if( i_global_position >= 0 )
695 /* Special case for seeking in files with no cues */
696 EbmlElement *el = NULL;
698 /* Start from the last known index instead of the beginning eachtime */
700 es.I_O().setFilePointer( i_start_pos, seek_beginning );
702 es.I_O().setFilePointer( p_indexes[ i_index - 1 ].i_position,
705 ep = new EbmlParser( &es, segment, &sys.demuxer );
708 while( ( el = ep->Get() ) != NULL )
710 if( MKV_IS_ID( el, KaxCluster ) )
712 cluster = (KaxCluster *)el;
713 i_cluster_pos = cluster->GetElementPosition();
716 p_indexes[i_index - 1].i_position < (int64_t)cluster->GetElementPosition() ) )
719 IndexAppendCluster( cluster );
721 if( es.I_O().getFilePointer() >= (unsigned) i_global_position )
727 /* Don't try complex seek if we seek to 0 */
730 es_out_Control( sys.demuxer.out, ES_OUT_SET_NEXT_DISPLAY_TIME, 0 );
731 es.I_O().setFilePointer( i_start_pos );
734 ep = new EbmlParser( &es, segment, &sys.demuxer );
743 for( ; i_idx < i_index; i_idx++ )
744 if( p_indexes[i_idx].i_time + i_time_offset > i_date )
750 i_seek_position = p_indexes[i_idx].i_position;
751 i_seek_time = p_indexes[i_idx].i_time;
754 msg_Dbg( &sys.demuxer, "seek got %"PRId64" (%d%%)",
755 i_seek_time, (int)( 100 * i_seek_position / stream_Size( sys.demuxer.s ) ) );
757 es.I_O().setFilePointer( i_seek_position, seek_beginning );
760 ep = new EbmlParser( &es, segment, &sys.demuxer );
763 sys.i_start_pts = i_date;
765 es_out_Control( sys.demuxer.out, ES_OUT_SET_NEXT_DISPLAY_TIME, i_date );
767 /* now parse until key frame */
768 for( i_track = 0; i_track < tracks.size(); i_track++ )
770 if( tracks[i_track]->fmt.i_cat == VIDEO_ES )
772 spoint * seekpoint = new spoint(i_track, i_seek_time, i_seek_position, i_seek_position);
773 if( unlikely( !seekpoint ) )
775 for( spoint * sp = p_first; sp; )
783 if( unlikely( !p_first ) )
790 p_last->p_next = seekpoint;
796 while( i_pts < i_date )
799 bool b_discardable_picture;
800 if( BlockGet( block, simpleblock, &b_key_picture, &b_discardable_picture, &i_block_duration ) )
802 msg_Warn( &sys.demuxer, "cannot get block EOF?" );
807 /* check if block's track is in our list */
808 for( i_track = 0; i_track < tracks.size(); i_track++ )
810 if( (simpleblock && tracks[i_track]->i_number == simpleblock->TrackNum()) ||
811 (block && tracks[i_track]->i_number == block->TrackNum()) )
816 i_pts = sys.i_chapter_time + simpleblock->GlobalTimecode() / (mtime_t) 1000;
818 i_pts = sys.i_chapter_time + block->GlobalTimecode() / (mtime_t) 1000;
819 if( i_track < tracks.size() )
821 if( tracks[i_track]->fmt.i_cat == VIDEO_ES && b_key_picture )
823 /* get the seekpoint */
825 for( sp = p_first; sp; sp = sp->p_next )
826 if( sp->i_track == i_track )
831 sp->i_seek_pos = simpleblock->GetElementPosition();
833 sp->i_seek_pos = i_block_pos;
834 sp->i_cluster_pos = i_cluster_pos;
841 /* rewind to the last I img */
843 for( p_min = p_first, p_last = p_first; p_last; p_last = p_last->p_next )
844 if( p_last->i_date < p_min->i_date )
847 sys.i_pts = p_min->i_date;
848 cluster = (KaxCluster *) ep->UnGet( p_min->i_seek_pos, p_min->i_cluster_pos );
850 /* hack use BlockGet to get the cluster then goto the wanted block */
854 bool b_discardable_picture;
855 BlockGet( block, simpleblock, &b_key_picture, &b_discardable_picture, &i_block_duration );
857 cluster = (KaxCluster *) ep->UnGet( p_min->i_seek_pos, p_min->i_cluster_pos );
863 p_first = p_first->p_next;
868 int matroska_segment_c::BlockFindTrackIndex( size_t *pi_track,
869 const KaxBlock *p_block, const KaxSimpleBlock *p_simpleblock )
872 for( i_track = 0; i_track < tracks.size(); i_track++ )
874 const mkv_track_t *tk = tracks[i_track];
876 if( ( p_block != NULL && tk->i_number == p_block->TrackNum() ) ||
877 ( p_simpleblock != NULL && tk->i_number == p_simpleblock->TrackNum() ) )
883 if( i_track >= tracks.size() )
891 static inline void fill_extra_data( mkv_track_t *p_tk, unsigned int offset )
893 if(p_tk->i_extra_data <= offset) return;
894 p_tk->fmt.i_extra = p_tk->i_extra_data - offset;
895 p_tk->fmt.p_extra = xmalloc( p_tk->fmt.i_extra );
896 if(!p_tk->fmt.p_extra) { p_tk->fmt.i_extra = 0; return; };
897 memcpy( p_tk->fmt.p_extra, p_tk->p_extra_data + offset, p_tk->fmt.i_extra );
900 bool matroska_segment_c::Select( mtime_t i_start_time )
903 msg_Dbg( &sys.demuxer, "found %d es", (int)tracks.size() );
905 for( size_t i_track = 0; i_track < tracks.size(); i_track++ )
907 mkv_track_t *p_tk = tracks[i_track];
908 es_format_t *p_fmt = &p_tk->fmt;
910 if( p_fmt->i_cat == UNKNOWN_ES || !p_tk->psz_codec )
912 msg_Warn( &sys.demuxer, "invalid track[%d, n=%d]", (int)i_track, p_tk->i_number );
917 if( !strcmp( p_tk->psz_codec, "V_MS/VFW/FOURCC" ) )
919 if( p_tk->i_extra_data < (int)sizeof( BITMAPINFOHEADER ) )
921 msg_Err( &sys.demuxer, "missing/invalid BITMAPINFOHEADER" );
922 p_tk->fmt.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
926 BITMAPINFOHEADER *p_bih = (BITMAPINFOHEADER*)p_tk->p_extra_data;
928 p_tk->fmt.video.i_width = GetDWLE( &p_bih->biWidth );
929 p_tk->fmt.video.i_height= GetDWLE( &p_bih->biHeight );
930 p_tk->fmt.i_codec = GetFOURCC( &p_bih->biCompression );
932 p_tk->fmt.i_extra = GetDWLE( &p_bih->biSize ) - sizeof( BITMAPINFOHEADER );
933 if( p_tk->fmt.i_extra > 0 )
935 /* Very unlikely yet possible: bug #5659*/
936 size_t maxlen = p_tk->i_extra_data - sizeof( BITMAPINFOHEADER );
937 p_tk->fmt.i_extra = ( p_tk->fmt.i_extra < maxlen )?
938 p_tk->fmt.i_extra : maxlen;
940 p_tk->fmt.p_extra = xmalloc( p_tk->fmt.i_extra );
941 memcpy( p_tk->fmt.p_extra, &p_bih[1], p_tk->fmt.i_extra );
944 p_tk->b_dts_only = true;
946 else if( !strcmp( p_tk->psz_codec, "V_MPEG1" ) ||
947 !strcmp( p_tk->psz_codec, "V_MPEG2" ) )
949 p_tk->fmt.i_codec = VLC_CODEC_MPGV;
950 if( p_tk->i_extra_data )
951 fill_extra_data( p_tk, 0 );
953 else if( !strncmp( p_tk->psz_codec, "V_THEORA", 8 ) )
955 p_tk->fmt.i_codec = VLC_CODEC_THEORA;
956 fill_extra_data( p_tk, 0 );
957 p_tk->b_pts_only = true;
959 else if( !strncmp( p_tk->psz_codec, "V_REAL/RV", 9 ) )
961 uint8_t *p = p_tk->p_extra_data;
963 if( !strcmp( p_tk->psz_codec, "V_REAL/RV10" ) )
964 p_fmt->i_codec = VLC_CODEC_RV10;
965 else if( !strcmp( p_tk->psz_codec, "V_REAL/RV20" ) )
966 p_fmt->i_codec = VLC_CODEC_RV20;
967 else if( !strcmp( p_tk->psz_codec, "V_REAL/RV30" ) )
968 p_fmt->i_codec = VLC_CODEC_RV30;
969 else if( !strcmp( p_tk->psz_codec, "V_REAL/RV40" ) )
970 p_fmt->i_codec = VLC_CODEC_RV40;
972 /* Extract the framerate from the header */
973 if( p_tk->i_extra_data >= 26 &&
974 p[4] == 'V' && p[5] == 'I' && p[6] == 'D' && p[7] == 'O' &&
975 p[8] == 'R' && p[9] == 'V' &&
976 (p[10] == '3' || p[10] == '4') && p[11] == '0' )
978 p_tk->fmt.video.i_frame_rate =
979 p[22] << 24 | p[23] << 16 | p[24] << 8 | p[25] << 0;
980 p_tk->fmt.video.i_frame_rate_base = 65536;
983 fill_extra_data( p_tk, 26 );
984 p_tk->b_dts_only = true;
986 else if( !strncmp( p_tk->psz_codec, "V_DIRAC", 7 ) )
988 p_tk->fmt.i_codec = VLC_CODEC_DIRAC;
990 else if( !strncmp( p_tk->psz_codec, "V_VP8", 5 ) )
992 p_tk->fmt.i_codec = VLC_CODEC_VP8;
993 p_tk->b_pts_only = true;
995 else if( !strncmp( p_tk->psz_codec, "V_MPEG4", 7 ) )
997 if( !strcmp( p_tk->psz_codec, "V_MPEG4/MS/V3" ) )
999 p_tk->fmt.i_codec = VLC_CODEC_DIV3;
1001 else if( !strncmp( p_tk->psz_codec, "V_MPEG4/ISO", 11 ) )
1003 /* A MPEG 4 codec, SP, ASP, AP or AVC */
1004 if( !strcmp( p_tk->psz_codec, "V_MPEG4/ISO/AVC" ) )
1005 p_tk->fmt.i_codec = VLC_FOURCC( 'a', 'v', 'c', '1' );
1007 p_tk->fmt.i_codec = VLC_CODEC_MP4V;
1008 fill_extra_data( p_tk, 0 );
1011 else if( !strcmp( p_tk->psz_codec, "V_QUICKTIME" ) )
1013 MP4_Box_t *p_box = (MP4_Box_t*)xmalloc( sizeof( MP4_Box_t ) );
1014 stream_t *p_mp4_stream = stream_MemoryNew( VLC_OBJECT(&sys.demuxer),
1018 if( MP4_ReadBoxCommon( p_mp4_stream, p_box ) &&
1019 MP4_ReadBox_sample_vide( p_mp4_stream, p_box ) )
1021 p_tk->fmt.i_codec = p_box->i_type;
1022 p_tk->fmt.video.i_width = p_box->data.p_sample_vide->i_width;
1023 p_tk->fmt.video.i_height = p_box->data.p_sample_vide->i_height;
1024 p_tk->fmt.i_extra = p_box->data.p_sample_vide->i_qt_image_description;
1025 p_tk->fmt.p_extra = xmalloc( p_tk->fmt.i_extra );
1026 memcpy( p_tk->fmt.p_extra, p_box->data.p_sample_vide->p_qt_image_description, p_tk->fmt.i_extra );
1027 MP4_FreeBox_sample_vide( p_box );
1033 stream_Delete( p_mp4_stream );
1035 else if( !strcmp( p_tk->psz_codec, "V_MJPEG" ) )
1037 p_tk->fmt.i_codec = VLC_CODEC_MJPG;
1039 else if( !strcmp( p_tk->psz_codec, "A_MS/ACM" ) )
1041 if( p_tk->i_extra_data < (int)sizeof( WAVEFORMATEX ) )
1043 msg_Err( &sys.demuxer, "missing/invalid WAVEFORMATEX" );
1044 p_tk->fmt.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
1048 WAVEFORMATEX *p_wf = (WAVEFORMATEX*)p_tk->p_extra_data;
1050 wf_tag_to_fourcc( GetWLE( &p_wf->wFormatTag ), &p_tk->fmt.i_codec, NULL );
1052 p_tk->fmt.audio.i_channels = GetWLE( &p_wf->nChannels );
1053 p_tk->fmt.audio.i_rate = GetDWLE( &p_wf->nSamplesPerSec );
1054 p_tk->fmt.i_bitrate = GetDWLE( &p_wf->nAvgBytesPerSec ) * 8;
1055 p_tk->fmt.audio.i_blockalign = GetWLE( &p_wf->nBlockAlign );;
1056 p_tk->fmt.audio.i_bitspersample = GetWLE( &p_wf->wBitsPerSample );
1058 p_tk->fmt.i_extra = GetWLE( &p_wf->cbSize );
1059 if( p_tk->fmt.i_extra > 0 )
1061 p_tk->fmt.p_extra = xmalloc( p_tk->fmt.i_extra );
1062 memcpy( p_tk->fmt.p_extra, &p_wf[1], p_tk->fmt.i_extra );
1066 else if( !strcmp( p_tk->psz_codec, "A_MPEG/L3" ) ||
1067 !strcmp( p_tk->psz_codec, "A_MPEG/L2" ) ||
1068 !strcmp( p_tk->psz_codec, "A_MPEG/L1" ) )
1070 p_tk->fmt.i_codec = VLC_CODEC_MPGA;
1072 else if( !strcmp( p_tk->psz_codec, "A_AC3" ) )
1074 p_tk->fmt.i_codec = VLC_CODEC_A52;
1076 else if( !strcmp( p_tk->psz_codec, "A_EAC3" ) )
1078 p_tk->fmt.i_codec = VLC_CODEC_EAC3;
1080 else if( !strcmp( p_tk->psz_codec, "A_DTS" ) )
1082 p_tk->fmt.i_codec = VLC_CODEC_DTS;
1084 else if( !strcmp( p_tk->psz_codec, "A_MLP" ) )
1086 p_tk->fmt.i_codec = VLC_CODEC_MLP;
1088 else if( !strcmp( p_tk->psz_codec, "A_TRUEHD" ) )
1090 /* FIXME when more samples arrive */
1091 p_tk->fmt.i_codec = VLC_CODEC_TRUEHD;
1092 p_fmt->b_packetized = false;
1094 else if( !strcmp( p_tk->psz_codec, "A_FLAC" ) )
1096 p_tk->fmt.i_codec = VLC_CODEC_FLAC;
1097 fill_extra_data( p_tk, 0 );
1099 else if( !strcmp( p_tk->psz_codec, "A_VORBIS" ) )
1101 p_tk->fmt.i_codec = VLC_CODEC_VORBIS;
1102 fill_extra_data( p_tk, 0 );
1104 else if( !strncmp( p_tk->psz_codec, "A_AAC/MPEG2/", strlen( "A_AAC/MPEG2/" ) ) ||
1105 !strncmp( p_tk->psz_codec, "A_AAC/MPEG4/", strlen( "A_AAC/MPEG4/" ) ) )
1107 int i_profile, i_srate, sbr = 0;
1108 static const unsigned int i_sample_rates[] =
1110 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
1111 16000, 12000, 11025, 8000, 7350, 0, 0, 0
1114 p_tk->fmt.i_codec = VLC_CODEC_MP4A;
1115 /* create data for faad (MP4DecSpecificDescrTag)*/
1117 if( !strcmp( &p_tk->psz_codec[12], "MAIN" ) )
1121 else if( !strcmp( &p_tk->psz_codec[12], "LC" ) )
1125 else if( !strcmp( &p_tk->psz_codec[12], "SSR" ) )
1129 else if( !strcmp( &p_tk->psz_codec[12], "LC/SBR" ) )
1139 for( i_srate = 0; i_srate < 13; i_srate++ )
1141 if( i_sample_rates[i_srate] == p_tk->i_original_rate )
1146 msg_Dbg( &sys.demuxer, "profile=%d srate=%d", i_profile, i_srate );
1148 p_tk->fmt.i_extra = sbr ? 5 : 2;
1149 p_tk->fmt.p_extra = xmalloc( p_tk->fmt.i_extra );
1150 ((uint8_t*)p_tk->fmt.p_extra)[0] = ((i_profile + 1) << 3) | ((i_srate&0xe) >> 1);
1151 ((uint8_t*)p_tk->fmt.p_extra)[1] = ((i_srate & 0x1) << 7) | (p_tk->fmt.audio.i_channels << 3);
1154 int syncExtensionType = 0x2B7;
1156 for (iDSRI=0; iDSRI<13; iDSRI++)
1157 if( i_sample_rates[iDSRI] == p_tk->fmt.audio.i_rate )
1159 ((uint8_t*)p_tk->fmt.p_extra)[2] = (syncExtensionType >> 3) & 0xFF;
1160 ((uint8_t*)p_tk->fmt.p_extra)[3] = ((syncExtensionType & 0x7) << 5) | 5;
1161 ((uint8_t*)p_tk->fmt.p_extra)[4] = ((1 & 0x1) << 7) | (iDSRI << 3);
1164 else if( !strcmp( p_tk->psz_codec, "A_AAC" ) )
1166 p_tk->fmt.i_codec = VLC_CODEC_MP4A;
1167 fill_extra_data( p_tk, 0 );
1169 else if( !strcmp( p_tk->psz_codec, "A_WAVPACK4" ) )
1171 p_tk->fmt.i_codec = VLC_CODEC_WAVPACK;
1172 fill_extra_data( p_tk, 0 );
1174 else if( !strcmp( p_tk->psz_codec, "A_TTA1" ) )
1176 p_fmt->i_codec = VLC_CODEC_TTA;
1177 if( p_tk->i_extra_data > 0 )
1179 fill_extra_data( p_tk, 0 );
1183 p_fmt->i_extra = 30;
1184 p_fmt->p_extra = xmalloc( p_fmt->i_extra );
1185 uint8_t *p_extra = (uint8_t*)p_fmt->p_extra;
1186 memcpy( &p_extra[ 0], "TTA1", 4 );
1187 SetWLE( &p_extra[ 4], 1 );
1188 SetWLE( &p_extra[ 6], p_fmt->audio.i_channels );
1189 SetWLE( &p_extra[ 8], p_fmt->audio.i_bitspersample );
1190 SetDWLE( &p_extra[10], p_fmt->audio.i_rate );
1191 SetDWLE( &p_extra[14], 0xffffffff );
1192 memset( &p_extra[18], 0, 30 - 18 );
1195 else if( !strcmp( p_tk->psz_codec, "A_PCM/INT/BIG" ) ||
1196 !strcmp( p_tk->psz_codec, "A_PCM/INT/LIT" ) ||
1197 !strcmp( p_tk->psz_codec, "A_PCM/FLOAT/IEEE" ) )
1199 if( !strcmp( p_tk->psz_codec, "A_PCM/INT/BIG" ) )
1201 p_tk->fmt.i_codec = VLC_FOURCC( 't', 'w', 'o', 's' );
1205 p_tk->fmt.i_codec = VLC_FOURCC( 'a', 'r', 'a', 'w' );
1207 p_tk->fmt.audio.i_blockalign = ( p_tk->fmt.audio.i_bitspersample + 7 ) / 8 * p_tk->fmt.audio.i_channels;
1209 else if( !strncmp( p_tk->psz_codec, "A_REAL/", 7 ) )
1211 if( !strcmp( p_tk->psz_codec, "A_REAL/COOK" ) )
1212 p_tk->fmt.i_codec = VLC_CODEC_COOK;
1213 else if( !strcmp( p_tk->psz_codec, "A_REAL/ATRC" ) )
1214 p_tk->fmt.i_codec = VLC_CODEC_ATRAC3;
1215 else if( !strcmp( p_tk->psz_codec, "A_REAL/28_8" ) )
1216 p_tk->fmt.i_codec = VLC_CODEC_RA_288;
1217 /* FIXME 14_4, RALF and SIPR */
1218 fill_extra_data( p_tk, p_tk->fmt.i_codec == VLC_CODEC_RA_288 ? 0 : 0 /*78 - FIXME need to implement reading support for cook */ );
1220 else if( !strcmp( p_tk->psz_codec, "A_REAL/14_4" ) )
1222 p_fmt->i_codec = VLC_CODEC_RA_144;
1223 p_fmt->audio.i_channels = 1;
1224 p_fmt->audio.i_rate = 8000;
1225 p_fmt->audio.i_blockalign = 0x14;
1227 else if( !strcmp( p_tk->psz_codec, "S_KATE" ) )
1229 p_tk->fmt.i_codec = VLC_CODEC_KATE;
1230 p_tk->fmt.subs.psz_encoding = strdup( "UTF-8" );
1232 fill_extra_data( p_tk, 0 );
1234 else if( !strcmp( p_tk->psz_codec, "S_TEXT/ASCII" ) )
1236 p_fmt->i_codec = VLC_CODEC_SUBT;
1237 p_fmt->subs.psz_encoding = strdup( "ASCII" );
1239 else if( !strcmp( p_tk->psz_codec, "S_TEXT/UTF8" ) )
1241 p_tk->fmt.i_codec = VLC_CODEC_SUBT;
1242 p_tk->fmt.subs.psz_encoding = strdup( "UTF-8" );
1244 else if( !strcmp( p_tk->psz_codec, "S_TEXT/USF" ) )
1246 p_tk->fmt.i_codec = VLC_FOURCC( 'u', 's', 'f', ' ' );
1247 p_tk->fmt.subs.psz_encoding = strdup( "UTF-8" );
1248 if( p_tk->i_extra_data )
1249 fill_extra_data( p_tk, 0 );
1251 else if( !strcmp( p_tk->psz_codec, "S_TEXT/SSA" ) ||
1252 !strcmp( p_tk->psz_codec, "S_TEXT/ASS" ) ||
1253 !strcmp( p_tk->psz_codec, "S_SSA" ) ||
1254 !strcmp( p_tk->psz_codec, "S_ASS" ))
1256 p_tk->fmt.i_codec = VLC_CODEC_SSA;
1257 p_tk->fmt.subs.psz_encoding = strdup( "UTF-8" );
1258 if( p_tk->i_extra_data )
1259 fill_extra_data( p_tk, 0 );
1261 else if( !strcmp( p_tk->psz_codec, "S_VOBSUB" ) )
1263 p_tk->fmt.i_codec = VLC_CODEC_SPU;
1264 if( p_tk->i_extra_data )
1267 char *psz_buf = (char *)malloc( p_tk->i_extra_data + 1);
1268 if( psz_buf != NULL )
1270 memcpy( psz_buf, p_tk->p_extra_data , p_tk->i_extra_data );
1271 psz_buf[p_tk->i_extra_data] = '\0';
1273 psz_start = strstr( psz_buf, "size:" );
1275 vobsub_size_parse( psz_start,
1276 &p_tk->fmt.subs.spu.i_original_frame_width,
1277 &p_tk->fmt.subs.spu.i_original_frame_height ) == VLC_SUCCESS )
1279 msg_Dbg( &sys.demuxer, "original frame size vobsubs: %dx%d",
1280 p_tk->fmt.subs.spu.i_original_frame_width,
1281 p_tk->fmt.subs.spu.i_original_frame_height );
1285 msg_Warn( &sys.demuxer, "reading original frame size for vobsub failed" );
1288 psz_start = strstr( psz_buf, "palette:" );
1290 vobsub_palette_parse( psz_start, &p_tk->fmt.subs.spu.palette[1] ) == VLC_SUCCESS )
1292 p_tk->fmt.subs.spu.palette[0] = 0xBeef;
1293 msg_Dbg( &sys.demuxer, "vobsub palette read" );
1297 msg_Warn( &sys.demuxer, "reading original palette failed" );
1303 else if( !strcmp( p_tk->psz_codec, "S_HDMV/PGS" ) )
1305 p_tk->fmt.i_codec = VLC_CODEC_BD_PG;
1307 else if( !strcmp( p_tk->psz_codec, "B_VOBBTN" ) )
1309 p_tk->fmt.i_cat = NAV_ES;
1314 msg_Err( &sys.demuxer, "unknown codec id=`%s'", p_tk->psz_codec );
1315 p_tk->fmt.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
1317 if( p_tk->b_default )
1319 p_tk->fmt.i_priority = 1000;
1322 p_tk->p_es = es_out_Add( sys.demuxer.out, &p_tk->fmt );
1324 /* Turn on a subtitles track if it has been flagged as default -
1325 * but only do this if no subtitles track has already been engaged,
1326 * either by an earlier 'default track' (??) or by default
1327 * language choice behaviour.
1329 if( p_tk->b_default )
1331 es_out_Control( sys.demuxer.out,
1332 ES_OUT_SET_ES_DEFAULT,
1336 es_out_Control( sys.demuxer.out, ES_OUT_SET_NEXT_DISPLAY_TIME, i_start_time );
1338 sys.i_start_pts = i_start_time;
1339 // reset the stream reading to the first cluster of the segment used
1340 es.I_O().setFilePointer( i_start_pos );
1343 ep = new EbmlParser( &es, segment, &sys.demuxer );
1348 void matroska_segment_c::UnSelect( )
1350 sys.p_ev->ResetPci();
1351 for( size_t i_track = 0; i_track < tracks.size(); i_track++ )
1353 if ( tracks[i_track]->p_es != NULL )
1355 // es_format_Clean( &tracks[i_track]->fmt );
1356 es_out_Del( sys.demuxer.out, tracks[i_track]->p_es );
1357 tracks[i_track]->p_es = NULL;
1364 int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_simpleblock, bool *pb_key_picture, bool *pb_discardable_picture, int64_t *pi_duration )
1366 pp_simpleblock = NULL;
1369 *pb_key_picture = true;
1370 *pb_discardable_picture = false;
1374 EbmlElement *el = NULL;
1378 return VLC_EGENERIC;
1380 if( pp_simpleblock != NULL || ((el = ep->Get()) == NULL && pp_block != NULL) )
1382 /* Check blocks validity to protect againts broken files */
1383 if( BlockFindTrackIndex( NULL, pp_block , pp_simpleblock ) )
1386 pp_simpleblock = NULL;
1390 if( pp_simpleblock != NULL )
1392 *pb_key_picture = pp_simpleblock->IsKeyframe();
1393 *pb_discardable_picture = pp_simpleblock->IsDiscardable();
1396 /* update the index */
1397 #define idx p_indexes[i_index - 1]
1398 if( i_index > 0 && idx.i_time == -1 )
1400 if ( pp_simpleblock != NULL )
1401 idx.i_time = pp_simpleblock->GlobalTimecode() / (mtime_t)1000;
1403 idx.i_time = (*pp_block).GlobalTimecode() / (mtime_t)1000;
1404 idx.b_key = *pb_key_picture;
1410 i_level = ep->GetLevel();
1419 msg_Warn( &sys.demuxer, "EOF" );
1420 return VLC_EGENERIC;
1423 /* Verify that we are still inside our cluster
1424 * It can happens whith broken files and when seeking
1428 if( cluster && !ep->IsTopPresent( cluster ) )
1430 msg_Warn( &sys.demuxer, "Unexpected escape from current cluster" );
1441 if( MKV_IS_ID( el, KaxCluster ) )
1443 cluster = (KaxCluster*)el;
1444 i_cluster_pos = cluster->GetElementPosition();
1446 // reset silent tracks
1447 for (size_t i=0; i<tracks.size(); i++)
1449 tracks[i]->b_silent = false;
1454 else if( MKV_IS_ID( el, KaxCues ) )
1456 msg_Warn( &sys.demuxer, "find KaxCues FIXME" );
1457 return VLC_EGENERIC;
1461 msg_Dbg( &sys.demuxer, "unknown (%s)", typeid( el ).name() );
1465 if( MKV_IS_ID( el, KaxClusterTimecode ) )
1467 KaxClusterTimecode &ctc = *(KaxClusterTimecode*)el;
1469 ctc.ReadData( es.I_O(), SCOPE_ALL_DATA );
1470 cluster->InitTimecode( uint64( ctc ), i_timescale );
1472 /* add it to the index */
1475 p_indexes[i_index - 1].i_position < (int64_t)cluster->GetElementPosition() ) )
1476 IndexAppendCluster( cluster );
1478 else if( MKV_IS_ID( el, KaxClusterSilentTracks ) )
1482 else if( MKV_IS_ID( el, KaxBlockGroup ) )
1484 i_block_pos = el->GetElementPosition();
1487 else if( MKV_IS_ID( el, KaxSimpleBlock ) )
1489 pp_simpleblock = (KaxSimpleBlock*)el;
1491 pp_simpleblock->ReadData( es.I_O() );
1492 pp_simpleblock->SetParent( *cluster );
1496 if( MKV_IS_ID( el, KaxBlock ) )
1498 pp_block = (KaxBlock*)el;
1500 pp_block->ReadData( es.I_O() );
1501 pp_block->SetParent( *cluster );
1505 else if( MKV_IS_ID( el, KaxBlockDuration ) )
1507 KaxBlockDuration &dur = *(KaxBlockDuration*)el;
1509 dur.ReadData( es.I_O() );
1510 *pi_duration = uint64( dur );
1512 else if( MKV_IS_ID( el, KaxReferenceBlock ) )
1514 KaxReferenceBlock &ref = *(KaxReferenceBlock*)el;
1516 ref.ReadData( es.I_O() );
1518 if( *pb_key_picture )
1519 *pb_key_picture = false;
1520 else if( int64( ref ) > 0 )
1521 *pb_discardable_picture = true;
1523 else if( MKV_IS_ID( el, KaxClusterSilentTrackNumber ) )
1525 KaxClusterSilentTrackNumber &track_num = *(KaxClusterSilentTrackNumber*)el;
1526 track_num.ReadData( es.I_O() );
1528 for (size_t i=0; i<tracks.size(); i++)
1530 if ( tracks[i]->i_number == uint32(track_num))
1532 tracks[i]->b_silent = true;
1539 msg_Err( &sys.demuxer, "invalid level = %d", i_level );
1540 return VLC_EGENERIC;