]> git.sesse.net Git - vlc/blob - modules/demux/mkv/matroska_segment.hpp
MKV: remove unused i_time_offset variable when seeking
[vlc] / modules / demux / mkv / matroska_segment.hpp
1 /*****************************************************************************
2  * matroska_segment.hpp : matroska demuxer
3  *****************************************************************************
4  * Copyright (C) 2003-2004 VLC authors and VideoLAN
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 it
11  * under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program; if not, write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifndef _MATROSKA_SEGMENT_HPP_
26 #define _MATROSKA_SEGMENT_HPP_
27
28 #include "mkv.hpp"
29
30 class EbmlParser;
31
32 class chapter_edition_c;
33 class chapter_translation_c;
34 class chapter_item_c;
35
36 struct mkv_track_t;
37 struct mkv_index_t;
38
39 typedef enum
40 {
41     WHOLE_SEGMENT,
42     TRACK_UID,
43     EDITION_UID,
44     CHAPTER_UID,
45     ATTACHMENT_UID
46 } tag_target_type;
47
48 class SimpleTag
49 {
50 public:
51     SimpleTag():
52         psz_tag_name(NULL), psz_lang(NULL), b_default(true), p_value(NULL){}
53     ~SimpleTag();
54     char *psz_tag_name;
55     char *psz_lang; /* NULL value means "undf" */
56     bool b_default;
57     char * p_value;
58     std::vector<SimpleTag *> sub_tags;
59 };
60
61 class Tag
62 {
63 public:
64     Tag():i_tag_type(WHOLE_SEGMENT),i_target_type(50),i_uid(0){}
65     ~Tag();
66     tag_target_type i_tag_type;
67     uint64_t        i_target_type;
68     uint64_t        i_uid;
69     std::vector<SimpleTag*> simple_tags;
70 };
71
72 class matroska_segment_c
73 {
74 public:
75     matroska_segment_c( demux_sys_t & demuxer, EbmlStream & estream );
76     virtual ~matroska_segment_c();
77
78     KaxSegment              *segment;
79     EbmlStream              & es;
80
81     /* time scale */
82     uint64_t                i_timescale;
83
84     /* duration of the segment */
85     mtime_t                 i_duration;
86     mtime_t                 i_start_time;
87
88     /* all tracks */
89     std::vector<mkv_track_t*> tracks;
90
91     /* from seekhead */
92     int                     i_seekhead_count;
93     int64_t                 i_seekhead_position;
94     int64_t                 i_cues_position;
95     int64_t                 i_tracks_position;
96     int64_t                 i_info_position;
97     int64_t                 i_chapters_position;
98     int64_t                 i_tags_position;
99     int64_t                 i_attachments_position;
100
101     KaxCluster              *cluster;
102     uint64                  i_block_pos;
103     uint64                  i_cluster_pos;
104     int64_t                 i_start_pos;
105     KaxSegmentUID           *p_segment_uid;
106     KaxPrevUID              *p_prev_segment_uid;
107     KaxNextUID              *p_next_segment_uid;
108
109     bool                    b_cues;
110     int                     i_index;
111     int                     i_index_max;
112     mkv_index_t             *p_indexes;
113
114     /* info */
115     char                    *psz_muxing_application;
116     char                    *psz_writing_application;
117     char                    *psz_segment_filename;
118     char                    *psz_title;
119     char                    *psz_date_utc;
120
121     /* !!!!! GCC 3.3 bug on Darwin !!!!! */
122     /* when you remove this variable the compiler issues an atomicity error */
123     /* this variable only works when using std::vector<chapter_edition_c> */
124     std::vector<chapter_edition_c*> stored_editions;
125     std::vector<chapter_edition_c*>::size_type i_default_edition;
126
127     std::vector<chapter_translation_c*> translations;
128     std::vector<KaxSegmentFamily*>  families;
129     std::vector<Tag *>              tags;
130
131     demux_sys_t                    & sys;
132     EbmlParser                     *ep;
133     bool                           b_preloaded;
134     bool                           b_ref_external_segments;
135
136     bool Preload();
137     bool PreloadFamily( const matroska_segment_c & segment );
138     void InformationCreate();
139     void Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_global_position );
140     int BlockGet( KaxBlock * &, KaxSimpleBlock * &, bool *, bool *, int64_t *);
141
142     int BlockFindTrackIndex( size_t *pi_track,
143                              const KaxBlock *, const KaxSimpleBlock * );
144
145     bool Select( mtime_t i_start_time );
146     void UnSelect();
147
148     static bool CompareSegmentUIDs( const matroska_segment_c * item_a, const matroska_segment_c * item_b );
149
150 private:
151     void LoadCues( KaxCues *cues );
152     void LoadTags( KaxTags *tags );
153     bool LoadSeekHeadItem( const EbmlCallbacks & ClassInfos, int64_t i_element_position );
154     void ParseInfo( KaxInfo *info );
155     void ParseAttachments( KaxAttachments *attachments );
156     void ParseChapters( KaxChapters *chapters );
157     void ParseSeekHead( KaxSeekHead *seekhead );
158     void ParseTracks( KaxTracks *tracks );
159     void ParseChapterAtom( int i_level, KaxChapterAtom *ca, chapter_item_c & chapters );
160     void ParseTrackEntry( KaxTrackEntry *m );
161     void ParseCluster( KaxCluster *cluster, bool b_update_start_time = true, ScopeMode read_fully = SCOPE_ALL_DATA );
162     SimpleTag * ParseSimpleTags( KaxTagSimple *tag, int level = 50 );
163     void IndexAppendCluster( KaxCluster *cluster );
164     int32_t TrackInit( mkv_track_t * p_tk );
165     void ComputeTrackPriority();
166     void EnsureDuration();
167 };
168
169
170 #endif