Commit c42f4116 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

MKV: privatize methods in virtual_segment_t

parent 7376fd3b
...@@ -660,23 +660,23 @@ void demux_sys_t::PreloadLinked( matroska_segment_c *p_segment ) ...@@ -660,23 +660,23 @@ void demux_sys_t::PreloadLinked( matroska_segment_c *p_segment )
for ( i=0; i< used_segments.size(); i++ ) for ( i=0; i< used_segments.size(); i++ )
{ {
p_seg = used_segments[i]; p_seg = used_segments[i];
if ( p_seg->p_editions != NULL ) if ( p_seg->Editions() != NULL )
{ {
input_title_t *p_title = vlc_input_title_New(); input_title_t *p_title = vlc_input_title_New();
p_seg->i_sys_title = i; p_seg->i_sys_title = i;
int i_chapters; int i_chapters;
// TODO use a name for each edition, let the TITLE deal with a codec name // TODO use a name for each edition, let the TITLE deal with a codec name
for ( j=0; j<p_seg->p_editions->size(); j++ ) for ( j=0; j<p_seg->Editions()->size(); j++ )
{ {
if ( p_title->psz_name == NULL ) if ( p_title->psz_name == NULL )
{ {
const char* psz_tmp = (*p_seg->p_editions)[j]->GetMainName().c_str(); const char* psz_tmp = (*p_seg->Editions())[j]->GetMainName().c_str();
if( *psz_tmp != '\0' ) if( *psz_tmp != '\0' )
p_title->psz_name = strdup( psz_tmp ); p_title->psz_name = strdup( psz_tmp );
} }
chapter_edition_c *p_edition = (*p_seg->p_editions)[j]; chapter_edition_c *p_edition = (*p_seg->Editions())[j];
i_chapters = 0; i_chapters = 0;
p_edition->PublishChapters( *p_title, i_chapters, 0 ); p_edition->PublishChapters( *p_title, i_chapters, 0 );
...@@ -708,24 +708,8 @@ bool demux_sys_t::IsUsedSegment( matroska_segment_c &segment ) const ...@@ -708,24 +708,8 @@ bool demux_sys_t::IsUsedSegment( matroska_segment_c &segment ) const
virtual_segment_c *demux_sys_t::VirtualFromSegments( matroska_segment_c *p_segment ) const virtual_segment_c *demux_sys_t::VirtualFromSegments( matroska_segment_c *p_segment ) const
{ {
size_t i_preloaded, i;
virtual_segment_c *p_result = new virtual_segment_c( p_segment ); virtual_segment_c *p_result = new virtual_segment_c( p_segment );
p_result->AddSegments( opened_segments );
// fill our current virtual segment with all hard linked segments
do {
i_preloaded = 0;
for ( i=0; i< opened_segments.size(); i++ )
{
i_preloaded += p_result->AddSegment( opened_segments[i] );
}
} while ( i_preloaded ); // worst case: will stop when all segments are found as linked
p_result->Sort( );
p_result->PreloadLinked( );
p_result->PrepareChapters( );
return p_result; return p_result;
} }
......
...@@ -54,50 +54,50 @@ void virtual_segment_c::PrepareChapters( ) ...@@ -54,50 +54,50 @@ void virtual_segment_c::PrepareChapters( )
bool virtual_segment_c::UpdateCurrentToChapter( demux_t & demux ) bool virtual_segment_c::UpdateCurrentToChapter( demux_t & demux )
{ {
demux_sys_t & sys = *demux.p_sys; demux_sys_t & sys = *demux.p_sys;
chapter_item_c *psz_curr_chapter; chapter_item_c *p_curr_chapter;
bool b_has_seeked = false; bool b_has_seeked = false;
/* update current chapter/seekpoint */ /* update current chapter/seekpoint */
if ( p_editions->size() ) if ( p_editions->size() )
{ {
/* 1st, we need to know in which chapter we are */ /* 1st, we need to know in which chapter we are */
psz_curr_chapter = (*p_editions)[i_current_edition]->FindTimecode( sys.i_pts, psz_current_chapter ); p_curr_chapter = (*p_editions)[i_current_edition]->FindTimecode( sys.i_pts, p_current_chapter );
/* we have moved to a new chapter */ /* we have moved to a new chapter */
if (psz_curr_chapter != NULL && psz_current_chapter != psz_curr_chapter) if (p_curr_chapter != NULL && p_current_chapter != p_curr_chapter)
{ {
if ( (*p_editions)[i_current_edition]->b_ordered ) if ( (*p_editions)[i_current_edition]->b_ordered )
{ {
// Leave/Enter up to the link point // Leave/Enter up to the link point
b_has_seeked = psz_curr_chapter->EnterAndLeave( psz_current_chapter ); b_has_seeked = p_curr_chapter->EnterAndLeave( p_current_chapter );
if ( !b_has_seeked ) if ( !b_has_seeked )
{ {
// only physically seek if necessary // only physically seek if necessary
if ( psz_current_chapter == NULL || (psz_current_chapter->i_end_time != psz_curr_chapter->i_start_time) ) if ( p_current_chapter == NULL || (p_current_chapter->i_end_time != p_curr_chapter->i_start_time) )
Seek( demux, sys.i_pts, 0, psz_curr_chapter, -1 ); Seek( demux, sys.i_pts, 0, p_curr_chapter, -1 );
} }
} }
if ( !b_has_seeked ) if ( !b_has_seeked )
{ {
psz_current_chapter = psz_curr_chapter; p_current_chapter = p_curr_chapter;
if ( psz_curr_chapter->i_seekpoint_num > 0 ) if ( p_curr_chapter->i_seekpoint_num > 0 )
{ {
demux.info.i_update |= INPUT_UPDATE_TITLE | INPUT_UPDATE_SEEKPOINT; demux.info.i_update |= INPUT_UPDATE_TITLE | INPUT_UPDATE_SEEKPOINT;
demux.info.i_title = sys.i_current_title = i_sys_title; demux.info.i_title = sys.i_current_title = i_sys_title;
demux.info.i_seekpoint = psz_curr_chapter->i_seekpoint_num - 1; demux.info.i_seekpoint = p_curr_chapter->i_seekpoint_num - 1;
} }
} }
return true; return true;
} }
else if (psz_curr_chapter == NULL) else if (p_curr_chapter == NULL)
{ {
// out of the scope of the data described by chapters, leave the edition // out of the scope of the data described by chapters, leave the edition
if ( (*p_editions)[i_current_edition]->b_ordered && psz_current_chapter != NULL ) if ( (*p_editions)[i_current_edition]->b_ordered && p_current_chapter != NULL )
{ {
if ( !(*p_editions)[i_current_edition]->EnterAndLeave( psz_current_chapter, false ) ) if ( !(*p_editions)[i_current_edition]->EnterAndLeave( p_current_chapter, false ) )
psz_current_chapter = NULL; p_current_chapter = NULL;
else else
return true; return true;
} }
...@@ -214,13 +214,13 @@ void virtual_segment_c::Seek( demux_t & demuxer, mtime_t i_date, mtime_t i_time_ ...@@ -214,13 +214,13 @@ void virtual_segment_c::Seek( demux_t & demuxer, mtime_t i_date, mtime_t i_time_
if ( Edition() && Edition()->b_ordered ) if ( Edition() && Edition()->b_ordered )
{ {
/* 1st, we need to know in which chapter we are */ /* 1st, we need to know in which chapter we are */
psz_chapter = (*p_editions)[i_current_edition]->FindTimecode( i_date, psz_current_chapter ); psz_chapter = (*p_editions)[i_current_edition]->FindTimecode( i_date, p_current_chapter );
} }
} }
if ( psz_chapter != NULL ) if ( psz_chapter != NULL )
{ {
psz_current_chapter = psz_chapter; p_current_chapter = psz_chapter;
p_sys->i_chapter_time = i_time_offset = psz_chapter->i_user_start_time - psz_chapter->i_start_time; p_sys->i_chapter_time = i_time_offset = psz_chapter->i_user_start_time - psz_chapter->i_start_time;
if ( psz_chapter->i_seekpoint_num > 0 ) if ( psz_chapter->i_seekpoint_num > 0 )
{ {
...@@ -262,3 +262,20 @@ chapter_item_c *virtual_segment_c::FindChapter( int64_t i_find_uid ) ...@@ -262,3 +262,20 @@ chapter_item_c *virtual_segment_c::FindChapter( int64_t i_find_uid )
} }
return NULL; return NULL;
} }
void virtual_segment_c::AddSegments(std::vector<matroska_segment_c *> segments)
{
// fill our current virtual segment with all hard linked segments
size_t i_preloaded;
do {
i_preloaded = 0;
for ( size_t i=0; i < segments.size(); i++ )
{
i_preloaded += AddSegment( segments[i] );
}
} while ( i_preloaded ); // worst case: will stop when all segments are found as linked
Sort();
PreloadLinked( );
PrepareChapters( );
}
...@@ -36,11 +36,11 @@ class virtual_segment_c ...@@ -36,11 +36,11 @@ class virtual_segment_c
{ {
public: public:
virtual_segment_c( matroska_segment_c *p_segment ) virtual_segment_c( matroska_segment_c *p_segment )
:p_editions(NULL) :i_sys_title(0)
,i_sys_title(0)
,i_current_segment(0) ,i_current_segment(0)
,i_current_edition(-1) ,i_current_edition(-1)
,psz_current_chapter(NULL) ,p_current_chapter(NULL)
,p_editions(NULL)
{ {
linked_segments.push_back( p_segment ); linked_segments.push_back( p_segment );
...@@ -49,18 +49,19 @@ public: ...@@ -49,18 +49,19 @@ public:
AppendUID( p_segment->p_next_segment_uid ); AppendUID( p_segment->p_next_segment_uid );
} }
void Sort(); void AddSegments( std::vector<matroska_segment_c*> segments );
size_t AddSegment( matroska_segment_c *p_segment );
void PreloadLinked( );
mtime_t Duration( ) const;
void Seek( demux_t & demuxer, mtime_t i_date, mtime_t i_time_offset, chapter_item_c *psz_chapter, int64_t i_global_position ); void Seek( demux_t & demuxer, mtime_t i_date, mtime_t i_time_offset, chapter_item_c *psz_chapter, int64_t i_global_position );
mtime_t Duration() const;
inline chapter_edition_c *Edition() inline chapter_edition_c *Edition()
{ {
if ( i_current_edition >= 0 && size_t(i_current_edition) < p_editions->size() ) if ( i_current_edition >= 0 && size_t(i_current_edition) < p_editions->size() )
return (*p_editions)[i_current_edition]; return (*p_editions)[i_current_edition];
return NULL; return NULL;
} }
std::vector<chapter_edition_c*>* Editions() const { return p_editions; };
matroska_segment_c * Segment() const matroska_segment_c * Segment() const
{ {
...@@ -69,9 +70,7 @@ public: ...@@ -69,9 +70,7 @@ public:
return linked_segments[i_current_segment]; return linked_segments[i_current_segment];
} }
inline chapter_item_c *CurrentChapter() { chapter_item_c *CurrentChapter() { return p_current_chapter; }
return psz_current_chapter;
}
bool SelectNext() bool SelectNext()
{ {
...@@ -93,16 +92,15 @@ public: ...@@ -93,16 +92,15 @@ public:
return false; return false;
} }
chapter_item_c *FindChapter( int64_t i_find_uid );
bool UpdateCurrentToChapter( demux_t & demux ); bool UpdateCurrentToChapter( demux_t & demux );
void PrepareChapters( );
chapter_item_c *BrowseCodecPrivate( unsigned int codec_id, chapter_item_c *BrowseCodecPrivate( unsigned int codec_id,
bool (*match)(const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size ), bool (*match)(const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size ),
const void *p_cookie, const void *p_cookie,
size_t i_cookie_size ); size_t i_cookie_size );
chapter_item_c *FindChapter( int64_t i_find_uid );
std::vector<chapter_edition_c*> *p_editions;
int i_sys_title; int i_sys_title;
protected: protected:
...@@ -111,9 +109,17 @@ protected: ...@@ -111,9 +109,17 @@ protected:
size_t i_current_segment; size_t i_current_segment;
int i_current_edition; int i_current_edition;
chapter_item_c *psz_current_chapter; chapter_item_c *p_current_chapter;
std::vector<chapter_edition_c*> *p_editions;
void AppendUID( const EbmlBinary * UID ); void AppendUID( const EbmlBinary * UID );
private:
void Sort();
size_t AddSegment( matroska_segment_c *p_segment );
void PreloadLinked( );
void PrepareChapters( );
}; };
#endif #endif
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