]> git.sesse.net Git - vlc/blob - modules/demux/mkv/virtual_segment.hpp
MKV: remove trailing spaces
[vlc] / modules / demux / mkv / virtual_segment.hpp
1 /*****************************************************************************
2  * virtual_segment.hpp : virtual segment implementation in the MKV demuxer
3  *****************************************************************************
4  * Copyright © 2003-2011 VideoLAN and VLC authors
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *          Steve Lhomme <steve.lhomme@free.fr>
9  *          Denis Charmet <typx@dinauz.org>
10  *
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.
15  *
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.
20  *
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  *****************************************************************************/
25
26 #ifndef _VIRTUAL_SEGMENT_HPP_
27 #define _VIRTUAL_SEGMENT_HPP_
28
29 #include "mkv.hpp"
30
31 #include "matroska_segment.hpp"
32 #include "chapters.hpp"
33
34 /* virtual classes don't own anything but virtual elements so they shouldn't have to delete anything */
35
36 class virtual_chapter_c
37 {
38 public:
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)
42     {}
43     ~virtual_chapter_c();
44
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 );
49
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 );
54
55     virtual_chapter_c * BrowseCodecPrivate( unsigned int codec_id,
56                                             bool (*match)( const chapter_codec_cmds_c &data,
57                                                            const void *p_cookie,
58                                                            size_t i_cookie_size ),
59                                             const void *p_cookie,
60                                             size_t i_cookie_size );
61     bool Enter( bool b_do_subs );
62     bool Leave( bool b_do_subs );
63
64     static bool CompareTimecode( const virtual_chapter_c * itemA, const virtual_chapter_c * itemB )
65     {
66         return ( itemA->i_virtual_start_time < itemB->i_virtual_start_time );
67     }
68
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;
73     int                 i_seekpoint_num;
74     std::vector<virtual_chapter_c *> sub_chapters;
75 #if MKV_DEBUG
76     void print();
77 #endif
78 };
79
80 class virtual_edition_c
81 {
82 public:
83     virtual_edition_c( chapter_edition_c * p_edition, std::vector<matroska_segment_c*> *opened_segments );
84     ~virtual_edition_c();
85     std::vector<virtual_chapter_c*> chapters;
86
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,
92                                                            const void *p_cookie,
93                                                            size_t i_cookie_size ),
94                                              const void *p_cookie, size_t i_cookie_size );
95
96     bool                b_ordered;
97     int64_t             i_duration;
98     chapter_edition_c   *p_edition;
99     int                 i_seekpoint_num;
100
101 private:
102     void retimeChapters();
103     void retimeSubChapters( virtual_chapter_c * p_vchap );
104 #if MKV_DEBUG
105     void print(){ for( size_t i = 0; i<chapters.size(); i++ ) chapters[i]->print(); }
106 #endif
107
108 };
109
110 // class holding hard-linked segment together in the playback order
111 class virtual_segment_c
112 {
113 public:
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;
119     int                             i_sys_title;
120
121
122     inline virtual_edition_c * CurrentEdition()
123     {
124         if( i_current_edition >= 0 && (size_t) i_current_edition < editions.size() )
125             return editions[i_current_edition];
126         return NULL;
127     }
128
129     virtual_chapter_c * CurrentChapter() const
130     {
131         return p_current_chapter;
132     }
133
134     matroska_segment_c * CurrentSegment() const
135     {
136         if ( !p_current_chapter )
137             return NULL;
138         return p_current_chapter->p_segment;
139     }
140
141     inline int64_t Duration()
142     {
143         return editions[i_current_edition]->i_duration / 1000;
144     }
145
146     inline std::vector<virtual_edition_c*>* Editions() { return &editions; }
147
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 );
154
155     virtual_chapter_c * FindChapter( int64_t i_find_uid );
156
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 );
160 private:
161     void ChangeSegment( matroska_segment_c * p_old, matroska_segment_c * p_new, mtime_t i_start_time );
162 };
163
164 #endif