]> git.sesse.net Git - vlc/blob - modules/demux/mkv/mkv.hpp
MKV: Split classes in many files.
[vlc] / modules / demux / mkv / mkv.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 _MKV_H_
26 #define _MKV_H_
27
28 /*****************************************************************************
29  * Preamble
30  *****************************************************************************/
31
32
33 /* config.h may include inttypes.h, so make sure we define that option
34  * early enough. */
35 #define __STDC_FORMAT_MACROS 1
36 #define __STDC_CONSTANT_MACROS 1
37
38 #ifdef HAVE_CONFIG_H
39 # include "config.h"
40 #endif
41
42 #include <inttypes.h>
43
44 #include <vlc_common.h>
45 #include <vlc_plugin.h>
46
47 #ifdef HAVE_TIME_H
48 #   include <time.h>                                               /* time() */
49 #endif
50
51
52 #include <vlc_codecs.h>               /* BITMAPINFOHEADER, WAVEFORMATEX */
53 #include <vlc_iso_lang.h>
54 #include "vlc_meta.h"
55 #include <vlc_charset.h>
56 #include <vlc_input.h>
57 #include <vlc_demux.h>
58
59 #include <iostream>
60 #include <cassert>
61 #include <typeinfo>
62 #include <string>
63 #include <vector>
64 #include <algorithm>
65
66 #ifdef HAVE_DIRENT_H
67 #   include <dirent.h>
68 #endif
69
70 /* libebml and matroska */
71 #include "ebml/EbmlHead.h"
72 #include "ebml/EbmlSubHead.h"
73 #include "ebml/EbmlStream.h"
74 #include "ebml/EbmlContexts.h"
75 #include "ebml/EbmlVoid.h"
76 #include "ebml/EbmlVersion.h"
77 #include "ebml/StdIOCallback.h"
78
79 #include "matroska/KaxAttachments.h"
80 #include "matroska/KaxAttached.h"
81 #include "matroska/KaxBlock.h"
82 #include "matroska/KaxBlockData.h"
83 #include "matroska/KaxChapters.h"
84 #include "matroska/KaxCluster.h"
85 #include "matroska/KaxClusterData.h"
86 #include "matroska/KaxContexts.h"
87 #include "matroska/KaxCues.h"
88 #include "matroska/KaxCuesData.h"
89 #include "matroska/KaxInfo.h"
90 #include "matroska/KaxInfoData.h"
91 #include "matroska/KaxSeekHead.h"
92 #include "matroska/KaxSegment.h"
93 #include "matroska/KaxTag.h"
94 #include "matroska/KaxTags.h"
95 #include "matroska/KaxTagMulti.h"
96 #include "matroska/KaxTracks.h"
97 #include "matroska/KaxTrackAudio.h"
98 #include "matroska/KaxTrackVideo.h"
99 #include "matroska/KaxTrackEntryData.h"
100 #include "matroska/KaxContentEncoding.h"
101 #include "matroska/KaxVersion.h"
102
103 #include "ebml/StdIOCallback.h"
104
105 #include "vlc_keys.h"
106
107 extern "C" {
108    #include "../mp4/libmp4.h"
109 }
110 #ifdef HAVE_ZLIB_H
111 #   include <zlib.h>
112 #endif
113
114 #define MATROSKA_COMPRESSION_NONE  -1
115 #define MATROSKA_COMPRESSION_ZLIB   0
116 #define MATROSKA_COMPRESSION_BLIB   1
117 #define MATROSKA_COMPRESSION_LZOX   2
118 #define MATROSKA_COMPRESSION_HEADER 3
119
120 #define MKVD_TIMECODESCALE 1000000
121
122 /**
123  * What's between a directory and a filename?
124  */
125 #if defined( WIN32 )
126     #define DIRECTORY_SEPARATOR '\\'
127 #else
128     #define DIRECTORY_SEPARATOR '/'
129 #endif
130
131
132 #define MKV_IS_ID( el, C ) ( EbmlId( (*el) ) == C::ClassInfos.GlobalId )
133
134 /*****************************************************************************
135  * Some functions to manipulate memory
136  *****************************************************************************/
137 #define GetFOURCC( p )  __GetFOURCC( (uint8_t*)p )
138 static vlc_fourcc_t __GetFOURCC( uint8_t *p )
139 {
140     return VLC_FOURCC( p[0], p[1], p[2], p[3] );
141 }
142 static inline char * ToUTF8( const UTFstring &u )
143 {
144     return strdup( u.GetUTF8().c_str() );
145 }
146
147
148 using namespace LIBMATROSKA_NAMESPACE;
149 using namespace std;
150
151 class attachment_c
152 {
153 public:
154     attachment_c()
155         :p_data(NULL)
156         ,i_size(0)
157     {}
158     virtual ~attachment_c()
159     {
160         free( p_data );
161     }
162
163     std::string    psz_file_name;
164     std::string    psz_mime_type;
165     void          *p_data;
166     int            i_size;
167 };
168
169 class matroska_segment_c;
170
171 class matroska_stream_c
172 {
173 public:
174     matroska_stream_c( demux_sys_t & demuxer )
175         :p_in(NULL)
176         ,p_es(NULL)
177         ,sys(demuxer)
178     {}
179
180     virtual ~matroska_stream_c()
181     {
182         delete p_in;
183         delete p_es;
184     }
185
186     IOCallback         *p_in;
187     EbmlStream         *p_es;
188
189     std::vector<matroska_segment_c*> segments;
190
191     demux_sys_t                      & sys;
192 };
193
194
195 /*****************************************************************************
196  * definitions of structures and functions used by this plugins
197  *****************************************************************************/
198 typedef struct
199 {
200 //    ~mkv_track_t();
201
202     bool         b_default;
203     bool         b_enabled;
204     unsigned int i_number;
205
206     int          i_extra_data;
207     uint8_t      *p_extra_data;
208
209     char         *psz_codec;
210
211     uint64_t     i_default_duration;
212     float        f_timecodescale;
213     mtime_t      i_last_dts;
214
215     /* video */
216     es_format_t fmt;
217     float       f_fps;
218     es_out_id_t *p_es;
219
220     /* audio */
221     unsigned int i_original_rate;
222
223     bool            b_inited;
224     /* data to be send first */
225     int             i_data_init;
226     uint8_t         *p_data_init;
227
228     /* hack : it's for seek */
229     bool            b_search_keyframe;
230     bool            b_silent;
231
232     /* informative */
233     const char   *psz_codec_name;
234     const char   *psz_codec_settings;
235     const char   *psz_codec_info_url;
236     const char   *psz_codec_download_url;
237
238     /* encryption/compression */
239     int                    i_compression_type;
240     KaxContentCompSettings *p_compression_data;
241
242 } mkv_track_t;
243
244 typedef struct
245 {
246     int     i_track;
247     int     i_block_number;
248
249     int64_t i_position;
250     int64_t i_time;
251
252     bool       b_key;
253 } mkv_index_t;
254
255
256 #endif /* _MKV_HPP_ */