annotate libmpdemux/demux_mkv.cpp @ 10028:7ca8b302032f

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