1 /*****************************************************************************
2 * mkv.cpp : matroska demuxer
3 *****************************************************************************
4 * Copyright (C) 2003-2004 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * Steve Lhomme <steve.lhomme@free.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #ifndef _VIRTUAL_SEGMENT_HPP_
26 #define _VIRTUAL_SEGMENT_HPP_
30 #include "matroska_segment.hpp"
31 #include "chapters.hpp"
33 /* virtual classes don't own anything but virtual elements so they shouldn't have to delete anything */
35 class virtual_chapter_c
38 virtual_chapter_c( matroska_segment_c *p_seg, chapter_item_c *p_chap, int64_t start, int64_t stop ):
39 p_segment(p_seg), p_chapter(p_chap),
40 i_virtual_start_time(start), i_virtual_stop_time(stop)
44 static virtual_chapter_c * CreateVirtualChapter( chapter_item_c * p_chap,
45 matroska_segment_c * p_main_segment,
46 std::vector<matroska_segment_c*> * segments,
47 int64_t * usertime_offset, bool b_ordered );
49 virtual_chapter_c* getSubChapterbyTimecode( int64_t time );
50 bool EnterAndLeave( virtual_chapter_c *p_item, bool b_enter = true );
51 virtual_chapter_c * FindChapter( int64_t i_find_uid );
52 int PublishChapters( input_title_t & title, int & i_user_chapters, int i_level );
54 virtual_chapter_c * BrowseCodecPrivate( unsigned int codec_id,
55 bool (*match)( const chapter_codec_cmds_c &data,
57 size_t i_cookie_size ),
59 size_t i_cookie_size );
60 bool Enter( bool b_do_subs );
61 bool Leave( bool b_do_subs );
63 static bool CompareTimecode( const virtual_chapter_c * itemA, const virtual_chapter_c * itemB )
65 return ( itemA->i_virtual_start_time < itemB->i_virtual_start_time ||
66 ( itemA->i_virtual_start_time == itemB->i_virtual_start_time &&
67 itemA->i_virtual_stop_time < itemB->i_virtual_stop_time ) );
70 matroska_segment_c *p_segment;
71 chapter_item_c *p_chapter;
72 int64_t i_virtual_start_time;
73 int64_t i_virtual_stop_time;
75 std::vector<virtual_chapter_c *> sub_chapters;
81 class virtual_edition_c
84 virtual_edition_c( chapter_edition_c * p_edition, std::vector<matroska_segment_c*> *opened_segments );
86 std::vector<virtual_chapter_c*> chapters;
88 virtual_chapter_c* getChapterbyTimecode( int64_t time );
89 std::string GetMainName();
90 int PublishChapters( input_title_t & title, int & i_user_chapters, int i_level );
91 virtual_chapter_c * BrowseCodecPrivate( unsigned int codec_id,
92 bool (*match)( const chapter_codec_cmds_c &data,
94 size_t i_cookie_size ),
95 const void *p_cookie, size_t i_cookie_size );
99 chapter_edition_c *p_edition;
103 void retimeChapters();
104 void retimeSubChapters( virtual_chapter_c * p_vchap );
106 void print(){ for( size_t i = 0; i<chapters.size(); i++ ) chapters[i]->print(); }
111 // class holding hard-linked segment together in the playback order
112 class virtual_segment_c
115 virtual_segment_c( std::vector<matroska_segment_c*> * opened_segments );
116 ~virtual_segment_c();
117 std::vector<virtual_edition_c*> editions;
118 int i_current_edition;
119 virtual_chapter_c *p_current_chapter;
123 inline virtual_edition_c * CurrentEdition()
125 if( i_current_edition >= 0 && (size_t) i_current_edition < editions.size() )
126 return editions[i_current_edition];
130 virtual_chapter_c * CurrentChapter() const
132 return p_current_chapter;
135 matroska_segment_c * CurrentSegment() const
137 if ( !p_current_chapter )
139 return p_current_chapter->p_segment;
142 inline int64_t Duration()
144 return editions[i_current_edition]->i_duration / 1000;
147 inline std::vector<virtual_edition_c*>* Editions() { return &editions; }
149 virtual_chapter_c *BrowseCodecPrivate( unsigned int codec_id,
150 bool (*match)( const chapter_codec_cmds_c &data,
151 const void *p_cookie,
152 size_t i_cookie_size ),
153 const void *p_cookie,
154 size_t i_cookie_size );
156 virtual_chapter_c * FindChapter( int64_t i_find_uid );
158 bool UpdateCurrentToChapter( demux_t & demux );
159 void Seek( demux_t & demuxer, mtime_t i_date, mtime_t i_time_offset,
160 virtual_chapter_c *p_chapter, int64_t i_global_position );