annotate libmpdemux/demux_mkv.cpp @ 11268:c367751bd7cb

10! someone please tell me how subs ever worked with mkv
author attila
date Sun, 26 Oct 2003 12:28:45 +0000
parents 1c269ab5f3f6
children ec45f2106ec6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10860
472c5531b695 Improved backwards seeking for small seek steps. Patch by matthieu <mat100@ifrance.com>.
mosu
parents: 10845
diff changeset
1 // Matroska demuxer
472c5531b695 Improved backwards seeking for small seek steps. Patch by matthieu <mat100@ifrance.com>.
mosu
parents: 10845
diff changeset
2 // written by Moritz Bunkus <moritz@bunkus.org>
472c5531b695 Improved backwards seeking for small seek steps. Patch by matthieu <mat100@ifrance.com>.
mosu
parents: 10845
diff changeset
3 // License: GPL of course ;)
472c5531b695 Improved backwards seeking for small seek steps. Patch by matthieu <mat100@ifrance.com>.
mosu
parents: 10845
diff changeset
4
472c5531b695 Improved backwards seeking for small seek steps. Patch by matthieu <mat100@ifrance.com>.
mosu
parents: 10845
diff changeset
5 // $Id$
472c5531b695 Improved backwards seeking for small seek steps. Patch by matthieu <mat100@ifrance.com>.
mosu
parents: 10845
diff changeset
6
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
7 extern "C" {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
8 #include "config.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
9 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
10
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
11 #ifdef HAVE_MATROSKA
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
12
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
13 #include <vector>
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
14
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
15 #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
16 #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
17 #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
18 #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
19 #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
20 #include <ebml/StdIOCallback.h>
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
21
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
22 #include <matroska/KaxVersion.h>
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
23
10437
3c7cd3196cf4 Fixed spelling mistakes that were present in libmatroska until now.
mosu
parents: 10434
diff changeset
24 #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
25 #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
26 #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
27 #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
28 #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
29 #include <matroska/KaxClusterData.h>
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
30 #if LIBMATROSKA_VERSION >= 000503
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
31 #include <matroska/KaxContentEncoding.h>
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
32 #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
33 #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
34 #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
35 #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
36 #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
37 #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
38 #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
39 #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
40 #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
41 #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
42 #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
43 #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
44 #include <matroska/FileKax.h>
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
45
11139
970e9c6471f4 Fix for compilation on mingw32/cygwin. Patch by Goodwu <goodwu@21cn.com>.
mosu
parents: 11114
diff changeset
46 extern "C" {
11154
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
47 #include <ctype.h>
11139
970e9c6471f4 Fix for compilation on mingw32/cygwin. Patch by Goodwu <goodwu@21cn.com>.
mosu
parents: 11114
diff changeset
48 #include <stdlib.h>
970e9c6471f4 Fix for compilation on mingw32/cygwin. Patch by Goodwu <goodwu@21cn.com>.
mosu
parents: 11114
diff changeset
49 #include <stdio.h>
970e9c6471f4 Fix for compilation on mingw32/cygwin. Patch by Goodwu <goodwu@21cn.com>.
mosu
parents: 11114
diff changeset
50 #include <string.h>
970e9c6471f4 Fix for compilation on mingw32/cygwin. Patch by Goodwu <goodwu@21cn.com>.
mosu
parents: 11114
diff changeset
51
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
52 #ifdef HAVE_ZLIB
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
53 #include <zlib.h>
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
54 #endif
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
55
11139
970e9c6471f4 Fix for compilation on mingw32/cygwin. Patch by Goodwu <goodwu@21cn.com>.
mosu
parents: 11114
diff changeset
56 #include "../mp_msg.h"
970e9c6471f4 Fix for compilation on mingw32/cygwin. Patch by Goodwu <goodwu@21cn.com>.
mosu
parents: 11114
diff changeset
57 #include "../help_mp.h"
970e9c6471f4 Fix for compilation on mingw32/cygwin. Patch by Goodwu <goodwu@21cn.com>.
mosu
parents: 11114
diff changeset
58 #include "stream.h"
970e9c6471f4 Fix for compilation on mingw32/cygwin. Patch by Goodwu <goodwu@21cn.com>.
mosu
parents: 11114
diff changeset
59 #include "demuxer.h"
970e9c6471f4 Fix for compilation on mingw32/cygwin. Patch by Goodwu <goodwu@21cn.com>.
mosu
parents: 11114
diff changeset
60 #include "stheader.h"
970e9c6471f4 Fix for compilation on mingw32/cygwin. Patch by Goodwu <goodwu@21cn.com>.
mosu
parents: 11114
diff changeset
61
970e9c6471f4 Fix for compilation on mingw32/cygwin. Patch by Goodwu <goodwu@21cn.com>.
mosu
parents: 11114
diff changeset
62 #include "../subreader.h"
970e9c6471f4 Fix for compilation on mingw32/cygwin. Patch by Goodwu <goodwu@21cn.com>.
mosu
parents: 11114
diff changeset
63 #include "../libvo/sub.h"
970e9c6471f4 Fix for compilation on mingw32/cygwin. Patch by Goodwu <goodwu@21cn.com>.
mosu
parents: 11114
diff changeset
64
970e9c6471f4 Fix for compilation on mingw32/cygwin. Patch by Goodwu <goodwu@21cn.com>.
mosu
parents: 11114
diff changeset
65 }
970e9c6471f4 Fix for compilation on mingw32/cygwin. Patch by Goodwu <goodwu@21cn.com>.
mosu
parents: 11114
diff changeset
66
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
67 #include "matroska.h"
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
68
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
69 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
70 using namespace libmatroska;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
71 using namespace std;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
72
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
73 #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
74 #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
75 #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
76
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
77 // 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
78 extern char *dvdsub_lang;
10167
531b00ad6f2d Support for selecting the audio track in Matroska files via -alang.
mosu
parents: 10149
diff changeset
79 extern char *audio_lang;
11260
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
80 // for "-chapter x-y"
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
81 extern int dvd_chapter;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
82 extern int dvd_last_chapter;
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
83
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
84 // default values for Matroska elements
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
85 #define MKVD_TIMECODESCALE 1000000 // 1000000 = 1ms
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
86
11154
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
87 #define MKV_SUBTYPE_TEXT 1
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
88 #define MKV_SUBTYPE_SSA 2
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
89 #define MKV_SUBTYPE_VOBSUB 3
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
90
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
91 #define MKV_SUBCOMPRESSION_NONE 0
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
92 #define MKV_SUBCOMPRESSION_ZLIB 1
10845
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
93
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
94 #define safefree(m) { if (m != NULL) free(m); }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
95 void *safemalloc(int bytes) {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
96 void *dst;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
97
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
98 dst = malloc(bytes);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
99 if (dst == NULL) {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
100 mp_msg(MSGT_DEMUX, MSGL_FATAL, "[mkv] Could not allocate %d bytes of "
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
101 "memory.\n", bytes);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
102 exit(1);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
103 }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
104
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
105 return dst;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
106 }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
107
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
108 void *safememdup(const void *src, int bytes) {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
109 void *dst;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
110
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
111 dst = safemalloc(bytes);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
112 memcpy(dst, src, bytes);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
113
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
114 return dst;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
115 }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
116
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
117 class mpstream_io_callback: public IOCallback {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
118 private:
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
119 stream_t *s;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
120 public:
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
121 mpstream_io_callback(stream_t *stream);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
122
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
123 virtual uint32 read(void *buffer, size_t size);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
124 virtual void setFilePointer(int64 offset, seek_mode mode = seek_beginning);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
125 virtual size_t write(const void *buffer, size_t size);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
126 virtual uint64 getFilePointer();
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
127 virtual void close();
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
128 };
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
129
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
130 mpstream_io_callback::mpstream_io_callback(stream_t *stream) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
131 s = stream;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
132 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
133
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
134 uint32 mpstream_io_callback::read(void *buffer, size_t size) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
135 uint32_t result;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
136
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
137 result = stream_read(s, (char *)buffer, size);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
138
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
139 return result;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
140 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
141
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
142 void mpstream_io_callback::setFilePointer(int64 offset, seek_mode mode) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
143 int64 new_pos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
144
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
145 if (mode == seek_beginning)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
146 new_pos = offset + s->start_pos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
147 else if (mode == seek_end)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
148 new_pos = s->end_pos - offset;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
149 else
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
150 new_pos = s->pos + offset;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
151
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
152 if (new_pos > s->end_pos) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
153 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] seek warning: new_pos %lld > end_pos "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
154 "%lld\n", new_pos, s->end_pos);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
155 return;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
156 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
157
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
158 stream_seek(s, new_pos);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
159 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
160
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
161 size_t mpstream_io_callback::write(const void */*buffer*/, size_t /*size*/) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
162 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
163 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
164
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
165 uint64 mpstream_io_callback::getFilePointer() {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
166 return s->pos - s->buf_len + s->buf_pos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
167 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
168
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
169 void mpstream_io_callback::close() {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
170 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
171
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
172 typedef struct mkv_index_entry {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
173 uint64_t timecode, filepos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
174 int is_key;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
175 } mkv_index_entry_t;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
176
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
177 typedef struct mkv_track_index {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
178 uint32_t tnum;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
179 int num_entries;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
180 mkv_index_entry_t *entries;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
181 } mkv_track_index_t;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
182
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
183 typedef struct {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
184 uint32_t order, type, scope;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
185 uint32_t comp_algo;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
186 unsigned char *comp_settings;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
187 uint32_t comp_settings_len;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
188 uint32_t enc_algo, sig_algo, sig_hash_algo;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
189 unsigned char *enc_keyid, *sig_keyid, *signature;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
190 uint32_t enc_keyid_len, sig_keyid_len, signature_len;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
191 } mkv_content_encoding_t;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
192
11260
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
193 typedef struct {
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
194 int64_t start, end;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
195 } mkv_chapter_t;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
196
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
197 typedef struct mkv_track {
10705
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
198 uint32_t tnum, xid;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
199
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
200 char *codec_id;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
201 int ms_compat;
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
202 char *language;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
203
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
204 char type; // 'v' = video, 'a' = audio, 's' = subs
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
205
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
206 char v_fourcc[5];
10081
0181d5fc8474 Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents: 10079
diff changeset
207 uint32_t v_width, v_height, v_dwidth, v_dheight;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
208 float v_frate;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
209
10125
252428ac7978 Added support for AAC.
mosu
parents: 10105
diff changeset
210 uint32_t a_formattag;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
211 uint32_t a_channels, a_bps;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
212 float a_sfreq;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
213
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
214 int default_track;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
215
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
216 void *private_data;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
217 unsigned int private_size;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
218
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
219 // For Vorbis audio
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
220 unsigned char *headers[3];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
221 uint32_t header_sizes[3];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
222
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
223 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
224
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
225 // 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
226 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
227 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
228 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
229 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
230 float ra_pts; // previous audio timestamp
10844
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
231
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
232 // Stuff for QuickTime
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
233 bool fix_i_bps;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
234 float qt_last_a_pts;
11154
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
235
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
236 // Stuff for VobSubs
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
237 mkv_sh_sub_t sh_sub;
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
238
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
239 // Generic content encoding support.
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
240 vector<mkv_content_encoding_t> *c_encodings;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
241 #ifdef HAVE_ZLIB
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
242 z_stream zstream;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
243 bool zstream_initiated;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
244 #endif
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
245 } mkv_track_t;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
246
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
247 typedef struct mkv_demuxer {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
248 float duration, last_pts;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
249 uint64_t last_filepos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
250
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
251 mkv_track_t **tracks;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
252 int num_tracks;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
253 mkv_track_t *video, *audio, *subs_track;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
254
10283
21972de8631d Support for files whose first timecode is not 0 (which is the case for splitted/linked files).
mosu
parents: 10273
diff changeset
255 uint64_t tc_scale, cluster_tc, first_tc;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
256
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
257 mpstream_io_callback *in;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
258
10845
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
259 uint64_t clear_subs_at[SUB_MAX_TEXT];
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
260
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
261 subtitle subs;
10845
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
262 int subtitle_type;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
263
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
264 EbmlStream *es;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
265 EbmlElement *saved_l1, *saved_l2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
266 KaxSegment *segment;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
267 KaxCluster *cluster;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
268
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
269 mkv_track_index_t *index;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
270 int num_indexes, cues_found, cues_searched;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
271 int64_t *cluster_positions;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
272 int num_cluster_pos;
10685
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
273 vector<uint64_t> *parsed_seekheads;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
274 vector<uint64_t> *parsed_cues;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
275
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
276 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
277 bool v_skip_to_keyframe, a_skip_to_keyframe;
11260
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
278
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
279 vector<mkv_chapter_t> *chapters; // No support for nested chapters atm.
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
280 uint64_t stop_timecode;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
281 } mkv_demuxer_t;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
282
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 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
284 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
285 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
286 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
287 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
288 } 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
289
10438
ed760986e1fd Fixes for stuff that only showed up with gcc versions other than 3.2.
mosu
parents: 10437
diff changeset
290 #if __GNUC__ == 2
ed760986e1fd Fixes for stuff that only showed up with gcc versions other than 3.2.
mosu
parents: 10437
diff changeset
291 #pragma pack(2)
ed760986e1fd Fixes for stuff that only showed up with gcc versions other than 3.2.
mosu
parents: 10437
diff changeset
292 #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
293 #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
294 #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
295
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
296 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
297 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
298 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
299 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
300 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
301 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
302 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
303 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
304 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
305 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
306 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
307 } 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
308
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
309 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
310 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
311 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
312 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
313 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
314 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
315 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
316 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
317 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
318 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
319 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
320 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
321 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
322 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
323 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
324 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
325 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
326 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
327 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
328 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
329 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
330 } 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
331
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 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
333 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
334 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
335 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
336 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
337 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
338 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
339 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
340 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
341 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
342 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
343 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
344 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
345 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
346 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
347 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
348 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
349 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
350 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
351 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
352 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
353 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
354 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
355 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
356 } 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
357
10844
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
358 // I have to (re)define this struct here because g++ will not compile
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
359 // components.h from the qtsdk if I include it.
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
360 typedef struct {
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
361 uint32_t id_size;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
362 uint32_t codec_type;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
363 uint32_t reserved1;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
364 uint16_t reserved2;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
365 uint16_t data_reference_index;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
366 uint16_t version;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
367 uint16_t revision;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
368 uint32_t vendor;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
369 uint32_t temporal_quality;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
370 uint32_t spatial_quality;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
371 uint16_t width;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
372 uint16_t height;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
373 uint32_t horizontal_resolution; // 32bit fixed-point number
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
374 uint32_t vertical_resolution; // 32bit fixed-point number
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
375 uint32_t data_size;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
376 uint16_t frame_count;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
377 char compressor_name[32];
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
378 uint16_t depth;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
379 uint16_t color_table_id;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
380 } qt_image_description_t;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
381
10438
ed760986e1fd Fixes for stuff that only showed up with gcc versions other than 3.2.
mosu
parents: 10437
diff changeset
382 #if __GNUC__ == 2
ed760986e1fd Fixes for stuff that only showed up with gcc versions other than 3.2.
mosu
parents: 10437
diff changeset
383 #pragma pack()
ed760986e1fd Fixes for stuff that only showed up with gcc versions other than 3.2.
mosu
parents: 10437
diff changeset
384 #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
385 #pragma pack(pop)
10438
ed760986e1fd Fixes for stuff that only showed up with gcc versions other than 3.2.
mosu
parents: 10437
diff changeset
386 #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
387
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
388 static uint16_t get_uint16(const void *buf) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
389 uint16_t ret;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
390 unsigned char *tmp;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
391
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
392 tmp = (unsigned char *) buf;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
393
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
394 ret = tmp[1] & 0xff;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
395 ret = (ret << 8) + (tmp[0] & 0xff);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
396
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
397 return ret;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
398 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
399
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
400 static uint32_t get_uint32(const void *buf) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
401 uint32_t ret;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
402 unsigned char *tmp;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
403
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
404 tmp = (unsigned char *) buf;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
405
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
406 ret = tmp[3] & 0xff;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
407 ret = (ret << 8) + (tmp[2] & 0xff);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
408 ret = (ret << 8) + (tmp[1] & 0xff);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
409 ret = (ret << 8) + (tmp[0] & 0xff);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
410
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
411 return ret;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
412 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
413
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
414 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
415 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
416 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
417
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
418 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
419
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
420 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
421 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
422
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
423 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
424 }
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
425
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
426 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
427 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
428 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
429
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
430 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
431
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
432 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
433 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
434 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
435 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
436
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
437 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
438 }
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
439
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
440 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
441 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
442 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
443 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
444 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
445 }
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
446
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
447 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
448 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
449
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
450 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
451 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
452 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
453 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
454 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
455 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
456 }
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
457
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
458 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
459 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
460
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
461 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
462 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
463 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
464 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
465 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
466 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
467 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
468 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
469 }
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
470
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
471 static void handle_subtitles(demuxer_t *d, KaxBlock *block, int64_t duration) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
472 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *)d->priv;
10845
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
473 int len, line, state, i;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
474 char *s1, *s2, *buffer;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
475
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
476 if (duration == -1) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
477 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Warning: No KaxBlockDuration "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
478 "element for subtitle track found.\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
479 return;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
480 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
481
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
482 DataBuffer &data = block->GetBuffer(0);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
483 len = data.Size();
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
484
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
485 buffer = (char *)data.Buffer();
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
486 s1 = buffer;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
487
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
488 while (((*s1 == '\n') || (*s1 == '\r')) &&
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
489 ((unsigned int)(s1 - buffer) <= data.Size()))
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
490 s1++;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
491
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
492 line = 0;
10845
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
493 mkv_d->subs.lines++;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
494 s2 = mkv_d->subs.text[mkv_d->subs.lines - 1];
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
495 state = 0;
10845
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
496
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
497 if (mkv_d->subtitle_type == MKV_SUBTYPE_SSA) {
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
498 /* Matroska's SSA format does not have timecodes embedded into
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
499 the SAA line. Timescodes are encoded into the blocks timecode
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
500 and duration. */
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
501
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
502 /* Find text section. */
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
503 for (i = 0; (i < 8) && (*s1 != 0); s1++)
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
504 if (*s1 == ',')
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
505 i++;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
506
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
507 if (*s1 == 0) { // Broken line?
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
508 mkv_d->subs.lines--;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
509 return;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
510 }
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
511
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
512 /* Load text. */
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
513 while ((unsigned int)(s1 - buffer) < data.Size()) {
10861
59e3d641c48c Marked SSA subs as UTF-8. Better newline handling for SSA subs. Patch by Tristan <z80@oceanfree.net>.
mosu
parents: 10860
diff changeset
514 if (*s1 == '{')
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
515 state = 1;
10861
59e3d641c48c Marked SSA subs as UTF-8. Better newline handling for SSA subs. Patch by Tristan <z80@oceanfree.net>.
mosu
parents: 10860
diff changeset
516 else if ((*s1 == '}') && (state == 1))
10845
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
517 state = 2;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
518
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
519 if (state == 0) {
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
520 *s2 = *s1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
521 s2++;
10845
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
522 if ((s2 - mkv_d->subs.text[mkv_d->subs.lines - 1]) >= 255)
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
523 break;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
524 }
10845
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
525 s1++;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
526
10861
59e3d641c48c Marked SSA subs as UTF-8. Better newline handling for SSA subs. Patch by Tristan <z80@oceanfree.net>.
mosu
parents: 10860
diff changeset
527 /* Newline */
59e3d641c48c Marked SSA subs as UTF-8. Better newline handling for SSA subs. Patch by Tristan <z80@oceanfree.net>.
mosu
parents: 10860
diff changeset
528 if ((*s1 == '\\') && ((unsigned int)(s1 + 1 - buffer) < data.Size()) &&
59e3d641c48c Marked SSA subs as UTF-8. Better newline handling for SSA subs. Patch by Tristan <z80@oceanfree.net>.
mosu
parents: 10860
diff changeset
529 ((*(s1 + 1) == 'N') || (*(s1 + 1) == 'n'))) {
59e3d641c48c Marked SSA subs as UTF-8. Better newline handling for SSA subs. Patch by Tristan <z80@oceanfree.net>.
mosu
parents: 10860
diff changeset
530 mkv_d->clear_subs_at[mkv_d->subs.lines - 1] =
59e3d641c48c Marked SSA subs as UTF-8. Better newline handling for SSA subs. Patch by Tristan <z80@oceanfree.net>.
mosu
parents: 10860
diff changeset
531 block->GlobalTimecode() / 1000000 - mkv_d->first_tc + duration;
59e3d641c48c Marked SSA subs as UTF-8. Better newline handling for SSA subs. Patch by Tristan <z80@oceanfree.net>.
mosu
parents: 10860
diff changeset
532
59e3d641c48c Marked SSA subs as UTF-8. Better newline handling for SSA subs. Patch by Tristan <z80@oceanfree.net>.
mosu
parents: 10860
diff changeset
533 mkv_d->subs.lines++;
59e3d641c48c Marked SSA subs as UTF-8. Better newline handling for SSA subs. Patch by Tristan <z80@oceanfree.net>.
mosu
parents: 10860
diff changeset
534 *s2 = 0;
59e3d641c48c Marked SSA subs as UTF-8. Better newline handling for SSA subs. Patch by Tristan <z80@oceanfree.net>.
mosu
parents: 10860
diff changeset
535 s2 = mkv_d->subs.text[mkv_d->subs.lines - 1];
59e3d641c48c Marked SSA subs as UTF-8. Better newline handling for SSA subs. Patch by Tristan <z80@oceanfree.net>.
mosu
parents: 10860
diff changeset
536 s1 += 2;
59e3d641c48c Marked SSA subs as UTF-8. Better newline handling for SSA subs. Patch by Tristan <z80@oceanfree.net>.
mosu
parents: 10860
diff changeset
537 }
59e3d641c48c Marked SSA subs as UTF-8. Better newline handling for SSA subs. Patch by Tristan <z80@oceanfree.net>.
mosu
parents: 10860
diff changeset
538
10845
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
539 if (state == 2)
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
540 state = 0;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
541 }
10845
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
542 *s2 = 0;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
543
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
544 } else {
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
545 while ((unsigned int)(s1 - buffer) != data.Size()) {
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
546 if ((*s1 == '\n') || (*s1 == '\r')) {
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
547 if (state == 0) { // normal char --> newline
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
548 if (mkv_d->subs.lines == SUB_MAX_TEXT)
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
549 break;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
550 *s2 = 0;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
551 mkv_d->clear_subs_at[mkv_d->subs.lines - 1]=
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
552 block->GlobalTimecode() / 1000000 - mkv_d->first_tc + duration;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
553 s2 = mkv_d->subs.text[mkv_d->subs.lines];
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
554 mkv_d->subs.lines++;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
555 state = 1;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
556 }
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
557 } else if (*s1 == '<') // skip HTML tags
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
558 state = 2;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
559 else if (*s1 == '>')
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
560 state = 0;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
561 else if (state != 2) { // normal character
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
562 state = 0;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
563 if ((s2 - mkv_d->subs.text[mkv_d->subs.lines - 1]) < 255) {
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
564 *s2 = *s1;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
565 s2++;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
566 }
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
567 }
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
568 s1++;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
569 }
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
570
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
571 *s2 = 0;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
572 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
573
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
574 #ifdef USE_ICONV
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
575 subcp_recode1(&mkv_d->subs);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
576 #endif
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
577
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
578 vo_sub = &mkv_d->subs;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
579 vo_osd_changed(OSDTYPE_SUBTITLE);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
580
10845
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
581 mkv_d->clear_subs_at[mkv_d->subs.lines - 1] =
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
582 block->GlobalTimecode() / 1000000 - mkv_d->first_tc + duration;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
583 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
584
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
585 static mkv_track_t *new_mkv_track(mkv_demuxer_t *d) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
586 mkv_track_t *t;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
587
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
588 t = (mkv_track_t *)safemalloc(sizeof(mkv_track_t));
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
589 memset(t, 0, sizeof(mkv_track_t));
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
590 d->tracks = (mkv_track_t **)realloc(d->tracks, (d->num_tracks + 1) *
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
591 sizeof(mkv_track_t *));
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
592 if (d->tracks == NULL)
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
593 return NULL;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
594 d->tracks[d->num_tracks] = t;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
595 d->num_tracks++;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
596
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
597 // Set default values.
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
598 t->default_track = 1;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
599 t->a_sfreq = 8000.0;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
600 t->a_channels = 1;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
601 t->language = strdup("eng");
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
602
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
603 t->c_encodings = new vector<mkv_content_encoding_t>;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
604
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
605 return t;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
606 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
607
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
608 static mkv_track_t *find_track_by_num(mkv_demuxer_t *d, uint32_t n,
10705
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
609 char track_type) {
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
610 int i;
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
611
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
612 for (i = 0; i < d->num_tracks; i++)
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
613 if ((d->tracks[i] != NULL) && (d->tracks[i]->type == track_type) &&
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
614 (d->tracks[i]->xid == n))
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
615 return d->tracks[i];
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
616
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
617 return NULL;
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
618 }
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
619
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
620 static mkv_track_t *find_duplicate_track_by_num(mkv_demuxer_t *d, uint32_t n,
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
621 mkv_track_t *c) {
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
622 int i;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
623
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
624 for (i = 0; i < d->num_tracks; i++)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
625 if ((d->tracks[i] != NULL) && (d->tracks[i]->tnum == n) &&
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
626 (d->tracks[i] != c))
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
627 return d->tracks[i];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
628
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
629 return NULL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
630 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
631
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
632 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
633 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
634 int i;
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
635
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
636 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
637 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
638 (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
639 !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
640 (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
641 return d->tracks[i];
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
642
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
643 return NULL;
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
644 }
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
645
11154
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
646 static bool mkv_parse_idx(mkv_track_t *t) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
647 uint32_t i, p, things_found;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
648 int idx;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
649 string line, s1, s2;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
650 char *src;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
651
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
652 if ((t->private_data == NULL) || (t->private_size < 1))
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
653 return false;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
654
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
655 things_found = 0;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
656 i = 0;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
657 src = (char *)t->private_data;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
658 do {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
659 line = "";
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
660 while ((i < t->private_size) && (src[i] != '\n') && (src[i] != '\r')) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
661 if (!isspace(src[i]))
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
662 line += src[i];
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
663 i++;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
664 }
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
665 while ((i < t->private_size) && ((src[i] == '\n') || (src[i] == '\r')))
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
666 i++;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
667
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
668 if (!strncasecmp(line.c_str(), "size:", 5)) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
669 s1 = line.substr(5);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
670 idx = s1.find('x');
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
671 if (idx >= 0) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
672 s2 = s1.substr(idx + 1);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
673 s1.erase(idx);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
674 t->sh_sub.width = strtol(s1.c_str(), NULL, 10);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
675 t->sh_sub.height = strtol(s2.c_str(), NULL, 10);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
676 things_found |= 1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
677 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] VobSub IDX parser: size: %d x %d\n",
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
678 t->sh_sub.width, t->sh_sub.height);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
679 }
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
680
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
681 } else if (!strncasecmp(line.c_str(), "palette:", 8)) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
682 s1 = line.substr(8);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
683 for (p = 0; p < 15; p++) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
684 idx = s1.find(',');
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
685 if (idx < 0)
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
686 break;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
687 s2 = s1.substr(0, idx);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
688 s1.erase(0, idx + 1);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
689 t->sh_sub.palette[p] = (unsigned int)strtol(s2.c_str(), NULL, 16);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
690 }
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
691 if (idx >= 0) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
692 t->sh_sub.palette[15] = (unsigned int)strtol(s1.c_str(), NULL, 16);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
693 things_found |= 2;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
694 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] VobSub IDX parser: palette: 0x%06x "
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
695 "0x%06x 0x%06x 0x%06x 0x%06x 0x%06x 0x%06x 0x%06x 0x%06x "
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
696 "0x%06x 0x%06x 0x%06x 0x%06x 0x%06x 0x%06x 0x%06x\n",
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
697 t->sh_sub.palette[0], t->sh_sub.palette[1],
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
698 t->sh_sub.palette[2], t->sh_sub.palette[3],
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
699 t->sh_sub.palette[4], t->sh_sub.palette[5],
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
700 t->sh_sub.palette[6], t->sh_sub.palette[7],
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
701 t->sh_sub.palette[8], t->sh_sub.palette[9],
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
702 t->sh_sub.palette[10], t->sh_sub.palette[11],
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
703 t->sh_sub.palette[12], t->sh_sub.palette[13],
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
704 t->sh_sub.palette[14], t->sh_sub.palette[15]);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
705 }
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
706 }
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
707
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
708 } while ((i != t->private_size) && (things_found != 3));
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
709 t->sh_sub.type = 'v';
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
710
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
711 return (things_found == 3);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
712 }
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
713
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
714 static bool reverse_encodings(mkv_track_t *track, unsigned char *&data,
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
715 uint32_t &size, uint32_t type) {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
716 int new_size;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
717 unsigned char *new_data, *old_data;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
718 bool modified;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
719 vector<mkv_content_encoding_t>::iterator ce;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
720
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
721 if (track->c_encodings->size() == 0)
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
722 return false;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
723
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
724 new_data = data;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
725 new_size = size;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
726 modified = false;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
727 for (ce = track->c_encodings->begin(); ce < track->c_encodings->end();
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
728 ce++) {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
729 if ((ce->scope & type) == 0)
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
730 continue;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
731
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
732 #ifdef HAVE_ZLIB
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
733 if (ce->comp_algo == 0) {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
734 int result;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
735
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
736 old_data = new_data;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
737 new_data = (unsigned char *)safemalloc(new_size * 20);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
738
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
739 track->zstream.next_in = (Bytef *)old_data;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
740 track->zstream.next_out = (Bytef *)new_data;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
741 track->zstream.avail_in = new_size;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
742 track->zstream.avail_out = 20 * new_size;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
743 result = inflate(&track->zstream, Z_FULL_FLUSH);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
744 if (result != Z_OK) {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
745 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Zlib decompression failed. "
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
746 "Result: %d\n", result);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
747 safefree(new_data);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
748 data = old_data;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
749 size = new_size;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
750 return modified;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
751 }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
752
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
753 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] zlib decompression: from %d to "
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
754 "%d\n", new_size, 20 * new_size - track->zstream.avail_out);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
755 new_size = 20 * new_size - track->zstream.avail_out;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
756
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
757 if (modified)
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
758 safefree(old_data);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
759 modified = true;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
760 }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
761 #endif
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
762 }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
763
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
764 data = new_data;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
765 size = new_size;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
766
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
767 return modified;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
768 }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
769
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
770 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
771 int i, track_num;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
772 unsigned char *c;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
773 uint32_t u, offset, length;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
774 mkv_track_t *t;
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
775 mkv_content_encoding_t *ce;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
776 BITMAPINFOHEADER *bih;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
777 WAVEFORMATEX *wfe;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
778
10028
7ca8b302032f Loop counter was used inside for another loop as well.
mosu
parents: 10024
diff changeset
779 for (track_num = 0; track_num < d->num_tracks; track_num++) {
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
780 t = d->tracks[track_num];
10028
7ca8b302032f Loop counter was used inside for another loop as well.
mosu
parents: 10024
diff changeset
781
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
782 t->ok = 1;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
783 for (i = 0; i < (int)t->c_encodings->size(); i++) {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
784 ce = &(*t->c_encodings)[i];
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
785
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
786 if (ce->type == 1) {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
787 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Track number %u has been "
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
788 "encrypted and decryption has not yet been implemented. "
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
789 "Skipping track.\n", t->tnum);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
790 t->ok = 0;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
791 break;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
792 }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
793
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
794 if (ce->type != 0) {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
795 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Unknown content encoding type %u "
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
796 "for track %u. Skipping track.\n", ce->type, t->tnum);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
797 t->ok = 0;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
798 break;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
799 }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
800
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
801 if (ce->comp_algo == 0) {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
802 #if !defined(HAVE_ZLIB)
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
803 mp_msg(MSGT_DEMUX, MSGL_WARN, "Track %u was compressed with zlib but "
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
804 "mplayer has not been compiled with support for zlib "
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
805 "compression. Skipping track.\n", t->tnum);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
806 t->ok = 0;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
807 break;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
808 #else
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
809 if (!t->zstream_initiated) {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
810 t->zstream.zalloc = (alloc_func)0;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
811 t->zstream.zfree = (free_func)0;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
812 t->zstream.opaque = (voidpf)0;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
813 inflateInit(&t->zstream);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
814 t->zstream_initiated = true;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
815 }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
816 #endif
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
817 } else {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
818 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Track %u has been compressed "
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
819 "with an unknown/unsupported compression algorithm (%u). "
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
820 "Skipping track.\n", t->tnum, ce->comp_algo);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
821 t->ok = 0;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
822 break;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
823 }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
824 }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
825
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
826 if (!t->ok)
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
827 continue;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
828 t->ok = 0;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
829
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
830 if (t->private_data != NULL) {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
831 c = (unsigned char *)t->private_data;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
832 length = t->private_size;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
833 if (reverse_encodings(t, c, length, 2)) {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
834 safefree(t->private_data);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
835 t->private_data = c;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
836 t->private_size = length;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
837 }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
838 }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
839
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
840 switch (t->type) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
841 case 'v': // video track
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
842 if (t->codec_id == NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
843 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
844 if (!strcmp(t->codec_id, MKV_V_MSCOMP)) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
845 if ((t->private_data == NULL) ||
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
846 (t->private_size < sizeof(BITMAPINFOHEADER))) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
847 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] WARNING: CodecID for track "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
848 "%u is '" MKV_V_MSCOMP "', but there was no "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
849 "BITMAPINFOHEADER struct present. Therefore we don't have "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
850 "a FourCC to identify the video codec used.\n", t->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
851 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
852 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
853 t->ms_compat = 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
854
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
855 bih = (BITMAPINFOHEADER *)t->private_data;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
856
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
857 u = get_uint32(&bih->biWidth);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
858 if (t->v_width != u) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
859 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] WARNING: (MS "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
860 "compatibility mode, track %u) "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
861 "Matrosa says video width is %u, but the "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
862 "BITMAPINFOHEADER says %u.\n", t->tnum, t->v_width, u);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
863 if (t->v_width == 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
864 t->v_width = u;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
865 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
866
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
867 u = get_uint32(&bih->biHeight);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
868 if (t->v_height != u) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
869 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] WARNING: (MS compatibility "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
870 "mode, track %u) "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
871 "Matrosa video height is %u, but the BITMAPINFOHEADER "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
872 "says %u.\n", t->tnum, t->v_height, u);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
873 if (t->v_height == 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
874 t->v_height = u;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
875 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
876
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
877 memcpy(t->v_fourcc, &bih->biCompression, 4);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
878 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
879 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
880
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
881 if (t->v_width == 0) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
882 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] The width for track %u was "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
883 "not set.\n", t->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
884 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
885 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
886 if (t->v_height == 0) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
887 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] The height for track %u was "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
888 "not set.\n", t->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
889 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
890 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
891
10081
0181d5fc8474 Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents: 10079
diff changeset
892 if (t->v_dwidth == 0)
0181d5fc8474 Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents: 10079
diff changeset
893 t->v_dwidth = t->v_width;
0181d5fc8474 Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents: 10079
diff changeset
894 if (t->v_dheight == 0)
0181d5fc8474 Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents: 10079
diff changeset
895 t->v_dheight = t->v_height;
0181d5fc8474 Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents: 10079
diff changeset
896
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
897 // This track seems to be ok.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
898 t->ok = 1;
10705
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
899 mp_msg(MSGT_DEMUX, MSGL_INFO, "[mkv] Track ID %u: video (%s), "
10706
ede87804e4e6 Removed some ":" in the track output for easier cut&paste.
mosu
parents: 10705
diff changeset
900 "-vid %u\n", t->tnum, t->codec_id, t->xid);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
901
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
902 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
903
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
904 case 'a': // audio track
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
905 if (t->codec_id == NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
906 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
907 if (!strcmp(t->codec_id, MKV_A_ACM)) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
908 if ((t->private_data == NULL) ||
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
909 (t->private_size < sizeof(WAVEFORMATEX))) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
910 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] WARNING: CodecID for track "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
911 "%u is '" MKV_A_ACM "', "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
912 "but there was no WAVEFORMATEX struct present. "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
913 "Therefore we don't have a format ID to identify the audio "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
914 "codec used.\n", t->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
915 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
916 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
917 t->ms_compat = 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
918
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
919 wfe = (WAVEFORMATEX *)t->private_data;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
920 u = get_uint32(&wfe->nSamplesPerSec);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
921 if (((uint32_t)t->a_sfreq) != u) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
922 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] WARNING: (MS compatibility "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
923 "mode for track %u) "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
924 "Matroska says that there are %u samples per second, "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
925 "but WAVEFORMATEX says that there are %u.\n", t->tnum,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
926 (uint32_t)t->a_sfreq, u);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
927 if (t->a_sfreq == 0.0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
928 t->a_sfreq = (float)u;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
929 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
930
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
931 u = get_uint16(&wfe->nChannels);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
932 if (t->a_channels != u) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
933 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] WARNING: (MS "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
934 "compatibility mode for track %u) "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
935 "Matroska says that there are %u channels, but the "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
936 "WAVEFORMATEX says that there are %u.\n", t->tnum,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
937 t->a_channels, u);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
938 if (t->a_channels == 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
939 t->a_channels = u;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
940 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
941
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
942 u = get_uint16(&wfe->wBitsPerSample);
10098
ebbe39bb55ab Check with the wrong variable.
mosu
parents: 10084
diff changeset
943 if (t->a_bps != u) {
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
944 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] WARNING: (MS "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
945 "compatibility mode for track %u) "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
946 "Matroska says that there are %u bits per sample, "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
947 "but the WAVEFORMATEX says that there are %u.\n", t->tnum,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
948 t->a_bps, u);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
949 if (t->a_bps == 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
950 t->a_bps = u;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
951 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
952
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
953 t->a_formattag = get_uint16(&wfe->wFormatTag);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
954 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
955 } else {
11155
4a21e1672c91 Support for MP2 audio.
mosu
parents: 11154
diff changeset
956 if (!strcmp(t->codec_id, MKV_A_MP3) ||
4a21e1672c91 Support for MP2 audio.
mosu
parents: 11154
diff changeset
957 !strcmp(t->codec_id, MKV_A_MP2))
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
958 t->a_formattag = 0x0055;
11114
d8ddd7727084 More liberal codec id recognition for AC3 codecs (needed for transcoded DNET from RM).
mosu
parents: 10984
diff changeset
959 else if (!strncmp(t->codec_id, MKV_A_AC3, strlen(MKV_A_AC3)))
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
960 t->a_formattag = 0x2000;
10105
dc4f1b768062 Support for DTS tracks (only with -hwac3 of course).
mosu
parents: 10099
diff changeset
961 else if (!strcmp(t->codec_id, MKV_A_DTS))
dc4f1b768062 Support for DTS tracks (only with -hwac3 of course).
mosu
parents: 10099
diff changeset
962 // 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
963 t->a_formattag = 0x2000;
10844
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
964 else if (!strcmp(t->codec_id, MKV_A_PCM) ||
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
965 !strcmp(t->codec_id, MKV_A_PCM_BE))
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
966 t->a_formattag = 0x0001;
10133
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
967 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
968 !strcmp(t->codec_id, MKV_A_AAC_2LC) ||
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
969 !strcmp(t->codec_id, MKV_A_AAC_2SSR) ||
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
970 !strcmp(t->codec_id, MKV_A_AAC_4MAIN) ||
10125
252428ac7978 Added support for AAC.
mosu
parents: 10105
diff changeset
971 !strcmp(t->codec_id, MKV_A_AAC_4LC) ||
10133
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
972 !strcmp(t->codec_id, MKV_A_AAC_4SSR) ||
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
973 !strcmp(t->codec_id, MKV_A_AAC_4LTP) ||
10125
252428ac7978 Added support for AAC.
mosu
parents: 10105
diff changeset
974 !strcmp(t->codec_id, MKV_A_AAC_4SBR))
252428ac7978 Added support for AAC.
mosu
parents: 10105
diff changeset
975 t->a_formattag = mmioFOURCC('M', 'P', '4', 'A');
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
976 else if (!strcmp(t->codec_id, MKV_A_VORBIS)) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
977 if (t->private_data == NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
978 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] WARNING: CodecID for "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
979 "track %u is '" MKV_A_VORBIS
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
980 "', but there are no header packets present.", t->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
981 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
982 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
983
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
984 c = (unsigned char *)t->private_data;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
985 if (c[0] != 2) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
986 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Vorbis track does not "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
987 "contain valid headers.\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
988 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
989 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
990
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
991 offset = 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
992 for (i = 0; i < 2; i++) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
993 length = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
994 while ((c[offset] == (unsigned char )255) &&
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
995 (length < t->private_size)) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
996 length += 255;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
997 offset++;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
998 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
999 if (offset >= (t->private_size - 1)) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1000 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Vorbis track does not "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1001 "contain valid headers.\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1002 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1003 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1004 length += c[offset];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1005 offset++;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1006 t->header_sizes[i] = length;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1007 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1008
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1009 t->headers[0] = &c[offset];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1010 t->headers[1] = &c[offset + t->header_sizes[0]];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1011 t->headers[2] = &c[offset + t->header_sizes[0] +
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1012 t->header_sizes[1]];
10079
7c13793dbfa0 Vorbis header packet lengths were calculated incorrectly.
mosu
parents: 10073
diff changeset
1013 t->header_sizes[2] = t->private_size - offset -
7c13793dbfa0 Vorbis header packet lengths were calculated incorrectly.
mosu
parents: 10073
diff changeset
1014 t->header_sizes[0] - t->header_sizes[1];
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1015
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1016 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
1017 } 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
1018 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
1019 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
1020 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
1021 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
1022 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
1023 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
1024 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
1025 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
1026 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
1027 t->a_formattag = mmioFOURCC('s', 'i', 'p', 'r');
10844
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
1028 } else if (!strcmp(t->codec_id, MKV_A_QDMC) ||
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
1029 !strcmp(t->codec_id, MKV_A_QDMC2)) {
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
1030 ;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1031 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1032 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
1033 "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
1034 "codec data.\n", t->codec_id, t->tnum);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1035 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1036 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1037 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1038
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1039 if (t->a_sfreq == 0.0) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1040 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] The sampling frequency was not "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1041 "set for track %u.\n", t->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1042 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1043 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1044
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1045 if (t->a_channels == 0) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1046 mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] The number of channels was not "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1047 "set for track %u.\n", t->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1048 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1049 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1050
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1051 // This track seems to be ok.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1052 t->ok = 1;
10706
ede87804e4e6 Removed some ":" in the track output for easier cut&paste.
mosu
parents: 10705
diff changeset
1053 mp_msg(MSGT_DEMUX, MSGL_INFO, "[mkv] Track ID %u: audio (%s), -aid "
10705
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
1054 "%u%s%s\n", t->tnum, t->codec_id, t->xid,
10706
ede87804e4e6 Removed some ":" in the track output for easier cut&paste.
mosu
parents: 10705
diff changeset
1055 t->language != NULL ? ", -alang " : "",
10705
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
1056 t->language != NULL ? t->language : "");
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1057 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1058
11154
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
1059 case 's':
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1060 if (!strcmp(t->codec_id, MKV_S_VOBSUB)) {
11154
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
1061 if (mkv_parse_idx(t)) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
1062 t->ok = 1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
1063 mp_msg(MSGT_DEMUX, MSGL_INFO, "[mkv] Track ID %u: subtitles (%s), "
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
1064 "-sid %u%s%s\n", t->tnum, t->codec_id,
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
1065 t->xid, t->language != NULL ? ", -slang " : "",
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
1066 t->language != NULL ? t->language : "");
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
1067 }
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
1068
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
1069 } else { // Text subtitles do not need any data
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
1070 t->ok = 1; // except the CodecID.
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
1071 mp_msg(MSGT_DEMUX, MSGL_INFO, "[mkv] Track ID %u: subtitles (%s), "
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
1072 "-sid %u%s%s\n", t->tnum, t->codec_id, t->xid,
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
1073 t->language != NULL ? ", -slang " : "",
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
1074 t->language != NULL ? t->language : "");
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
1075 }
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1076 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1077
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1078 default: // unknown track type!? error in demuxer...
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1079 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] Error in demux_mkv.cpp: unknown "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1080 "demuxer type for track %u: '%c'\n", t->tnum, t->type);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1081 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1082 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1083
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1084 if (t->ok)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1085 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
1086 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1087
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1088 return 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1089 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1090
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1091 static void free_mkv_demuxer(mkv_demuxer_t *d) {
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1092 int i, k;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1093
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1094 if (d == NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1095 return;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1096
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1097 for (i = 0; i < d->num_tracks; i++)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1098 if (d->tracks[i] != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1099 if (d->tracks[i]->private_data != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1100 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
1101 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
1102 free(d->tracks[i]->language);
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1103 for (k = 0; k < (int)d->tracks[i]->c_encodings->size(); k++) {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1104 safefree((*d->tracks[i]->c_encodings)[k].comp_settings);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1105 safefree((*d->tracks[i]->c_encodings)[k].enc_keyid);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1106 safefree((*d->tracks[i]->c_encodings)[k].sig_keyid);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1107 safefree((*d->tracks[i]->c_encodings)[k].signature);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1108 }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1109 delete d->tracks[i]->c_encodings;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1110 #ifdef HAVE_ZLIB
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1111 if (d->tracks[i]->zstream_initiated)
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1112 inflateEnd(&d->tracks[i]->zstream);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1113 #endif
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1114 free(d->tracks[i]);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1115 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1116
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1117 for (i = 0; i < d->num_indexes; i++)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1118 free(d->index[i].entries);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1119 free(d->index);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1120
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1121 if (d->es != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1122 delete d->es;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1123 if (d->saved_l1 != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1124 delete d->saved_l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1125 if (d->in != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1126 delete d->in;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1127 if (d->segment != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1128 delete d->segment;
11260
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1129 if (d->chapters != NULL)
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1130 delete d->chapters;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1131
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1132 free(d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1133 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1134
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1135 static void add_index_entry(mkv_demuxer_t *d, uint32_t tnum, uint64_t filepos,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1136 uint64_t timecode, int is_key) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1137 int i, found;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1138 mkv_index_entry_t *entry;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1139
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1140 for (i = 0, found = 0; i < d->num_indexes; i++)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1141 if (d->index[i].tnum == tnum) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1142 found = 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1143 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1144 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1145
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1146 if (!found) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1147 d->index = (mkv_track_index_t *)realloc(d->index, (d->num_indexes + 1) *
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1148 sizeof(mkv_track_index_t));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1149 if (d->index == NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1150 return;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1151 i = d->num_indexes;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1152 memset(&d->index[i], 0, sizeof(mkv_track_index_t));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1153 d->index[i].tnum = tnum;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1154 d->num_indexes++;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1155 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1156
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1157 d->index[i].entries =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1158 (mkv_index_entry_t *)realloc(d->index[i].entries,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1159 (d->index[i].num_entries + 1) *
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1160 sizeof(mkv_index_entry_t));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1161 if (d->index[i].entries == NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1162 return;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1163 entry = &d->index[i].entries[d->index[i].num_entries];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1164 entry->filepos = filepos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1165 entry->timecode = timecode;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1166 entry->is_key = is_key;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1167 d->index[i].num_entries++;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1168 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1169
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1170 static void add_cluster_position(mkv_demuxer_t *mkv_d, int64_t position) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1171 mkv_d->cluster_positions = (int64_t *)realloc(mkv_d->cluster_positions,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1172 (mkv_d->num_cluster_pos + 1) *
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1173 sizeof(int64_t));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1174 if (mkv_d->cluster_positions != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1175 mkv_d->cluster_positions[mkv_d->num_cluster_pos] = position;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1176 mkv_d->num_cluster_pos++;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1177 } else
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1178 mkv_d->num_cluster_pos = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1179 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1180
10685
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1181 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
1182 unsigned int i;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1183
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1184 for (i = 0; i < vec.size(); i++)
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1185 if (vec[i] == value)
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1186 return 1;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1187
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1188 return 0;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1189 }
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1190
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
1191 #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
1192 (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
1193 #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
1194 (((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
1195 #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
1196 (((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
1197
10685
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1198 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
1199 EbmlElement *l2 = NULL;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1200 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
1201 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
1202 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
1203 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
1204 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
1205 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
1206 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
1207 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
1208 int upper_lvl_el, i, k;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1209 uint64_t tc_scale, filepos = 0, timecode = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1210 uint32_t tnum = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1211 mkv_index_entry_t *entry;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1212
10685
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1213 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
1214 return;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1215
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1216 mkv_d->parsed_cues->push_back(pos);
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1217
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1218 mkv_d->in->setFilePointer(pos);
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1219
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1220 es = mkv_d->es;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1221 tc_scale = mkv_d->tc_scale;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1222 upper_lvl_el = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1223
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1224 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] /---- [ parsing cues ] -----------\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1225
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
1226 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
1227 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
1228 if (cues == NULL)
10685
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1229 return;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1230
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
1231 if (!(EbmlId(*cues) == KaxCues::ClassInfos.GlobalId)) {
10685
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1232 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
1233 "[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
1234 cues->Generic().DebugName);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1235
10685
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1236 return;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1237 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1238
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1239 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] |+ found cues\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1240
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
1241 cues->Read(*es, KaxCues::ClassInfos.Context, upper_lvl_el, l2, true);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1242
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
1243 cpoint = FINDFIRST(cues, KaxCuePoint);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1244
10637
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1245 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
1246 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue point\n");
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1247
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
1248 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
1249 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
1250 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
1251 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
1252 }
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1253
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1254 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
1255 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
1256 (float)timecode / 1000.0);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1257
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
1258 ctrackpos = FINDFIRST(cpoint, KaxCueTrackPositions);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1259
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
1260 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
1261 ctrack = FINDFIRST(ctrackpos, KaxCueTrack);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1262
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
1263 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
1264 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
1265 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
1266 }
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
1267
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
1268 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
1269 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] | + found cue track: %u\n", tnum);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1270
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
1271 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
1272 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
1273 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
1274 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
1275 }
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1276
10637
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1277 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
1278 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
1279 "position: %llu\n", filepos);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1280
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
1281 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
1282 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
1283 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
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 ctrackpos = FINDNEXT(cpoint, KaxCueTrackPositions, ctrackpos);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1286 }
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
1287
10637
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1288 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
1289 }
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. 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
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. 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 delete cues;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1292
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1293 // Debug: dump the index
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1294 for (i = 0; i < mkv_d->num_indexes; i++) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1295 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] Index for track %u contains %u "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1296 "entries.\n", mkv_d->index[i].tnum, mkv_d->index[i].num_entries);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1297 for (k = 0; k < mkv_d->index[i].num_entries; k++) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1298 entry = &mkv_d->index[i].entries[k];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1299 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] %d: timecode %llu, filepos %llu, "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1300 "is key: %s\n", k, entry->timecode, entry->filepos,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1301 entry->is_key ? "yes" : "no");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1302 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1303 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1304
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1305 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] \\---- [ parsing cues ] -----------\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1306
10685
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1307 mkv_d->cues_found = 1;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1308 }
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1309
11260
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1310 static void parse_chapters(mkv_demuxer_t *mkv_d, uint64_t pos) {
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1311 EbmlElement *l2 = NULL;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1312 EbmlStream *es;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1313 KaxChapters *kchapters;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1314 KaxEditionEntry *keentry;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1315 KaxChapterAtom *kcatom;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1316 KaxChapterTimeStart *kctstart;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1317 KaxChapterTimeEnd *kctend;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1318 int upper_lvl_el, i, k;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1319 mkv_chapter_t chapter;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1320
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1321 if (mkv_d->chapters != NULL)
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1322 return;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1323
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1324 es = mkv_d->es;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1325 upper_lvl_el = 0;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1326
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1327 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] /---- [ parsing chapters ] ---------\n");
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1328
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1329 mkv_d->in->setFilePointer(pos);
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1330
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1331 kchapters =
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1332 (KaxChapters *)es->FindNextElement(mkv_d->segment->Generic().Context,
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1333 upper_lvl_el, 0xFFFFFFFFL, true, 1);
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1334 if (kchapters == NULL)
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1335 return;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1336
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1337 if (!(EbmlId(*kchapters) == KaxChapters::ClassInfos.GlobalId)) {
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1338 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] No KaxChapters element found but %s.\n"
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1339 "[mkv] \\---- [ parsing chapters ] ---------\n",
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1340 kchapters->Generic().DebugName);
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1341
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1342 return;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1343 }
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1344
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1345 mkv_d->chapters = new vector<mkv_chapter_t>;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1346 kchapters->Read(*es, KaxChapters::ClassInfos.Context, upper_lvl_el, l2,
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1347 true);
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1348
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1349 for (i = 0; i < (int)kchapters->ListSize(); i++) {
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1350 keentry = (KaxEditionEntry *)(*kchapters)[i];
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1351 if (EbmlId(*keentry) == KaxEditionEntry::ClassInfos.GlobalId) {
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1352 for (k = 0; k < (int)keentry->ListSize(); k++) {
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1353 kcatom = (KaxChapterAtom *)(*keentry)[k];
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1354 if (EbmlId(*kcatom) == KaxChapterAtom::ClassInfos.GlobalId) {
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1355 chapter.start = 0;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1356 chapter.end = 0;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1357 kctstart = FINDFIRST(kcatom, KaxChapterTimeStart);
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1358 if (kctstart != NULL)
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1359 chapter.start = uint64(*kctstart) / 1000000;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1360 kctend = FINDFIRST(kcatom, KaxChapterTimeEnd);
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1361 if (kctend != NULL)
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1362 chapter.end = uint64(*kctend) / 1000000;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1363 mkv_d->chapters->push_back(chapter);
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1364 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Chapter %u from %02d:%02d:%02d."
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1365 "%03d to %02d:%02d:%02d.%03d\n", mkv_d->chapters->size(),
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1366 (int)(chapter.start / 60 / 60 / 1000),
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1367 (int)((chapter.start / 60 / 1000) % 60),
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1368 (int)((chapter.start / 1000) % 60),
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1369 (int)(chapter.start % 1000),
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1370 (int)(chapter.end / 60 / 60 / 1000),
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1371 (int)((chapter.end / 60 / 1000) % 60),
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1372 (int)((chapter.end / 1000) % 60),
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1373 (int)(chapter.end % 1000));
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1374 }
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1375 }
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1376 }
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1377 }
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1378
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1379 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] \\---- [ parsing chapters ] ---------\n");
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1380 delete kchapters;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1381 }
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1382
10685
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1383 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
1384 EbmlElement *l2 = NULL;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1385 EbmlStream *es;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1386 KaxSeekHead *kseekhead;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1387 KaxSeek *kseek;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1388 KaxSeekID *ksid;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1389 KaxSeekPosition *kspos;
10705
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
1390 int upper_lvl_el, i, k, s;
10685
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1391 uint64_t seek_pos;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1392 EbmlId *id;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1393 EbmlElement *e;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1394 binary *b;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1395
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1396 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
1397 return;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1398
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1399 mkv_d->parsed_seekheads->push_back(pos);
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1400
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1401 es = mkv_d->es;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1402 upper_lvl_el = 0;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1403
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1404 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
1405
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1406 mkv_d->in->setFilePointer(pos);
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1407
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1408 kseekhead =
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1409 (KaxSeekHead *)es->FindNextElement(mkv_d->segment->Generic().Context,
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1410 upper_lvl_el, 0xFFFFFFFFL, true, 1);
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1411 if (kseekhead == NULL)
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1412 return;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1413
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1414 if (!(EbmlId(*kseekhead) == KaxSeekHead::ClassInfos.GlobalId)) {
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1415 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
1416 "[mkv] \\---- [ parsing seek head ] ---------\n",
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1417 kseekhead->Generic().DebugName);
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1418
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1419 return;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1420 }
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1421
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1422 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
1423 true);
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1424
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1425 for (i = 0; i < (int)kseekhead->ListSize(); i++) {
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1426 kseek = (KaxSeek *)(*kseekhead)[i];
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1427 if (!(EbmlId(*kseek) == KaxSeek::ClassInfos.GlobalId))
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1428 continue;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1429
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1430 seek_pos = 0;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1431 id = NULL;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1432
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1433 for (k = 0; k < (int)kseek->ListSize(); k++) {
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1434 e = (*kseek)[k];
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1435
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1436 if (EbmlId(*e) == KaxSeekID::ClassInfos.GlobalId) {
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1437 ksid = (KaxSeekID *)e;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1438
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1439 b = ksid->GetBuffer();
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1440 s = ksid->GetSize();
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1441 if (id != NULL)
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1442 delete id;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1443 id = new EbmlId(b, s);
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1444
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1445 } else if (EbmlId(*e) == KaxSeekPosition::ClassInfos.GlobalId) {
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1446 kspos = (KaxSeekPosition *)e;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1447 seek_pos = mkv_d->segment->GetGlobalPosition(uint64(*kspos));
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1448
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1449 }
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1450 }
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1451
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1452 if ((seek_pos != 0) && (id != NULL)) {
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1453 if (*id == KaxSeekHead::ClassInfos.GlobalId)
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1454 parse_seekhead(mkv_d, seek_pos);
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1455 else if (*id == KaxCues::ClassInfos.GlobalId)
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1456 parse_cues(mkv_d, seek_pos);
11260
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1457 else if (*id == KaxChapters::ClassInfos.GlobalId)
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1458 parse_chapters(mkv_d, seek_pos);
10685
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1459 }
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1460
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1461 if (id != NULL)
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1462 delete id;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1463 }
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1464
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1465 delete kseekhead;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1466
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1467 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] \\---- [ parsing seek head ] ---------\n");
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1468 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1469
11260
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1470 extern "C" void demux_mkv_seek(demuxer_t *demuxer, float rel_seek_secs,
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1471 int flags);
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
1472
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1473 extern "C" int demux_mkv_open(demuxer_t *demuxer) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1474 unsigned char signature[4];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1475 stream_t *s;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1476 demux_packet_t *dp;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1477 mkv_demuxer_t *mkv_d;
10705
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
1478 int upper_lvl_el, exit_loop, i, vid, sid, aid;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1479 // 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
1480 EbmlElement *l0 = NULL, *l1 = NULL, *l2 = NULL;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1481 EbmlStream *es;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1482 mkv_track_t *track;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1483 sh_audio_t *sh_a;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1484 sh_video_t *sh_v;
10685
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1485 vector<uint64_t> seekheads_to_parse;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1486 vector<uint64_t> cues_to_parse;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1487 int64_t current_pos;
10844
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
1488 qt_image_description_t *idesc;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1489
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1490 #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
1491 subcp_open();
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1492 #endif
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1493
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1494 s = demuxer->stream;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1495 stream_seek(s, s->start_pos);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1496 memset(signature, 0, 4);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1497 stream_read(s, (char *)signature, 4);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1498 if ((signature[0] != 0x1A) || (signature[1] != 0x45) ||
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1499 (signature[2] != 0xDF) || (signature[3] != 0xA3))
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1500 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1501 stream_seek(s, s->start_pos);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1502
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1503 try {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1504 // structure for storing the demuxer's private data
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1505 mkv_d = (mkv_demuxer_t *)safemalloc(sizeof(mkv_demuxer_t));
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1506 memset(mkv_d, 0, sizeof(mkv_demuxer_t));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1507 mkv_d->duration = -1.0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1508
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1509 // Create the interface between MPlayer's IO system and
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1510 // libmatroska's IO system.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1511 mkv_d->in = new mpstream_io_callback(demuxer->stream);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1512 if (mkv_d->in == NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1513 free_mkv_demuxer(mkv_d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1514 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1515 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1516 mpstream_io_callback &io = *static_cast<mpstream_io_callback *>(mkv_d->in);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1517 mkv_d->es = new EbmlStream(io);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1518 if (mkv_d->es == NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1519 free_mkv_demuxer(mkv_d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1520 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1521 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1522 es = mkv_d->es;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1523
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1524 // Find the EbmlHead element. Must be the first one.
10638
9d0b8330a683 Fixes for compilation with gcc versions != 3.2.
mosu
parents: 10637
diff changeset
1525 l0 = es->FindNextID(EbmlHead::ClassInfos, 0xFFFFFFFFFFFFFFFFULL);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1526 if (l0 == NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1527 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] no head found\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1528 free_mkv_demuxer(mkv_d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1529 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1530 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1531 // Don't verify its data for now.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1532 l0->SkipData(static_cast<EbmlStream &>(*es), l0->Generic().Context);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1533 delete l0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1534 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Found the head...\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1535
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1536 // Next element must be a segment
10638
9d0b8330a683 Fixes for compilation with gcc versions != 3.2.
mosu
parents: 10637
diff changeset
1537 l0 = es->FindNextID(KaxSegment::ClassInfos, 0xFFFFFFFFFFFFFFFFULL);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1538 if (l0 == NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1539 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] but no segment :(\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1540 free_mkv_demuxer(mkv_d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1541 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1542 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1543 if (!(EbmlId(*l0) == KaxSegment::ClassInfos.GlobalId)) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1544 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] but no segment :(\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1545 free_mkv_demuxer(mkv_d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1546 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1547 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1548 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] + a segment...\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1549
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1550 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
1551 mkv_d->tc_scale = MKVD_TIMECODESCALE;
10685
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1552 mkv_d->parsed_seekheads = new vector<uint64_t>;
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1553 mkv_d->parsed_cues = new vector<uint64_t>;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1554
10705
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
1555 vid = 0;
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
1556 aid = 0;
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
1557 sid = 0;
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
1558
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1559 upper_lvl_el = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1560 exit_loop = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1561 // We've got our segment, so let's find the tracks
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1562 l1 = es->FindNextElement(l0->Generic().Context, upper_lvl_el, 0xFFFFFFFFL,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1563 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
1564 while ((l1 != NULL) && (upper_lvl_el <= 0)) {
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1565
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1566 if (EbmlId(*l1) == KaxInfo::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1567 // 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
1568 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
1569 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
1570
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1571 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] |+ segment information...\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1572
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
1573 l1->Read(*es, KaxInfo::ClassInfos.Context, upper_lvl_el, l2, true);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1574
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
1575 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
1576 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
1577 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
1578 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
1579 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
1580 } 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
1581 mkv_d->tc_scale = MKVD_TIMECODESCALE;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1582
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
1583 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
1584 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
1585 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
1586 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
1587 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
1588 }
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1589
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
1590 l1->SkipData(*es, l1->Generic().Context);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1591
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1592 } else if (EbmlId(*l1) == KaxTracks::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1593 // Yep, we've found our KaxTracks element. Now find all tracks
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1594 // 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
1595
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1596 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
1597
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1598 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
1599
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1600 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
1601
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1602 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
1603 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
1604 // We actually found a track entry :) We're happy now.
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1605
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
1606 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
1607 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
1608 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
1609 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
1610 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
1611 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
1612 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
1613 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
1614 KaxTrackLanguage *ktlanguage;
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1615 #if LIBMATROSKA_VERSION >= 000503
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1616 KaxContentEncodings *kcencodings;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1617 int kcenc_idx;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1618 vector<mkv_content_encoding_t>::iterator ce_ins_it;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1619 #endif
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1620
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
1621 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
1622
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1623 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
1624 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
1625 return 0;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1626
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
1627 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
1628 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
1629 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
1630 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
1631 track->tnum = uint32(*ktnum);
10705
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
1632 if (find_duplicate_track_by_num(mkv_d, track->tnum, 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
1633 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
1634 "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
1635 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
1636 }
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1637
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
1638 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
1639 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
1640 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
1641 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
1642 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
1643 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
1644 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
1645 "%.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
1646 (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
1647 }
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1648 }
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1649
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
1650 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
1651 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
1652 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Track type: ");
10081
0181d5fc8474 Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents: 10079
diff changeset
1653
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
1654 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
1655 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
1656 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
1657 track->type = 'a';
10705
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
1658 track->xid = aid;
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
1659 aid++;
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
1660 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
1661 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
1662 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
1663 track->type = 'v';
10705
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
1664 track->xid = vid;
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
1665 vid++;
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
1666 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
1667 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
1668 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
1669 track->type = 's';
10705
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
1670 track->xid = sid;
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
1671 sid++;
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
1672 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
1673 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
1674 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
1675 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
1676 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
1677 }
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1678 }
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1679
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
1680 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
1681 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
1682 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
1683 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
1684 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
1685
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1686 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Audio track\n");
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1687
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
1688 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
1689 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
1690 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
1691 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
1692 "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
1693 } 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
1694 track->a_sfreq = 8000.0;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1695
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
1696 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
1697 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
1698 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
1699 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
1700 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
1701 } 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
1702 track->a_channels = 1;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1703
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
1704 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
1705 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
1706 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
1707 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
1708 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
1709 }
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1710
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1711 }
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
1712
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
1713 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
1714 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
1715 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
1716 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
1717 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
1718 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
1719 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
1720
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1721 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
1722 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
1723 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
1724 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
1725 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
1726 }
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1727
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1728 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
1729 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
1730 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
1731 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
1732 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
1733 }
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1734
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1735 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
1736 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
1737 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
1738 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
1739 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
1740 }
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1741
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1742 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
1743 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
1744 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
1745 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
1746 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
1747 }
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1748
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1749 // 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
1750 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
1751 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
1752 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
1753 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
1754 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
1755 }
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1756
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1757 }
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1758
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1759 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
1760 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
1761 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
1762 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
1763 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
1764 }
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1765
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1766 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
1767 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
1768 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
1769 "%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
1770 track->private_size = kcodecpriv->GetSize();
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1771 if (track->private_size > 0)
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1772 track->private_data = safememdup(kcodecpriv->GetBuffer(),
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1773 track->private_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
1774 }
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1775
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1776 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
1777 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
1778 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
1779 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
1780 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
1781 }
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1782
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1783 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
1784 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
1785 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
1786 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
1787 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
1788 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
1789 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
1790 }
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1791
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1792 #if LIBMATROSKA_VERSION >= 000503
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1793 kcencodings = FINDFIRST(ktentry, KaxContentEncodings);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1794 if (kcencodings != NULL) {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1795 for (kcenc_idx = 0; kcenc_idx < (int)kcencodings->ListSize();
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1796 kcenc_idx++) {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1797 EbmlElement *l3;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1798
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1799 l3 = (*kcencodings)[kcenc_idx];
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1800 if (EbmlId(*l3) == KaxContentEncoding::ClassInfos.GlobalId) {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1801 KaxContentEncoding *kcenc;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1802 KaxContentEncodingOrder *ce_order;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1803 KaxContentEncodingType *ce_type;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1804 KaxContentEncodingScope *ce_scope;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1805 KaxContentCompression *ce_comp;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1806 KaxContentEncryption *ce_enc;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1807 mkv_content_encoding_t enc;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1808
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1809 memset(&enc, 0, sizeof(mkv_content_encoding_t));
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1810 kcenc = static_cast<KaxContentEncoding *>(l3);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1811
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1812 ce_order = FINDFIRST(kcenc, KaxContentEncodingOrder);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1813 if (ce_order != NULL)
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1814 enc.order = uint32(*ce_order);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1815
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1816 ce_type = FINDFIRST(kcenc, KaxContentEncodingType);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1817 if (ce_type != NULL)
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1818 enc.type = uint32(*ce_type);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1819
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1820 ce_scope = FINDFIRST(kcenc, KaxContentEncodingScope);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1821 if (ce_scope != NULL)
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1822 enc.scope = uint32(*ce_scope);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1823 else
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1824 enc.scope = 1;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1825
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1826 ce_comp = FINDFIRST(kcenc, KaxContentCompression);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1827 if (ce_comp != NULL) {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1828 KaxContentCompAlgo *cc_algo;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1829 KaxContentCompSettings *cc_settings;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1830
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1831 cc_algo = FINDFIRST(ce_comp, KaxContentCompAlgo);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1832 if (cc_algo != NULL)
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1833 enc.comp_algo = uint32(*cc_algo);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1834
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1835 cc_settings = FINDFIRST(ce_comp, KaxContentCompSettings);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1836 if (cc_settings != NULL) {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1837 enc.comp_settings =
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1838 (unsigned char *)safememdup(&binary(*cc_settings),
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1839 cc_settings->GetSize());
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1840 enc.comp_settings_len = cc_settings->GetSize();
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1841 }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1842 }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1843
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1844 ce_enc = FINDFIRST(kcenc, KaxContentEncryption);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1845 if (ce_enc != NULL) {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1846 KaxContentEncAlgo *ce_ealgo;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1847 KaxContentEncKeyID *ce_ekeyid;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1848 KaxContentSigAlgo *ce_salgo;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1849 KaxContentSigHashAlgo *ce_shalgo;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1850 KaxContentSigKeyID *ce_skeyid;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1851 KaxContentSignature *ce_signature;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1852
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1853 ce_ealgo = FINDFIRST(ce_enc, KaxContentEncAlgo);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1854 if (ce_ealgo != NULL)
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1855 enc.enc_algo = uint32(*ce_ealgo);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1856
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1857 ce_ekeyid = FINDFIRST(ce_enc, KaxContentEncKeyID);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1858 if (ce_ekeyid != NULL) {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1859 enc.enc_keyid =
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1860 (unsigned char *)safememdup(&binary(*ce_ekeyid),
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1861 ce_ekeyid->GetSize());
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1862 enc.enc_keyid_len = ce_ekeyid->GetSize();
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1863 }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1864
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1865 ce_salgo = FINDFIRST(ce_enc, KaxContentSigAlgo);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1866 if (ce_salgo != NULL)
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1867 enc.enc_algo = uint32(*ce_salgo);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1868
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1869 ce_shalgo = FINDFIRST(ce_enc, KaxContentSigHashAlgo);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1870 if (ce_shalgo != NULL)
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1871 enc.enc_algo = uint32(*ce_shalgo);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1872
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1873 ce_skeyid = FINDFIRST(ce_enc, KaxContentSigKeyID);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1874 if (ce_skeyid != NULL) {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1875 enc.sig_keyid =
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1876 (unsigned char *)safememdup(&binary(*ce_skeyid),
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1877 ce_skeyid->GetSize());
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1878 enc.sig_keyid_len = ce_skeyid->GetSize();
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1879 }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1880
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1881 ce_signature = FINDFIRST(ce_enc, KaxContentSignature);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1882 if (ce_signature != NULL) {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1883 enc.signature =
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1884 (unsigned char *)safememdup(&binary(*ce_signature),
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1885 ce_signature->GetSize());
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1886 enc.signature_len = ce_signature->GetSize();
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1887 }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1888
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1889 }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1890
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1891 ce_ins_it = track->c_encodings->begin();
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1892 while ((ce_ins_it != track->c_encodings->end()) &&
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1893 (enc.order <= (*ce_ins_it).order))
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1894 ce_ins_it++;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1895 track->c_encodings->insert(ce_ins_it, enc);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1896 }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1897 }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1898 }
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1899
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
1900 #endif
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
1901 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
1902 } // 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
1903
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1904 l1->SkipData(*es, l1->Generic().Context);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1905
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1906 } else if (EbmlId(*l1) == KaxSeekHead::ClassInfos.GlobalId) {
10685
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1907 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
1908 seekheads_to_parse.push_back(l1->GetElementPosition());
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1909 l1->SkipData(*es, l1->Generic().Context);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1910
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1911 } else if ((EbmlId(*l1) == KaxCues::ClassInfos.GlobalId) &&
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1912 !mkv_d->cues_found) {
10685
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1913 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
1914 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
1915 l1->SkipData(*es, l1->Generic().Context);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1916
11260
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1917 } else if (EbmlId(*l1) == KaxChapters::ClassInfos.GlobalId) {
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1918 parse_chapters(mkv_d, l1->GetElementPosition());
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1919 l1->SkipData(*es, l1->Generic().Context);
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
1920
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1921 } else if (EbmlId(*l1) == KaxCluster::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1922 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] |+ found cluster, headers are "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1923 "parsed completely :)\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1924 add_cluster_position(mkv_d, l1->GetElementPosition());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1925 mkv_d->saved_l1 = l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1926 exit_loop = 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1927
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1928 } 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
1929 l1->SkipData(*es, l1->Generic().Context);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1930
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
1931 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
1932 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
1933 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
1934 }
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1935
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1936 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
1937 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
1938 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
1939 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
1940 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
1941 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
1942 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
1943
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1944 } 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
1945 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
1946 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
1947 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
1948
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1949 }
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
1950
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1951 if (exit_loop) // we've found the first cluster, so get out
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1952 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1953
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
1954 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
1955 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
1956 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
1957 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
1958
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1959 } // while (l1 != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1960
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1961 if (!exit_loop) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1962 free_mkv_demuxer(mkv_d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1963 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1964 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1965
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
1966 current_pos = io.getFilePointer();
10685
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1967
10283
21972de8631d Support for files whose first timecode is not 0 (which is the case for splitted/linked files).
mosu
parents: 10273
diff changeset
1968 // 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
1969 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
1970 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
1971 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
1972 (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
1973 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
1974 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
1975 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
1976 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
1977 } else
21972de8631d Support for files whose first timecode is not 0 (which is the case for splitted/linked files).
mosu
parents: 10273
diff changeset
1978 mkv_d->first_tc = 0;
10685
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1979
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1980 // Parse all cues and seek heads
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1981 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
1982 parse_cues(mkv_d, cues_to_parse[i]);
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1983 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
1984 parse_seekhead(mkv_d, seekheads_to_parse[i]);
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
1985
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
1986 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
1987
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1988 } catch (exception &ex) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1989 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] caught exception\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1990 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1991 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1992
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1993 if (!check_track_information(mkv_d)) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1994 free_mkv_demuxer(mkv_d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1995 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1996 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1997
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1998 track = NULL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
1999 if (demuxer->video->id == -1) { // Automatically select a video track.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2000 // Search for a video track that has the 'default' flag set.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2001 for (i = 0; i < mkv_d->num_tracks; i++)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2002 if ((mkv_d->tracks[i]->type == 'v') && mkv_d->tracks[i]->ok &&
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2003 mkv_d->tracks[i]->default_track) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2004 track = mkv_d->tracks[i];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2005 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2006 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2007
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2008 if (track == NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2009 // No track has the 'default' flag set - let's take the first video
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2010 // track.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2011 for (i = 0; i < mkv_d->num_tracks; i++)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2012 if ((mkv_d->tracks[i]->type == 'v') && mkv_d->tracks[i]->ok) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2013 track = mkv_d->tracks[i];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2014 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2015 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2016 } else if (demuxer->video->id != -2) // -2 = no video at all
10705
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
2017 track = find_track_by_num(mkv_d, demuxer->video->id, 'v');
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2018
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2019 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
2020 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
2021
10844
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2022 idesc = NULL;
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2023 bih = (BITMAPINFOHEADER *)safemalloc(track->private_size);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2024 memset(bih, 0, sizeof(BITMAPINFOHEADER));
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
2025
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2026 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
2027 BITMAPINFOHEADER *src;
10133
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2028 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
2029 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
2030 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
2031 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
2032 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
2033 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
2034 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
2035 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
2036 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
2037 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
2038 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
2039 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
2040 memcpy((char *)bih + sizeof(BITMAPINFOHEADER),
10133
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2041 (char *)src + sizeof(BITMAPINFOHEADER),
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2042 track->private_size - sizeof(BITMAPINFOHEADER));
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2043
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
2044 } 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
2045 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
2046 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
2047 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
2048 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
2049 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
2050
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
2051 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
2052 (!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
2053 !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
2054 !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
2055 !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
2056 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
2057 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
2058 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
2059
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
2060 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
2061 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
2062
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
2063 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
2064 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
2065 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
2066 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
2067 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
2068 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
2069 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
2070 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
2071 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
2072 ((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
2073 ((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
2074
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
2075 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
2076 (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
2077 // 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
2078 ((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
2079 ((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
2080 } 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
2081 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
2082 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
2083
10844
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2084 #if defined(USE_QTX_CODECS)
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2085 } else if ((track->private_size >= sizeof(qt_image_description_t)) &&
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2086 (!strcmp(track->codec_id, MKV_V_QUICKTIME))) {
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2087 idesc = (qt_image_description_t *)track->private_data;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2088 idesc->id_size = get_uint32_be(&idesc->id_size);
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2089 idesc->codec_type = get_uint32(&idesc->codec_type);
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2090 idesc->version = get_uint16_be(&idesc->version);
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2091 idesc->revision = get_uint16_be(&idesc->revision);
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2092 idesc->vendor = get_uint32_be(&idesc->vendor);
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2093 idesc->temporal_quality = get_uint32_be(&idesc->temporal_quality);
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2094 idesc->spatial_quality = get_uint32_be(&idesc->spatial_quality);
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2095 idesc->width = get_uint16_be(&idesc->width);
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2096 idesc->height = get_uint16_be(&idesc->height);
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2097 idesc->horizontal_resolution =
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2098 get_uint32_be(&idesc->horizontal_resolution);
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2099 idesc->vertical_resolution =
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2100 get_uint32_be(&idesc->vertical_resolution);
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2101 idesc->data_size = get_uint32_be(&idesc->data_size);
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2102 idesc->frame_count = get_uint16_be(&idesc->frame_count);
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2103 idesc->depth = get_uint16_be(&idesc->depth);
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2104 idesc->color_table_id = get_uint16_be(&idesc->color_table_id);
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2105 bih->biPlanes = 1;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2106 bih->biCompression = idesc->codec_type;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2107 #endif // defined(USE_QTX_CODECS)
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2108
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
2109 } 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
2110 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
2111 "(%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
2112 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
2113 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
2114 }
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
2115 }
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
2116
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
2117 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
2118 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
2119 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
2120
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
2121 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
2122 sh_v->bih = bih;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2123 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
2124 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
2125 track->v_frate = 25.0;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2126 sh_v->fps = track->v_frate;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2127 sh_v->frametime = 1 / track->v_frate;
10081
0181d5fc8474 Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents: 10079
diff changeset
2128 sh_v->disp_w = track->v_width;
0181d5fc8474 Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents: 10079
diff changeset
2129 sh_v->disp_h = track->v_height;
0181d5fc8474 Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents: 10079
diff changeset
2130 sh_v->aspect = (float)track->v_dwidth / (float)track->v_dheight;
10844
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2131 if (idesc != NULL)
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2132 sh_v->ImageDesc = idesc;
10081
0181d5fc8474 Support for aspect ratio set via DisplayWidth/DisplayHeight.
mosu
parents: 10079
diff changeset
2133 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Aspect: %f\n", sh_v->aspect);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2134
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2135 demuxer->video->id = track->tnum;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2136 demuxer->video->sh = sh_v;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2137 sh_v->ds = demuxer->video;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2138
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2139 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
2140 } 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
2141 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
2142
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2143 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2144 mp_msg(MSGT_DEMUX, MSGL_INFO, "[mkv] No video track found/wanted.\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2145 demuxer->video->id = -2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2146 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2147
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2148 track = NULL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2149 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
2150 // 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
2151 if (audio_lang != NULL) {
531b00ad6f2d Support for selecting the audio track in Matroska files via -alang.
mosu
parents: 10149
diff changeset
2152 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
2153 }
531b00ad6f2d Support for selecting the audio track in Matroska files via -alang.
mosu
parents: 10149
diff changeset
2154 if (track == NULL)
531b00ad6f2d Support for selecting the audio track in Matroska files via -alang.
mosu
parents: 10149
diff changeset
2155 // 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
2156 // 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
2157 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
2158 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
2159 mkv_d->tracks[i]->default_track) {
531b00ad6f2d Support for selecting the audio track in Matroska files via -alang.
mosu
parents: 10149
diff changeset
2160 track = mkv_d->tracks[i];
531b00ad6f2d Support for selecting the audio track in Matroska files via -alang.
mosu
parents: 10149
diff changeset
2161 break;
531b00ad6f2d Support for selecting the audio track in Matroska files via -alang.
mosu
parents: 10149
diff changeset
2162 }
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2163
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2164 if (track == NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2165 // No track has the 'default' flag set - let's take the first audio
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2166 // track.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2167 for (i = 0; i < mkv_d->num_tracks; i++)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2168 if ((mkv_d->tracks[i]->type == 'a') && mkv_d->tracks[i]->ok) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2169 track = mkv_d->tracks[i];
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 } else if (demuxer->audio->id != -2) // -2 = no audio at all
10705
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
2173 track = find_track_by_num(mkv_d, demuxer->audio->id, 'a');
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2174
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2175 if (track) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2176 mp_msg(MSGT_DEMUX, MSGL_INFO, "[mkv] Will play audio track %u\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2177 track->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2178 sh_a = new_sh_audio(demuxer, track->tnum);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2179
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2180 demuxer->audio->id = track->tnum;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2181 demuxer->audio->sh = sh_a;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2182 sh_a->ds = demuxer->audio;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2183
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2184 mkv_d->audio = track;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2185
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2186 if (track->ms_compat)
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2187 sh_a->wf = (WAVEFORMATEX *)safememdup(track->private_data,
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2188 track->private_size);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2189 else {
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2190 sh_a->wf = (WAVEFORMATEX *)safemalloc(sizeof(WAVEFORMATEX));
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2191 memset(sh_a->wf, 0, sizeof(WAVEFORMATEX));
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2192 }
10125
252428ac7978 Added support for AAC.
mosu
parents: 10105
diff changeset
2193 sh_a->format = track->a_formattag;
252428ac7978 Added support for AAC.
mosu
parents: 10105
diff changeset
2194 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
2195 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
2196 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
2197 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
2198 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
2199 sh_a->samplesize = track->a_bps / 8;
11155
4a21e1672c91 Support for MP2 audio.
mosu
parents: 11154
diff changeset
2200 if (!strcmp(track->codec_id, MKV_A_MP3) ||
4a21e1672c91 Support for MP2 audio.
mosu
parents: 11154
diff changeset
2201 !strcmp(track->codec_id, MKV_A_MP2)) {
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2202 sh_a->wf->nAvgBytesPerSec = 16000;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2203 sh_a->wf->nBlockAlign = 1152;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2204 sh_a->wf->wBitsPerSample = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2205 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
2206
11114
d8ddd7727084 More liberal codec id recognition for AC3 codecs (needed for transcoded DNET from RM).
mosu
parents: 10984
diff changeset
2207 } else if (!strncmp(track->codec_id, MKV_A_AC3, strlen(MKV_A_AC3))) {
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2208 sh_a->wf->nAvgBytesPerSec = 16000;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2209 sh_a->wf->nBlockAlign = 1536;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2210 sh_a->wf->wBitsPerSample = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2211 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
2212
10844
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2213 } else if (!strcmp(track->codec_id, MKV_A_PCM) ||
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2214 !strcmp(track->codec_id, MKV_A_PCM_BE)) {
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2215 sh_a->wf->nAvgBytesPerSec = sh_a->channels * sh_a->samplerate * 2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2216 sh_a->wf->nBlockAlign = sh_a->wf->nAvgBytesPerSec;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2217 sh_a->wf->wBitsPerSample = track->a_bps;
10844
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2218 if (!strcmp(track->codec_id, MKV_A_PCM_BE))
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2219 sh_a->format = mmioFOURCC('t', 'w', 'o', 's');
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2220
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2221 } else if (!strcmp(track->codec_id, MKV_A_QDMC) ||
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2222 !strcmp(track->codec_id, MKV_A_QDMC2)) {
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2223 sh_a->wf->wBitsPerSample = track->a_bps;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2224 sh_a->wf->nAvgBytesPerSec = 16000;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2225 sh_a->wf->nBlockAlign = 1486;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2226 track->fix_i_bps = true;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2227 track->qt_last_a_pts = 0.0;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2228 if (track->private_data != NULL) {
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2229 sh_a->codecdata = (unsigned char *)safememdup(track->private_data,
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2230 track->private_size);
10844
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2231 sh_a->codecdata_len = track->private_size;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2232 }
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2233 if (!strcmp(track->codec_id, MKV_A_QDMC))
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2234 sh_a->format = mmioFOURCC('Q', 'D', 'M', 'C');
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2235 else
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2236 sh_a->format = mmioFOURCC('Q', 'D', 'M', '2');
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
2237
10133
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2238 } 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
2239 int profile, srate_idx;
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2240
10125
252428ac7978 Added support for AAC.
mosu
parents: 10105
diff changeset
2241 sh_a->wf->nAvgBytesPerSec = 16000;
252428ac7978 Added support for AAC.
mosu
parents: 10105
diff changeset
2242 sh_a->wf->nBlockAlign = 1024;
252428ac7978 Added support for AAC.
mosu
parents: 10105
diff changeset
2243 sh_a->wf->wBitsPerSample = 0;
252428ac7978 Added support for AAC.
mosu
parents: 10105
diff changeset
2244 sh_a->samplesize = 0;
10133
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2245
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2246 // 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
2247 // A_AAC/MPEG2/MAIN
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2248 // 0123456789012345
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2249 if (!strcmp(&track->codec_id[12], "MAIN"))
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2250 profile = 0;
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2251 else if (!strcmp(&track->codec_id[12], "LC"))
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2252 profile = 1;
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2253 else if (!strcmp(&track->codec_id[12], "SSR"))
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2254 profile = 2;
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2255 else
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2256 profile = 3;
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2257 if (92017 <= sh_a->samplerate)
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2258 srate_idx = 0;
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2259 else if (75132 <= sh_a->samplerate)
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2260 srate_idx = 1;
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2261 else if (55426 <= sh_a->samplerate)
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2262 srate_idx = 2;
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2263 else if (46009 <= sh_a->samplerate)
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2264 srate_idx = 3;
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2265 else if (37566 <= sh_a->samplerate)
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2266 srate_idx = 4;
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2267 else if (27713 <= sh_a->samplerate)
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2268 srate_idx = 5;
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2269 else if (23004 <= sh_a->samplerate)
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2270 srate_idx = 6;
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2271 else if (18783 <= sh_a->samplerate)
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2272 srate_idx = 7;
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2273 else if (13856 <= sh_a->samplerate)
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2274 srate_idx = 8;
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2275 else if (11502 <= sh_a->samplerate)
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2276 srate_idx = 9;
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2277 else if (9391 <= sh_a->samplerate)
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2278 srate_idx = 10;
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2279 else
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2280 srate_idx = 11;
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2281
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2282 sh_a->codecdata = (unsigned char *)safemalloc(2);
10133
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2283 sh_a->codecdata_len = 2;
d9c9422887ca Endian fixes and proper support for headerless AAC streams.
mosu
parents: 10125
diff changeset
2284 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
2285 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
2286
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2287 } else if (!strcmp(track->codec_id, MKV_A_VORBIS)) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2288 for (i = 0; i < 3; i++) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2289 dp = new_demux_packet(track->header_sizes[i]);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2290 memcpy(dp->buffer, track->headers[i], track->header_sizes[i]);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2291 dp->pts = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2292 dp->flags = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2293 ds_add_packet(demuxer->audio, dp);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2294 }
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
2295
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
2296 } 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
2297 !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
2298 // 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
2299 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
2300 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
2301 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
2302 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
2303
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
2304 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
2305 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
2306
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
2307 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
2308 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
2309 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
2310
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
2311 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
2312
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
2313 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
2314 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
2315 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
2316 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
2317 } 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
2318 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
2319
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
2320 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
2321 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
2322 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
2323 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
2324 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
2325 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
2326 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
2327 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
2328 ((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
2329 ((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
2330 ((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
2331 ((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
2332 ((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
2333 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
2334
dd64e1fe919d Better support for RealVideo/RealAudio in Matroska. Includes the timestamp fixes from demux_real.c. Seeking is working. Added Matroska to the formats with variable FPS in video.c.
mosu
parents: 10410
diff changeset
2335 track->realmedia = true;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2336 }
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
2337
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2338 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2339 mp_msg(MSGT_DEMUX, MSGL_INFO, "[mkv] No audio track found/wanted.\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2340 demuxer->audio->id = -2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2341 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2342
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2343 // DO NOT automatically select a subtitle track and behave like DVD
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2344 // 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
2345 track = NULL;
4c4c2761643c Proper key frame reporting. Proper handling of "no subtitles wanted".
mosu
parents: 10060
diff changeset
2346 if (demuxer->sub->id >= 0)
10705
4079bc9b15f9 Track selection uses the n-th audio/subtitle/video track as the ID, not the n-th track overall. All tracks are listed upon opening of the file along with their -aid/-sid etc.
mosu
parents: 10685
diff changeset
2347 track = find_track_by_num(mkv_d, demuxer->sub->id, 's');
10073
4c4c2761643c Proper key frame reporting. Proper handling of "no subtitles wanted".
mosu
parents: 10060
diff changeset
2348 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
2349 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
2350 if (track) {
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2351 if (!strcmp(track->codec_id, MKV_S_VOBSUB)) {
11154
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2352 mp_msg(MSGT_DEMUX, MSGL_INFO, "[mkv] Will display subtitle track %u\n",
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2353 track->tnum);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2354 mkv_d->subs_track = track;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2355 mkv_d->subtitle_type = MKV_SUBTYPE_VOBSUB;
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2356 demuxer->sub->sh = (mkv_sh_sub_t *)safememdup(&track->sh_sub,
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2357 sizeof(mkv_sh_sub_t));
11154
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2358 demuxer->sub->id = track->xid;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2359
11268
attila
parents: 11260
diff changeset
2360 } else if (!(strcmp(track->codec_id, MKV_S_TEXTASCII) &&
11154
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2361 strcmp(track->codec_id, MKV_S_TEXTUTF8) &&
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2362 strcmp(track->codec_id, MKV_S_TEXTSSA) &&
11268
attila
parents: 11260
diff changeset
2363 strcmp(track->codec_id, "S_SSA")))
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
2364 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
2365 "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
2366 else {
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
2367 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
2368 track->tnum);
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
2369 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
2370 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
2371 for (i = 0; i < SUB_MAX_TEXT; i++)
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2372 mkv_d->subs.text[i] = (char *)safemalloc(256);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2373
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
2374 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
2375 sub_utf8 = 1; // Force UTF-8 conversion.
10984
e5f2765c6d80 Backwards compatibility fix for old SSA CodecIDs.
mosu
parents: 10930
diff changeset
2376 if (!strcmp(track->codec_id, MKV_S_TEXTSSA) ||
e5f2765c6d80 Backwards compatibility fix for old SSA CodecIDs.
mosu
parents: 10930
diff changeset
2377 !strcmp(track->codec_id, "S_SSA")) {
10845
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2378 mkv_d->subtitle_type = MKV_SUBTYPE_SSA;
10861
59e3d641c48c Marked SSA subs as UTF-8. Better newline handling for SSA subs. Patch by Tristan <z80@oceanfree.net>.
mosu
parents: 10860
diff changeset
2379 sub_utf8 = 1;
59e3d641c48c Marked SSA subs as UTF-8. Better newline handling for SSA subs. Patch by Tristan <z80@oceanfree.net>.
mosu
parents: 10860
diff changeset
2380 } else
10845
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2381 mkv_d->subtitle_type = MKV_SUBTYPE_TEXT;
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
2382 } else
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
2383 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
2384 "subtitle track with the id %u.\n", demuxer->sub->id);
11154
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2385 demuxer->sub->sh = NULL;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2386 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2387 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2388
11260
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2389 demuxer->priv = mkv_d;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2390
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2391 if (mkv_d->chapters != NULL) {
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2392 for (i = 0; i < (int)mkv_d->chapters->size(); i++) {
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2393 (*mkv_d->chapters)[i].start -= mkv_d->first_tc;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2394 (*mkv_d->chapters)[i].end -= mkv_d->first_tc;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2395 }
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2396 if ((dvd_last_chapter > 0) &&
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2397 (dvd_last_chapter <= (int)mkv_d->chapters->size())) {
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2398 if ((*mkv_d->chapters)[dvd_last_chapter - 1].end != 0)
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2399 mkv_d->stop_timecode = (*mkv_d->chapters)[dvd_last_chapter - 1].end;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2400 else if ((dvd_last_chapter + 1) <= (int)mkv_d->chapters->size())
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2401 mkv_d->stop_timecode = (*mkv_d->chapters)[dvd_last_chapter].start;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2402 }
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2403 }
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2404
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2405 if (s->end_pos == 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2406 demuxer->seekable = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2407 else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2408 demuxer->movi_start = s->start_pos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2409 demuxer->movi_end = s->end_pos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2410 demuxer->seekable = 1;
11260
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2411 if ((dvd_chapter != 1) && (mkv_d->chapters != NULL) &&
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2412 (dvd_chapter <= (int)mkv_d->chapters->size()))
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2413 demux_mkv_seek(demuxer, (float)(*mkv_d->chapters)[dvd_chapter - 1].start
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2414 / 1000.0, 1);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2415 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2416
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2417 return 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2418 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2419
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
2420 // 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
2421 #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
2422 #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
2423
dd64e1fe919d Better support for RealVideo/RealAudio in Matroska. Includes the timestamp fixes from demux_real.c. Seeking is working. Added Matroska to the formats with variable FPS in video.c.
mosu
parents: 10410
diff changeset
2424 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
2425 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
2426 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
2427 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
2428 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
2429 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
2430 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
2431
dd64e1fe919d Better support for RealVideo/RealAudio in Matroska. Includes the timestamp fixes from demux_real.c. Seeking is working. Added Matroska to the formats with variable FPS in video.c.
mosu
parents: 10410
diff changeset
2432 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
2433 !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
2434
dd64e1fe919d Better support for RealVideo/RealAudio in Matroska. Includes the timestamp fixes from demux_real.c. Seeking is working. Added Matroska to the formats with variable FPS in video.c.
mosu
parents: 10410
diff changeset
2435 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
2436 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
2437 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
2438 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
2439 }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
2440 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
2441 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
2442 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
2443 }
dd64e1fe919d Better support for RealVideo/RealAudio in Matroska. Includes the timestamp fixes from demux_real.c. Seeking is working. Added Matroska to the formats with variable FPS in video.c.
mosu
parents: 10410
diff changeset
2444 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
2445 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
2446 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
2447 // 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
2448 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
2449 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
2450 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
2451 } 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
2452 // 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
2453 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
2454 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
2455 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
2456 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
2457 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
2458 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
2459 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
2460 }
dd64e1fe919d Better support for RealVideo/RealAudio in Matroska. Includes the timestamp fixes from demux_real.c. Seeking is working. Added Matroska to the formats with variable FPS in video.c.
mosu
parents: 10410
diff changeset
2461 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
2462 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
2463 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
2464 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
2465 }
dd64e1fe919d Better support for RealVideo/RealAudio in Matroska. Includes the timestamp fixes from demux_real.c. Seeking is working. Added Matroska to the formats with variable FPS in video.c.
mosu
parents: 10410
diff changeset
2466 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
2467 "%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
2468 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
2469 }
dd64e1fe919d Better support for RealVideo/RealAudio in Matroska. Includes the timestamp fixes from demux_real.c. Seeking is working. Added Matroska to the formats with variable FPS in video.c.
mosu
parents: 10410
diff changeset
2470 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
2471 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
2472
dd64e1fe919d Better support for RealVideo/RealAudio in Matroska. Includes the timestamp fixes from demux_real.c. Seeking is working. Added Matroska to the formats with variable FPS in video.c.
mosu
parents: 10410
diff changeset
2473 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
2474 }
dd64e1fe919d Better support for RealVideo/RealAudio in Matroska. Includes the timestamp fixes from demux_real.c. Seeking is working. Added Matroska to the formats with variable FPS in video.c.
mosu
parents: 10410
diff changeset
2475
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2476 static void handle_realvideo(demuxer_t *demuxer, unsigned char *data,
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2477 uint32_t size, bool keyframe, int &found_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
2478 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
2479 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
2480 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
2481 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
2482 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
2483
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
2484 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
2485 ds = demuxer->video;
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2486 chunks = data[0];
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2487 isize = size - 1 - (chunks + 1) * 8;
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
2488 dp = new_demux_packet(sizeof(dp_hdr_t) + isize + 8 * (chunks + 1));
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2489 memcpy(&dp->buffer[sizeof(dp_hdr_t)], &data[1 + (chunks + 1) * 8], isize);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2490 memcpy(&dp->buffer[sizeof(dp_hdr_t) + isize], &data[1], (chunks + 1) * 8);
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
2491 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
2492 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
2493 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
2494 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
2495 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
2496
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
2497 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
2498 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
2499 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
2500 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
2501 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
2502 } 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
2503 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
2504 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
2505 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
2506 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
2507
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
2508 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
2509
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
2510 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
2511 }
c2fc1c310699 Necessary changes for the upcoming libebml/libmatroska 0.5.0. Implemented support for RealAudio and RealVideo inside Matroska.
mosu
parents: 10283
diff changeset
2512
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2513 static void handle_realaudio(demuxer_t *demuxer, unsigned char *data,
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2514 uint32_t size, 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
2515 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
2516 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
2517
dd64e1fe919d Better support for RealVideo/RealAudio in Matroska. Includes the timestamp fixes from demux_real.c. Seeking is working. Added Matroska to the formats with variable FPS in video.c.
mosu
parents: 10410
diff changeset
2518 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
2519
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2520 dp = new_demux_packet(size);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2521 memcpy(dp->buffer, data, size);
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
2522 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
2523 !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
2524 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
2525 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
2526 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
2527 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
2528
dd64e1fe919d Better support for RealVideo/RealAudio in Matroska. Includes the timestamp fixes from demux_real.c. Seeking is working. Added Matroska to the formats with variable FPS in video.c.
mosu
parents: 10410
diff changeset
2529 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
2530 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
2531
dd64e1fe919d Better support for RealVideo/RealAudio in Matroska. Includes the timestamp fixes from demux_real.c. Seeking is working. Added Matroska to the formats with variable FPS in video.c.
mosu
parents: 10410
diff changeset
2532 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
2533
dd64e1fe919d Better support for RealVideo/RealAudio in Matroska. Includes the timestamp fixes from demux_real.c. Seeking is working. Added Matroska to the formats with variable FPS in video.c.
mosu
parents: 10410
diff changeset
2534 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
2535 }
dd64e1fe919d Better support for RealVideo/RealAudio in Matroska. Includes the timestamp fixes from demux_real.c. Seeking is working. Added Matroska to the formats with variable FPS in video.c.
mosu
parents: 10410
diff changeset
2536
11154
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2537 #define mpeg_read(buf, num) _mpeg_read(srcbuf, size, srcpos, buf, num)
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2538 static uint32_t _mpeg_read(unsigned char *srcbuf, uint32_t size,
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2539 uint32_t &srcpos, unsigned char *dstbuf,
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2540 uint32_t num) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2541 uint32_t real_num;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2542
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2543 if ((srcpos + num) >= size)
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2544 real_num = size - srcpos;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2545 else
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2546 real_num = num;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2547 memcpy(dstbuf, &srcbuf[srcpos], real_num);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2548 srcpos += real_num;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2549
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2550 return real_num;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2551 }
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2552
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2553 #define mpeg_getc() _mpeg_getch(srcbuf, size, srcpos)
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2554 static int _mpeg_getch(unsigned char *srcbuf, uint32_t size,
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2555 uint32_t &srcpos) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2556 unsigned char c;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2557
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2558 if (mpeg_read(&c, 1) != 1)
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2559 return -1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2560 return (int)c;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2561 }
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2562
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2563 #define mpeg_seek(b, w) _mpeg_seek(size, srcpos, b, w)
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2564 static int _mpeg_seek(uint32_t size, uint32_t &srcpos, uint32_t num,
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2565 int whence) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2566 uint32_t new_pos;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2567
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2568 if (whence == SEEK_SET)
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2569 new_pos = num;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2570 else if (whence == SEEK_CUR)
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2571 new_pos = srcpos + num;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2572 else
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2573 abort();
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2574
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2575 if (new_pos >= size) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2576 srcpos = size;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2577 return 1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2578 }
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2579
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2580 srcpos = new_pos;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2581 return 0;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2582 }
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2583
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2584 #define mpeg_tell() srcpos
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2585
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2586 // Adopted from vobsub.c
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2587 static int mpeg_run(demuxer_t *demuxer, unsigned char *srcbuf, uint32_t size) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2588 uint32_t len, idx, version, srcpos, packet_size;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2589 int c, aid;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2590 float pts;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2591 /* Goto start of a packet, it starts with 0x000001?? */
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2592 const unsigned char wanted[] = { 0, 0, 1 };
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2593 unsigned char buf[5];
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2594 demux_packet_t *dp;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2595 demux_stream_t *ds;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2596 mkv_demuxer_t *mkv_d;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2597
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2598 mkv_d = (mkv_demuxer_t *)demuxer->priv;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2599 ds = demuxer->sub;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2600
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2601 srcpos = 0;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2602 packet_size = 0;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2603 while (1) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2604 if (mpeg_read(buf, 4) != 4)
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2605 return -1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2606 while (memcmp(buf, wanted, sizeof(wanted)) != 0) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2607 c = mpeg_getc();
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2608 if (c < 0)
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2609 return -1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2610 memmove(buf, buf + 1, 3);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2611 buf[3] = c;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2612 }
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2613 switch (buf[3]) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2614 case 0xb9: /* System End Code */
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2615 return 0;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2616 break;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2617
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2618 case 0xba: /* Packet start code */
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2619 c = mpeg_getc();
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2620 if (c < 0)
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2621 return -1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2622 if ((c & 0xc0) == 0x40)
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2623 version = 4;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2624 else if ((c & 0xf0) == 0x20)
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2625 version = 2;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2626 else {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2627 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] VobSub: Unsupported MPEG "
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2628 "version: 0x%02x\n", c);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2629 return -1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2630 }
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2631
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2632 if (version == 4) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2633 if (mpeg_seek(9, SEEK_CUR))
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2634 return -1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2635 } else if (version == 2) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2636 if (mpeg_seek(7, SEEK_CUR))
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2637 return -1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2638 } else
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2639 abort();
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2640 break;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2641
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2642 case 0xbd: /* packet */
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2643 if (mpeg_read(buf, 2) != 2)
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2644 return -1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2645 len = buf[0] << 8 | buf[1];
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2646 idx = mpeg_tell();
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2647 c = mpeg_getc();
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2648 if (c < 0)
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2649 return -1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2650 if ((c & 0xC0) == 0x40) { /* skip STD scale & size */
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2651 if (mpeg_getc() < 0)
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2652 return -1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2653 c = mpeg_getc();
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2654 if (c < 0)
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2655 return -1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2656 }
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2657 if ((c & 0xf0) == 0x20) { /* System-1 stream timestamp */
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2658 /* Do we need this? */
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2659 abort();
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2660 } else if ((c & 0xf0) == 0x30) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2661 /* Do we need this? */
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2662 abort();
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2663 } else if ((c & 0xc0) == 0x80) { /* System-2 (.VOB) stream */
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2664 uint32_t pts_flags, hdrlen, dataidx;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2665 c = mpeg_getc();
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2666 if (c < 0)
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2667 return -1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2668 pts_flags = c;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2669 c = mpeg_getc();
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2670 if (c < 0)
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2671 return -1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2672 hdrlen = c;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2673 dataidx = mpeg_tell() + hdrlen;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2674 if (dataidx > idx + len) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2675 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] VobSub: Invalid header "
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2676 "length: %d (total length: %d, idx: %d, dataidx: %d)\n",
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2677 hdrlen, len, idx, dataidx);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2678 return -1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2679 }
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2680 if ((pts_flags & 0xc0) == 0x80) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2681 if (mpeg_read(buf, 5) != 5)
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2682 return -1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2683 if (!(((buf[0] & 0xf0) == 0x20) && (buf[0] & 1) && (buf[2] & 1) &&
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2684 (buf[4] & 1))) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2685 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] VobSub PTS error: 0x%02x "
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2686 "%02x%02x %02x%02x \n",
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2687 buf[0], buf[1], buf[2], buf[3], buf[4]);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2688 pts = 0;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2689 } else
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2690 pts = ((buf[0] & 0x0e) << 29 | buf[1] << 22 |
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2691 (buf[2] & 0xfe) << 14 | buf[3] << 7 | (buf[4] >> 1));
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2692 } else /* if ((pts_flags & 0xc0) == 0xc0) */ {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2693 /* what's this? */
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2694 /* abort(); */
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2695 }
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2696 mpeg_seek(dataidx, SEEK_SET);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2697 aid = mpeg_getc();
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2698 if (aid < 0) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2699 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] VobSub: Bogus aid %d\n", aid);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2700 return -1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2701 }
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2702 packet_size = len - ((unsigned int)mpeg_tell() - idx);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2703
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2704 dp = new_demux_packet(packet_size);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2705 dp->flags = 1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2706 dp->pts = mkv_d->last_pts;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2707 if (mpeg_read(dp->buffer, packet_size) != packet_size) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2708 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] VobSub: mpeg_read failure");
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2709 packet_size = 0;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2710 return -1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2711 }
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2712 ds_add_packet(ds, dp);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2713 idx = len;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2714 }
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2715 break;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2716
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2717 case 0xbe: /* Padding */
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2718 if (mpeg_read(buf, 2) != 2)
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2719 return -1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2720 len = buf[0] << 8 | buf[1];
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2721 if ((len > 0) && mpeg_seek(len, SEEK_CUR))
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2722 return -1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2723 break;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2724
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2725 default:
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2726 if ((0xc0 <= buf[3]) && (buf[3] < 0xf0)) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2727 /* MPEG audio or video */
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2728 if (mpeg_read(buf, 2) != 2)
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2729 return -1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2730 len = (buf[0] << 8) | buf[1];
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2731 if ((len > 0) && mpeg_seek(len, SEEK_CUR))
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2732 return -1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2733
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2734 }
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2735 else {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2736 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] VobSub: unknown header "
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2737 "0x%02X%02X%02X%02X\n", buf[0], buf[1], buf[2], buf[3]);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2738 return -1;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2739 }
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2740 }
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2741 }
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2742 return 0;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2743 }
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2744
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2745 extern "C" int demux_mkv_fill_buffer(demuxer_t *d) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2746 demux_packet_t *dp;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2747 demux_stream_t *ds;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2748 mkv_demuxer_t *mkv_d;
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2749 mkv_track_t *t;
10845
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2750 int upper_lvl_el, exit_loop, found_data, i, linei, sl;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2751 char *texttmp;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2752 // 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
2753 EbmlElement *l0 = NULL, *l1 = NULL, *l2 = NULL, *l3 = NULL;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2754 EbmlStream *es;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2755 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
2756 int64_t block_duration, block_bref, block_fref;
10845
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2757 bool use_this_block, lines_cut;
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
2758 float current_pts;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2759
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2760 mkv_d = (mkv_demuxer_t *)d->priv;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2761 es = mkv_d->es;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2762 l0 = mkv_d->segment;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2763
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2764 // End of stream
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2765 if (mkv_d->saved_l1 == NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2766 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2767
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2768 exit_loop = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2769 upper_lvl_el = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2770 l1 = mkv_d->saved_l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2771 mkv_d->saved_l1 = NULL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2772 found_data = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2773 try {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2774 // The idea is not to handle a complete KaxCluster with each call to
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2775 // 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
2776 while ((l1 != NULL) && (upper_lvl_el <= 0)) {
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2777
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2778 if (EbmlId(*l1) == KaxCluster::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2779 mkv_d->cluster = (KaxCluster *)l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2780 if (found_data) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2781 mkv_d->saved_l1 = l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2782 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2783 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2784
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2785 if (mkv_d->saved_l2 != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2786 l2 = mkv_d->saved_l2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2787 mkv_d->saved_l2 = NULL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2788 } else
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2789 l2 = es->FindNextElement(l1->Generic().Context, upper_lvl_el,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2790 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
2791 while ((l2 != NULL) && (upper_lvl_el <= 0)) {
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2792
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
2793 // Handle at least one data packets in one call to
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2794 // demux_mkv_fill_buffer - but abort if we have found that.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2795 if (found_data >= 1) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2796 mkv_d->saved_l2 = l2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2797 mkv_d->saved_l1 = l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2798 exit_loop = 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2799 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2800 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2801
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2802 if (EbmlId(*l2) == KaxClusterTimecode::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2803 KaxClusterTimecode &ctc = *static_cast<KaxClusterTimecode *>(l2);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2804 ctc.ReadData(es->I_O());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2805 mkv_d->cluster_tc = uint64(ctc);
10273
02c2c05b7da6 Updates needed for libebml/libmatroska 0.4.4
mosu
parents: 10167
diff changeset
2806 #if LIBEBML_VERSION >= 000404
02c2c05b7da6 Updates needed for libebml/libmatroska 0.4.4
mosu
parents: 10167
diff changeset
2807 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
2808 #else
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2809 mkv_d->cluster->InitTimecode(mkv_d->cluster_tc);
10273
02c2c05b7da6 Updates needed for libebml/libmatroska 0.4.4
mosu
parents: 10167
diff changeset
2810 #endif // LIBEBML_VERSION
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2811
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2812 } else if (EbmlId(*l2) == KaxBlockGroup::ClassInfos.GlobalId) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2813
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
2814 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
2815 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
2816 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
2817
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2818 block = NULL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2819 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
2820 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
2821 block_fref = 0;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2822
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
2823 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
2824 true);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2825
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
2826 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
2827 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
2828 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
2829
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
2830 kblock = FINDFIRST(l2, KaxBlock);
11260
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2831 if (kblock != 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
2832 kblock->SetParent(*mkv_d->cluster);
11260
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2833 if ((mkv_d->stop_timecode > 0) &&
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2834 ((kblock->GlobalTimecode() / 1000000 - mkv_d->first_tc) >=
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2835 mkv_d->stop_timecode)) {
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2836 delete l2;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2837 return 0;
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2838 }
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
2839 }
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2840
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
2841 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
2842 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
2843 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
2844 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
2845 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
2846 block_fref = int64(*krefblock);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2847
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
2848 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
2849 }
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
2850
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
2851 if (kblock != NULL) {
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2852 // Clear the subtitles if they're obsolete now.
10845
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2853 lines_cut = false;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2854 for (linei = 0; linei < mkv_d->subs.lines; linei++) {
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2855 if (mkv_d->clear_subs_at[linei] <=
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2856 (kblock->GlobalTimecode() / 1000000 - mkv_d->first_tc)) {
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2857 sl = linei;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2858 texttmp = mkv_d->subs.text[sl];
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2859 while (sl < mkv_d->subs.lines) {
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2860 mkv_d->subs.text[sl] = mkv_d->subs.text[sl + 1];
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2861 mkv_d->clear_subs_at[sl] = mkv_d->clear_subs_at[sl + 1];
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2862 sl++;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2863 }
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2864 mkv_d->subs.text[sl] = texttmp;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2865 mkv_d->subs.lines--;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2866 linei--;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2867 lines_cut = true;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2868 }
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2869 if (lines_cut) {
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2870 vo_sub = &mkv_d->subs;
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2871 vo_osd_changed(OSDTYPE_SUBTITLE);
71db96cf88d4 Support for SSA text subs in Matroska. Patch partially by Tristan <z80@oceanfree.net>.
mosu
parents: 10844
diff changeset
2872 }
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2873 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2874
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2875 ds = NULL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2876 if ((mkv_d->video != NULL) &&
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2877 (mkv_d->video->tnum == kblock->TrackNum())) {
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2878 ds = d->video;
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2879 t = mkv_d->video;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2880 } else if ((mkv_d->audio != NULL) &&
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2881 (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
2882 ds = d->audio;
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2883 t = mkv_d->audio;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2884 } else if ((mkv_d->subs_track != NULL) &&
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2885 (mkv_d->subs_track->tnum == kblock->TrackNum())) {
11154
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2886 ds = d->sub;
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2887 t = mkv_d->subs_track;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2888 }
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2889
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
2890 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
2891
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
2892 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
2893 mkv_d->first_tc) / 1000.0;
10930
624f11cc5034 Fix for imprecise floating point calculations.
mosu
parents: 10874
diff changeset
2894 if (current_pts < 0.0)
624f11cc5034 Fix for imprecise floating point calculations.
mosu
parents: 10874
diff changeset
2895 current_pts = 0.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
2896
dd64e1fe919d Better support for RealVideo/RealAudio in Matroska. Includes the timestamp fixes from demux_real.c. Seeking is working. Added Matroska to the formats with variable FPS in video.c.
mosu
parents: 10410
diff changeset
2897 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
2898 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
2899 (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
2900 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
2901
dd64e1fe919d Better support for RealVideo/RealAudio in Matroska. Includes the timestamp fixes from demux_real.c. Seeking is working. Added Matroska to the formats with variable FPS in video.c.
mosu
parents: 10410
diff changeset
2902 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
2903 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
2904
10844
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2905 if (mkv_d->audio->fix_i_bps && use_this_block) {
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2906 uint32_t i, sum;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2907 sh_audio_t *sh;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2908
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2909 for (i = 0, sum = 0; i < kblock->NumberFrames(); i++) {
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2910 DataBuffer &data = kblock->GetBuffer(i);
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2911 sum += data.Size();
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2912 }
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2913 sh = (sh_audio_t *)ds->sh;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2914 if (block_duration != -1) {
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2915 sh->i_bps = sum * 1000 / block_duration;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2916 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Changed i_bps to %d.\n",
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2917 sh->i_bps);
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2918 mkv_d->audio->fix_i_bps = false;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2919 } else if (mkv_d->audio->qt_last_a_pts == 0.0)
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2920 mkv_d->audio->qt_last_a_pts = current_pts;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2921 else if (mkv_d->audio->qt_last_a_pts != current_pts) {
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2922 sh->i_bps = (int)(sum / (current_pts -
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2923 mkv_d->audio->qt_last_a_pts));
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2924 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Changed i_bps to %d.\n",
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2925 sh->i_bps);
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2926 mkv_d->audio->fix_i_bps = false;
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2927 }
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2928 }
98681fdabf79 Support for Quicktime stuff in Matroska (e.g. Sorenson, QDesign Music codecs etc.).
mosu
parents: 10706
diff changeset
2929
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
2930 } 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
2931 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
2932
dd64e1fe919d Better support for RealVideo/RealAudio in Matroska. Includes the timestamp fixes from demux_real.c. Seeking is working. Added Matroska to the formats with variable FPS in video.c.
mosu
parents: 10410
diff changeset
2933 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
2934 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
2935 (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
2936 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
2937
dd64e1fe919d Better support for RealVideo/RealAudio in Matroska. Includes the timestamp fixes from demux_real.c. Seeking is working. Added Matroska to the formats with variable FPS in video.c.
mosu
parents: 10410
diff changeset
2938 } 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
2939 (mkv_d->subs_track->tnum == kblock->TrackNum())) {
11154
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2940 if (mkv_d->subtitle_type != MKV_SUBTYPE_VOBSUB) {
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2941 if (!mkv_d->v_skip_to_keyframe)
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2942 handle_subtitles(d, kblock, block_duration);
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2943 use_this_block = false;
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2944 }
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
2945
dd64e1fe919d Better support for RealVideo/RealAudio in Matroska. Includes the timestamp fixes from demux_real.c. Seeking is working. Added Matroska to the formats with variable FPS in video.c.
mosu
parents: 10410
diff changeset
2946 } 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
2947 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
2948
dd64e1fe919d Better support for RealVideo/RealAudio in Matroska. Includes the timestamp fixes from demux_real.c. Seeking is working. Added Matroska to the formats with variable FPS in video.c.
mosu
parents: 10410
diff changeset
2949 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
2950 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
2951 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
2952 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
2953
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
2954 for (i = 0; i < (int)kblock->NumberFrames(); i++) {
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2955 unsigned char *re_buffer;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2956 uint32_t re_size;
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2957 bool re_modified;
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
2958 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
2959
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2960 re_buffer = data.Buffer();
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2961 re_size = data.Size();
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2962 re_modified = reverse_encodings(t, re_buffer, re_size, 1);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2963
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
2964 if ((ds == d->video) && mkv_d->video->realmedia)
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2965 handle_realvideo(d, re_buffer, re_size, 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
2966 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
2967
dd64e1fe919d Better support for RealVideo/RealAudio in Matroska. Includes the timestamp fixes from demux_real.c. Seeking is working. Added Matroska to the formats with variable FPS in video.c.
mosu
parents: 10410
diff changeset
2968 else if ((ds == d->audio) && mkv_d->audio->realmedia)
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2969 handle_realaudio(d, re_buffer, re_size, 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
2970 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
2971
11154
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2972 else if ((ds == d->sub) &&
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2973 (mkv_d->subtitle_type == MKV_SUBTYPE_VOBSUB))
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2974 mpeg_run(d, re_buffer, re_size);
11154
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2975
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
2976 else {
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2977 dp = new_demux_packet(re_size);
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2978 memcpy(dp->buffer, re_buffer, re_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
2979 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
2980 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
2981 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
2982 found_data++;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2983 }
11229
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2984 if (re_modified)
b4040706e1d3 Added support for additional content encoding (compression, encryption) in general and zlib compression in particular (to be used with VobSubs).
mosu
parents: 11155
diff changeset
2985 safefree(re_buffer);
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
2986 }
dd64e1fe919d Better support for RealVideo/RealAudio in Matroska. Includes the timestamp fixes from demux_real.c. Seeking is working. Added Matroska to the formats with variable FPS in video.c.
mosu
parents: 10410
diff changeset
2987 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
2988 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
2989 mkv_d->skip_to_timecode = 0;
11154
0e9ea2a3a220 Support for uncompressed VobSubs.
mosu
parents: 11139
diff changeset
2990 } else if (ds == d->audio)
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
2991 mkv_d->a_skip_to_keyframe = false;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2992 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2993
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2994 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
2995 } // kblock != NULL
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2996
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
2997 } 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
2998 l2->SkipData(*es, l2->Generic().Context);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
2999
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
3000 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
3001 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
3002 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
3003 }
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
3004
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
3005 if (upper_lvl_el > 0) {
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3006 upper_lvl_el--;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3007 if (upper_lvl_el > 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3008 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
3009 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
3010 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
3011 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
3012
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
3013 } 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
3014 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
3015 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
3016 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
3017
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3018 }
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
3019
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
3020 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
3021 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
3022 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
3023 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
3024
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3025 } // 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
3026
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3027 } else if (EbmlId(*l1) == KaxCues::ClassInfos.GlobalId)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3028 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3029 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
3030 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
3031
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
3032 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
3033 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
3034 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
3035 }
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
3036
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
3037 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
3038 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
3039 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
3040 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
3041 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
3042 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
3043 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
3044
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
3045 } 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
3046 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
3047 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
3048 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
3049
b6a31ca4f9a2 Big reorganization. Relies on libmatroska's Read() function and then processes units in memory. Also some fixes for handling of global elements which re-enable playback of files created with the latest VDubMod.
mosu
parents: 10438
diff changeset
3050 }
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3051
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3052 if (exit_loop)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3053 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3054
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
3055 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
3056 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
3057 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
3058 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
3059
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3060 } // while (l1 != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3061 } catch (exception ex) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3062 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] exception caught\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3063 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3064 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3065
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3066 if (found_data)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3067 return 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3068
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3069 return 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3070 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3071
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3072 extern "C" void resync_audio_stream(sh_audio_t *sh_audio);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3073
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3074 extern "C" void demux_mkv_seek(demuxer_t *demuxer, float rel_seek_secs,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3075 int flags) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3076 int i, k, upper_lvl_el;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3077 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *)demuxer->priv;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3078 int64_t target_timecode, target_filepos = 0, min_diff, diff, current_pos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3079 int64_t cluster_pos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3080 mkv_track_index_t *index;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3081 mkv_index_entry_t *entry;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3082 EbmlElement *l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3083
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3084 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] SEEK, relss: %.3f, flags: %d\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3085 rel_seek_secs, flags);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3086
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3087 if (!mkv_d->cues_found && !mkv_d->cues_searched) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3088 // 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
3089 // elements until we either hit another segment, the end of the file
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3090 // or - suprise - some cues.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3091 current_pos = mkv_d->in->getFilePointer();
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3092
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3093 // Skip the data but do not delete the element! This is our current
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3094 // cluster, and we need it later on in demux_mkv_fill_buffer.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3095 l1 = mkv_d->saved_l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3096 l1->SkipData(static_cast<EbmlStream &>(*mkv_d->es), l1->Generic().Context);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3097 l1 = mkv_d->es->FindNextElement(mkv_d->segment->Generic().Context,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3098 upper_lvl_el, 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3099 while (l1 != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3100 if (upper_lvl_el)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3101 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3102
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3103 if (EbmlId(*l1) == KaxCues::ClassInfos.GlobalId) {
10685
f54ffeb29447 Support for linked seek heads, multiple seek heads, multiple cues.
mosu
parents: 10684
diff changeset
3104 parse_cues(mkv_d, l1->GetElementPosition());
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3105 delete l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3106 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3107 } else {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3108 if (EbmlId(*l1) == KaxCluster::ClassInfos.GlobalId)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3109 add_cluster_position(mkv_d, l1->GetElementPosition());
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3110 l1->SkipData(static_cast<EbmlStream &>(*mkv_d->es),
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3111 l1->Generic().Context);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3112 delete l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3113 l1 = mkv_d->es->FindNextElement(mkv_d->segment->Generic().Context,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3114 upper_lvl_el, 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3115 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3116 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3117
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3118 if (demuxer->stream->eof)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3119 stream_reset(demuxer->stream);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3120 mkv_d->in->setFilePointer(current_pos);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3121
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3122 mkv_d->cues_searched = 1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3123 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3124
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3125 if (!(flags & 2)) { // Time in secs
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3126 if (flags & 1) // Absolute seek
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3127 target_timecode = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3128 else // Relative seek
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3129 target_timecode = (int64_t)(mkv_d->last_pts * 1000.0);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3130 target_timecode += (int64_t)(rel_seek_secs * 1000.0);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3131 if (target_timecode < 0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3132 target_timecode = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3133
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3134 min_diff = 0xFFFFFFFL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3135
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3136 // Let's find the entry in the index with the smallest difference
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3137 // to the wanted timecode.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3138 entry = NULL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3139 for (i = 0; i < mkv_d->num_indexes; i++)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3140 if (mkv_d->index[i].tnum == mkv_d->video->tnum) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3141 index = &mkv_d->index[i];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3142 for (k = 0; k < index->num_entries; k++) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3143 if (!index->entries[k].is_key)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3144 continue;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3145 diff = target_timecode - (int64_t)index->entries[k].timecode;
11260
1c269ab5f3f6 Support for -chapter selection.
mosu
parents: 11229
diff changeset
3146 if (((flags & 1) || (target_timecode <= (mkv_d->last_pts * 1000))) &&
10874
f75ec55301c4 Different decision making for seeking which takes the direction into account.
mosu
parents: 10861
diff changeset
3147 (diff >= 0) && (diff < min_diff)) {
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3148 min_diff = diff;
10874
f75ec55301c4 Different decision making for seeking which takes the direction into account.
mosu
parents: 10861
diff changeset
3149 entry = &index->entries[k];
f75ec55301c4 Different decision making for seeking which takes the direction into account.
mosu
parents: 10861
diff changeset
3150 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] seek BACK, solution: last_pts: "
f75ec55301c4 Different decision making for seeking which takes the direction into account.
mosu
parents: 10861
diff changeset
3151 "%d, target: %d, diff: %d, entry->timecode: %d, PREV diff: "
f75ec55301c4 Different decision making for seeking which takes the direction into account.
mosu
parents: 10861
diff changeset
3152 "%d, k: %d\n", (int)(mkv_d->last_pts * 1000),
f75ec55301c4 Different decision making for seeking which takes the direction into account.
mosu
parents: 10861
diff changeset
3153 (int)target_timecode, (int)diff, (int)entry->timecode,
f75ec55301c4 Different decision making for seeking which takes the direction into account.
mosu
parents: 10861
diff changeset
3154 k > 0 ? (int)(index->entries[k - 1].timecode -
f75ec55301c4 Different decision making for seeking which takes the direction into account.
mosu
parents: 10861
diff changeset
3155 target_timecode) : 0, k);
f75ec55301c4 Different decision making for seeking which takes the direction into account.
mosu
parents: 10861
diff changeset
3156
f75ec55301c4 Different decision making for seeking which takes the direction into account.
mosu
parents: 10861
diff changeset
3157 } else if ((target_timecode > (mkv_d->last_pts * 1000)) &&
f75ec55301c4 Different decision making for seeking which takes the direction into account.
mosu
parents: 10861
diff changeset
3158 (diff < 0) && (-diff < min_diff)) {
f75ec55301c4 Different decision making for seeking which takes the direction into account.
mosu
parents: 10861
diff changeset
3159 min_diff = -diff;
f75ec55301c4 Different decision making for seeking which takes the direction into account.
mosu
parents: 10861
diff changeset
3160 entry = &index->entries[k];
f75ec55301c4 Different decision making for seeking which takes the direction into account.
mosu
parents: 10861
diff changeset
3161 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] seek FORW, solution: last_pts: "
f75ec55301c4 Different decision making for seeking which takes the direction into account.
mosu
parents: 10861
diff changeset
3162 "%d, target: %d, diff: %d, entry->timecode: %d, NEXT diff: "
f75ec55301c4 Different decision making for seeking which takes the direction into account.
mosu
parents: 10861
diff changeset
3163 "%d, k: %d\n", (int)(mkv_d->last_pts * 1000),
f75ec55301c4 Different decision making for seeking which takes the direction into account.
mosu
parents: 10861
diff changeset
3164 (int)target_timecode, (int)diff, (int)entry->timecode,
f75ec55301c4 Different decision making for seeking which takes the direction into account.
mosu
parents: 10861
diff changeset
3165 k < index->num_entries ?
f75ec55301c4 Different decision making for seeking which takes the direction into account.
mosu
parents: 10861
diff changeset
3166 (int)(index->entries[k + 1].timecode - target_timecode) :
f75ec55301c4 Different decision making for seeking which takes the direction into account.
mosu
parents: 10861
diff changeset
3167 0, k);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3168 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3169 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3170 break;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3171 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3172
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3173 if (mkv_d->saved_l1 != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3174 delete mkv_d->saved_l1;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3175
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3176 if (mkv_d->saved_l2 != NULL) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3177 delete mkv_d->saved_l2;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3178 mkv_d->saved_l2 = NULL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3179 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3180
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3181 if (entry != NULL) { // We've found an entry.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3182 mkv_d->in->setFilePointer(entry->filepos);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3183 upper_lvl_el = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3184 mkv_d->saved_l1 =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3185 mkv_d->es->FindNextElement(mkv_d->segment->Generic().Context,
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3186 upper_lvl_el, 0xFFFFFFFFL, true, 1);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3187 } else { // We've not found an entry --> no index?
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3188 target_filepos = (int64_t)(target_timecode * mkv_d->last_filepos /
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3189 (mkv_d->last_pts * 1000.0));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3190 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
3191 "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
3192 (int64_t)(mkv_d->last_pts * 1000.0));
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3193 // Let's find the nearest cluster so that libebml does not have to
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3194 // do so much work.
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3195 cluster_pos = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3196 min_diff = 0x0FFFFFFFL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3197 for (i = 0; i < mkv_d->num_cluster_pos; i++) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3198 diff = mkv_d->cluster_positions[i] - target_filepos;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3199 if (rel_seek_secs < 0) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3200 if ((diff > 0) && (diff < min_diff)) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3201 cluster_pos = mkv_d->cluster_positions[i];
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3202 min_diff = diff;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3203 }
10099
71d703e35ff3 Removed the abs function as someone reported compilation problems under MacOS.
mosu
parents: 10098
diff changeset
3204 } else if ((diff < 0 ? -1 * diff : diff) < min_diff) {
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3205 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
3206 min_diff = diff < 0 ? -1 * diff : diff;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3207 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3208 }
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
3209 if (min_diff != 0x0FFFFFFFL) {
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3210 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
3211 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
3212 "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
3213 }
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3214 if (target_filepos >= demuxer->movi_end)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3215 return;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3216 mkv_d->in->setFilePointer(target_filepos);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3217 upper_lvl_el = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3218 mkv_d->saved_l1 =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3219 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
3220 upper_lvl_el, 0xFFFFFFFFL, true, 1);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3221 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] seek result: target_timecode %lld, "
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3222 "did not find an entry. Calculated target_filspos: %lld\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3223 target_timecode, target_filepos);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3224 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] seek found %p (%s).\n",
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3225 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
3226 mkv_d->saved_l1->Generic().DebugName);
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3227 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3228
10060
f4d6cf8c6c93 Fixed seeking in audio-only files. Added support for subtitle track selection via "-slang".
mosu
parents: 10036
diff changeset
3229 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
3230 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
3231 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
3232 mkv_d->skip_to_timecode = target_timecode;
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3233
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
3234 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
3235
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3236 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
3237 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
3238 (int64_t)(mkv_d->last_pts * 1000.0));
10024
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3239
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3240 mkv_d->subs.lines = 0;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3241 vo_sub = &mkv_d->subs;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3242 vo_osd_changed(OSDTYPE_SUBTITLE);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3243
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3244 if(demuxer->audio->sh != NULL)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3245 resync_audio_stream((sh_audio_t *)demuxer->audio->sh);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3246
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3247 } else
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3248 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] seek unsupported flags\n");
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3249
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3250 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3251
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3252 extern "C" void demux_close_mkv(demuxer_t *demuxer) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3253 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *)demuxer->priv;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3254
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3255 free_mkv_demuxer(mkv_d);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3256
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3257 #ifdef USE_ICONV
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3258 subcp_close();
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3259 #endif
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3260 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3261
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3262 extern "C" int demux_mkv_control(demuxer_t *demuxer, int cmd, void *arg) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3263 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *)demuxer->priv;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3264
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3265 switch (cmd) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3266 case DEMUXER_CTRL_GET_TIME_LENGTH:
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3267 if (mkv_d->duration == -1.0)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3268 return DEMUXER_CTRL_DONTKNOW;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3269
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3270 *((unsigned long *)arg) = (unsigned long)mkv_d->duration;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3271 return DEMUXER_CTRL_OK;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3272
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3273 case DEMUXER_CTRL_GET_PERCENT_POS:
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3274 if (mkv_d->duration == -1.0) {
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3275 if (demuxer->movi_start == demuxer->movi_end)
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3276 return DEMUXER_CTRL_DONTKNOW;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3277
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3278 *((int *)arg) =
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3279 (int)((demuxer->filepos - demuxer->movi_start) /
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3280 ((demuxer->movi_end - demuxer->movi_start) / 100));
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3281 return DEMUXER_CTRL_OK;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3282 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3283
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3284 *((int *)arg) = (int)(100 * mkv_d->last_pts / mkv_d->duration);
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3285 return DEMUXER_CTRL_OK;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3286
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3287 default:
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3288 return DEMUXER_CTRL_NOTIMPL;
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3289 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3290 }
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3291
c6fab860ab18 Added Matroska demuxing support.
mosu
parents:
diff changeset
3292 #endif /* HAVE_MATROSKA */