]> git.sesse.net Git - vlc/blob - modules/demux/mkv/virtual_segment.hpp
Use var_Inherit* instead of var_CreateGet*.
[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         :p_editions(NULL)
40         ,i_sys_title(0)
41         ,i_current_segment(0)
42         ,i_current_edition(-1)
43         ,psz_current_chapter(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 Sort();
53     size_t AddSegment( matroska_segment_c *p_segment );
54     void PreloadLinked( );
55     mtime_t Duration( ) const;
56     void Seek( demux_t & demuxer, mtime_t i_date, mtime_t i_time_offset, chapter_item_c *psz_chapter, int64_t i_global_position );
57
58     inline chapter_edition_c *Edition()
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
65     matroska_segment_c * Segment() const
66     {
67         if ( linked_segments.size() == 0 || i_current_segment >= linked_segments.size() )
68             return NULL;
69         return linked_segments[i_current_segment];
70     }
71
72     inline chapter_item_c *CurrentChapter() {
73         return psz_current_chapter;
74     }
75
76     bool SelectNext()
77     {
78         if ( i_current_segment < linked_segments.size()-1 )
79         {
80             i_current_segment++;
81             return true;
82         }
83         return false;
84     }
85
86     bool FindUID( KaxSegmentUID & uid ) const
87     {
88         for ( size_t i=0; i<linked_uids.size(); i++ )
89         {
90             if ( linked_uids[i] == uid )
91                 return true;
92         }
93         return false;
94     }
95
96     bool UpdateCurrentToChapter( demux_t & demux );
97     void PrepareChapters( );
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     chapter_item_c *FindChapter( int64_t i_find_uid );
104
105     std::vector<chapter_edition_c*>  *p_editions;
106     int                              i_sys_title;
107
108 protected:
109     std::vector<matroska_segment_c*> linked_segments;
110     std::vector<KaxSegmentUID>       linked_uids;
111     size_t                           i_current_segment;
112
113     int                              i_current_edition;
114     chapter_item_c                   *psz_current_chapter;
115
116     void                             AppendUID( const EbmlBinary * UID );
117 };
118
119 #endif