1 /*****************************************************************************
2 * virtual_segment.hpp : virtual segment implementation in the MKV demuxer
3 *****************************************************************************
4 * Copyright © 2003-2011 VideoLAN and VLC authors
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * Steve Lhomme <steve.lhomme@free.fr>
9 * Denis Charmet <typx@dinauz.org>
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation; either version 2.1 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this program; if not, write to the Free Software Foundation,
23 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 #ifndef _VIRTUAL_SEGMENT_HPP_
27 #define _VIRTUAL_SEGMENT_HPP_
31 #include "matroska_segment.hpp"
32 #include "chapters.hpp"
34 /* virtual classes don't own anything but virtual elements so they shouldn't have to delete anything */
36 class virtual_chapter_c
39 virtual_chapter_c( matroska_segment_c *p_seg, chapter_item_c *p_chap, int64_t start, int64_t stop ):
40 p_segment(p_seg), p_chapter(p_chap),
41 i_virtual_start_time(start), i_virtual_stop_time(stop)
45 static virtual_chapter_c * CreateVirtualChapter( chapter_item_c * p_chap,
46 matroska_segment_c * p_main_segment,
47 std::vector<matroska_segment_c*> * segments,
48 int64_t * usertime_offset, bool b_ordered );
50 virtual_chapter_c* getSubChapterbyTimecode( int64_t time );
51 bool EnterAndLeave( virtual_chapter_c *p_item, bool b_enter = true );
52 virtual_chapter_c * FindChapter( int64_t i_find_uid );
53 int PublishChapters( input_title_t & title, int & i_user_chapters, int i_level );
55 virtual_chapter_c * BrowseCodecPrivate( unsigned int codec_id,
56 bool (*match)( const chapter_codec_cmds_c &data,
58 size_t i_cookie_size ),
60 size_t i_cookie_size );
61 bool Enter( bool b_do_subs );
62 bool Leave( bool b_do_subs );
64 static bool CompareTimecode( const virtual_chapter_c * itemA, const virtual_chapter_c * itemB )
66 return ( itemA->i_virtual_start_time < itemB->i_virtual_start_time );
69 matroska_segment_c *p_segment;
70 chapter_item_c *p_chapter;
71 int64_t i_virtual_start_time;
72 int64_t i_virtual_stop_time;
74 std::vector<virtual_chapter_c *> sub_chapters;
80 class virtual_edition_c
83 virtual_edition_c( chapter_edition_c * p_edition, std::vector<matroska_segment_c*> *opened_segments );
85 std::vector<virtual_chapter_c*> chapters;
87 virtual_chapter_c* getChapterbyTimecode( int64_t time );
88 std::string GetMainName();
89 int PublishChapters( input_title_t & title, int & i_user_chapters, int i_level );
90 virtual_chapter_c * BrowseCodecPrivate( unsigned int codec_id,
91 bool (*match)( const chapter_codec_cmds_c &data,
93 size_t i_cookie_size ),
94 const void *p_cookie, size_t i_cookie_size );
98 chapter_edition_c *p_edition;
102 void retimeChapters();
103 void retimeSubChapters( virtual_chapter_c * p_vchap );
105 void print(){ for( size_t i = 0; i<chapters.size(); i++ ) chapters[i]->print(); }
110 // class holding hard-linked segment together in the playback order
111 class virtual_segment_c
114 virtual_segment_c( std::vector<matroska_segment_c*> * opened_segments );
115 ~virtual_segment_c();
116 std::vector<virtual_edition_c*> editions;
117 int i_current_edition;
118 virtual_chapter_c *p_current_chapter;
122 inline virtual_edition_c * CurrentEdition()
124 if( i_current_edition >= 0 && (size_t) i_current_edition < editions.size() )
125 return editions[i_current_edition];
129 virtual_chapter_c * CurrentChapter() const
131 return p_current_chapter;
134 matroska_segment_c * CurrentSegment() const
136 if ( !p_current_chapter )
138 return p_current_chapter->p_segment;
141 inline int64_t Duration()
143 return editions[i_current_edition]->i_duration / 1000;
146 inline std::vector<virtual_edition_c*>* Editions() { return &editions; }
148 virtual_chapter_c *BrowseCodecPrivate( unsigned int codec_id,
149 bool (*match)( const chapter_codec_cmds_c &data,
150 const void *p_cookie,
151 size_t i_cookie_size ),
152 const void *p_cookie,
153 size_t i_cookie_size );
155 virtual_chapter_c * FindChapter( int64_t i_find_uid );
157 bool UpdateCurrentToChapter( demux_t & demux );
158 void Seek( demux_t & demuxer, mtime_t i_date, mtime_t i_time_offset,
159 virtual_chapter_c *p_chapter, int64_t i_global_position );
161 void ChangeSegment( matroska_segment_c * p_old, matroska_segment_c * p_new, mtime_t i_start_time );