]> git.sesse.net Git - vlc/blob - modules/demux/mkv/mkv.hpp
Use _WIN32 rather than WIN32 (same for WIN64)
[vlc] / modules / demux / mkv / mkv.hpp
1 /*****************************************************************************
2  * mkv.hpp : matroska demuxer
3  *****************************************************************************
4  * Copyright (C) 2003-2005, 2008 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 _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 #define __STDC_LIMIT_MACROS 1
38
39 #ifdef HAVE_CONFIG_H
40 # include "config.h"
41 #endif
42
43 #include <inttypes.h>
44
45 #include <vlc_common.h>
46 #include <vlc_plugin.h>
47
48 #ifdef HAVE_TIME_H
49 #   include <time.h>                                               /* time() */
50 #endif
51
52 #include <vlc_meta.h>
53 #include <vlc_charset.h>
54 #include <vlc_input.h>
55 #include <vlc_demux.h>
56
57 #include <iostream>
58 #include <cassert>
59 #include <typeinfo>
60 #include <string>
61 #include <vector>
62 #include <algorithm>
63
64 /* libebml and matroska */
65 #include "ebml/EbmlHead.h"
66 #include "ebml/EbmlSubHead.h"
67 #include "ebml/EbmlStream.h"
68 #include "ebml/EbmlContexts.h"
69 #include "ebml/EbmlVoid.h"
70 #include "ebml/EbmlVersion.h"
71 #include "ebml/StdIOCallback.h"
72
73 #include "matroska/KaxAttachments.h"
74 #include "matroska/KaxAttached.h"
75 #include "matroska/KaxBlock.h"
76 #include "matroska/KaxBlockData.h"
77 #include "matroska/KaxChapters.h"
78 #include "matroska/KaxCluster.h"
79 #include "matroska/KaxClusterData.h"
80 #include "matroska/KaxContexts.h"
81 #include "matroska/KaxCues.h"
82 #include "matroska/KaxCuesData.h"
83 #include "matroska/KaxInfo.h"
84 #include "matroska/KaxInfoData.h"
85 #include "matroska/KaxSeekHead.h"
86 #include "matroska/KaxSegment.h"
87 #include "matroska/KaxTag.h"
88 #include "matroska/KaxTags.h"
89 //#include "matroska/KaxTagMulti.h"
90 #include "matroska/KaxTracks.h"
91 #include "matroska/KaxTrackAudio.h"
92 #include "matroska/KaxTrackVideo.h"
93 #include "matroska/KaxTrackEntryData.h"
94 #include "matroska/KaxContentEncoding.h"
95 #include "matroska/KaxVersion.h"
96
97 #include "ebml/StdIOCallback.h"
98
99 extern "C" {
100    #include "../mp4/libmp4.h"
101 }
102 #ifdef HAVE_ZLIB_H
103 #   include <zlib.h>
104 #endif
105
106 #define MKV_DEBUG 0
107
108 #define MATROSKA_COMPRESSION_NONE  -1
109 #define MATROSKA_COMPRESSION_ZLIB   0
110 #define MATROSKA_COMPRESSION_BLIB   1
111 #define MATROSKA_COMPRESSION_LZOX   2
112 #define MATROSKA_COMPRESSION_HEADER 3
113
114 enum
115 {
116     MATROSKA_ENCODING_SCOPE_ALL_FRAMES = 1,
117     MATROSKA_ENCODING_SCOPE_PRIVATE = 2,
118     MATROSKA_ENCODING_SCOPE_NEXT = 4 /* unsupported */
119 };
120
121 #define MKVD_TIMECODESCALE 1000000
122
123 #define MKV_IS_ID( el, C ) ( el != NULL && typeid( *el ) == typeid( C ) )
124
125
126 using namespace LIBMATROSKA_NAMESPACE;
127 using namespace std;
128
129 void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simpleblock,
130                          mtime_t i_pts, mtime_t i_duration, bool f_mandatory );
131
132 class attachment_c
133 {
134 public:
135     attachment_c( const std::string& _psz_file_name, const std::string& _psz_mime_type, int _i_size )
136         :i_size(_i_size)
137         ,psz_file_name( _psz_file_name)
138         ,psz_mime_type( _psz_mime_type)
139     {
140         p_data = NULL;
141     }
142     ~attachment_c() { free( p_data ); }
143
144     /* Allocs the data space. Returns true if allocation went ok */
145     bool init()
146     {
147         p_data = malloc( i_size );
148         return (p_data != NULL);
149     }
150
151     const char* fileName() const { return psz_file_name.c_str(); }
152     const char* mimeType() const { return psz_mime_type.c_str(); }
153     int         size() const    { return i_size; }
154
155     void          *p_data;
156 private:
157     int            i_size;
158     std::string    psz_file_name;
159     std::string    psz_mime_type;
160 };
161
162 class matroska_segment_c;
163 struct matroska_stream_c
164 {
165     matroska_stream_c() :p_io_callback(NULL) ,p_estream(NULL) {}
166     ~matroska_stream_c()
167     {
168         delete p_io_callback;
169         delete p_estream;
170     }
171
172     IOCallback         *p_io_callback;
173     EbmlStream         *p_estream;
174
175     std::vector<matroska_segment_c*> segments;
176 };
177
178
179 /*****************************************************************************
180  * definitions of structures and functions used by this plugins
181  *****************************************************************************/
182 class PrivateTrackData
183 {
184 public:
185     virtual ~PrivateTrackData() {}
186     virtual int32_t Init() { return 0; }
187 };
188
189 struct mkv_track_t
190 {
191 //    ~mkv_track_t();
192
193     bool         b_default;
194     bool         b_enabled;
195     bool         b_forced;
196     unsigned int i_number;
197
198     unsigned int i_extra_data;
199     uint8_t      *p_extra_data;
200
201     char         *psz_codec;
202     bool         b_dts_only;
203     bool         b_pts_only;
204
205     uint64_t     i_default_duration;
206     float        f_timecodescale;
207     mtime_t      i_last_dts;
208
209     /* video */
210     es_format_t fmt;
211     float       f_fps;
212     es_out_id_t *p_es;
213
214     /* audio */
215     unsigned int i_original_rate;
216
217     /* Private track paramters */
218     PrivateTrackData *p_sys;
219
220     bool            b_inited;
221     /* data to be send first */
222     int             i_data_init;
223     uint8_t         *p_data_init;
224
225     /* hack : it's for seek */
226     bool            b_search_keyframe;
227     bool            b_silent;
228
229     /* informative */
230     const char   *psz_codec_name;
231     const char   *psz_codec_settings;
232     const char   *psz_codec_info_url;
233     const char   *psz_codec_download_url;
234
235     /* encryption/compression */
236     int                    i_compression_type;
237     uint32_t               i_encoding_scope;
238     KaxContentCompSettings *p_compression_data;
239
240 };
241
242 struct mkv_index_t
243 {
244     int     i_track;
245     int     i_block_number;
246
247     int64_t i_position;
248     int64_t i_time;
249
250     bool       b_key;
251 };
252
253
254 #endif /* _MKV_HPP_ */