annotate libmpdemux/demux_mkv.cpp @ 10060:f4d6cf8c6c93

Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
author mosu
date Sun, 04 May 2003 11:03:02 +0000
parents 1dfe4dab4a42
children 4c4c2761643c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1 extern "C" {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2 #include "config.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
4
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
5 #ifdef HAVE_MATROSKA
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
6
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
7 extern "C" {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
8 #include <stdlib.h>
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
9 #include <stdio.h>
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
10 #include <string.h>
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
11
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
12 #include "../mp_msg.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
13 #include "../help_mp.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
14 #include "stream.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
15 #include "demuxer.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
16 #include "stheader.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
17
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
18 #include "../subreader.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
19 #include "../libvo/sub.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
20 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
21
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
22 #include <iostream>
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
23 #include <cassert>
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
24 #include <typeinfo>
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
25
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
26 #include "EbmlHead.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
27 #include "EbmlSubHead.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
28 #include "EbmlStream.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
29 #include "EbmlContexts.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
30 #include "FileKax.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
31
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
32 #include "KaxAttachements.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
33 #include "KaxBlock.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
34 #include "KaxBlockData.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
35 #include "KaxChapters.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
36 #include "KaxCluster.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
37 #include "KaxClusterData.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
38 #include "KaxContexts.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
39 #include "KaxCues.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
40 #include "KaxCuesData.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
41 #include "KaxInfo.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
42 #include "KaxInfoData.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
43 #include "KaxSeekHead.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
44 #include "KaxSegment.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
45 #include "KaxTracks.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
46 #include "KaxTrackAudio.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
47 #include "KaxTrackVideo.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
48
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
49 #include "StdIOCallback.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
50
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
51 #include "matroska.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
52
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
53 using namespace LIBMATROSKA_NAMESPACE;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
54 using namespace std;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
55
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
56 // 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
57 extern char *dvdsub_lang;
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
58
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
59 // default values for Matroska elements
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
60 #define MKVD_TIMECODESCALE 1000000 // 1000000 = 1ms
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
61
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
62 class mpstream_io_callback: public IOCallback {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
63 private:
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
64 stream_t *s;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
65 public:
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
66 mpstream_io_callback(stream_t *stream);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
67
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
68 virtual uint32 read(void *buffer, size_t size);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
69 virtual void setFilePointer(int64 offset, seek_mode mode = seek_beginning);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
70 virtual size_t write(const void *buffer, size_t size);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
71 virtual uint64 getFilePointer();
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
72 virtual void close();
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
73 };
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
74
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
75 mpstream_io_callback::mpstream_io_callback(stream_t *stream) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
76 s = stream;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
77 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
78
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
79 uint32 mpstream_io_callback::read(void *buffer, size_t size) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
80 uint32_t result;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
81
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
82 result = stream_read(s, (char *)buffer, size);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
83
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
84 return result;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
85 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
86
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
87 void mpstream_io_callback::setFilePointer(int64 offset, seek_mode mode) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
88 int64 new_pos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
89
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
90 if (mode == seek_beginning)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
91 new_pos = offset + s->start_pos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
92 else if (mode == seek_end)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
93 new_pos = s->end_pos - offset;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
94 else
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
95 new_pos = s->pos + offset;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
96
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
97 if (new_pos > s->end_pos) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
98 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] seek warning: new_pos %lld > end_pos "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
99 "%lld\n", new_pos, s->end_pos);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
100 return;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
101 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
102
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
103 stream_seek(s, new_pos);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
104 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
105
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
106 size_t mpstream_io_callback::write(const void */*buffer*/, size_t /*size*/) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
107 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
108 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
109
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
110 uint64 mpstream_io_callback::getFilePointer() {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
111 return s->pos - s->buf_len + s->buf_pos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
112 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
113
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
114 void mpstream_io_callback::close() {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
115 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
116
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
117 typedef struct mkv_index_entry {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
118 uint64_t timecode, filepos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
119 int is_key;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
120 } mkv_index_entry_t;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
121
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
122 typedef struct mkv_track_index {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
123 uint32_t tnum;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
124 int num_entries;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
125 mkv_index_entry_t *entries;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
126 } mkv_track_index_t;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
127
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
128 typedef struct mkv_track {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
129 uint32_t tnum;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
130
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
131 char *codec_id;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
132 int ms_compat;
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
133 char *language;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
134
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
135 char type; // 'v' = video, 'a' = audio, 's' = subs
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
136
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
137 char v_fourcc[5];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
138 uint32_t v_width, v_height;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
139 float v_frate;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
140
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
141 uint16_t a_formattag;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
142 uint32_t a_channels, a_bps;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
143 float a_sfreq;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
144
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
145 int default_track;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
146
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
147 void *private_data;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
148 unsigned int private_size;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
149
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
150 unsigned char *headers[3];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
151 uint32_t header_sizes[3];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
152
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
153 int ok;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
154 } mkv_track_t;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
155
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
156 typedef struct mkv_demuxer {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
157 float duration, last_pts;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
158 uint64_t last_filepos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
159
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
160 mkv_track_t **tracks;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
161 int num_tracks;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
162 mkv_track_t *video, *audio, *subs_track;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
163
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
164 uint64_t tc_scale, cluster_tc;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
165
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
166 mpstream_io_callback *in;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
167
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
168 uint64_t clear_subs_at;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
169
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
170 subtitle subs;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
171
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
172 EbmlStream *es;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
173 EbmlElement *saved_l1, *saved_l2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
174 KaxSegment *segment;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
175 KaxCluster *cluster;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
176
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
177 mkv_track_index_t *index;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
178 int num_indexes, cues_found, cues_searched;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
179 int64_t *cluster_positions;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
180 int num_cluster_pos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
181
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
182 int skip_to_keyframe;
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
183 int64_t skip_to_timecode;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
184 } mkv_demuxer_t;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
185
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
186 static uint16_t get_uint16(const void *buf) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
187 uint16_t ret;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
188 unsigned char *tmp;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
189
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
190 tmp = (unsigned char *) buf;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
191
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
192 ret = tmp[1] & 0xff;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
193 ret = (ret << 8) + (tmp[0] & 0xff);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
194
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
195 return ret;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
196 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
197
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
198 static uint32_t get_uint32(const void *buf) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
199 uint32_t ret;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
200 unsigned char *tmp;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
201
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
202 tmp = (unsigned char *) buf;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
203
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
204 ret = tmp[3] & 0xff;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
205 ret = (ret << 8) + (tmp[2] & 0xff);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
206 ret = (ret << 8) + (tmp[1] & 0xff);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
207 ret = (ret << 8) + (tmp[0] & 0xff);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
208
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
209 return ret;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
210 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
211
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
212 static void handle_subtitles(demuxer_t *d, KaxBlock *block, int64_t duration) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
213 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *)d->priv;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
214 int len, line, state;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
215 char *s1, *s2, *buffer;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
216
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
217 if (duration == -1) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
218 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Warning: No KaxBlockDuration "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
219 "element for subtitle track found.\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
220 return;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
221 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
222
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
223 DataBuffer &data = block->GetBuffer(0);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
224 len = data.Size();
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
225
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
226 buffer = (char *)data.Buffer();
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
227 s1 = buffer;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
228
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
229 while (((*s1 == '\n') || (*s1 == '\r')) &&
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
230 ((unsigned int)(s1 - buffer) <= data.Size()))
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
231 s1++;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
232
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
233 line = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
234 s2 = mkv_d->subs.text[0];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
235 mkv_d->subs.lines = 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
236 state = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
237 while ((unsigned int)(s1 - buffer) != data.Size()) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
238 if ((*s1 == '\n') || (*s1 == '\r')) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
239 if (state == 0) { // normal char --> newline
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
240 if (mkv_d->subs.lines == SUB_MAX_TEXT)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
241 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
242 *s2 = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
243 s2 = mkv_d->subs.text[mkv_d->subs.lines];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
244 mkv_d->subs.lines++;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
245 state = 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
246 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
247 } else if (*s1 == '<') // skip HTML tags
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
248 state = 2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
249 else if (*s1 == '>')
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
250 state = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
251 else if (state != 2) { // normal character
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
252 state = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
253 if ((s2 - mkv_d->subs.text[mkv_d->subs.lines - 1]) < 255) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
254 *s2 = *s1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
255 s2++;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
256 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
257 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
258 s1++;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
259 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
260
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
261 *s2 = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
262
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
263 #ifdef USE_ICONV
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
264 subcp_recode1(&mkv_d->subs);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
265 #endif
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
266
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
267 vo_sub = &mkv_d->subs;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
268 vo_osd_changed(OSDTYPE_SUBTITLE);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
269
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
270 mkv_d->clear_subs_at = block->GlobalTimecode() / 1000000 + duration;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
271 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
272
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
273 static mkv_track_t *new_mkv_track(mkv_demuxer_t *d) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
274 mkv_track_t *t;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
275
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
276 t = (mkv_track_t *)malloc(sizeof(mkv_track_t));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
277 if (t != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
278 memset(t, 0, sizeof(mkv_track_t));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
279 d->tracks = (mkv_track_t **)realloc(d->tracks, (d->num_tracks + 1) *
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
280 sizeof(mkv_track_t *));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
281 if (d->tracks == NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
282 return NULL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
283 d->tracks[d->num_tracks] = t;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
284 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
285
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
286 // 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
287 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
288 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
289 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
290 t->language = strdup("eng");
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
291 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
292
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
293 return t;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
294 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
295
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
296 static mkv_track_t *find_track_by_num(mkv_demuxer_t *d, uint32_t n,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
297 mkv_track_t *c) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
298 int i;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
299
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
300 for (i = 0; i < d->num_tracks; i++)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
301 if ((d->tracks[i] != NULL) && (d->tracks[i]->tnum == n) &&
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
302 (d->tracks[i] != c))
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
303 return d->tracks[i];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
304
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
305 return NULL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
306 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
307
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
308 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
309 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
310 int i;
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
311
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
312 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
313 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
314 (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
315 !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
316 (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
317 return d->tracks[i];
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
318
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
319 return NULL;
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
320 }
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
321
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
322 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
323 int i, track_num;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
324 unsigned char *c;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
325 uint32_t u, offset, length;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
326 mkv_track_t *t;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
327 BITMAPINFOHEADER *bih;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
328 WAVEFORMATEX *wfe;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
329
10028
7ca8b302032f Loop counter was used inside for another loop as well.
mosu
parents: 10024
diff changeset
330 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
331
7ca8b302032f Loop counter was used inside for another loop as well.
mosu
parents: 10024
diff changeset
332 t = d->tracks[track_num];
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
333 switch (t->type) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
334 case 'v': // video track
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
335 if (t->codec_id == NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
336 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
337 if (!strcmp(t->codec_id, MKV_V_MSCOMP)) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
338 if ((t->private_data == NULL) ||
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
339 (t->private_size < sizeof(BITMAPINFOHEADER))) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
340 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] WARNING: CodecID for track "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
341 "%u is '" MKV_V_MSCOMP "', but there was no "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
342 "BITMAPINFOHEADER struct present. Therefore we don't have "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
343 "a FourCC to identify the video codec used.\n", t->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
344 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
345 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
346 t->ms_compat = 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
347
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
348 bih = (BITMAPINFOHEADER *)t->private_data;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
349
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
350 u = get_uint32(&bih->biWidth);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
351 if (t->v_width != u) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
352 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] WARNING: (MS "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
353 "compatibility mode, track %u) "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
354 "Matrosa says video width is %u, but the "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
355 "BITMAPINFOHEADER says %u.\n", t->tnum, t->v_width, u);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
356 if (t->v_width == 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
357 t->v_width = u;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
358 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
359
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
360 u = get_uint32(&bih->biHeight);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
361 if (t->v_height != u) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
362 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] WARNING: (MS compatibility "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
363 "mode, track %u) "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
364 "Matrosa video height is %u, but the BITMAPINFOHEADER "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
365 "says %u.\n", t->tnum, t->v_height, u);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
366 if (t->v_height == 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
367 t->v_height = u;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
368 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
369
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
370 memcpy(t->v_fourcc, &bih->biCompression, 4);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
371
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
372 if (t->v_frate == 0.0) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
373 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] ERROR: (MS compatibility "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
374 "mode, track %u) "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
375 "No VideoFrameRate element was found.\n", t->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
376 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
377 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
378 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
379 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
380 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Native CodecIDs for video "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
381 "tracks are not supported yet (track %u).\n", t->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
382 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
383 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
384
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
385 if (t->v_width == 0) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
386 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] The width for track %u was "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
387 "not set.\n", t->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
388 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
389 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
390 if (t->v_height == 0) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
391 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] The height for track %u was "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
392 "not set.\n", t->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
393 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
394 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
395
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
396 // This track seems to be ok.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
397 t->ok = 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
398
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
399 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
400
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
401 case 'a': // audio track
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
402 if (t->codec_id == NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
403 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
404 if (!strcmp(t->codec_id, MKV_A_ACM)) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
405 if ((t->private_data == NULL) ||
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
406 (t->private_size < sizeof(WAVEFORMATEX))) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
407 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] WARNING: CodecID for track "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
408 "%u is '" MKV_A_ACM "', "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
409 "but there was no WAVEFORMATEX struct present. "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
410 "Therefore we don't have a format ID to identify the audio "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
411 "codec used.\n", t->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
412 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
413 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
414 t->ms_compat = 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
415
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
416 wfe = (WAVEFORMATEX *)t->private_data;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
417 u = get_uint32(&wfe->nSamplesPerSec);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
418 if (((uint32_t)t->a_sfreq) != u) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
419 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] WARNING: (MS compatibility "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
420 "mode for track %u) "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
421 "Matroska says that there are %u samples per second, "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
422 "but WAVEFORMATEX says that there are %u.\n", t->tnum,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
423 (uint32_t)t->a_sfreq, u);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
424 if (t->a_sfreq == 0.0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
425 t->a_sfreq = (float)u;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
426 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
427
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
428 u = get_uint16(&wfe->nChannels);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
429 if (t->a_channels != u) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
430 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] WARNING: (MS "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
431 "compatibility mode for track %u) "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
432 "Matroska says that there are %u channels, but the "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
433 "WAVEFORMATEX says that there are %u.\n", t->tnum,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
434 t->a_channels, u);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
435 if (t->a_channels == 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
436 t->a_channels = u;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
437 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
438
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
439 u = get_uint16(&wfe->wBitsPerSample);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
440 if (t->a_channels != u) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
441 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] WARNING: (MS "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
442 "compatibility mode for track %u) "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
443 "Matroska says that there are %u bits per sample, "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
444 "but the WAVEFORMATEX says that there are %u.\n", t->tnum,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
445 t->a_bps, u);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
446 if (t->a_bps == 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
447 t->a_bps = u;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
448 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
449
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
450 t->a_formattag = get_uint16(&wfe->wFormatTag);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
451 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
452 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
453 if (!strcmp(t->codec_id, MKV_A_MP3))
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
454 t->a_formattag = 0x0055;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
455 else if (!strcmp(t->codec_id, MKV_A_AC3))
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
456 t->a_formattag = 0x2000;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
457 else if (!strcmp(t->codec_id, MKV_A_PCM))
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
458 t->a_formattag = 0x0001;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
459 else if (!strcmp(t->codec_id, MKV_A_VORBIS)) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
460 if (t->private_data == NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
461 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] WARNING: CodecID for "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
462 "track %u is '" MKV_A_VORBIS
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
463 "', but there are no header packets present.", t->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
464 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
465 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
466
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
467 c = (unsigned char *)t->private_data;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
468 if (c[0] != 2) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
469 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Vorbis track does not "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
470 "contain valid headers.\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
471 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
472 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
473
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
474 offset = 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
475 for (i = 0; i < 2; i++) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
476 length = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
477 while ((c[offset] == (unsigned char )255) &&
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
478 (length < t->private_size)) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
479 length += 255;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
480 offset++;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
481 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
482 if (offset >= (t->private_size - 1)) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
483 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Vorbis track does not "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
484 "contain valid headers.\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
485 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
486 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
487 length += c[offset];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
488 offset++;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
489 t->header_sizes[i] = length;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
490 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
491
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
492 t->headers[0] = &c[offset];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
493 t->headers[1] = &c[offset + t->header_sizes[0]];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
494 t->headers[2] = &c[offset + t->header_sizes[0] +
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
495 t->header_sizes[1]];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
496 t->header_sizes[2] = t->private_size - offset;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
497
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
498 t->a_formattag = 0xFFFE;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
499 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
500 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Unknown/unsupported audio "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
501 "codec ID '%s' for track %u.\n", t->codec_id, t->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
502 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
503 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
504 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
505
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
506 if (t->a_sfreq == 0.0) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
507 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] The sampling frequency was not "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
508 "set for track %u.\n", t->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
509 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
510 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
511
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
512 if (t->a_channels == 0) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
513 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] The number of channels was not "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
514 "set for track %u.\n", t->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
515 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
516 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
517
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
518 if (t->a_formattag == 0) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
519 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] The audio format tag was not "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
520 "set for track %u.\n", t->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
521 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
522 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
523
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
524 // This track seems to be ok.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
525 t->ok = 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
526
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
527 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
528
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
529 case 's': // Text subtitles do not need any data
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
530 t->ok = 1; // except the CodecID.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
531 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
532
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
533 default: // unknown track type!? error in demuxer...
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
534 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] Error in demux_mkv.cpp: unknown "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
535 "demuxer type for track %u: '%c'\n", t->tnum, t->type);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
536 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
537 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
538
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
539 if (t->ok)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
540 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Track %u seems to be ok.\n", t->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
541 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
542
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
543 return 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
544 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
545
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
546 static void free_mkv_demuxer(mkv_demuxer_t *d) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
547 int i;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
548
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
549 if (d == NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
550 return;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
551
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
552 for (i = 0; i < d->num_tracks; i++)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
553 if (d->tracks[i] != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
554 if (d->tracks[i]->private_data != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
555 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
556 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
557 free(d->tracks[i]->language);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
558 free(d->tracks[i]);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
559 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
560
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
561 for (i = 0; i < d->num_indexes; i++)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
562 free(d->index[i].entries);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
563 free(d->index);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
564
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
565 if (d->es != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
566 delete d->es;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
567 if (d->saved_l1 != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
568 delete d->saved_l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
569 if (d->in != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
570 delete d->in;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
571 if (d->segment != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
572 delete d->segment;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
573
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
574 free(d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
575 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
576
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
577 static void add_index_entry(mkv_demuxer_t *d, uint32_t tnum, uint64_t filepos,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
578 uint64_t timecode, int is_key) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
579 int i, found;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
580 mkv_index_entry_t *entry;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
581
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
582 for (i = 0, found = 0; i < d->num_indexes; i++)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
583 if (d->index[i].tnum == tnum) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
584 found = 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
585 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
586 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
587
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
588 if (!found) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
589 d->index = (mkv_track_index_t *)realloc(d->index, (d->num_indexes + 1) *
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
590 sizeof(mkv_track_index_t));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
591 if (d->index == NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
592 return;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
593 i = d->num_indexes;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
594 memset(&d->index[i], 0, sizeof(mkv_track_index_t));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
595 d->index[i].tnum = tnum;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
596 d->num_indexes++;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
597 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
598
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
599 d->index[i].entries =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
600 (mkv_index_entry_t *)realloc(d->index[i].entries,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
601 (d->index[i].num_entries + 1) *
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
602 sizeof(mkv_index_entry_t));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
603 if (d->index[i].entries == NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
604 return;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
605 entry = &d->index[i].entries[d->index[i].num_entries];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
606 entry->filepos = filepos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
607 entry->timecode = timecode;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
608 entry->is_key = is_key;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
609 d->index[i].num_entries++;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
610 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
611
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
612 static void add_cluster_position(mkv_demuxer_t *mkv_d, int64_t position) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
613 mkv_d->cluster_positions = (int64_t *)realloc(mkv_d->cluster_positions,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
614 (mkv_d->num_cluster_pos + 1) *
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
615 sizeof(int64_t));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
616 if (mkv_d->cluster_positions != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
617 mkv_d->cluster_positions[mkv_d->num_cluster_pos] = position;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
618 mkv_d->num_cluster_pos++;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
619 } else
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
620 mkv_d->num_cluster_pos = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
621 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
622
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
623 static int parse_cues(mkv_demuxer_t *mkv_d) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
624 EbmlElement *l1 = NULL, *l2 = NULL, *l3 = NULL, *l4 = NULL, *l5 = NULL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
625 EbmlStream *es;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
626 int upper_lvl_el, elements_found, i, k;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
627 uint64_t tc_scale, filepos = 0, timecode = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
628 uint32_t tnum = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
629 mkv_index_entry_t *entry;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
630
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
631 es = mkv_d->es;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
632 tc_scale = mkv_d->tc_scale;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
633 upper_lvl_el = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
634
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
635 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] /---- [ parsing cues ] -----------\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
636
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
637 l1 = es->FindNextElement(mkv_d->segment->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
638 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
639 if (l1 == NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
640 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
641
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
642 if (!(EbmlId(*l1) == KaxCues::ClassInfos.GlobalId)) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
643 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] No KaxCues element found but but %s.\n"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
644 "[mkv] \\---- [ parsing cues ] -----------\n", typeid(*l1).name());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
645
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
646 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
647 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
648
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
649 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] |+ found cues\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
650
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
651 l2 = es->FindNextElement(l1->Generic().Context, upper_lvl_el, 0xFFFFFFFFL,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
652 true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
653 while (l2 != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
654 if (upper_lvl_el != 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
655 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
656
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
657 if (EbmlId(*l2) == KaxCuePoint::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
658 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue point\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
659
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
660 elements_found = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
661
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
662 l3 = es->FindNextElement(l2->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
663 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
664 while (l3 != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
665 if (upper_lvl_el != 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
666 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
667
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
668 if (EbmlId(*l3) == KaxCueTime::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
669 KaxCueTime &cue_time = *static_cast<KaxCueTime *>(l3);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
670 cue_time.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
671 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue time: %.3fs\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
672 ((float)uint64(cue_time)) * tc_scale / 1000000000.0);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
673
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
674 timecode = uint64(cue_time) * tc_scale / 1000000;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
675 elements_found |= 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
676
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
677 } else if (EbmlId(*l3) ==
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
678 KaxCueTrackPositions::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
679 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue track "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
680 "positions\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
681
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
682 l4 = es->FindNextElement(l3->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
683 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
684 while (l4 != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
685 if (upper_lvl_el != 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
686 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
687
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
688 if (EbmlId(*l4) == KaxCueTrack::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
689 KaxCueTrack &cue_track = *static_cast<KaxCueTrack *>(l4);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
690 cue_track.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
691 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue track: "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
692 "%u\n", uint32(cue_track));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
693
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
694 tnum = uint32(cue_track);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
695 elements_found |= 2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
696
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
697 } else if (EbmlId(*l4) ==
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
698 KaxCueClusterPosition::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
699 KaxCueClusterPosition &cue_cp =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
700 *static_cast<KaxCueClusterPosition *>(l4);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
701 cue_cp.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
702 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue cluster "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
703 "position: %llu\n", uint64(cue_cp));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
704
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
705 filepos = mkv_d->segment->GetGlobalPosition(uint64_t(cue_cp));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
706 elements_found |= 4;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
707
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
708 } else if (EbmlId(*l4) ==
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
709 KaxCueBlockNumber::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
710 KaxCueBlockNumber &cue_bn =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
711 *static_cast<KaxCueBlockNumber *>(l4);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
712 cue_bn.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
713 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue block "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
714 "number: %llu\n", uint64(cue_bn));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
715
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
716 } else if (EbmlId(*l4) ==
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
717 KaxCueCodecState::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
718 KaxCueCodecState &cue_cs =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
719 *static_cast<KaxCueCodecState *>(l4);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
720 cue_cs.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
721 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue codec "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
722 "state: %llu\n", uint64(cue_cs));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
723
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
724 } else if (EbmlId(*l4) ==
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
725 KaxCueReference::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
726 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
727 "reference\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
728
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
729 elements_found |= 8;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
730
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
731 l5 = es->FindNextElement(l4->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
732 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
733 while (l5 != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
734 if (upper_lvl_el != 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
735 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
736
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
737 if (EbmlId(*l5) == KaxCueRefTime::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
738 KaxCueRefTime &cue_rt =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
739 *static_cast<KaxCueRefTime *>(l5);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
740 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue ref "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
741 "time: %.3fs\n", ((float)uint64(cue_rt)) * tc_scale /
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
742 1000000000.0);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
743
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
744 } else if (EbmlId(*l5) ==
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
745 KaxCueRefCluster::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
746 KaxCueRefCluster &cue_rc =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
747 *static_cast<KaxCueRefCluster *>(l5);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
748 cue_rc.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
749 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue ref "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
750 "cluster: %llu\n", uint64(cue_rc));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
751
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
752 } else if (EbmlId(*l5) ==
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
753 KaxCueRefNumber::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
754 KaxCueRefNumber &cue_rn =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
755 *static_cast<KaxCueRefNumber *>(l5);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
756 cue_rn.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
757 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue ref "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
758 "number: %llu\n", uint64(cue_rn));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
759
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
760 } else if (EbmlId(*l5) ==
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
761 KaxCueRefCodecState::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
762 KaxCueRefCodecState &cue_rcs =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
763 *static_cast<KaxCueRefCodecState *>(l5);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
764 cue_rcs.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
765 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue ref "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
766 "codec state: %llu\n", uint64(cue_rcs));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
767
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
768 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
769 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + unknown "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
770 "element, level 5: %s\n", typeid(*l5).name());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
771 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
772
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
773 l5->SkipData(static_cast<EbmlStream &>(*es),
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
774 l5->Generic().Context);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
775 delete l5;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
776 l5 = es->FindNextElement(l4->Generic().Context,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
777 upper_lvl_el, 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
778 } // while (l5 != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
779
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
780 } else
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
781 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + unknown element, "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
782 "level 4: %s\n", typeid(*l4).name());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
783
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
784 if (upper_lvl_el > 0) { // we're coming from l5
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
785 upper_lvl_el--;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
786 delete l4;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
787 l4 = l5;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
788 if (upper_lvl_el > 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
789 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
790
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
791 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
792 l4->SkipData(static_cast<EbmlStream &>(*es),
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
793 l4->Generic().Context);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
794 delete l4;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
795 l4 = es->FindNextElement(l3->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
796 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
797 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
798 } // while (l4 != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
799
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
800 } else
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
801 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + unknown element, level 3: "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
802 "%s\n", typeid(*l3).name());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
803
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
804 if (upper_lvl_el > 0) { // we're coming from l4
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
805 upper_lvl_el--;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
806 delete l3;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
807 l3 = l4;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
808 if (upper_lvl_el > 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
809 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
810
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
811 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
812 l3->SkipData(static_cast<EbmlStream &>(*es),
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
813 l3->Generic().Context);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
814 delete l3;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
815 l3 = es->FindNextElement(l2->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
816 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
817 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
818 } // while (l3 != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
819
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
820 // Three elements must have been found in order for this to be a
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
821 // correct entry:
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
822 // 1: cue time (timecode)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
823 // 2: cue track (tnum)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
824 // 4: cue cluster position (filepos)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
825 // If 8 is also set, then there was a reference element, and the
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
826 // current block is not an I frame. If 8 is not set then this is
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
827 // an I frame.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
828 if ((elements_found & 7) == 7)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
829 add_index_entry(mkv_d, tnum, filepos, timecode,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
830 (elements_found & 8) ? 0 : 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
831
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
832 } else
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
833 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + unknown element, level 2: "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
834 "%s\n", typeid(*l2).name());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
835
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
836 if (upper_lvl_el > 0) { // we're coming from l3
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
837 upper_lvl_el--;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
838 delete l2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
839 l2 = l3;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
840 if (upper_lvl_el > 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
841 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
842
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
843 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
844 l2->SkipData(static_cast<EbmlStream &>(*es),
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
845 l2->Generic().Context);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
846 delete l2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
847 l2 = es->FindNextElement(l1->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
848 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
849 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
850 } // while (l2 != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
851
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
852 // Debug: dump the index
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
853 for (i = 0; i < mkv_d->num_indexes; i++) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
854 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] Index for track %u contains %u "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
855 "entries.\n", mkv_d->index[i].tnum, mkv_d->index[i].num_entries);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
856 for (k = 0; k < mkv_d->index[i].num_entries; k++) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
857 entry = &mkv_d->index[i].entries[k];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
858 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] %d: timecode %llu, filepos %llu, "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
859 "is key: %s\n", k, entry->timecode, entry->filepos,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
860 entry->is_key ? "yes" : "no");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
861 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
862 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
863
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
864 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] \\---- [ parsing cues ] -----------\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
865
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
866 return 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
867 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
868
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
869 extern "C" int demux_mkv_open(demuxer_t *demuxer) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
870 unsigned char signature[4];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
871 stream_t *s;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
872 demux_packet_t *dp;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
873 mkv_demuxer_t *mkv_d;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
874 int upper_lvl_el, exit_loop, i;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
875 // Elements for different levels
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
876 EbmlElement *l0 = NULL, *l1 = NULL, *l2 = NULL, *l3 = NULL, *l4 = NULL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
877 EbmlStream *es;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
878 mkv_track_t *track;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
879 sh_audio_t *sh_a;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
880 sh_video_t *sh_v;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
881 uint64_t seek_pos, current_pos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
882 int seek_element_is_cue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
883
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
884 #ifdef USE_ICONV
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
885 subcp_open();
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
886 #endif
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
887
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
888 s = demuxer->stream;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
889 stream_seek(s, s->start_pos);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
890 memset(signature, 0, 4);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
891 stream_read(s, (char *)signature, 4);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
892 if ((signature[0] != 0x1A) || (signature[1] != 0x45) ||
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
893 (signature[2] != 0xDF) || (signature[3] != 0xA3))
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
894 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
895 stream_seek(s, s->start_pos);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
896
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
897 try {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
898 // structure for storing the demuxer's private data
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
899 mkv_d = (mkv_demuxer_t *)malloc(sizeof(mkv_demuxer_t));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
900 if (mkv_d == NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
901 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
902 memset(mkv_d, 0, sizeof(mkv_demuxer_t));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
903 mkv_d->duration = -1.0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
904
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
905 // Create the interface between MPlayer's IO system and
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
906 // libmatroska's IO system.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
907 mkv_d->in = new mpstream_io_callback(demuxer->stream);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
908 if (mkv_d->in == NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
909 free_mkv_demuxer(mkv_d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
910 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
911 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
912 mpstream_io_callback &io = *static_cast<mpstream_io_callback *>(mkv_d->in);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
913 mkv_d->es = new EbmlStream(io);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
914 if (mkv_d->es == NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
915 free_mkv_demuxer(mkv_d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
916 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
917 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
918 es = mkv_d->es;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
919
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
920 // Find the EbmlHead element. Must be the first one.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
921 l0 = es->FindNextID(EbmlHead::ClassInfos, 0xFFFFFFFFL);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
922 if (l0 == NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
923 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] no head found\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
924 free_mkv_demuxer(mkv_d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
925 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
926 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
927 // Don't verify its data for now.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
928 l0->SkipData(static_cast<EbmlStream &>(*es), l0->Generic().Context);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
929 delete l0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
930 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Found the head...\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
931
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
932 // Next element must be a segment
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
933 l0 = es->FindNextID(KaxSegment::ClassInfos, 0xFFFFFFFFL);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
934 if (l0 == NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
935 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] but no segment :(\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
936 free_mkv_demuxer(mkv_d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
937 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
938 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
939 if (!(EbmlId(*l0) == KaxSegment::ClassInfos.GlobalId)) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
940 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] but no segment :(\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
941 free_mkv_demuxer(mkv_d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
942 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
943 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
944 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] + a segment...\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
945
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
946 mkv_d->segment = (KaxSegment *)l0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
947
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
948 upper_lvl_el = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
949 exit_loop = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
950 // We've got our segment, so let's find the tracks
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
951 l1 = es->FindNextElement(l0->Generic().Context, upper_lvl_el, 0xFFFFFFFFL,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
952 true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
953 while (l1 != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
954 if ((upper_lvl_el != 0) || exit_loop)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
955 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
956
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
957 if (EbmlId(*l1) == KaxInfo::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
958 // General info about this Matroska file
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
959 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] |+ segment information...\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
960
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
961 l2 = es->FindNextElement(l1->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
962 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
963 while (l2 != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
964 if ((upper_lvl_el != 0) || exit_loop)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
965 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
966
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
967 if (EbmlId(*l2) == KaxTimecodeScale::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
968 KaxTimecodeScale &tc_scale = *static_cast<KaxTimecodeScale *>(l2);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
969 tc_scale.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
970 mkv_d->tc_scale = uint64(tc_scale);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
971 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + timecode scale: %llu\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
972 mkv_d->tc_scale);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
973
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
974 } else if (EbmlId(*l2) == KaxDuration::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
975 KaxDuration &duration = *static_cast<KaxDuration *>(l2);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
976 duration.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
977 mkv_d->duration = float(duration) * mkv_d->tc_scale / 1000000000.0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
978 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + duration: %.3fs\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
979 mkv_d->duration);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
980
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
981 } else
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
982 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + unknown element@2: %s\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
983 typeid(*l2).name());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
984
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
985 l2->SkipData(static_cast<EbmlStream &>(*es),
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
986 l2->Generic().Context);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
987 delete l2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
988 l2 = es->FindNextElement(l1->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
989 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
990 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
991
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
992 if (mkv_d->tc_scale == 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
993 mkv_d->tc_scale = MKVD_TIMECODESCALE;
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
994
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
995 } else if (EbmlId(*l1) == KaxTracks::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
996 // Yep, we've found our KaxTracks element. Now find all tracks
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
997 // contained in this segment.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
998 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] |+ segment tracks...\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
999
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1000 l2 = es->FindNextElement(l1->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1001 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1002 while (l2 != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1003 if ((upper_lvl_el != 0) || exit_loop)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1004 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1005
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1006 if (EbmlId(*l2) == KaxTrackEntry::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1007 // We actually found a track entry :) We're happy now.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1008 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + a track...\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1009
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1010 track = new_mkv_track(mkv_d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1011 if (track == NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1012 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1013
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1014 l3 = es->FindNextElement(l2->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1015 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1016 while (l3 != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1017 if (upper_lvl_el != 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1018 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1019
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1020 // Now evaluate the data belonging to this track
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1021 if (EbmlId(*l3) == KaxTrackNumber::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1022 KaxTrackNumber &tnum = *static_cast<KaxTrackNumber *>(l3);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1023 tnum.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1024 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Track number: %u\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1025 uint32(tnum));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1026 track->tnum = uint32(tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1027 if (find_track_by_num(mkv_d, track->tnum, track) != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1028 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] | + WARNING: There's "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1029 "more than one track with the number %u.\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1030 track->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1031
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1032 } else if (EbmlId(*l3) == KaxTrackUID::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1033 KaxTrackUID &tuid = *static_cast<KaxTrackUID *>(l3);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1034 tuid.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1035 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Track UID: %u\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1036 uint32(tuid));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1037
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1038 } else if (EbmlId(*l3) == KaxTrackType::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1039 KaxTrackType &ttype = *static_cast<KaxTrackType *>(l3);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1040 ttype.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1041 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Track type: ");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1042
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1043 switch (uint8(ttype)) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1044 case track_audio:
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1045 mp_msg(MSGT_DEMUX, MSGL_V, "Audio\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1046 track->type = 'a';
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1047 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1048 case track_video:
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1049 mp_msg(MSGT_DEMUX, MSGL_V, "Video\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1050 track->type = 'v';
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1051 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1052 case track_subtitle:
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1053 mp_msg(MSGT_DEMUX, MSGL_V, "Subtitle\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1054 track->type = 's';
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1055 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1056 default:
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1057 mp_msg(MSGT_DEMUX, MSGL_V, "unknown\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1058 track->type = '?';
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1059 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1060 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1061
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1062 } else if (EbmlId(*l3) == KaxTrackAudio::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1063 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Audio track\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1064 l4 = es->FindNextElement(l3->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1065 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1066 while (l4 != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1067 if (upper_lvl_el != 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1068 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1069
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1070 if (EbmlId(*l4) ==
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1071 KaxAudioSamplingFreq::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1072 KaxAudioSamplingFreq &freq =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1073 *static_cast<KaxAudioSamplingFreq*>(l4);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1074 freq.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1075 track->a_sfreq = float(freq);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1076 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Sampling "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1077 "frequency: %f\n", track->a_sfreq);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1078
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1079 } else if (EbmlId(*l4) ==
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1080 KaxAudioChannels::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1081 KaxAudioChannels &channels =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1082 *static_cast<KaxAudioChannels*>(l4);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1083 channels.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1084 track->a_channels = uint8(channels);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1085 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Channels: %u\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1086 track->a_channels);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1087
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1088 } else if (EbmlId(*l4) ==
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1089 KaxAudioBitDepth::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1090 KaxAudioBitDepth &bps =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1091 *static_cast<KaxAudioBitDepth*>(l4);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1092 bps.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1093 track->a_bps = uint8(bps);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1094 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Bit depth: %u\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1095 track->a_bps);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1096
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1097 } else
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1098 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + unknown "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1099 "element@4: %s\n", typeid(*l4).name());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1100
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1101 l4->SkipData(static_cast<EbmlStream &>(*es),
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1102 l4->Generic().Context);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1103 delete l4;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1104 l4 = es->FindNextElement(l3->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1105 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1106 } // while (l4 != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1107
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1108 } else if (EbmlId(*l3) == KaxTrackVideo::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1109 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Video track\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1110 l4 = es->FindNextElement(l3->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1111 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1112 while (l4 != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1113 if (upper_lvl_el != 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1114 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1115
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1116 if (EbmlId(*l4) == KaxVideoPixelWidth::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1117 KaxVideoPixelWidth &width =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1118 *static_cast<KaxVideoPixelWidth *>(l4);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1119 width.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1120 track->v_width = uint16(width);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1121 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Pixel width: %u\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1122 track->v_width);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1123
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1124 } else if (EbmlId(*l4) ==
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1125 KaxVideoPixelHeight::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1126 KaxVideoPixelHeight &height =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1127 *static_cast<KaxVideoPixelHeight *>(l4);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1128 height.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1129 track->v_height = uint16(height);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1130 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Pixel height: "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1131 "%u\n", track->v_height);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1132
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1133 } else if (EbmlId(*l4) ==
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1134 KaxVideoFrameRate::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1135 KaxVideoFrameRate &framerate =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1136 *static_cast<KaxVideoFrameRate *>(l4);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1137 framerate.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1138 track->v_frate = float(framerate);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1139 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Frame rate: %f\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1140 float(framerate));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1141
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1142 } else
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1143 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + unknown "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1144 "element@4: %s\n", typeid(*l4).name());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1145
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1146 l4->SkipData(static_cast<EbmlStream &>(*es),
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1147 l4->Generic().Context);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1148 delete l4;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1149 l4 = es->FindNextElement(l3->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1150 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1151 } // while (l4 != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1152
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1153 } else if (EbmlId(*l3) == KaxCodecID::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1154 KaxCodecID &codec_id = *static_cast<KaxCodecID*>(l3);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1155 codec_id.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1156 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Codec ID: %s\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1157 &binary(codec_id));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1158 track->codec_id = strdup((char *)&binary(codec_id));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1159
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1160 } else if (EbmlId(*l3) == KaxCodecPrivate::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1161 KaxCodecPrivate &c_priv = *static_cast<KaxCodecPrivate*>(l3);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1162 c_priv.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1163 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + CodecPrivate, length "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1164 "%llu\n", c_priv.GetSize());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1165 track->private_size = c_priv.GetSize();
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1166 if (track->private_size > 0) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1167 track->private_data = malloc(track->private_size);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1168 if (track->private_data == NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1169 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1170 memcpy(track->private_data, c_priv.GetBuffer(),
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1171 track->private_size);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1172 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1173
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1174 } else if (EbmlId(*l3) ==
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1175 KaxTrackFlagDefault::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1176 KaxTrackFlagDefault &f_default =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1177 *static_cast<KaxTrackFlagDefault *>(l3);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1178 f_default.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1179 track->default_track = uint32(f_default);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1180 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Default flag: %u\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1181 track->default_track);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1182
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1183 } else if (EbmlId(*l3) ==
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1184 KaxTrackLanguage::ClassInfos.GlobalId) {
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1185 KaxTrackLanguage &language =
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1186 *static_cast<KaxTrackLanguage *>(l3);
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1187 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
1188 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
1189 string(language).c_str());
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1190 if (track->language != NULL)
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1191 free(track->language);
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1192 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
1193
10029
2d31643a3c22 Fixes for gcc 3.2
mosu
parents: 10028
diff changeset
1194 } else if ((!(EbmlId(*l3) ==
2d31643a3c22 Fixes for gcc 3.2
mosu
parents: 10028
diff changeset
1195 KaxTrackFlagLacing::ClassInfos.GlobalId)) &&
2d31643a3c22 Fixes for gcc 3.2
mosu
parents: 10028
diff changeset
1196 (!(EbmlId(*l3) ==
2d31643a3c22 Fixes for gcc 3.2
mosu
parents: 10028
diff changeset
1197 KaxTrackMinCache::ClassInfos.GlobalId)) &&
2d31643a3c22 Fixes for gcc 3.2
mosu
parents: 10028
diff changeset
1198 (!(EbmlId(*l3) ==
2d31643a3c22 Fixes for gcc 3.2
mosu
parents: 10028
diff changeset
1199 KaxTrackMaxCache::ClassInfos.GlobalId)))
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1200 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + unknown element@3: "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1201 "%s\n", typeid(*l3).name());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1202
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1203 if (upper_lvl_el > 0) { // we're coming from l4
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1204 upper_lvl_el--;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1205 delete l3;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1206 l3 = l4;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1207 if (upper_lvl_el > 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1208 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1209 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1210 l3->SkipData(static_cast<EbmlStream &>(*es),
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1211 l3->Generic().Context);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1212 delete l3;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1213 l3 = es->FindNextElement(l2->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1214 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1215 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1216 } // while (l3 != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1217
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1218 } else
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1219 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + unknown element@2: %s\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1220 typeid(*l2).name());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1221 if (upper_lvl_el > 0) { // we're coming from l3
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1222 upper_lvl_el--;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1223 delete l2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1224 l2 = l3;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1225 if (upper_lvl_el > 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1226 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1227 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1228 l2->SkipData(static_cast<EbmlStream &>(*es),
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1229 l2->Generic().Context);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1230 delete l2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1231 l2 = es->FindNextElement(l1->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1232 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1233 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1234 } // while (l2 != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1235
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1236 } else if (EbmlId(*l1) == KaxSeekHead::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1237 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] |+ found seek head\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1238
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1239 l2 = es->FindNextElement(l1->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1240 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1241 while (l2 != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1242 if (upper_lvl_el != 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1243 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1244
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1245 if (EbmlId(*l2) == KaxSeek::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1246 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + seek entry\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1247
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1248 seek_pos = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1249 seek_element_is_cue = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1250
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1251 l3 = es->FindNextElement(l2->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1252 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1253 while (l3 != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1254 if (upper_lvl_el != 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1255 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1256
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1257 if (EbmlId(*l3) == KaxSeekID::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1258 binary *b;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1259 int s;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1260 KaxSeekID &seek_id = static_cast<KaxSeekID &>(*l3);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1261 seek_id.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1262 b = seek_id.GetBuffer();
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1263 s = seek_id.GetSize();
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1264 EbmlId id(b, s);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1265 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + seek ID: ");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1266 for (i = 0; i < s; i++)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1267 mp_msg(MSGT_DEMUX, MSGL_V, "0x%02x ",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1268 ((unsigned char *)b)[i]);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1269 mp_msg(MSGT_DEMUX, MSGL_V, "(%s)\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1270 (id == KaxInfo::ClassInfos.GlobalId) ?
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1271 "KaxInfo" :
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1272 (id == KaxCluster::ClassInfos.GlobalId) ?
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1273 "KaxCluster" :
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1274 (id == KaxTracks::ClassInfos.GlobalId) ?
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1275 "KaxTracks" :
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1276 (id == KaxCues::ClassInfos.GlobalId) ?
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1277 "KaxCues" :
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1278 (id == KaxAttachements::ClassInfos.GlobalId) ?
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1279 "KaxAttachements" :
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1280 (id == KaxChapters::ClassInfos.GlobalId) ?
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1281 "KaxChapters" :
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1282 "unknown");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1283
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1284 if (id == KaxCues::ClassInfos.GlobalId)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1285 seek_element_is_cue = 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1286
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1287 } else if (EbmlId(*l3) == KaxSeekPosition::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1288 KaxSeekPosition &kax_seek_pos =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1289 static_cast<KaxSeekPosition &>(*l3);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1290 kax_seek_pos.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1291 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + seek position: %llu\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1292 uint64(kax_seek_pos));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1293
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1294 seek_pos = uint64(kax_seek_pos);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1295
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1296 } else
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1297 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + unknown element, "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1298 "level 3: %s\n", typeid(*l3).name());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1299
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1300 l3->SkipData(static_cast<EbmlStream &>(*es),
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1301 l3->Generic().Context);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1302 delete l3;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1303 l3 = es->FindNextElement(l2->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1304 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1305 } // while (l3 != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1306
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1307 if (!mkv_d->cues_found && (seek_pos > 0) &&
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1308 seek_element_is_cue && (s->end_pos != 0)) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1309 current_pos = io.getFilePointer();
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1310 io.setFilePointer(mkv_d->segment->GetGlobalPosition(seek_pos));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1311 mkv_d->cues_found = parse_cues(mkv_d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1312 if (s->eof)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1313 stream_reset(s);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1314 io.setFilePointer(current_pos);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1315 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1316
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1317 } else
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1318 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + unknown element, level 2: "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1319 "%s\n", typeid(*l2).name());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1320
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1321 if (upper_lvl_el > 0) { // we're coming from l3
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1322 upper_lvl_el--;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1323 delete l2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1324 l2 = l3;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1325 if (upper_lvl_el > 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1326 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1327
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1328 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1329 l2->SkipData(static_cast<EbmlStream &>(*es),
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1330 l2->Generic().Context);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1331 delete l2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1332 l2 = es->FindNextElement(l1->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1333 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1334 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1335 } // while (l2 != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1336
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1337 } else if ((EbmlId(*l1) == KaxCues::ClassInfos.GlobalId) &&
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1338 !mkv_d->cues_found) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1339 // If the cues are up front then by all means read them now!
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1340 current_pos = io.getFilePointer();
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1341 io.setFilePointer(l1->GetElementPosition());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1342 mkv_d->cues_found = parse_cues(mkv_d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1343 stream_reset(s);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1344 io.setFilePointer(current_pos);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1345
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1346 } else if (EbmlId(*l1) == KaxCluster::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1347 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] |+ found cluster, headers are "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1348 "parsed completely :)\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1349 add_cluster_position(mkv_d, l1->GetElementPosition());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1350 mkv_d->saved_l1 = l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1351 exit_loop = 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1352
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1353 } else
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1354 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] |+ unknown element@1: %s\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1355 typeid(*l1).name());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1356
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1357 if (exit_loop) // we've found the first cluster, so get out
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1358 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1359
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1360 if (upper_lvl_el > 0) { // we're coming from l2
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1361 upper_lvl_el--;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1362 delete l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1363 l1 = l2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1364 if (upper_lvl_el > 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1365 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1366 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1367 l1->SkipData(static_cast<EbmlStream &>(*es), l1->Generic().Context);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1368 delete l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1369 l1 = es->FindNextElement(l0->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1370 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1371 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1372 } // while (l1 != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1373
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1374 if (!exit_loop) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1375 free_mkv_demuxer(mkv_d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1376 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1377 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1378
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1379 } catch (exception &ex) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1380 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] caught exception\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1381 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1382 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1383
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1384 if (!check_track_information(mkv_d)) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1385 free_mkv_demuxer(mkv_d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1386 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1387 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1388
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1389 track = NULL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1390 if (demuxer->video->id == -1) { // Automatically select a video track.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1391 // Search for a video track that has the 'default' flag set.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1392 for (i = 0; i < mkv_d->num_tracks; i++)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1393 if ((mkv_d->tracks[i]->type == 'v') && mkv_d->tracks[i]->ok &&
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1394 mkv_d->tracks[i]->default_track) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1395 track = mkv_d->tracks[i];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1396 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1397 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1398
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1399 if (track == NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1400 // No track has the 'default' flag set - let's take the first video
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1401 // track.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1402 for (i = 0; i < mkv_d->num_tracks; i++)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1403 if ((mkv_d->tracks[i]->type == 'v') && mkv_d->tracks[i]->ok) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1404 track = mkv_d->tracks[i];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1405 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1406 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1407 } else if (demuxer->video->id != -2) // -2 = no video at all
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1408 track = find_track_by_num(mkv_d, demuxer->video->id, NULL);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1409
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1410 if (track) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1411 if (track->ms_compat) { // MS compatibility mode
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1412 mp_msg(MSGT_DEMUX, MSGL_INFO, "[mkv] Will play video track %u\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1413 track->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1414 sh_v = new_sh_video(demuxer, track->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1415 sh_v->bih = (BITMAPINFOHEADER *)calloc(1, sizeof(BITMAPINFOHEADER));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1416 if (sh_v->bih == NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1417 free_mkv_demuxer(mkv_d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1418 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1419 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1420
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1421 memcpy(sh_v->bih, track->private_data, sizeof(BITMAPINFOHEADER));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1422 sh_v->format = sh_v->bih->biCompression;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1423 sh_v->fps = track->v_frate;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1424 sh_v->frametime = 1 / track->v_frate;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1425 sh_v->disp_w = sh_v->bih->biWidth;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1426 sh_v->disp_h = sh_v->bih->biHeight;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1427
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1428 demuxer->video->id = track->tnum;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1429 demuxer->video->sh = sh_v;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1430 sh_v->ds = demuxer->video;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1431
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1432 mkv_d->video = track;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1433 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1434 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Native CodecIDs not supported at "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1435 "the moment (track %u).\n", track->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1436 demuxer->video->id = -2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1437 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1438 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1439 mp_msg(MSGT_DEMUX, MSGL_INFO, "[mkv] No video track found/wanted.\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1440 demuxer->video->id = -2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1441 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1442
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1443 track = NULL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1444 if (demuxer->audio->id == -1) { // Automatically select an audio track.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1445 // Search for an audio track that has the 'default' flag set.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1446 for (i = 0; i < mkv_d->num_tracks; i++)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1447 if ((mkv_d->tracks[i]->type == 'a') && mkv_d->tracks[i]->ok &&
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1448 mkv_d->tracks[i]->default_track) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1449 track = mkv_d->tracks[i];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1450 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1451 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1452
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1453 if (track == NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1454 // No track has the 'default' flag set - let's take the first audio
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1455 // track.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1456 for (i = 0; i < mkv_d->num_tracks; i++)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1457 if ((mkv_d->tracks[i]->type == 'a') && mkv_d->tracks[i]->ok) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1458 track = mkv_d->tracks[i];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1459 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1460 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1461 } else if (demuxer->audio->id != -2) // -2 = no audio at all
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1462 track = find_track_by_num(mkv_d, demuxer->audio->id, NULL);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1463
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1464 if (track) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1465 mp_msg(MSGT_DEMUX, MSGL_INFO, "[mkv] Will play audio track %u\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1466 track->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1467 sh_a = new_sh_audio(demuxer, track->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1468
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1469 demuxer->audio->id = track->tnum;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1470 demuxer->audio->sh = sh_a;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1471 sh_a->ds = demuxer->audio;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1472
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1473 mkv_d->audio = track;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1474
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1475 if (track->ms_compat) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1476 sh_a->wf = (WAVEFORMATEX *)calloc(1, track->private_size);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1477 if (sh_a->wf == NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1478 free_mkv_demuxer(mkv_d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1479 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1480 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1481 memcpy(sh_a->wf, track->private_data, track->private_size);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1482 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1483 sh_a->wf = (WAVEFORMATEX *)calloc(1, sizeof(WAVEFORMATEX));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1484 if (sh_a->wf == NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1485 free_mkv_demuxer(mkv_d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1486 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1487 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1488 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1489 sh_a->format = sh_a->wf->wFormatTag = track->a_formattag;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1490 sh_a->channels = sh_a->wf->nChannels = track->a_channels;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1491 sh_a->samplerate = sh_a->wf->nSamplesPerSec = (uint32_t)track->a_sfreq;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1492 if (!strcmp(track->codec_id, MKV_A_MP3)) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1493 sh_a->wf->nAvgBytesPerSec = 16000;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1494 sh_a->wf->nBlockAlign = 1152;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1495 sh_a->wf->wBitsPerSample = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1496 sh_a->samplesize = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1497 } else if (!strcmp(track->codec_id, MKV_A_AC3)) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1498 sh_a->wf->nAvgBytesPerSec = 16000;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1499 sh_a->wf->nBlockAlign = 1536;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1500 sh_a->wf->wBitsPerSample = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1501 sh_a->samplesize = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1502 } else if (!strcmp(track->codec_id, MKV_A_PCM)) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1503 sh_a->wf->nAvgBytesPerSec = sh_a->channels * sh_a->samplerate * 2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1504 sh_a->wf->nBlockAlign = sh_a->wf->nAvgBytesPerSec;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1505 sh_a->wf->wBitsPerSample = track->a_bps;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1506 sh_a->samplesize = track->a_bps / 8;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1507 } else if (!strcmp(track->codec_id, MKV_A_VORBIS)) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1508 for (i = 0; i < 3; i++) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1509 dp = new_demux_packet(track->header_sizes[i]);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1510 memcpy(dp->buffer, track->headers[i], track->header_sizes[i]);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1511 dp->pts = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1512 dp->flags = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1513 ds_add_packet(demuxer->audio, dp);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1514 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1515 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1516 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1517 mp_msg(MSGT_DEMUX, MSGL_INFO, "[mkv] No audio track found/wanted.\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1518 demuxer->audio->id = -2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1519 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1520
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1521 // DO NOT automatically select a subtitle track and behave like DVD
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1522 // playback: only show subtitles if the user explicitely wants them.
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1523 if (dvdsub_lang != NULL)
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1524 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
1525 else if (demuxer->sub->id >= 0)
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1526 track = find_track_by_num(mkv_d, demuxer->sub->id, NULL);
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1527 if (track) {
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1528 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
1529 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
1530 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
1531 "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
1532 else {
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1533 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
1534 track->tnum);
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1535 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
1536 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
1537 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
1538 mkv_d->subs.text[i] = (char *)malloc(256);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1539
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1540 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
1541 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
1542 } else
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1543 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
1544 "subtitle track with the id %u.\n", demuxer->sub->id);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1545 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1546 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1547
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1548 if (s->end_pos == 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1549 demuxer->seekable = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1550 else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1551 demuxer->movi_start = s->start_pos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1552 demuxer->movi_end = s->end_pos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1553 demuxer->seekable = 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1554 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1555
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1556 demuxer->priv = mkv_d;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1557
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1558 return 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1559 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1560
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1561 extern "C" int demux_mkv_fill_buffer(demuxer_t *d) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1562 demux_packet_t *dp;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1563 demux_stream_t *ds;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1564 mkv_demuxer_t *mkv_d;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1565 int upper_lvl_el, exit_loop, found_data, i, delete_element, elements_found;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1566 // 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
1567 EbmlElement *l0 = NULL, *l1 = NULL, *l2 = NULL, *l3 = NULL;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1568 EbmlStream *es;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1569 KaxBlock *block;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1570 int64_t block_duration, block_ref1, block_ref2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1571
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1572 mkv_d = (mkv_demuxer_t *)d->priv;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1573 es = mkv_d->es;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1574 l0 = mkv_d->segment;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1575
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1576 // End of stream
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1577 if (mkv_d->saved_l1 == NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1578 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1579
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1580 exit_loop = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1581 upper_lvl_el = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1582 l1 = mkv_d->saved_l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1583 mkv_d->saved_l1 = NULL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1584 found_data = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1585 try {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1586 // The idea is not to handle a complete KaxCluster with each call to
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1587 // demux_mkv_fill_buffer because those might be rather big.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1588 while (l1 != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1589 if ((upper_lvl_el != 0) || exit_loop)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1590 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1591
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1592 if (EbmlId(*l1) == KaxCluster::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1593 mkv_d->cluster = (KaxCluster *)l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1594 if (found_data) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1595 mkv_d->saved_l1 = l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1596 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1597 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1598
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1599 if (mkv_d->saved_l2 != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1600 l2 = mkv_d->saved_l2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1601 mkv_d->saved_l2 = NULL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1602 } else
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1603 l2 = es->FindNextElement(l1->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1604 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1605 while (l2 != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1606 if (upper_lvl_el != 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1607 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1608
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1609 // Handle at least one data packets in one call to
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1610 // demux_mkv_fill_buffer - but abort if we have found that.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1611 if (found_data >= 1) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1612 mkv_d->saved_l2 = l2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1613 mkv_d->saved_l1 = l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1614 exit_loop = 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1615 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1616 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1617
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1618 if (EbmlId(*l2) == KaxClusterTimecode::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1619 KaxClusterTimecode &ctc = *static_cast<KaxClusterTimecode *>(l2);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1620 ctc.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1621 mkv_d->cluster_tc = uint64(ctc);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1622 mkv_d->cluster->InitTimecode(mkv_d->cluster_tc);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1623
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1624 } else if (EbmlId(*l2) == KaxBlockGroup::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1625
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1626 block = NULL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1627 block_duration = -1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1628 block_ref1 = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1629 block_ref2 = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1630 elements_found = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1631
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1632 l3 = es->FindNextElement(l2->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1633 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1634 while (l3 != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1635 delete_element = 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1636 if (upper_lvl_el > 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1637 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1638
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1639 if (EbmlId(*l3) == KaxBlock::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1640 block = static_cast<KaxBlock *>(l3);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1641 block->SetParent(*mkv_d->cluster);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1642 block->ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1643 delete_element = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1644 elements_found |= 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1645
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1646 } else if (EbmlId(*l3) ==
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1647 KaxBlockDuration::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1648 KaxBlockDuration &duration =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1649 *static_cast<KaxBlockDuration *>(l3);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1650 duration.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1651 block_duration = (int64_t)uint64(duration);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1652 elements_found |= 2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1653
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1654 } else if (EbmlId(*l3) ==
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1655 KaxReferenceBlock::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1656 KaxReferenceBlock &ref =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1657 *static_cast<KaxReferenceBlock *>(l3);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1658 ref.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1659 if (block_ref1 == 0) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1660 block_ref1 = int64(ref);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1661 elements_found |= 4;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1662 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1663 block_ref2 = int64(ref);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1664 elements_found |= 8;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1665 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1666
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1667 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1668
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1669 l3->SkipData(static_cast<EbmlStream &>(*es),
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1670 l3->Generic().Context);
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1671 if (delete_element)
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1672 delete l3;
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1673 l3 = es->FindNextElement(l2->Generic().Context, upper_lvl_el,
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1674 0xFFFFFFFFL, true, 1);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1675 } // while (l3 != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1676
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1677 if (block != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1678 // Clear the subtitles if they're obsolete now.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1679 if ((mkv_d->clear_subs_at > 0) &&
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1680 (mkv_d->clear_subs_at <=
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1681 (block->GlobalTimecode() / 1000000))) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1682 mkv_d->subs.lines = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1683 vo_sub = &mkv_d->subs;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1684 vo_osd_changed(OSDTYPE_SUBTITLE);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1685 mkv_d->clear_subs_at = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1686 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1687
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1688 ds = NULL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1689 if ((mkv_d->video != NULL) &&
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1690 (mkv_d->video->tnum == block->TrackNum()))
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1691 ds = d->video;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1692 else if ((mkv_d->audio != NULL) &&
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1693 (mkv_d->audio->tnum == block->TrackNum()))
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1694 ds = d->audio;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1695
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1696 if (!mkv_d->skip_to_keyframe || // Not skipping is ok.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1697 (((elements_found & 4) == 0) && // It's a key frame.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1698 (ds != NULL) && // Corresponding track found
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1699 (ds == d->video))) { // track is our video track
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1700 if ((ds != NULL) && ((block->GlobalTimecode() / 1000000) >=
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1701 (uint64_t)mkv_d->skip_to_timecode)) {
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1702 for (i = 0; i < (int)block->NumberFrames(); i++) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1703 DataBuffer &data = block->GetBuffer(i);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1704 dp = new_demux_packet(data.Size());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1705 memcpy(dp->buffer, data.Buffer(), data.Size());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1706 dp->pts = mkv_d->last_pts;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1707 dp->flags = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1708 ds_add_packet(ds, dp);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1709 found_data++;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1710 }
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1711 mkv_d->skip_to_keyframe = 0;
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1712 mkv_d->skip_to_timecode = 0;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1713 } else if ((mkv_d->subs_track != NULL) &&
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1714 (mkv_d->subs_track->tnum == block->TrackNum()))
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1715 handle_subtitles(d, block, block_duration);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1716
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1717 d->filepos = mkv_d->in->getFilePointer();
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1718 mkv_d->last_pts = (float)block->GlobalTimecode() /
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1719 1000000000.0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1720 mkv_d->last_filepos = d->filepos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1721 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1722
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1723 delete block;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1724 } // block != NULL
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1725
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1726 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1727
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1728 if (upper_lvl_el > 0) { // we're coming from l3
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1729 upper_lvl_el--;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1730 delete l2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1731 l2 = l3;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1732 if (upper_lvl_el > 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1733 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1734 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1735 l2->SkipData(static_cast<EbmlStream &>(*es),
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1736 l2->Generic().Context);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1737 delete l2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1738 l2 = es->FindNextElement(l1->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1739 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1740 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1741 } // while (l2 != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1742 } else if (EbmlId(*l1) == KaxCues::ClassInfos.GlobalId)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1743 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1744 else
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1745 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Unknown element@1: %s (stream "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1746 "position %llu)\n", typeid(*l1).name(),
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1747 l1->GetElementPosition());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1748
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1749 if (exit_loop)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1750 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1751
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1752 if (upper_lvl_el > 0) { // we're coming from l2
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1753 upper_lvl_el--;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1754 delete l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1755 l1 = l2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1756 if (upper_lvl_el > 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1757 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1758 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1759 l1->SkipData(static_cast<EbmlStream &>(*es), l1->Generic().Context);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1760 delete l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1761 l1 = es->FindNextElement(l0->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1762 0xFFFFFFFFL, true, 1);
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1763 if ((l1 != NULL) && (EbmlId(*l1) == KaxCluster::ClassInfos.GlobalId))
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1764 add_cluster_position(mkv_d, l1->GetElementPosition());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1765 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1766 } // while (l1 != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1767 } catch (exception ex) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1768 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] exception caught\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1769 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1770 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1771
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1772 if (found_data)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1773 return 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1774
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1775 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1776 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1777
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1778 extern "C" void resync_audio_stream(sh_audio_t *sh_audio);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1779
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1780 extern "C" void demux_mkv_seek(demuxer_t *demuxer, float rel_seek_secs,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1781 int flags) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1782 int i, k, upper_lvl_el;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1783 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *)demuxer->priv;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1784 int64_t target_timecode, target_filepos = 0, min_diff, diff, current_pos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1785 int64_t cluster_pos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1786 mkv_track_index_t *index;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1787 mkv_index_entry_t *entry;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1788 EbmlElement *l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1789
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1790 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] SEEK, relss: %.3f, flags: %d\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1791 rel_seek_secs, flags);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1792
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1793 if (!mkv_d->cues_found && !mkv_d->cues_searched) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1794 // We've not found an index so far. So let's skip over all level 1
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1795 // elements until we either hit another segment, the end of the file
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1796 // or - suprise - some cues.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1797 current_pos = mkv_d->in->getFilePointer();
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1798
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1799 // Skip the data but do not delete the element! This is our current
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1800 // cluster, and we need it later on in demux_mkv_fill_buffer.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1801 l1 = mkv_d->saved_l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1802 l1->SkipData(static_cast<EbmlStream &>(*mkv_d->es), l1->Generic().Context);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1803 l1 = mkv_d->es->FindNextElement(mkv_d->segment->Generic().Context,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1804 upper_lvl_el, 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1805 while (l1 != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1806 if (upper_lvl_el)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1807 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1808
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1809 if (EbmlId(*l1) == KaxCues::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1810 mkv_d->in->setFilePointer(l1->GetElementPosition());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1811 delete l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1812 mkv_d->cues_found = parse_cues(mkv_d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1813 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1814 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1815 if (EbmlId(*l1) == KaxCluster::ClassInfos.GlobalId)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1816 add_cluster_position(mkv_d, l1->GetElementPosition());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1817 l1->SkipData(static_cast<EbmlStream &>(*mkv_d->es),
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1818 l1->Generic().Context);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1819 delete l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1820 l1 = mkv_d->es->FindNextElement(mkv_d->segment->Generic().Context,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1821 upper_lvl_el, 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1822 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1823 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1824
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1825 if (demuxer->stream->eof)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1826 stream_reset(demuxer->stream);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1827 mkv_d->in->setFilePointer(current_pos);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1828
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1829 mkv_d->cues_searched = 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1830 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1831
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1832 if (!(flags & 2)) { // Time in secs
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1833 if (flags & 1) // Absolute seek
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1834 target_timecode = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1835 else // Relative seek
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1836 target_timecode = (int64_t)(mkv_d->last_pts * 1000.0);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1837 target_timecode += (int64_t)(rel_seek_secs * 1000.0);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1838 if (target_timecode < 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1839 target_timecode = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1840
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1841 min_diff = 0xFFFFFFFL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1842
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1843 // Let's find the entry in the index with the smallest difference
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1844 // to the wanted timecode.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1845 entry = NULL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1846 for (i = 0; i < mkv_d->num_indexes; i++)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1847 if (mkv_d->index[i].tnum == mkv_d->video->tnum) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1848 index = &mkv_d->index[i];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1849 for (k = 0; k < index->num_entries; k++) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1850 if (!index->entries[k].is_key)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1851 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1852 diff = target_timecode - (int64_t)index->entries[k].timecode;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1853 if (diff < 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1854 diff *= -1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1855 if (diff < min_diff) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1856 min_diff = diff;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1857 entry = & index->entries[k];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1858 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1859 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1860 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1861 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1862
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1863 if (mkv_d->saved_l1 != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1864 delete mkv_d->saved_l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1865
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1866 if (mkv_d->saved_l2 != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1867 delete mkv_d->saved_l2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1868 mkv_d->saved_l2 = NULL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1869 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1870
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1871 if (entry != NULL) { // We've found an entry.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1872 mkv_d->in->setFilePointer(entry->filepos);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1873 upper_lvl_el = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1874 mkv_d->saved_l1 =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1875 mkv_d->es->FindNextElement(mkv_d->segment->Generic().Context,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1876 upper_lvl_el, 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1877 } else { // We've not found an entry --> no index?
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1878 target_filepos = (int64_t)(target_timecode * mkv_d->last_filepos /
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1879 (mkv_d->last_pts * 1000.0));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1880 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
1881 "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
1882 (int64_t)(mkv_d->last_pts * 1000.0));
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1883 // Let's find the nearest cluster so that libebml does not have to
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1884 // do so much work.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1885 cluster_pos = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1886 min_diff = 0x0FFFFFFFL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1887 for (i = 0; i < mkv_d->num_cluster_pos; i++) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1888 diff = mkv_d->cluster_positions[i] - target_filepos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1889 if (rel_seek_secs < 0) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1890 if ((diff > 0) && (diff < min_diff)) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1891 cluster_pos = mkv_d->cluster_positions[i];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1892 min_diff = diff;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1893 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1894 } else if (abs(diff) < min_diff) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1895 cluster_pos = mkv_d->cluster_positions[i];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1896 min_diff = abs(diff);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1897 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1898 }
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1899 if (min_diff != 0x0FFFFFFFL) {
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1900 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
1901 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
1902 "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
1903 }
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1904 if (target_filepos >= demuxer->movi_end)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1905 return;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1906 mkv_d->in->setFilePointer(target_filepos);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1907 upper_lvl_el = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1908 mkv_d->saved_l1 =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1909 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
1910 upper_lvl_el, 0xFFFFFFFFL, true, 1);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1911 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] seek result: target_timecode %lld, "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1912 "did not find an entry. Calculated target_filspos: %lld\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1913 target_timecode, target_filepos);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1914 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] seek found %p (%s).\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1915 mkv_d->saved_l1, mkv_d->saved_l1 == NULL ? "null" :
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1916 typeid(*mkv_d->saved_l1).name());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1917 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1918
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1919 if (mkv_d->video != NULL)
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1920 mkv_d->skip_to_keyframe = 1;
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
1921 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
1922 mkv_d->skip_to_timecode = target_timecode;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1923
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1924 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
1925 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
1926 (int64_t)(mkv_d->last_pts * 1000.0));
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1927
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1928 mkv_d->subs.lines = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1929 vo_sub = &mkv_d->subs;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1930 vo_osd_changed(OSDTYPE_SUBTITLE);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1931 mkv_d->clear_subs_at = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1932
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1933 if(demuxer->audio->sh != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1934 resync_audio_stream((sh_audio_t *)demuxer->audio->sh);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1935
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1936 } else
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1937 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] seek unsupported flags\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1938
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1939 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1940
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1941 extern "C" void demux_close_mkv(demuxer_t *demuxer) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1942 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *)demuxer->priv;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1943
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1944 free_mkv_demuxer(mkv_d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1945
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1946 #ifdef USE_ICONV
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1947 subcp_close();
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1948 #endif
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1949 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1950
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1951 extern "C" int demux_mkv_control(demuxer_t *demuxer, int cmd, void *arg) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1952 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *)demuxer->priv;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1953
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1954 switch (cmd) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1955 case DEMUXER_CTRL_GET_TIME_LENGTH:
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1956 if (mkv_d->duration == -1.0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1957 return DEMUXER_CTRL_DONTKNOW;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1958
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1959 *((unsigned long *)arg) = (unsigned long)mkv_d->duration;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1960 return DEMUXER_CTRL_OK;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1961
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1962 case DEMUXER_CTRL_GET_PERCENT_POS:
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1963 if (mkv_d->duration == -1.0) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1964 if (demuxer->movi_start == demuxer->movi_end)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1965 return DEMUXER_CTRL_DONTKNOW;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1966
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1967 *((int *)arg) =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1968 (int)((demuxer->filepos - demuxer->movi_start) /
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1969 ((demuxer->movi_end - demuxer->movi_start) / 100));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1970 return DEMUXER_CTRL_OK;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1971 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1972
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1973 *((int *)arg) = (int)(100 * mkv_d->last_pts / mkv_d->duration);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1974 return DEMUXER_CTRL_OK;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1975
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1976 default:
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1977 return DEMUXER_CTRL_NOTIMPL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1978 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1979 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1980
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1981 #endif /* HAVE_MATROSKA */