Commit 7f634ecb authored by Steve Lhomme's avatar Steve Lhomme

mkv.cpp: know your parents better

parent 885a0983
...@@ -184,12 +184,12 @@ block_t *block_zlib_decompress( vlc_object_t *p_this, block_t *p_in_block ) { ...@@ -184,12 +184,12 @@ block_t *block_zlib_decompress( vlc_object_t *p_this, block_t *p_in_block ) {
/** /**
* Helper function to print the mkv parse tree * Helper function to print the mkv parse tree
*/ */
static void MkvTree( demux_t *p_this, int i_level, char *psz_format, ... ) static void MkvTree( demux_t & demuxer, int i_level, char *psz_format, ... )
{ {
va_list args; va_list args;
if( i_level > 9 ) if( i_level > 9 )
{ {
msg_Err( p_this, "too deep tree" ); msg_Err( &demuxer, "too deep tree" );
return; return;
} }
va_start( args, psz_format ); va_start( args, psz_format );
...@@ -199,7 +199,7 @@ static void MkvTree( demux_t *p_this, int i_level, char *psz_format, ... ) ...@@ -199,7 +199,7 @@ static void MkvTree( demux_t *p_this, int i_level, char *psz_format, ... )
psz_foo2[ 4 * i_level ] = '+'; psz_foo2[ 4 * i_level ] = '+';
psz_foo2[ 4 * i_level + 1 ] = ' '; psz_foo2[ 4 * i_level + 1 ] = ' ';
strcpy( &psz_foo2[ 4 * i_level + 2 ], psz_format ); strcpy( &psz_foo2[ 4 * i_level + 2 ], psz_format );
__msg_GenericVa( VLC_OBJECT(p_this), VLC_MSG_DBG, "mkv", psz_foo2, args ); __msg_GenericVa( VLC_OBJECT(&demuxer), VLC_MSG_DBG, "mkv", psz_foo2, args );
free( psz_foo2 ); free( psz_foo2 );
va_end( args ); va_end( args );
} }
...@@ -369,8 +369,9 @@ class demux_sys_t; ...@@ -369,8 +369,9 @@ class demux_sys_t;
class matroska_segment_t class matroska_segment_t
{ {
public: public:
matroska_segment_t( demux_sys_t *p_demuxer ) matroska_segment_t( demux_sys_t & demuxer, EbmlStream & estream )
:segment(NULL) :segment(NULL)
,es(estream)
,i_timescale(MKVD_TIMECODESCALE) ,i_timescale(MKVD_TIMECODESCALE)
,f_duration(-1.0) ,f_duration(-1.0)
,i_cues_position(-1) ,i_cues_position(-1)
...@@ -387,7 +388,7 @@ public: ...@@ -387,7 +388,7 @@ public:
,psz_date_utc(NULL) ,psz_date_utc(NULL)
,i_current_edition(-1) ,i_current_edition(-1)
,psz_current_chapter(NULL) ,psz_current_chapter(NULL)
,p_sys(p_demuxer) ,sys(demuxer)
,ep(NULL) ,ep(NULL)
,b_preloaded(false) ,b_preloaded(false)
{ {
...@@ -442,6 +443,7 @@ public: ...@@ -442,6 +443,7 @@ public:
} }
KaxSegment *segment; KaxSegment *segment;
EbmlStream & es;
/* time scale */ /* time scale */
uint64_t i_timescale; uint64_t i_timescale;
...@@ -478,11 +480,11 @@ public: ...@@ -478,11 +480,11 @@ public:
int i_current_edition; int i_current_edition;
const chapter_item_t *psz_current_chapter; const chapter_item_t *psz_current_chapter;
std::vector<KaxSegmentFamily> families; std::vector<KaxSegmentFamily> families;
demux_sys_t *p_sys; demux_sys_t & sys;
EbmlParser *ep; EbmlParser *ep;
bool b_preloaded; bool b_preloaded;
inline chapter_edition_t *Edition() inline chapter_edition_t *Edition()
{ {
...@@ -491,36 +493,42 @@ public: ...@@ -491,36 +493,42 @@ public:
return NULL; return NULL;
} }
bool Preload( demux_t *p_demux ); bool Preload( );
bool PreloadFamily( demux_t *p_demux, const matroska_segment_t & segment ); bool PreloadFamily( const matroska_segment_t & segment );
size_t PreloadLinked( demux_t *p_demux, const demux_sys_t & of_sys ); size_t PreloadLinked( const demux_sys_t & of_sys );
void ParseInfo( EbmlElement *info );
void ParseChapters( EbmlElement *chapters );
void ParseSeekHead( EbmlElement *seekhead );
void ParseTracks( EbmlElement *tracks );
void ParseChapterAtom( int i_level, EbmlMaster *ca, chapter_item_t & chapters );
void ParseTrackEntry( EbmlMaster *m );
}; };
class matroska_stream_t class matroska_stream_t
{ {
public: public:
matroska_stream_t( demux_sys_t *p_demuxer ) matroska_stream_t( demux_sys_t & demuxer )
:in(NULL) :p_in(NULL)
,es(NULL) ,p_es(NULL)
,i_current_segment(-1) ,i_current_segment(-1)
,p_sys(p_demuxer) ,sys(demuxer)
{} {}
~matroska_stream_t() ~matroska_stream_t()
{ {
for ( size_t i=0; i<segments.size(); i++ ) for ( size_t i=0; i<segments.size(); i++ )
delete segments[i]; delete segments[i];
delete in; delete p_in;
delete es; delete p_es;
} }
vlc_stream_io_callback *in; vlc_stream_io_callback *p_in;
EbmlStream *es; EbmlStream *p_es;
std::vector<matroska_segment_t*> segments; std::vector<matroska_segment_t*> segments;
int i_current_segment; int i_current_segment;
demux_sys_t *p_sys; demux_sys_t & sys;
inline matroska_segment_t *Segment() inline matroska_segment_t *Segment()
{ {
...@@ -531,15 +539,16 @@ public: ...@@ -531,15 +539,16 @@ public:
matroska_segment_t *FindSegment( EbmlBinary & uid ) const; matroska_segment_t *FindSegment( EbmlBinary & uid ) const;
void PreloadFamily( demux_t *p_demux, const matroska_segment_t & segment ); void PreloadFamily( const matroska_segment_t & segment );
size_t PreloadLinked( demux_t *p_demux, const demux_sys_t & of_sys ); size_t PreloadLinked( const demux_sys_t & of_sys );
}; };
class demux_sys_t class demux_sys_t
{ {
public: public:
demux_sys_t() demux_sys_t( demux_t & demux )
:i_pts(0) :demuxer(demux)
,i_pts(0)
,i_start_pts(0) ,i_start_pts(0)
,i_chapter_time(0) ,i_chapter_time(0)
,meta(NULL) ,meta(NULL)
...@@ -554,6 +563,8 @@ public: ...@@ -554,6 +563,8 @@ public:
} }
/* current data */ /* current data */
demux_t & demuxer;
mtime_t i_pts; mtime_t i_pts;
mtime_t i_start_pts; mtime_t i_start_pts;
mtime_t i_chapter_time; mtime_t i_chapter_time;
...@@ -573,8 +584,8 @@ public: ...@@ -573,8 +584,8 @@ public:
} }
matroska_segment_t *FindSegment( EbmlBinary & uid ) const; matroska_segment_t *FindSegment( EbmlBinary & uid ) const;
void PreloadFamily( demux_t *p_demux ); void PreloadFamily( );
void PreloadLinked( demux_t *p_demux ); void PreloadLinked( );
bool AnalyseAllSegmentsFound( EbmlStream *p_estream ); bool AnalyseAllSegmentsFound( EbmlStream *p_estream );
}; };
...@@ -589,11 +600,6 @@ static char *UTF8ToStr ( const UTFstring &u ); ...@@ -589,11 +600,6 @@ static char *UTF8ToStr ( const UTFstring &u );
static void LoadCues ( demux_t * ); static void LoadCues ( demux_t * );
static void InformationCreate ( demux_t * ); static void InformationCreate ( demux_t * );
static void ParseInfo( demux_t *, EbmlElement *info );
static void ParseTracks( demux_t *, EbmlElement *tracks );
static void ParseSeekHead( demux_t *, EbmlElement *seekhead );
static void ParseChapters( demux_t *, EbmlElement *chapters );
/***************************************************************************** /*****************************************************************************
* Open: initializes matroska demux structures * Open: initializes matroska demux structures
*****************************************************************************/ *****************************************************************************/
...@@ -619,28 +625,29 @@ static int Open( vlc_object_t * p_this ) ...@@ -619,28 +625,29 @@ static int Open( vlc_object_t * p_this )
/* Set the demux function */ /* Set the demux function */
p_demux->pf_demux = Demux; p_demux->pf_demux = Demux;
p_demux->pf_control = Control; p_demux->pf_control = Control;
p_demux->p_sys = p_sys = new demux_sys_t(); p_demux->p_sys = p_sys = new demux_sys_t( *p_demux );
p_stream = new matroska_stream_t( p_sys ); p_stream = new matroska_stream_t( *p_sys );
p_segment = new matroska_segment_t( p_sys );
p_sys->streams.push_back( p_stream ); p_sys->streams.push_back( p_stream );
p_sys->i_current_stream = 0; p_sys->i_current_stream = 0;
p_stream->p_in = new vlc_stream_io_callback( p_demux->s );
p_stream->p_es = new EbmlStream( *p_stream->p_in );
p_segment = new matroska_segment_t( *p_sys, *p_stream->p_es );
p_stream->segments.push_back( p_segment ); p_stream->segments.push_back( p_segment );
p_stream->i_current_segment = 0; p_stream->i_current_segment = 0;
p_stream->in = new vlc_stream_io_callback( p_demux->s ); if( p_stream->p_es == NULL )
p_stream->es = new EbmlStream( *p_stream->in );
if( p_stream->es == NULL )
{ {
msg_Err( p_demux, "failed to create EbmlStream" ); msg_Err( p_demux, "failed to create EbmlStream" );
delete p_sys; delete p_sys;
return VLC_EGENERIC; return VLC_EGENERIC;
} }
/* Find the EbmlHead element */ /* Find the EbmlHead element */
el = p_stream->es->FindNextID(EbmlHead::ClassInfos, 0xFFFFFFFFL); el = p_stream->p_es->FindNextID(EbmlHead::ClassInfos, 0xFFFFFFFFL);
if( el == NULL ) if( el == NULL )
{ {
msg_Err( p_demux, "cannot find EbmlHead" ); msg_Err( p_demux, "cannot find EbmlHead" );
...@@ -648,23 +655,23 @@ static int Open( vlc_object_t * p_this ) ...@@ -648,23 +655,23 @@ static int Open( vlc_object_t * p_this )
} }
msg_Dbg( p_demux, "EbmlHead" ); msg_Dbg( p_demux, "EbmlHead" );
/* skip it */ /* skip it */
el->SkipData( *p_stream->es, el->Generic().Context ); el->SkipData( *p_stream->p_es, el->Generic().Context );
delete el; delete el;
/* Find a segment */ /* Find a segment */
el = p_stream->es->FindNextID( KaxSegment::ClassInfos, 0xFFFFFFFFL); el = p_stream->p_es->FindNextID( KaxSegment::ClassInfos, 0xFFFFFFFFL);
if( el == NULL ) if( el == NULL )
{ {
msg_Err( p_demux, "cannot find KaxSegment" ); msg_Err( p_demux, "cannot find KaxSegment" );
goto error; goto error;
} }
MkvTree( p_demux, 0, "Segment" ); MkvTree( *p_demux, 0, "Segment" );
p_segment->segment = (KaxSegment*)el; p_segment->segment = (KaxSegment*)el;
p_segment->cluster = NULL; p_segment->cluster = NULL;
p_segment->ep = new EbmlParser( p_stream->es, el ); p_segment->ep = new EbmlParser( p_stream->p_es, el );
p_segment->Preload( p_demux ); p_segment->Preload( );
/* get the files from the same dir from the same family (based on p_demux->psz_path) */ /* get the files from the same dir from the same family (based on p_demux->psz_path) */
/* TODO handle multi-segment files */ /* TODO handle multi-segment files */
...@@ -730,8 +737,8 @@ static int Open( vlc_object_t * p_this ) ...@@ -730,8 +737,8 @@ static int Open( vlc_object_t * p_this )
goto error; goto error;
} }
p_sys->PreloadFamily( p_demux ); p_sys->PreloadFamily( );
p_sys->PreloadLinked( p_demux ); p_sys->PreloadLinked( );
/* *** Load the cue if found *** */ /* *** Load the cue if found *** */
if( p_segment->i_cues_position >= 0 ) if( p_segment->i_cues_position >= 0 )
...@@ -1236,7 +1243,7 @@ static int BlockGet( demux_t *p_demux, KaxBlock **pp_block, int64_t *pi_ref1, in ...@@ -1236,7 +1243,7 @@ static int BlockGet( demux_t *p_demux, KaxBlock **pp_block, int64_t *pi_ref1, in
{ {
KaxClusterTimecode &ctc = *(KaxClusterTimecode*)el; KaxClusterTimecode &ctc = *(KaxClusterTimecode*)el;
ctc.ReadData( p_stream->es->I_O(), SCOPE_ALL_DATA ); ctc.ReadData( p_stream->p_es->I_O(), SCOPE_ALL_DATA );
p_segment->cluster->InitTimecode( uint64( ctc ), p_segment->i_timescale ); p_segment->cluster->InitTimecode( uint64( ctc ), p_segment->i_timescale );
} }
else if( MKV_IS_ID( el, KaxBlockGroup ) ) else if( MKV_IS_ID( el, KaxBlockGroup ) )
...@@ -1250,7 +1257,7 @@ static int BlockGet( demux_t *p_demux, KaxBlock **pp_block, int64_t *pi_ref1, in ...@@ -1250,7 +1257,7 @@ static int BlockGet( demux_t *p_demux, KaxBlock **pp_block, int64_t *pi_ref1, in
{ {
*pp_block = (KaxBlock*)el; *pp_block = (KaxBlock*)el;
(*pp_block)->ReadData( p_stream->es->I_O() ); (*pp_block)->ReadData( p_stream->p_es->I_O() );
(*pp_block)->SetParent( *p_segment->cluster ); (*pp_block)->SetParent( *p_segment->cluster );
p_segment->ep->Keep(); p_segment->ep->Keep();
...@@ -1259,14 +1266,14 @@ static int BlockGet( demux_t *p_demux, KaxBlock **pp_block, int64_t *pi_ref1, in ...@@ -1259,14 +1266,14 @@ static int BlockGet( demux_t *p_demux, KaxBlock **pp_block, int64_t *pi_ref1, in
{ {
KaxBlockDuration &dur = *(KaxBlockDuration*)el; KaxBlockDuration &dur = *(KaxBlockDuration*)el;
dur.ReadData( p_stream->es->I_O() ); dur.ReadData( p_stream->p_es->I_O() );
*pi_duration = uint64( dur ); *pi_duration = uint64( dur );
} }
else if( MKV_IS_ID( el, KaxReferenceBlock ) ) else if( MKV_IS_ID( el, KaxReferenceBlock ) )
{ {
KaxReferenceBlock &ref = *(KaxReferenceBlock*)el; KaxReferenceBlock &ref = *(KaxReferenceBlock*)el;
ref.ReadData( p_stream->es->I_O() ); ref.ReadData( p_stream->p_es->I_O() );
if( *pi_ref1 == -1 ) if( *pi_ref1 == -1 )
{ {
*pi_ref1 = int64( ref ); *pi_ref1 = int64( ref );
...@@ -1393,7 +1400,7 @@ static void BlockDecode( demux_t *p_demux, KaxBlock *block, mtime_t i_pts, ...@@ -1393,7 +1400,7 @@ static void BlockDecode( demux_t *p_demux, KaxBlock *block, mtime_t i_pts,
bool demux_sys_t::AnalyseAllSegmentsFound( EbmlStream *p_estream ) bool demux_sys_t::AnalyseAllSegmentsFound( EbmlStream *p_estream )
{ {
return false; return false; // FIXME safer until this thing works
int i_upper_lvl = 0; int i_upper_lvl = 0;
size_t i; size_t i;
EbmlElement *p_l0, *p_l1, *p_l2; EbmlElement *p_l0, *p_l1, *p_l2;
...@@ -1406,7 +1413,7 @@ return false; ...@@ -1406,7 +1413,7 @@ return false;
return false; return false;
} }
matroska_stream_t *p_stream1 = new matroska_stream_t( this ); matroska_stream_t *p_stream1 = new matroska_stream_t( *this );
p_l0->SkipData(*p_estream, EbmlHead_Context); p_l0->SkipData(*p_estream, EbmlHead_Context);
delete p_l0; delete p_l0;
...@@ -1424,7 +1431,7 @@ return false; ...@@ -1424,7 +1431,7 @@ return false;
if (EbmlId(*p_l0) == KaxSegment::ClassInfos.GlobalId) if (EbmlId(*p_l0) == KaxSegment::ClassInfos.GlobalId)
{ {
EbmlParser *ep; EbmlParser *ep;
matroska_segment_t *p_segment1 = new matroska_segment_t( this ); matroska_segment_t *p_segment1 = new matroska_segment_t( *this, *p_estream );
b_keep_segment = false; b_keep_segment = false;
ep = new EbmlParser(p_estream, p_l0); ep = new EbmlParser(p_estream, p_l0);
...@@ -1557,7 +1564,7 @@ static void Seek( demux_t *p_demux, mtime_t i_date, double f_percent, const chap ...@@ -1557,7 +1564,7 @@ static void Seek( demux_t *p_demux, mtime_t i_date, double f_percent, const chap
} }
delete p_segment->ep; delete p_segment->ep;
p_segment->ep = new EbmlParser( p_stream->es, p_segment->segment ); p_segment->ep = new EbmlParser( p_stream->p_es, p_segment->segment );
p_segment->cluster = NULL; p_segment->cluster = NULL;
/* seek without index or without date */ /* seek without index or without date */
...@@ -1652,7 +1659,7 @@ static void Seek( demux_t *p_demux, mtime_t i_date, double f_percent, const chap ...@@ -1652,7 +1659,7 @@ static void Seek( demux_t *p_demux, mtime_t i_date, double f_percent, const chap
(int)( 100 * p_segment->index[i_index].i_position / (int)( 100 * p_segment->index[i_index].i_position /
stream_Size( p_demux->s ) ) ); stream_Size( p_demux->s ) ) );
p_stream->in->setFilePointer( p_segment->index[i_index].i_position, p_stream->p_in->setFilePointer( p_segment->index[i_index].i_position,
seek_beginning ); seek_beginning );
p_sys->i_start_pts = i_date; p_sys->i_start_pts = i_date;
...@@ -1972,22 +1979,22 @@ static void LoadCues( demux_t *p_demux ) ...@@ -1972,22 +1979,22 @@ static void LoadCues( demux_t *p_demux )
demux_sys_t *p_sys = p_demux->p_sys; demux_sys_t *p_sys = p_demux->p_sys;
matroska_stream_t *p_stream = p_sys->Stream(); matroska_stream_t *p_stream = p_sys->Stream();
matroska_segment_t *p_segment = p_stream->Segment(); matroska_segment_t *p_segment = p_stream->Segment();
int64_t i_sav_position = p_stream->in->getFilePointer(); int64_t i_sav_position = p_stream->p_in->getFilePointer();
EbmlParser *ep; EbmlParser *ep;
EbmlElement *el, *cues; EbmlElement *el, *cues;
msg_Dbg( p_demux, "loading cues" ); msg_Dbg( p_demux, "loading cues" );
p_stream->in->setFilePointer( p_segment->i_cues_position, seek_beginning ); p_stream->p_in->setFilePointer( p_segment->i_cues_position, seek_beginning );
cues = p_stream->es->FindNextID( KaxCues::ClassInfos, 0xFFFFFFFFL); cues = p_stream->p_es->FindNextID( KaxCues::ClassInfos, 0xFFFFFFFFL);
if( cues == NULL ) if( cues == NULL )
{ {
msg_Err( p_demux, "cannot load cues (broken seekhead or file)" ); msg_Err( p_demux, "cannot load cues (broken seekhead or file)" );
p_stream->in->setFilePointer( i_sav_position, seek_beginning ); p_stream->p_in->setFilePointer( i_sav_position, seek_beginning );
return; return;
} }
ep = new EbmlParser( p_stream->es, cues ); ep = new EbmlParser( p_stream->p_es, cues );
while( ( el = ep->Get() ) != NULL ) while( ( el = ep->Get() ) != NULL )
{ {
if( MKV_IS_ID( el, KaxCuePoint ) ) if( MKV_IS_ID( el, KaxCuePoint ) )
...@@ -2007,7 +2014,7 @@ static void LoadCues( demux_t *p_demux ) ...@@ -2007,7 +2014,7 @@ static void LoadCues( demux_t *p_demux )
{ {
KaxCueTime &ctime = *(KaxCueTime*)el; KaxCueTime &ctime = *(KaxCueTime*)el;
ctime.ReadData( p_stream->es->I_O() ); ctime.ReadData( p_stream->p_es->I_O() );
idx.i_time = uint64( ctime ) * p_segment->i_timescale / (mtime_t)1000; idx.i_time = uint64( ctime ) * p_segment->i_timescale / (mtime_t)1000;
} }
...@@ -2020,21 +2027,21 @@ static void LoadCues( demux_t *p_demux ) ...@@ -2020,21 +2027,21 @@ static void LoadCues( demux_t *p_demux )
{ {
KaxCueTrack &ctrack = *(KaxCueTrack*)el; KaxCueTrack &ctrack = *(KaxCueTrack*)el;
ctrack.ReadData( p_stream->es->I_O() ); ctrack.ReadData( p_stream->p_es->I_O() );
idx.i_track = uint16( ctrack ); idx.i_track = uint16( ctrack );
} }
else if( MKV_IS_ID( el, KaxCueClusterPosition ) ) else if( MKV_IS_ID( el, KaxCueClusterPosition ) )
{ {
KaxCueClusterPosition &ccpos = *(KaxCueClusterPosition*)el; KaxCueClusterPosition &ccpos = *(KaxCueClusterPosition*)el;
ccpos.ReadData( p_stream->es->I_O() ); ccpos.ReadData( p_stream->p_es->I_O() );
idx.i_position = p_segment->segment->GetGlobalPosition( uint64( ccpos ) ); idx.i_position = p_segment->segment->GetGlobalPosition( uint64( ccpos ) );
} }
else if( MKV_IS_ID( el, KaxCueBlockNumber ) ) else if( MKV_IS_ID( el, KaxCueBlockNumber ) )
{ {
KaxCueBlockNumber &cbnum = *(KaxCueBlockNumber*)el; KaxCueBlockNumber &cbnum = *(KaxCueBlockNumber*)el;
cbnum.ReadData( p_stream->es->I_O() ); cbnum.ReadData( p_stream->p_es->I_O() );
idx.i_block_number = uint32( cbnum ); idx.i_block_number = uint32( cbnum );
} }
else else
...@@ -2076,7 +2083,7 @@ static void LoadCues( demux_t *p_demux ) ...@@ -2076,7 +2083,7 @@ static void LoadCues( demux_t *p_demux )
p_segment->b_cues = VLC_TRUE; p_segment->b_cues = VLC_TRUE;
msg_Dbg( p_demux, "loading cues done." ); msg_Dbg( p_demux, "loading cues done." );
p_stream->in->setFilePointer( i_sav_position, seek_beginning ); p_stream->p_in->setFilePointer( i_sav_position, seek_beginning );
} }
static void LoadTags( demux_t *p_demux ) static void LoadTags( demux_t *p_demux )
...@@ -2084,23 +2091,23 @@ static void LoadTags( demux_t *p_demux ) ...@@ -2084,23 +2091,23 @@ static void LoadTags( demux_t *p_demux )
demux_sys_t *p_sys = p_demux->p_sys; demux_sys_t *p_sys = p_demux->p_sys;
matroska_stream_t *p_stream = p_sys->Stream(); matroska_stream_t *p_stream = p_sys->Stream();
matroska_segment_t *p_segment = p_stream->Segment(); matroska_segment_t *p_segment = p_stream->Segment();
int64_t i_sav_position = p_stream->in->getFilePointer(); int64_t i_sav_position = p_stream->p_in->getFilePointer();
EbmlParser *ep; EbmlParser *ep;
EbmlElement *el, *tags; EbmlElement *el, *tags;
msg_Dbg( p_demux, "loading tags" ); msg_Dbg( p_demux, "loading tags" );
p_stream->in->setFilePointer( p_segment->i_tags_position, seek_beginning ); p_stream->p_in->setFilePointer( p_segment->i_tags_position, seek_beginning );
tags = p_stream->es->FindNextID( KaxTags::ClassInfos, 0xFFFFFFFFL); tags = p_stream->p_es->FindNextID( KaxTags::ClassInfos, 0xFFFFFFFFL);
if( tags == NULL ) if( tags == NULL )
{ {
msg_Err( p_demux, "cannot load tags (broken seekhead or file)" ); msg_Err( p_demux, "cannot load tags (broken seekhead or file)" );
p_stream->in->setFilePointer( i_sav_position, seek_beginning ); p_stream->p_in->setFilePointer( i_sav_position, seek_beginning );
return; return;
} }
msg_Dbg( p_demux, "Tags" ); msg_Dbg( p_demux, "Tags" );
ep = new EbmlParser( p_stream->es, tags ); ep = new EbmlParser( p_stream->p_es, tags );
while( ( el = ep->Get() ) != NULL ) while( ( el = ep->Get() ) != NULL )
{ {
if( MKV_IS_ID( el, KaxTag ) ) if( MKV_IS_ID( el, KaxTag ) )
...@@ -2203,27 +2210,24 @@ static void LoadTags( demux_t *p_demux ) ...@@ -2203,27 +2210,24 @@ static void LoadTags( demux_t *p_demux )
delete tags; delete tags;
msg_Dbg( p_demux, "loading tags done." ); msg_Dbg( p_demux, "loading tags done." );
p_stream->in->setFilePointer( i_sav_position, seek_beginning ); p_stream->p_in->setFilePointer( i_sav_position, seek_beginning );
} }
/***************************************************************************** /*****************************************************************************
* ParseInfo: * ParseSeekHead:
*****************************************************************************/ *****************************************************************************/
static void ParseSeekHead( demux_t *p_demux, EbmlElement *seekhead ) void matroska_segment_t::ParseSeekHead( EbmlElement *seekhead )
{ {
demux_sys_t *p_sys = p_demux->p_sys;
matroska_stream_t *p_stream = p_sys->Stream();
matroska_segment_t *p_segment = p_stream->Segment();
EbmlElement *el; EbmlElement *el;
EbmlMaster *m; EbmlMaster *m;
unsigned int i; unsigned int i;
int i_upper_level = 0; int i_upper_level = 0;
msg_Dbg( p_demux, "| + Seek head" ); msg_Dbg( &sys.demuxer, "| + Seek head" );
/* Master elements */ /* Master elements */
m = static_cast<EbmlMaster *>(seekhead); m = static_cast<EbmlMaster *>(seekhead);
m->Read( *p_stream->es, seekhead->Generic().Context, i_upper_level, el, true ); m->Read( es, seekhead->Generic().Context, i_upper_level, el, true );
for( i = 0; i < m->ListSize(); i++ ) for( i = 0; i < m->ListSize(); i++ )
{ {
...@@ -2253,7 +2257,7 @@ static void ParseSeekHead( demux_t *p_demux, EbmlElement *seekhead ) ...@@ -2253,7 +2257,7 @@ static void ParseSeekHead( demux_t *p_demux, EbmlElement *seekhead )
} }
else else
{ {
msg_Dbg( p_demux, "| | | + Unknown (%s)", typeid(*l).name() ); msg_Dbg( &sys.demuxer, "| | | + Unknown (%s)", typeid(*l).name() );
} }
} }
...@@ -2261,24 +2265,24 @@ static void ParseSeekHead( demux_t *p_demux, EbmlElement *seekhead ) ...@@ -2261,24 +2265,24 @@ static void ParseSeekHead( demux_t *p_demux, EbmlElement *seekhead )
{ {
if( id == KaxCues::ClassInfos.GlobalId ) if( id == KaxCues::ClassInfos.GlobalId )
{ {
msg_Dbg( p_demux, "| | | = cues at "I64Fd, i_pos ); msg_Dbg( &sys.demuxer, "| | | = cues at "I64Fd, i_pos );
p_segment->i_cues_position = p_segment->segment->GetGlobalPosition( i_pos ); i_cues_position = segment->GetGlobalPosition( i_pos );
} }
else if( id == KaxChapters::ClassInfos.GlobalId ) else if( id == KaxChapters::ClassInfos.GlobalId )
{ {
msg_Dbg( p_demux, "| | | = chapters at "I64Fd, i_pos ); msg_Dbg( &sys.demuxer, "| | | = chapters at "I64Fd, i_pos );
p_segment->i_chapters_position = p_segment->segment->GetGlobalPosition( i_pos ); i_chapters_position = segment->GetGlobalPosition( i_pos );
} }
else if( id == KaxTags::ClassInfos.GlobalId ) else if( id == KaxTags::ClassInfos.GlobalId )
{ {
msg_Dbg( p_demux, "| | | = tags at "I64Fd, i_pos ); msg_Dbg( &sys.demuxer, "| | | = tags at "I64Fd, i_pos );
p_segment->i_tags_position = p_segment->segment->GetGlobalPosition( i_pos ); i_tags_position = segment->GetGlobalPosition( i_pos );
} }
} }
} }
else else
{ {
msg_Dbg( p_demux, "| | + Unknown (%s)", typeid(*l).name() ); msg_Dbg( &sys.demuxer, "| | + Unknown (%s)", typeid(*l).name() );
} }
} }
} }
...@@ -2286,19 +2290,16 @@ static void ParseSeekHead( demux_t *p_demux, EbmlElement *seekhead ) ...@@ -2286,19 +2290,16 @@ static void ParseSeekHead( demux_t *p_demux, EbmlElement *seekhead )
/***************************************************************************** /*****************************************************************************
* ParseTracks: * ParseTracks:
*****************************************************************************/ *****************************************************************************/
static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m ) void matroska_segment_t::ParseTrackEntry( EbmlMaster *m )
{ {
demux_sys_t *p_sys = p_demux->p_sys;
matroska_stream_t *p_stream = p_sys->Stream();
matroska_segment_t *p_segment = p_stream->Segment();
unsigned int i; unsigned int i;
mkv_track_t *tk; mkv_track_t *tk;
msg_Dbg( p_demux, "| | + Track Entry" ); msg_Dbg( &sys.demuxer, "| | + Track Entry" );
tk = new mkv_track_t(); tk = new mkv_track_t();
p_segment->tracks.push_back( tk ); tracks.push_back( tk );
/* Init the track */ /* Init the track */
memset( tk, 0, sizeof( mkv_track_t ) ); memset( tk, 0, sizeof( mkv_track_t ) );
...@@ -2309,7 +2310,7 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m ) ...@@ -2309,7 +2310,7 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m )
tk->b_default = VLC_TRUE; tk->b_default = VLC_TRUE;
tk->b_enabled = VLC_TRUE; tk->b_enabled = VLC_TRUE;
tk->i_number = p_segment->tracks.size() - 1; tk->i_number = tracks.size() - 1;
tk->i_extra_data = 0; tk->i_extra_data = 0;
tk->p_extra_data = NULL; tk->p_extra_data = NULL;
tk->psz_codec = NULL; tk->psz_codec = NULL;
...@@ -2336,13 +2337,13 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m ) ...@@ -2336,13 +2337,13 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m )
KaxTrackNumber &tnum = *(KaxTrackNumber*)l; KaxTrackNumber &tnum = *(KaxTrackNumber*)l;
tk->i_number = uint32( tnum ); tk->i_number = uint32( tnum );
msg_Dbg( p_demux, "| | | + Track Number=%u", uint32( tnum ) ); msg_Dbg( &sys.demuxer, "| | | + Track Number=%u", uint32( tnum ) );
} }
else if( MKV_IS_ID( l, KaxTrackUID ) ) else if( MKV_IS_ID( l, KaxTrackUID ) )
{ {
KaxTrackUID &tuid = *(KaxTrackUID*)l; KaxTrackUID &tuid = *(KaxTrackUID*)l;
msg_Dbg( p_demux, "| | | + Track UID=%u", uint32( tuid ) ); msg_Dbg( &sys.demuxer, "| | | + Track UID=%u", uint32( tuid ) );
} }
else if( MKV_IS_ID( l, KaxTrackType ) ) else if( MKV_IS_ID( l, KaxTrackType ) )
{ {
...@@ -2369,14 +2370,14 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m ) ...@@ -2369,14 +2370,14 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m )
break; break;
} }
msg_Dbg( p_demux, "| | | + Track Type=%s", psz_type ); msg_Dbg( &sys.demuxer, "| | | + Track Type=%s", psz_type );
} }
// else if( EbmlId( *l ) == KaxTrackFlagEnabled::ClassInfos.GlobalId ) // else if( EbmlId( *l ) == KaxTrackFlagEnabled::ClassInfos.GlobalId )
// { // {
// KaxTrackFlagEnabled &fenb = *(KaxTrackFlagEnabled*)l; // KaxTrackFlagEnabled &fenb = *(KaxTrackFlagEnabled*)l;
// tk->b_enabled = uint32( fenb ); // tk->b_enabled = uint32( fenb );
// msg_Dbg( p_demux, "| | | + Track Enabled=%u", // msg_Dbg( &sys.demuxer, "| | | + Track Enabled=%u",
// uint32( fenb ) ); // uint32( fenb ) );
// } // }
else if( MKV_IS_ID( l, KaxTrackFlagDefault ) ) else if( MKV_IS_ID( l, KaxTrackFlagDefault ) )
...@@ -2384,53 +2385,53 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m ) ...@@ -2384,53 +2385,53 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m )
KaxTrackFlagDefault &fdef = *(KaxTrackFlagDefault*)l; KaxTrackFlagDefault &fdef = *(KaxTrackFlagDefault*)l;
tk->b_default = uint32( fdef ); tk->b_default = uint32( fdef );
msg_Dbg( p_demux, "| | | + Track Default=%u", uint32( fdef ) ); msg_Dbg( &sys.demuxer, "| | | + Track Default=%u", uint32( fdef ) );
} }
else if( MKV_IS_ID( l, KaxTrackFlagLacing ) ) else if( MKV_IS_ID( l, KaxTrackFlagLacing ) )
{ {
KaxTrackFlagLacing &lac = *(KaxTrackFlagLacing*)l; KaxTrackFlagLacing &lac = *(KaxTrackFlagLacing*)l;
msg_Dbg( p_demux, "| | | + Track Lacing=%d", uint32( lac ) ); msg_Dbg( &sys.demuxer, "| | | + Track Lacing=%d", uint32( lac ) );
} }
else if( MKV_IS_ID( l, KaxTrackMinCache ) ) else if( MKV_IS_ID( l, KaxTrackMinCache ) )
{ {
KaxTrackMinCache &cmin = *(KaxTrackMinCache*)l; KaxTrackMinCache &cmin = *(KaxTrackMinCache*)l;
msg_Dbg( p_demux, "| | | + Track MinCache=%d", uint32( cmin ) ); msg_Dbg( &sys.demuxer, "| | | + Track MinCache=%d", uint32( cmin ) );
} }
else if( MKV_IS_ID( l, KaxTrackMaxCache ) ) else if( MKV_IS_ID( l, KaxTrackMaxCache ) )
{ {
KaxTrackMaxCache &cmax = *(KaxTrackMaxCache*)l; KaxTrackMaxCache &cmax = *(KaxTrackMaxCache*)l;
msg_Dbg( p_demux, "| | | + Track MaxCache=%d", uint32( cmax ) ); msg_Dbg( &sys.demuxer, "| | | + Track MaxCache=%d", uint32( cmax ) );
} }
else if( MKV_IS_ID( l, KaxTrackDefaultDuration ) ) else if( MKV_IS_ID( l, KaxTrackDefaultDuration ) )
{ {
KaxTrackDefaultDuration &defd = *(KaxTrackDefaultDuration*)l; KaxTrackDefaultDuration &defd = *(KaxTrackDefaultDuration*)l;
tk->i_default_duration = uint64(defd); tk->i_default_duration = uint64(defd);
msg_Dbg( p_demux, "| | | + Track Default Duration="I64Fd, uint64(defd) ); msg_Dbg( &sys.demuxer, "| | | + Track Default Duration="I64Fd, uint64(defd) );
} }
else if( MKV_IS_ID( l, KaxTrackTimecodeScale ) ) else if( MKV_IS_ID( l, KaxTrackTimecodeScale ) )
{ {
KaxTrackTimecodeScale &ttcs = *(KaxTrackTimecodeScale*)l; KaxTrackTimecodeScale &ttcs = *(KaxTrackTimecodeScale*)l;
tk->f_timecodescale = float( ttcs ); tk->f_timecodescale = float( ttcs );
msg_Dbg( p_demux, "| | | + Track TimeCodeScale=%f", tk->f_timecodescale ); msg_Dbg( &sys.demuxer, "| | | + Track TimeCodeScale=%f", tk->f_timecodescale );
} }
else if( MKV_IS_ID( l, KaxTrackName ) ) else if( MKV_IS_ID( l, KaxTrackName ) )
{ {
KaxTrackName &tname = *(KaxTrackName*)l; KaxTrackName &tname = *(KaxTrackName*)l;
tk->fmt.psz_description = UTF8ToStr( UTFstring( tname ) ); tk->fmt.psz_description = UTF8ToStr( UTFstring( tname ) );
msg_Dbg( p_demux, "| | | + Track Name=%s", tk->fmt.psz_description ); msg_Dbg( &sys.demuxer, "| | | + Track Name=%s", tk->fmt.psz_description );
} }
else if( MKV_IS_ID( l, KaxTrackLanguage ) ) else if( MKV_IS_ID( l, KaxTrackLanguage ) )
{ {
KaxTrackLanguage &lang = *(KaxTrackLanguage*)l; KaxTrackLanguage &lang = *(KaxTrackLanguage*)l;
tk->fmt.psz_language = strdup( string( lang ).c_str() ); tk->fmt.psz_language = strdup( string( lang ).c_str() );
msg_Dbg( p_demux, msg_Dbg( &sys.demuxer,
"| | | + Track Language=`%s'", tk->fmt.psz_language ); "| | | + Track Language=`%s'", tk->fmt.psz_language );
} }
else if( MKV_IS_ID( l, KaxCodecID ) ) else if( MKV_IS_ID( l, KaxCodecID ) )
...@@ -2438,7 +2439,7 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m ) ...@@ -2438,7 +2439,7 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m )
KaxCodecID &codecid = *(KaxCodecID*)l; KaxCodecID &codecid = *(KaxCodecID*)l;
tk->psz_codec = strdup( string( codecid ).c_str() ); tk->psz_codec = strdup( string( codecid ).c_str() );
msg_Dbg( p_demux, "| | | + Track CodecId=%s", string( codecid ).c_str() ); msg_Dbg( &sys.demuxer, "| | | + Track CodecId=%s", string( codecid ).c_str() );
} }
else if( MKV_IS_ID( l, KaxCodecPrivate ) ) else if( MKV_IS_ID( l, KaxCodecPrivate ) )
{ {
...@@ -2450,25 +2451,25 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m ) ...@@ -2450,25 +2451,25 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m )
tk->p_extra_data = (uint8_t*)malloc( tk->i_extra_data ); tk->p_extra_data = (uint8_t*)malloc( tk->i_extra_data );
memcpy( tk->p_extra_data, cpriv.GetBuffer(), tk->i_extra_data ); memcpy( tk->p_extra_data, cpriv.GetBuffer(), tk->i_extra_data );
} }
msg_Dbg( p_demux, "| | | + Track CodecPrivate size="I64Fd, cpriv.GetSize() ); msg_Dbg( &sys.demuxer, "| | | + Track CodecPrivate size="I64Fd, cpriv.GetSize() );
} }
else if( MKV_IS_ID( l, KaxCodecName ) ) else if( MKV_IS_ID( l, KaxCodecName ) )
{ {
KaxCodecName &cname = *(KaxCodecName*)l; KaxCodecName &cname = *(KaxCodecName*)l;
tk->psz_codec_name = UTF8ToStr( UTFstring( cname ) ); tk->psz_codec_name = UTF8ToStr( UTFstring( cname ) );
msg_Dbg( p_demux, "| | | + Track Codec Name=%s", tk->psz_codec_name ); msg_Dbg( &sys.demuxer, "| | | + Track Codec Name=%s", tk->psz_codec_name );
} }
else if( MKV_IS_ID( l, KaxContentEncodings ) ) else if( MKV_IS_ID( l, KaxContentEncodings ) )
{ {
EbmlMaster *cencs = static_cast<EbmlMaster*>(l); EbmlMaster *cencs = static_cast<EbmlMaster*>(l);
MkvTree( p_demux, 3, "Content Encodings" ); MkvTree( sys.demuxer, 3, "Content Encodings" );
for( unsigned int i = 0; i < cencs->ListSize(); i++ ) for( unsigned int i = 0; i < cencs->ListSize(); i++ )
{ {
EbmlElement *l2 = (*cencs)[i]; EbmlElement *l2 = (*cencs)[i];
if( MKV_IS_ID( l2, KaxContentEncoding ) ) if( MKV_IS_ID( l2, KaxContentEncoding ) )
{ {
MkvTree( p_demux, 4, "Content Encoding" ); MkvTree( sys.demuxer, 4, "Content Encoding" );
EbmlMaster *cenc = static_cast<EbmlMaster*>(l2); EbmlMaster *cenc = static_cast<EbmlMaster*>(l2);
for( unsigned int i = 0; i < cenc->ListSize(); i++ ) for( unsigned int i = 0; i < cenc->ListSize(); i++ )
{ {
...@@ -2476,29 +2477,29 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m ) ...@@ -2476,29 +2477,29 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m )
if( MKV_IS_ID( l3, KaxContentEncodingOrder ) ) if( MKV_IS_ID( l3, KaxContentEncodingOrder ) )
{ {
KaxContentEncodingOrder &encord = *(KaxContentEncodingOrder*)l3; KaxContentEncodingOrder &encord = *(KaxContentEncodingOrder*)l3;
MkvTree( p_demux, 5, "Order: %i", uint32( encord ) ); MkvTree( sys.demuxer, 5, "Order: %i", uint32( encord ) );
} }
else if( MKV_IS_ID( l3, KaxContentEncodingScope ) ) else if( MKV_IS_ID( l3, KaxContentEncodingScope ) )
{ {
KaxContentEncodingScope &encscope = *(KaxContentEncodingScope*)l3; KaxContentEncodingScope &encscope = *(KaxContentEncodingScope*)l3;
MkvTree( p_demux, 5, "Scope: %i", uint32( encscope ) ); MkvTree( sys.demuxer, 5, "Scope: %i", uint32( encscope ) );
} }
else if( MKV_IS_ID( l3, KaxContentEncodingType ) ) else if( MKV_IS_ID( l3, KaxContentEncodingType ) )
{ {
KaxContentEncodingType &enctype = *(KaxContentEncodingType*)l3; KaxContentEncodingType &enctype = *(KaxContentEncodingType*)l3;
MkvTree( p_demux, 5, "Type: %i", uint32( enctype ) ); MkvTree( sys.demuxer, 5, "Type: %i", uint32( enctype ) );
} }
else if( MKV_IS_ID( l3, KaxContentCompression ) ) else if( MKV_IS_ID( l3, KaxContentCompression ) )
{ {
EbmlMaster *compr = static_cast<EbmlMaster*>(l3); EbmlMaster *compr = static_cast<EbmlMaster*>(l3);
MkvTree( p_demux, 5, "Content Compression" ); MkvTree( sys.demuxer, 5, "Content Compression" );
for( unsigned int i = 0; i < compr->ListSize(); i++ ) for( unsigned int i = 0; i < compr->ListSize(); i++ )
{ {
EbmlElement *l4 = (*compr)[i]; EbmlElement *l4 = (*compr)[i];
if( MKV_IS_ID( l4, KaxContentCompAlgo ) ) if( MKV_IS_ID( l4, KaxContentCompAlgo ) )
{ {
KaxContentCompAlgo &compalg = *(KaxContentCompAlgo*)l4; KaxContentCompAlgo &compalg = *(KaxContentCompAlgo*)l4;
MkvTree( p_demux, 6, "Compression Algorithm: %i", uint32(compalg) ); MkvTree( sys.demuxer, 6, "Compression Algorithm: %i", uint32(compalg) );
if( uint32( compalg ) == 0 ) if( uint32( compalg ) == 0 )
{ {
tk->i_compression_type = MATROSKA_COMPRESSION_ZLIB; tk->i_compression_type = MATROSKA_COMPRESSION_ZLIB;
...@@ -2506,21 +2507,21 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m ) ...@@ -2506,21 +2507,21 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m )
} }
else else
{ {
MkvTree( p_demux, 6, "Unknown (%s)", typeid(*l4).name() ); MkvTree( sys.demuxer, 6, "Unknown (%s)", typeid(*l4).name() );
} }
} }
} }
else else
{ {
MkvTree( p_demux, 5, "Unknown (%s)", typeid(*l3).name() ); MkvTree( sys.demuxer, 5, "Unknown (%s)", typeid(*l3).name() );
} }
} }
} }
else else
{ {
MkvTree( p_demux, 4, "Unknown (%s)", typeid(*l2).name() ); MkvTree( sys.demuxer, 4, "Unknown (%s)", typeid(*l2).name() );
} }
} }
...@@ -2530,40 +2531,40 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m ) ...@@ -2530,40 +2531,40 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m )
// KaxCodecSettings &cset = *(KaxCodecSettings*)l; // KaxCodecSettings &cset = *(KaxCodecSettings*)l;
// tk->psz_codec_settings = UTF8ToStr( UTFstring( cset ) ); // tk->psz_codec_settings = UTF8ToStr( UTFstring( cset ) );
// msg_Dbg( p_demux, "| | | + Track Codec Settings=%s", tk->psz_codec_settings ); // msg_Dbg( &sys.demuxer, "| | | + Track Codec Settings=%s", tk->psz_codec_settings );
// } // }
// else if( EbmlId( *l ) == KaxCodecInfoURL::ClassInfos.GlobalId ) // else if( EbmlId( *l ) == KaxCodecInfoURL::ClassInfos.GlobalId )
// { // {
// KaxCodecInfoURL &ciurl = *(KaxCodecInfoURL*)l; // KaxCodecInfoURL &ciurl = *(KaxCodecInfoURL*)l;
// tk->psz_codec_info_url = strdup( string( ciurl ).c_str() ); // tk->psz_codec_info_url = strdup( string( ciurl ).c_str() );
// msg_Dbg( p_demux, "| | | + Track Codec Info URL=%s", tk->psz_codec_info_url ); // msg_Dbg( &sys.demuxer, "| | | + Track Codec Info URL=%s", tk->psz_codec_info_url );
// } // }
// else if( EbmlId( *l ) == KaxCodecDownloadURL::ClassInfos.GlobalId ) // else if( EbmlId( *l ) == KaxCodecDownloadURL::ClassInfos.GlobalId )
// { // {
// KaxCodecDownloadURL &cdurl = *(KaxCodecDownloadURL*)l; // KaxCodecDownloadURL &cdurl = *(KaxCodecDownloadURL*)l;
// tk->psz_codec_download_url = strdup( string( cdurl ).c_str() ); // tk->psz_codec_download_url = strdup( string( cdurl ).c_str() );
// msg_Dbg( p_demux, "| | | + Track Codec Info URL=%s", tk->psz_codec_download_url ); // msg_Dbg( &sys.demuxer, "| | | + Track Codec Info URL=%s", tk->psz_codec_download_url );
// } // }
// else if( EbmlId( *l ) == KaxCodecDecodeAll::ClassInfos.GlobalId ) // else if( EbmlId( *l ) == KaxCodecDecodeAll::ClassInfos.GlobalId )
// { // {
// KaxCodecDecodeAll &cdall = *(KaxCodecDecodeAll*)l; // KaxCodecDecodeAll &cdall = *(KaxCodecDecodeAll*)l;
// msg_Dbg( p_demux, "| | | + Track Codec Decode All=%u <== UNUSED", uint8( cdall ) ); // msg_Dbg( &sys.demuxer, "| | | + Track Codec Decode All=%u <== UNUSED", uint8( cdall ) );
// } // }
// else if( EbmlId( *l ) == KaxTrackOverlay::ClassInfos.GlobalId ) // else if( EbmlId( *l ) == KaxTrackOverlay::ClassInfos.GlobalId )
// { // {
// KaxTrackOverlay &tovr = *(KaxTrackOverlay*)l; // KaxTrackOverlay &tovr = *(KaxTrackOverlay*)l;
// msg_Dbg( p_demux, "| | | + Track Overlay=%u <== UNUSED", uint32( tovr ) ); // msg_Dbg( &sys.demuxer, "| | | + Track Overlay=%u <== UNUSED", uint32( tovr ) );
// } // }
else if( MKV_IS_ID( l, KaxTrackVideo ) ) else if( MKV_IS_ID( l, KaxTrackVideo ) )
{ {
EbmlMaster *tkv = static_cast<EbmlMaster*>(l); EbmlMaster *tkv = static_cast<EbmlMaster*>(l);
unsigned int j; unsigned int j;
msg_Dbg( p_demux, "| | | + Track Video" ); msg_Dbg( &sys.demuxer, "| | | + Track Video" );
tk->f_fps = 0.0; tk->f_fps = 0.0;
for( j = 0; j < tkv->ListSize(); j++ ) for( j = 0; j < tkv->ListSize(); j++ )
...@@ -2573,13 +2574,13 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m ) ...@@ -2573,13 +2574,13 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m )
// { // {
// KaxVideoFlagInterlaced &fint = *(KaxVideoFlagInterlaced*)el4; // KaxVideoFlagInterlaced &fint = *(KaxVideoFlagInterlaced*)el4;
// msg_Dbg( p_demux, "| | | | + Track Video Interlaced=%u", uint8( fint ) ); // msg_Dbg( &sys.demuxer, "| | | | + Track Video Interlaced=%u", uint8( fint ) );
// } // }
// else if( EbmlId( *el4 ) == KaxVideoStereoMode::ClassInfos.GlobalId ) // else if( EbmlId( *el4 ) == KaxVideoStereoMode::ClassInfos.GlobalId )
// { // {
// KaxVideoStereoMode &stereo = *(KaxVideoStereoMode*)el4; // KaxVideoStereoMode &stereo = *(KaxVideoStereoMode*)el4;
// msg_Dbg( p_demux, "| | | | + Track Video Stereo Mode=%u", uint8( stereo ) ); // msg_Dbg( &sys.demuxer, "| | | | + Track Video Stereo Mode=%u", uint8( stereo ) );
// } // }
// else // else
if( MKV_IS_ID( l, KaxVideoPixelWidth ) ) if( MKV_IS_ID( l, KaxVideoPixelWidth ) )
...@@ -2587,58 +2588,58 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m ) ...@@ -2587,58 +2588,58 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m )
KaxVideoPixelWidth &vwidth = *(KaxVideoPixelWidth*)l; KaxVideoPixelWidth &vwidth = *(KaxVideoPixelWidth*)l;
tk->fmt.video.i_width = uint16( vwidth ); tk->fmt.video.i_width = uint16( vwidth );
msg_Dbg( p_demux, "| | | | + width=%d", uint16( vwidth ) ); msg_Dbg( &sys.demuxer, "| | | | + width=%d", uint16( vwidth ) );
} }
else if( MKV_IS_ID( l, KaxVideoPixelHeight ) ) else if( MKV_IS_ID( l, KaxVideoPixelHeight ) )
{ {
KaxVideoPixelWidth &vheight = *(KaxVideoPixelWidth*)l; KaxVideoPixelWidth &vheight = *(KaxVideoPixelWidth*)l;
tk->fmt.video.i_height = uint16( vheight ); tk->fmt.video.i_height = uint16( vheight );
msg_Dbg( p_demux, "| | | | + height=%d", uint16( vheight ) ); msg_Dbg( &sys.demuxer, "| | | | + height=%d", uint16( vheight ) );
} }
else if( MKV_IS_ID( l, KaxVideoDisplayWidth ) ) else if( MKV_IS_ID( l, KaxVideoDisplayWidth ) )
{ {
KaxVideoDisplayWidth &vwidth = *(KaxVideoDisplayWidth*)l; KaxVideoDisplayWidth &vwidth = *(KaxVideoDisplayWidth*)l;
tk->fmt.video.i_visible_width = uint16( vwidth ); tk->fmt.video.i_visible_width = uint16( vwidth );
msg_Dbg( p_demux, "| | | | + display width=%d", uint16( vwidth ) ); msg_Dbg( &sys.demuxer, "| | | | + display width=%d", uint16( vwidth ) );
} }
else if( MKV_IS_ID( l, KaxVideoDisplayHeight ) ) else if( MKV_IS_ID( l, KaxVideoDisplayHeight ) )
{ {
KaxVideoDisplayWidth &vheight = *(KaxVideoDisplayWidth*)l; KaxVideoDisplayWidth &vheight = *(KaxVideoDisplayWidth*)l;
tk->fmt.video.i_visible_height = uint16( vheight ); tk->fmt.video.i_visible_height = uint16( vheight );
msg_Dbg( p_demux, "| | | | + display height=%d", uint16( vheight ) ); msg_Dbg( &sys.demuxer, "| | | | + display height=%d", uint16( vheight ) );
} }
else if( MKV_IS_ID( l, KaxVideoFrameRate ) ) else if( MKV_IS_ID( l, KaxVideoFrameRate ) )
{ {
KaxVideoFrameRate &vfps = *(KaxVideoFrameRate*)l; KaxVideoFrameRate &vfps = *(KaxVideoFrameRate*)l;
tk->f_fps = float( vfps ); tk->f_fps = float( vfps );
msg_Dbg( p_demux, " | | | + fps=%f", float( vfps ) ); msg_Dbg( &sys.demuxer, " | | | + fps=%f", float( vfps ) );
} }
// else if( EbmlId( *l ) == KaxVideoDisplayUnit::ClassInfos.GlobalId ) // else if( EbmlId( *l ) == KaxVideoDisplayUnit::ClassInfos.GlobalId )
// { // {
// KaxVideoDisplayUnit &vdmode = *(KaxVideoDisplayUnit*)l; // KaxVideoDisplayUnit &vdmode = *(KaxVideoDisplayUnit*)l;
// msg_Dbg( p_demux, "| | | | + Track Video Display Unit=%s", // msg_Dbg( &sys.demuxer, "| | | | + Track Video Display Unit=%s",
// uint8( vdmode ) == 0 ? "pixels" : ( uint8( vdmode ) == 1 ? "centimeters": "inches" ) ); // uint8( vdmode ) == 0 ? "pixels" : ( uint8( vdmode ) == 1 ? "centimeters": "inches" ) );
// } // }
// else if( EbmlId( *l ) == KaxVideoAspectRatio::ClassInfos.GlobalId ) // else if( EbmlId( *l ) == KaxVideoAspectRatio::ClassInfos.GlobalId )
// { // {
// KaxVideoAspectRatio &ratio = *(KaxVideoAspectRatio*)l; // KaxVideoAspectRatio &ratio = *(KaxVideoAspectRatio*)l;
// msg_Dbg( p_demux, " | | | + Track Video Aspect Ratio Type=%u", uint8( ratio ) ); // msg_Dbg( &sys.demuxer, " | | | + Track Video Aspect Ratio Type=%u", uint8( ratio ) );
// } // }
// else if( EbmlId( *l ) == KaxVideoGamma::ClassInfos.GlobalId ) // else if( EbmlId( *l ) == KaxVideoGamma::ClassInfos.GlobalId )
// { // {
// KaxVideoGamma &gamma = *(KaxVideoGamma*)l; // KaxVideoGamma &gamma = *(KaxVideoGamma*)l;
// msg_Dbg( p_demux, " | | | + fps=%f", float( gamma ) ); // msg_Dbg( &sys.demuxer, " | | | + fps=%f", float( gamma ) );
// } // }
else else
{ {
msg_Dbg( p_demux, "| | | | + Unknown (%s)", typeid(*l).name() ); msg_Dbg( &sys.demuxer, "| | | | + Unknown (%s)", typeid(*l).name() );
} }
} }
if ( tk->fmt.video.i_visible_height && tk->fmt.video.i_visible_width ) if ( tk->fmt.video.i_visible_height && tk->fmt.video.i_visible_width )
...@@ -2649,7 +2650,7 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m ) ...@@ -2649,7 +2650,7 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m )
EbmlMaster *tka = static_cast<EbmlMaster*>(l); EbmlMaster *tka = static_cast<EbmlMaster*>(l);
unsigned int j; unsigned int j;
msg_Dbg( p_demux, "| | | + Track Audio" ); msg_Dbg( &sys.demuxer, "| | | + Track Audio" );
for( j = 0; j < tka->ListSize(); j++ ) for( j = 0; j < tka->ListSize(); j++ )
{ {
...@@ -2660,50 +2661,48 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m ) ...@@ -2660,50 +2661,48 @@ static void ParseTrackEntry( demux_t *p_demux, EbmlMaster *m )
KaxAudioSamplingFreq &afreq = *(KaxAudioSamplingFreq*)l; KaxAudioSamplingFreq &afreq = *(KaxAudioSamplingFreq*)l;
tk->fmt.audio.i_rate = (int)float( afreq ); tk->fmt.audio.i_rate = (int)float( afreq );
msg_Dbg( p_demux, "| | | | + afreq=%d", tk->fmt.audio.i_rate ); msg_Dbg( &sys.demuxer, "| | | | + afreq=%d", tk->fmt.audio.i_rate );
} }
else if( MKV_IS_ID( l, KaxAudioChannels ) ) else if( MKV_IS_ID( l, KaxAudioChannels ) )
{ {
KaxAudioChannels &achan = *(KaxAudioChannels*)l; KaxAudioChannels &achan = *(KaxAudioChannels*)l;
tk->fmt.audio.i_channels = uint8( achan ); tk->fmt.audio.i_channels = uint8( achan );
msg_Dbg( p_demux, "| | | | + achan=%u", uint8( achan ) ); msg_Dbg( &sys.demuxer, "| | | | + achan=%u", uint8( achan ) );
} }
else if( MKV_IS_ID( l, KaxAudioBitDepth ) ) else if( MKV_IS_ID( l, KaxAudioBitDepth ) )
{ {
KaxAudioBitDepth &abits = *(KaxAudioBitDepth*)l; KaxAudioBitDepth &abits = *(KaxAudioBitDepth*)l;
tk->fmt.audio.i_bitspersample = uint8( abits ); tk->fmt.audio.i_bitspersample = uint8( abits );
msg_Dbg( p_demux, "| | | | + abits=%u", uint8( abits ) ); msg_Dbg( &sys.demuxer, "| | | | + abits=%u", uint8( abits ) );
} }
else else
{ {
msg_Dbg( p_demux, "| | | | + Unknown (%s)", typeid(*l).name() ); msg_Dbg( &sys.demuxer, "| | | | + Unknown (%s)", typeid(*l).name() );
} }
} }
} }
else else
{ {
msg_Dbg( p_demux, "| | | + Unknown (%s)", msg_Dbg( &sys.demuxer, "| | | + Unknown (%s)",
typeid(*l).name() ); typeid(*l).name() );
} }
} }
} }
static void ParseTracks( demux_t *p_demux, EbmlElement *tracks ) void matroska_segment_t::ParseTracks( EbmlElement *tracks )
{ {
demux_sys_t *p_sys = p_demux->p_sys;
matroska_stream_t *p_stream = p_sys->Stream();
EbmlElement *el; EbmlElement *el;
EbmlMaster *m; EbmlMaster *m;
unsigned int i; unsigned int i;
int i_upper_level = 0; int i_upper_level = 0;
msg_Dbg( p_demux, "| + Tracks" ); msg_Dbg( &sys.demuxer, "| + Tracks" );
/* Master elements */ /* Master elements */
m = static_cast<EbmlMaster *>(tracks); m = static_cast<EbmlMaster *>(tracks);
m->Read( *p_stream->es, tracks->Generic().Context, i_upper_level, el, true ); m->Read( es, tracks->Generic().Context, i_upper_level, el, true );
for( i = 0; i < m->ListSize(); i++ ) for( i = 0; i < m->ListSize(); i++ )
{ {
...@@ -2711,11 +2710,11 @@ static void ParseTracks( demux_t *p_demux, EbmlElement *tracks ) ...@@ -2711,11 +2710,11 @@ static void ParseTracks( demux_t *p_demux, EbmlElement *tracks )
if( MKV_IS_ID( l, KaxTrackEntry ) ) if( MKV_IS_ID( l, KaxTrackEntry ) )
{ {
ParseTrackEntry( p_demux, static_cast<EbmlMaster *>(l) ); ParseTrackEntry( static_cast<EbmlMaster *>(l) );
} }
else else
{ {
msg_Dbg( p_demux, "| | + Unknown (%s)", typeid(*l).name() ); msg_Dbg( &sys.demuxer, "| | + Unknown (%s)", typeid(*l).name() );
} }
} }
} }
...@@ -2723,21 +2722,18 @@ static void ParseTracks( demux_t *p_demux, EbmlElement *tracks ) ...@@ -2723,21 +2722,18 @@ static void ParseTracks( demux_t *p_demux, EbmlElement *tracks )
/***************************************************************************** /*****************************************************************************
* ParseInfo: * ParseInfo:
*****************************************************************************/ *****************************************************************************/
static void ParseInfo( demux_t *p_demux, EbmlElement *info ) void matroska_segment_t::ParseInfo( EbmlElement *info )
{ {
demux_sys_t *p_sys = p_demux->p_sys;
matroska_stream_t *p_stream = p_sys->Stream();
matroska_segment_t *p_segment = p_stream->Segment();
EbmlElement *el; EbmlElement *el;
EbmlMaster *m; EbmlMaster *m;
unsigned int i; unsigned int i;
int i_upper_level = 0; int i_upper_level = 0;
msg_Dbg( p_demux, "| + Information" ); msg_Dbg( &sys.demuxer, "| + Information" );
/* Master elements */ /* Master elements */
m = static_cast<EbmlMaster *>(info); m = static_cast<EbmlMaster *>(info);
m->Read( *p_stream->es, info->Generic().Context, i_upper_level, el, true ); m->Read( es, info->Generic().Context, i_upper_level, el, true );
for( i = 0; i < m->ListSize(); i++ ) for( i = 0; i < m->ListSize(); i++ )
{ {
...@@ -2745,82 +2741,82 @@ static void ParseInfo( demux_t *p_demux, EbmlElement *info ) ...@@ -2745,82 +2741,82 @@ static void ParseInfo( demux_t *p_demux, EbmlElement *info )
if( MKV_IS_ID( l, KaxSegmentUID ) ) if( MKV_IS_ID( l, KaxSegmentUID ) )
{ {
p_segment->segment_uid = *(new KaxSegmentUID(*static_cast<KaxSegmentUID*>(l))); segment_uid = *(new KaxSegmentUID(*static_cast<KaxSegmentUID*>(l)));
msg_Dbg( p_demux, "| | + UID=%d", *(uint32*)p_segment->segment_uid.GetBuffer() ); msg_Dbg( &sys.demuxer, "| | + UID=%d", *(uint32*)segment_uid.GetBuffer() );
} }
else if( MKV_IS_ID( l, KaxPrevUID ) ) else if( MKV_IS_ID( l, KaxPrevUID ) )
{ {
p_segment->prev_segment_uid = *(new KaxPrevUID(*static_cast<KaxPrevUID*>(l))); prev_segment_uid = *(new KaxPrevUID(*static_cast<KaxPrevUID*>(l)));
msg_Dbg( p_demux, "| | + PrevUID=%d", *(uint32*)p_segment->prev_segment_uid.GetBuffer() ); msg_Dbg( &sys.demuxer, "| | + PrevUID=%d", *(uint32*)prev_segment_uid.GetBuffer() );
} }
else if( MKV_IS_ID( l, KaxNextUID ) ) else if( MKV_IS_ID( l, KaxNextUID ) )
{ {
p_segment->next_segment_uid = *(new KaxNextUID(*static_cast<KaxNextUID*>(l))); next_segment_uid = *(new KaxNextUID(*static_cast<KaxNextUID*>(l)));
msg_Dbg( p_demux, "| | + NextUID=%d", *(uint32*)p_segment->next_segment_uid.GetBuffer() ); msg_Dbg( &sys.demuxer, "| | + NextUID=%d", *(uint32*)next_segment_uid.GetBuffer() );
} }
else if( MKV_IS_ID( l, KaxTimecodeScale ) ) else if( MKV_IS_ID( l, KaxTimecodeScale ) )
{ {
KaxTimecodeScale &tcs = *(KaxTimecodeScale*)l; KaxTimecodeScale &tcs = *(KaxTimecodeScale*)l;
p_segment->i_timescale = uint64(tcs); i_timescale = uint64(tcs);
msg_Dbg( p_demux, "| | + TimecodeScale="I64Fd, msg_Dbg( &sys.demuxer, "| | + TimecodeScale="I64Fd,
p_segment->i_timescale ); i_timescale );
} }
else if( MKV_IS_ID( l, KaxDuration ) ) else if( MKV_IS_ID( l, KaxDuration ) )
{ {
KaxDuration &dur = *(KaxDuration*)l; KaxDuration &dur = *(KaxDuration*)l;
p_segment->f_duration = float(dur); f_duration = float(dur);
msg_Dbg( p_demux, "| | + Duration=%f", msg_Dbg( &sys.demuxer, "| | + Duration=%f",
p_segment->f_duration ); f_duration );
} }
else if( MKV_IS_ID( l, KaxMuxingApp ) ) else if( MKV_IS_ID( l, KaxMuxingApp ) )
{ {
KaxMuxingApp &mapp = *(KaxMuxingApp*)l; KaxMuxingApp &mapp = *(KaxMuxingApp*)l;
p_segment->psz_muxing_application = UTF8ToStr( UTFstring( mapp ) ); psz_muxing_application = UTF8ToStr( UTFstring( mapp ) );
msg_Dbg( p_demux, "| | + Muxing Application=%s", msg_Dbg( &sys.demuxer, "| | + Muxing Application=%s",
p_segment->psz_muxing_application ); psz_muxing_application );
} }
else if( MKV_IS_ID( l, KaxWritingApp ) ) else if( MKV_IS_ID( l, KaxWritingApp ) )
{ {
KaxWritingApp &wapp = *(KaxWritingApp*)l; KaxWritingApp &wapp = *(KaxWritingApp*)l;
p_segment->psz_writing_application = UTF8ToStr( UTFstring( wapp ) ); psz_writing_application = UTF8ToStr( UTFstring( wapp ) );
msg_Dbg( p_demux, "| | + Writing Application=%s", msg_Dbg( &sys.demuxer, "| | + Writing Application=%s",
p_segment->psz_writing_application ); psz_writing_application );
} }
else if( MKV_IS_ID( l, KaxSegmentFilename ) ) else if( MKV_IS_ID( l, KaxSegmentFilename ) )
{ {
KaxSegmentFilename &sfn = *(KaxSegmentFilename*)l; KaxSegmentFilename &sfn = *(KaxSegmentFilename*)l;
p_segment->psz_segment_filename = UTF8ToStr( UTFstring( sfn ) ); psz_segment_filename = UTF8ToStr( UTFstring( sfn ) );
msg_Dbg( p_demux, "| | + Segment Filename=%s", msg_Dbg( &sys.demuxer, "| | + Segment Filename=%s",
p_segment->psz_segment_filename ); psz_segment_filename );
} }
else if( MKV_IS_ID( l, KaxTitle ) ) else if( MKV_IS_ID( l, KaxTitle ) )
{ {
KaxTitle &title = *(KaxTitle*)l; KaxTitle &title = *(KaxTitle*)l;
p_segment->psz_title = UTF8ToStr( UTFstring( title ) ); psz_title = UTF8ToStr( UTFstring( title ) );
msg_Dbg( p_demux, "| | + Title=%s", p_segment->psz_title ); msg_Dbg( &sys.demuxer, "| | + Title=%s", psz_title );
} }
else if( MKV_IS_ID( l, KaxSegmentFamily ) ) else if( MKV_IS_ID( l, KaxSegmentFamily ) )
{ {
KaxSegmentFamily *uid = static_cast<KaxSegmentFamily*>(l); KaxSegmentFamily *uid = static_cast<KaxSegmentFamily*>(l);
p_segment->families.push_back(*uid); families.push_back(*uid);
msg_Dbg( p_demux, "| | + family=%d", *(uint32*)uid->GetBuffer() ); msg_Dbg( &sys.demuxer, "| | + family=%d", *(uint32*)uid->GetBuffer() );
} }
#if defined( HAVE_GMTIME_R ) && !defined( SYS_DARWIN ) #if defined( HAVE_GMTIME_R ) && !defined( SYS_DARWIN )
else if( MKV_IS_ID( l, KaxDateUTC ) ) else if( MKV_IS_ID( l, KaxDateUTC ) )
...@@ -2836,35 +2832,34 @@ static void ParseInfo( demux_t *p_demux, EbmlElement *info ) ...@@ -2836,35 +2832,34 @@ static void ParseInfo( demux_t *p_demux, EbmlElement *info )
asctime_r( &tmres, buffer ) ) asctime_r( &tmres, buffer ) )
{ {
buffer[strlen( buffer)-1]= '\0'; buffer[strlen( buffer)-1]= '\0';
p_segment->psz_date_utc = strdup( buffer ); psz_date_utc = strdup( buffer );
msg_Dbg( p_demux, "| | + Date=%s", p_segment->psz_date_utc ); msg_Dbg( &sys.demuxer, "| | + Date=%s", psz_date_utc );
} }
} }
#endif #endif
else else
{ {
msg_Dbg( p_demux, "| | + Unknown (%s)", typeid(*l).name() ); msg_Dbg( &sys.demuxer, "| | + Unknown (%s)", typeid(*l).name() );
} }
} }
p_segment->f_duration *= p_segment->i_timescale / 1000000.0; f_duration *= i_timescale / 1000000.0;
} }
/***************************************************************************** /*****************************************************************************
* ParseChapterAtom * ParseChapterAtom
*****************************************************************************/ *****************************************************************************/
static void ParseChapterAtom( demux_t *p_demux, int i_level, EbmlMaster *ca, chapter_item_t & chapters ) void matroska_segment_t::ParseChapterAtom( int i_level, EbmlMaster *ca, chapter_item_t & chapters )
{ {
demux_sys_t *p_sys = p_demux->p_sys;
unsigned int i; unsigned int i;
if( p_sys->title == NULL ) if( sys.title == NULL )
{ {
p_sys->title = vlc_input_title_New(); sys.title = vlc_input_title_New();
} }
msg_Dbg( p_demux, "| | | + ChapterAtom (level=%d)", i_level ); msg_Dbg( &sys.demuxer, "| | | + ChapterAtom (level=%d)", i_level );
for( i = 0; i < ca->ListSize(); i++ ) for( i = 0; i < ca->ListSize(); i++ )
{ {
EbmlElement *l = (*ca)[i]; EbmlElement *l = (*ca)[i];
...@@ -2872,35 +2867,35 @@ static void ParseChapterAtom( demux_t *p_demux, int i_level, EbmlMaster *ca, cha ...@@ -2872,35 +2867,35 @@ static void ParseChapterAtom( demux_t *p_demux, int i_level, EbmlMaster *ca, cha
if( MKV_IS_ID( l, KaxChapterUID ) ) if( MKV_IS_ID( l, KaxChapterUID ) )
{ {
chapters.i_uid = uint64_t(*(KaxChapterUID*)l); chapters.i_uid = uint64_t(*(KaxChapterUID*)l);
msg_Dbg( p_demux, "| | | | + ChapterUID: %lld", chapters.i_uid ); msg_Dbg( &sys.demuxer, "| | | | + ChapterUID: %lld", chapters.i_uid );
} }
else if( MKV_IS_ID( l, KaxChapterFlagHidden ) ) else if( MKV_IS_ID( l, KaxChapterFlagHidden ) )
{ {
KaxChapterFlagHidden &flag =*(KaxChapterFlagHidden*)l; KaxChapterFlagHidden &flag =*(KaxChapterFlagHidden*)l;
chapters.b_display_seekpoint = uint8( flag ) == 0; chapters.b_display_seekpoint = uint8( flag ) == 0;
msg_Dbg( p_demux, "| | | | + ChapterFlagHidden: %s", chapters.b_display_seekpoint ? "no":"yes" ); msg_Dbg( &sys.demuxer, "| | | | + ChapterFlagHidden: %s", chapters.b_display_seekpoint ? "no":"yes" );
} }
else if( MKV_IS_ID( l, KaxChapterTimeStart ) ) else if( MKV_IS_ID( l, KaxChapterTimeStart ) )
{ {
KaxChapterTimeStart &start =*(KaxChapterTimeStart*)l; KaxChapterTimeStart &start =*(KaxChapterTimeStart*)l;
chapters.i_start_time = uint64( start ) / I64C(1000); chapters.i_start_time = uint64( start ) / I64C(1000);
msg_Dbg( p_demux, "| | | | + ChapterTimeStart: %lld", chapters.i_start_time ); msg_Dbg( &sys.demuxer, "| | | | + ChapterTimeStart: %lld", chapters.i_start_time );
} }
else if( MKV_IS_ID( l, KaxChapterTimeEnd ) ) else if( MKV_IS_ID( l, KaxChapterTimeEnd ) )
{ {
KaxChapterTimeEnd &end =*(KaxChapterTimeEnd*)l; KaxChapterTimeEnd &end =*(KaxChapterTimeEnd*)l;
chapters.i_end_time = uint64( end ) / I64C(1000); chapters.i_end_time = uint64( end ) / I64C(1000);
msg_Dbg( p_demux, "| | | | + ChapterTimeEnd: %lld", chapters.i_end_time ); msg_Dbg( &sys.demuxer, "| | | | + ChapterTimeEnd: %lld", chapters.i_end_time );
} }
else if( MKV_IS_ID( l, KaxChapterDisplay ) ) else if( MKV_IS_ID( l, KaxChapterDisplay ) )
{ {
EbmlMaster *cd = static_cast<EbmlMaster *>(l); EbmlMaster *cd = static_cast<EbmlMaster *>(l);
unsigned int j; unsigned int j;
msg_Dbg( p_demux, "| | | | + ChapterDisplay" ); msg_Dbg( &sys.demuxer, "| | | | + ChapterDisplay" );
for( j = 0; j < cd->ListSize(); j++ ) for( j = 0; j < cd->ListSize(); j++ )
{ {
EbmlElement *l= (*cd)[j]; EbmlElement *l= (*cd)[j];
...@@ -2915,28 +2910,28 @@ static void ParseChapterAtom( demux_t *p_demux, int i_level, EbmlMaster *ca, cha ...@@ -2915,28 +2910,28 @@ static void ParseChapterAtom( demux_t *p_demux, int i_level, EbmlMaster *ca, cha
chapters.psz_name += ' '; chapters.psz_name += ' ';
chapters.psz_name += UTF8ToStr( UTFstring( name ) ); chapters.psz_name += UTF8ToStr( UTFstring( name ) );
msg_Dbg( p_demux, "| | | | | + ChapterString '%s'", UTF8ToStr(UTFstring(name)) ); msg_Dbg( &sys.demuxer, "| | | | | + ChapterString '%s'", UTF8ToStr(UTFstring(name)) );
} }
else if( MKV_IS_ID( l, KaxChapterLanguage ) ) else if( MKV_IS_ID( l, KaxChapterLanguage ) )
{ {
KaxChapterLanguage &lang =*(KaxChapterLanguage*)l; KaxChapterLanguage &lang =*(KaxChapterLanguage*)l;
const char *psz = string( lang ).c_str(); const char *psz = string( lang ).c_str();
msg_Dbg( p_demux, "| | | | | + ChapterLanguage '%s'", psz ); msg_Dbg( &sys.demuxer, "| | | | | + ChapterLanguage '%s'", psz );
} }
else if( MKV_IS_ID( l, KaxChapterCountry ) ) else if( MKV_IS_ID( l, KaxChapterCountry ) )
{ {
KaxChapterCountry &ct =*(KaxChapterCountry*)l; KaxChapterCountry &ct =*(KaxChapterCountry*)l;
const char *psz = string( ct ).c_str(); const char *psz = string( ct ).c_str();
msg_Dbg( p_demux, "| | | | | + ChapterCountry '%s'", psz ); msg_Dbg( &sys.demuxer, "| | | | | + ChapterCountry '%s'", psz );
} }
} }
} }
else if( MKV_IS_ID( l, KaxChapterAtom ) ) else if( MKV_IS_ID( l, KaxChapterAtom ) )
{ {
chapter_item_t new_sub_chapter; chapter_item_t new_sub_chapter;
ParseChapterAtom( p_demux, i_level+1, static_cast<EbmlMaster *>(l), new_sub_chapter ); ParseChapterAtom( i_level+1, static_cast<EbmlMaster *>(l), new_sub_chapter );
new_sub_chapter.psz_parent = &chapters; new_sub_chapter.psz_parent = &chapters;
chapters.sub_chapters.push_back( new_sub_chapter ); chapters.sub_chapters.push_back( new_sub_chapter );
} }
...@@ -2946,21 +2941,18 @@ static void ParseChapterAtom( demux_t *p_demux, int i_level, EbmlMaster *ca, cha ...@@ -2946,21 +2941,18 @@ static void ParseChapterAtom( demux_t *p_demux, int i_level, EbmlMaster *ca, cha
/***************************************************************************** /*****************************************************************************
* ParseChapters: * ParseChapters:
*****************************************************************************/ *****************************************************************************/
static void ParseChapters( demux_t *p_demux, EbmlElement *chapters ) void matroska_segment_t::ParseChapters( EbmlElement *chapters )
{ {
demux_sys_t *p_sys = p_demux->p_sys;
matroska_stream_t *p_stream = p_sys->Stream();
matroska_segment_t *p_segment = p_stream->Segment();
EbmlElement *el; EbmlElement *el;
EbmlMaster *m; EbmlMaster *m;
unsigned int i; unsigned int i;
int i_upper_level = 0; int i_upper_level = 0;
int i_default_edition = 0; int i_default_edition = 0;
float f_duration; float f_dur;
/* Master elements */ /* Master elements */
m = static_cast<EbmlMaster *>(chapters); m = static_cast<EbmlMaster *>(chapters);
m->Read( *p_stream->es, chapters->Generic().Context, i_upper_level, el, true ); m->Read( es, chapters->Generic().Context, i_upper_level, el, true );
for( i = 0; i < m->ListSize(); i++ ) for( i = 0; i < m->ListSize(); i++ )
{ {
...@@ -2972,7 +2964,7 @@ static void ParseChapters( demux_t *p_demux, EbmlElement *chapters ) ...@@ -2972,7 +2964,7 @@ static void ParseChapters( demux_t *p_demux, EbmlElement *chapters )
EbmlMaster *E = static_cast<EbmlMaster *>(l ); EbmlMaster *E = static_cast<EbmlMaster *>(l );
unsigned int j; unsigned int j;
msg_Dbg( p_demux, "| | + EditionEntry" ); msg_Dbg( &sys.demuxer, "| | + EditionEntry" );
for( j = 0; j < E->ListSize(); j++ ) for( j = 0; j < E->ListSize(); j++ )
{ {
EbmlElement *l = (*E)[j]; EbmlElement *l = (*E)[j];
...@@ -2980,7 +2972,7 @@ static void ParseChapters( demux_t *p_demux, EbmlElement *chapters ) ...@@ -2980,7 +2972,7 @@ static void ParseChapters( demux_t *p_demux, EbmlElement *chapters )
if( MKV_IS_ID( l, KaxChapterAtom ) ) if( MKV_IS_ID( l, KaxChapterAtom ) )
{ {
chapter_item_t new_sub_chapter; chapter_item_t new_sub_chapter;
ParseChapterAtom( p_demux, 0, static_cast<EbmlMaster *>(l), new_sub_chapter ); ParseChapterAtom( 0, static_cast<EbmlMaster *>(l), new_sub_chapter );
edition.chapters.push_back( new_sub_chapter ); edition.chapters.push_back( new_sub_chapter );
} }
else if( MKV_IS_ID( l, KaxEditionUID ) ) else if( MKV_IS_ID( l, KaxEditionUID ) )
...@@ -2994,34 +2986,34 @@ static void ParseChapters( demux_t *p_demux, EbmlElement *chapters ) ...@@ -2994,34 +2986,34 @@ static void ParseChapters( demux_t *p_demux, EbmlElement *chapters )
else if( MKV_IS_ID( l, KaxEditionFlagDefault ) ) else if( MKV_IS_ID( l, KaxEditionFlagDefault ) )
{ {
if (uint8(*static_cast<KaxEditionFlagDefault *>( l )) != 0) if (uint8(*static_cast<KaxEditionFlagDefault *>( l )) != 0)
i_default_edition = p_segment->editions.size(); i_default_edition = editions.size();
} }
else else
{ {
msg_Dbg( p_demux, "| | | + Unknown (%s)", typeid(*l).name() ); msg_Dbg( &sys.demuxer, "| | | + Unknown (%s)", typeid(*l).name() );
} }
} }
p_segment->editions.push_back( edition ); editions.push_back( edition );
} }
else else
{ {
msg_Dbg( p_demux, "| | + Unknown (%s)", typeid(*l).name() ); msg_Dbg( &sys.demuxer, "| | + Unknown (%s)", typeid(*l).name() );
} }
} }
for( i = 0; i < p_segment->editions.size(); i++ ) for( i = 0; i < editions.size(); i++ )
{ {
p_segment->editions[i].RefreshChapters( *p_sys->title ); editions[i].RefreshChapters( *sys.title );
} }
p_segment->i_current_edition = i_default_edition; i_current_edition = i_default_edition;
if ( p_segment->editions[i_default_edition].b_ordered ) if ( editions[i_default_edition].b_ordered )
{ {
/* update the duration of the segment according to the sum of all sub chapters */ /* update the duration of the segment according to the sum of all sub chapters */
f_duration = p_segment->editions[i_default_edition].Duration() / I64C(1000); f_dur = editions[i_default_edition].Duration() / I64C(1000);
if (f_duration > 0.0) if (f_dur > 0.0)
p_segment->f_duration = f_duration; f_duration = f_dur;
} }
} }
...@@ -3266,7 +3258,7 @@ const chapter_item_t *chapter_edition_t::FindTimecode( mtime_t i_user_timecode ) ...@@ -3266,7 +3258,7 @@ const chapter_item_t *chapter_edition_t::FindTimecode( mtime_t i_user_timecode )
return psz_result; return psz_result;
} }
void demux_sys_t::PreloadFamily( demux_t *p_demux ) void demux_sys_t::PreloadFamily( )
{ {
matroska_stream_t *p_stream = Stream(); matroska_stream_t *p_stream = Stream();
if ( p_stream ) if ( p_stream )
...@@ -3276,21 +3268,21 @@ void demux_sys_t::PreloadFamily( demux_t *p_demux ) ...@@ -3276,21 +3268,21 @@ void demux_sys_t::PreloadFamily( demux_t *p_demux )
{ {
for (size_t i=0; i<streams.size(); i++) for (size_t i=0; i<streams.size(); i++)
{ {
streams[i]->PreloadFamily( p_demux, *p_segment ); streams[i]->PreloadFamily( *p_segment );
} }
} }
} }
} }
void matroska_stream_t::PreloadFamily( demux_t *p_demux, const matroska_segment_t & of_segment ) void matroska_stream_t::PreloadFamily( const matroska_segment_t & of_segment )
{ {
for (size_t i=0; i<segments.size(); i++) for (size_t i=0; i<segments.size(); i++)
{ {
segments[i]->PreloadFamily( p_demux, of_segment ); segments[i]->PreloadFamily( of_segment );
} }
} }
bool matroska_segment_t::PreloadFamily( demux_t *p_demux, const matroska_segment_t & of_segment ) bool matroska_segment_t::PreloadFamily( const matroska_segment_t & of_segment )
{ {
if ( b_preloaded ) if ( b_preloaded )
return false; return false;
...@@ -3300,7 +3292,7 @@ bool matroska_segment_t::PreloadFamily( demux_t *p_demux, const matroska_segment ...@@ -3300,7 +3292,7 @@ bool matroska_segment_t::PreloadFamily( demux_t *p_demux, const matroska_segment
for (size_t j=0; j<of_segment.families.size(); j++) for (size_t j=0; j<of_segment.families.size(); j++)
{ {
if ( families[i] == of_segment.families[j] ) if ( families[i] == of_segment.families[j] )
return Preload( p_demux ); return Preload( );
} }
} }
...@@ -3308,29 +3300,29 @@ bool matroska_segment_t::PreloadFamily( demux_t *p_demux, const matroska_segment ...@@ -3308,29 +3300,29 @@ bool matroska_segment_t::PreloadFamily( demux_t *p_demux, const matroska_segment
} }
// preload all the linked segments for all preloaded segments // preload all the linked segments for all preloaded segments
void demux_sys_t::PreloadLinked( demux_t *p_demux ) void demux_sys_t::PreloadLinked( )
{ {
size_t i_prealoaded; size_t i_prealoaded;
do { do {
i_prealoaded = 0; i_prealoaded = 0;
for (size_t i=0; i<streams.size(); i++) for (size_t i=0; i<streams.size(); i++)
{ {
i_prealoaded += streams[i]->PreloadLinked( p_demux, *this ); i_prealoaded += streams[i]->PreloadLinked( *this );
} }
} while ( i_prealoaded ); // worst case: will stop when all segments are preloaded } while ( i_prealoaded ); // worst case: will stop when all segments are preloaded
} }
size_t matroska_stream_t::PreloadLinked( demux_t *p_demux, const demux_sys_t & of_sys ) size_t matroska_stream_t::PreloadLinked( const demux_sys_t & of_sys )
{ {
size_t i_result = 0; size_t i_result = 0;
for (size_t i=0; i<segments.size(); i++) for (size_t i=0; i<segments.size(); i++)
{ {
i_result += segments[i]->PreloadLinked( p_demux, of_sys ); i_result += segments[i]->PreloadLinked( of_sys );
} }
return i_result; return i_result;
} }
size_t matroska_segment_t::PreloadLinked( demux_t *p_demux, const demux_sys_t & of_sys ) size_t matroska_segment_t::PreloadLinked( const demux_sys_t & of_sys )
{ {
size_t i_result = 0; size_t i_result = 0;
if ( prev_segment_uid.GetBuffer() ) if ( prev_segment_uid.GetBuffer() )
...@@ -3338,7 +3330,7 @@ size_t matroska_segment_t::PreloadLinked( demux_t *p_demux, const demux_sys_t & ...@@ -3338,7 +3330,7 @@ size_t matroska_segment_t::PreloadLinked( demux_t *p_demux, const demux_sys_t &
matroska_segment_t *p_segment = of_sys.FindSegment( prev_segment_uid ); matroska_segment_t *p_segment = of_sys.FindSegment( prev_segment_uid );
if ( p_segment ) if ( p_segment )
{ {
i_result += p_segment->Preload( p_demux ) ? 1 : 0; i_result += p_segment->Preload( ) ? 1 : 0;
} }
} }
if ( next_segment_uid.GetBuffer() ) if ( next_segment_uid.GetBuffer() )
...@@ -3346,13 +3338,13 @@ size_t matroska_segment_t::PreloadLinked( demux_t *p_demux, const demux_sys_t & ...@@ -3346,13 +3338,13 @@ size_t matroska_segment_t::PreloadLinked( demux_t *p_demux, const demux_sys_t &
matroska_segment_t *p_segment = of_sys.FindSegment( next_segment_uid ); matroska_segment_t *p_segment = of_sys.FindSegment( next_segment_uid );
if ( p_segment ) if ( p_segment )
{ {
i_result += p_segment->Preload( p_demux ) ? 1 : 0; i_result += p_segment->Preload( ) ? 1 : 0;
} }
} }
return i_result; return i_result;
} }
bool matroska_segment_t::Preload( demux_t *p_demux ) bool matroska_segment_t::Preload( )
{ {
if ( b_preloaded ) if ( b_preloaded )
return false; return false;
...@@ -3363,23 +3355,23 @@ bool matroska_segment_t::Preload( demux_t *p_demux ) ...@@ -3363,23 +3355,23 @@ bool matroska_segment_t::Preload( demux_t *p_demux )
{ {
if( MKV_IS_ID( el, KaxInfo ) ) if( MKV_IS_ID( el, KaxInfo ) )
{ {
ParseInfo( p_demux, el ); ParseInfo( el );
} }
else if( MKV_IS_ID( el, KaxTracks ) ) else if( MKV_IS_ID( el, KaxTracks ) )
{ {
ParseTracks( p_demux, el ); ParseTracks( el );
} }
else if( MKV_IS_ID( el, KaxSeekHead ) ) else if( MKV_IS_ID( el, KaxSeekHead ) )
{ {
ParseSeekHead( p_demux, el ); ParseSeekHead( el );
} }
else if( MKV_IS_ID( el, KaxCues ) ) else if( MKV_IS_ID( el, KaxCues ) )
{ {
msg_Dbg( p_demux, "| + Cues" ); msg_Dbg( &sys.demuxer, "| + Cues" );
} }
else if( MKV_IS_ID( el, KaxCluster ) ) else if( MKV_IS_ID( el, KaxCluster ) )
{ {
msg_Dbg( p_demux, "| + Cluster" ); msg_Dbg( &sys.demuxer, "| + Cluster" );
cluster = (KaxCluster*)el; cluster = (KaxCluster*)el;
...@@ -3389,20 +3381,20 @@ bool matroska_segment_t::Preload( demux_t *p_demux ) ...@@ -3389,20 +3381,20 @@ bool matroska_segment_t::Preload( demux_t *p_demux )
} }
else if( MKV_IS_ID( el, KaxAttachments ) ) else if( MKV_IS_ID( el, KaxAttachments ) )
{ {
msg_Dbg( p_demux, "| + Attachments FIXME TODO (but probably never supported)" ); msg_Dbg( &sys.demuxer, "| + Attachments FIXME TODO (but probably never supported)" );
} }
else if( MKV_IS_ID( el, KaxChapters ) ) else if( MKV_IS_ID( el, KaxChapters ) )
{ {
msg_Dbg( p_demux, "| + Chapters" ); msg_Dbg( &sys.demuxer, "| + Chapters" );
ParseChapters( p_demux, el ); ParseChapters( el );
} }
else if( MKV_IS_ID( el, KaxTag ) ) else if( MKV_IS_ID( el, KaxTag ) )
{ {
msg_Dbg( p_demux, "| + Tags FIXME TODO" ); msg_Dbg( &sys.demuxer, "| + Tags FIXME TODO" );
} }
else else
{ {
msg_Dbg( p_demux, "| + Unknown (%s)", typeid(*el).name() ); msg_Dbg( &sys.demuxer, "| + Unknown (%s)", typeid(*el).name() );
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment