]> git.sesse.net Git - vlc/blob - modules/demux/mkv/virtual_segment.hpp
mkv: Avoid duplicating the entire vector.
[vlc] / modules / demux / mkv / virtual_segment.hpp
1
2 /*****************************************************************************
3  * mkv.cpp : matroska demuxer
4  *****************************************************************************
5  * Copyright (C) 2003-2004 the VideoLAN team
6  * $Id$
7  *
8  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9  *          Steve Lhomme <steve.lhomme@free.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 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 General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, 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 // class holding hard-linked segment together in the playback order
35 class virtual_segment_c
36 {
37 public:
38     virtual_segment_c( matroska_segment_c *p_segment )
39         :i_sys_title(0)
40         ,i_current_segment(0)
41         ,i_current_edition(-1)
42         ,p_current_chapter(NULL)
43         ,p_editions(NULL)
44     {
45         linked_segments.push_back( p_segment );
46
47         AppendUID( p_segment->p_segment_uid );
48         AppendUID( p_segment->p_prev_segment_uid );
49         AppendUID( p_segment->p_next_segment_uid );
50     }
51
52     void AddSegments( const std::vector<matroska_segment_c*> &segments );
53
54     void Seek( demux_t & demuxer, mtime_t i_date, mtime_t i_time_offset, chapter_item_c *p_chapter, int64_t i_global_position );
55
56     mtime_t Duration() const;
57
58     inline chapter_edition_c *CurrentEdition()
59     {
60         if ( i_current_edition >= 0 && size_t(i_current_edition) < p_editions->size() )
61             return (*p_editions)[i_current_edition];
62         return NULL;
63     }
64     std::vector<chapter_edition_c*>*  Editions() const { return p_editions; };
65
66     matroska_segment_c * CurrentSegment() const
67     {
68         if ( linked_segments.size() == 0 || i_current_segment >= linked_segments.size() )
69             return NULL;
70         return linked_segments[i_current_segment];
71     }
72
73     chapter_item_c *CurrentChapter() { return p_current_chapter; }
74
75     bool SelectNext()
76     {
77         if ( i_current_segment < linked_segments.size()-1 )
78         {
79             i_current_segment++;
80             return true;
81         }
82         return false;
83     }
84
85     bool FindUID( KaxSegmentUID & uid ) const
86     {
87         for ( size_t i=0; i<linked_uids.size(); i++ )
88         {
89             if ( linked_uids[i] == uid )
90                 return true;
91         }
92         return false;
93     }
94
95     chapter_item_c *FindChapter( int64_t i_find_uid );
96
97     bool UpdateCurrentToChapter( demux_t & demux );
98
99     chapter_item_c *BrowseCodecPrivate( unsigned int codec_id,
100                                         bool (*match)(const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size ),
101                                         const void *p_cookie,
102                                         size_t i_cookie_size );
103
104     int                              i_sys_title;
105
106 protected:
107     std::vector<matroska_segment_c*> linked_segments;
108     std::vector<KaxSegmentUID>       linked_uids;
109     size_t                           i_current_segment;
110
111     int                              i_current_edition;
112     chapter_item_c                   *p_current_chapter;
113
114     std::vector<chapter_edition_c*>  *p_editions;
115
116     void                             AppendUID( const EbmlBinary * UID );
117
118 private:
119     void Sort();
120     size_t AddSegment( matroska_segment_c *p_segment );
121     void PreloadLinked( );
122     void PrepareChapters( );
123 };
124
125 #endif