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