]> git.sesse.net Git - vlc/blob - modules/demux/mkv/mkv.hpp
6b46c2a28dc0666d0ab9eb69a6743c6ed55d27cb
[vlc] / modules / demux / mkv / mkv.hpp
1 /*****************************************************************************
2  * mkv.cpp : matroska demuxer
3  *****************************************************************************
4  * Copyright (C) 2003-2005, 2008 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 #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_iso_lang.h>
53 #include <vlc_meta.h>
54 #include <vlc_charset.h>
55 #include <vlc_input.h>
56 #include <vlc_demux.h>
57
58 #include <iostream>
59 #include <cassert>
60 #include <typeinfo>
61 #include <string>
62 #include <vector>
63 #include <algorithm>
64
65 #ifdef HAVE_DIRENT_H
66 #   include <dirent.h>
67 #endif
68
69 /* libebml and matroska */
70 #include "ebml/EbmlHead.h"
71 #include "ebml/EbmlSubHead.h"
72 #include "ebml/EbmlStream.h"
73 #include "ebml/EbmlContexts.h"
74 #include "ebml/EbmlVoid.h"
75 #include "ebml/EbmlVersion.h"
76 #include "ebml/StdIOCallback.h"
77
78 #include "matroska/KaxAttachments.h"
79 #include "matroska/KaxAttached.h"
80 #include "matroska/KaxBlock.h"
81 #include "matroska/KaxBlockData.h"
82 #include "matroska/KaxChapters.h"
83 #include "matroska/KaxCluster.h"
84 #include "matroska/KaxClusterData.h"
85 #include "matroska/KaxContexts.h"
86 #include "matroska/KaxCues.h"
87 #include "matroska/KaxCuesData.h"
88 #include "matroska/KaxInfo.h"
89 #include "matroska/KaxInfoData.h"
90 #include "matroska/KaxSeekHead.h"
91 #include "matroska/KaxSegment.h"
92 #include "matroska/KaxTag.h"
93 #include "matroska/KaxTags.h"
94 #include "matroska/KaxTagMulti.h"
95 #include "matroska/KaxTracks.h"
96 #include "matroska/KaxTrackAudio.h"
97 #include "matroska/KaxTrackVideo.h"
98 #include "matroska/KaxTrackEntryData.h"
99 #include "matroska/KaxContentEncoding.h"
100 #include "matroska/KaxVersion.h"
101
102 #include "ebml/StdIOCallback.h"
103
104 #include <vlc_keys.h>
105
106 extern "C" {
107    #include "../mp4/libmp4.h"
108 }
109 #ifdef HAVE_ZLIB_H
110 #   include <zlib.h>
111 #endif
112
113 #define MKV_DEBUG 0
114
115 #define MATROSKA_COMPRESSION_NONE  -1
116 #define MATROSKA_COMPRESSION_ZLIB   0
117 #define MATROSKA_COMPRESSION_BLIB   1
118 #define MATROSKA_COMPRESSION_LZOX   2
119 #define MATROSKA_COMPRESSION_HEADER 3
120
121 #define MKVD_TIMECODESCALE 1000000
122
123 #define MKV_IS_ID( el, C ) ( EbmlId( (*el) ) == C::ClassInfos.GlobalId )
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()
136         :p_data(NULL)
137         ,i_size(0)
138     {}
139     virtual ~attachment_c()
140     {
141         free( p_data );
142     }
143
144     std::string    psz_file_name;
145     std::string    psz_mime_type;
146     void          *p_data;
147     int            i_size;
148 };
149
150 class matroska_segment_c;
151
152 class matroska_stream_c
153 {
154 public:
155     matroska_stream_c( demux_sys_t & demuxer )
156         :p_in(NULL)
157         ,p_es(NULL)
158         ,sys(demuxer)
159     {}
160
161     virtual ~matroska_stream_c()
162     {
163         delete p_in;
164         delete p_es;
165     }
166
167     IOCallback         *p_in;
168     EbmlStream         *p_es;
169
170     std::vector<matroska_segment_c*> segments;
171
172     demux_sys_t                      & sys;
173 };
174
175
176 /*****************************************************************************
177  * definitions of structures and functions used by this plugins
178  *****************************************************************************/
179 typedef struct
180 {
181 //    ~mkv_track_t();
182
183     bool         b_default;
184     bool         b_enabled;
185     unsigned int i_number;
186
187     int          i_extra_data;
188     uint8_t      *p_extra_data;
189
190     char         *psz_codec;
191     bool         b_dts_only;
192     bool         b_pts_only;
193
194     uint64_t     i_default_duration;
195     float        f_timecodescale;
196     mtime_t      i_last_dts;
197
198     /* video */
199     es_format_t fmt;
200     float       f_fps;
201     es_out_id_t *p_es;
202
203     /* audio */
204     unsigned int i_original_rate;
205
206     bool            b_inited;
207     /* data to be send first */
208     int             i_data_init;
209     uint8_t         *p_data_init;
210
211     /* hack : it's for seek */
212     bool            b_search_keyframe;
213     bool            b_silent;
214
215     /* informative */
216     const char   *psz_codec_name;
217     const char   *psz_codec_settings;
218     const char   *psz_codec_info_url;
219     const char   *psz_codec_download_url;
220
221     /* encryption/compression */
222     int                    i_compression_type;
223     KaxContentCompSettings *p_compression_data;
224
225 } mkv_track_t;
226
227 typedef struct
228 {
229     int     i_track;
230     int     i_block_number;
231
232     int64_t i_position;
233     int64_t i_time;
234
235     bool       b_key;
236 } mkv_index_t;
237
238
239 #endif /* _MKV_HPP_ */