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