1 /*****************************************************************************
2 * mp4.c : MP4 file input module for vlc
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: mp4.c,v 1.54 2004/01/18 18:31:50 fenrir Exp $
6 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
23 /*****************************************************************************
25 *****************************************************************************/
26 #include <stdlib.h> /* malloc(), free() */
29 #include <vlc/input.h>
30 #include <vlc_playlist.h>
37 /*****************************************************************************
39 *****************************************************************************/
40 static int Open ( vlc_object_t * );
41 static void Close( vlc_object_t * );
44 set_description( _("MP4 demuxer") );
45 set_capability( "demux", 242 );
46 set_callbacks( Open, Close );
49 /*****************************************************************************
51 *****************************************************************************/
52 static int Demux ( input_thread_t * );
53 static int DemuxRef( input_thread_t *p_input )
57 static int Seek ( input_thread_t *, mtime_t );
58 static int Control ( input_thread_t *, int, va_list );
60 /*****************************************************************************
61 * Declaration of local function
62 *****************************************************************************/
63 static void MP4_TrackCreate ( input_thread_t *, mp4_track_t *, MP4_Box_t *);
64 static void MP4_TrackDestroy( input_thread_t *, mp4_track_t * );
66 static int MP4_TrackSelect ( input_thread_t *, mp4_track_t *, mtime_t );
67 static void MP4_TrackUnselect(input_thread_t *, mp4_track_t * );
69 static int MP4_TrackSeek ( input_thread_t *, mp4_track_t *, mtime_t );
71 static uint64_t MP4_TrackGetPos ( mp4_track_t * );
72 static int MP4_TrackSampleSize( mp4_track_t * );
73 static int MP4_TrackNextSample( input_thread_t *, mp4_track_t * );
75 /* Return time in µs of a track */
76 static inline mtime_t MP4_TrackGetPTS( mp4_track_t *p_track )
78 unsigned int i_sample;
82 i_sample = p_track->i_sample - p_track->chunk[p_track->i_chunk].i_sample_first;
83 i_dts = p_track->chunk[p_track->i_chunk].i_first_dts;
87 if( i_sample > p_track->chunk[p_track->i_chunk].p_sample_count_dts[i_index] )
89 i_dts += p_track->chunk[p_track->i_chunk].p_sample_count_dts[i_index] *
90 p_track->chunk[p_track->i_chunk].p_sample_delta_dts[i_index];
91 i_sample -= p_track->chunk[p_track->i_chunk].p_sample_count_dts[i_index];
97 p_track->chunk[p_track->i_chunk].p_sample_delta_dts[i_index];
103 return (int64_t)1000000 * i_dts / p_track->i_timescale;
105 static inline int64_t MP4_GetMoviePTS(demux_sys_t *p_sys )
107 return (int64_t)1000000 * p_sys->i_time / p_sys->i_timescale;
110 static char *LanguageGetName( const char *psz_code );
112 #define FREE( p ) if( p ) { free( p ); (p) = NULL;}
114 /*****************************************************************************
115 * Open: check file and initializes MP4 structures
116 *****************************************************************************/
117 static int Open( vlc_object_t * p_this )
119 input_thread_t *p_input = (input_thread_t *)p_this;
130 vlc_bool_t b_seekable;
132 /* a little test to see if it could be a mp4 */
133 if( stream_Peek( p_input->s, &p_peek, 8 ) < 8 )
135 msg_Warn( p_input, "MP4 plugin discarded (cannot peek)" );
138 switch( VLC_FOURCC( p_peek[4], p_peek[5], p_peek[6], p_peek[7] ) )
149 case VLC_FOURCC( 'p', 'n', 'o', 't' ):
152 msg_Warn( p_input, "MP4 plugin discarded (not a valid file)" );
157 stream_Control( p_input->s, STREAM_CAN_SEEK, &b_seekable );
160 msg_Warn( p_input, "MP4 plugin discarded (unseekable)" );
164 /*Set exported functions */
165 p_input->pf_demux = Demux;
166 p_input->pf_demux_control = Control;
168 /* create our structure that will contains all data */
169 p_input->p_demux_data = p_sys = malloc( sizeof( demux_sys_t ) );
170 memset( p_sys, 0, sizeof( demux_sys_t ) );
172 /* Now load all boxes ( except raw data ) */
173 if( ( p_sys->p_root = MP4_BoxGetRoot( p_input ) ) == NULL )
175 msg_Warn( p_input, "MP4 plugin discarded (not a valid file)" );
179 MP4_BoxDumpStructure( p_input, p_sys->p_root );
181 if( ( p_ftyp = MP4_BoxGet( p_sys->p_root, "/ftyp" ) ) )
183 switch( p_ftyp->data.p_ftyp->i_major_brand )
187 "ISO Media file (isom) version %d.",
188 p_ftyp->data.p_ftyp->i_minor_version );
192 "unrecognized major file specification (%4.4s).",
193 (char*)&p_ftyp->data.p_ftyp->i_major_brand );
199 msg_Dbg( p_input, "file type box missing (assuming ISO Media file)" );
202 /* the file need to have one moov box */
203 if( MP4_BoxCount( p_sys->p_root, "/moov" ) <= 0 )
205 MP4_Box_t *p_foov = MP4_BoxGet( p_sys->p_root, "/foov" );
209 msg_Err( p_input, "MP4 plugin discarded (no moov box)" );
212 /* we have a free box as a moov, rename it */
213 p_foov->i_type = FOURCC_moov;
216 if( ( p_rmra = MP4_BoxGet( p_sys->p_root, "/moov/rmra" ) ) )
218 playlist_t *p_playlist;
219 int i_count = MP4_BoxCount( p_rmra, "rmda" );
222 msg_Dbg( p_input, "detected playlist mov file (%d ref)", i_count );
225 (playlist_t *)vlc_object_find( p_input,
230 //p_playlist->pp_items[p_playlist->i_index]->b_autodeletion = VLC_TRUE;
231 for( i = 0; i < i_count; i++ )
233 MP4_Box_t *p_rdrf = MP4_BoxGet( p_rmra, "rmda[%d]/rdrf", i );
237 if( !p_rdrf || !( psz_ref = p_rdrf->data.p_rdrf->psz_ref ) )
241 i_ref_type = p_rdrf->data.p_rdrf->i_ref_type;
243 msg_Dbg( p_input, "new ref=`%s' type=%4.4s",
244 psz_ref, (char*)&i_ref_type );
246 if( i_ref_type == VLC_FOURCC( 'u', 'r', 'l', ' ' ) )
248 if( strstr( psz_ref, "qt5gateQT" ) )
250 msg_Dbg( p_input, "ignoring pseudo ref =`%s'", psz_ref );
253 if( !strncmp( psz_ref, "http://", 7 ) ||
254 !strncmp( psz_ref, "rtsp://", 7 ) )
256 msg_Dbg( p_input, "adding ref = `%s'", psz_ref );
257 playlist_Add( p_playlist, psz_ref, psz_ref,
258 PLAYLIST_APPEND, PLAYLIST_END );
262 /* msg dbg relative ? */
263 char *psz_absolute = alloca( strlen( p_input->psz_source ) + strlen( psz_ref ) + 1);
264 char *end = strrchr( p_input->psz_source, '/' );
268 int i_len = end + 1 - p_input->psz_source;
270 strncpy( psz_absolute, p_input->psz_source, i_len);
271 psz_absolute[i_len] = '\0';
275 strcpy( psz_absolute, "" );
277 strcat( psz_absolute, psz_ref );
278 msg_Dbg( p_input, "adding ref = `%s'", psz_absolute );
279 playlist_Add( p_playlist, psz_absolute, psz_absolute,
280 PLAYLIST_APPEND, PLAYLIST_END );
285 msg_Err( p_input, "unknown ref type=%4.4s FIXME (send a bug report)",
286 (char*)&p_rdrf->data.p_rdrf->i_ref_type );
289 vlc_object_release( p_playlist );
293 msg_Err( p_input, "can't find playlist" );
297 if( !(p_mvhd = MP4_BoxGet( p_sys->p_root, "/moov/mvhd" ) ) )
301 msg_Err( p_input, "cannot find /moov/mvhd" );
306 msg_Warn( p_input, "cannot find /moov/mvhd (pure ref file)" );
307 p_input->pf_demux = DemuxRef;
313 p_sys->i_timescale = p_mvhd->data.p_mvhd->i_timescale;
314 p_sys->i_duration = p_mvhd->data.p_mvhd->i_duration;
317 if( !( p_sys->i_tracks = MP4_BoxCount( p_sys->p_root, "/moov/trak" ) ) )
319 msg_Err( p_input, "cannot find any /moov/trak" );
322 msg_Dbg( p_input, "find %d track%c",
324 p_sys->i_tracks ? 's':' ' );
326 /* create one program */
327 vlc_mutex_lock( &p_input->stream.stream_lock );
328 if( input_InitStream( p_input, 0 ) == -1)
330 vlc_mutex_unlock( &p_input->stream.stream_lock );
331 msg_Err( p_input, "cannot init stream" );
334 if( p_sys->i_duration/p_sys->i_timescale > 0 )
336 p_input->stream.i_mux_rate =
337 p_input->stream.p_selected_area->i_size / 50 /
338 ( p_sys->i_duration / p_sys->i_timescale );
342 p_input->stream.i_mux_rate = 0;
344 vlc_mutex_unlock( &p_input->stream.stream_lock );
347 /* allocate memory */
348 p_sys->track = calloc( p_sys->i_tracks, sizeof( mp4_track_t ) );
349 memset( p_sys->track, 0, p_sys->i_tracks * sizeof( mp4_track_t ) );
351 /* now process each track and extract all usefull informations */
352 for( i = 0; i < p_sys->i_tracks; i++ )
354 p_trak = MP4_BoxGet( p_sys->p_root, "/moov/trak[%d]", i );
355 MP4_TrackCreate( p_input, &p_sys->track[i], p_trak );
357 if( p_sys->track[i].b_ok )
360 switch( p_sys->track[i].fmt.i_cat )
373 msg_Dbg( p_input, "adding track[Id 0x%x] %s (%s) language %s",
374 p_sys->track[i].i_track_ID,
376 p_sys->track[i].b_enable ? "enable":"disable",
377 p_sys->track[i].fmt.psz_language ? p_sys->track[i].fmt.psz_language : "undef" );
381 msg_Dbg( p_input, "ignoring track[Id 0x%x]", p_sys->track[i].i_track_ID );
390 MP4_BoxFree( p_input, p_sys->p_root );
396 /*****************************************************************************
397 * Demux: read packet and send them to decoders
398 *****************************************************************************
399 * TODO check for newly selected track (ie audio upt to now )
400 *****************************************************************************/
401 static int Demux( input_thread_t *p_input )
403 demux_sys_t *p_sys = p_input->p_demux_data;
404 unsigned int i_track;
407 unsigned int i_track_selected;
408 vlc_bool_t b_play_audio;
410 /* check for newly selected/unselected track */
411 for( i_track = 0, i_track_selected = 0; i_track < p_sys->i_tracks; i_track++ )
413 mp4_track_t *tk = &p_sys->track[i_track];
415 if( tk->b_selected && tk->i_sample >= tk->i_sample_count )
417 msg_Warn( p_input, "track[0x%x] will be disabled", tk->i_track_ID );
418 MP4_TrackUnselect( p_input, tk);
423 es_out_Control( p_input->p_es_out, ES_OUT_GET_ES_STATE, tk->p_es, &b );
425 if( tk->b_selected && !b )
427 MP4_TrackUnselect( p_input, tk );
429 else if( !tk->b_selected && b)
431 MP4_TrackSelect( p_input, tk, MP4_GetMoviePTS( p_sys ) );
441 if( i_track_selected <= 0 )
443 msg_Warn( p_input, "no track selected, exiting..." );
447 /* first wait for the good time to read a packet */
448 input_ClockManageRef( p_input,
449 p_input->stream.p_selected_program,
452 /* update pcr XXX in mpeg scale so in 90000 unit/s */
453 p_sys->i_pcr = MP4_GetMoviePTS( p_sys ) * 9 / 100;
455 /* we will read 100ms for each stream so ...*/
456 p_sys->i_time += __MAX( p_sys->i_timescale / 10 , 1 );
458 /* Check if we need to send the audio data to decoder */
459 b_play_audio = !p_input->stream.control.b_mute;
461 for( i_track = 0; i_track < p_sys->i_tracks; i_track++ )
463 mp4_track_t *tk = &p_sys->track[i_track];
465 if( !tk->b_ok || !tk->b_selected )
470 while( MP4_TrackGetPTS( tk) < MP4_GetMoviePTS( p_sys ) )
472 if( MP4_TrackSampleSize( tk ) > 0 &&
473 ( b_play_audio || tk->fmt.i_cat != AUDIO_ES ) )
478 if( stream_Seek( p_input->s, MP4_TrackGetPos( tk ) ) )
480 msg_Warn( p_input, "track[0x%x] will be disabled (eof?)", tk->i_track_ID );
481 MP4_TrackUnselect( p_input, tk );
486 if( ( p_block = stream_Block( p_input->s,
487 MP4_TrackSampleSize( tk ) ) ) == NULL )
489 msg_Warn( p_input, "track[0x%x] will be disabled (eof?)", tk->i_track_ID );
490 MP4_TrackUnselect( p_input, tk );
494 if( tk->b_drms && tk->p_drms )
496 drms_decrypt( tk->p_drms,
497 (uint32_t*)p_block->p_buffer,
501 input_ClockGetTS( p_input,
502 p_input->stream.p_selected_program,
503 MP4_TrackGetPTS( tk ) * 9/100 );
505 p_block->i_pts = tk->fmt.i_cat == VIDEO_ES ? 0 : p_block->i_dts;
507 if( !tk->b_drms || ( tk->b_drms && tk->p_drms ) )
509 es_out_Send( p_input->p_es_out, tk->p_es, p_block );
514 if( MP4_TrackNextSample( p_input, tk ) )
523 /*****************************************************************************
524 * Seek: Got to i_date
525 ******************************************************************************/
526 static int Seek ( input_thread_t *p_input, mtime_t i_date )
528 demux_sys_t *p_sys = p_input->p_demux_data;
529 unsigned int i_track;
531 /* First update update global time */
532 p_sys->i_time = i_date * p_sys->i_timescale / 1000000;
533 p_sys->i_pcr = i_date* 9 / 100;
535 /* Now for each stream try to go to this time */
536 for( i_track = 0; i_track < p_sys->i_tracks; i_track++ )
538 mp4_track_t *tk = &p_sys->track[i_track];
540 if( tk->b_ok && tk->b_selected )
542 MP4_TrackSeek( p_input, tk, i_date );
548 /*****************************************************************************
550 *****************************************************************************/
551 static int Control ( input_thread_t *p_input, int i_query, va_list args )
553 demux_sys_t *p_sys = p_input->p_demux_data;
560 case DEMUX_GET_POSITION:
561 pf = (double*)va_arg( args, double * );
562 if( p_sys->i_duration > 0 )
564 *pf = (double)p_sys->i_time / (double)p_sys->i_duration;
572 case DEMUX_SET_POSITION:
573 f = (double)va_arg( args, double );
576 (double)p_sys->i_duration /
577 (double)p_sys->i_timescale );
578 return Seek( p_input, i64 );
581 pi64 = (int64_t*)va_arg( args, int64_t * );
582 *pi64 = (mtime_t)1000000 *
583 (mtime_t)p_sys->i_time /
584 (mtime_t)p_sys->i_timescale;
588 i64 = (int64_t)va_arg( args, int64_t );
589 return Seek( p_input, i64 );
591 case DEMUX_GET_LENGTH:
592 pi64 = (int64_t*)va_arg( args, int64_t * );
593 *pi64 = (mtime_t)1000000 *
594 (mtime_t)p_sys->i_duration /
595 (mtime_t)p_sys->i_timescale;
598 msg_Warn( p_input, "DEMUX_GET_FPS unimplemented !!" );
601 msg_Err( p_input, "control query unimplemented !!!" );
602 return demux_vaControlDefault( p_input, i_query, args );
606 /*****************************************************************************
607 * Close: frees unused data
608 *****************************************************************************/
609 static void Close ( vlc_object_t * p_this )
611 unsigned int i_track;
612 input_thread_t * p_input = (input_thread_t *)p_this;
613 demux_sys_t *p_sys = p_input->p_demux_data;
615 msg_Dbg( p_input, "freeing all memory" );
617 MP4_BoxFree( p_input, p_sys->p_root );
618 for( i_track = 0; i_track < p_sys->i_tracks; i_track++ )
620 MP4_TrackDestroy( p_input, &p_sys->track[i_track] );
622 FREE( p_sys->track );
629 /****************************************************************************
630 * Local functions, specific to vlc
631 ****************************************************************************/
633 /* now create basic chunk data, the rest will be filled by MP4_CreateSamplesIndex */
634 static int TrackCreateChunksIndex( input_thread_t *p_input,
635 mp4_track_t *p_demux_track )
637 MP4_Box_t *p_co64; /* give offset for each chunk, same for stco and co64 */
640 unsigned int i_chunk;
641 unsigned int i_index, i_last;
643 if( ( !(p_co64 = MP4_BoxGet( p_demux_track->p_stbl, "stco" ) )&&
644 !(p_co64 = MP4_BoxGet( p_demux_track->p_stbl, "co64" ) ) )||
645 ( !(p_stsc = MP4_BoxGet( p_demux_track->p_stbl, "stsc" ) ) ))
647 return( VLC_EGENERIC );
650 p_demux_track->i_chunk_count = p_co64->data.p_co64->i_entry_count;
651 if( !p_demux_track->i_chunk_count )
653 msg_Warn( p_input, "no chunk defined" );
654 return( VLC_EGENERIC );
656 p_demux_track->chunk = calloc( p_demux_track->i_chunk_count,
657 sizeof( mp4_chunk_t ) );
659 /* first we read chunk offset */
660 for( i_chunk = 0; i_chunk < p_demux_track->i_chunk_count; i_chunk++ )
662 p_demux_track->chunk[i_chunk].i_offset =
663 p_co64->data.p_co64->i_chunk_offset[i_chunk];
666 /* now we read index for SampleEntry( soun vide mp4a mp4v ...)
667 to be used for the sample XXX begin to 1
668 We construct it begining at the end */
669 i_last = p_demux_track->i_chunk_count; /* last chunk proceded */
670 i_index = p_stsc->data.p_stsc->i_entry_count;
673 msg_Warn( p_input, "cannot read chunk table or table empty" );
674 return( VLC_EGENERIC );
680 for( i_chunk = p_stsc->data.p_stsc->i_first_chunk[i_index] - 1;
681 i_chunk < i_last; i_chunk++ )
683 p_demux_track->chunk[i_chunk].i_sample_description_index =
684 p_stsc->data.p_stsc->i_sample_description_index[i_index];
685 p_demux_track->chunk[i_chunk].i_sample_count =
686 p_stsc->data.p_stsc->i_samples_per_chunk[i_index];
688 i_last = p_stsc->data.p_stsc->i_first_chunk[i_index] - 1;
691 p_demux_track->chunk[0].i_sample_first = 0;
692 for( i_chunk = 1; i_chunk < p_demux_track->i_chunk_count; i_chunk++ )
694 p_demux_track->chunk[i_chunk].i_sample_first =
695 p_demux_track->chunk[i_chunk-1].i_sample_first +
696 p_demux_track->chunk[i_chunk-1].i_sample_count;
700 "track[Id 0x%x] read %d chunk",
701 p_demux_track->i_track_ID,
702 p_demux_track->i_chunk_count );
704 return( VLC_SUCCESS );
706 static int TrackCreateSamplesIndex( input_thread_t *p_input,
707 mp4_track_t *p_demux_track )
709 MP4_Box_t *p_stts; /* makes mapping between sample and decoding time,
710 ctts make same mapping but for composition time,
711 not yet used and probably not usefull */
712 MP4_Box_t *p_stsz; /* gives sample size of each samples, there is also stz2
713 that uses a compressed form FIXME make them in libmp4
715 /* TODO use also stss and stsh table for seeking */
716 /* FIXME use edit table */
721 int64_t i_index_sample_used;
725 p_stts = MP4_BoxGet( p_demux_track->p_stbl, "stts" );
726 p_stsz = MP4_BoxGet( p_demux_track->p_stbl, "stsz" ); /* FIXME and stz2 */
728 if( ( !p_stts )||( !p_stsz ) )
730 msg_Warn( p_input, "cannot read sample table" );
731 return( VLC_EGENERIC );
734 p_demux_track->i_sample_count = p_stsz->data.p_stsz->i_sample_count;
737 /* for sample size, there are 2 case */
738 if( p_stsz->data.p_stsz->i_sample_size )
740 /* 1: all sample have the same size, so no need to construct a table */
741 p_demux_track->i_sample_size = p_stsz->data.p_stsz->i_sample_size;
742 p_demux_track->p_sample_size = NULL;
746 /* 2: each sample can have a different size */
747 p_demux_track->i_sample_size = 0;
748 p_demux_track->p_sample_size =
749 calloc( p_demux_track->i_sample_count, sizeof( uint32_t ) );
751 for( i_sample = 0; i_sample < p_demux_track->i_sample_count; i_sample++ )
753 p_demux_track->p_sample_size[i_sample] =
754 p_stsz->data.p_stsz->i_entry_size[i_sample];
757 /* we have extract all information from stsz,
760 /* if we don't want to waste too much memory, we can't expand
761 the box !, so each chunk will contain an "extract" of this table
765 i_index = 0; i_index_sample_used =0;
767 /* create and init last data for each chunk */
768 for(i_chunk = 0 ; i_chunk < p_demux_track->i_chunk_count; i_chunk++ )
771 int64_t i_entry, i_sample_count, i;
773 p_demux_track->chunk[i_chunk].i_first_dts = i_last_dts;
774 /* count how many entries needed for this chunk
775 for p_sample_delta_dts and p_sample_count_dts */
777 i_sample_count = p_demux_track->chunk[i_chunk].i_sample_count;
780 while( i_sample_count > 0 )
782 i_sample_count -= p_stts->data.p_stts->i_sample_count[i_index+i_entry];
785 i_sample_count += i_index_sample_used; /* don't count already used sample
792 p_demux_track->chunk[i_chunk].p_sample_count_dts =
793 calloc( i_entry, sizeof( uint32_t ) );
794 p_demux_track->chunk[i_chunk].p_sample_delta_dts =
795 calloc( i_entry, sizeof( uint32_t ) );
798 i_sample_count = p_demux_track->chunk[i_chunk].i_sample_count;
799 for( i = 0; i < i_entry; i++ )
804 i_rest = p_stts->data.p_stts->i_sample_count[i_index] - i_index_sample_used;
806 i_used = __MIN( i_rest, i_sample_count );
808 i_index_sample_used += i_used;
809 i_sample_count -= i_used;
811 p_demux_track->chunk[i_chunk].p_sample_count_dts[i] = i_used;
813 p_demux_track->chunk[i_chunk].p_sample_delta_dts[i] =
814 p_stts->data.p_stts->i_sample_delta[i_index];
816 i_last_dts += i_used *
817 p_demux_track->chunk[i_chunk].p_sample_delta_dts[i];
819 if( i_index_sample_used >=
820 p_stts->data.p_stts->i_sample_count[i_index] )
824 i_index_sample_used = 0;
831 "track[Id 0x%x] read %d samples length:"I64Fd"s",
832 p_demux_track->i_track_ID,
833 p_demux_track->i_sample_count,
834 i_last_dts / p_demux_track->i_timescale );
836 return( VLC_SUCCESS );
841 * Create ES and PES to init decoder if needed, for a track starting at i_chunk
843 static int TrackCreateES ( input_thread_t *p_input,
844 mp4_track_t *p_track,
845 unsigned int i_chunk,
846 es_out_id_t **pp_es )
853 if( !p_track->chunk[i_chunk].i_sample_description_index )
856 "invalid SampleEntry index (track[Id 0x%x])",
857 p_track->i_track_ID );
861 p_sample = MP4_BoxGet( p_track->p_stsd, "[%d]",
862 p_track->chunk[i_chunk].i_sample_description_index - 1 );
864 if( !p_sample || !p_sample->data.p_data )
867 "cannot find SampleEntry (track[Id 0x%x])",
868 p_track->i_track_ID );
869 return( VLC_EGENERIC );
872 p_track->p_sample = p_sample;
874 if( p_track->i_sample_size == 1 )
876 MP4_Box_data_sample_soun_t *p_soun;
878 p_soun = p_sample->data.p_sample_soun;
880 if( p_soun->i_qt_version == 0 )
882 switch( p_sample->i_type )
884 case VLC_FOURCC( 'i', 'm', 'a', '4' ):
885 p_soun->i_qt_version = 1;
886 p_soun->i_sample_per_packet = 64;
887 p_soun->i_bytes_per_packet = 34;
888 p_soun->i_bytes_per_frame = 34 * p_soun->i_channelcount;
889 p_soun->i_bytes_per_sample = 2;
891 case VLC_FOURCC( 'M', 'A', 'C', '3' ):
892 p_soun->i_qt_version = 1;
893 p_soun->i_sample_per_packet = 6;
894 p_soun->i_bytes_per_packet = 2;
895 p_soun->i_bytes_per_frame = 2 * p_soun->i_channelcount;
896 p_soun->i_bytes_per_sample = 2;
898 case VLC_FOURCC( 'M', 'A', 'C', '6' ):
899 p_soun->i_qt_version = 1;
900 p_soun->i_sample_per_packet = 12;
901 p_soun->i_bytes_per_packet = 2;
902 p_soun->i_bytes_per_frame = 2 * p_soun->i_channelcount;
903 p_soun->i_bytes_per_sample = 2;
910 else if( p_soun->i_qt_version == 1 && p_soun->i_sample_per_packet <= 0 )
912 p_soun->i_qt_version = 0;
917 /* It's a little ugly but .. there are special cases */
918 switch( p_sample->i_type )
920 case( VLC_FOURCC( '.', 'm', 'p', '3' ) ):
921 case( VLC_FOURCC( 'm', 's', 0x00, 0x55 ) ):
922 p_track->fmt.i_codec = VLC_FOURCC( 'm', 'p', 'g', 'a' );
924 case( VLC_FOURCC( 'r', 'a', 'w', ' ' ) ):
925 p_track->fmt.i_codec = VLC_FOURCC( 'a', 'r', 'a', 'w' );
927 case( VLC_FOURCC( 's', '2', '6', '3' ) ):
928 p_track->fmt.i_codec = VLC_FOURCC( 'h', '2', '6', '3' );
931 p_track->fmt.i_codec = p_sample->i_type;
935 /* now see if esds is present and if so create a data packet
936 with decoder_specific_info */
937 #define p_decconfig p_esds->data.p_esds->es_descriptor.p_decConfigDescr
938 if( ( ( p_esds = MP4_BoxGet( p_sample, "esds" ) ) ||
939 ( p_esds = MP4_BoxGet( p_sample, "wave/esds" ) ) )&&
940 ( p_esds->data.p_esds )&&
943 /* First update information based on i_objectTypeIndication */
944 switch( p_decconfig->i_objectTypeIndication )
946 case( 0x20 ): /* MPEG4 VIDEO */
947 p_track->fmt.i_codec = VLC_FOURCC( 'm','p','4','v' );
950 p_track->fmt.i_codec = VLC_FOURCC( 'm','p','4','a' );
957 case( 0x65): /* MPEG2 video */
958 p_track->fmt.i_codec = VLC_FOURCC( 'm','p','g','v' );
960 /* Theses are MPEG2-AAC */
961 case( 0x66): /* main profile */
962 case( 0x67): /* Low complexity profile */
963 case( 0x68): /* Scaleable Sampling rate profile */
964 p_track->fmt.i_codec = VLC_FOURCC( 'm','p','4','a' );
966 /* true MPEG 2 audio */
968 p_track->fmt.i_codec = VLC_FOURCC( 'm','p','g','a' );
970 case( 0x6a): /* MPEG1 video */
971 p_track->fmt.i_codec = VLC_FOURCC( 'm','p','g','v' );
973 case( 0x6b): /* MPEG1 audio */
974 p_track->fmt.i_codec = VLC_FOURCC( 'm','p','g','a' );
976 case( 0x6c ): /* jpeg */
977 p_track->fmt.i_codec = VLC_FOURCC( 'j','p','e','g' );
980 /* Unknown entry, but don't touch i_fourcc */
982 "unknown objectTypeIndication(0x%x) (Track[ID 0x%x])",
983 p_decconfig->i_objectTypeIndication,
984 p_track->i_track_ID );
987 p_track->fmt.i_extra = p_decconfig->i_decoder_specific_info_len;
988 if( p_track->fmt.i_extra > 0 )
990 p_track->fmt.p_extra = malloc( p_track->fmt.i_extra );
991 memcpy( p_track->fmt.p_extra, p_decconfig->p_decoder_specific_info,
992 p_track->fmt.i_extra );
997 switch( p_sample->i_type )
999 /* qt decoder, send the complete chunk */
1000 case VLC_FOURCC( 'S', 'V', 'Q', '3' ):
1001 case VLC_FOURCC( 'S', 'V', 'Q', '1' ):
1002 case VLC_FOURCC( 'V', 'P', '3', '1' ):
1003 case VLC_FOURCC( '3', 'I', 'V', '1' ):
1004 case VLC_FOURCC( 'Z', 'y', 'G', 'o' ):
1005 p_track->fmt.i_extra =
1006 p_sample->data.p_sample_vide->i_qt_image_description;
1007 if( p_track->fmt.i_extra > 0 )
1009 p_track->fmt.p_extra = malloc( p_track->fmt.i_extra );
1010 memcpy( p_track->fmt.p_extra,
1011 p_sample->data.p_sample_vide->p_qt_image_description,
1012 p_track->fmt.i_extra);
1015 case VLC_FOURCC( 'Q', 'D', 'M', 'C' ):
1016 case VLC_FOURCC( 'Q', 'D', 'M', '2' ):
1017 case VLC_FOURCC( 'Q', 'c', 'l', 'p' ):
1018 case VLC_FOURCC( 's', 'a', 'm', 'r' ):
1019 p_track->fmt.i_extra =
1020 p_sample->data.p_sample_soun->i_qt_description;
1021 if( p_track->fmt.i_extra > 0 )
1023 p_track->fmt.p_extra = malloc( p_track->fmt.i_extra );
1024 memcpy( p_track->fmt.p_extra,
1025 p_sample->data.p_sample_soun->p_qt_description,
1026 p_track->fmt.i_extra);
1036 /* some last initialisation */
1037 switch( p_track->fmt.i_cat )
1040 p_track->fmt.video.i_width = p_sample->data.p_sample_vide->i_width;
1041 p_track->fmt.video.i_height = p_sample->data.p_sample_vide->i_height;
1043 /* fall on display size */
1044 if( p_track->fmt.video.i_width <= 0 )
1045 p_track->fmt.video.i_width = p_track->i_width;
1046 if( p_track->fmt.video.i_height <= 0 )
1047 p_track->fmt.video.i_height = p_track->i_height;
1049 /* Find out apect ratio from display size */
1050 if( p_track->i_width > 0 && p_track->i_height > 0 )
1051 p_track->fmt.video.i_aspect =
1052 VOUT_ASPECT_FACTOR * p_track->i_width / p_track->i_height;
1057 p_track->fmt.audio.i_channels =
1058 p_sample->data.p_sample_soun->i_channelcount;
1059 p_track->fmt.audio.i_rate =
1060 p_sample->data.p_sample_soun->i_sampleratehi;
1061 p_track->fmt.i_bitrate = p_sample->data.p_sample_soun->i_channelcount *
1062 p_sample->data.p_sample_soun->i_sampleratehi *
1063 p_sample->data.p_sample_soun->i_samplesize;
1064 p_track->fmt.audio.i_bitspersample =
1065 p_sample->data.p_sample_soun->i_samplesize;
1072 *pp_es = es_out_Add( p_input->p_es_out, &p_track->fmt );
1077 /* given a time it return sample/chunk */
1078 static int TrackTimeToSampleChunk( input_thread_t *p_input,
1079 mp4_track_t *p_track,
1082 uint32_t *pi_sample )
1086 unsigned int i_sample;
1087 unsigned int i_chunk;
1090 /* convert absolute time to in timescale unit */
1091 i_start = i_start * (mtime_t)p_track->i_timescale / (mtime_t)1000000;
1093 /* FIXME see if it's needed to check p_track->i_chunk_count */
1094 if( !p_track->b_ok || p_track->i_chunk_count == 0 )
1096 return( VLC_EGENERIC );
1099 /* we start from sample 0/chunk 0, hope it won't take too much time */
1100 /* *** find good chunk *** */
1101 for( i_chunk = 0; ; i_chunk++ )
1103 if( i_chunk + 1 >= p_track->i_chunk_count )
1105 /* at the end and can't check if i_start in this chunk,
1106 it will be check while searching i_sample */
1107 i_chunk = p_track->i_chunk_count - 1;
1111 if( i_start >= p_track->chunk[i_chunk].i_first_dts &&
1112 i_start < p_track->chunk[i_chunk + 1].i_first_dts )
1118 /* *** find sample in the chunk *** */
1119 i_sample = p_track->chunk[i_chunk].i_sample_first;
1120 i_dts = p_track->chunk[i_chunk].i_first_dts;
1121 for( i_index = 0; i_sample < p_track->chunk[i_chunk].i_sample_count; )
1124 p_track->chunk[i_chunk].p_sample_count_dts[i_index] *
1125 p_track->chunk[i_chunk].p_sample_delta_dts[i_index] < i_start )
1128 p_track->chunk[i_chunk].p_sample_count_dts[i_index] *
1129 p_track->chunk[i_chunk].p_sample_delta_dts[i_index];
1131 i_sample += p_track->chunk[i_chunk].p_sample_count_dts[i_index];
1136 if( p_track->chunk[i_chunk].p_sample_delta_dts[i_index] <= 0 )
1140 i_sample += ( i_start - i_dts ) / p_track->chunk[i_chunk].p_sample_delta_dts[i_index];
1145 if( i_sample >= p_track->i_sample_count )
1148 "track[Id 0x%x] will be disabled (seeking too far) chunk=%d sample=%d",
1149 p_track->i_track_ID, i_chunk, i_sample );
1150 return( VLC_EGENERIC );
1154 /* *** Try to find nearest sync points *** */
1155 if( ( p_stss = MP4_BoxGet( p_track->p_stbl, "stss" ) ) )
1157 unsigned int i_index;
1159 "track[Id 0x%x] using Sync Sample Box (stss)",
1160 p_track->i_track_ID );
1161 for( i_index = 0; i_index < p_stss->data.p_stss->i_entry_count; i_index++ )
1163 if( p_stss->data.p_stss->i_sample_number[i_index] >= i_sample )
1167 msg_Dbg( p_input, "stts gives %d --> %d (sample number)",
1169 p_stss->data.p_stss->i_sample_number[i_index-1] );
1170 i_sample = p_stss->data.p_stss->i_sample_number[i_index-1];
1171 /* new i_sample is less than old so i_chunk can only decreased */
1172 while( i_chunk > 0 &&
1173 i_sample < p_track->chunk[i_chunk].i_sample_first )
1180 msg_Dbg( p_input, "stts gives %d --> %d (sample number)",
1182 p_stss->data.p_stss->i_sample_number[i_index] );
1183 i_sample = p_stss->data.p_stss->i_sample_number[i_index];
1184 /* new i_sample is more than old so i_chunk can only increased */
1185 while( i_chunk < p_track->i_chunk_count - 1 &&
1186 i_sample >= p_track->chunk[i_chunk].i_sample_first +
1187 p_track->chunk[i_chunk].i_sample_count )
1199 "track[Id 0x%x] does not provide Sync Sample Box (stss)",
1200 p_track->i_track_ID );
1203 if( pi_chunk ) *pi_chunk = i_chunk;
1204 if( pi_sample ) *pi_sample = i_sample;
1205 return( VLC_SUCCESS );
1208 static int TrackGotoChunkSample( input_thread_t *p_input,
1209 mp4_track_t *p_track,
1210 unsigned int i_chunk,
1211 unsigned int i_sample )
1213 vlc_bool_t b_reselect = VLC_FALSE;
1215 /* now see if actual es is ok */
1216 if( p_track->i_chunk < 0 ||
1217 p_track->i_chunk >= p_track->i_chunk_count ||
1218 p_track->chunk[p_track->i_chunk].i_sample_description_index !=
1219 p_track->chunk[i_chunk].i_sample_description_index )
1221 msg_Warn( p_input, "Recreate ES" );
1223 es_out_Control( p_input->p_es_out, ES_OUT_GET_ES_STATE, p_track->p_es, &b_reselect );
1225 es_out_Del( p_input->p_es_out, p_track->p_es );
1227 p_track->p_es = NULL;
1229 if( TrackCreateES( p_input,
1233 msg_Err( p_input, "cannot create es for track[Id 0x%x]",
1234 p_track->i_track_ID );
1236 p_track->b_ok = VLC_FALSE;
1237 p_track->b_selected = VLC_FALSE;
1238 return VLC_EGENERIC;
1242 /* select again the new decoder */
1245 es_out_Control( p_input->p_es_out, ES_OUT_SET_ES, p_track->p_es );
1248 p_track->i_chunk = i_chunk;
1249 p_track->i_sample = i_sample;
1251 return p_track->b_selected ? VLC_SUCCESS : VLC_EGENERIC;
1254 /****************************************************************************
1256 ****************************************************************************
1257 * Parse track information and create all needed data to run a track
1258 * If it succeed b_ok is set to 1 else to 0
1259 ****************************************************************************/
1260 static void MP4_TrackCreate( input_thread_t *p_input,
1261 mp4_track_t *p_track,
1262 MP4_Box_t * p_box_trak )
1264 MP4_Box_t *p_tkhd = MP4_BoxGet( p_box_trak, "tkhd" );
1265 MP4_Box_t *p_tref = MP4_BoxGet( p_box_trak, "tref" );
1279 /* hint track unsuported */
1281 /* set default value (-> track unusable) */
1282 p_track->b_ok = VLC_FALSE;
1283 p_track->b_enable = VLC_FALSE;
1284 p_track->b_selected = VLC_FALSE;
1286 es_format_Init( &p_track->fmt, UNKNOWN_ES, 0 );
1293 /* do we launch this track by default ? */
1295 ( ( p_tkhd->data.p_tkhd->i_flags&MP4_TRACK_ENABLED ) != 0 );
1297 p_track->i_track_ID = p_tkhd->data.p_tkhd->i_track_ID;
1298 p_track->i_width = p_tkhd->data.p_tkhd->i_width / 65536;
1299 p_track->i_height = p_tkhd->data.p_tkhd->i_height / 65536;
1301 if( ( p_elst = MP4_BoxGet( p_box_trak, "edts/elst" ) ) )
1303 /* msg_Warn( p_input, "unhandled box: edts --> FIXME" ); */
1308 /* msg_Warn( p_input, "unhandled box: tref --> FIXME" ); */
1311 p_mdhd = MP4_BoxGet( p_box_trak, "mdia/mdhd" );
1312 p_hdlr = MP4_BoxGet( p_box_trak, "mdia/hdlr" );
1314 if( ( !p_mdhd )||( !p_hdlr ) )
1319 p_track->i_timescale = p_mdhd->data.p_mdhd->i_timescale;
1321 for( i = 0; i < 3; i++ )
1323 language[i] = p_mdhd->data.p_mdhd->i_language[i];
1327 switch( p_hdlr->data.p_hdlr->i_handler_type )
1329 case( FOURCC_soun ):
1330 if( !( p_smhd = MP4_BoxGet( p_box_trak, "mdia/minf/smhd" ) ) )
1334 p_track->fmt.i_cat = AUDIO_ES;
1337 case( FOURCC_vide ):
1338 if( !( p_vmhd = MP4_BoxGet( p_box_trak, "mdia/minf/vmhd" ) ) )
1342 p_track->fmt.i_cat = VIDEO_ES;
1350 p_dinf = MP4_BoxGet( p_minf, "dinf" );
1352 if( !( p_track->p_stbl = MP4_BoxGet( p_box_trak,"mdia/minf/stbl" ) ) ||
1353 !( p_track->p_stsd = MP4_BoxGet( p_box_trak,"mdia/minf/stbl/stsd") ) )
1358 p_drms = MP4_BoxGet( p_track->p_stsd, "drms" );
1359 p_track->b_drms = p_drms != NULL;
1360 p_track->p_drms = p_track->b_drms ?
1361 p_drms->data.p_sample_soun->p_drms : NULL;
1364 if( strcmp( language, "```" ) && strcmp( language, "und" ) )
1366 p_track->fmt.psz_language = LanguageGetName( language );
1369 /* fxi i_timescale for AUDIO_ES with i_qt_version == 0 */
1370 if( p_track->fmt.i_cat == AUDIO_ES ) //&& p_track->i_sample_size == 1 )
1372 MP4_Box_t *p_sample;
1374 p_sample = MP4_BoxGet( p_track->p_stsd, "[0]" );
1375 if( p_sample && p_sample->data.p_sample_soun)
1377 MP4_Box_data_sample_soun_t *p_soun = p_sample->data.p_sample_soun;
1378 if( p_soun->i_qt_version == 0 &&
1379 p_track->i_timescale != p_soun->i_sampleratehi )
1382 "i_timescale ("I64Fu") != i_sampleratehi (%u) with "
1384 "Making both equal. (report any problem)",
1385 p_track->i_timescale, p_soun->i_sampleratehi );
1387 if( p_soun->i_sampleratehi )
1388 p_track->i_timescale = p_soun->i_sampleratehi;
1390 p_soun->i_sampleratehi = p_track->i_timescale;
1395 /* Create chunk index table and sample index table */
1396 if( TrackCreateChunksIndex( p_input,p_track ) ||
1397 TrackCreateSamplesIndex( p_input, p_track ) )
1399 return; /* cannot create chunks index */
1402 p_track->i_chunk = 0;
1403 p_track->i_sample = 0;
1406 if( TrackCreateES( p_input,
1407 p_track, p_track->i_chunk,
1410 msg_Err( p_input, "cannot create es for track[Id 0x%x]",
1411 p_track->i_track_ID );
1418 for( i = 0; i < p_track->i_chunk_count; i++ )
1420 fprintf( stderr, "%-5d sample_count=%d pts=%lld\n", i, p_track->chunk[i].i_sample_count, p_track->chunk[i].i_first_dts );
1425 p_track->b_ok = VLC_TRUE;
1428 /****************************************************************************
1430 ****************************************************************************
1431 * Destroy a track created by MP4_TrackCreate.
1432 ****************************************************************************/
1433 static void MP4_TrackDestroy( input_thread_t *p_input,
1434 mp4_track_t *p_track )
1436 unsigned int i_chunk;
1438 p_track->b_ok = VLC_FALSE;
1439 p_track->b_enable = VLC_FALSE;
1440 p_track->b_selected = VLC_FALSE;
1442 es_format_Init( &p_track->fmt, UNKNOWN_ES, 0 );
1444 for( i_chunk = 0; i_chunk < p_track->i_chunk_count; i_chunk++ )
1446 if( p_track->chunk )
1448 FREE(p_track->chunk[i_chunk].p_sample_count_dts);
1449 FREE(p_track->chunk[i_chunk].p_sample_delta_dts );
1452 FREE( p_track->chunk );
1454 if( !p_track->i_sample_size )
1456 FREE( p_track->p_sample_size );
1460 static int MP4_TrackSelect ( input_thread_t *p_input,
1461 mp4_track_t *p_track,
1467 if( !p_track->b_ok )
1469 return( VLC_EGENERIC );
1472 if( p_track->b_selected )
1475 "track[Id 0x%x] already selected",
1476 p_track->i_track_ID );
1477 return( VLC_SUCCESS );
1480 if( TrackTimeToSampleChunk( p_input,
1482 &i_chunk, &i_sample ) )
1485 "cannot select track[Id 0x%x]",
1486 p_track->i_track_ID );
1487 return( VLC_EGENERIC );
1490 p_track->b_selected = VLC_TRUE;
1492 if( TrackGotoChunkSample( p_input, p_track, i_chunk, i_sample ) )
1494 p_track->b_selected = VLC_FALSE;
1496 return p_track->b_selected ? VLC_SUCCESS : VLC_EGENERIC;
1499 static void MP4_TrackUnselect(input_thread_t *p_input,
1500 mp4_track_t *p_track )
1502 if( !p_track->b_ok )
1507 if( !p_track->b_selected )
1510 "track[Id 0x%x] already unselected",
1511 p_track->i_track_ID );
1516 es_out_Control( p_input->p_es_out, ES_OUT_SET_ES_STATE, p_track->p_es, VLC_FALSE );
1519 p_track->b_selected = VLC_FALSE;
1522 static int MP4_TrackSeek ( input_thread_t *p_input,
1523 mp4_track_t *p_track,
1529 if( !p_track->b_ok )
1531 return( VLC_EGENERIC );
1534 if( TrackTimeToSampleChunk( p_input,
1536 &i_chunk, &i_sample ) )
1539 "cannot select track[Id 0x%x]",
1540 p_track->i_track_ID );
1541 return( VLC_EGENERIC );
1544 p_track->b_selected = VLC_TRUE;
1546 TrackGotoChunkSample( p_input, p_track, i_chunk, i_sample );
1548 return( p_track->b_selected ? VLC_SUCCESS : VLC_EGENERIC );
1554 * 3 types: for audio
1557 #define QT_V0_MAX_SAMPLES 1500
1558 static int MP4_TrackSampleSize( mp4_track_t *p_track )
1561 MP4_Box_data_sample_soun_t *p_soun;
1563 if( p_track->i_sample_size == 0 )
1565 /* most simple case */
1566 return( p_track->p_sample_size[p_track->i_sample] );
1568 if( p_track->fmt.i_cat != AUDIO_ES )
1570 return( p_track->i_sample_size );
1573 if( p_track->i_sample_size != 1 )
1575 //msg_Warn( p_input, "SampleSize != 1" );
1576 return( p_track->i_sample_size );
1579 p_soun = p_track->p_sample->data.p_sample_soun;
1581 if( p_soun->i_qt_version == 1 )
1583 i_size = p_track->chunk[p_track->i_chunk].i_sample_count / p_soun->i_sample_per_packet * p_soun->i_bytes_per_frame;
1588 int i_samples = p_track->chunk[p_track->i_chunk].i_sample_count -
1589 ( p_track->i_sample - p_track->chunk[p_track->i_chunk].i_sample_first );
1590 if( i_samples > QT_V0_MAX_SAMPLES )
1592 i_samples = QT_V0_MAX_SAMPLES;
1594 i_size = i_samples * p_soun->i_channelcount * p_soun->i_samplesize / 8;
1597 //fprintf( stderr, "size=%d\n", i_size );
1602 static uint64_t MP4_TrackGetPos( mp4_track_t *p_track )
1604 unsigned int i_sample;
1608 i_pos = p_track->chunk[p_track->i_chunk].i_offset;
1610 if( p_track->i_sample_size )
1612 MP4_Box_data_sample_soun_t *p_soun = p_track->p_sample->data.p_sample_soun;
1614 if( p_soun->i_qt_version == 0 )
1616 i_pos += ( p_track->i_sample - p_track->chunk[p_track->i_chunk].i_sample_first ) *
1617 p_soun->i_channelcount * p_soun->i_samplesize / 8;
1621 /* we read chunk by chunk */
1627 for( i_sample = p_track->chunk[p_track->i_chunk].i_sample_first;
1628 i_sample < p_track->i_sample; i_sample++ )
1630 i_pos += p_track->p_sample_size[i_sample];
1637 static int MP4_TrackNextSample( input_thread_t *p_input,
1638 mp4_track_t *p_track )
1641 if( p_track->fmt.i_cat == AUDIO_ES &&
1642 p_track->i_sample_size != 0 )
1644 MP4_Box_data_sample_soun_t *p_soun;
1646 p_soun = p_track->p_sample->data.p_sample_soun;
1648 if( p_soun->i_qt_version == 1 )
1650 /* chunk by chunk */
1652 p_track->chunk[p_track->i_chunk].i_sample_first +
1653 p_track->chunk[p_track->i_chunk].i_sample_count;
1658 p_track->i_sample += QT_V0_MAX_SAMPLES;
1659 if( p_track->i_sample > p_track->chunk[p_track->i_chunk].i_sample_first + p_track->chunk[p_track->i_chunk].i_sample_count )
1662 p_track->chunk[p_track->i_chunk].i_sample_first +
1663 p_track->chunk[p_track->i_chunk].i_sample_count;
1669 p_track->i_sample++;
1672 if( p_track->i_sample >= p_track->i_sample_count )
1674 /* we have reach end of the track so free decoder stuff */
1675 msg_Warn( p_input, "track[0x%x] will be disabled", p_track->i_track_ID );
1676 MP4_TrackUnselect( p_input, p_track );
1677 return( VLC_EGENERIC );
1680 /* Have we changed chunk ? */
1681 if( p_track->i_sample >=
1682 p_track->chunk[p_track->i_chunk].i_sample_first +
1683 p_track->chunk[p_track->i_chunk].i_sample_count )
1685 if( TrackGotoChunkSample( p_input,
1687 p_track->i_chunk + 1,
1688 p_track->i_sample ) )
1690 msg_Warn( p_input, "track[0x%x] will be disabled (cannot restart decoder)", p_track->i_track_ID );
1691 MP4_TrackUnselect( p_input, p_track );
1692 return( VLC_EGENERIC );
1696 return( VLC_SUCCESS );
1700 static char *LanguageGetName( const char *psz_code )
1702 const iso639_lang_t *pl;
1704 pl = GetLang_2B( psz_code );
1705 if( !strcmp( pl->psz_iso639_1, "??" ) )
1707 pl = GetLang_2T( psz_code );
1710 if( !strcmp( pl->psz_iso639_1, "??" ) )
1712 return strdup( psz_code );
1715 if( *pl->psz_native_name )
1717 return strdup( pl->psz_native_name );
1719 return strdup( pl->psz_eng_name );