/src/vlc/modules/demux/mkv/matroska_segment.hpp
Line | Count | Source (jump to first uncovered line) |
1 | | /***************************************************************************** |
2 | | * matroska_segment.hpp : matroska demuxer |
3 | | ***************************************************************************** |
4 | | * Copyright (C) 2003-2004 VLC authors and VideoLAN |
5 | | * |
6 | | * Authors: Laurent Aimar <fenrir@via.ecp.fr> |
7 | | * Steve Lhomme <steve.lhomme@free.fr> |
8 | | * |
9 | | * This program is free software; you can redistribute it and/or modify it |
10 | | * under the terms of the GNU Lesser General Public License as published by |
11 | | * the Free Software Foundation; either version 2.1 of the License, or |
12 | | * (at your option) any later version. |
13 | | * |
14 | | * This program is distributed in the hope that it will be useful, |
15 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | | * GNU Lesser General Public License for more details. |
18 | | * |
19 | | * You should have received a copy of the GNU Lesser General Public License |
20 | | * along with this program; if not, write to the Free Software Foundation, |
21 | | * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. |
22 | | *****************************************************************************/ |
23 | | |
24 | | #ifndef VLC_MKV_MATROSKA_SEGMENT_HPP_ |
25 | | #define VLC_MKV_MATROSKA_SEGMENT_HPP_ |
26 | | |
27 | | #include "demux.hpp" |
28 | | #include "mkv.hpp" |
29 | | #include "matroska_segment_seeker.hpp" |
30 | | #include <vector> |
31 | | #include <string> |
32 | | |
33 | | #include <map> |
34 | | #include <set> |
35 | | #include <memory> |
36 | | |
37 | | #include "Ebml_parser.hpp" |
38 | | |
39 | | namespace mkv { |
40 | | |
41 | | class EbmlParser; |
42 | | |
43 | | class chapter_edition_c; |
44 | | class chapter_translation_c; |
45 | | class chapter_item_c; |
46 | | |
47 | | class mkv_track_t; |
48 | | |
49 | | typedef enum |
50 | | { |
51 | | WHOLE_SEGMENT, |
52 | | TRACK_UID, |
53 | | EDITION_UID, |
54 | | CHAPTER_UID, |
55 | | ATTACHMENT_UID |
56 | | } tag_target_type; |
57 | | |
58 | | class SimpleTag |
59 | | { |
60 | | public: |
61 | | typedef std::vector<SimpleTag> sub_tags_t; |
62 | | std::string tag_name; |
63 | | std::string lang; |
64 | | std::string value; |
65 | | sub_tags_t sub_tags; |
66 | | }; |
67 | | |
68 | | class Tag |
69 | | { |
70 | | public: |
71 | | typedef std::vector<SimpleTag> simple_tags_t; |
72 | 0 | Tag():i_tag_type(WHOLE_SEGMENT),i_target_type(50),i_uid(0){} |
73 | | tag_target_type i_tag_type; |
74 | | uint64_t i_target_type; |
75 | | uint64_t i_uid; |
76 | | simple_tags_t simple_tags; |
77 | | }; |
78 | | |
79 | | struct demux_sys_t; |
80 | | |
81 | | class matroska_segment_c |
82 | | { |
83 | | public: |
84 | | typedef std::map<mkv_track_t::track_id_t, std::unique_ptr<mkv_track_t>> tracks_map_t; |
85 | | typedef std::vector<Tag> tags_t; |
86 | | |
87 | | matroska_segment_c( demux_sys_t &, matroska_iostream_c &, KaxSegment * ); |
88 | | virtual ~matroska_segment_c(); |
89 | | |
90 | | KaxSegment *segment; |
91 | | matroska_iostream_c & es; |
92 | | |
93 | | /* time scale */ |
94 | | uint64_t i_timescale; |
95 | | |
96 | | /* duration of the segment */ |
97 | | vlc_tick_t i_duration; |
98 | | vlc_tick_t i_mk_start_time; |
99 | | |
100 | | /* all tracks */ |
101 | | tracks_map_t tracks; |
102 | | SegmentSeeker::track_ids_t priority_tracks; |
103 | | vlc_tick_t pcr_shift = 0; |
104 | | |
105 | | /* from seekhead */ |
106 | | int i_seekhead_count; |
107 | | int64_t i_seekhead_position; |
108 | | int64_t i_cues_position; |
109 | | int64_t i_tracks_position; |
110 | | int64_t i_info_position; |
111 | | int64_t i_chapters_position; |
112 | | int64_t i_attachments_position; |
113 | | |
114 | | KaxCluster *cluster; |
115 | | uint64_t i_block_pos; |
116 | | KaxSegmentUID *p_segment_uid; |
117 | | KaxPrevUID *p_prev_segment_uid; |
118 | | KaxNextUID *p_next_segment_uid; |
119 | | |
120 | | bool b_cues; |
121 | | |
122 | | /* info */ |
123 | | char *psz_muxing_application; |
124 | | char *psz_writing_application; |
125 | | char *psz_segment_filename; |
126 | | char *psz_title; |
127 | | char *psz_date_utc; |
128 | | |
129 | | /* !!!!! GCC 3.3 bug on Darwin !!!!! */ |
130 | | /* when you remove this variable the compiler issues an atomicity error */ |
131 | | /* this variable only works when using std::vector<chapter_edition_c> */ |
132 | | std::vector<chapter_edition_c*> stored_editions; |
133 | | std::vector<chapter_edition_c*>::size_type i_default_edition; |
134 | | |
135 | | std::vector<chapter_translation_c*> translations; |
136 | | std::vector<KaxSegmentFamily*> families; |
137 | | tags_t tags; |
138 | | |
139 | | demux_sys_t & sys; |
140 | | EbmlParser ep; |
141 | | bool b_preloaded; |
142 | | bool b_ref_external_segments; |
143 | | |
144 | | bool Preload(); |
145 | | bool PreloadFamily( const matroska_segment_c & segment ); |
146 | | bool PreloadClusters( uint64_t i_cluster_position ); |
147 | | void InformationCreate(); |
148 | | |
149 | | bool Seek( demux_t &, vlc_tick_t i_mk_date, vlc_tick_t i_mk_time_offset, bool b_accurate ); |
150 | | |
151 | | int BlockGet( KaxBlock * &, KaxSimpleBlock * &, KaxBlockAdditions * &, |
152 | | bool *, bool *, int64_t *); |
153 | | |
154 | | mkv_track_t * FindTrackByBlock(const KaxBlock *, const KaxSimpleBlock * ); |
155 | | |
156 | | bool ESCreate( ); |
157 | | void ESDestroy( ); |
158 | | |
159 | | static bool CompareSegmentUIDs( const matroska_segment_c * item_a, const matroska_segment_c * item_b ); |
160 | | |
161 | | bool SameFamily( const matroska_segment_c & of_segment ) const; |
162 | | |
163 | | private: |
164 | | void LoadCues( KaxCues *cues ); |
165 | | void LoadTags( KaxTags *tags ); |
166 | | bool LoadSeekHeadItem( const EbmlCallbacks & ClassInfos, int64_t i_element_position ); |
167 | | void ParseInfo( KaxInfo *info ); |
168 | | void ParseAttachments( KaxAttachments *attachments ); |
169 | | void ParseChapters( KaxChapters *chapters ); |
170 | | void ParseSeekHead( KaxSeekHead *seekhead ); |
171 | | void ParseTracks( KaxTracks *tracks ); |
172 | | void ParseChapterAtom( int i_level, KaxChapterAtom *ca, chapter_item_c & chapters ); |
173 | | void ParseTrackEntry( const KaxTrackEntry* m ); |
174 | | bool ParseCluster( KaxCluster *cluster, bool b_update_start_time = true, ScopeMode read_fully = SCOPE_ALL_DATA ); |
175 | | bool ParseSimpleTags( SimpleTag* out, KaxTagSimple *tag, int level = 50 ); |
176 | | bool TrackInit( mkv_track_t * p_tk ); |
177 | | void ComputeTrackPriority(); |
178 | | void EnsureDuration(); |
179 | | |
180 | | SegmentSeeker _seeker; |
181 | | |
182 | | friend SegmentSeeker; |
183 | | }; |
184 | | |
185 | | } // namespace |
186 | | |
187 | | #endif |