1 /*****************************************************************************
2 * mkv.cpp : matroska demuxer
3 *****************************************************************************
4 * Copyright (C) 2003-2004 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"
32 #include "../vobsub.h"
35 /* GetFourCC helper */
36 #define GetFOURCC( p ) __GetFOURCC( (uint8_t*)p )
37 static vlc_fourcc_t __GetFOURCC( uint8_t *p )
39 return VLC_FOURCC( p[0], p[1], p[2], p[3] );
43 matroska_segment_c::~matroska_segment_c()
45 for( size_t i_track = 0; i_track < tracks.size(); i_track++ )
47 delete tracks[i_track]->p_compression_data;
48 es_format_Clean( &tracks[i_track]->fmt );
49 free( tracks[i_track]->p_extra_data );
50 free( tracks[i_track]->psz_codec );
51 delete tracks[i_track];
54 free( psz_writing_application );
55 free( psz_muxing_application );
56 free( psz_segment_filename );
64 delete p_prev_segment_uid;
65 delete p_next_segment_uid;
67 std::vector<chapter_edition_c*>::iterator index = stored_editions.begin();
68 while ( index != stored_editions.end() )
73 std::vector<chapter_translation_c*>::iterator indext = translations.begin();
74 while ( indext != translations.end() )
79 std::vector<KaxSegmentFamily*>::iterator indexf = families.begin();
80 while ( indexf != families.end() )
88 /*****************************************************************************
90 * * LoadCues : load the cues element and update index
92 * * LoadTags : load ... the tags element
94 * * InformationCreate : create all information, load tags if present
96 *****************************************************************************/
97 void matroska_segment_c::LoadCues( KaxCues *cues )
104 msg_Err( &sys.demuxer, "There can be only 1 Cues per section." );
108 ep = new EbmlParser( &es, cues, &sys.demuxer );
109 while( ( el = ep->Get() ) != NULL )
111 if( MKV_IS_ID( el, KaxCuePoint ) )
113 #define idx p_indexes[i_index]
116 idx.i_block_number= -1;
122 while( ( el = ep->Get() ) != NULL )
124 if( MKV_IS_ID( el, KaxCueTime ) )
126 KaxCueTime &ctime = *(KaxCueTime*)el;
128 ctime.ReadData( es.I_O() );
130 idx.i_time = uint64( ctime ) * i_timescale / (mtime_t)1000;
132 else if( MKV_IS_ID( el, KaxCueTrackPositions ) )
135 while( ( el = ep->Get() ) != NULL )
137 if( MKV_IS_ID( el, KaxCueTrack ) )
139 KaxCueTrack &ctrack = *(KaxCueTrack*)el;
141 ctrack.ReadData( es.I_O() );
142 idx.i_track = uint16( ctrack );
144 else if( MKV_IS_ID( el, KaxCueClusterPosition ) )
146 KaxCueClusterPosition &ccpos = *(KaxCueClusterPosition*)el;
148 ccpos.ReadData( es.I_O() );
149 idx.i_position = segment->GetGlobalPosition( uint64( ccpos ) );
151 else if( MKV_IS_ID( el, KaxCueBlockNumber ) )
153 KaxCueBlockNumber &cbnum = *(KaxCueBlockNumber*)el;
155 cbnum.ReadData( es.I_O() );
156 idx.i_block_number = uint32( cbnum );
160 msg_Dbg( &sys.demuxer, " * Unknown (%s)", typeid(*el).name() );
167 msg_Dbg( &sys.demuxer, " * Unknown (%s)", typeid(*el).name() );
173 msg_Dbg( &sys.demuxer, " * added time=%"PRId64" pos=%"PRId64
174 " track=%d bnum=%d", idx.i_time, idx.i_position,
175 idx.i_track, idx.i_block_number );
179 if( i_index >= i_index_max )
182 p_indexes = (mkv_index_t*)xrealloc( p_indexes,
183 sizeof( mkv_index_t ) * i_index_max );
189 msg_Dbg( &sys.demuxer, " * Unknown (%s)", typeid(*el).name() );
194 msg_Dbg( &sys.demuxer, "| - loading cues done." );
197 void matroska_segment_c::LoadTags( KaxTags *tags )
202 /* Master elements */
203 ep = new EbmlParser( &es, tags, &sys.demuxer );
205 while( ( el = ep->Get() ) != NULL )
207 if( MKV_IS_ID( el, KaxTag ) )
209 msg_Dbg( &sys.demuxer, "+ Tag" );
211 while( ( el = ep->Get() ) != NULL )
213 if( MKV_IS_ID( el, KaxTagTargets ) )
215 msg_Dbg( &sys.demuxer, "| + Targets" );
217 while( ( el = ep->Get() ) != NULL )
219 msg_Dbg( &sys.demuxer, "| | + Unknown (%s)", typeid( *el ).name() );
223 else if( MKV_IS_ID( el, KaxTagGeneral ) )
225 msg_Dbg( &sys.demuxer, "| + General" );
227 while( ( el = ep->Get() ) != NULL )
229 msg_Dbg( &sys.demuxer, "| | + Unknown (%s)", typeid( *el ).name() );
233 else if( MKV_IS_ID( el, KaxTagGenres ) )
235 msg_Dbg( &sys.demuxer, "| + Genres" );
237 while( ( el = ep->Get() ) != NULL )
239 msg_Dbg( &sys.demuxer, "| | + Unknown (%s)", typeid( *el ).name() );
243 else if( MKV_IS_ID( el, KaxTagAudioSpecific ) )
245 msg_Dbg( &sys.demuxer, "| + Audio Specific" );
247 while( ( el = ep->Get() ) != NULL )
249 msg_Dbg( &sys.demuxer, "| | + Unknown (%s)", typeid( *el ).name() );
253 else if( MKV_IS_ID( el, KaxTagImageSpecific ) )
255 msg_Dbg( &sys.demuxer, "| + Images Specific" );
257 while( ( el = ep->Get() ) != NULL )
259 msg_Dbg( &sys.demuxer, "| | + Unknown (%s)", typeid( *el ).name() );
263 else if( MKV_IS_ID( el, KaxTagMultiComment ) )
265 msg_Dbg( &sys.demuxer, "| + Multi Comment" );
267 else if( MKV_IS_ID( el, KaxTagMultiCommercial ) )
269 msg_Dbg( &sys.demuxer, "| + Multi Commercial" );
271 else if( MKV_IS_ID( el, KaxTagMultiDate ) )
273 msg_Dbg( &sys.demuxer, "| + Multi Date" );
275 else if( MKV_IS_ID( el, KaxTagMultiEntity ) )
277 msg_Dbg( &sys.demuxer, "| + Multi Entity" );
279 else if( MKV_IS_ID( el, KaxTagMultiIdentifier ) )
281 msg_Dbg( &sys.demuxer, "| + Multi Identifier" );
283 else if( MKV_IS_ID( el, KaxTagMultiLegal ) )
285 msg_Dbg( &sys.demuxer, "| + Multi Legal" );
287 else if( MKV_IS_ID( el, KaxTagMultiTitle ) )
289 msg_Dbg( &sys.demuxer, "| + Multi Title" );
293 msg_Dbg( &sys.demuxer, "| + LoadTag Unknown (%s)", typeid( *el ).name() );
300 msg_Dbg( &sys.demuxer, "+ Unknown (%s)", typeid( *el ).name() );
305 msg_Dbg( &sys.demuxer, "loading tags done." );
308 /*****************************************************************************
310 *****************************************************************************/
311 void matroska_segment_c::InformationCreate( )
313 sys.meta = vlc_meta_New();
317 vlc_meta_SetTitle( sys.meta, psz_title );
321 vlc_meta_SetDate( sys.meta, psz_date_utc );
324 if( psz_segment_filename )
326 fprintf( stderr, "***** WARNING: Unhandled meta - Use custom\n" );
328 if( psz_muxing_application )
330 fprintf( stderr, "***** WARNING: Unhandled meta - Use custom\n" );
332 if( psz_writing_application )
334 fprintf( stderr, "***** WARNING: Unhandled meta - Use custom\n" );
337 for( size_t i_track = 0; i_track < tracks.size(); i_track++ )
339 // mkv_track_t *tk = tracks[i_track];
340 // vlc_meta_t *mtk = vlc_meta_New();
341 fprintf( stderr, "***** WARNING: Unhandled child meta\n");
345 if( i_tags_position >= 0 )
349 stream_Control( sys.demuxer.s, STREAM_CAN_FASTSEEK, &b_seekable );
359 /*****************************************************************************
361 *****************************************************************************/
363 void matroska_segment_c::IndexAppendCluster( KaxCluster *cluster )
365 #define idx p_indexes[i_index]
367 idx.i_block_number= -1;
368 idx.i_position = cluster->GetElementPosition();
373 if( i_index >= i_index_max )
376 p_indexes = (mkv_index_t*)xrealloc( p_indexes,
377 sizeof( mkv_index_t ) * i_index_max );
383 bool matroska_segment_c::PreloadFamily( const matroska_segment_c & of_segment )
388 for (size_t i=0; i<families.size(); i++)
390 for (size_t j=0; j<of_segment.families.size(); j++)
392 if ( *(families[i]) == *(of_segment.families[j]) )
400 bool matroska_segment_c::CompareSegmentUIDs( const matroska_segment_c * p_item_a, const matroska_segment_c * p_item_b )
404 if ( p_item_a == NULL || p_item_b == NULL )
407 p_tmp = (EbmlBinary *)p_item_a->p_segment_uid;
408 if ( p_item_b->p_prev_segment_uid != NULL
409 && *p_tmp == *p_item_b->p_prev_segment_uid )
412 p_tmp = (EbmlBinary *)p_item_a->p_next_segment_uid;
416 if ( p_item_b->p_segment_uid != NULL
417 && *p_tmp == *p_item_b->p_segment_uid )
420 if ( p_item_b->p_prev_segment_uid != NULL
421 && *p_tmp == *p_item_b->p_prev_segment_uid )
427 bool matroska_segment_c::Preload( )
432 EbmlElement *el = NULL;
434 ep->Reset( &sys.demuxer );
436 while( ( el = ep->Get() ) != NULL )
438 if( MKV_IS_ID( el, KaxSeekHead ) )
440 /* Multiple allowed */
441 /* We bail at 10, to prevent possible recursion */
442 msg_Dbg( &sys.demuxer, "| + Seek head" );
443 if( i_seekhead_count < 10 )
445 i_seekhead_position = (int64_t) es.I_O().getFilePointer();
446 ParseSeekHead( static_cast<KaxSeekHead*>( el ) );
449 else if( MKV_IS_ID( el, KaxInfo ) )
451 /* Multiple allowed, mandatory */
452 msg_Dbg( &sys.demuxer, "| + Information" );
453 if( i_info_position < 0 ) // FIXME
454 ParseInfo( static_cast<KaxInfo*>( el ) );
455 i_info_position = (int64_t) es.I_O().getFilePointer();
457 else if( MKV_IS_ID( el, KaxTracks ) )
459 /* Multiple allowed */
460 msg_Dbg( &sys.demuxer, "| + Tracks" );
461 if( i_tracks_position < 0 ) // FIXME
462 ParseTracks( static_cast<KaxTracks*>( el ) );
463 if ( tracks.size() == 0 )
465 msg_Err( &sys.demuxer, "No tracks supported" );
468 i_tracks_position = (int64_t) es.I_O().getFilePointer();
470 else if( MKV_IS_ID( el, KaxCues ) )
472 msg_Dbg( &sys.demuxer, "| + Cues" );
473 if( i_cues_position < 0 )
474 LoadCues( static_cast<KaxCues*>( el ) );
475 i_cues_position = (int64_t) es.I_O().getFilePointer();
477 else if( MKV_IS_ID( el, KaxCluster ) )
479 msg_Dbg( &sys.demuxer, "| + Cluster" );
481 cluster = (KaxCluster*)el;
483 i_cluster_pos = i_start_pos = cluster->GetElementPosition();
487 /* stop pre-parsing the stream */
490 else if( MKV_IS_ID( el, KaxAttachments ) )
492 msg_Dbg( &sys.demuxer, "| + Attachments" );
493 if( i_attachments_position < 0 )
494 ParseAttachments( static_cast<KaxAttachments*>( el ) );
495 i_attachments_position = (int64_t) es.I_O().getFilePointer();
497 else if( MKV_IS_ID( el, KaxChapters ) )
499 msg_Dbg( &sys.demuxer, "| + Chapters" );
500 if( i_chapters_position < 0 )
501 ParseChapters( static_cast<KaxChapters*>( el ) );
502 i_chapters_position = (int64_t) es.I_O().getFilePointer();
504 else if( MKV_IS_ID( el, KaxTag ) )
506 msg_Dbg( &sys.demuxer, "| + Tags" );
507 if( i_tags_position < 0) // FIXME
508 ;//LoadTags( static_cast<KaxTags*>( el ) );
509 i_tags_position = (int64_t) es.I_O().getFilePointer();
512 msg_Dbg( &sys.demuxer, "| + Preload Unknown (%s)", typeid(*el).name() );
520 /* Here we try to load elements that were found in Seek Heads, but not yet parsed */
521 bool matroska_segment_c::LoadSeekHeadItem( const EbmlCallbacks & ClassInfos, int64_t i_element_position )
523 int64_t i_sav_position = (int64_t)es.I_O().getFilePointer();
526 es.I_O().setFilePointer( i_element_position, seek_beginning );
527 el = es.FindNextID( ClassInfos, 0xFFFFFFFFL);
531 msg_Err( &sys.demuxer, "cannot load some cues/chapters/tags etc. (broken seekhead or file)" );
532 es.I_O().setFilePointer( i_sav_position, seek_beginning );
536 if( MKV_IS_ID( el, KaxSeekHead ) )
538 /* Multiple allowed */
539 msg_Dbg( &sys.demuxer, "| + Seek head" );
540 if( i_seekhead_count < 10 )
542 i_seekhead_position = i_element_position;
543 ParseSeekHead( static_cast<KaxSeekHead*>( el ) );
546 else if( MKV_IS_ID( el, KaxInfo ) ) // FIXME
548 /* Multiple allowed, mandatory */
549 msg_Dbg( &sys.demuxer, "| + Information" );
550 if( i_info_position < 0 )
551 ParseInfo( static_cast<KaxInfo*>( el ) );
552 i_info_position = i_element_position;
554 else if( MKV_IS_ID( el, KaxTracks ) ) // FIXME
556 /* Multiple allowed */
557 msg_Dbg( &sys.demuxer, "| + Tracks" );
558 if( i_tracks_position < 0 )
559 ParseTracks( static_cast<KaxTracks*>( el ) );
560 if ( tracks.size() == 0 )
562 msg_Err( &sys.demuxer, "No tracks supported" );
564 es.I_O().setFilePointer( i_sav_position, seek_beginning );
567 i_tracks_position = i_element_position;
569 else if( MKV_IS_ID( el, KaxCues ) )
571 msg_Dbg( &sys.demuxer, "| + Cues" );
572 if( i_cues_position < 0 )
573 LoadCues( static_cast<KaxCues*>( el ) );
574 i_cues_position = i_element_position;
576 else if( MKV_IS_ID( el, KaxAttachments ) )
578 msg_Dbg( &sys.demuxer, "| + Attachments" );
579 if( i_attachments_position < 0 )
580 ParseAttachments( static_cast<KaxAttachments*>( el ) );
581 i_attachments_position = i_element_position;
583 else if( MKV_IS_ID( el, KaxChapters ) )
585 msg_Dbg( &sys.demuxer, "| + Chapters" );
586 if( i_chapters_position < 0 )
587 ParseChapters( static_cast<KaxChapters*>( el ) );
588 i_chapters_position = i_element_position;
590 else if( MKV_IS_ID( el, KaxTag ) ) // FIXME
592 msg_Dbg( &sys.demuxer, "| + Tags" );
593 if( i_tags_position < 0 )
594 ;//LoadTags( static_cast<KaxTags*>( el ) );
595 i_tags_position = i_element_position;
599 msg_Dbg( &sys.demuxer, "| + LoadSeekHeadItem Unknown (%s)", typeid(*el).name() );
603 es.I_O().setFilePointer( i_sav_position, seek_beginning );
607 void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_global_position )
610 KaxSimpleBlock *simpleblock;
611 int i_track_skipping;
612 int64_t i_block_duration;
613 int64_t i_block_ref1;
614 int64_t i_block_ref2;
616 int64_t i_seek_position = i_start_pos;
617 int64_t i_seek_time = i_start_time;
619 if( i_global_position >= 0 )
621 /* Special case for seeking in files with no cues */
622 EbmlElement *el = NULL;
623 es.I_O().setFilePointer( i_start_pos, seek_beginning );
625 ep = new EbmlParser( &es, segment, &sys.demuxer );
628 while( ( el = ep->Get() ) != NULL )
630 if( MKV_IS_ID( el, KaxCluster ) )
632 cluster = (KaxCluster *)el;
633 i_cluster_pos = cluster->GetElementPosition();
635 ( i_index > 0 && p_indexes[i_index - 1].i_position < (int64_t)cluster->GetElementPosition() ) )
637 IndexAppendCluster( cluster );
639 if( es.I_O().getFilePointer() >= i_global_position )
642 msg_Dbg( &sys.demuxer, "we found a cluster that is in the neighbourhood" );
647 msg_Err( &sys.demuxer, "This file has no cues, and we were unable to seek to the requested position by parsing." );
655 for( ; i_idx < i_index; i_idx++ )
657 if( p_indexes[i_idx].i_time + i_time_offset > i_date )
668 i_seek_position = p_indexes[i_idx].i_position;
669 i_seek_time = p_indexes[i_idx].i_time;
672 msg_Dbg( &sys.demuxer, "seek got %"PRId64" (%d%%)",
673 i_seek_time, (int)( 100 * i_seek_position / stream_Size( sys.demuxer.s ) ) );
675 es.I_O().setFilePointer( i_seek_position, seek_beginning );
678 ep = new EbmlParser( &es, segment, &sys.demuxer );
681 sys.i_start_pts = i_date;
683 /* now parse until key frame */
684 i_track_skipping = 0;
685 for( i_track = 0; i_track < tracks.size(); i_track++ )
687 if( tracks[i_track]->fmt.i_cat == VIDEO_ES )
689 tracks[i_track]->b_search_keyframe = true;
693 es_out_Control( sys.demuxer.out, ES_OUT_SET_NEXT_DISPLAY_TIME, i_date );
695 while( i_track_skipping > 0 )
697 if( BlockGet( block, simpleblock, &i_block_ref1, &i_block_ref2, &i_block_duration ) )
699 msg_Warn( &sys.demuxer, "cannot get block EOF?" );
704 for( i_track = 0; i_track < tracks.size(); i_track++ )
706 if( (simpleblock && tracks[i_track]->i_number == simpleblock->TrackNum()) ||
707 (block && tracks[i_track]->i_number == block->TrackNum()) )
714 sys.i_pts = (sys.i_chapter_time + simpleblock->GlobalTimecode()) / (mtime_t) 1000;
716 sys.i_pts = (sys.i_chapter_time + block->GlobalTimecode()) / (mtime_t) 1000;
718 if( i_track < tracks.size() )
720 if( sys.i_pts > sys.i_start_pts )
722 cluster = static_cast<KaxCluster*>(ep->UnGet( i_block_pos, i_cluster_pos ));
723 i_track_skipping = 0;
725 else if( tracks[i_track]->fmt.i_cat == VIDEO_ES )
727 if( i_block_ref1 == 0 && tracks[i_track]->b_search_keyframe )
729 tracks[i_track]->b_search_keyframe = false;
732 if( !tracks[i_track]->b_search_keyframe )
734 BlockDecode( &sys.demuxer, block, simpleblock, sys.i_pts, 0, i_block_ref1 >= 0 || i_block_ref2 > 0 );
742 /* FIXME current ES_OUT_SET_NEXT_DISPLAY_TIME does not work that well if
743 * the delay is too high. */
744 if( sys.i_pts + 500*1000 < sys.i_start_pts )
746 sys.i_start_pts = sys.i_pts;
748 es_out_Control( sys.demuxer.out, ES_OUT_SET_NEXT_DISPLAY_TIME, sys.i_start_pts );
753 int matroska_segment_c::BlockFindTrackIndex( size_t *pi_track,
754 const KaxBlock *p_block, const KaxSimpleBlock *p_simpleblock )
758 for( i_track = 0; i_track < tracks.size(); i_track++ )
760 const mkv_track_t *tk = tracks[i_track];
762 if( ( p_block != NULL && tk->i_number == p_block->TrackNum() ) ||
763 ( p_simpleblock != NULL && tk->i_number == p_simpleblock->TrackNum() ) )
769 if( i_track >= tracks.size() )
777 bool matroska_segment_c::Select( mtime_t i_start_time )
782 msg_Dbg( &sys.demuxer, "found %d es", (int)tracks.size() );
783 sys.b_pci_packet_set = false;
785 for( i_track = 0; i_track < tracks.size(); i_track++ )
787 mkv_track_t *p_tk = tracks[i_track];
788 es_format_t *p_fmt = &p_tk->fmt;
790 if( p_fmt->i_cat == UNKNOWN_ES || !p_tk->psz_codec )
792 msg_Warn( &sys.demuxer, "invalid track[%d, n=%d]", (int)i_track, tracks[i_track]->i_number );
793 tracks[i_track]->p_es = NULL;
797 if( !strcmp( tracks[i_track]->psz_codec, "V_MS/VFW/FOURCC" ) )
799 if( tracks[i_track]->i_extra_data < (int)sizeof( BITMAPINFOHEADER ) )
801 msg_Err( &sys.demuxer, "missing/invalid BITMAPINFOHEADER" );
802 tracks[i_track]->fmt.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
806 BITMAPINFOHEADER *p_bih = (BITMAPINFOHEADER*)tracks[i_track]->p_extra_data;
808 tracks[i_track]->fmt.video.i_width = GetDWLE( &p_bih->biWidth );
809 tracks[i_track]->fmt.video.i_height= GetDWLE( &p_bih->biHeight );
810 tracks[i_track]->fmt.i_codec = GetFOURCC( &p_bih->biCompression );
812 tracks[i_track]->fmt.i_extra = GetDWLE( &p_bih->biSize ) - sizeof( BITMAPINFOHEADER );
813 if( tracks[i_track]->fmt.i_extra > 0 )
815 tracks[i_track]->fmt.p_extra = xmalloc( tracks[i_track]->fmt.i_extra );
816 memcpy( tracks[i_track]->fmt.p_extra, &p_bih[1], tracks[i_track]->fmt.i_extra );
819 p_tk->b_dts_only = true;
821 else if( !strcmp( tracks[i_track]->psz_codec, "V_MPEG1" ) ||
822 !strcmp( tracks[i_track]->psz_codec, "V_MPEG2" ) )
824 tracks[i_track]->fmt.i_codec = VLC_CODEC_MPGV;
826 else if( !strncmp( tracks[i_track]->psz_codec, "V_THEORA", 8 ) )
828 tracks[i_track]->fmt.i_codec = VLC_CODEC_THEORA;
829 tracks[i_track]->fmt.i_extra = tracks[i_track]->i_extra_data;
830 tracks[i_track]->fmt.p_extra = xmalloc( tracks[i_track]->i_extra_data );
831 memcpy( tracks[i_track]->fmt.p_extra,tracks[i_track]->p_extra_data, tracks[i_track]->i_extra_data );
833 else if( !strncmp( tracks[i_track]->psz_codec, "V_REAL/RV", 9 ) )
835 if( !strcmp( p_tk->psz_codec, "V_REAL/RV10" ) )
836 p_fmt->i_codec = VLC_CODEC_RV10;
837 else if( !strcmp( p_tk->psz_codec, "V_REAL/RV20" ) )
838 p_fmt->i_codec = VLC_CODEC_RV20;
839 else if( !strcmp( p_tk->psz_codec, "V_REAL/RV30" ) )
840 p_fmt->i_codec = VLC_CODEC_RV30;
841 else if( !strcmp( p_tk->psz_codec, "V_REAL/RV40" ) )
842 p_fmt->i_codec = VLC_CODEC_RV40;
844 if( p_tk->i_extra_data > 26 )
846 p_fmt->p_extra = malloc( p_tk->i_extra_data - 26 );
849 p_fmt->i_extra = p_tk->i_extra_data - 26;
850 memcpy( p_fmt->p_extra, &p_tk->p_extra_data[26], p_fmt->i_extra );
853 p_tk->b_dts_only = true;
855 else if( !strncmp( tracks[i_track]->psz_codec, "V_DIRAC", 7 ) )
857 tracks[i_track]->fmt.i_codec = VLC_CODEC_DIRAC;
859 else if( !strncmp( tracks[i_track]->psz_codec, "V_MPEG4", 7 ) )
861 if( !strcmp( tracks[i_track]->psz_codec, "V_MPEG4/MS/V3" ) )
863 tracks[i_track]->fmt.i_codec = VLC_CODEC_DIV3;
865 else if( !strncmp( tracks[i_track]->psz_codec, "V_MPEG4/ISO", 11 ) )
867 /* A MPEG 4 codec, SP, ASP, AP or AVC */
868 if( !strcmp( tracks[i_track]->psz_codec, "V_MPEG4/ISO/AVC" ) )
869 tracks[i_track]->fmt.i_codec = VLC_FOURCC( 'a', 'v', 'c', '1' );
871 tracks[i_track]->fmt.i_codec = VLC_CODEC_MP4V;
872 tracks[i_track]->fmt.i_extra = tracks[i_track]->i_extra_data;
873 tracks[i_track]->fmt.p_extra = xmalloc( tracks[i_track]->i_extra_data );
874 memcpy( tracks[i_track]->fmt.p_extra,tracks[i_track]->p_extra_data, tracks[i_track]->i_extra_data );
877 else if( !strcmp( tracks[i_track]->psz_codec, "V_QUICKTIME" ) )
879 MP4_Box_t *p_box = (MP4_Box_t*)xmalloc( sizeof( MP4_Box_t ) );
880 stream_t *p_mp4_stream = stream_MemoryNew( VLC_OBJECT(&sys.demuxer),
881 tracks[i_track]->p_extra_data,
882 tracks[i_track]->i_extra_data,
884 if( MP4_ReadBoxCommon( p_mp4_stream, p_box ) &&
885 MP4_ReadBox_sample_vide( p_mp4_stream, p_box ) )
887 tracks[i_track]->fmt.i_codec = p_box->i_type;
888 tracks[i_track]->fmt.video.i_width = p_box->data.p_sample_vide->i_width;
889 tracks[i_track]->fmt.video.i_height = p_box->data.p_sample_vide->i_height;
890 tracks[i_track]->fmt.i_extra = p_box->data.p_sample_vide->i_qt_image_description;
891 tracks[i_track]->fmt.p_extra = xmalloc( tracks[i_track]->fmt.i_extra );
892 memcpy( tracks[i_track]->fmt.p_extra, p_box->data.p_sample_vide->p_qt_image_description, tracks[i_track]->fmt.i_extra );
893 MP4_FreeBox_sample_vide( p_box );
899 stream_Delete( p_mp4_stream );
901 else if( !strcmp( tracks[i_track]->psz_codec, "A_MS/ACM" ) )
903 if( tracks[i_track]->i_extra_data < (int)sizeof( WAVEFORMATEX ) )
905 msg_Err( &sys.demuxer, "missing/invalid WAVEFORMATEX" );
906 tracks[i_track]->fmt.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
910 WAVEFORMATEX *p_wf = (WAVEFORMATEX*)tracks[i_track]->p_extra_data;
912 wf_tag_to_fourcc( GetWLE( &p_wf->wFormatTag ), &tracks[i_track]->fmt.i_codec, NULL );
914 tracks[i_track]->fmt.audio.i_channels = GetWLE( &p_wf->nChannels );
915 tracks[i_track]->fmt.audio.i_rate = GetDWLE( &p_wf->nSamplesPerSec );
916 tracks[i_track]->fmt.i_bitrate = GetDWLE( &p_wf->nAvgBytesPerSec ) * 8;
917 tracks[i_track]->fmt.audio.i_blockalign = GetWLE( &p_wf->nBlockAlign );;
918 tracks[i_track]->fmt.audio.i_bitspersample = GetWLE( &p_wf->wBitsPerSample );
920 tracks[i_track]->fmt.i_extra = GetWLE( &p_wf->cbSize );
921 if( tracks[i_track]->fmt.i_extra > 0 )
923 tracks[i_track]->fmt.p_extra = xmalloc( tracks[i_track]->fmt.i_extra );
924 memcpy( tracks[i_track]->fmt.p_extra, &p_wf[1], tracks[i_track]->fmt.i_extra );
928 else if( !strcmp( tracks[i_track]->psz_codec, "A_MPEG/L3" ) ||
929 !strcmp( tracks[i_track]->psz_codec, "A_MPEG/L2" ) ||
930 !strcmp( tracks[i_track]->psz_codec, "A_MPEG/L1" ) )
932 tracks[i_track]->fmt.i_codec = VLC_CODEC_MPGA;
934 else if( !strcmp( tracks[i_track]->psz_codec, "A_AC3" ) )
936 tracks[i_track]->fmt.i_codec = VLC_CODEC_A52;
938 else if( !strcmp( tracks[i_track]->psz_codec, "A_EAC3" ) )
940 tracks[i_track]->fmt.i_codec = VLC_CODEC_EAC3;
942 else if( !strcmp( tracks[i_track]->psz_codec, "A_DTS" ) )
944 tracks[i_track]->fmt.i_codec = VLC_CODEC_DTS;
946 else if( !strcmp( tracks[i_track]->psz_codec, "A_MLP" ) )
948 tracks[i_track]->fmt.i_codec = VLC_CODEC_MLP;
950 else if( !strcmp( tracks[i_track]->psz_codec, "A_TRUEHD" ) )
952 /* FIXME when more samples arrive */
953 tracks[i_track]->fmt.i_codec = VLC_CODEC_TRUEHD;
954 p_fmt->b_packetized = false;
956 else if( !strcmp( tracks[i_track]->psz_codec, "A_FLAC" ) )
958 tracks[i_track]->fmt.i_codec = VLC_CODEC_FLAC;
959 tracks[i_track]->fmt.i_extra = tracks[i_track]->i_extra_data;
960 tracks[i_track]->fmt.p_extra = xmalloc( tracks[i_track]->i_extra_data );
961 memcpy( tracks[i_track]->fmt.p_extra,tracks[i_track]->p_extra_data, tracks[i_track]->i_extra_data );
963 else if( !strcmp( tracks[i_track]->psz_codec, "A_VORBIS" ) )
965 tracks[i_track]->fmt.i_codec = VLC_CODEC_VORBIS;
966 tracks[i_track]->fmt.i_extra = tracks[i_track]->i_extra_data;
967 tracks[i_track]->fmt.p_extra = xmalloc( tracks[i_track]->i_extra_data );
968 memcpy( tracks[i_track]->fmt.p_extra,tracks[i_track]->p_extra_data, tracks[i_track]->i_extra_data );
970 else if( !strncmp( tracks[i_track]->psz_codec, "A_AAC/MPEG2/", strlen( "A_AAC/MPEG2/" ) ) ||
971 !strncmp( tracks[i_track]->psz_codec, "A_AAC/MPEG4/", strlen( "A_AAC/MPEG4/" ) ) )
973 int i_profile, i_srate, sbr = 0;
974 static const unsigned int i_sample_rates[] =
976 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
977 16000, 12000, 11025, 8000, 7350, 0, 0, 0
980 tracks[i_track]->fmt.i_codec = VLC_CODEC_MP4A;
981 /* create data for faad (MP4DecSpecificDescrTag)*/
983 if( !strcmp( &tracks[i_track]->psz_codec[12], "MAIN" ) )
987 else if( !strcmp( &tracks[i_track]->psz_codec[12], "LC" ) )
991 else if( !strcmp( &tracks[i_track]->psz_codec[12], "SSR" ) )
995 else if( !strcmp( &tracks[i_track]->psz_codec[12], "LC/SBR" ) )
1005 for( i_srate = 0; i_srate < 13; i_srate++ )
1007 if( i_sample_rates[i_srate] == tracks[i_track]->i_original_rate )
1012 msg_Dbg( &sys.demuxer, "profile=%d srate=%d", i_profile, i_srate );
1014 tracks[i_track]->fmt.i_extra = sbr ? 5 : 2;
1015 tracks[i_track]->fmt.p_extra = xmalloc( tracks[i_track]->fmt.i_extra );
1016 ((uint8_t*)tracks[i_track]->fmt.p_extra)[0] = ((i_profile + 1) << 3) | ((i_srate&0xe) >> 1);
1017 ((uint8_t*)tracks[i_track]->fmt.p_extra)[1] = ((i_srate & 0x1) << 7) | (tracks[i_track]->fmt.audio.i_channels << 3);
1020 int syncExtensionType = 0x2B7;
1022 for (iDSRI=0; iDSRI<13; iDSRI++)
1023 if( i_sample_rates[iDSRI] == tracks[i_track]->fmt.audio.i_rate )
1025 ((uint8_t*)tracks[i_track]->fmt.p_extra)[2] = (syncExtensionType >> 3) & 0xFF;
1026 ((uint8_t*)tracks[i_track]->fmt.p_extra)[3] = ((syncExtensionType & 0x7) << 5) | 5;
1027 ((uint8_t*)tracks[i_track]->fmt.p_extra)[4] = ((1 & 0x1) << 7) | (iDSRI << 3);
1030 else if( !strcmp( tracks[i_track]->psz_codec, "A_AAC" ) )
1032 tracks[i_track]->fmt.i_codec = VLC_CODEC_MP4A;
1033 tracks[i_track]->fmt.i_extra = tracks[i_track]->i_extra_data;
1034 tracks[i_track]->fmt.p_extra = xmalloc( tracks[i_track]->i_extra_data );
1035 memcpy( tracks[i_track]->fmt.p_extra, tracks[i_track]->p_extra_data, tracks[i_track]->i_extra_data );
1037 else if( !strcmp( tracks[i_track]->psz_codec, "A_WAVPACK4" ) )
1039 tracks[i_track]->fmt.i_codec = VLC_CODEC_WAVPACK;
1040 tracks[i_track]->fmt.i_extra = tracks[i_track]->i_extra_data;
1041 tracks[i_track]->fmt.p_extra = xmalloc( tracks[i_track]->i_extra_data );
1042 memcpy( tracks[i_track]->fmt.p_extra, tracks[i_track]->p_extra_data, tracks[i_track]->i_extra_data );
1044 else if( !strcmp( tracks[i_track]->psz_codec, "A_TTA1" ) )
1046 p_fmt->i_codec = VLC_CODEC_TTA;
1047 p_fmt->i_extra = p_tk->i_extra_data;
1048 if( p_fmt->i_extra > 0 )
1050 p_fmt->p_extra = xmalloc( p_tk->i_extra_data );
1051 memcpy( p_fmt->p_extra, p_tk->p_extra_data, p_tk->i_extra_data );
1055 p_fmt->i_extra = 30;
1056 p_fmt->p_extra = xmalloc( p_fmt->i_extra );
1057 uint8_t *p_extra = (uint8_t*)p_fmt->p_extra;
1058 memcpy( &p_extra[ 0], "TTA1", 4 );
1059 SetWLE( &p_extra[ 4], 1 );
1060 SetWLE( &p_extra[ 6], p_fmt->audio.i_channels );
1061 SetWLE( &p_extra[ 8], p_fmt->audio.i_bitspersample );
1062 SetDWLE( &p_extra[10], p_fmt->audio.i_rate );
1063 SetDWLE( &p_extra[14], 0xffffffff );
1064 memset( &p_extra[18], 0, 30 - 18 );
1067 else if( !strcmp( tracks[i_track]->psz_codec, "A_PCM/INT/BIG" ) ||
1068 !strcmp( tracks[i_track]->psz_codec, "A_PCM/INT/LIT" ) ||
1069 !strcmp( tracks[i_track]->psz_codec, "A_PCM/FLOAT/IEEE" ) )
1071 if( !strcmp( tracks[i_track]->psz_codec, "A_PCM/INT/BIG" ) )
1073 tracks[i_track]->fmt.i_codec = VLC_FOURCC( 't', 'w', 'o', 's' );
1077 tracks[i_track]->fmt.i_codec = VLC_FOURCC( 'a', 'r', 'a', 'w' );
1079 tracks[i_track]->fmt.audio.i_blockalign = ( tracks[i_track]->fmt.audio.i_bitspersample + 7 ) / 8 * tracks[i_track]->fmt.audio.i_channels;
1081 else if( !strncmp( tracks[i_track]->psz_codec, "A_REAL/", 7 ) )
1083 if( !strcmp( tracks[i_track]->psz_codec, "A_REAL/COOK" ) )
1084 tracks[i_track]->fmt.i_codec = VLC_CODEC_COOK;
1085 tracks[i_track]->fmt.i_extra = tracks[i_track]->i_extra_data;
1086 tracks[i_track]->fmt.p_extra = xmalloc( tracks[i_track]->i_extra_data );
1087 memcpy( tracks[i_track]->fmt.p_extra,tracks[i_track]->p_extra_data, tracks[i_track]->i_extra_data );
1089 /* disabled due to the potential "S_KATE" namespace issue */
1090 else if( !strcmp( tracks[i_track]->psz_codec, "S_KATE" ) )
1092 int i, i_offset = 1, i_extra, num_headers, size_so_far;
1095 tracks[i_track]->fmt.i_codec = VLC_CODEC_KATE;
1096 tracks[i_track]->fmt.subs.psz_encoding = strdup( "UTF-8" );
1098 tracks[i_track]->fmt.i_extra = tracks[i_track]->i_extra_data;
1099 tracks[i_track]->fmt.p_extra = xmalloc( tracks[i_track]->i_extra_data );
1100 memcpy( tracks[i_track]->fmt.p_extra,tracks[i_track]->p_extra_data, tracks[i_track]->i_extra_data );
1102 else if( !strcmp( tracks[i_track]->psz_codec, "S_TEXT/ASCII" ) )
1104 p_fmt->i_codec = VLC_CODEC_SUBT;
1105 p_fmt->subs.psz_encoding = NULL; /* Is there a place where it is stored ? */
1107 else if( !strcmp( tracks[i_track]->psz_codec, "S_TEXT/UTF8" ) )
1109 tracks[i_track]->fmt.i_codec = VLC_CODEC_SUBT;
1110 tracks[i_track]->fmt.subs.psz_encoding = strdup( "UTF-8" );
1112 else if( !strcmp( tracks[i_track]->psz_codec, "S_TEXT/USF" ) )
1114 tracks[i_track]->fmt.i_codec = VLC_FOURCC( 'u', 's', 'f', ' ' );
1115 tracks[i_track]->fmt.subs.psz_encoding = strdup( "UTF-8" );
1116 if( tracks[i_track]->i_extra_data )
1118 tracks[i_track]->fmt.i_extra = tracks[i_track]->i_extra_data;
1119 tracks[i_track]->fmt.p_extra = xmalloc( tracks[i_track]->i_extra_data );
1120 memcpy( tracks[i_track]->fmt.p_extra, tracks[i_track]->p_extra_data, tracks[i_track]->i_extra_data );
1123 else if( !strcmp( tracks[i_track]->psz_codec, "S_TEXT/SSA" ) ||
1124 !strcmp( tracks[i_track]->psz_codec, "S_TEXT/ASS" ) ||
1125 !strcmp( tracks[i_track]->psz_codec, "S_SSA" ) ||
1126 !strcmp( tracks[i_track]->psz_codec, "S_ASS" ))
1128 tracks[i_track]->fmt.i_codec = VLC_CODEC_SSA;
1129 tracks[i_track]->fmt.subs.psz_encoding = strdup( "UTF-8" );
1130 if( tracks[i_track]->i_extra_data )
1132 tracks[i_track]->fmt.i_extra = tracks[i_track]->i_extra_data;
1133 tracks[i_track]->fmt.p_extra = xmalloc( tracks[i_track]->i_extra_data );
1134 memcpy( tracks[i_track]->fmt.p_extra, tracks[i_track]->p_extra_data, tracks[i_track]->i_extra_data );
1137 else if( !strcmp( tracks[i_track]->psz_codec, "S_VOBSUB" ) )
1139 tracks[i_track]->fmt.i_codec = VLC_CODEC_SPU;
1140 if( tracks[i_track]->i_extra_data )
1143 char *psz_buf = (char *)malloc( tracks[i_track]->i_extra_data + 1);
1144 if( psz_buf != NULL )
1146 memcpy( psz_buf, tracks[i_track]->p_extra_data , tracks[i_track]->i_extra_data );
1147 psz_buf[tracks[i_track]->i_extra_data] = '\0';
1149 psz_start = strstr( psz_buf, "size:" );
1151 vobsub_size_parse( psz_start,
1152 &tracks[i_track]->fmt.subs.spu.i_original_frame_width,
1153 &tracks[i_track]->fmt.subs.spu.i_original_frame_height ) == VLC_SUCCESS )
1155 msg_Dbg( &sys.demuxer, "original frame size vobsubs: %dx%d",
1156 tracks[i_track]->fmt.subs.spu.i_original_frame_width,
1157 tracks[i_track]->fmt.subs.spu.i_original_frame_height );
1161 msg_Warn( &sys.demuxer, "reading original frame size for vobsub failed" );
1164 psz_start = strstr( psz_buf, "palette:" );
1166 vobsub_palette_parse( psz_start, &tracks[i_track]->fmt.subs.spu.palette[1] ) == VLC_SUCCESS )
1168 tracks[i_track]->fmt.subs.spu.palette[0] = 0xBeef;
1169 msg_Dbg( &sys.demuxer, "vobsub palette read" );
1173 msg_Warn( &sys.demuxer, "reading original palette failed" );
1179 else if( !strcmp( tracks[i_track]->psz_codec, "S_HDMV/PGS" ) )
1181 tracks[i_track]->fmt.i_codec = VLC_CODEC_BD_PG;
1183 else if( !strcmp( tracks[i_track]->psz_codec, "B_VOBBTN" ) )
1185 tracks[i_track]->fmt.i_cat = NAV_ES;
1188 else if( !strcmp( p_tk->psz_codec, "A_REAL/14_4" ) )
1190 p_fmt->i_codec = VLC_CODEC_RA_144;
1191 p_fmt->audio.i_channels = 1;
1192 p_fmt->audio.i_rate = 8000;
1193 p_fmt->audio.i_blockalign = 0x14;
1197 msg_Err( &sys.demuxer, "unknown codec id=`%s'", tracks[i_track]->psz_codec );
1198 tracks[i_track]->fmt.i_codec = VLC_FOURCC( 'u', 'n', 'd', 'f' );
1200 if( tracks[i_track]->b_default )
1202 tracks[i_track]->fmt.i_priority = 1000;
1205 tracks[i_track]->p_es = es_out_Add( sys.demuxer.out, &tracks[i_track]->fmt );
1207 /* Turn on a subtitles track if it has been flagged as default -
1208 * but only do this if no subtitles track has already been engaged,
1209 * either by an earlier 'default track' (??) or by default
1210 * language choice behaviour.
1212 if( tracks[i_track]->b_default )
1214 es_out_Control( sys.demuxer.out,
1215 ES_OUT_SET_ES_DEFAULT,
1216 tracks[i_track]->p_es );
1219 es_out_Control( sys.demuxer.out, ES_OUT_SET_NEXT_DISPLAY_TIME, i_start_time );
1221 sys.i_start_pts = i_start_time;
1222 // reset the stream reading to the first cluster of the segment used
1223 es.I_O().setFilePointer( i_start_pos );
1226 ep = new EbmlParser( &es, segment, &sys.demuxer );
1231 void matroska_segment_c::UnSelect( )
1235 for( i_track = 0; i_track < tracks.size(); i_track++ )
1237 if ( tracks[i_track]->p_es != NULL )
1239 // es_format_Clean( &tracks[i_track]->fmt );
1240 es_out_Del( sys.demuxer.out, tracks[i_track]->p_es );
1241 tracks[i_track]->p_es = NULL;
1248 int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_simpleblock, int64_t *pi_ref1, int64_t *pi_ref2, int64_t *pi_duration )
1250 pp_simpleblock = NULL;
1257 EbmlElement *el = NULL;
1261 return VLC_EGENERIC;
1263 if( pp_simpleblock != NULL || ((el = ep->Get()) == NULL && pp_block != NULL) )
1265 /* Check blocks validity to protect againts broken files */
1266 if( BlockFindTrackIndex( NULL, pp_block , pp_simpleblock ) )
1269 pp_simpleblock = NULL;
1274 /* update the index */
1275 #define idx p_indexes[i_index - 1]
1276 if( i_index > 0 && idx.i_time == -1 )
1278 if ( pp_simpleblock != NULL )
1279 idx.i_time = pp_simpleblock->GlobalTimecode() / (mtime_t)1000;
1281 idx.i_time = (*pp_block).GlobalTimecode() / (mtime_t)1000;
1282 idx.b_key = *pi_ref1 == 0 ? true : false;
1288 i_level = ep->GetLevel();
1297 msg_Warn( &sys.demuxer, "EOF" );
1298 return VLC_EGENERIC;
1301 /* Verify that we are still inside our cluster
1302 * It can happens whith broken files and when seeking
1306 if( cluster && !ep->IsTopPresent( cluster ) )
1308 msg_Warn( &sys.demuxer, "Unexpected escape from current cluster" );
1319 if( MKV_IS_ID( el, KaxCluster ) )
1321 cluster = (KaxCluster*)el;
1322 i_cluster_pos = cluster->GetElementPosition();
1324 /* add it to the index */
1326 ( i_index > 0 && p_indexes[i_index - 1].i_position < (int64_t)cluster->GetElementPosition() ) )
1328 IndexAppendCluster( cluster );
1331 // reset silent tracks
1332 for (size_t i=0; i<tracks.size(); i++)
1334 tracks[i]->b_silent = false;
1339 else if( MKV_IS_ID( el, KaxCues ) )
1341 msg_Warn( &sys.demuxer, "find KaxCues FIXME" );
1342 return VLC_EGENERIC;
1346 msg_Dbg( &sys.demuxer, "unknown (%s)", typeid( el ).name() );
1350 if( MKV_IS_ID( el, KaxClusterTimecode ) )
1352 KaxClusterTimecode &ctc = *(KaxClusterTimecode*)el;
1354 ctc.ReadData( es.I_O(), SCOPE_ALL_DATA );
1355 cluster->InitTimecode( uint64( ctc ), i_timescale );
1357 else if( MKV_IS_ID( el, KaxClusterSilentTracks ) )
1361 else if( MKV_IS_ID( el, KaxBlockGroup ) )
1363 i_block_pos = el->GetElementPosition();
1366 else if( MKV_IS_ID( el, KaxSimpleBlock ) )
1368 pp_simpleblock = (KaxSimpleBlock*)el;
1370 pp_simpleblock->ReadData( es.I_O() );
1371 pp_simpleblock->SetParent( *cluster );
1375 if( MKV_IS_ID( el, KaxBlock ) )
1377 pp_block = (KaxBlock*)el;
1379 pp_block->ReadData( es.I_O() );
1380 pp_block->SetParent( *cluster );
1384 else if( MKV_IS_ID( el, KaxBlockDuration ) )
1386 KaxBlockDuration &dur = *(KaxBlockDuration*)el;
1388 dur.ReadData( es.I_O() );
1389 *pi_duration = uint64( dur );
1391 else if( MKV_IS_ID( el, KaxReferenceBlock ) )
1393 KaxReferenceBlock &ref = *(KaxReferenceBlock*)el;
1395 ref.ReadData( es.I_O() );
1398 *pi_ref1 = int64( ref ) * cluster->GlobalTimecodeScale();
1400 else if( *pi_ref2 == 0 )
1402 *pi_ref2 = int64( ref ) * cluster->GlobalTimecodeScale();
1405 else if( MKV_IS_ID( el, KaxClusterSilentTrackNumber ) )
1407 KaxClusterSilentTrackNumber &track_num = *(KaxClusterSilentTrackNumber*)el;
1408 track_num.ReadData( es.I_O() );
1410 for (size_t i=0; i<tracks.size(); i++)
1412 if ( tracks[i]->i_number == uint32(track_num))
1414 tracks[i]->b_silent = true;
1421 msg_Err( &sys.demuxer, "invalid level = %d", i_level );
1422 return VLC_EGENERIC;