Mercurial > mplayer.hg
annotate libmpdemux/demux_mkv.cpp @ 10433:f06e65561257
Pause message shortened to not be longer than the audio file status line.
Inspired by a patch from Alex Sisson <alex_sisson@yahoo.co.uk>.
author | diego |
---|---|
date | Mon, 14 Jul 2003 17:12:06 +0000 |
parents | c2fc1c310699 |
children | dd64e1fe919d |
rev | line source |
---|---|
10024 | 1 extern "C" { |
2 #include "config.h" | |
3 } | |
4 | |
5 #ifdef HAVE_MATROSKA | |
6 | |
7 extern "C" { | |
8 #include <stdlib.h> | |
9 #include <stdio.h> | |
10 #include <string.h> | |
11 | |
12 #include "../mp_msg.h" | |
13 #include "../help_mp.h" | |
14 #include "stream.h" | |
15 #include "demuxer.h" | |
16 #include "stheader.h" | |
17 | |
18 #include "../subreader.h" | |
19 #include "../libvo/sub.h" | |
20 } | |
21 | |
22 #include <iostream> | |
23 #include <cassert> | |
24 #include <typeinfo> | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
25 #include <vector> |
10024 | 26 |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
27 #include <ebml/EbmlHead.h> |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
28 #include <ebml/EbmlSubHead.h> |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
29 #include <ebml/EbmlStream.h> |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
30 #include <ebml/EbmlContexts.h> |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
31 #include <ebml/EbmlVersion.h> |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
32 #include <ebml/StdIOCallback.h> |
10024 | 33 |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
34 #include <matroska/KaxAttachements.h> |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
35 #include <matroska/KaxBlock.h> |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
36 #include <matroska/KaxBlockData.h> |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
37 #include <matroska/KaxChapters.h> |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
38 #include <matroska/KaxCluster.h> |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
39 #include <matroska/KaxClusterData.h> |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
40 #include <matroska/KaxContexts.h> |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
41 #include <matroska/KaxCues.h> |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
42 #include <matroska/KaxCuesData.h> |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
43 #include <matroska/KaxInfo.h> |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
44 #include <matroska/KaxInfoData.h> |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
45 #include <matroska/KaxSeekHead.h> |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
46 #include <matroska/KaxSegment.h> |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
47 #include <matroska/KaxTracks.h> |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
48 #include <matroska/KaxTrackAudio.h> |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
49 #include <matroska/KaxTrackVideo.h> |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
50 #include <matroska/FileKax.h> |
10024 | 51 |
52 #include "matroska.h" | |
53 | |
54 using namespace LIBMATROSKA_NAMESPACE; | |
55 using namespace std; | |
56 | |
10273 | 57 #ifndef LIBEBML_VERSION |
58 #define LIBEBML_VERSION 000000 | |
59 #endif // LIBEBML_VERSION | |
60 | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
61 #if LIBEBML_VERSION < 000500 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
62 #error libebml version too old - need at least 0.5.0 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
63 #endif |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
64 |
10060
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
65 // for e.g. "-slang ger" |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
66 extern char *dvdsub_lang; |
10167
531b00ad6f2d
Support for selecting the audio track in Matroska files via -alang.
mosu
parents:
10149
diff
changeset
|
67 extern char *audio_lang; |
10060
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
68 |
10024 | 69 // default values for Matroska elements |
70 #define MKVD_TIMECODESCALE 1000000 // 1000000 = 1ms | |
71 | |
72 class mpstream_io_callback: public IOCallback { | |
73 private: | |
74 stream_t *s; | |
75 public: | |
76 mpstream_io_callback(stream_t *stream); | |
77 | |
78 virtual uint32 read(void *buffer, size_t size); | |
79 virtual void setFilePointer(int64 offset, seek_mode mode = seek_beginning); | |
80 virtual size_t write(const void *buffer, size_t size); | |
81 virtual uint64 getFilePointer(); | |
82 virtual void close(); | |
83 }; | |
84 | |
85 mpstream_io_callback::mpstream_io_callback(stream_t *stream) { | |
86 s = stream; | |
87 } | |
88 | |
89 uint32 mpstream_io_callback::read(void *buffer, size_t size) { | |
90 uint32_t result; | |
91 | |
92 result = stream_read(s, (char *)buffer, size); | |
93 | |
94 return result; | |
95 } | |
96 | |
97 void mpstream_io_callback::setFilePointer(int64 offset, seek_mode mode) { | |
98 int64 new_pos; | |
99 | |
100 if (mode == seek_beginning) | |
101 new_pos = offset + s->start_pos; | |
102 else if (mode == seek_end) | |
103 new_pos = s->end_pos - offset; | |
104 else | |
105 new_pos = s->pos + offset; | |
106 | |
107 if (new_pos > s->end_pos) { | |
108 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] seek warning: new_pos %lld > end_pos " | |
109 "%lld\n", new_pos, s->end_pos); | |
110 return; | |
111 } | |
112 | |
113 stream_seek(s, new_pos); | |
114 } | |
115 | |
116 size_t mpstream_io_callback::write(const void */*buffer*/, size_t /*size*/) { | |
117 return 0; | |
118 } | |
119 | |
120 uint64 mpstream_io_callback::getFilePointer() { | |
121 return s->pos - s->buf_len + s->buf_pos; | |
122 } | |
123 | |
124 void mpstream_io_callback::close() { | |
125 } | |
126 | |
127 typedef struct mkv_index_entry { | |
128 uint64_t timecode, filepos; | |
129 int is_key; | |
130 } mkv_index_entry_t; | |
131 | |
132 typedef struct mkv_track_index { | |
133 uint32_t tnum; | |
134 int num_entries; | |
135 mkv_index_entry_t *entries; | |
136 } mkv_track_index_t; | |
137 | |
138 typedef struct mkv_track { | |
139 uint32_t tnum; | |
140 | |
141 char *codec_id; | |
142 int ms_compat; | |
10060
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
143 char *language; |
10024 | 144 |
10060
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
145 char type; // 'v' = video, 'a' = audio, 's' = subs |
10024 | 146 |
147 char v_fourcc[5]; | |
10081
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
148 uint32_t v_width, v_height, v_dwidth, v_dheight; |
10024 | 149 float v_frate; |
150 | |
10125 | 151 uint32_t a_formattag; |
10024 | 152 uint32_t a_channels, a_bps; |
153 float a_sfreq; | |
154 | |
155 int default_track; | |
156 | |
157 void *private_data; | |
158 unsigned int private_size; | |
159 | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
160 // For Vorbis audio |
10024 | 161 unsigned char *headers[3]; |
162 uint32_t header_sizes[3]; | |
163 | |
164 int ok; | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
165 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
166 // Stuff for RealMedia packet assembly |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
167 bool realmedia; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
168 demux_packet_t *rm_dp; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
169 int rm_seqnum; |
10024 | 170 } mkv_track_t; |
171 | |
172 typedef struct mkv_demuxer { | |
173 float duration, last_pts; | |
174 uint64_t last_filepos; | |
175 | |
176 mkv_track_t **tracks; | |
177 int num_tracks; | |
178 mkv_track_t *video, *audio, *subs_track; | |
179 | |
10283
21972de8631d
Support for files whose first timecode is not 0 (which is the case for splitted/linked files).
mosu
parents:
10273
diff
changeset
|
180 uint64_t tc_scale, cluster_tc, first_tc; |
10024 | 181 |
182 mpstream_io_callback *in; | |
183 | |
184 uint64_t clear_subs_at; | |
185 | |
186 subtitle subs; | |
187 | |
188 EbmlStream *es; | |
189 EbmlElement *saved_l1, *saved_l2; | |
190 KaxSegment *segment; | |
191 KaxCluster *cluster; | |
192 | |
193 mkv_track_index_t *index; | |
194 int num_indexes, cues_found, cues_searched; | |
195 int64_t *cluster_positions; | |
196 int num_cluster_pos; | |
197 | |
198 int skip_to_keyframe; | |
10060
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
199 int64_t skip_to_timecode; |
10024 | 200 } mkv_demuxer_t; |
201 | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
202 typedef struct { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
203 uint32_t chunks; // number of chunks |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
204 uint32_t timestamp; // timestamp from packet header |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
205 uint32_t len; // length of actual data |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
206 uint32_t chunktab; // offset to chunk offset array |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
207 } dp_hdr_t; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
208 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
209 #pragma pack(push,2) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
210 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
211 typedef struct { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
212 uint32_t size; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
213 uint32_t fourcc1; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
214 uint32_t fourcc2; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
215 uint16_t width; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
216 uint16_t height; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
217 uint16_t bpp; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
218 uint32_t unknown1; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
219 uint32_t fps; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
220 uint32_t type1; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
221 uint32_t type2; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
222 } real_video_props_t; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
223 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
224 typedef struct { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
225 uint32_t fourcc1; // '.', 'r', 'a', 0xfd |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
226 uint16_t version1; // 4 or 5 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
227 uint16_t unknown1; // 00 000 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
228 uint32_t fourcc2; // .ra4 or .ra5 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
229 uint32_t unknown2; // ??? |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
230 uint16_t version2; // 4 or 5 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
231 uint32_t header_size; // == 0x4e |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
232 uint16_t flavor; // codec flavor id |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
233 uint32_t coded_frame_size; // coded frame size |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
234 uint32_t unknown3; // big number |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
235 uint32_t unknown4; // bigger number |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
236 uint32_t unknown5; // yet another number |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
237 uint16_t sub_packet_h; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
238 uint16_t frame_size; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
239 uint16_t sub_packet_size; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
240 uint16_t unknown6; // 00 00 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
241 uint16_t sample_rate; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
242 uint16_t unknown8; // 0 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
243 uint16_t sample_size; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
244 uint16_t channels; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
245 } real_audio_v4_props_t; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
246 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
247 typedef struct { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
248 uint32_t fourcc1; // '.', 'r', 'a', 0xfd |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
249 uint16_t version1; // 4 or 5 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
250 uint16_t unknown1; // 00 000 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
251 uint32_t fourcc2; // .ra4 or .ra5 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
252 uint32_t unknown2; // ??? |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
253 uint16_t version2; // 4 or 5 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
254 uint32_t header_size; // == 0x4e |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
255 uint16_t flavor; // codec flavor id |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
256 uint32_t coded_frame_size; // coded frame size |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
257 uint32_t unknown3; // big number |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
258 uint32_t unknown4; // bigger number |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
259 uint32_t unknown5; // yet another number |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
260 uint16_t sub_packet_h; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
261 uint16_t frame_size; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
262 uint16_t sub_packet_size; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
263 uint16_t unknown6; // 00 00 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
264 uint8_t unknown7[6]; // 0, srate, 0 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
265 uint16_t sample_rate; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
266 uint16_t unknown8; // 0 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
267 uint16_t sample_size; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
268 uint16_t channels; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
269 uint32_t genr; // "genr" |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
270 uint32_t fourcc3; // fourcc |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
271 } real_audio_v5_props_t; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
272 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
273 #pragma pack(pop) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
274 |
10024 | 275 static uint16_t get_uint16(const void *buf) { |
276 uint16_t ret; | |
277 unsigned char *tmp; | |
278 | |
279 tmp = (unsigned char *) buf; | |
280 | |
281 ret = tmp[1] & 0xff; | |
282 ret = (ret << 8) + (tmp[0] & 0xff); | |
283 | |
284 return ret; | |
285 } | |
286 | |
287 static uint32_t get_uint32(const void *buf) { | |
288 uint32_t ret; | |
289 unsigned char *tmp; | |
290 | |
291 tmp = (unsigned char *) buf; | |
292 | |
293 ret = tmp[3] & 0xff; | |
294 ret = (ret << 8) + (tmp[2] & 0xff); | |
295 ret = (ret << 8) + (tmp[1] & 0xff); | |
296 ret = (ret << 8) + (tmp[0] & 0xff); | |
297 | |
298 return ret; | |
299 } | |
300 | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
301 static uint16_t get_uint16_be(const void *buf) { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
302 uint16_t ret; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
303 unsigned char *tmp; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
304 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
305 tmp = (unsigned char *) buf; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
306 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
307 ret = tmp[0] & 0xff; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
308 ret = (ret << 8) + (tmp[1] & 0xff); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
309 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
310 return ret; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
311 } |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
312 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
313 static uint32_t get_uint32_be(const void *buf) { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
314 uint32_t ret; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
315 unsigned char *tmp; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
316 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
317 tmp = (unsigned char *) buf; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
318 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
319 ret = tmp[0] & 0xff; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
320 ret = (ret << 8) + (tmp[1] & 0xff); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
321 ret = (ret << 8) + (tmp[2] & 0xff); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
322 ret = (ret << 8) + (tmp[3] & 0xff); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
323 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
324 return ret; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
325 } |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
326 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
327 unsigned char read_char(unsigned char *p, int &pos, int size) { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
328 if ((pos + 1) > size) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
329 throw exception(); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
330 pos++; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
331 return p[pos - 1]; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
332 } |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
333 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
334 unsigned short read_word(unsigned char *p, int &pos, int size) { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
335 unsigned short v; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
336 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
337 if ((pos + 2) > size) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
338 throw exception(); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
339 v = p[pos]; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
340 v = (v << 8) | (p[pos + 1] & 0xff); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
341 pos += 2; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
342 return v; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
343 } |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
344 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
345 unsigned int read_dword(unsigned char *p, int &pos, int size) { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
346 unsigned int v; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
347 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
348 if ((pos + 4) > size) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
349 throw exception(); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
350 v = p[pos]; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
351 v = (v << 8) | (p[pos + 1] & 0xff); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
352 v = (v << 8) | (p[pos + 2] & 0xff); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
353 v = (v << 8) | (p[pos + 3] & 0xff); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
354 pos += 4; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
355 return v; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
356 } |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
357 |
10024 | 358 static void handle_subtitles(demuxer_t *d, KaxBlock *block, int64_t duration) { |
359 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *)d->priv; | |
360 int len, line, state; | |
361 char *s1, *s2, *buffer; | |
362 | |
363 if (duration == -1) { | |
364 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Warning: No KaxBlockDuration " | |
365 "element for subtitle track found.\n"); | |
366 return; | |
367 } | |
368 | |
369 DataBuffer &data = block->GetBuffer(0); | |
370 len = data.Size(); | |
371 | |
372 buffer = (char *)data.Buffer(); | |
373 s1 = buffer; | |
374 | |
375 while (((*s1 == '\n') || (*s1 == '\r')) && | |
376 ((unsigned int)(s1 - buffer) <= data.Size())) | |
377 s1++; | |
378 | |
379 line = 0; | |
380 s2 = mkv_d->subs.text[0]; | |
381 mkv_d->subs.lines = 1; | |
382 state = 0; | |
383 while ((unsigned int)(s1 - buffer) != data.Size()) { | |
384 if ((*s1 == '\n') || (*s1 == '\r')) { | |
385 if (state == 0) { // normal char --> newline | |
386 if (mkv_d->subs.lines == SUB_MAX_TEXT) | |
387 break; | |
388 *s2 = 0; | |
389 s2 = mkv_d->subs.text[mkv_d->subs.lines]; | |
390 mkv_d->subs.lines++; | |
391 state = 1; | |
392 } | |
393 } else if (*s1 == '<') // skip HTML tags | |
394 state = 2; | |
395 else if (*s1 == '>') | |
396 state = 0; | |
397 else if (state != 2) { // normal character | |
398 state = 0; | |
399 if ((s2 - mkv_d->subs.text[mkv_d->subs.lines - 1]) < 255) { | |
400 *s2 = *s1; | |
401 s2++; | |
402 } | |
403 } | |
404 s1++; | |
405 } | |
406 | |
407 *s2 = 0; | |
408 | |
409 #ifdef USE_ICONV | |
410 subcp_recode1(&mkv_d->subs); | |
411 #endif | |
412 | |
413 vo_sub = &mkv_d->subs; | |
414 vo_osd_changed(OSDTYPE_SUBTITLE); | |
415 | |
10283
21972de8631d
Support for files whose first timecode is not 0 (which is the case for splitted/linked files).
mosu
parents:
10273
diff
changeset
|
416 mkv_d->clear_subs_at = block->GlobalTimecode() / 1000000 - mkv_d->first_tc + |
21972de8631d
Support for files whose first timecode is not 0 (which is the case for splitted/linked files).
mosu
parents:
10273
diff
changeset
|
417 duration; |
10024 | 418 } |
419 | |
420 static mkv_track_t *new_mkv_track(mkv_demuxer_t *d) { | |
421 mkv_track_t *t; | |
422 | |
423 t = (mkv_track_t *)malloc(sizeof(mkv_track_t)); | |
424 if (t != NULL) { | |
425 memset(t, 0, sizeof(mkv_track_t)); | |
426 d->tracks = (mkv_track_t **)realloc(d->tracks, (d->num_tracks + 1) * | |
427 sizeof(mkv_track_t *)); | |
428 if (d->tracks == NULL) | |
429 return NULL; | |
430 d->tracks[d->num_tracks] = t; | |
431 d->num_tracks++; | |
10036
1dfe4dab4a42
Implemented some default values. The corresponding Kax elements are not stored if they are set to their default value.
mosu
parents:
10029
diff
changeset
|
432 |
1dfe4dab4a42
Implemented some default values. The corresponding Kax elements are not stored if they are set to their default value.
mosu
parents:
10029
diff
changeset
|
433 // Set default values. |
1dfe4dab4a42
Implemented some default values. The corresponding Kax elements are not stored if they are set to their default value.
mosu
parents:
10029
diff
changeset
|
434 t->default_track = 1; |
1dfe4dab4a42
Implemented some default values. The corresponding Kax elements are not stored if they are set to their default value.
mosu
parents:
10029
diff
changeset
|
435 t->a_sfreq = 8000.0; |
1dfe4dab4a42
Implemented some default values. The corresponding Kax elements are not stored if they are set to their default value.
mosu
parents:
10029
diff
changeset
|
436 t->a_channels = 1; |
10060
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
437 t->language = strdup("eng"); |
10024 | 438 } |
439 | |
440 return t; | |
441 } | |
442 | |
443 static mkv_track_t *find_track_by_num(mkv_demuxer_t *d, uint32_t n, | |
444 mkv_track_t *c) { | |
445 int i; | |
446 | |
447 for (i = 0; i < d->num_tracks; i++) | |
448 if ((d->tracks[i] != NULL) && (d->tracks[i]->tnum == n) && | |
449 (d->tracks[i] != c)) | |
450 return d->tracks[i]; | |
451 | |
452 return NULL; | |
453 } | |
454 | |
10060
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
455 static mkv_track_t *find_track_by_language(mkv_demuxer_t *d, char *language, |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
456 mkv_track_t *c, char type = 's') { |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
457 int i; |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
458 |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
459 for (i = 0; i < d->num_tracks; i++) |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
460 if ((d->tracks[i] != NULL) && (d->tracks[i] != c) && |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
461 (d->tracks[i]->language != NULL) && |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
462 !strcmp(d->tracks[i]->language, language) && |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
463 (d->tracks[i]->type == type)) |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
464 return d->tracks[i]; |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
465 |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
466 return NULL; |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
467 } |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
468 |
10024 | 469 static int check_track_information(mkv_demuxer_t *d) { |
10028
7ca8b302032f
Loop counter was used inside for another loop as well.
mosu
parents:
10024
diff
changeset
|
470 int i, track_num; |
10024 | 471 unsigned char *c; |
472 uint32_t u, offset, length; | |
473 mkv_track_t *t; | |
474 BITMAPINFOHEADER *bih; | |
475 WAVEFORMATEX *wfe; | |
476 | |
10028
7ca8b302032f
Loop counter was used inside for another loop as well.
mosu
parents:
10024
diff
changeset
|
477 for (track_num = 0; track_num < d->num_tracks; track_num++) { |
7ca8b302032f
Loop counter was used inside for another loop as well.
mosu
parents:
10024
diff
changeset
|
478 |
7ca8b302032f
Loop counter was used inside for another loop as well.
mosu
parents:
10024
diff
changeset
|
479 t = d->tracks[track_num]; |
10024 | 480 switch (t->type) { |
481 case 'v': // video track | |
482 if (t->codec_id == NULL) | |
483 continue; | |
484 if (!strcmp(t->codec_id, MKV_V_MSCOMP)) { | |
485 if ((t->private_data == NULL) || | |
486 (t->private_size < sizeof(BITMAPINFOHEADER))) { | |
487 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] WARNING: CodecID for track " | |
488 "%u is '" MKV_V_MSCOMP "', but there was no " | |
489 "BITMAPINFOHEADER struct present. Therefore we don't have " | |
490 "a FourCC to identify the video codec used.\n", t->tnum); | |
491 continue; | |
492 } else { | |
493 t->ms_compat = 1; | |
494 | |
495 bih = (BITMAPINFOHEADER *)t->private_data; | |
496 | |
497 u = get_uint32(&bih->biWidth); | |
498 if (t->v_width != u) { | |
499 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] WARNING: (MS " | |
500 "compatibility mode, track %u) " | |
501 "Matrosa says video width is %u, but the " | |
502 "BITMAPINFOHEADER says %u.\n", t->tnum, t->v_width, u); | |
503 if (t->v_width == 0) | |
504 t->v_width = u; | |
505 } | |
506 | |
507 u = get_uint32(&bih->biHeight); | |
508 if (t->v_height != u) { | |
509 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] WARNING: (MS compatibility " | |
510 "mode, track %u) " | |
511 "Matrosa video height is %u, but the BITMAPINFOHEADER " | |
512 "says %u.\n", t->tnum, t->v_height, u); | |
513 if (t->v_height == 0) | |
514 t->v_height = u; | |
515 } | |
516 | |
517 memcpy(t->v_fourcc, &bih->biCompression, 4); | |
518 } | |
519 } | |
520 | |
521 if (t->v_width == 0) { | |
522 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] The width for track %u was " | |
523 "not set.\n", t->tnum); | |
524 continue; | |
525 } | |
526 if (t->v_height == 0) { | |
527 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] The height for track %u was " | |
528 "not set.\n", t->tnum); | |
529 continue; | |
530 } | |
531 | |
10081
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
532 if (t->v_dwidth == 0) |
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
533 t->v_dwidth = t->v_width; |
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
534 if (t->v_dheight == 0) |
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
535 t->v_dheight = t->v_height; |
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
536 |
10024 | 537 // This track seems to be ok. |
538 t->ok = 1; | |
539 | |
540 break; | |
541 | |
542 case 'a': // audio track | |
543 if (t->codec_id == NULL) | |
544 continue; | |
545 if (!strcmp(t->codec_id, MKV_A_ACM)) { | |
546 if ((t->private_data == NULL) || | |
547 (t->private_size < sizeof(WAVEFORMATEX))) { | |
548 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] WARNING: CodecID for track " | |
549 "%u is '" MKV_A_ACM "', " | |
550 "but there was no WAVEFORMATEX struct present. " | |
551 "Therefore we don't have a format ID to identify the audio " | |
552 "codec used.\n", t->tnum); | |
553 continue; | |
554 } else { | |
555 t->ms_compat = 1; | |
556 | |
557 wfe = (WAVEFORMATEX *)t->private_data; | |
558 u = get_uint32(&wfe->nSamplesPerSec); | |
559 if (((uint32_t)t->a_sfreq) != u) { | |
560 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] WARNING: (MS compatibility " | |
561 "mode for track %u) " | |
562 "Matroska says that there are %u samples per second, " | |
563 "but WAVEFORMATEX says that there are %u.\n", t->tnum, | |
564 (uint32_t)t->a_sfreq, u); | |
565 if (t->a_sfreq == 0.0) | |
566 t->a_sfreq = (float)u; | |
567 } | |
568 | |
569 u = get_uint16(&wfe->nChannels); | |
570 if (t->a_channels != u) { | |
571 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] WARNING: (MS " | |
572 "compatibility mode for track %u) " | |
573 "Matroska says that there are %u channels, but the " | |
574 "WAVEFORMATEX says that there are %u.\n", t->tnum, | |
575 t->a_channels, u); | |
576 if (t->a_channels == 0) | |
577 t->a_channels = u; | |
578 } | |
579 | |
580 u = get_uint16(&wfe->wBitsPerSample); | |
10098 | 581 if (t->a_bps != u) { |
10024 | 582 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] WARNING: (MS " |
583 "compatibility mode for track %u) " | |
584 "Matroska says that there are %u bits per sample, " | |
585 "but the WAVEFORMATEX says that there are %u.\n", t->tnum, | |
586 t->a_bps, u); | |
587 if (t->a_bps == 0) | |
588 t->a_bps = u; | |
589 } | |
590 | |
591 t->a_formattag = get_uint16(&wfe->wFormatTag); | |
592 } | |
593 } else { | |
594 if (!strcmp(t->codec_id, MKV_A_MP3)) | |
595 t->a_formattag = 0x0055; | |
596 else if (!strcmp(t->codec_id, MKV_A_AC3)) | |
597 t->a_formattag = 0x2000; | |
10105
dc4f1b768062
Support for DTS tracks (only with -hwac3 of course).
mosu
parents:
10099
diff
changeset
|
598 else if (!strcmp(t->codec_id, MKV_A_DTS)) |
dc4f1b768062
Support for DTS tracks (only with -hwac3 of course).
mosu
parents:
10099
diff
changeset
|
599 // uses same format tag as AC3, only supported with -hwac3 |
dc4f1b768062
Support for DTS tracks (only with -hwac3 of course).
mosu
parents:
10099
diff
changeset
|
600 t->a_formattag = 0x2000; |
10024 | 601 else if (!strcmp(t->codec_id, MKV_A_PCM)) |
602 t->a_formattag = 0x0001; | |
10133
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
603 else if (!strcmp(t->codec_id, MKV_A_AAC_2MAIN) || |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
604 !strcmp(t->codec_id, MKV_A_AAC_2LC) || |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
605 !strcmp(t->codec_id, MKV_A_AAC_2SSR) || |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
606 !strcmp(t->codec_id, MKV_A_AAC_4MAIN) || |
10125 | 607 !strcmp(t->codec_id, MKV_A_AAC_4LC) || |
10133
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
608 !strcmp(t->codec_id, MKV_A_AAC_4SSR) || |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
609 !strcmp(t->codec_id, MKV_A_AAC_4LTP) || |
10125 | 610 !strcmp(t->codec_id, MKV_A_AAC_4SBR)) |
611 t->a_formattag = mmioFOURCC('M', 'P', '4', 'A'); | |
10024 | 612 else if (!strcmp(t->codec_id, MKV_A_VORBIS)) { |
613 if (t->private_data == NULL) { | |
614 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] WARNING: CodecID for " | |
615 "track %u is '" MKV_A_VORBIS | |
616 "', but there are no header packets present.", t->tnum); | |
617 continue; | |
618 } | |
619 | |
620 c = (unsigned char *)t->private_data; | |
621 if (c[0] != 2) { | |
622 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Vorbis track does not " | |
623 "contain valid headers.\n"); | |
624 continue; | |
625 } | |
626 | |
627 offset = 1; | |
628 for (i = 0; i < 2; i++) { | |
629 length = 0; | |
630 while ((c[offset] == (unsigned char )255) && | |
631 (length < t->private_size)) { | |
632 length += 255; | |
633 offset++; | |
634 } | |
635 if (offset >= (t->private_size - 1)) { | |
636 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Vorbis track does not " | |
637 "contain valid headers.\n"); | |
638 continue; | |
639 } | |
640 length += c[offset]; | |
641 offset++; | |
642 t->header_sizes[i] = length; | |
643 } | |
644 | |
645 t->headers[0] = &c[offset]; | |
646 t->headers[1] = &c[offset + t->header_sizes[0]]; | |
647 t->headers[2] = &c[offset + t->header_sizes[0] + | |
648 t->header_sizes[1]]; | |
10079
7c13793dbfa0
Vorbis header packet lengths were calculated incorrectly.
mosu
parents:
10073
diff
changeset
|
649 t->header_sizes[2] = t->private_size - offset - |
7c13793dbfa0
Vorbis header packet lengths were calculated incorrectly.
mosu
parents:
10073
diff
changeset
|
650 t->header_sizes[0] - t->header_sizes[1]; |
10024 | 651 |
652 t->a_formattag = 0xFFFE; | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
653 } else if (t->private_size >= sizeof(real_audio_v4_props_t)) { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
654 if (!strcmp(t->codec_id, MKV_A_REAL28)) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
655 t->a_formattag = mmioFOURCC('2', '8', '_', '8'); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
656 else if (!strcmp(t->codec_id, MKV_A_REALATRC)) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
657 t->a_formattag = mmioFOURCC('a', 't', 'r', 'c'); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
658 else if (!strcmp(t->codec_id, MKV_A_REALCOOK)) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
659 t->a_formattag = mmioFOURCC('c', 'o', 'o', 'k'); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
660 else if (!strcmp(t->codec_id, MKV_A_REALDNET)) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
661 t->a_formattag = mmioFOURCC('d', 'n', 'e', 't'); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
662 else if (!strcmp(t->codec_id, MKV_A_REALSIPR)) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
663 t->a_formattag = mmioFOURCC('s', 'i', 'p', 'r'); |
10024 | 664 } else { |
665 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Unknown/unsupported audio " | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
666 "codec ID '%s' for track %u or missing/faulty private " |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
667 "codec data.\n", t->codec_id, t->tnum); |
10024 | 668 continue; |
669 } | |
670 } | |
671 | |
672 if (t->a_sfreq == 0.0) { | |
673 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] The sampling frequency was not " | |
674 "set for track %u.\n", t->tnum); | |
675 continue; | |
676 } | |
677 | |
678 if (t->a_channels == 0) { | |
679 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] The number of channels was not " | |
680 "set for track %u.\n", t->tnum); | |
681 continue; | |
682 } | |
683 | |
684 if (t->a_formattag == 0) { | |
685 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] The audio format tag was not " | |
686 "set for track %u.\n", t->tnum); | |
687 continue; | |
688 } | |
689 | |
690 // This track seems to be ok. | |
691 t->ok = 1; | |
692 | |
693 break; | |
694 | |
695 case 's': // Text subtitles do not need any data | |
696 t->ok = 1; // except the CodecID. | |
697 break; | |
698 | |
699 default: // unknown track type!? error in demuxer... | |
700 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] Error in demux_mkv.cpp: unknown " | |
701 "demuxer type for track %u: '%c'\n", t->tnum, t->type); | |
702 continue; | |
703 } | |
704 | |
705 if (t->ok) | |
706 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Track %u seems to be ok.\n", t->tnum); | |
707 } | |
708 | |
709 return 1; | |
710 } | |
711 | |
712 static void free_mkv_demuxer(mkv_demuxer_t *d) { | |
713 int i; | |
714 | |
715 if (d == NULL) | |
716 return; | |
717 | |
718 for (i = 0; i < d->num_tracks; i++) | |
719 if (d->tracks[i] != NULL) { | |
720 if (d->tracks[i]->private_data != NULL) | |
721 free(d->tracks[i]->private_data); | |
10060
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
722 if (d->tracks[i]->language != NULL) |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
723 free(d->tracks[i]->language); |
10024 | 724 free(d->tracks[i]); |
725 } | |
726 | |
727 for (i = 0; i < d->num_indexes; i++) | |
728 free(d->index[i].entries); | |
729 free(d->index); | |
730 | |
731 if (d->es != NULL) | |
732 delete d->es; | |
733 if (d->saved_l1 != NULL) | |
734 delete d->saved_l1; | |
735 if (d->in != NULL) | |
736 delete d->in; | |
737 if (d->segment != NULL) | |
738 delete d->segment; | |
739 | |
740 free(d); | |
741 } | |
742 | |
743 static void add_index_entry(mkv_demuxer_t *d, uint32_t tnum, uint64_t filepos, | |
744 uint64_t timecode, int is_key) { | |
745 int i, found; | |
746 mkv_index_entry_t *entry; | |
747 | |
748 for (i = 0, found = 0; i < d->num_indexes; i++) | |
749 if (d->index[i].tnum == tnum) { | |
750 found = 1; | |
751 break; | |
752 } | |
753 | |
754 if (!found) { | |
755 d->index = (mkv_track_index_t *)realloc(d->index, (d->num_indexes + 1) * | |
756 sizeof(mkv_track_index_t)); | |
757 if (d->index == NULL) | |
758 return; | |
759 i = d->num_indexes; | |
760 memset(&d->index[i], 0, sizeof(mkv_track_index_t)); | |
761 d->index[i].tnum = tnum; | |
762 d->num_indexes++; | |
763 } | |
764 | |
765 d->index[i].entries = | |
766 (mkv_index_entry_t *)realloc(d->index[i].entries, | |
767 (d->index[i].num_entries + 1) * | |
768 sizeof(mkv_index_entry_t)); | |
769 if (d->index[i].entries == NULL) | |
770 return; | |
771 entry = &d->index[i].entries[d->index[i].num_entries]; | |
772 entry->filepos = filepos; | |
773 entry->timecode = timecode; | |
774 entry->is_key = is_key; | |
775 d->index[i].num_entries++; | |
776 } | |
777 | |
778 static void add_cluster_position(mkv_demuxer_t *mkv_d, int64_t position) { | |
779 mkv_d->cluster_positions = (int64_t *)realloc(mkv_d->cluster_positions, | |
780 (mkv_d->num_cluster_pos + 1) * | |
781 sizeof(int64_t)); | |
782 if (mkv_d->cluster_positions != NULL) { | |
783 mkv_d->cluster_positions[mkv_d->num_cluster_pos] = position; | |
784 mkv_d->num_cluster_pos++; | |
785 } else | |
786 mkv_d->num_cluster_pos = 0; | |
787 } | |
788 | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
789 #define fits_parent(l, p) (l->GetElementPosition() < \ |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
790 (p->GetElementPosition() + p->ElementSize())) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
791 |
10024 | 792 static int parse_cues(mkv_demuxer_t *mkv_d) { |
793 EbmlElement *l1 = NULL, *l2 = NULL, *l3 = NULL, *l4 = NULL, *l5 = NULL; | |
794 EbmlStream *es; | |
795 int upper_lvl_el, elements_found, i, k; | |
796 uint64_t tc_scale, filepos = 0, timecode = 0; | |
797 uint32_t tnum = 0; | |
798 mkv_index_entry_t *entry; | |
799 | |
800 es = mkv_d->es; | |
801 tc_scale = mkv_d->tc_scale; | |
802 upper_lvl_el = 0; | |
803 | |
804 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] /---- [ parsing cues ] -----------\n"); | |
805 | |
806 l1 = es->FindNextElement(mkv_d->segment->Generic().Context, upper_lvl_el, | |
807 0xFFFFFFFFL, true, 1); | |
808 if (l1 == NULL) | |
809 return 0; | |
810 | |
811 if (!(EbmlId(*l1) == KaxCues::ClassInfos.GlobalId)) { | |
812 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] No KaxCues element found but but %s.\n" | |
813 "[mkv] \\---- [ parsing cues ] -----------\n", typeid(*l1).name()); | |
814 | |
815 return 0; | |
816 } | |
817 | |
818 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] |+ found cues\n"); | |
819 | |
820 l2 = es->FindNextElement(l1->Generic().Context, upper_lvl_el, 0xFFFFFFFFL, | |
821 true, 1); | |
822 while (l2 != NULL) { | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
823 if (upper_lvl_el > 0) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
824 break; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
825 if ((upper_lvl_el < 0) && !fits_parent(l2, l1)) |
10024 | 826 break; |
827 | |
828 if (EbmlId(*l2) == KaxCuePoint::ClassInfos.GlobalId) { | |
829 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue point\n"); | |
830 | |
831 elements_found = 0; | |
832 | |
833 l3 = es->FindNextElement(l2->Generic().Context, upper_lvl_el, | |
834 0xFFFFFFFFL, true, 1); | |
835 while (l3 != NULL) { | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
836 if (upper_lvl_el > 0) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
837 break; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
838 if ((upper_lvl_el < 0) && !fits_parent(l3, l2)) |
10024 | 839 break; |
840 | |
841 if (EbmlId(*l3) == KaxCueTime::ClassInfos.GlobalId) { | |
842 KaxCueTime &cue_time = *static_cast<KaxCueTime *>(l3); | |
843 cue_time.ReadData(es->I_O()); | |
10283
21972de8631d
Support for files whose first timecode is not 0 (which is the case for splitted/linked files).
mosu
parents:
10273
diff
changeset
|
844 timecode = uint64(cue_time) * tc_scale / 1000000 - mkv_d->first_tc; |
10024 | 845 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue time: %.3fs\n", |
10283
21972de8631d
Support for files whose first timecode is not 0 (which is the case for splitted/linked files).
mosu
parents:
10273
diff
changeset
|
846 (float)timecode / 1000.0); |
10024 | 847 elements_found |= 1; |
848 | |
849 } else if (EbmlId(*l3) == | |
850 KaxCueTrackPositions::ClassInfos.GlobalId) { | |
851 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue track " | |
852 "positions\n"); | |
853 | |
854 l4 = es->FindNextElement(l3->Generic().Context, upper_lvl_el, | |
855 0xFFFFFFFFL, true, 1); | |
856 while (l4 != NULL) { | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
857 if (upper_lvl_el > 0) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
858 break; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
859 if ((upper_lvl_el < 0) && !fits_parent(l4, l3)) |
10024 | 860 break; |
861 | |
862 if (EbmlId(*l4) == KaxCueTrack::ClassInfos.GlobalId) { | |
863 KaxCueTrack &cue_track = *static_cast<KaxCueTrack *>(l4); | |
864 cue_track.ReadData(es->I_O()); | |
865 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue track: " | |
866 "%u\n", uint32(cue_track)); | |
867 | |
868 tnum = uint32(cue_track); | |
869 elements_found |= 2; | |
870 | |
871 } else if (EbmlId(*l4) == | |
872 KaxCueClusterPosition::ClassInfos.GlobalId) { | |
873 KaxCueClusterPosition &cue_cp = | |
874 *static_cast<KaxCueClusterPosition *>(l4); | |
875 cue_cp.ReadData(es->I_O()); | |
876 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue cluster " | |
877 "position: %llu\n", uint64(cue_cp)); | |
878 | |
879 filepos = mkv_d->segment->GetGlobalPosition(uint64_t(cue_cp)); | |
880 elements_found |= 4; | |
881 | |
882 } else if (EbmlId(*l4) == | |
883 KaxCueBlockNumber::ClassInfos.GlobalId) { | |
884 KaxCueBlockNumber &cue_bn = | |
885 *static_cast<KaxCueBlockNumber *>(l4); | |
886 cue_bn.ReadData(es->I_O()); | |
887 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue block " | |
888 "number: %llu\n", uint64(cue_bn)); | |
889 | |
890 } else if (EbmlId(*l4) == | |
891 KaxCueCodecState::ClassInfos.GlobalId) { | |
892 KaxCueCodecState &cue_cs = | |
893 *static_cast<KaxCueCodecState *>(l4); | |
894 cue_cs.ReadData(es->I_O()); | |
895 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue codec " | |
896 "state: %llu\n", uint64(cue_cs)); | |
897 | |
898 } else if (EbmlId(*l4) == | |
899 KaxCueReference::ClassInfos.GlobalId) { | |
900 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue " | |
901 "reference\n"); | |
902 | |
903 elements_found |= 8; | |
904 | |
905 l5 = es->FindNextElement(l4->Generic().Context, upper_lvl_el, | |
906 0xFFFFFFFFL, true, 1); | |
907 while (l5 != NULL) { | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
908 if (upper_lvl_el > 0) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
909 break; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
910 if ((upper_lvl_el < 0) && !fits_parent(l5, l4)) |
10024 | 911 break; |
912 | |
913 if (EbmlId(*l5) == KaxCueRefTime::ClassInfos.GlobalId) { | |
914 KaxCueRefTime &cue_rt = | |
915 *static_cast<KaxCueRefTime *>(l5); | |
916 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue ref " | |
917 "time: %.3fs\n", ((float)uint64(cue_rt)) * tc_scale / | |
918 1000000000.0); | |
919 | |
920 } else if (EbmlId(*l5) == | |
921 KaxCueRefCluster::ClassInfos.GlobalId) { | |
922 KaxCueRefCluster &cue_rc = | |
923 *static_cast<KaxCueRefCluster *>(l5); | |
924 cue_rc.ReadData(es->I_O()); | |
925 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue ref " | |
926 "cluster: %llu\n", uint64(cue_rc)); | |
927 | |
928 } else if (EbmlId(*l5) == | |
929 KaxCueRefNumber::ClassInfos.GlobalId) { | |
930 KaxCueRefNumber &cue_rn = | |
931 *static_cast<KaxCueRefNumber *>(l5); | |
932 cue_rn.ReadData(es->I_O()); | |
933 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue ref " | |
934 "number: %llu\n", uint64(cue_rn)); | |
935 | |
936 } else if (EbmlId(*l5) == | |
937 KaxCueRefCodecState::ClassInfos.GlobalId) { | |
938 KaxCueRefCodecState &cue_rcs = | |
939 *static_cast<KaxCueRefCodecState *>(l5); | |
940 cue_rcs.ReadData(es->I_O()); | |
941 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue ref " | |
942 "codec state: %llu\n", uint64(cue_rcs)); | |
943 | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
944 } else |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
945 upper_lvl_el = 0; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
946 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
947 if (upper_lvl_el == 0) { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
948 l5->SkipData(static_cast<EbmlStream &>(*es), |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
949 l5->Generic().Context); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
950 delete l5; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
951 l5 = es->FindNextElement(l4->Generic().Context, |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
952 upper_lvl_el, 0xFFFFFFFFL, true); |
10024 | 953 } |
954 | |
955 } // while (l5 != NULL) | |
956 | |
957 } else | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
958 upper_lvl_el = 0; |
10024 | 959 |
960 if (upper_lvl_el > 0) { // we're coming from l5 | |
961 upper_lvl_el--; | |
962 delete l4; | |
963 l4 = l5; | |
964 if (upper_lvl_el > 0) | |
965 break; | |
966 | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
967 } else if (upper_lvl_el == 0) { |
10024 | 968 l4->SkipData(static_cast<EbmlStream &>(*es), |
969 l4->Generic().Context); | |
970 delete l4; | |
971 l4 = es->FindNextElement(l3->Generic().Context, upper_lvl_el, | |
972 0xFFFFFFFFL, true, 1); | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
973 } else { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
974 delete l4; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
975 l4 = l5; |
10024 | 976 } |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
977 |
10024 | 978 } // while (l4 != NULL) |
979 | |
980 } else | |
981 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + unknown element, level 3: " | |
982 "%s\n", typeid(*l3).name()); | |
983 | |
984 if (upper_lvl_el > 0) { // we're coming from l4 | |
985 upper_lvl_el--; | |
986 delete l3; | |
987 l3 = l4; | |
988 if (upper_lvl_el > 0) | |
989 break; | |
990 | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
991 } else if (upper_lvl_el == 0) { |
10024 | 992 l3->SkipData(static_cast<EbmlStream &>(*es), |
993 l3->Generic().Context); | |
994 delete l3; | |
995 l3 = es->FindNextElement(l2->Generic().Context, upper_lvl_el, | |
996 0xFFFFFFFFL, true, 1); | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
997 } else { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
998 delete l3; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
999 l3 = l4; |
10024 | 1000 } |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1001 |
10024 | 1002 } // while (l3 != NULL) |
1003 | |
1004 // Three elements must have been found in order for this to be a | |
1005 // correct entry: | |
1006 // 1: cue time (timecode) | |
1007 // 2: cue track (tnum) | |
1008 // 4: cue cluster position (filepos) | |
1009 // If 8 is also set, then there was a reference element, and the | |
1010 // current block is not an I frame. If 8 is not set then this is | |
1011 // an I frame. | |
1012 if ((elements_found & 7) == 7) | |
1013 add_index_entry(mkv_d, tnum, filepos, timecode, | |
1014 (elements_found & 8) ? 0 : 1); | |
1015 | |
1016 } else | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1017 upper_lvl_el = 0; |
10024 | 1018 |
1019 if (upper_lvl_el > 0) { // we're coming from l3 | |
1020 upper_lvl_el--; | |
1021 delete l2; | |
1022 l2 = l3; | |
1023 if (upper_lvl_el > 0) | |
1024 break; | |
1025 | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1026 } else if (upper_lvl_el == 0) { |
10024 | 1027 l2->SkipData(static_cast<EbmlStream &>(*es), |
1028 l2->Generic().Context); | |
1029 delete l2; | |
1030 l2 = es->FindNextElement(l1->Generic().Context, upper_lvl_el, | |
1031 0xFFFFFFFFL, true, 1); | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1032 } else { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1033 delete l2; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1034 l2 = l3; |
10024 | 1035 } |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1036 |
10024 | 1037 } // while (l2 != NULL) |
1038 | |
1039 // Debug: dump the index | |
1040 for (i = 0; i < mkv_d->num_indexes; i++) { | |
1041 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] Index for track %u contains %u " | |
1042 "entries.\n", mkv_d->index[i].tnum, mkv_d->index[i].num_entries); | |
1043 for (k = 0; k < mkv_d->index[i].num_entries; k++) { | |
1044 entry = &mkv_d->index[i].entries[k]; | |
1045 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] %d: timecode %llu, filepos %llu, " | |
1046 "is key: %s\n", k, entry->timecode, entry->filepos, | |
1047 entry->is_key ? "yes" : "no"); | |
1048 } | |
1049 } | |
1050 | |
1051 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] \\---- [ parsing cues ] -----------\n"); | |
1052 | |
1053 return 1; | |
1054 } | |
1055 | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1056 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1057 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1058 extern "C" void print_wave_header(WAVEFORMATEX *h); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1059 |
10024 | 1060 extern "C" int demux_mkv_open(demuxer_t *demuxer) { |
1061 unsigned char signature[4]; | |
1062 stream_t *s; | |
1063 demux_packet_t *dp; | |
1064 mkv_demuxer_t *mkv_d; | |
1065 int upper_lvl_el, exit_loop, i; | |
1066 // Elements for different levels | |
1067 EbmlElement *l0 = NULL, *l1 = NULL, *l2 = NULL, *l3 = NULL, *l4 = NULL; | |
1068 EbmlStream *es; | |
1069 mkv_track_t *track; | |
1070 sh_audio_t *sh_a; | |
1071 sh_video_t *sh_v; | |
10149
bb1d5c054148
Delayed the parsing of the cues for the case that the KaxInfos (and therefore the timecode scale) is located after the meta seek stuff.
mosu
parents:
10133
diff
changeset
|
1072 uint64_t seek_pos, current_pos, cues_pos; |
10024 | 1073 int seek_element_is_cue; |
1074 | |
1075 #ifdef USE_ICONV | |
1076 subcp_open(); | |
1077 #endif | |
1078 | |
1079 s = demuxer->stream; | |
1080 stream_seek(s, s->start_pos); | |
1081 memset(signature, 0, 4); | |
1082 stream_read(s, (char *)signature, 4); | |
1083 if ((signature[0] != 0x1A) || (signature[1] != 0x45) || | |
1084 (signature[2] != 0xDF) || (signature[3] != 0xA3)) | |
1085 return 0; | |
1086 stream_seek(s, s->start_pos); | |
1087 | |
1088 try { | |
1089 // structure for storing the demuxer's private data | |
1090 mkv_d = (mkv_demuxer_t *)malloc(sizeof(mkv_demuxer_t)); | |
1091 if (mkv_d == NULL) | |
1092 return 0; | |
1093 memset(mkv_d, 0, sizeof(mkv_demuxer_t)); | |
1094 mkv_d->duration = -1.0; | |
1095 | |
1096 // Create the interface between MPlayer's IO system and | |
1097 // libmatroska's IO system. | |
1098 mkv_d->in = new mpstream_io_callback(demuxer->stream); | |
1099 if (mkv_d->in == NULL) { | |
1100 free_mkv_demuxer(mkv_d); | |
1101 return 0; | |
1102 } | |
1103 mpstream_io_callback &io = *static_cast<mpstream_io_callback *>(mkv_d->in); | |
1104 mkv_d->es = new EbmlStream(io); | |
1105 if (mkv_d->es == NULL) { | |
1106 free_mkv_demuxer(mkv_d); | |
1107 return 0; | |
1108 } | |
1109 es = mkv_d->es; | |
1110 | |
1111 // Find the EbmlHead element. Must be the first one. | |
1112 l0 = es->FindNextID(EbmlHead::ClassInfos, 0xFFFFFFFFL); | |
1113 if (l0 == NULL) { | |
1114 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] no head found\n"); | |
1115 free_mkv_demuxer(mkv_d); | |
1116 return 0; | |
1117 } | |
1118 // Don't verify its data for now. | |
1119 l0->SkipData(static_cast<EbmlStream &>(*es), l0->Generic().Context); | |
1120 delete l0; | |
1121 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Found the head...\n"); | |
1122 | |
1123 // Next element must be a segment | |
1124 l0 = es->FindNextID(KaxSegment::ClassInfos, 0xFFFFFFFFL); | |
1125 if (l0 == NULL) { | |
1126 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] but no segment :(\n"); | |
1127 free_mkv_demuxer(mkv_d); | |
1128 return 0; | |
1129 } | |
1130 if (!(EbmlId(*l0) == KaxSegment::ClassInfos.GlobalId)) { | |
1131 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] but no segment :(\n"); | |
1132 free_mkv_demuxer(mkv_d); | |
1133 return 0; | |
1134 } | |
1135 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] + a segment...\n"); | |
1136 | |
1137 mkv_d->segment = (KaxSegment *)l0; | |
10149
bb1d5c054148
Delayed the parsing of the cues for the case that the KaxInfos (and therefore the timecode scale) is located after the meta seek stuff.
mosu
parents:
10133
diff
changeset
|
1138 mkv_d->tc_scale = MKVD_TIMECODESCALE; |
bb1d5c054148
Delayed the parsing of the cues for the case that the KaxInfos (and therefore the timecode scale) is located after the meta seek stuff.
mosu
parents:
10133
diff
changeset
|
1139 cues_pos = 0; |
10024 | 1140 |
1141 upper_lvl_el = 0; | |
1142 exit_loop = 0; | |
1143 // We've got our segment, so let's find the tracks | |
1144 l1 = es->FindNextElement(l0->Generic().Context, upper_lvl_el, 0xFFFFFFFFL, | |
1145 true, 1); | |
1146 while (l1 != NULL) { | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1147 if ((upper_lvl_el > 0) || exit_loop) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1148 break; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1149 if ((upper_lvl_el < 0) && !fits_parent(l1, l0)) |
10024 | 1150 break; |
1151 | |
1152 if (EbmlId(*l1) == KaxInfo::ClassInfos.GlobalId) { | |
1153 // General info about this Matroska file | |
1154 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] |+ segment information...\n"); | |
1155 | |
1156 l2 = es->FindNextElement(l1->Generic().Context, upper_lvl_el, | |
1157 0xFFFFFFFFL, true, 1); | |
1158 while (l2 != NULL) { | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1159 if ((upper_lvl_el > 0) || exit_loop) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1160 break; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1161 if ((upper_lvl_el < 0) && !fits_parent(l2, l1)) |
10024 | 1162 break; |
1163 | |
1164 if (EbmlId(*l2) == KaxTimecodeScale::ClassInfos.GlobalId) { | |
1165 KaxTimecodeScale &tc_scale = *static_cast<KaxTimecodeScale *>(l2); | |
1166 tc_scale.ReadData(es->I_O()); | |
1167 mkv_d->tc_scale = uint64(tc_scale); | |
1168 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + timecode scale: %llu\n", | |
1169 mkv_d->tc_scale); | |
1170 | |
1171 } else if (EbmlId(*l2) == KaxDuration::ClassInfos.GlobalId) { | |
1172 KaxDuration &duration = *static_cast<KaxDuration *>(l2); | |
1173 duration.ReadData(es->I_O()); | |
1174 mkv_d->duration = float(duration) * mkv_d->tc_scale / 1000000000.0; | |
1175 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + duration: %.3fs\n", | |
1176 mkv_d->duration); | |
1177 | |
1178 } else | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1179 upper_lvl_el = 0; |
10024 | 1180 |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1181 if (upper_lvl_el == 0) { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1182 l2->SkipData(static_cast<EbmlStream &>(*es), |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1183 l2->Generic().Context); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1184 delete l2; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1185 l2 = es->FindNextElement(l1->Generic().Context, upper_lvl_el, |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1186 0xFFFFFFFFL, true, 1); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1187 } |
10024 | 1188 } |
1189 | |
1190 } else if (EbmlId(*l1) == KaxTracks::ClassInfos.GlobalId) { | |
1191 // Yep, we've found our KaxTracks element. Now find all tracks | |
1192 // contained in this segment. | |
1193 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] |+ segment tracks...\n"); | |
1194 | |
1195 l2 = es->FindNextElement(l1->Generic().Context, upper_lvl_el, | |
1196 0xFFFFFFFFL, true, 1); | |
1197 while (l2 != NULL) { | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1198 if ((upper_lvl_el > 0) || exit_loop) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1199 break; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1200 if ((upper_lvl_el < 0) && !fits_parent(l2, l1)) |
10024 | 1201 break; |
1202 | |
1203 if (EbmlId(*l2) == KaxTrackEntry::ClassInfos.GlobalId) { | |
1204 // We actually found a track entry :) We're happy now. | |
1205 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + a track...\n"); | |
1206 | |
1207 track = new_mkv_track(mkv_d); | |
1208 if (track == NULL) | |
1209 return 0; | |
1210 | |
1211 l3 = es->FindNextElement(l2->Generic().Context, upper_lvl_el, | |
1212 0xFFFFFFFFL, true, 1); | |
1213 while (l3 != NULL) { | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1214 if (upper_lvl_el > 0) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1215 break; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1216 if ((upper_lvl_el < 0) && !fits_parent(l3, l2)) |
10024 | 1217 break; |
1218 | |
1219 // Now evaluate the data belonging to this track | |
1220 if (EbmlId(*l3) == KaxTrackNumber::ClassInfos.GlobalId) { | |
1221 KaxTrackNumber &tnum = *static_cast<KaxTrackNumber *>(l3); | |
1222 tnum.ReadData(es->I_O()); | |
1223 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Track number: %u\n", | |
1224 uint32(tnum)); | |
1225 track->tnum = uint32(tnum); | |
1226 if (find_track_by_num(mkv_d, track->tnum, track) != NULL) | |
1227 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] | + WARNING: There's " | |
1228 "more than one track with the number %u.\n", | |
1229 track->tnum); | |
1230 | |
1231 } else if (EbmlId(*l3) == KaxTrackUID::ClassInfos.GlobalId) { | |
1232 KaxTrackUID &tuid = *static_cast<KaxTrackUID *>(l3); | |
1233 tuid.ReadData(es->I_O()); | |
1234 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Track UID: %u\n", | |
1235 uint32(tuid)); | |
1236 | |
10273 | 1237 } else if (EbmlId(*l3) == |
1238 KaxTrackDefaultDuration::ClassInfos.GlobalId) { | |
1239 KaxTrackDefaultDuration &def_duration = | |
1240 *static_cast<KaxTrackDefaultDuration *>(l3); | |
1241 def_duration.ReadData(es->I_O()); | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1242 if (uint64(def_duration) == 0) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1243 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Default duration: 0"); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1244 else { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1245 track->v_frate = 1000000000.0 / (float)uint64(def_duration); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1246 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Default duration: " |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1247 "%.3fms ( = %.3f fps)\n", |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1248 (float)uint64(def_duration) / 1000000.0, |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1249 track->v_frate); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1250 } |
10273 | 1251 |
10024 | 1252 } else if (EbmlId(*l3) == KaxTrackType::ClassInfos.GlobalId) { |
1253 KaxTrackType &ttype = *static_cast<KaxTrackType *>(l3); | |
1254 ttype.ReadData(es->I_O()); | |
1255 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Track type: "); | |
1256 | |
1257 switch (uint8(ttype)) { | |
1258 case track_audio: | |
1259 mp_msg(MSGT_DEMUX, MSGL_V, "Audio\n"); | |
1260 track->type = 'a'; | |
1261 break; | |
1262 case track_video: | |
1263 mp_msg(MSGT_DEMUX, MSGL_V, "Video\n"); | |
1264 track->type = 'v'; | |
1265 break; | |
1266 case track_subtitle: | |
1267 mp_msg(MSGT_DEMUX, MSGL_V, "Subtitle\n"); | |
1268 track->type = 's'; | |
1269 break; | |
1270 default: | |
1271 mp_msg(MSGT_DEMUX, MSGL_V, "unknown\n"); | |
1272 track->type = '?'; | |
1273 break; | |
1274 } | |
1275 | |
1276 } else if (EbmlId(*l3) == KaxTrackAudio::ClassInfos.GlobalId) { | |
1277 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Audio track\n"); | |
1278 l4 = es->FindNextElement(l3->Generic().Context, upper_lvl_el, | |
1279 0xFFFFFFFFL, true, 1); | |
1280 while (l4 != NULL) { | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1281 if (upper_lvl_el > 0) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1282 break; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1283 if ((upper_lvl_el < 0) && !fits_parent(l4, l3)) |
10024 | 1284 break; |
1285 | |
1286 if (EbmlId(*l4) == | |
1287 KaxAudioSamplingFreq::ClassInfos.GlobalId) { | |
1288 KaxAudioSamplingFreq &freq = | |
1289 *static_cast<KaxAudioSamplingFreq*>(l4); | |
1290 freq.ReadData(es->I_O()); | |
1291 track->a_sfreq = float(freq); | |
1292 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Sampling " | |
1293 "frequency: %f\n", track->a_sfreq); | |
1294 | |
1295 } else if (EbmlId(*l4) == | |
1296 KaxAudioChannels::ClassInfos.GlobalId) { | |
1297 KaxAudioChannels &channels = | |
1298 *static_cast<KaxAudioChannels*>(l4); | |
1299 channels.ReadData(es->I_O()); | |
1300 track->a_channels = uint8(channels); | |
1301 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Channels: %u\n", | |
1302 track->a_channels); | |
1303 | |
1304 } else if (EbmlId(*l4) == | |
1305 KaxAudioBitDepth::ClassInfos.GlobalId) { | |
1306 KaxAudioBitDepth &bps = | |
1307 *static_cast<KaxAudioBitDepth*>(l4); | |
1308 bps.ReadData(es->I_O()); | |
1309 track->a_bps = uint8(bps); | |
1310 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Bit depth: %u\n", | |
1311 track->a_bps); | |
1312 | |
1313 } else | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1314 upper_lvl_el = 0; |
10024 | 1315 |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1316 if (upper_lvl_el == 0) { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1317 l4->SkipData(static_cast<EbmlStream &>(*es), |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1318 l4->Generic().Context); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1319 delete l4; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1320 l4 = es->FindNextElement(l3->Generic().Context, |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1321 upper_lvl_el, 0xFFFFFFFFL, true); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1322 } |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1323 |
10024 | 1324 } // while (l4 != NULL) |
1325 | |
1326 } else if (EbmlId(*l3) == KaxTrackVideo::ClassInfos.GlobalId) { | |
1327 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Video track\n"); | |
1328 l4 = es->FindNextElement(l3->Generic().Context, upper_lvl_el, | |
1329 0xFFFFFFFFL, true, 1); | |
1330 while (l4 != NULL) { | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1331 if (upper_lvl_el > 0) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1332 break; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1333 if ((upper_lvl_el < 0) && !fits_parent(l4, l3)) |
10024 | 1334 break; |
1335 | |
1336 if (EbmlId(*l4) == KaxVideoPixelWidth::ClassInfos.GlobalId) { | |
1337 KaxVideoPixelWidth &width = | |
1338 *static_cast<KaxVideoPixelWidth *>(l4); | |
1339 width.ReadData(es->I_O()); | |
1340 track->v_width = uint16(width); | |
1341 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Pixel width: %u\n", | |
1342 track->v_width); | |
1343 | |
1344 } else if (EbmlId(*l4) == | |
1345 KaxVideoPixelHeight::ClassInfos.GlobalId) { | |
1346 KaxVideoPixelHeight &height = | |
1347 *static_cast<KaxVideoPixelHeight *>(l4); | |
1348 height.ReadData(es->I_O()); | |
1349 track->v_height = uint16(height); | |
1350 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Pixel height: " | |
1351 "%u\n", track->v_height); | |
1352 | |
1353 } else if (EbmlId(*l4) == | |
10081
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
1354 KaxVideoDisplayWidth::ClassInfos.GlobalId) { |
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
1355 KaxVideoDisplayWidth &width = |
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
1356 *static_cast<KaxVideoDisplayWidth *>(l4); |
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
1357 width.ReadData(es->I_O()); |
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
1358 track->v_dwidth = uint16(width); |
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
1359 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Display width: " |
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
1360 "%u\n", track->v_dwidth); |
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
1361 |
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
1362 } else if (EbmlId(*l4) == |
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
1363 KaxVideoDisplayHeight::ClassInfos.GlobalId) { |
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
1364 KaxVideoDisplayHeight &height = |
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
1365 *static_cast<KaxVideoDisplayHeight *>(l4); |
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
1366 height.ReadData(es->I_O()); |
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
1367 track->v_dheight = uint16(height); |
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
1368 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Display height: " |
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
1369 "%u\n", track->v_dheight); |
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
1370 |
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
1371 } else if (EbmlId(*l4) == |
10024 | 1372 KaxVideoFrameRate::ClassInfos.GlobalId) { |
10273 | 1373 // For older files. |
10024 | 1374 KaxVideoFrameRate &framerate = |
1375 *static_cast<KaxVideoFrameRate *>(l4); | |
1376 framerate.ReadData(es->I_O()); | |
1377 track->v_frate = float(framerate); | |
1378 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Frame rate: %f\n", | |
1379 float(framerate)); | |
1380 | |
1381 } else | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1382 upper_lvl_el = 0; |
10024 | 1383 |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1384 if (upper_lvl_el == 0) { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1385 l4->SkipData(static_cast<EbmlStream &>(*es), |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1386 l4->Generic().Context); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1387 delete l4; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1388 l4 = es->FindNextElement(l3->Generic().Context, |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1389 upper_lvl_el, 0xFFFFFFFFL, true); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1390 } |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1391 |
10024 | 1392 } // while (l4 != NULL) |
1393 | |
1394 } else if (EbmlId(*l3) == KaxCodecID::ClassInfos.GlobalId) { | |
1395 KaxCodecID &codec_id = *static_cast<KaxCodecID*>(l3); | |
1396 codec_id.ReadData(es->I_O()); | |
10273 | 1397 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Codec ID: %s\n", |
1398 string(codec_id).c_str()); | |
1399 track->codec_id = strdup(string(codec_id).c_str()); | |
10024 | 1400 |
1401 } else if (EbmlId(*l3) == KaxCodecPrivate::ClassInfos.GlobalId) { | |
1402 KaxCodecPrivate &c_priv = *static_cast<KaxCodecPrivate*>(l3); | |
1403 c_priv.ReadData(es->I_O()); | |
1404 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + CodecPrivate, length " | |
1405 "%llu\n", c_priv.GetSize()); | |
1406 track->private_size = c_priv.GetSize(); | |
1407 if (track->private_size > 0) { | |
1408 track->private_data = malloc(track->private_size); | |
1409 if (track->private_data == NULL) | |
1410 return 0; | |
1411 memcpy(track->private_data, c_priv.GetBuffer(), | |
1412 track->private_size); | |
1413 } | |
1414 | |
1415 } else if (EbmlId(*l3) == | |
1416 KaxTrackFlagDefault::ClassInfos.GlobalId) { | |
1417 KaxTrackFlagDefault &f_default = | |
1418 *static_cast<KaxTrackFlagDefault *>(l3); | |
1419 f_default.ReadData(es->I_O()); | |
1420 track->default_track = uint32(f_default); | |
1421 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Default flag: %u\n", | |
1422 track->default_track); | |
1423 | |
10060
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1424 } else if (EbmlId(*l3) == |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1425 KaxTrackLanguage::ClassInfos.GlobalId) { |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1426 KaxTrackLanguage &language = |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1427 *static_cast<KaxTrackLanguage *>(l3); |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1428 language.ReadData(es->I_O()); |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1429 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Language: %s\n", |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1430 string(language).c_str()); |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1431 if (track->language != NULL) |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1432 free(track->language); |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1433 track->language = strdup(string(language).c_str()); |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1434 |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1435 } else |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1436 upper_lvl_el = 0; |
10024 | 1437 |
1438 if (upper_lvl_el > 0) { // we're coming from l4 | |
1439 upper_lvl_el--; | |
1440 delete l3; | |
1441 l3 = l4; | |
1442 if (upper_lvl_el > 0) | |
1443 break; | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1444 } else if (upper_lvl_el == 0) { |
10024 | 1445 l3->SkipData(static_cast<EbmlStream &>(*es), |
1446 l3->Generic().Context); | |
1447 delete l3; | |
1448 l3 = es->FindNextElement(l2->Generic().Context, upper_lvl_el, | |
1449 0xFFFFFFFFL, true, 1); | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1450 } else { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1451 delete l3; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1452 l3 = l4; |
10024 | 1453 } |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1454 |
10024 | 1455 } // while (l3 != NULL) |
1456 | |
1457 } else | |
1458 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + unknown element@2: %s\n", | |
1459 typeid(*l2).name()); | |
1460 if (upper_lvl_el > 0) { // we're coming from l3 | |
1461 upper_lvl_el--; | |
1462 delete l2; | |
1463 l2 = l3; | |
1464 if (upper_lvl_el > 0) | |
1465 break; | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1466 } else if (upper_lvl_el == 0) { |
10024 | 1467 l2->SkipData(static_cast<EbmlStream &>(*es), |
1468 l2->Generic().Context); | |
1469 delete l2; | |
1470 l2 = es->FindNextElement(l1->Generic().Context, upper_lvl_el, | |
1471 0xFFFFFFFFL, true, 1); | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1472 } else { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1473 delete l2; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1474 l2 = l3; |
10024 | 1475 } |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1476 |
10024 | 1477 } // while (l2 != NULL) |
1478 | |
1479 } else if (EbmlId(*l1) == KaxSeekHead::ClassInfos.GlobalId) { | |
1480 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] |+ found seek head\n"); | |
1481 | |
1482 l2 = es->FindNextElement(l1->Generic().Context, upper_lvl_el, | |
1483 0xFFFFFFFFL, true, 1); | |
1484 while (l2 != NULL) { | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1485 if (upper_lvl_el > 0) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1486 break; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1487 if ((upper_lvl_el < 0) && !fits_parent(l2, l1)) |
10024 | 1488 break; |
1489 | |
1490 if (EbmlId(*l2) == KaxSeek::ClassInfos.GlobalId) { | |
1491 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + seek entry\n"); | |
1492 | |
1493 seek_pos = 0; | |
1494 seek_element_is_cue = 0; | |
1495 | |
1496 l3 = es->FindNextElement(l2->Generic().Context, upper_lvl_el, | |
1497 0xFFFFFFFFL, true, 1); | |
1498 while (l3 != NULL) { | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1499 if (upper_lvl_el > 0) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1500 break; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1501 if ((upper_lvl_el < 0) && !fits_parent(l3, l2)) |
10024 | 1502 break; |
1503 | |
1504 if (EbmlId(*l3) == KaxSeekID::ClassInfos.GlobalId) { | |
1505 binary *b; | |
1506 int s; | |
1507 KaxSeekID &seek_id = static_cast<KaxSeekID &>(*l3); | |
1508 seek_id.ReadData(es->I_O()); | |
1509 b = seek_id.GetBuffer(); | |
1510 s = seek_id.GetSize(); | |
1511 EbmlId id(b, s); | |
1512 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + seek ID: "); | |
1513 for (i = 0; i < s; i++) | |
1514 mp_msg(MSGT_DEMUX, MSGL_V, "0x%02x ", | |
1515 ((unsigned char *)b)[i]); | |
1516 mp_msg(MSGT_DEMUX, MSGL_V, "(%s)\n", | |
1517 (id == KaxInfo::ClassInfos.GlobalId) ? | |
1518 "KaxInfo" : | |
1519 (id == KaxCluster::ClassInfos.GlobalId) ? | |
1520 "KaxCluster" : | |
1521 (id == KaxTracks::ClassInfos.GlobalId) ? | |
1522 "KaxTracks" : | |
1523 (id == KaxCues::ClassInfos.GlobalId) ? | |
1524 "KaxCues" : | |
1525 (id == KaxAttachements::ClassInfos.GlobalId) ? | |
1526 "KaxAttachements" : | |
1527 (id == KaxChapters::ClassInfos.GlobalId) ? | |
1528 "KaxChapters" : | |
1529 "unknown"); | |
1530 | |
1531 if (id == KaxCues::ClassInfos.GlobalId) | |
1532 seek_element_is_cue = 1; | |
1533 | |
1534 } else if (EbmlId(*l3) == KaxSeekPosition::ClassInfos.GlobalId) { | |
1535 KaxSeekPosition &kax_seek_pos = | |
1536 static_cast<KaxSeekPosition &>(*l3); | |
1537 kax_seek_pos.ReadData(es->I_O()); | |
1538 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + seek position: %llu\n", | |
1539 uint64(kax_seek_pos)); | |
1540 | |
1541 seek_pos = uint64(kax_seek_pos); | |
1542 | |
1543 } else | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1544 upper_lvl_el = 0; |
10024 | 1545 |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1546 if (upper_lvl_el == 0) { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1547 l3->SkipData(static_cast<EbmlStream &>(*es), |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1548 l3->Generic().Context); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1549 delete l3; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1550 l3 = es->FindNextElement(l2->Generic().Context, upper_lvl_el, |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1551 0xFFFFFFFFL, true, 1); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1552 } |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1553 |
10024 | 1554 } // while (l3 != NULL) |
1555 | |
1556 if (!mkv_d->cues_found && (seek_pos > 0) && | |
10149
bb1d5c054148
Delayed the parsing of the cues for the case that the KaxInfos (and therefore the timecode scale) is located after the meta seek stuff.
mosu
parents:
10133
diff
changeset
|
1557 seek_element_is_cue && (s->end_pos != 0)) |
bb1d5c054148
Delayed the parsing of the cues for the case that the KaxInfos (and therefore the timecode scale) is located after the meta seek stuff.
mosu
parents:
10133
diff
changeset
|
1558 cues_pos = mkv_d->segment->GetGlobalPosition(seek_pos); |
10024 | 1559 |
1560 } else | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1561 upper_lvl_el = 0; |
10024 | 1562 |
1563 if (upper_lvl_el > 0) { // we're coming from l3 | |
1564 upper_lvl_el--; | |
1565 delete l2; | |
1566 l2 = l3; | |
1567 if (upper_lvl_el > 0) | |
1568 break; | |
1569 | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1570 } else if (upper_lvl_el == 0) { |
10024 | 1571 l2->SkipData(static_cast<EbmlStream &>(*es), |
1572 l2->Generic().Context); | |
1573 delete l2; | |
1574 l2 = es->FindNextElement(l1->Generic().Context, upper_lvl_el, | |
1575 0xFFFFFFFFL, true, 1); | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1576 } else { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1577 delete l2; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1578 l2 = l3; |
10024 | 1579 } |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1580 |
10024 | 1581 } // while (l2 != NULL) |
1582 | |
1583 } else if ((EbmlId(*l1) == KaxCues::ClassInfos.GlobalId) && | |
1584 !mkv_d->cues_found) { | |
1585 // If the cues are up front then by all means read them now! | |
1586 current_pos = io.getFilePointer(); | |
1587 io.setFilePointer(l1->GetElementPosition()); | |
1588 mkv_d->cues_found = parse_cues(mkv_d); | |
1589 stream_reset(s); | |
1590 io.setFilePointer(current_pos); | |
1591 | |
1592 } else if (EbmlId(*l1) == KaxCluster::ClassInfos.GlobalId) { | |
1593 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] |+ found cluster, headers are " | |
1594 "parsed completely :)\n"); | |
1595 add_cluster_position(mkv_d, l1->GetElementPosition()); | |
1596 mkv_d->saved_l1 = l1; | |
1597 exit_loop = 1; | |
1598 | |
1599 } else | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1600 upper_lvl_el = 0; |
10024 | 1601 |
1602 if (exit_loop) // we've found the first cluster, so get out | |
1603 break; | |
1604 | |
1605 if (upper_lvl_el > 0) { // we're coming from l2 | |
1606 upper_lvl_el--; | |
1607 delete l1; | |
1608 l1 = l2; | |
1609 if (upper_lvl_el > 0) | |
1610 break; | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1611 } else if (upper_lvl_el == 0) { |
10024 | 1612 l1->SkipData(static_cast<EbmlStream &>(*es), l1->Generic().Context); |
1613 delete l1; | |
1614 l1 = es->FindNextElement(l0->Generic().Context, upper_lvl_el, | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1615 0xFFFFFFFFL, true); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1616 } else { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1617 delete l1; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1618 l1 = l2; |
10024 | 1619 } |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1620 |
10024 | 1621 } // while (l1 != NULL) |
1622 | |
1623 if (!exit_loop) { | |
1624 free_mkv_demuxer(mkv_d); | |
1625 return 0; | |
1626 } | |
1627 | |
10283
21972de8631d
Support for files whose first timecode is not 0 (which is the case for splitted/linked files).
mosu
parents:
10273
diff
changeset
|
1628 // Try to find the very first timecode (cluster timecode). |
21972de8631d
Support for files whose first timecode is not 0 (which is the case for splitted/linked files).
mosu
parents:
10273
diff
changeset
|
1629 l2 = es->FindNextElement(l1->Generic().Context, upper_lvl_el, |
21972de8631d
Support for files whose first timecode is not 0 (which is the case for splitted/linked files).
mosu
parents:
10273
diff
changeset
|
1630 0xFFFFFFFFL, true, 1); |
21972de8631d
Support for files whose first timecode is not 0 (which is the case for splitted/linked files).
mosu
parents:
10273
diff
changeset
|
1631 if ((l2 != NULL) && !upper_lvl_el && |
21972de8631d
Support for files whose first timecode is not 0 (which is the case for splitted/linked files).
mosu
parents:
10273
diff
changeset
|
1632 (EbmlId(*l2) == KaxClusterTimecode::ClassInfos.GlobalId)) { |
21972de8631d
Support for files whose first timecode is not 0 (which is the case for splitted/linked files).
mosu
parents:
10273
diff
changeset
|
1633 KaxClusterTimecode &ctc = *static_cast<KaxClusterTimecode *>(l2); |
21972de8631d
Support for files whose first timecode is not 0 (which is the case for splitted/linked files).
mosu
parents:
10273
diff
changeset
|
1634 ctc.ReadData(es->I_O()); |
21972de8631d
Support for files whose first timecode is not 0 (which is the case for splitted/linked files).
mosu
parents:
10273
diff
changeset
|
1635 mkv_d->first_tc = uint64(ctc) * mkv_d->tc_scale / 1000000; |
21972de8631d
Support for files whose first timecode is not 0 (which is the case for splitted/linked files).
mosu
parents:
10273
diff
changeset
|
1636 delete l2; |
21972de8631d
Support for files whose first timecode is not 0 (which is the case for splitted/linked files).
mosu
parents:
10273
diff
changeset
|
1637 } else |
21972de8631d
Support for files whose first timecode is not 0 (which is the case for splitted/linked files).
mosu
parents:
10273
diff
changeset
|
1638 mkv_d->first_tc = 0; |
21972de8631d
Support for files whose first timecode is not 0 (which is the case for splitted/linked files).
mosu
parents:
10273
diff
changeset
|
1639 stream_seek(s, l1->GetElementPosition()); |
21972de8631d
Support for files whose first timecode is not 0 (which is the case for splitted/linked files).
mosu
parents:
10273
diff
changeset
|
1640 |
10149
bb1d5c054148
Delayed the parsing of the cues for the case that the KaxInfos (and therefore the timecode scale) is located after the meta seek stuff.
mosu
parents:
10133
diff
changeset
|
1641 // If we have found an entry for the cues in the meta seek data but no |
bb1d5c054148
Delayed the parsing of the cues for the case that the KaxInfos (and therefore the timecode scale) is located after the meta seek stuff.
mosu
parents:
10133
diff
changeset
|
1642 // cues at the front of the file then read them now. This way the |
bb1d5c054148
Delayed the parsing of the cues for the case that the KaxInfos (and therefore the timecode scale) is located after the meta seek stuff.
mosu
parents:
10133
diff
changeset
|
1643 // timecode scale will have been initialized correctly. |
bb1d5c054148
Delayed the parsing of the cues for the case that the KaxInfos (and therefore the timecode scale) is located after the meta seek stuff.
mosu
parents:
10133
diff
changeset
|
1644 if (cues_pos && !mkv_d->cues_found) { |
bb1d5c054148
Delayed the parsing of the cues for the case that the KaxInfos (and therefore the timecode scale) is located after the meta seek stuff.
mosu
parents:
10133
diff
changeset
|
1645 current_pos = io.getFilePointer(); |
bb1d5c054148
Delayed the parsing of the cues for the case that the KaxInfos (and therefore the timecode scale) is located after the meta seek stuff.
mosu
parents:
10133
diff
changeset
|
1646 io.setFilePointer(cues_pos); |
bb1d5c054148
Delayed the parsing of the cues for the case that the KaxInfos (and therefore the timecode scale) is located after the meta seek stuff.
mosu
parents:
10133
diff
changeset
|
1647 mkv_d->cues_found = parse_cues(mkv_d); |
bb1d5c054148
Delayed the parsing of the cues for the case that the KaxInfos (and therefore the timecode scale) is located after the meta seek stuff.
mosu
parents:
10133
diff
changeset
|
1648 if (s->eof) |
bb1d5c054148
Delayed the parsing of the cues for the case that the KaxInfos (and therefore the timecode scale) is located after the meta seek stuff.
mosu
parents:
10133
diff
changeset
|
1649 stream_reset(s); |
bb1d5c054148
Delayed the parsing of the cues for the case that the KaxInfos (and therefore the timecode scale) is located after the meta seek stuff.
mosu
parents:
10133
diff
changeset
|
1650 io.setFilePointer(current_pos); |
bb1d5c054148
Delayed the parsing of the cues for the case that the KaxInfos (and therefore the timecode scale) is located after the meta seek stuff.
mosu
parents:
10133
diff
changeset
|
1651 } |
bb1d5c054148
Delayed the parsing of the cues for the case that the KaxInfos (and therefore the timecode scale) is located after the meta seek stuff.
mosu
parents:
10133
diff
changeset
|
1652 |
10024 | 1653 } catch (exception &ex) { |
1654 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] caught exception\n"); | |
1655 return 0; | |
1656 } | |
1657 | |
1658 if (!check_track_information(mkv_d)) { | |
1659 free_mkv_demuxer(mkv_d); | |
1660 return 0; | |
1661 } | |
1662 | |
1663 track = NULL; | |
1664 if (demuxer->video->id == -1) { // Automatically select a video track. | |
1665 // Search for a video track that has the 'default' flag set. | |
1666 for (i = 0; i < mkv_d->num_tracks; i++) | |
1667 if ((mkv_d->tracks[i]->type == 'v') && mkv_d->tracks[i]->ok && | |
1668 mkv_d->tracks[i]->default_track) { | |
1669 track = mkv_d->tracks[i]; | |
1670 break; | |
1671 } | |
1672 | |
1673 if (track == NULL) | |
1674 // No track has the 'default' flag set - let's take the first video | |
1675 // track. | |
1676 for (i = 0; i < mkv_d->num_tracks; i++) | |
1677 if ((mkv_d->tracks[i]->type == 'v') && mkv_d->tracks[i]->ok) { | |
1678 track = mkv_d->tracks[i]; | |
1679 break; | |
1680 } | |
1681 } else if (demuxer->video->id != -2) // -2 = no video at all | |
1682 track = find_track_by_num(mkv_d, demuxer->video->id, NULL); | |
1683 | |
1684 if (track) { | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1685 BITMAPINFOHEADER *bih; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1686 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1687 bih = (BITMAPINFOHEADER *)calloc(1, track->private_size); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1688 if (bih == NULL) { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1689 free_mkv_demuxer(mkv_d); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1690 return 0; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1691 } |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1692 |
10024 | 1693 if (track->ms_compat) { // MS compatibility mode |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1694 BITMAPINFOHEADER *src; |
10133
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1695 src = (BITMAPINFOHEADER *)track->private_data; |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1696 bih->biSize = get_uint32(&src->biSize); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1697 bih->biWidth = get_uint32(&src->biWidth); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1698 bih->biHeight = get_uint32(&src->biHeight); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1699 bih->biPlanes = get_uint16(&src->biPlanes); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1700 bih->biBitCount = get_uint16(&src->biBitCount); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1701 bih->biCompression = get_uint32(&src->biCompression); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1702 bih->biSizeImage = get_uint32(&src->biSizeImage); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1703 bih->biXPelsPerMeter = get_uint32(&src->biXPelsPerMeter); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1704 bih->biYPelsPerMeter = get_uint32(&src->biYPelsPerMeter); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1705 bih->biClrUsed = get_uint32(&src->biClrUsed); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1706 bih->biClrImportant = get_uint32(&src->biClrImportant); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1707 memcpy((char *)bih + sizeof(BITMAPINFOHEADER), |
10133
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1708 (char *)src + sizeof(BITMAPINFOHEADER), |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1709 track->private_size - sizeof(BITMAPINFOHEADER)); |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1710 |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1711 } else { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1712 bih->biSize = sizeof(BITMAPINFOHEADER); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1713 bih->biWidth = track->v_width; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1714 bih->biHeight = track->v_height; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1715 bih->biBitCount = 24; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1716 bih->biSizeImage = bih->biWidth * bih->biHeight * bih->biBitCount / 8; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1717 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1718 if ((track->private_size >= sizeof(real_video_props_t)) && |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1719 (!strcmp(track->codec_id, MKV_V_REALV10) || |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1720 !strcmp(track->codec_id, MKV_V_REALV20) || |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1721 !strcmp(track->codec_id, MKV_V_REALV30) || |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1722 !strcmp(track->codec_id, MKV_V_REALV40))) { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1723 unsigned char *dst, *src; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1724 real_video_props_t *rvp; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1725 uint32_t type2; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1726 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1727 rvp = (real_video_props_t *)track->private_data; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1728 src = (unsigned char *)(rvp + 1); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1729 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1730 bih = (BITMAPINFOHEADER *)realloc(bih, sizeof(BITMAPINFOHEADER) + 12); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1731 bih->biSize += 12; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1732 type2 = get_uint32_be(&rvp->type2); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1733 if ((type2 == 0x10003000) || (type2 == 0x100030001)) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1734 bih->biCompression = mmioFOURCC('R', 'V', '1', '3'); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1735 else |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1736 bih->biCompression = mmioFOURCC('R', 'V', track->codec_id[9], '0'); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1737 dst = (unsigned char *)(bih + 1); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1738 ((unsigned int *)dst)[0] = get_uint32_be(&rvp->type1); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1739 ((unsigned int *)dst)[1] = type2; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1740 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1741 if ((bih->biCompression <= 0x30335652) && |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1742 (type2 >= 0x20200002)) { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1743 // read secondary WxH for the cmsg24[] (see vd_realvid.c) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1744 ((unsigned short *)(bih + 1))[4] = 4 * (unsigned short)src[0]; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1745 ((unsigned short *)(bih + 1))[5] = 4 * (unsigned short)src[1]; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1746 } else |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1747 memset(&dst[8], 0, 4); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1748 track->realmedia = true; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1749 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1750 } else { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1751 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Unknown/unsupported CodecID " |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1752 "(%s) or missing/bad CodecPrivate data (track %u).\n", |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1753 track->codec_id, track->tnum); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1754 demuxer->video->id = -2; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1755 } |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1756 } |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1757 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1758 if (demuxer->video->id != -2) { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1759 mp_msg(MSGT_DEMUX, MSGL_INFO, "[mkv] Will play video track %u\n", |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1760 track->tnum); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1761 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1762 sh_v = new_sh_video(demuxer, track->tnum); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1763 sh_v->bih = bih; |
10024 | 1764 sh_v->format = sh_v->bih->biCompression; |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1765 if (track->v_frate == 0.0) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1766 track->v_frate = 25.0; |
10024 | 1767 sh_v->fps = track->v_frate; |
1768 sh_v->frametime = 1 / track->v_frate; | |
10081
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
1769 sh_v->disp_w = track->v_width; |
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
1770 sh_v->disp_h = track->v_height; |
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
1771 sh_v->aspect = (float)track->v_dwidth / (float)track->v_dheight; |
0181d5fc8474
Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents:
10079
diff
changeset
|
1772 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Aspect: %f\n", sh_v->aspect); |
10024 | 1773 |
1774 demuxer->video->id = track->tnum; | |
1775 demuxer->video->sh = sh_v; | |
1776 sh_v->ds = demuxer->video; | |
1777 | |
1778 mkv_d->video = track; | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1779 } else |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1780 free(bih); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1781 |
10024 | 1782 } else { |
1783 mp_msg(MSGT_DEMUX, MSGL_INFO, "[mkv] No video track found/wanted.\n"); | |
1784 demuxer->video->id = -2; | |
1785 } | |
1786 | |
1787 track = NULL; | |
1788 if (demuxer->audio->id == -1) { // Automatically select an audio track. | |
10167
531b00ad6f2d
Support for selecting the audio track in Matroska files via -alang.
mosu
parents:
10149
diff
changeset
|
1789 // check if the user specified an audio language |
531b00ad6f2d
Support for selecting the audio track in Matroska files via -alang.
mosu
parents:
10149
diff
changeset
|
1790 if (audio_lang != NULL) { |
531b00ad6f2d
Support for selecting the audio track in Matroska files via -alang.
mosu
parents:
10149
diff
changeset
|
1791 track = find_track_by_language(mkv_d, audio_lang, NULL, 'a'); |
531b00ad6f2d
Support for selecting the audio track in Matroska files via -alang.
mosu
parents:
10149
diff
changeset
|
1792 } |
531b00ad6f2d
Support for selecting the audio track in Matroska files via -alang.
mosu
parents:
10149
diff
changeset
|
1793 if (track == NULL) |
531b00ad6f2d
Support for selecting the audio track in Matroska files via -alang.
mosu
parents:
10149
diff
changeset
|
1794 // no audio language specified, or language not found |
531b00ad6f2d
Support for selecting the audio track in Matroska files via -alang.
mosu
parents:
10149
diff
changeset
|
1795 // Search for an audio track that has the 'default' flag set. |
531b00ad6f2d
Support for selecting the audio track in Matroska files via -alang.
mosu
parents:
10149
diff
changeset
|
1796 for (i = 0; i < mkv_d->num_tracks; i++) |
531b00ad6f2d
Support for selecting the audio track in Matroska files via -alang.
mosu
parents:
10149
diff
changeset
|
1797 if ((mkv_d->tracks[i]->type == 'a') && mkv_d->tracks[i]->ok && |
531b00ad6f2d
Support for selecting the audio track in Matroska files via -alang.
mosu
parents:
10149
diff
changeset
|
1798 mkv_d->tracks[i]->default_track) { |
531b00ad6f2d
Support for selecting the audio track in Matroska files via -alang.
mosu
parents:
10149
diff
changeset
|
1799 track = mkv_d->tracks[i]; |
531b00ad6f2d
Support for selecting the audio track in Matroska files via -alang.
mosu
parents:
10149
diff
changeset
|
1800 break; |
531b00ad6f2d
Support for selecting the audio track in Matroska files via -alang.
mosu
parents:
10149
diff
changeset
|
1801 } |
10024 | 1802 |
1803 if (track == NULL) | |
1804 // No track has the 'default' flag set - let's take the first audio | |
1805 // track. | |
1806 for (i = 0; i < mkv_d->num_tracks; i++) | |
1807 if ((mkv_d->tracks[i]->type == 'a') && mkv_d->tracks[i]->ok) { | |
1808 track = mkv_d->tracks[i]; | |
1809 break; | |
1810 } | |
1811 } else if (demuxer->audio->id != -2) // -2 = no audio at all | |
1812 track = find_track_by_num(mkv_d, demuxer->audio->id, NULL); | |
1813 | |
1814 if (track) { | |
1815 mp_msg(MSGT_DEMUX, MSGL_INFO, "[mkv] Will play audio track %u\n", | |
1816 track->tnum); | |
1817 sh_a = new_sh_audio(demuxer, track->tnum); | |
1818 | |
1819 demuxer->audio->id = track->tnum; | |
1820 demuxer->audio->sh = sh_a; | |
1821 sh_a->ds = demuxer->audio; | |
1822 | |
1823 mkv_d->audio = track; | |
1824 | |
1825 if (track->ms_compat) { | |
1826 sh_a->wf = (WAVEFORMATEX *)calloc(1, track->private_size); | |
1827 if (sh_a->wf == NULL) { | |
1828 free_mkv_demuxer(mkv_d); | |
1829 return 0; | |
1830 } | |
1831 memcpy(sh_a->wf, track->private_data, track->private_size); | |
1832 } else { | |
1833 sh_a->wf = (WAVEFORMATEX *)calloc(1, sizeof(WAVEFORMATEX)); | |
1834 if (sh_a->wf == NULL) { | |
1835 free_mkv_demuxer(mkv_d); | |
1836 return 0; | |
1837 } | |
1838 } | |
10125 | 1839 sh_a->format = track->a_formattag; |
1840 sh_a->wf->wFormatTag = track->a_formattag; | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1841 sh_a->channels = track->a_channels; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1842 sh_a->wf->nChannels = track->a_channels; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1843 sh_a->samplerate = (uint32_t)track->a_sfreq; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1844 sh_a->wf->nSamplesPerSec = (uint32_t)track->a_sfreq; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1845 sh_a->samplesize = track->a_bps / 8; |
10024 | 1846 if (!strcmp(track->codec_id, MKV_A_MP3)) { |
1847 sh_a->wf->nAvgBytesPerSec = 16000; | |
1848 sh_a->wf->nBlockAlign = 1152; | |
1849 sh_a->wf->wBitsPerSample = 0; | |
1850 sh_a->samplesize = 0; | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1851 |
10024 | 1852 } else if (!strcmp(track->codec_id, MKV_A_AC3)) { |
1853 sh_a->wf->nAvgBytesPerSec = 16000; | |
1854 sh_a->wf->nBlockAlign = 1536; | |
1855 sh_a->wf->wBitsPerSample = 0; | |
1856 sh_a->samplesize = 0; | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1857 |
10024 | 1858 } else if (!strcmp(track->codec_id, MKV_A_PCM)) { |
1859 sh_a->wf->nAvgBytesPerSec = sh_a->channels * sh_a->samplerate * 2; | |
1860 sh_a->wf->nBlockAlign = sh_a->wf->nAvgBytesPerSec; | |
1861 sh_a->wf->wBitsPerSample = track->a_bps; | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1862 |
10133
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1863 } else if (track->a_formattag == mmioFOURCC('M', 'P', '4', 'A')) { |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1864 int profile, srate_idx; |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1865 |
10125 | 1866 sh_a->wf->nAvgBytesPerSec = 16000; |
1867 sh_a->wf->nBlockAlign = 1024; | |
1868 sh_a->wf->wBitsPerSample = 0; | |
1869 sh_a->samplesize = 0; | |
10133
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1870 |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1871 // Recreate the 'private data' which faad2 uses in its initialization. |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1872 // A_AAC/MPEG2/MAIN |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1873 // 0123456789012345 |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1874 if (!strcmp(&track->codec_id[12], "MAIN")) |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1875 profile = 0; |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1876 else if (!strcmp(&track->codec_id[12], "LC")) |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1877 profile = 1; |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1878 else if (!strcmp(&track->codec_id[12], "SSR")) |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1879 profile = 2; |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1880 else |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1881 profile = 3; |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1882 if (92017 <= sh_a->samplerate) |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1883 srate_idx = 0; |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1884 else if (75132 <= sh_a->samplerate) |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1885 srate_idx = 1; |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1886 else if (55426 <= sh_a->samplerate) |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1887 srate_idx = 2; |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1888 else if (46009 <= sh_a->samplerate) |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1889 srate_idx = 3; |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1890 else if (37566 <= sh_a->samplerate) |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1891 srate_idx = 4; |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1892 else if (27713 <= sh_a->samplerate) |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1893 srate_idx = 5; |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1894 else if (23004 <= sh_a->samplerate) |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1895 srate_idx = 6; |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1896 else if (18783 <= sh_a->samplerate) |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1897 srate_idx = 7; |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1898 else if (13856 <= sh_a->samplerate) |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1899 srate_idx = 8; |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1900 else if (11502 <= sh_a->samplerate) |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1901 srate_idx = 9; |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1902 else if (9391 <= sh_a->samplerate) |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1903 srate_idx = 10; |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1904 else |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1905 srate_idx = 11; |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1906 |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1907 sh_a->codecdata = (unsigned char *)calloc(1, 2); |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1908 sh_a->codecdata_len = 2; |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1909 sh_a->codecdata[0] = ((profile + 1) << 3) | ((srate_idx & 0xe) >> 1); |
d9c9422887ca
Endian fixes and proper support for headerless AAC streams.
mosu
parents:
10125
diff
changeset
|
1910 sh_a->codecdata[1] = ((srate_idx & 0x1) << 7) | (track->a_channels << 3); |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1911 |
10024 | 1912 } else if (!strcmp(track->codec_id, MKV_A_VORBIS)) { |
1913 for (i = 0; i < 3; i++) { | |
1914 dp = new_demux_packet(track->header_sizes[i]); | |
1915 memcpy(dp->buffer, track->headers[i], track->header_sizes[i]); | |
1916 dp->pts = 0; | |
1917 dp->flags = 0; | |
1918 ds_add_packet(demuxer->audio, dp); | |
1919 } | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1920 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1921 } else if ((track->private_size >= sizeof(real_audio_v4_props_t)) && |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1922 !strncmp(track->codec_id, MKV_A_REALATRC, 7)) { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1923 // Common initialization for all RealAudio codecs |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1924 real_audio_v4_props_t *ra4p; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1925 real_audio_v5_props_t *ra5p; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1926 unsigned char *src; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1927 int codecdata_length, version; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1928 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1929 ra4p = (real_audio_v4_props_t *)track->private_data; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1930 ra5p = (real_audio_v5_props_t *)track->private_data; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1931 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1932 sh_a->wf->wBitsPerSample = sh_a->samplesize * 8; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1933 sh_a->wf->nAvgBytesPerSec = 0; // FIXME !? |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1934 sh_a->wf->nBlockAlign = get_uint16_be(&ra4p->frame_size); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1935 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1936 version = get_uint16_be(&ra4p->version1); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1937 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1938 if (version == 4) { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1939 src = (unsigned char *)(ra4p + 1); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1940 src += src[0] + 1; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1941 src += src[0] + 1; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1942 } else |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1943 src = (unsigned char *)(ra5p + 1); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1944 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1945 src += 3; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1946 if (version == 5) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1947 src++; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1948 codecdata_length = get_uint32_be(src); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1949 src += 4; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1950 sh_a->wf->cbSize = 10 + codecdata_length; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1951 sh_a->wf = (WAVEFORMATEX *)realloc(sh_a->wf, sizeof(WAVEFORMATEX) + |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1952 sh_a->wf->cbSize); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1953 ((short *)(sh_a->wf + 1))[0] = get_uint16_be(&ra4p->sub_packet_size); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1954 ((short *)(sh_a->wf + 1))[1] = get_uint16_be(&ra4p->sub_packet_h); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1955 ((short *)(sh_a->wf + 1))[2] = get_uint16_be(&ra4p->flavor); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1956 ((short *)(sh_a->wf + 1))[3] = get_uint32_be(&ra4p->coded_frame_size); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1957 ((short *)(sh_a->wf + 1))[4] = codecdata_length; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1958 memcpy(((char *)(sh_a->wf + 1)) + 10, src, codecdata_length); |
10024 | 1959 } |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
1960 |
10024 | 1961 } else { |
1962 mp_msg(MSGT_DEMUX, MSGL_INFO, "[mkv] No audio track found/wanted.\n"); | |
1963 demuxer->audio->id = -2; | |
1964 } | |
1965 | |
1966 // DO NOT automatically select a subtitle track and behave like DVD | |
1967 // playback: only show subtitles if the user explicitely wants them. | |
10073
4c4c2761643c
Proper key frame reporting. Proper handling of "no subtitles wanted".
mosu
parents:
10060
diff
changeset
|
1968 track = NULL; |
4c4c2761643c
Proper key frame reporting. Proper handling of "no subtitles wanted".
mosu
parents:
10060
diff
changeset
|
1969 if (demuxer->sub->id >= 0) |
4c4c2761643c
Proper key frame reporting. Proper handling of "no subtitles wanted".
mosu
parents:
10060
diff
changeset
|
1970 track = find_track_by_num(mkv_d, demuxer->sub->id, NULL); |
4c4c2761643c
Proper key frame reporting. Proper handling of "no subtitles wanted".
mosu
parents:
10060
diff
changeset
|
1971 else if (dvdsub_lang != NULL) |
10060
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1972 track = find_track_by_language(mkv_d, dvdsub_lang, NULL); |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1973 if (track) { |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1974 if (strcmp(track->codec_id, MKV_S_TEXTASCII) && |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1975 strcmp(track->codec_id, MKV_S_TEXTUTF8)) |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1976 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] Subtitle type '%s' is not " |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1977 "supported. Track will not be displayed.\n", track->codec_id); |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1978 else { |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1979 mp_msg(MSGT_DEMUX, MSGL_INFO, "[mkv] Will display subtitle track %u\n", |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1980 track->tnum); |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1981 mkv_d->subs_track = track; |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1982 if (!mkv_d->subs.text[0]) { |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1983 for (i = 0; i < SUB_MAX_TEXT; i++) |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1984 mkv_d->subs.text[i] = (char *)malloc(256); |
10024 | 1985 |
10060
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1986 if (!strcmp(track->codec_id, MKV_S_TEXTUTF8)) |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1987 sub_utf8 = 1; // Force UTF-8 conversion. |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1988 } else |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1989 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] File does not contain a " |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
1990 "subtitle track with the id %u.\n", demuxer->sub->id); |
10024 | 1991 } |
1992 } | |
1993 | |
1994 if (s->end_pos == 0) | |
1995 demuxer->seekable = 0; | |
1996 else { | |
1997 demuxer->movi_start = s->start_pos; | |
1998 demuxer->movi_end = s->end_pos; | |
1999 demuxer->seekable = 1; | |
2000 } | |
2001 | |
2002 demuxer->priv = mkv_d; | |
2003 | |
2004 return 1; | |
2005 } | |
2006 | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2007 static void handle_realvideo(demuxer_t *demuxer, DataBuffer &data, |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2008 bool keyframe, int &found_data) { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2009 unsigned char *p, *buffer; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2010 dp_hdr_t *hdr; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2011 int chunks, isize; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2012 mkv_demuxer_t *mkv_d; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2013 demux_stream_t *ds; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2014 demux_packet_t *dp; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2015 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2016 mkv_d = (mkv_demuxer_t *)demuxer->priv; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2017 ds = demuxer->video; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2018 p = (unsigned char *)data.Buffer(); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2019 chunks = p[0]; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2020 isize = data.Size() - 1 - (chunks + 1) * 8; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2021 dp = new_demux_packet(sizeof(dp_hdr_t) + isize + 8 * (chunks + 1)); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2022 memcpy(&dp->buffer[sizeof(dp_hdr_t)], &p[1 + (chunks + 1) * 8], isize); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2023 memcpy(&dp->buffer[sizeof(dp_hdr_t) + isize], &p[1], (chunks + 1) * 8); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2024 hdr = (dp_hdr_t *)dp->buffer; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2025 hdr->len = isize; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2026 hdr->chunks = chunks; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2027 hdr->timestamp = (int)(mkv_d->last_pts * 1000); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2028 hdr->chunktab = sizeof(dp_hdr_t) + isize; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2029 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2030 dp->len = sizeof(dp_hdr_t) + isize + 8 * (chunks + 1); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2031 dp->pts = hdr->timestamp; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2032 dp->pos = demuxer->filepos; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2033 dp->flags = keyframe ? 0x10 : 0; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2034 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2035 ds_add_packet(ds, dp); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2036 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2037 found_data++; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2038 } |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2039 |
10024 | 2040 extern "C" int demux_mkv_fill_buffer(demuxer_t *d) { |
2041 demux_packet_t *dp; | |
2042 demux_stream_t *ds; | |
2043 mkv_demuxer_t *mkv_d; | |
2044 int upper_lvl_el, exit_loop, found_data, i, delete_element, elements_found; | |
2045 // Elements for different levels | |
10060
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
2046 EbmlElement *l0 = NULL, *l1 = NULL, *l2 = NULL, *l3 = NULL; |
10024 | 2047 EbmlStream *es; |
2048 KaxBlock *block; | |
2049 int64_t block_duration, block_ref1, block_ref2; | |
2050 | |
2051 mkv_d = (mkv_demuxer_t *)d->priv; | |
2052 es = mkv_d->es; | |
2053 l0 = mkv_d->segment; | |
2054 | |
2055 // End of stream | |
2056 if (mkv_d->saved_l1 == NULL) | |
2057 return 0; | |
2058 | |
2059 exit_loop = 0; | |
2060 upper_lvl_el = 0; | |
2061 l1 = mkv_d->saved_l1; | |
2062 mkv_d->saved_l1 = NULL; | |
2063 found_data = 0; | |
2064 try { | |
2065 // The idea is not to handle a complete KaxCluster with each call to | |
2066 // demux_mkv_fill_buffer because those might be rather big. | |
2067 while (l1 != NULL) { | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2068 if ((upper_lvl_el > 0) || exit_loop) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2069 break; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2070 if ((upper_lvl_el < 0) && !fits_parent(l1, l0)) |
10024 | 2071 break; |
2072 | |
2073 if (EbmlId(*l1) == KaxCluster::ClassInfos.GlobalId) { | |
2074 mkv_d->cluster = (KaxCluster *)l1; | |
2075 if (found_data) { | |
2076 mkv_d->saved_l1 = l1; | |
2077 break; | |
2078 } | |
2079 | |
2080 if (mkv_d->saved_l2 != NULL) { | |
2081 l2 = mkv_d->saved_l2; | |
2082 mkv_d->saved_l2 = NULL; | |
2083 } else | |
2084 l2 = es->FindNextElement(l1->Generic().Context, upper_lvl_el, | |
2085 0xFFFFFFFFL, true, 1); | |
2086 while (l2 != NULL) { | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2087 if (upper_lvl_el > 0) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2088 break; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2089 if ((upper_lvl_el < 0) && !fits_parent(l2, l1)) |
10024 | 2090 break; |
2091 | |
10060
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
2092 // Handle at least one data packets in one call to |
10024 | 2093 // demux_mkv_fill_buffer - but abort if we have found that. |
2094 if (found_data >= 1) { | |
2095 mkv_d->saved_l2 = l2; | |
2096 mkv_d->saved_l1 = l1; | |
2097 exit_loop = 1; | |
2098 break; | |
2099 } | |
2100 | |
2101 if (EbmlId(*l2) == KaxClusterTimecode::ClassInfos.GlobalId) { | |
2102 KaxClusterTimecode &ctc = *static_cast<KaxClusterTimecode *>(l2); | |
2103 ctc.ReadData(es->I_O()); | |
2104 mkv_d->cluster_tc = uint64(ctc); | |
10273 | 2105 #if LIBEBML_VERSION >= 000404 |
2106 mkv_d->cluster->InitTimecode(mkv_d->cluster_tc, mkv_d->tc_scale); | |
2107 #else | |
10024 | 2108 mkv_d->cluster->InitTimecode(mkv_d->cluster_tc); |
10273 | 2109 #endif // LIBEBML_VERSION |
10024 | 2110 |
2111 } else if (EbmlId(*l2) == KaxBlockGroup::ClassInfos.GlobalId) { | |
2112 | |
2113 block = NULL; | |
2114 block_duration = -1; | |
2115 block_ref1 = 0; | |
2116 block_ref2 = 0; | |
2117 elements_found = 0; | |
2118 | |
2119 l3 = es->FindNextElement(l2->Generic().Context, upper_lvl_el, | |
2120 0xFFFFFFFFL, true, 1); | |
2121 while (l3 != NULL) { | |
2122 delete_element = 1; | |
2123 if (upper_lvl_el > 0) | |
2124 break; | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2125 if ((upper_lvl_el < 0) && !fits_parent(l3, l2)) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2126 break; |
10024 | 2127 |
2128 if (EbmlId(*l3) == KaxBlock::ClassInfos.GlobalId) { | |
2129 block = static_cast<KaxBlock *>(l3); | |
10084
04dacb55d55d
timecode scale value must be initialized before the duration is found. API change of libmatroska 0.4.2. Will not work with 0.4.1!
mosu
parents:
10081
diff
changeset
|
2130 block->ReadData(es->I_O()); |
10024 | 2131 block->SetParent(*mkv_d->cluster); |
2132 delete_element = 0; | |
2133 elements_found |= 1; | |
2134 | |
2135 } else if (EbmlId(*l3) == | |
2136 KaxBlockDuration::ClassInfos.GlobalId) { | |
2137 KaxBlockDuration &duration = | |
2138 *static_cast<KaxBlockDuration *>(l3); | |
2139 duration.ReadData(es->I_O()); | |
2140 block_duration = (int64_t)uint64(duration); | |
2141 elements_found |= 2; | |
2142 | |
2143 } else if (EbmlId(*l3) == | |
2144 KaxReferenceBlock::ClassInfos.GlobalId) { | |
2145 KaxReferenceBlock &ref = | |
2146 *static_cast<KaxReferenceBlock *>(l3); | |
2147 ref.ReadData(es->I_O()); | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2148 if ((elements_found & 4) == 0) { |
10024 | 2149 block_ref1 = int64(ref); |
2150 elements_found |= 4; | |
2151 } else { | |
2152 block_ref2 = int64(ref); | |
2153 elements_found |= 8; | |
2154 } | |
2155 | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2156 } else |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2157 upper_lvl_el = 0; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2158 |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2159 if (upper_lvl_el == 0) { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2160 l3->SkipData(static_cast<EbmlStream &>(*es), |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2161 l3->Generic().Context); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2162 if (delete_element) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2163 delete l3; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2164 l3 = es->FindNextElement(l2->Generic().Context, upper_lvl_el, |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2165 0xFFFFFFFFL, true, 1); |
10024 | 2166 } |
2167 | |
2168 } // while (l3 != NULL) | |
2169 | |
2170 if (block != NULL) { | |
2171 // Clear the subtitles if they're obsolete now. | |
2172 if ((mkv_d->clear_subs_at > 0) && | |
2173 (mkv_d->clear_subs_at <= | |
10283
21972de8631d
Support for files whose first timecode is not 0 (which is the case for splitted/linked files).
mosu
parents:
10273
diff
changeset
|
2174 (block->GlobalTimecode() / 1000000 - mkv_d->first_tc))) { |
10024 | 2175 mkv_d->subs.lines = 0; |
2176 vo_sub = &mkv_d->subs; | |
2177 vo_osd_changed(OSDTYPE_SUBTITLE); | |
2178 mkv_d->clear_subs_at = 0; | |
2179 } | |
2180 | |
2181 ds = NULL; | |
2182 if ((mkv_d->video != NULL) && | |
2183 (mkv_d->video->tnum == block->TrackNum())) | |
2184 ds = d->video; | |
2185 else if ((mkv_d->audio != NULL) && | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2186 (mkv_d->audio->tnum == block->TrackNum())) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2187 ds = d->audio; |
10024 | 2188 |
2189 if (!mkv_d->skip_to_keyframe || // Not skipping is ok. | |
2190 (((elements_found & 4) == 0) && // It's a key frame. | |
2191 (ds != NULL) && // Corresponding track found | |
2192 (ds == d->video))) { // track is our video track | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2193 mkv_d->last_pts = (float)(block->GlobalTimecode() / 1000000.0 - |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2194 mkv_d->first_tc) / 1000.0; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2195 d->filepos = mkv_d->in->getFilePointer(); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2196 mkv_d->last_filepos = d->filepos; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2197 |
10283
21972de8631d
Support for files whose first timecode is not 0 (which is the case for splitted/linked files).
mosu
parents:
10273
diff
changeset
|
2198 if ((ds != NULL) && ((block->GlobalTimecode() / 1000000 - |
21972de8631d
Support for files whose first timecode is not 0 (which is the case for splitted/linked files).
mosu
parents:
10273
diff
changeset
|
2199 mkv_d->first_tc) >= |
10060
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
2200 (uint64_t)mkv_d->skip_to_timecode)) { |
10024 | 2201 for (i = 0; i < (int)block->NumberFrames(); i++) { |
2202 DataBuffer &data = block->GetBuffer(i); | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2203 if ((mkv_d->video != NULL) && |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2204 mkv_d->video->realmedia && |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2205 (mkv_d->video->tnum == block->TrackNum())) |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2206 handle_realvideo(d, data, (elements_found & 4) == 0, |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2207 found_data); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2208 else { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2209 dp = new_demux_packet(data.Size()); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2210 memcpy(dp->buffer, data.Buffer(), data.Size()); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2211 dp->pts = mkv_d->last_pts; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2212 // keyframe? |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2213 dp->flags = (elements_found & 4) == 0 ? 1 : 0; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2214 ds_add_packet(ds, dp); |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2215 found_data++; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2216 } |
10024 | 2217 } |
10060
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
2218 mkv_d->skip_to_keyframe = 0; |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
2219 mkv_d->skip_to_timecode = 0; |
10024 | 2220 } else if ((mkv_d->subs_track != NULL) && |
2221 (mkv_d->subs_track->tnum == block->TrackNum())) | |
2222 handle_subtitles(d, block, block_duration); | |
2223 } | |
2224 | |
2225 delete block; | |
2226 } // block != NULL | |
2227 | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2228 } else |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2229 upper_lvl_el = 0; |
10024 | 2230 |
2231 if (upper_lvl_el > 0) { // we're coming from l3 | |
2232 upper_lvl_el--; | |
2233 delete l2; | |
2234 l2 = l3; | |
2235 if (upper_lvl_el > 0) | |
2236 break; | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2237 } else if (upper_lvl_el == 0) { |
10024 | 2238 l2->SkipData(static_cast<EbmlStream &>(*es), |
2239 l2->Generic().Context); | |
2240 delete l2; | |
2241 l2 = es->FindNextElement(l1->Generic().Context, upper_lvl_el, | |
2242 0xFFFFFFFFL, true, 1); | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2243 } else { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2244 delete l2; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2245 l2 = l3; |
10024 | 2246 } |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2247 |
10024 | 2248 } // while (l2 != NULL) |
2249 } else if (EbmlId(*l1) == KaxCues::ClassInfos.GlobalId) | |
2250 return 0; | |
2251 else | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2252 upper_lvl_el = 0; |
10024 | 2253 |
2254 if (exit_loop) | |
2255 break; | |
2256 | |
2257 if (upper_lvl_el > 0) { // we're coming from l2 | |
2258 upper_lvl_el--; | |
2259 delete l1; | |
2260 l1 = l2; | |
2261 if (upper_lvl_el > 0) | |
2262 break; | |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2263 } else if (upper_lvl_el == 0) { |
10024 | 2264 l1->SkipData(static_cast<EbmlStream &>(*es), l1->Generic().Context); |
2265 delete l1; | |
2266 l1 = es->FindNextElement(l0->Generic().Context, upper_lvl_el, | |
2267 0xFFFFFFFFL, true, 1); | |
10060
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
2268 if ((l1 != NULL) && (EbmlId(*l1) == KaxCluster::ClassInfos.GlobalId)) |
10024 | 2269 add_cluster_position(mkv_d, l1->GetElementPosition()); |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2270 } else { |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2271 delete l1; |
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2272 l1 = l2; |
10024 | 2273 } |
10410
c2fc1c310699
Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents:
10283
diff
changeset
|
2274 |
10024 | 2275 } // while (l1 != NULL) |
2276 } catch (exception ex) { | |
2277 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] exception caught\n"); | |
2278 return 0; | |
2279 } | |
2280 | |
2281 if (found_data) | |
2282 return 1; | |
2283 | |
2284 return 0; | |
2285 } | |
2286 | |
2287 extern "C" void resync_audio_stream(sh_audio_t *sh_audio); | |
2288 | |
2289 extern "C" void demux_mkv_seek(demuxer_t *demuxer, float rel_seek_secs, | |
2290 int flags) { | |
2291 int i, k, upper_lvl_el; | |
2292 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *)demuxer->priv; | |
2293 int64_t target_timecode, target_filepos = 0, min_diff, diff, current_pos; | |
2294 int64_t cluster_pos; | |
2295 mkv_track_index_t *index; | |
2296 mkv_index_entry_t *entry; | |
2297 EbmlElement *l1; | |
2298 | |
2299 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] SEEK, relss: %.3f, flags: %d\n", | |
2300 rel_seek_secs, flags); | |
2301 | |
2302 if (!mkv_d->cues_found && !mkv_d->cues_searched) { | |
2303 // We've not found an index so far. So let's skip over all level 1 | |
2304 // elements until we either hit another segment, the end of the file | |
2305 // or - suprise - some cues. | |
2306 current_pos = mkv_d->in->getFilePointer(); | |
2307 | |
2308 // Skip the data but do not delete the element! This is our current | |
2309 // cluster, and we need it later on in demux_mkv_fill_buffer. | |
2310 l1 = mkv_d->saved_l1; | |
2311 l1->SkipData(static_cast<EbmlStream &>(*mkv_d->es), l1->Generic().Context); | |
2312 l1 = mkv_d->es->FindNextElement(mkv_d->segment->Generic().Context, | |
2313 upper_lvl_el, 0xFFFFFFFFL, true, 1); | |
2314 while (l1 != NULL) { | |
2315 if (upper_lvl_el) | |
2316 break; | |
2317 | |
2318 if (EbmlId(*l1) == KaxCues::ClassInfos.GlobalId) { | |
2319 mkv_d->in->setFilePointer(l1->GetElementPosition()); | |
2320 delete l1; | |
2321 mkv_d->cues_found = parse_cues(mkv_d); | |
2322 break; | |
2323 } else { | |
2324 if (EbmlId(*l1) == KaxCluster::ClassInfos.GlobalId) | |
2325 add_cluster_position(mkv_d, l1->GetElementPosition()); | |
2326 l1->SkipData(static_cast<EbmlStream &>(*mkv_d->es), | |
2327 l1->Generic().Context); | |
2328 delete l1; | |
2329 l1 = mkv_d->es->FindNextElement(mkv_d->segment->Generic().Context, | |
2330 upper_lvl_el, 0xFFFFFFFFL, true, 1); | |
2331 } | |
2332 } | |
2333 | |
2334 if (demuxer->stream->eof) | |
2335 stream_reset(demuxer->stream); | |
2336 mkv_d->in->setFilePointer(current_pos); | |
2337 | |
2338 mkv_d->cues_searched = 1; | |
2339 } | |
2340 | |
2341 if (!(flags & 2)) { // Time in secs | |
2342 if (flags & 1) // Absolute seek | |
2343 target_timecode = 0; | |
2344 else // Relative seek | |
2345 target_timecode = (int64_t)(mkv_d->last_pts * 1000.0); | |
2346 target_timecode += (int64_t)(rel_seek_secs * 1000.0); | |
2347 if (target_timecode < 0) | |
2348 target_timecode = 0; | |
2349 | |
2350 min_diff = 0xFFFFFFFL; | |
2351 | |
2352 // Let's find the entry in the index with the smallest difference | |
2353 // to the wanted timecode. | |
2354 entry = NULL; | |
2355 for (i = 0; i < mkv_d->num_indexes; i++) | |
2356 if (mkv_d->index[i].tnum == mkv_d->video->tnum) { | |
2357 index = &mkv_d->index[i]; | |
2358 for (k = 0; k < index->num_entries; k++) { | |
2359 if (!index->entries[k].is_key) | |
2360 continue; | |
2361 diff = target_timecode - (int64_t)index->entries[k].timecode; | |
2362 if (diff < 0) | |
2363 diff *= -1; | |
2364 if (diff < min_diff) { | |
2365 min_diff = diff; | |
2366 entry = & index->entries[k]; | |
2367 } | |
2368 } | |
2369 break; | |
2370 } | |
2371 | |
2372 if (mkv_d->saved_l1 != NULL) | |
2373 delete mkv_d->saved_l1; | |
2374 | |
2375 if (mkv_d->saved_l2 != NULL) { | |
2376 delete mkv_d->saved_l2; | |
2377 mkv_d->saved_l2 = NULL; | |
2378 } | |
2379 | |
2380 if (entry != NULL) { // We've found an entry. | |
2381 mkv_d->in->setFilePointer(entry->filepos); | |
2382 upper_lvl_el = 0; | |
2383 mkv_d->saved_l1 = | |
2384 mkv_d->es->FindNextElement(mkv_d->segment->Generic().Context, | |
2385 upper_lvl_el, 0xFFFFFFFFL, true, 1); | |
2386 } else { // We've not found an entry --> no index? | |
2387 target_filepos = (int64_t)(target_timecode * mkv_d->last_filepos / | |
2388 (mkv_d->last_pts * 1000.0)); | |
2389 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] No index entry found. Calculated " | |
10060
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
2390 "filepos %lld. Old timecode %lld.\n", target_filepos, |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
2391 (int64_t)(mkv_d->last_pts * 1000.0)); |
10024 | 2392 // Let's find the nearest cluster so that libebml does not have to |
2393 // do so much work. | |
2394 cluster_pos = 0; | |
2395 min_diff = 0x0FFFFFFFL; | |
2396 for (i = 0; i < mkv_d->num_cluster_pos; i++) { | |
2397 diff = mkv_d->cluster_positions[i] - target_filepos; | |
2398 if (rel_seek_secs < 0) { | |
2399 if ((diff > 0) && (diff < min_diff)) { | |
2400 cluster_pos = mkv_d->cluster_positions[i]; | |
2401 min_diff = diff; | |
2402 } | |
10099
71d703e35ff3
Removed the abs function as someone reported compilation problems under MacOS.
mosu
parents:
10098
diff
changeset
|
2403 } else if ((diff < 0 ? -1 * diff : diff) < min_diff) { |
10024 | 2404 cluster_pos = mkv_d->cluster_positions[i]; |
10099
71d703e35ff3
Removed the abs function as someone reported compilation problems under MacOS.
mosu
parents:
10098
diff
changeset
|
2405 min_diff = diff < 0 ? -1 * diff : diff; |
10024 | 2406 } |
2407 } | |
10060
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
2408 if (min_diff != 0x0FFFFFFFL) { |
10024 | 2409 target_filepos = cluster_pos; |
10060
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
2410 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] New target_filepos because of " |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
2411 "cluster: %lld.\n", target_filepos); |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
2412 } |
10024 | 2413 if (target_filepos >= demuxer->movi_end) |
2414 return; | |
2415 mkv_d->in->setFilePointer(target_filepos); | |
2416 upper_lvl_el = 0; | |
2417 mkv_d->saved_l1 = | |
2418 mkv_d->es->FindNextElement(mkv_d->segment->Generic().Context, | |
10060
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
2419 upper_lvl_el, 0xFFFFFFFFL, true, 1); |
10024 | 2420 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] seek result: target_timecode %lld, " |
2421 "did not find an entry. Calculated target_filspos: %lld\n", | |
2422 target_timecode, target_filepos); | |
2423 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] seek found %p (%s).\n", | |
2424 mkv_d->saved_l1, mkv_d->saved_l1 == NULL ? "null" : | |
2425 typeid(*mkv_d->saved_l1).name()); | |
2426 } | |
2427 | |
10060
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
2428 if (mkv_d->video != NULL) |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
2429 mkv_d->skip_to_keyframe = 1; |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
2430 if (rel_seek_secs > 0.0) |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
2431 mkv_d->skip_to_timecode = target_timecode; |
10024 | 2432 |
2433 demux_mkv_fill_buffer(demuxer); | |
10060
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
2434 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] New timecode: %lld\n", |
f4d6cf8c6c93
Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents:
10036
diff
changeset
|
2435 (int64_t)(mkv_d->last_pts * 1000.0)); |
10024 | 2436 |
2437 mkv_d->subs.lines = 0; | |
2438 vo_sub = &mkv_d->subs; | |
2439 vo_osd_changed(OSDTYPE_SUBTITLE); | |
2440 mkv_d->clear_subs_at = 0; | |
2441 | |
2442 if(demuxer->audio->sh != NULL) | |
2443 resync_audio_stream((sh_audio_t *)demuxer->audio->sh); | |
2444 | |
2445 } else | |
2446 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] seek unsupported flags\n"); | |
2447 | |
2448 } | |
2449 | |
2450 extern "C" void demux_close_mkv(demuxer_t *demuxer) { | |
2451 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *)demuxer->priv; | |
2452 | |
2453 free_mkv_demuxer(mkv_d); | |
2454 | |
2455 #ifdef USE_ICONV | |
2456 subcp_close(); | |
2457 #endif | |
2458 } | |
2459 | |
2460 extern "C" int demux_mkv_control(demuxer_t *demuxer, int cmd, void *arg) { | |
2461 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *)demuxer->priv; | |
2462 | |
2463 switch (cmd) { | |
2464 case DEMUXER_CTRL_GET_TIME_LENGTH: | |
2465 if (mkv_d->duration == -1.0) | |
2466 return DEMUXER_CTRL_DONTKNOW; | |
2467 | |
2468 *((unsigned long *)arg) = (unsigned long)mkv_d->duration; | |
2469 return DEMUXER_CTRL_OK; | |
2470 | |
2471 case DEMUXER_CTRL_GET_PERCENT_POS: | |
2472 if (mkv_d->duration == -1.0) { | |
2473 if (demuxer->movi_start == demuxer->movi_end) | |
2474 return DEMUXER_CTRL_DONTKNOW; | |
2475 | |
2476 *((int *)arg) = | |
2477 (int)((demuxer->filepos - demuxer->movi_start) / | |
2478 ((demuxer->movi_end - demuxer->movi_start) / 100)); | |
2479 return DEMUXER_CTRL_OK; | |
2480 } | |
2481 | |
2482 *((int *)arg) = (int)(100 * mkv_d->last_pts / mkv_d->duration); | |
2483 return DEMUXER_CTRL_OK; | |
2484 | |
2485 default: | |
2486 return DEMUXER_CTRL_NOTIMPL; | |
2487 } | |
2488 } | |
2489 | |
2490 #endif /* HAVE_MATROSKA */ |