annotate libmpdemux/demux_mkv.cpp @ 10638:9d0b8330a683

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