annotate libmpdemux/demux_mkv.cpp @ 10685:f54ffeb29447

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