]> git.sesse.net Git - vlc/blob - modules/demux/mkv/matroska_segment.hpp
WinCE: fix function declaration
[vlc] / modules / demux / mkv / matroska_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 _MATROSKA_SEGMENT_HPP_
26 #define _MATROSKA_SEGMENT_HPP_
27
28 #include "mkv.hpp"
29
30 #include "Ebml_parser.hpp"
31
32 class chapter_edition_c;
33 class chapter_translation_c;
34 class chapter_item_c;
35
36 class matroska_segment_c
37 {
38 public:
39     matroska_segment_c( demux_sys_t & demuxer, EbmlStream & estream )
40         :segment(NULL)
41         ,es(estream)
42         ,i_timescale(MKVD_TIMECODESCALE)
43         ,i_duration(-1)
44         ,i_start_time(0)
45         ,i_cues_position(-1)
46         ,i_info_position(-1)
47         ,i_chapters_position(-1)
48         ,i_tags_position(-1)
49         ,i_tracks_position(-1)
50         ,i_attachments_position(-1)
51         ,i_seekhead_position(-1)
52         ,i_seekhead_count(0)
53         ,cluster(NULL)
54         ,i_block_pos(0)
55         ,i_cluster_pos(0)
56         ,i_start_pos(0)
57         ,p_segment_uid(NULL)
58         ,p_prev_segment_uid(NULL)
59         ,p_next_segment_uid(NULL)
60         ,b_cues(false)
61         ,i_index(0)
62         ,i_index_max(1024)
63         ,psz_muxing_application(NULL)
64         ,psz_writing_application(NULL)
65         ,psz_segment_filename(NULL)
66         ,psz_title(NULL)
67         ,psz_date_utc(NULL)
68         ,i_default_edition(0)
69         ,sys(demuxer)
70         ,ep(NULL)
71         ,b_preloaded(false)
72     {
73         p_indexes = (mkv_index_t*)malloc( sizeof( mkv_index_t ) * i_index_max );
74     }
75
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     int                             i_default_edition;
126
127     std::vector<chapter_translation_c*> translations;
128     std::vector<KaxSegmentFamily*>  families;
129  
130     demux_sys_t                    & sys;
131     EbmlParser                     *ep;
132     bool                           b_preloaded;
133
134     bool Preload( );
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 *);
151
152     int BlockFindTrackIndex( size_t *pi_track,
153                              const KaxBlock *, const KaxSimpleBlock * );
154
155
156     bool Select( mtime_t i_start_time );
157     void UnSelect( );
158
159     static bool CompareSegmentUIDs( const matroska_segment_c * item_a, const matroska_segment_c * item_b );
160 };
161
162 /**
163  * Helper function to print the mkv parse tree
164  */
165 static void MkvTree( demux_t & demuxer, int i_level, const char *psz_format, ... )
166 {
167     va_list args;
168     if( i_level > 9 )
169     {
170         msg_Err( &demuxer, "too deep tree" );
171         return;
172     }
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 );
181     free( psz_foo2 );
182     va_end( args );
183 }
184
185
186 #endif