1 /*****************************************************************************
2 * mkv.cpp : matroska demuxer
3 *****************************************************************************
4 * Copyright (C) 2003-2004 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * Steve Lhomme <steve.lhomme@free.fr>
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.
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.
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 *****************************************************************************/
25 #ifndef _MATROSKA_SEGMENT_HPP_
26 #define _MATROSKA_SEGMENT_HPP_
30 #include "Ebml_parser.hpp"
32 class chapter_edition_c;
33 class chapter_translation_c;
36 class matroska_segment_c
39 matroska_segment_c( demux_sys_t & demuxer, EbmlStream & estream )
42 ,i_timescale(MKVD_TIMECODESCALE)
47 ,i_chapters_position(-1)
49 ,i_tracks_position(-1)
50 ,i_attachments_position(-1)
51 ,i_seekhead_position(-1)
58 ,p_prev_segment_uid(NULL)
59 ,p_next_segment_uid(NULL)
63 ,psz_muxing_application(NULL)
64 ,psz_writing_application(NULL)
65 ,psz_segment_filename(NULL)
73 p_indexes = (mkv_index_t*)malloc( sizeof( mkv_index_t ) * i_index_max );
76 virtual ~matroska_segment_c();
84 /* duration of the segment */
89 std::vector<mkv_track_t*> tracks;
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;
103 uint64 i_cluster_pos;
105 KaxSegmentUID *p_segment_uid;
106 KaxPrevUID *p_prev_segment_uid;
107 KaxNextUID *p_next_segment_uid;
112 mkv_index_t *p_indexes;
115 char *psz_muxing_application;
116 char *psz_writing_application;
117 char *psz_segment_filename;
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 int i_default_edition;
127 std::vector<chapter_translation_c*> translations;
128 std::vector<KaxSegmentFamily*> families;
135 bool LoadSeekHeadItem( const EbmlCallbacks & ClassInfos, int64_t i_element_position );
136 bool PreloadFamily( const matroska_segment_c & segment );
137 void ParseInfo( KaxInfo *info );
138 void ParseAttachments( KaxAttachments *attachments );
139 void ParseChapters( KaxChapters *chapters );
140 void ParseSeekHead( KaxSeekHead *seekhead );
141 void ParseTracks( KaxTracks *tracks );
142 void ParseChapterAtom( int i_level, KaxChapterAtom *ca, chapter_item_c & chapters );
143 void ParseTrackEntry( KaxTrackEntry *m );
144 void ParseCluster( );
145 void IndexAppendCluster( KaxCluster *cluster );
146 void LoadCues( KaxCues *cues );
147 void LoadTags( KaxTags *tags );
148 void InformationCreate( );
149 void Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_global_position );
150 int BlockGet( KaxBlock * &, KaxSimpleBlock * &, int64_t *, int64_t *, int64_t *);
152 int BlockFindTrackIndex( size_t *pi_track,
153 const KaxBlock *, const KaxSimpleBlock * );
156 bool Select( mtime_t i_start_time );
159 static bool CompareSegmentUIDs( const matroska_segment_c * item_a, const matroska_segment_c * item_b );
163 * Helper function to print the mkv parse tree
165 static void MkvTree( demux_t & demuxer, int i_level, const char *psz_format, ... )
170 msg_Err( &demuxer, "too deep tree" );
173 va_start( args, psz_format );
174 static const char psz_foo[] = "| | | | | | | | | |";
175 char *psz_foo2 = (char*)malloc( ( i_level * 4 + 3 + strlen( psz_format ) ) * sizeof(char) );
176 strncpy( psz_foo2, psz_foo, 4 * i_level );
177 psz_foo2[ 4 * i_level ] = '+';
178 psz_foo2[ 4 * i_level + 1 ] = ' ';
179 strcpy( &psz_foo2[ 4 * i_level + 2 ], psz_format );
180 __msg_GenericVa( VLC_OBJECT(&demuxer),VLC_MSG_DBG, "mkv", psz_foo2, args );