annotate libmpdemux/demux_mkv.cpp @ 10125:252428ac7978

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