annotate libmpdemux/demux_mkv.c @ 18701:b45c4e057999

Remove unnecessary rsync exclude.
author diego
date Wed, 14 Jun 2006 10:24:41 +0000
parents 4928dd61f136
children 9e2b300db17b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1 /*
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2 * native Matroska demuxer
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3 * Written by Aurelien Jacobs <aurel@gnuage.org>
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
4 * Based on the one written by Ronald Bultje for gstreamer
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
5 * and on demux_mkv.cpp from Moritz Bunkus.
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
6 * Licence: GPL
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
7 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
8
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
9 #include "config.h"
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
10
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
11 #include <stdlib.h>
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
12 #include <stdio.h>
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
13 #include <ctype.h>
18558
4928dd61f136 Fix potential integer overflows in memory allocation.
rtogni
parents: 18507
diff changeset
14 #include <inttypes.h>
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
15
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
16 #include "stream.h"
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
17 #include "demuxer.h"
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
18 #include "stheader.h"
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
19 #include "ebml.h"
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
20 #include "matroska.h"
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
21 #include "bswap.h"
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
22
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16912
diff changeset
23 #include "subreader.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16912
diff changeset
24 #include "libvo/sub.h"
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
25
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
26 #ifdef USE_QTX_CODECS
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
27 #include "qtx/qtxsdk/components.h"
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
28 #endif
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
29
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
30 #ifdef HAVE_ZLIB
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
31 #include <zlib.h>
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
32 #endif
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
33
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
34 #ifdef USE_LIBLZO
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
35 #include <lzo1x.h>
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
36 #else
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16912
diff changeset
37 #include "libmpcodecs/native/minilzo.h"
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
38 #endif
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
39
12550
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
40 #if !defined(MIN)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
41 #define MIN(a, b) ((a)<(b)?(a):(b))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
42 #endif
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
43 #if !defined(MAX)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
44 #define MAX(a, b) ((a)>(b)?(a):(b))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
45 #endif
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
46
18036
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
47 static unsigned char sipr_swaps[38][2]={
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
48 {0,63},{1,22},{2,44},{3,90},{5,81},{7,31},{8,86},{9,58},{10,36},{12,68},
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
49 {13,39},{14,73},{15,53},{16,69},{17,57},{19,88},{20,34},{21,71},{24,46},
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
50 {25,94},{26,54},{28,75},{29,50},{32,70},{33,92},{35,74},{38,85},{40,56},
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
51 {42,87},{43,65},{45,59},{48,79},{49,93},{51,89},{55,95},{61,76},{67,83},
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
52 {77,80} };
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
53
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
54 // Map flavour to bytes per second
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
55 #define SIPR_FLAVORS 4
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
56 #define ATRC_FLAVORS 8
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
57 #define COOK_FLAVORS 34
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
58 static int sipr_fl2bps[SIPR_FLAVORS] = {813, 1062, 625, 2000};
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
59 static int atrc_fl2bps[ATRC_FLAVORS] = {8269, 11714, 13092, 16538, 18260, 22050, 33075, 44100};
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
60 static int cook_fl2bps[COOK_FLAVORS] = {1000, 1378, 2024, 2584, 4005, 5513, 8010, 4005, 750, 2498,
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
61 4048, 5513, 8010, 11973, 8010, 2584, 4005, 2067, 2584, 2584,
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
62 4005, 4005, 5513, 5513, 8010, 12059, 1550, 8010, 12059, 5513,
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
63 12016, 16408, 22911, 33506};
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
64
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
65 typedef struct
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
66 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
67 uint32_t order, type, scope;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
68 uint32_t comp_algo;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
69 uint8_t *comp_settings;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
70 int comp_settings_len;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
71 } mkv_content_encoding_t;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
72
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
73 typedef struct mkv_track
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
74 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
75 int tnum;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
76
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
77 char *codec_id;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
78 int ms_compat;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
79 char *language;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
80
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
81 int type;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
82
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
83 uint32_t v_width, v_height, v_dwidth, v_dheight;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
84 float v_frate;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
85
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
86 uint32_t a_formattag;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
87 uint32_t a_channels, a_bps;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
88 float a_sfreq;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
89
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
90 float default_duration;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
91
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
92 int default_track;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
93
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
94 void *private_data;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
95 unsigned int private_size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
96
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
97 /* stuff for realmedia */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
98 int realmedia;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
99 int rv_kf_base, rv_kf_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
100 float rv_pts; /* previous video timestamp */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
101 float ra_pts; /* previous audio timestamp */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
102
18036
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
103 /** realaudio descrambling */
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
104 int sub_packet_size; ///< sub packet size, per stream
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
105 int sub_packet_h; ///< number of coded frames per block
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
106 int coded_framesize; ///< coded frame size, per stream
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
107 int audiopk_size; ///< audio packet size
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
108 unsigned char *audio_buf; ///< place to store reordered audio data
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
109 float *audio_timestamp; ///< timestamp for each audio packet
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
110 int sub_packet_cnt; ///< number of subpacket already received
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
111 int audio_filepos; ///< file position of first audio packet in block
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
112
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
113 /* stuff for quicktime */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
114 int fix_i_bps;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
115 float qt_last_a_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
116
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
117 int subtitle_type;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
118
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
119 /* The timecodes of video frames might have to be reordered if they're
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
120 in display order (the timecodes, not the frames themselves!). In this
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
121 case demux packets have to be cached with the help of these variables. */
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
122 int reorder_timecodes;
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
123 demux_packet_t **cached_dps;
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
124 int num_cached_dps, num_allocated_dps;
14515
35a6c4db00ae More support for AVC in Matroska.
mosu
parents: 14513
diff changeset
125 float max_pts;
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
126
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
127 /* generic content encoding support */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
128 mkv_content_encoding_t *encodings;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
129 int num_encodings;
12547
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
130
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
131 /* For VobSubs */
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
132 mkv_sh_sub_t sh_sub;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
133 } mkv_track_t;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
134
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
135 typedef struct mkv_index
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
136 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
137 int tnum;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
138 uint64_t timecode, filepos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
139 } mkv_index_t;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
140
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
141 typedef struct mkv_chapter
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
142 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
143 uint64_t start, end;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
144 } mkv_chapter_t;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
145
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
146 typedef struct mkv_demuxer
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
147 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
148 off_t segment_start;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
149
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
150 float duration, last_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
151 uint64_t last_filepos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
152
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
153 mkv_track_t **tracks;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
154 int num_tracks;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
155
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
156 uint64_t tc_scale, cluster_tc, first_tc;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
157 int has_first_tc;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
158
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
159 uint64_t clear_subs_at[SUB_MAX_TEXT];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
160 subtitle subs;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
161
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
162 uint64_t cluster_size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
163 uint64_t blockgroup_size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
164
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
165 mkv_index_t *indexes;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
166 int num_indexes;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
167
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
168 off_t *parsed_cues;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
169 int parsed_cues_num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
170 off_t *parsed_seekhead;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
171 int parsed_seekhead_num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
172
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
173 uint64_t *cluster_positions;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
174 int num_cluster_pos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
175
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
176 int64_t skip_to_timecode;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
177 int v_skip_to_keyframe, a_skip_to_keyframe;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
178
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
179 mkv_chapter_t *chapters;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
180 int num_chapters;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
181 int64_t stop_timecode;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
182 } mkv_demuxer_t;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
183
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
184
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
185 typedef struct
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
186 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
187 uint32_t chunks; /* number of chunks */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
188 uint32_t timestamp; /* timestamp from packet header */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
189 uint32_t len; /* length of actual data */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
190 uint32_t chunktab; /* offset to chunk offset array */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
191 } dp_hdr_t;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
192
11815
0fa6f4fcfcbb Compiler/system compatibility fixes.
mosu
parents: 11812
diff changeset
193 typedef struct __attribute__((__packed__))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
194 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
195 uint32_t size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
196 uint32_t fourcc1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
197 uint32_t fourcc2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
198 uint16_t width;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
199 uint16_t height;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
200 uint16_t bpp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
201 uint32_t unknown1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
202 uint32_t fps;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
203 uint32_t type1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
204 uint32_t type2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
205 } real_video_props_t;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
206
11815
0fa6f4fcfcbb Compiler/system compatibility fixes.
mosu
parents: 11812
diff changeset
207 typedef struct __attribute__((__packed__))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
208 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
209 uint32_t fourcc1; /* '.', 'r', 'a', 0xfd */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
210 uint16_t version1; /* 4 or 5 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
211 uint16_t unknown1; /* 00 000 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
212 uint32_t fourcc2; /* .ra4 or .ra5 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
213 uint32_t unknown2; /* ??? */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
214 uint16_t version2; /* 4 or 5 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
215 uint32_t header_size; /* == 0x4e */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
216 uint16_t flavor; /* codec flavor id */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
217 uint32_t coded_frame_size; /* coded frame size */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
218 uint32_t unknown3; /* big number */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
219 uint32_t unknown4; /* bigger number */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
220 uint32_t unknown5; /* yet another number */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
221 uint16_t sub_packet_h;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
222 uint16_t frame_size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
223 uint16_t sub_packet_size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
224 uint16_t unknown6; /* 00 00 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
225 uint16_t sample_rate;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
226 uint16_t unknown8; /* 0 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
227 uint16_t sample_size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
228 uint16_t channels;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
229 } real_audio_v4_props_t;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
230
11815
0fa6f4fcfcbb Compiler/system compatibility fixes.
mosu
parents: 11812
diff changeset
231 typedef struct __attribute__((__packed__))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
232 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
233 uint32_t fourcc1; /* '.', 'r', 'a', 0xfd */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
234 uint16_t version1; /* 4 or 5 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
235 uint16_t unknown1; /* 00 000 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
236 uint32_t fourcc2; /* .ra4 or .ra5 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
237 uint32_t unknown2; /* ??? */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
238 uint16_t version2; /* 4 or 5 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
239 uint32_t header_size; /* == 0x4e */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
240 uint16_t flavor; /* codec flavor id */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
241 uint32_t coded_frame_size; /* coded frame size */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
242 uint32_t unknown3; /* big number */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
243 uint32_t unknown4; /* bigger number */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
244 uint32_t unknown5; /* yet another number */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
245 uint16_t sub_packet_h;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
246 uint16_t frame_size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
247 uint16_t sub_packet_size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
248 uint16_t unknown6; /* 00 00 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
249 uint8_t unknown7[6]; /* 0, srate, 0 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
250 uint16_t sample_rate;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
251 uint16_t unknown8; /* 0 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
252 uint16_t sample_size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
253 uint16_t channels;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
254 uint32_t genr; /* "genr" */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
255 uint32_t fourcc3; /* fourcc */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
256 } real_audio_v5_props_t;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
257
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
258
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
259 /* for e.g. "-slang ger" */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
260 extern char *dvdsub_lang;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
261 extern char *audio_lang;
13501
a5004eb92a79 fix sub_select fiasco with global sub numbering. now multiple sub sources can be managed in essentially one list.
joey
parents: 13424
diff changeset
262 extern int dvdsub_id;
14046
4802041ab8e3 Output more information about vids, aids, sids, alangs and slangs with -identify. Patch by kiriuja <mplayer-patches@en-directo.net>
mosu
parents: 13804
diff changeset
263 extern int demux_aid_vid_mismatch;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
264
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
265
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
266 static mkv_track_t *
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
267 demux_mkv_find_track_by_num (mkv_demuxer_t *d, int n, int type)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
268 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
269 int i, id;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
270
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
271 for (i=0, id=0; i < d->num_tracks; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
272 if (d->tracks[i] != NULL && d->tracks[i]->type == type)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
273 if (id++ == n)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
274 return d->tracks[i];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
275
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
276 return NULL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
277 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
278
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
279 static mkv_track_t *
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
280 demux_mkv_find_track_by_language (mkv_demuxer_t *d, char *language, int type)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
281 {
12041
c5aa951feff8 Parse comma separated language lists instead of comparing the complete language string. Patch by Loren Merritt <lorenm at u dot washington dot edu>
mosu
parents: 11934
diff changeset
282 int i, len;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
283
12041
c5aa951feff8 Parse comma separated language lists instead of comparing the complete language string. Patch by Loren Merritt <lorenm at u dot washington dot edu>
mosu
parents: 11934
diff changeset
284 language += strspn(language,",");
c5aa951feff8 Parse comma separated language lists instead of comparing the complete language string. Patch by Loren Merritt <lorenm at u dot washington dot edu>
mosu
parents: 11934
diff changeset
285 while((len = strcspn(language,",")) > 0)
c5aa951feff8 Parse comma separated language lists instead of comparing the complete language string. Patch by Loren Merritt <lorenm at u dot washington dot edu>
mosu
parents: 11934
diff changeset
286 {
c5aa951feff8 Parse comma separated language lists instead of comparing the complete language string. Patch by Loren Merritt <lorenm at u dot washington dot edu>
mosu
parents: 11934
diff changeset
287 for (i=0; i < d->num_tracks; i++)
c5aa951feff8 Parse comma separated language lists instead of comparing the complete language string. Patch by Loren Merritt <lorenm at u dot washington dot edu>
mosu
parents: 11934
diff changeset
288 if (d->tracks[i] != NULL && d->tracks[i]->language != NULL &&
c5aa951feff8 Parse comma separated language lists instead of comparing the complete language string. Patch by Loren Merritt <lorenm at u dot washington dot edu>
mosu
parents: 11934
diff changeset
289 d->tracks[i]->type == type &&
c5aa951feff8 Parse comma separated language lists instead of comparing the complete language string. Patch by Loren Merritt <lorenm at u dot washington dot edu>
mosu
parents: 11934
diff changeset
290 !strncmp(d->tracks[i]->language, language, len))
c5aa951feff8 Parse comma separated language lists instead of comparing the complete language string. Patch by Loren Merritt <lorenm at u dot washington dot edu>
mosu
parents: 11934
diff changeset
291 return d->tracks[i];
c5aa951feff8 Parse comma separated language lists instead of comparing the complete language string. Patch by Loren Merritt <lorenm at u dot washington dot edu>
mosu
parents: 11934
diff changeset
292 language += len;
c5aa951feff8 Parse comma separated language lists instead of comparing the complete language string. Patch by Loren Merritt <lorenm at u dot washington dot edu>
mosu
parents: 11934
diff changeset
293 language += strspn(language,",");
c5aa951feff8 Parse comma separated language lists instead of comparing the complete language string. Patch by Loren Merritt <lorenm at u dot washington dot edu>
mosu
parents: 11934
diff changeset
294 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
295
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
296 return NULL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
297 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
298
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
299 static void
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
300 add_cluster_position (mkv_demuxer_t *mkv_d, uint64_t position)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
301 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
302 int i = mkv_d->num_cluster_pos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
303
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
304 while (i--)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
305 if (mkv_d->cluster_positions[i] == position)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
306 return;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
307
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
308 if (!mkv_d->cluster_positions)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
309 mkv_d->cluster_positions = (uint64_t *) malloc (32 * sizeof (uint64_t));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
310 else if (!(mkv_d->num_cluster_pos % 32))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
311 mkv_d->cluster_positions = (uint64_t *) realloc(mkv_d->cluster_positions,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
312 (mkv_d->num_cluster_pos+32)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
313 * sizeof (uint64_t));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
314 mkv_d->cluster_positions[mkv_d->num_cluster_pos++] = position;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
315 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
316
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
317
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
318 #define AAC_SYNC_EXTENSION_TYPE 0x02b7
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
319 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
320 aac_get_sample_rate_index (uint32_t sample_rate)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
321 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
322 if (92017 <= sample_rate)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
323 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
324 else if (75132 <= sample_rate)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
325 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
326 else if (55426 <= sample_rate)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
327 return 2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
328 else if (46009 <= sample_rate)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
329 return 3;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
330 else if (37566 <= sample_rate)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
331 return 4;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
332 else if (27713 <= sample_rate)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
333 return 5;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
334 else if (23004 <= sample_rate)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
335 return 6;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
336 else if (18783 <= sample_rate)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
337 return 7;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
338 else if (13856 <= sample_rate)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
339 return 8;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
340 else if (11502 <= sample_rate)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
341 return 9;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
342 else if (9391 <= sample_rate)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
343 return 10;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
344 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
345 return 11;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
346 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
347
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
348
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
349 static int
12550
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
350 vobsub_parse_size (mkv_track_t *t, const char *start)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
351 {
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
352 if (sscanf(&start[6], "%dx%d", &t->sh_sub.width, &t->sh_sub.height) == 2)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
353 {
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
354 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] VobSub size: %ux%u\n",
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
355 t->sh_sub.width, t->sh_sub.height);
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
356 return 1;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
357 }
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
358 return 0;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
359 }
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
360
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
361 static int
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
362 vobsub_parse_palette (mkv_track_t *t, const char *start)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
363 {
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
364 int i, r, g, b, y, u, v, tmp;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
365
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
366 start += 8;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
367 while (isspace(*start))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
368 start++;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
369 for (i = 0; i < 16; i++)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
370 {
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
371 if (sscanf(start, "%06x", &tmp) != 1)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
372 break;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
373 r = tmp >> 16 & 0xff;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
374 g = tmp >> 8 & 0xff;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
375 b = tmp & 0xff;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
376 y = MIN(MAX((int)(0.1494 * r + 0.6061 * g + 0.2445 * b), 0),
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
377 0xff);
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
378 u = MIN(MAX((int)(0.6066 * r - 0.4322 * g - 0.1744 * b) + 128,
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
379 0), 0xff);
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
380 v = MIN(MAX((int)(-0.08435 * r - 0.3422 * g + 0.4266 * b) +
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
381 128, 0), 0xff);
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
382 t->sh_sub.palette[i] = y << 16 | u << 8 | v;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
383 start += 6;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
384 while ((*start == ',') || isspace(*start))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
385 start++;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
386 }
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
387 if (i == 16)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
388 {
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
389 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] VobSub palette: %06x,%06x,"
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
390 "%06x,%06x,%06x,%06x,%06x,%06x,%06x,%06x,%06x,%06x,%06x,"
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
391 "%06x,%06x,%06x\n", t->sh_sub.palette[0],
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
392 t->sh_sub.palette[1], t->sh_sub.palette[2],
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
393 t->sh_sub.palette[3], t->sh_sub.palette[4],
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
394 t->sh_sub.palette[5], t->sh_sub.palette[6],
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
395 t->sh_sub.palette[7], t->sh_sub.palette[8],
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
396 t->sh_sub.palette[9], t->sh_sub.palette[10],
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
397 t->sh_sub.palette[11], t->sh_sub.palette[12],
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
398 t->sh_sub.palette[13], t->sh_sub.palette[14],
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
399 t->sh_sub.palette[15]);
14561
a226d301eec1 Handle missing palettes in the info part of VobSubs in Matroska files correctly by giving mplayer a NULL pointer. This way it will use a default palette instead of black only. Patch by Csillag Kristof (fenwick () freemail ! hu)
mosu
parents: 14515
diff changeset
400 t->sh_sub.has_palette = 1;
12550
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
401 return 2;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
402 }
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
403 return 0;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
404 }
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
405
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
406 static int
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
407 vobsub_parse_custom_colors (mkv_track_t *t, const char *start)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
408 {
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
409 int use_custom_colors, i;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
410
13131
ab937f4a17ad Cosmetics: fix some compiler warnings.
mosu
parents: 13129
diff changeset
411 use_custom_colors = 0;
12550
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
412 start += 14;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
413 while (isspace(*start))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
414 start++;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
415 if (!strncasecmp(start, "ON", 2) || (*start == '1'))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
416 use_custom_colors = 1;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
417 else if (!strncasecmp(start, "OFF", 3) || (*start == '0'))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
418 use_custom_colors = 0;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
419 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] VobSub custom colors: %s\n",
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
420 use_custom_colors ? "ON" : "OFF");
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
421 if ((start = strstr(start, "colors:")) != NULL)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
422 {
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
423 start += 7;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
424 while (isspace(*start))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
425 start++;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
426 for (i = 0; i < 4; i++)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
427 {
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
428 if (sscanf(start, "%06x", &t->sh_sub.colors[i]) != 1)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
429 break;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
430 start += 6;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
431 while ((*start == ',') || isspace(*start))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
432 start++;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
433 }
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
434 if (i == 4)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
435 {
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
436 t->sh_sub.custom_colors = 4;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
437 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] VobSub colors: %06x,"
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
438 "%06x,%06x,%06x\n", t->sh_sub.colors[0],
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
439 t->sh_sub.colors[1], t->sh_sub.colors[2],
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
440 t->sh_sub.colors[3]);
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
441 }
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
442 }
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
443 if (!use_custom_colors)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
444 t->sh_sub.custom_colors = 0;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
445 return 4;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
446 }
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
447
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
448 static int
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
449 vobsub_parse_forced_subs (mkv_track_t *t, const char *start)
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
450 {
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
451 start += 12;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
452 while (isspace(*start))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
453 start++;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
454 if (!strncasecmp(start, "on", 2) || (*start == '1'))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
455 t->sh_sub.forced_subs_only = 1;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
456 else if (!strncasecmp(start, "off", 3) || (*start == '0'))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
457 t->sh_sub.forced_subs_only = 0;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
458 else
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
459 return 0;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
460 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] VobSub forced subs: %d\n",
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
461 t->sh_sub.forced_subs_only);
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
462 return 8;
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
463 }
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
464
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
465 /** \brief Free cached demux packets
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
466 *
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
467 * Reordering the timecodes requires caching of demux packets. This function
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
468 * frees all these cached packets and the memory for the cached pointers
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
469 * itself.
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
470 *
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
471 * \param demuxer The demuxer for which the cache is to be freed.
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
472 */
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
473 static void
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
474 free_cached_dps (demuxer_t *demuxer)
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
475 {
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
476 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
477 mkv_track_t *track;
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
478 int i, k;
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
479
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
480 for (k = 0; k < mkv_d->num_tracks; k++)
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
481 {
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
482 track = mkv_d->tracks[k];
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
483 for (i = 0; i < track->num_cached_dps; i++)
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
484 free_demux_packet (track->cached_dps[i]);
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
485 free(track->cached_dps);
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
486 track->cached_dps = NULL;
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
487 track->num_cached_dps = 0;
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
488 track->num_allocated_dps = 0;
15517
9560b286481c Reset the saved max_pts used for timecode reordering after seeking. Otherwise playback is broken after seeking back in a file that needs the timecodes to be reordered. Patch by Sam Dennis <sam () malfunction ! screaming !net>
mosu
parents: 15450
diff changeset
489 track->max_pts = 0;
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
490 }
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
491 }
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
492
12550
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
493 static int
12547
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
494 demux_mkv_parse_idx (mkv_track_t *t)
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
495 {
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
496 int things_found, last;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
497 char *buf, *pos, *start;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
498
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
499 if ((t->private_data == NULL) || (t->private_size == 0))
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
500 return 0;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
501
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
502 things_found = 0;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
503 buf = (char *)malloc(t->private_size + 1);
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
504 if (buf == NULL)
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
505 return 0;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
506 memcpy(buf, t->private_data, t->private_size);
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
507 buf[t->private_size] = 0;
12550
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
508 t->sh_sub.type = 'v';
14561
a226d301eec1 Handle missing palettes in the info part of VobSubs in Matroska files correctly by giving mplayer a NULL pointer. This way it will use a default palette instead of black only. Patch by Csillag Kristof (fenwick () freemail ! hu)
mosu
parents: 14515
diff changeset
509 t->sh_sub.has_palette = 0;
12547
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
510
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
511 pos = buf;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
512 start = buf;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
513 last = 0;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
514 do
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
515 {
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
516 if ((*pos == 0) || (*pos == '\r') || (*pos == '\n'))
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
517 {
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
518 if (*pos == 0)
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
519 last = 1;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
520 *pos = 0;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
521
12550
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
522 if (!strncasecmp(start, "size: ", 6))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
523 things_found |= vobsub_parse_size(t, start);
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
524 else if (!strncasecmp(start, "palette:", 8))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
525 things_found |= vobsub_parse_palette(t, start);
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
526 else if (!strncasecmp(start, "custom colors:", 14))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
527 things_found |= vobsub_parse_custom_colors(t, start);
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
528 else if (!strncasecmp(start, "forced subs:", 12))
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
529 things_found |= vobsub_parse_forced_subs(t, start);
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
530
12547
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
531 if (last)
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
532 break;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
533 do
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
534 {
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
535 pos++;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
536 }
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
537 while ((*pos == '\r') || (*pos == '\n'));
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
538 start = pos;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
539 }
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
540 else
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
541 pos++;
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
542 }
12550
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
543 while (!last && (*start != 0));
12547
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
544
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
545 free(buf);
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
546
12550
733c9d9882d1 Support for the "custom colors" and "forced subtitles" entries in the VobSub idx. Made the parser handle whitespaces better.
mosu
parents: 12547
diff changeset
547 return (things_found & 3) == 3;
12547
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
548 }
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
549
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
550
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
551 static int
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
552 demux_mkv_decode (mkv_track_t *track, uint8_t *src, uint8_t **dest,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
553 uint32_t *size, uint32_t type)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
554 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
555 int i, result;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
556 int modified = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
557
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
558 *dest = src;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
559 if (track->num_encodings <= 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
560 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
561
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
562 for (i=0; i<track->num_encodings; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
563 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
564 if (!(track->encodings[i].scope & type))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
565 continue;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
566
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
567 #ifdef HAVE_ZLIB
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
568 if (track->encodings[i].comp_algo == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
569 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
570 /* zlib encoded track */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
571 z_stream zstream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
572
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
573 zstream.zalloc = (alloc_func) 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
574 zstream.zfree = (free_func) 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
575 zstream.opaque = (voidpf) 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
576 if (inflateInit (&zstream) != Z_OK)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
577 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
578 mp_msg (MSGT_DEMUX, MSGL_WARN,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
579 "[mkv] zlib initialization failed.\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
580 return modified;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
581 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
582 zstream.next_in = (Bytef *) src;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
583 zstream.avail_in = *size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
584
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
585 modified = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
586 *dest = (uint8_t *) malloc (*size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
587 zstream.avail_out = *size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
588 do {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
589 *size += 4000;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
590 *dest = (uint8_t *) realloc (*dest, *size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
591 zstream.next_out = (Bytef *) (*dest + zstream.total_out);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
592 result = inflate (&zstream, Z_NO_FLUSH);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
593 if (result != Z_OK && result != Z_STREAM_END)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
594 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
595 mp_msg (MSGT_DEMUX, MSGL_WARN,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
596 "[mkv] zlib decompression failed.\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
597 free(*dest);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
598 *dest = NULL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
599 inflateEnd (&zstream);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
600 return modified;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
601 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
602 zstream.avail_out += 4000;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
603 } while (zstream.avail_out == 4000 &&
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
604 zstream.avail_in != 0 && result != Z_STREAM_END);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
605
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
606 *size = zstream.total_out;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
607 inflateEnd (&zstream);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
608 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
609 #endif
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
610 if (track->encodings[i].comp_algo == 2)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
611 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
612 /* lzo encoded track */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
613 int dstlen = *size * 3;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
614
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
615 if (lzo_init () != LZO_E_OK)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
616 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
617 mp_msg (MSGT_DEMUX, MSGL_WARN,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
618 "[mkv] lzo initialization failed.\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
619 return modified;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
620 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
621
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
622 *dest = (uint8_t *) malloc (dstlen);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
623 while (1)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
624 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
625 result = lzo1x_decompress_safe (src, *size, *dest, &dstlen,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
626 NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
627 if (result == LZO_E_OK)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
628 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
629 if (result != LZO_E_OUTPUT_OVERRUN)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
630 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
631 mp_msg (MSGT_DEMUX, MSGL_WARN,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
632 "[mkv] lzo decompression failed.\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
633 return modified;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
634 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
635 mp_msg (MSGT_DEMUX, MSGL_DBG2,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
636 "[mkv] lzo decompression buffer too small.\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
637 dstlen *= 2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
638 *dest = (uint8_t *) realloc (*dest, dstlen);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
639 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
640 *size = dstlen;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
641 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
642 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
643
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
644 return modified;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
645 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
646
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
647
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
648 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
649 demux_mkv_read_info (demuxer_t *demuxer)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
650 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
651 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
652 stream_t *s = demuxer->stream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
653 uint64_t length, l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
654 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
655
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
656 length = ebml_read_length (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
657 while (length > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
658 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
659 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
660 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
661 case MATROSKA_ID_TIMECODESCALE:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
662 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
663 uint64_t num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
664 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
665 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
666 mkv_d->tc_scale = num;
16750
0a31740dd5e6 Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents: 16346
diff changeset
667 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + timecode scale: %"PRIu64"\n",
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
668 mkv_d->tc_scale);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
669 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
670 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
671
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
672 case MATROSKA_ID_DURATION:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
673 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
674 long double num = ebml_read_float (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
675 if (num == EBML_FLOAT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
676 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
677 mkv_d->duration = num * mkv_d->tc_scale / 1000000000.0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
678 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + duration: %.3fs\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
679 mkv_d->duration);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
680 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
681 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
682
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
683 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
684 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
685 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
686 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
687 length -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
688 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
689 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
690 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
691
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
692 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
693 demux_mkv_read_trackencodings (demuxer_t *demuxer, mkv_track_t *track)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
694 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
695 stream_t *s = demuxer->stream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
696 mkv_content_encoding_t *ce, e;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
697 uint64_t len, length, l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
698 int il, n;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
699
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
700 ce = (mkv_content_encoding_t *) malloc (sizeof (*ce));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
701 n = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
702
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
703 len = length = ebml_read_length (s, &il);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
704 len += il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
705 while (length > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
706 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
707 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
708 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
709 case MATROSKA_ID_CONTENTENCODING:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
710 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
711 uint64_t len;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
712 int i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
713
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
714 memset (&e, 0, sizeof (e));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
715 e.scope = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
716
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
717 len = ebml_read_length (s, &i);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
718 l = len + i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
719
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
720 while (len > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
721 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
722 uint64_t num, l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
723 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
724
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
725 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
726 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
727 case MATROSKA_ID_CONTENTENCODINGORDER:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
728 num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
729 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
730 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
731 e.order = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
732 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
733
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
734 case MATROSKA_ID_CONTENTENCODINGSCOPE:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
735 num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
736 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
737 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
738 e.scope = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
739 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
740
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
741 case MATROSKA_ID_CONTENTENCODINGTYPE:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
742 num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
743 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
744 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
745 e.type = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
746 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
747
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
748 case MATROSKA_ID_CONTENTCOMPRESSION:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
749 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
750 uint64_t le;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
751
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
752 le = ebml_read_length (s, &i);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
753 l = le + i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
754
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
755 while (le > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
756 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
757 uint64_t l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
758 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
759
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
760 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
761 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
762 case MATROSKA_ID_CONTENTCOMPALGO:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
763 num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
764 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
765 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
766 e.comp_algo = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
767 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
768
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
769 case MATROSKA_ID_CONTENTCOMPSETTINGS:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
770 l = ebml_read_length (s, &i);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
771 e.comp_settings = (uint8_t *) malloc (l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
772 stream_read (s, e.comp_settings, l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
773 e.comp_settings_len = l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
774 l += i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
775 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
776
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
777 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
778 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
779 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
780 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
781 le -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
782 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
783
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
784 if (e.type == 1)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
785 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
786 mp_msg(MSGT_DEMUX, MSGL_WARN,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
787 "[mkv] Track number %u has been encrypted "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
788 "and decryption has not yet been implemented."
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
789 " Skipping track.\n", track->tnum);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
790 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
791 else if (e.type != 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
792 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
793 mp_msg(MSGT_DEMUX, MSGL_WARN,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
794 "[mkv] Unknown content encoding type for "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
795 "track %u. Skipping track.\n", track->tnum);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
796 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
797
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
798 if (e.comp_algo != 0 && e.comp_algo != 2)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
799 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
800 mp_msg (MSGT_DEMUX, MSGL_WARN,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
801 "[mkv] Track %u has been compressed with an "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
802 "unknown/unsupported compression algorithm "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
803 "(%u). Skipping track.\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
804 track->tnum, e.comp_algo);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
805 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
806 #ifndef HAVE_ZLIB
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
807 else if (e.comp_algo == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
808 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
809 mp_msg (MSGT_DEMUX, MSGL_WARN,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
810 "Track %u was compressed with zlib but "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
811 "mplayer has not been compiled with support "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
812 "for zlib compression. Skipping track.\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
813 track->tnum);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
814 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
815 #endif
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
816
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
817 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
818 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
819
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
820 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
821 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
822 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
823 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
824 len -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
825 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
826 for (i=0; i<n; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
827 if (e.order <= ce[i].order)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
828 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
829 ce = (mkv_content_encoding_t *) realloc (ce, (n+1) *sizeof (*ce));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
830 memmove (ce+i+1, ce+i, (n-i) * sizeof (*ce));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
831 memcpy (ce+i, &e, sizeof (e));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
832 n++;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
833 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
834 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
835
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
836 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
837 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
838 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
839 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
840
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
841 length -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
842 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
843
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
844 track->encodings = ce;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
845 track->num_encodings = n;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
846 return len;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
847 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
848
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
849 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
850 demux_mkv_read_trackaudio (demuxer_t *demuxer, mkv_track_t *track)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
851 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
852 stream_t *s = demuxer->stream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
853 uint64_t len, length, l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
854 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
855
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
856 track->a_sfreq = 8000.0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
857 track->a_channels = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
858
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
859 len = length = ebml_read_length (s, &il);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
860 len += il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
861 while (length > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
862 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
863 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
864 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
865 case MATROSKA_ID_AUDIOSAMPLINGFREQ:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
866 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
867 long double num = ebml_read_float (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
868 if (num == EBML_FLOAT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
869 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
870 track->a_sfreq = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
871 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Sampling frequency: %f\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
872 track->a_sfreq);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
873 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
874 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
875
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
876 case MATROSKA_ID_AUDIOBITDEPTH:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
877 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
878 uint64_t num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
879 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
880 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
881 track->a_bps = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
882 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Bit depth: %u\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
883 track->a_bps);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
884 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
885 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
886
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
887 case MATROSKA_ID_AUDIOCHANNELS:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
888 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
889 uint64_t num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
890 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
891 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
892 track->a_channels = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
893 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Channels: %u\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
894 track->a_channels);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
895 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
896 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
897
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
898 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
899 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
900 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
901 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
902 length -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
903 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
904 return len;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
905 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
906
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
907 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
908 demux_mkv_read_trackvideo (demuxer_t *demuxer, mkv_track_t *track)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
909 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
910 stream_t *s = demuxer->stream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
911 uint64_t len, length, l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
912 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
913
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
914 len = length = ebml_read_length (s, &il);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
915 len += il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
916 while (length > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
917 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
918 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
919 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
920 case MATROSKA_ID_VIDEOFRAMERATE:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
921 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
922 long double num = ebml_read_float (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
923 if (num == EBML_FLOAT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
924 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
925 track->v_frate = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
926 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Frame rate: %f\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
927 track->v_frate);
14058
4dee22ed8608 Make use of the default duration for one frame if it is present in the file. This produces much smoother timecodes for laced audio frames. And I REALLY don't know why I missed that before...
mosu
parents: 14054
diff changeset
928 if (track->v_frate > 0)
4dee22ed8608 Make use of the default duration for one frame if it is present in the file. This produces much smoother timecodes for laced audio frames. And I REALLY don't know why I missed that before...
mosu
parents: 14054
diff changeset
929 track->default_duration = 1 / track->v_frate;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
930 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
931 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
932
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
933 case MATROSKA_ID_VIDEODISPLAYWIDTH:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
934 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
935 uint64_t num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
936 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
937 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
938 track->v_dwidth = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
939 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Display width: %u\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
940 track->v_dwidth);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
941 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
942 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
943
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
944 case MATROSKA_ID_VIDEODISPLAYHEIGHT:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
945 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
946 uint64_t num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
947 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
948 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
949 track->v_dheight = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
950 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Display height: %u\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
951 track->v_dheight);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
952 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
953 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
954
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
955 case MATROSKA_ID_VIDEOPIXELWIDTH:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
956 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
957 uint64_t num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
958 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
959 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
960 track->v_width = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
961 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Pixel width: %u\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
962 track->v_width);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
963 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
964 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
965
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
966 case MATROSKA_ID_VIDEOPIXELHEIGHT:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
967 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
968 uint64_t num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
969 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
970 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
971 track->v_height = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
972 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Pixel height: %u\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
973 track->v_height);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
974 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
975 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
976
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
977 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
978 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
979 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
980 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
981 length -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
982 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
983 return len;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
984 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
985
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
986 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
987 demux_mkv_read_trackentry (demuxer_t *demuxer)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
988 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
989 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
990 stream_t *s = demuxer->stream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
991 mkv_track_t *track;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
992 uint64_t len, length, l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
993 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
994
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
995 track = (mkv_track_t *) malloc (sizeof (*track));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
996 memset(track, 0, sizeof(*track));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
997 /* set default values */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
998 track->default_track = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
999 track->language = strdup("eng");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1000
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1001 len = length = ebml_read_length (s, &il);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1002 len += il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1003 while (length > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1004 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1005 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1006 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1007 case MATROSKA_ID_TRACKNUMBER:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1008 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1009 uint64_t num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1010 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1011 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1012 track->tnum = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1013 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Track number: %u\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1014 track->tnum);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1015 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1016 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1017
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1018 case MATROSKA_ID_TRACKTYPE:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1019 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1020 uint64_t num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1021 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1022 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1023 track->type = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1024 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Track type: ");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1025 switch (track->type)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1026 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1027 case MATROSKA_TRACK_AUDIO:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1028 mp_msg (MSGT_DEMUX, MSGL_V, "Audio\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1029 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1030 case MATROSKA_TRACK_VIDEO:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1031 mp_msg (MSGT_DEMUX, MSGL_V, "Video\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1032 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1033 case MATROSKA_TRACK_SUBTITLE:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1034 mp_msg (MSGT_DEMUX, MSGL_V, "Subtitle\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1035 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1036 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1037 mp_msg (MSGT_DEMUX, MSGL_V, "unknown\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1038 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1039 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1040 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1041 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1042
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1043 case MATROSKA_ID_TRACKAUDIO:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1044 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Audio track\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1045 l = demux_mkv_read_trackaudio (demuxer, track);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1046 if (l == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1047 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1048 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1049
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1050 case MATROSKA_ID_TRACKVIDEO:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1051 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Video track\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1052 l = demux_mkv_read_trackvideo (demuxer, track);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1053 if (l == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1054 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1055 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1056
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1057 case MATROSKA_ID_CODECID:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1058 track->codec_id = ebml_read_ascii (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1059 if (track->codec_id == NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1060 return 0;
12101
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1061 if (!strcmp (track->codec_id, MKV_V_MSCOMP) ||
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1062 !strcmp (track->codec_id, MKV_A_ACM))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1063 track->ms_compat = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1064 else if (!strcmp (track->codec_id, MKV_S_VOBSUB))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1065 track->subtitle_type = MATROSKA_SUBTYPE_VOBSUB;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1066 else if (!strcmp (track->codec_id, MKV_S_TEXTSSA)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1067 || !strcmp (track->codec_id, MKV_S_TEXTASS)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1068 || !strcmp (track->codec_id, MKV_S_SSA)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1069 || !strcmp (track->codec_id, MKV_S_ASS))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1070 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1071 track->subtitle_type = MATROSKA_SUBTYPE_SSA;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1072 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1073 else if (!strcmp (track->codec_id, MKV_S_TEXTASCII))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1074 track->subtitle_type = MATROSKA_SUBTYPE_TEXT;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1075 if (!strcmp (track->codec_id, MKV_S_TEXTUTF8))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1076 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1077 track->subtitle_type = MATROSKA_SUBTYPE_TEXT;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1078 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1079 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Codec ID: %s\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1080 track->codec_id);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1081 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1082
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1083 case MATROSKA_ID_CODECPRIVATE:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1084 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1085 int x;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1086 uint64_t num = ebml_read_length (s, &x);
18558
4928dd61f136 Fix potential integer overflows in memory allocation.
rtogni
parents: 18507
diff changeset
1087 // audit: cheap guard against overflows later..
4928dd61f136 Fix potential integer overflows in memory allocation.
rtogni
parents: 18507
diff changeset
1088 if (num > SIZE_MAX - 1000) return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1089 l = x + num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1090 track->private_data = malloc (num);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1091 if (stream_read(s, track->private_data, num) != (int) num)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1092 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1093 track->private_size = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1094 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + CodecPrivate, length "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1095 "%u\n", track->private_size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1096 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1097 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1098
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1099 case MATROSKA_ID_TRACKLANGUAGE:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1100 track->language = ebml_read_utf8 (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1101 if (track->language == NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1102 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1103 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Language: %s\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1104 track->language);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1105 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1106
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1107 case MATROSKA_ID_TRACKFLAGDEFAULT:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1108 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1109 uint64_t num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1110 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1111 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1112 track->default_track = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1113 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Default flag: %u\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1114 track->default_track);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1115 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1116 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1117
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1118 case MATROSKA_ID_TRACKDEFAULTDURATION:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1119 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1120 uint64_t num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1121 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1122 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1123 if (num == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1124 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Default duration: 0");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1125 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1126 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1127 track->v_frate = 1000000000.0 / num;
14058
4dee22ed8608 Make use of the default duration for one frame if it is present in the file. This produces much smoother timecodes for laced audio frames. And I REALLY don't know why I missed that before...
mosu
parents: 14054
diff changeset
1128 track->default_duration = num / 1000000000.0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1129 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + Default duration: "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1130 "%.3fms ( = %.3f fps)\n",num/1000000.0,track->v_frate);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1131 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1132 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1133 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1134
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1135 case MATROSKA_ID_TRACKENCODINGS:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1136 l = demux_mkv_read_trackencodings (demuxer, track);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1137 if (l == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1138 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1139 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1140
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1141 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1142 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1143 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1144 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1145 length -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1146 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1147
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1148 mkv_d->tracks[mkv_d->num_tracks++] = track;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1149 return len;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1150 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1151
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1152 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1153 demux_mkv_read_tracks (demuxer_t *demuxer)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1154 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1155 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1156 stream_t *s = demuxer->stream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1157 uint64_t length, l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1158 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1159
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1160 mkv_d->tracks = (mkv_track_t **) malloc (sizeof (*mkv_d->tracks));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1161 mkv_d->num_tracks = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1162
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1163 length = ebml_read_length (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1164 while (length > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1165 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1166 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1167 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1168 case MATROSKA_ID_TRACKENTRY:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1169 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] | + a track...\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1170 mkv_d->tracks = (mkv_track_t **) realloc (mkv_d->tracks,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1171 (mkv_d->num_tracks+1)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1172 *sizeof (*mkv_d->tracks));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1173 l = demux_mkv_read_trackentry (demuxer);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1174 if (l == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1175 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1176 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1177
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1178 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1179 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1180 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1181 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1182 length -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1183 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1184 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1185 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1186
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1187 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1188 demux_mkv_read_cues (demuxer_t *demuxer)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1189 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1190 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1191 stream_t *s = demuxer->stream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1192 uint64_t length, l, time, track, pos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1193 off_t off;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1194 int i, il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1195
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1196 off = stream_tell (s);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1197 for (i=0; i<mkv_d->parsed_cues_num; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1198 if (mkv_d->parsed_cues[i] == off)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1199 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1200 ebml_read_skip (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1201 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1202 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1203 mkv_d->parsed_cues = (off_t *) realloc (mkv_d->parsed_cues,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1204 (mkv_d->parsed_cues_num+1)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1205 * sizeof (off_t));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1206 mkv_d->parsed_cues[mkv_d->parsed_cues_num++] = off;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1207
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1208 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] /---- [ parsing cues ] -----------\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1209 length = ebml_read_length (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1210
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1211 while (length > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1212 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1213 time = track = pos = EBML_UINT_INVALID;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1214
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1215 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1216 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1217 case MATROSKA_ID_POINTENTRY:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1218 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1219 uint64_t len;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1220
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1221 len = ebml_read_length (s, &i);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1222 l = len + i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1223
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1224 while (len > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1225 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1226 uint64_t l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1227 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1228
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1229 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1230 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1231 case MATROSKA_ID_CUETIME:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1232 time = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1233 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1234
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1235 case MATROSKA_ID_CUETRACKPOSITION:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1236 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1237 uint64_t le;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1238
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1239 le = ebml_read_length (s, &i);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1240 l = le + i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1241
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1242 while (le > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1243 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1244 uint64_t l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1245 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1246
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1247 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1248 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1249 case MATROSKA_ID_CUETRACK:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1250 track = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1251 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1252
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1253 case MATROSKA_ID_CUECLUSTERPOSITION:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1254 pos = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1255 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1256
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1257 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1258 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1259 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1260 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1261 le -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1262 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1263 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1264 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1265
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1266 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1267 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1268 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1269 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1270 len -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1271 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1272 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1273 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1274
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1275 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1276 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1277 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1278 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1279
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1280 length -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1281
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1282 if (time != EBML_UINT_INVALID && track != EBML_UINT_INVALID
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1283 && pos != EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1284 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1285 if (mkv_d->indexes == NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1286 mkv_d->indexes = (mkv_index_t *) malloc (32*sizeof (mkv_index_t));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1287 else if (mkv_d->num_indexes % 32 == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1288 mkv_d->indexes = (mkv_index_t *) realloc (mkv_d->indexes,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1289 (mkv_d->num_indexes+32)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1290 *sizeof (mkv_index_t));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1291 mkv_d->indexes[mkv_d->num_indexes].tnum = track;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1292 mkv_d->indexes[mkv_d->num_indexes].timecode = time;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1293 mkv_d->indexes[mkv_d->num_indexes].filepos =mkv_d->segment_start+pos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1294 mp_msg (MSGT_DEMUX, MSGL_DBG2, "[mkv] |+ found cue point "
16750
0a31740dd5e6 Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents: 16346
diff changeset
1295 "for track %"PRIu64": timecode %"PRIu64", filepos: %"PRIu64"\n",
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1296 track, time, mkv_d->segment_start + pos);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1297 mkv_d->num_indexes++;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1298 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1299 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1300
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1301 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] \\---- [ parsing cues ] -----------\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1302 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1303 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1304
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1305 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1306 demux_mkv_read_chapters (demuxer_t *demuxer)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1307 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1308 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1309 stream_t *s = demuxer->stream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1310 uint64_t length, l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1311 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1312
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1313 if (mkv_d->chapters)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1314 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1315 ebml_read_skip (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1316 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1317 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1318
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1319 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] /---- [ parsing chapters ] ---------\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1320 length = ebml_read_length (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1321
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1322 while (length > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1323 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1324 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1325 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1326 case MATROSKA_ID_EDITIONENTRY:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1327 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1328 uint64_t len;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1329 int i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1330
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1331 len = ebml_read_length (s, &i);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1332 l = len + i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1333
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1334 while (len > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1335 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1336 uint64_t l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1337 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1338
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1339 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1340 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1341 case MATROSKA_ID_CHAPTERATOM:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1342 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1343 uint64_t len, start=0, end=0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1344 int i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1345
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1346 len = ebml_read_length (s, &i);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1347 l = len + i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1348
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1349 if (mkv_d->chapters == NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1350 mkv_d->chapters = malloc (32*sizeof(*mkv_d->chapters));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1351 else if (!(mkv_d->num_chapters % 32))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1352 mkv_d->chapters = realloc (mkv_d->chapters,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1353 (mkv_d->num_chapters + 32)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1354 * sizeof(*mkv_d->chapters));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1355
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1356 while (len > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1357 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1358 uint64_t l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1359 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1360
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1361 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1362 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1363 case MATROSKA_ID_CHAPTERTIMESTART:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1364 start = ebml_read_uint (s, &l) / 1000000;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1365 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1366
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1367 case MATROSKA_ID_CHAPTERTIMEEND:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1368 end = ebml_read_uint (s, &l) / 1000000;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1369 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1370
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1371 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1372 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1373 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1374 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1375 len -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1376 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1377
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1378 mkv_d->chapters[mkv_d->num_chapters].start = start;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1379 mkv_d->chapters[mkv_d->num_chapters].end = end;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1380 mp_msg(MSGT_DEMUX, MSGL_V,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1381 "[mkv] Chapter %u from %02d:%02d:%02d."
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1382 "%03d to %02d:%02d:%02d.%03d\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1383 ++mkv_d->num_chapters,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1384 (int) (start / 60 / 60 / 1000),
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1385 (int) ((start / 60 / 1000) % 60),
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1386 (int) ((start / 1000) % 60),
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1387 (int) (start % 1000),
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1388 (int) (end / 60 / 60 / 1000),
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1389 (int) ((end / 60 / 1000) % 60),
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1390 (int) ((end / 1000) % 60),
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1391 (int) (end % 1000));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1392 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1393 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1394
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1395 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1396 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1397 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1398 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1399 len -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1400 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1401 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1402 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1403
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1404 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1405 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1406 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1407 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1408
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1409 length -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1410 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1411
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1412 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] \\---- [ parsing chapters ] ---------\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1413 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1414 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1415
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1416 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1417 demux_mkv_read_tags (demuxer_t *demuxer)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1418 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1419 ebml_read_skip (demuxer->stream, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1420 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1421 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1422
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1423 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1424 demux_mkv_read_seekhead (demuxer_t *demuxer)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1425 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1426 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1427 stream_t *s = demuxer->stream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1428 uint64_t length, l, seek_pos, saved_pos, num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1429 uint32_t seek_id;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1430 int i, il, res = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1431 off_t off;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1432
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1433 off = stream_tell (s);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1434 for (i=0; i<mkv_d->parsed_seekhead_num; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1435 if (mkv_d->parsed_seekhead[i] == off)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1436 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1437 ebml_read_skip (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1438 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1439 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1440 mkv_d->parsed_seekhead = (off_t *) realloc (mkv_d->parsed_seekhead,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1441 (mkv_d->parsed_seekhead_num+1)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1442 * sizeof (off_t));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1443 mkv_d->parsed_seekhead[mkv_d->parsed_seekhead_num++] = off;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1444
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1445 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] /---- [ parsing seek head ] ---------\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1446 length = ebml_read_length (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1447 while (length > 0 && !res)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1448 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1449
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1450 seek_id = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1451 seek_pos = EBML_UINT_INVALID;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1452
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1453 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1454 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1455 case MATROSKA_ID_SEEKENTRY:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1456 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1457 uint64_t len;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1458
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1459 len = ebml_read_length (s, &i);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1460 l = len + i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1461
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1462 while (len > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1463 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1464 uint64_t l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1465 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1466
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1467 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1468 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1469 case MATROSKA_ID_SEEKID:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1470 num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1471 if (num != EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1472 seek_id = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1473 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1474
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1475 case MATROSKA_ID_SEEKPOSITION:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1476 seek_pos = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1477 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1478
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1479 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1480 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1481 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1482 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1483 len -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1484 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1485
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1486 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1487 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1488
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1489 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1490 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1491 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1492 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1493 length -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1494
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1495 if (seek_id == 0 || seek_id == MATROSKA_ID_CLUSTER
11899
18bd28454ef6 Do not try to seek beyond the end of the stream when parsing the headers.
mosu
parents: 11856
diff changeset
1496 || seek_pos == EBML_UINT_INVALID ||
18bd28454ef6 Do not try to seek beyond the end of the stream when parsing the headers.
mosu
parents: 11856
diff changeset
1497 ((mkv_d->segment_start + seek_pos) >= (uint64_t)demuxer->movi_end))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1498 continue;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1499
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1500 saved_pos = stream_tell (s);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1501 if (!stream_seek (s, mkv_d->segment_start + seek_pos))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1502 res = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1503 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1504 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1505 if (ebml_read_id (s, &il) != seek_id)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1506 res = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1507 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1508 switch (seek_id)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1509 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1510 case MATROSKA_ID_CUES:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1511 if (demux_mkv_read_cues (demuxer))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1512 res = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1513 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1514
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1515 case MATROSKA_ID_TAGS:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1516 if (demux_mkv_read_tags (demuxer))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1517 res = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1518 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1519
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1520 case MATROSKA_ID_SEEKHEAD:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1521 if (demux_mkv_read_seekhead (demuxer))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1522 res = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1523 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1524
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1525 case MATROSKA_ID_CHAPTERS:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1526 if (demux_mkv_read_chapters (demuxer))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1527 res = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1528 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1529 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1530 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1531
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1532 stream_seek (s, saved_pos);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1533 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1534 if (length > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1535 stream_seek (s, stream_tell (s) + length);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1536 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] \\---- [ parsing seek head ] ---------\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1537 return res;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1538 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1539
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1540 static void
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1541 display_tracks (mkv_demuxer_t *mkv_d)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1542 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1543 int i, vid=0, aid=0, sid=0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1544
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1545 for (i=0; i<mkv_d->num_tracks; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1546 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1547 char *type = "unknown", str[32];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1548 *str = '\0';
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1549 switch (mkv_d->tracks[i]->type)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1550 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1551 case MATROSKA_TRACK_VIDEO:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1552 type = "video";
18237
4231482179b6 Get ride of the several if(identify) messy lines and rearangment of some of the output, both patches by Kiriuja mplayer-patches AT en-directo_net, his changes are barely unrelated, nevertheless Im commiting them thogeter just for the sake of my mental healt, I had both patches already applied on my local three
reynaldo
parents: 18236
diff changeset
1553 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_ID=%d\n", vid);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1554 sprintf (str, "-vid %u", vid++);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1555 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1556 case MATROSKA_TRACK_AUDIO:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1557 type = "audio";
18237
4231482179b6 Get ride of the several if(identify) messy lines and rearangment of some of the output, both patches by Kiriuja mplayer-patches AT en-directo_net, his changes are barely unrelated, nevertheless Im commiting them thogeter just for the sake of my mental healt, I had both patches already applied on my local three
reynaldo
parents: 18236
diff changeset
1558 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_ID=%d\n", aid);
4231482179b6 Get ride of the several if(identify) messy lines and rearangment of some of the output, both patches by Kiriuja mplayer-patches AT en-directo_net, his changes are barely unrelated, nevertheless Im commiting them thogeter just for the sake of my mental healt, I had both patches already applied on my local three
reynaldo
parents: 18236
diff changeset
1559 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AID_%d_LANG=%s\n", aid, mkv_d->tracks[i]->language);
12288
8c8c71a02e5a fix exploitable buffer overflow
rfelker
parents: 12101
diff changeset
1560 sprintf (str, "-aid %u, -alang %.5s",aid++,mkv_d->tracks[i]->language);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1561 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1562 case MATROSKA_TRACK_SUBTITLE:
13324
dcbdd8ea356d Spelling. Patch by Jan Minar <jjminar at fastmail onedot fm>.
mosu
parents: 13131
diff changeset
1563 type = "subtitles";
18237
4231482179b6 Get ride of the several if(identify) messy lines and rearangment of some of the output, both patches by Kiriuja mplayer-patches AT en-directo_net, his changes are barely unrelated, nevertheless Im commiting them thogeter just for the sake of my mental healt, I had both patches already applied on my local three
reynaldo
parents: 18236
diff changeset
1564 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SUBTITLE_ID=%d\n", sid);
4231482179b6 Get ride of the several if(identify) messy lines and rearangment of some of the output, both patches by Kiriuja mplayer-patches AT en-directo_net, his changes are barely unrelated, nevertheless Im commiting them thogeter just for the sake of my mental healt, I had both patches already applied on my local three
reynaldo
parents: 18236
diff changeset
1565 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SID_%d_LANG=%s\n", sid, mkv_d->tracks[i]->language);
12288
8c8c71a02e5a fix exploitable buffer overflow
rfelker
parents: 12101
diff changeset
1566 sprintf (str, "-sid %u, -slang %.5s",sid++,mkv_d->tracks[i]->language);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1567 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1568 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1569 mp_msg(MSGT_DEMUX, MSGL_INFO, "[mkv] Track ID %u: %s (%s), %s\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1570 mkv_d->tracks[i]->tnum, type, mkv_d->tracks[i]->codec_id, str);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1571 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1572 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1573
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1574 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1575 demux_mkv_open_video (demuxer_t *demuxer, mkv_track_t *track)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1576 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1577 BITMAPINFOHEADER *bih;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1578 void *ImageDesc = NULL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1579 sh_video_t *sh_v;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1580
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1581 if (track->ms_compat) /* MS compatibility mode */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1582 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1583 BITMAPINFOHEADER *src;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1584
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1585 if (track->private_data == NULL
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1586 || track->private_size < sizeof (BITMAPINFOHEADER))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1587 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1588
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1589 src = (BITMAPINFOHEADER *) track->private_data;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1590 bih = (BITMAPINFOHEADER *) malloc (track->private_size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1591 memset (bih, 0, track->private_size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1592 bih->biSize = le2me_32 (src->biSize);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1593 bih->biWidth = le2me_32 (src->biWidth);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1594 bih->biHeight = le2me_32 (src->biHeight);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1595 bih->biPlanes = le2me_16 (src->biPlanes);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1596 bih->biBitCount = le2me_16 (src->biBitCount);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1597 bih->biCompression = le2me_32 (src->biCompression);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1598 bih->biSizeImage = le2me_32 (src->biSizeImage);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1599 bih->biXPelsPerMeter = le2me_32 (src->biXPelsPerMeter);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1600 bih->biYPelsPerMeter = le2me_32 (src->biYPelsPerMeter);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1601 bih->biClrUsed = le2me_32 (src->biClrUsed);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1602 bih->biClrImportant = le2me_32 (src->biClrImportant);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1603 memcpy((char *) bih + sizeof (BITMAPINFOHEADER),
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1604 (char *) src + sizeof (BITMAPINFOHEADER),
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1605 track->private_size - sizeof (BITMAPINFOHEADER));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1606
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1607 if (track->v_width == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1608 track->v_width = bih->biWidth;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1609 if (track->v_height == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1610 track->v_height = bih->biHeight;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1611 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1612 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1613 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1614 bih = (BITMAPINFOHEADER *) malloc (sizeof (BITMAPINFOHEADER));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1615 memset (bih, 0, sizeof (BITMAPINFOHEADER));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1616 bih->biSize = sizeof (BITMAPINFOHEADER);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1617 bih->biWidth = track->v_width;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1618 bih->biHeight = track->v_height;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1619 bih->biBitCount = 24;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1620 bih->biSizeImage = bih->biWidth * bih->biHeight * bih->biBitCount/8;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1621
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1622 if (track->private_size >= sizeof (real_video_props_t)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1623 && (!strcmp (track->codec_id, MKV_V_REALV10)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1624 || !strcmp (track->codec_id, MKV_V_REALV20)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1625 || !strcmp (track->codec_id, MKV_V_REALV30)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1626 || !strcmp (track->codec_id, MKV_V_REALV40)))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1627 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1628 unsigned char *dst, *src;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1629 real_video_props_t *rvp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1630 uint32_t type2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1631
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1632 rvp = (real_video_props_t *) track->private_data;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1633 src = (unsigned char *) (rvp + 1);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1634
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1635 bih = (BITMAPINFOHEADER *) realloc(bih,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1636 sizeof (BITMAPINFOHEADER)+12);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1637 bih->biSize = 48;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1638 bih->biPlanes = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1639 type2 = be2me_32 (rvp->type2);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1640 if (type2 == 0x10003000 || type2 == 0x10003001)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1641 bih->biCompression=mmioFOURCC('R','V','1','3');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1642 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1643 bih->biCompression=mmioFOURCC('R','V',track->codec_id[9],'0');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1644 dst = (unsigned char *) (bih + 1);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1645 ((unsigned int *) dst)[0] = be2me_32 (rvp->type1);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1646 ((unsigned int *) dst)[1] = type2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1647
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1648 if (bih->biCompression <= 0x30335652 && type2 >= 0x20200002)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1649 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1650 /* read secondary WxH for the cmsg24[] (see vd_realvid.c) */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1651 ((unsigned short *)(bih+1))[4] = 4 * (unsigned short) src[0];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1652 ((unsigned short *)(bih+1))[5] = 4 * (unsigned short) src[1];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1653 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1654 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1655 memset(&dst[8], 0, 4);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1656 track->realmedia = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1657
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1658 #ifdef USE_QTX_CODECS
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1659 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1660 else if (track->private_size >= sizeof (ImageDescription)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1661 && !strcmp(track->codec_id, MKV_V_QUICKTIME))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1662 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1663 ImageDescriptionPtr idesc;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1664
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1665 idesc = (ImageDescriptionPtr) track->private_data;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1666 idesc->idSize = be2me_32 (idesc->idSize);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1667 idesc->cType = be2me_32 (idesc->cType);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1668 idesc->version = be2me_16 (idesc->version);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1669 idesc->revisionLevel = be2me_16 (idesc->revisionLevel);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1670 idesc->vendor = be2me_32 (idesc->vendor);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1671 idesc->temporalQuality = be2me_32 (idesc->temporalQuality);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1672 idesc->spatialQuality = be2me_32 (idesc->spatialQuality);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1673 idesc->width = be2me_16 (idesc->width);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1674 idesc->height = be2me_16 (idesc->height);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1675 idesc->hRes = be2me_32 (idesc->hRes);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1676 idesc->vRes = be2me_32 (idesc->vRes);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1677 idesc->dataSize = be2me_32 (idesc->dataSize);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1678 idesc->frameCount = be2me_16 (idesc->frameCount);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1679 idesc->depth = be2me_16 (idesc->depth);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1680 idesc->clutID = be2me_16 (idesc->clutID);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1681 bih->biPlanes = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1682 bih->biCompression = idesc->cType;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1683 ImageDesc = idesc;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1684 #endif /* USE_QTX_CODECS */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1685
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1686 }
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
1687 else if (!strcmp(track->codec_id, MKV_V_MPEG1))
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
1688 {
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
1689 bih->biCompression = mmioFOURCC('m', 'p', 'g', '1');
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
1690 track->reorder_timecodes = 1;
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
1691 }
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
1692 else if (!strcmp(track->codec_id, MKV_V_MPEG2))
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
1693 {
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
1694 bih->biCompression = mmioFOURCC('m', 'p', 'g', '2');
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
1695 track->reorder_timecodes = 1;
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
1696 }
14458
6e5956958746 Support for AVC in Matroska.
mosu
parents: 14058
diff changeset
1697 else if (!strcmp(track->codec_id, MKV_V_MPEG4_AVC))
6e5956958746 Support for AVC in Matroska.
mosu
parents: 14058
diff changeset
1698 {
6e5956958746 Support for AVC in Matroska.
mosu
parents: 14058
diff changeset
1699 bih->biCompression = mmioFOURCC('a', 'v', 'c', '1');
6e5956958746 Support for AVC in Matroska.
mosu
parents: 14058
diff changeset
1700 if (track->private_data && (track->private_size > 0))
6e5956958746 Support for AVC in Matroska.
mosu
parents: 14058
diff changeset
1701 {
6e5956958746 Support for AVC in Matroska.
mosu
parents: 14058
diff changeset
1702 bih->biSize += track->private_size;
6e5956958746 Support for AVC in Matroska.
mosu
parents: 14058
diff changeset
1703 bih = (BITMAPINFOHEADER *) realloc (bih, bih->biSize);
6e5956958746 Support for AVC in Matroska.
mosu
parents: 14058
diff changeset
1704 memcpy (bih + 1, track->private_data, track->private_size);
6e5956958746 Support for AVC in Matroska.
mosu
parents: 14058
diff changeset
1705 }
6e5956958746 Support for AVC in Matroska.
mosu
parents: 14058
diff changeset
1706 track->reorder_timecodes = 1;
6e5956958746 Support for AVC in Matroska.
mosu
parents: 14058
diff changeset
1707 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1708 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1709 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1710 mp_msg (MSGT_DEMUX,MSGL_WARN,"[mkv] Unknown/unsupported CodecID "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1711 "(%s) or missing/bad CodecPrivate data (track %u).\n",
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1712 track->codec_id, track->tnum);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1713 free(bih);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1714 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1715 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1716 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1717
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1718 sh_v = new_sh_video (demuxer, track->tnum);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1719 sh_v->bih = bih;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1720 sh_v->format = sh_v->bih->biCompression;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1721 if (track->v_frate == 0.0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1722 track->v_frate = 25.0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1723 sh_v->fps = track->v_frate;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1724 sh_v->frametime = 1 / track->v_frate;
13381
8db5683d2b3c fix playback of files with displaysize not set (aspect was set to NaN for these)
reimar
parents: 13324
diff changeset
1725 sh_v->aspect = 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1726 if (!track->realmedia)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1727 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1728 sh_v->disp_w = track->v_width;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1729 sh_v->disp_h = track->v_height;
13381
8db5683d2b3c fix playback of files with displaysize not set (aspect was set to NaN for these)
reimar
parents: 13324
diff changeset
1730 if (track->v_dheight)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1731 sh_v->aspect = (float)track->v_dwidth / (float)track->v_dheight;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1732 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1733 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1734 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1735 // vd_realvid.c will set aspect to disp_w/disp_h and rederive
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1736 // disp_w and disp_h from the RealVideo stream contents returned
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1737 // by the Real DLLs. If DisplayWidth/DisplayHeight was not set in
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1738 // the Matroska file then it has already been set to PixelWidth/Height
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1739 // by check_track_information.
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1740 sh_v->disp_w = track->v_dwidth;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1741 sh_v->disp_h = track->v_dheight;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1742 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1743 sh_v->ImageDesc = ImageDesc;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1744 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] Aspect: %f\n", sh_v->aspect);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1745
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1746 sh_v->ds = demuxer->video;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1747 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1748 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1749
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1750 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1751 demux_mkv_open_audio (demuxer_t *demuxer, mkv_track_t *track)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1752 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1753 sh_audio_t *sh_a = new_sh_audio(demuxer, track->tnum);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1754 demux_packet_t *dp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1755
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1756 sh_a->ds = demuxer->audio;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1757 sh_a->wf = (WAVEFORMATEX *) malloc (sizeof (WAVEFORMATEX));
12101
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1758 if (track->ms_compat && (track->private_size >= sizeof(WAVEFORMATEX)))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1759 {
12101
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1760 WAVEFORMATEX *wf = (WAVEFORMATEX *)track->private_data;
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1761 sh_a->wf = (WAVEFORMATEX *) realloc(sh_a->wf, track->private_size);
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1762 sh_a->wf->wFormatTag = le2me_16 (wf->wFormatTag);
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1763 sh_a->wf->nChannels = le2me_16 (wf->nChannels);
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1764 sh_a->wf->nSamplesPerSec = le2me_32 (wf->nSamplesPerSec);
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1765 sh_a->wf->nAvgBytesPerSec = le2me_32 (wf->nAvgBytesPerSec);
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1766 sh_a->wf->nBlockAlign = le2me_16 (wf->nBlockAlign);
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1767 sh_a->wf->wBitsPerSample = le2me_16 (wf->wBitsPerSample);
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1768 sh_a->wf->cbSize = track->private_size - sizeof(WAVEFORMATEX);
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1769 memcpy(sh_a->wf + 1, wf + 1, track->private_size - sizeof(WAVEFORMATEX));
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1770 if (track->a_sfreq == 0.0)
12101
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1771 track->a_sfreq = sh_a->wf->nSamplesPerSec;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1772 if (track->a_channels == 0)
12101
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1773 track->a_channels = sh_a->wf->nChannels;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1774 if (track->a_bps == 0)
12101
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1775 track->a_bps = sh_a->wf->wBitsPerSample;
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
1776 track->a_formattag = sh_a->wf->wFormatTag;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1777 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1778 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1779 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1780 memset(sh_a->wf, 0, sizeof (WAVEFORMATEX));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1781 if (!strcmp(track->codec_id, MKV_A_MP3) ||
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1782 !strcmp(track->codec_id, MKV_A_MP2))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1783 track->a_formattag = 0x0055;
13804
5c0fda3b83c3 DTS uses the format tag 0x2001. Patch by Joakim Plate (joakim ! plate () ecce ! se)
mosu
parents: 13501
diff changeset
1784 else if (!strncmp(track->codec_id, MKV_A_AC3, strlen(MKV_A_AC3)))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1785 track->a_formattag = 0x2000;
13804
5c0fda3b83c3 DTS uses the format tag 0x2001. Patch by Joakim Plate (joakim ! plate () ecce ! se)
mosu
parents: 13501
diff changeset
1786 else if (!strcmp(track->codec_id, MKV_A_DTS))
5c0fda3b83c3 DTS uses the format tag 0x2001. Patch by Joakim Plate (joakim ! plate () ecce ! se)
mosu
parents: 13501
diff changeset
1787 track->a_formattag = 0x2001;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1788 else if (!strcmp(track->codec_id, MKV_A_PCM) ||
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1789 !strcmp(track->codec_id, MKV_A_PCM_BE))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1790 track->a_formattag = 0x0001;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1791 else if (!strcmp(track->codec_id, MKV_A_AAC_2MAIN) ||
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1792 !strncmp(track->codec_id, MKV_A_AAC_2LC,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1793 strlen(MKV_A_AAC_2LC)) ||
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1794 !strcmp(track->codec_id, MKV_A_AAC_2SSR) ||
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1795 !strcmp(track->codec_id, MKV_A_AAC_4MAIN) ||
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1796 !strncmp(track->codec_id, MKV_A_AAC_4LC,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1797 strlen(MKV_A_AAC_4LC)) ||
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1798 !strcmp(track->codec_id, MKV_A_AAC_4SSR) ||
16824
ab1eb8054890 Added support for A_AAC.
mosu
parents: 16750
diff changeset
1799 !strcmp(track->codec_id, MKV_A_AAC_4LTP) ||
ab1eb8054890 Added support for A_AAC.
mosu
parents: 16750
diff changeset
1800 !strcmp(track->codec_id, MKV_A_AAC))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1801 track->a_formattag = mmioFOURCC('M', 'P', '4', 'A');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1802 else if (!strcmp(track->codec_id, MKV_A_VORBIS))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1803 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1804 if (track->private_data == NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1805 return 1;
14843
bbb693d3b130 Fix the ogg fourcc nightmare!!!
rfelker
parents: 14561
diff changeset
1806 track->a_formattag = mmioFOURCC('v', 'r', 'b', 's');
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1807 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1808 else if (!strcmp(track->codec_id, MKV_A_QDMC))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1809 track->a_formattag = mmioFOURCC('Q', 'D', 'M', 'C');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1810 else if (!strcmp(track->codec_id, MKV_A_QDMC2))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1811 track->a_formattag = mmioFOURCC('Q', 'D', 'M', '2');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1812 else if (!strcmp(track->codec_id, MKV_A_FLAC))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1813 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1814 if (track->private_data == NULL || track->private_size == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1815 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1816 mp_msg (MSGT_DEMUX, MSGL_WARN, "[mkv] FLAC track does not "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1817 "contain valid headers.\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1818 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1819 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1820 track->a_formattag = mmioFOURCC ('f', 'L', 'a', 'C');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1821 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1822 else if (track->private_size >= sizeof (real_audio_v4_props_t))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1823 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1824 if (!strcmp(track->codec_id, MKV_A_REAL28))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1825 track->a_formattag = mmioFOURCC('2', '8', '_', '8');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1826 else if (!strcmp(track->codec_id, MKV_A_REALATRC))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1827 track->a_formattag = mmioFOURCC('a', 't', 'r', 'c');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1828 else if (!strcmp(track->codec_id, MKV_A_REALCOOK))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1829 track->a_formattag = mmioFOURCC('c', 'o', 'o', 'k');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1830 else if (!strcmp(track->codec_id, MKV_A_REALDNET))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1831 track->a_formattag = mmioFOURCC('d', 'n', 'e', 't');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1832 else if (!strcmp(track->codec_id, MKV_A_REALSIPR))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1833 track->a_formattag = mmioFOURCC('s', 'i', 'p', 'r');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1834 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1835 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1836 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1837 mp_msg (MSGT_DEMUX, MSGL_WARN, "[mkv] Unknown/unsupported audio "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1838 "codec ID '%s' for track %u or missing/faulty private "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1839 "codec data.\n", track->codec_id, track->tnum);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1840 free_sh_audio (sh_a);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1841 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1842 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1843 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1844
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1845 sh_a->format = track->a_formattag;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1846 sh_a->wf->wFormatTag = track->a_formattag;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1847 sh_a->channels = track->a_channels;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1848 sh_a->wf->nChannels = track->a_channels;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1849 sh_a->samplerate = (uint32_t) track->a_sfreq;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1850 sh_a->wf->nSamplesPerSec = (uint32_t) track->a_sfreq;
13424
907cc2547357 With the latest change to dec_audio.c (1.32) the demuxers have to set sh_a->samplesize to something != 0.
mosu
parents: 13381
diff changeset
1851 if (track->a_bps == 0)
907cc2547357 With the latest change to dec_audio.c (1.32) the demuxers have to set sh_a->samplesize to something != 0.
mosu
parents: 13381
diff changeset
1852 {
907cc2547357 With the latest change to dec_audio.c (1.32) the demuxers have to set sh_a->samplesize to something != 0.
mosu
parents: 13381
diff changeset
1853 sh_a->samplesize = 2;
907cc2547357 With the latest change to dec_audio.c (1.32) the demuxers have to set sh_a->samplesize to something != 0.
mosu
parents: 13381
diff changeset
1854 sh_a->wf->wBitsPerSample = 16;
907cc2547357 With the latest change to dec_audio.c (1.32) the demuxers have to set sh_a->samplesize to something != 0.
mosu
parents: 13381
diff changeset
1855 }
907cc2547357 With the latest change to dec_audio.c (1.32) the demuxers have to set sh_a->samplesize to something != 0.
mosu
parents: 13381
diff changeset
1856 else
907cc2547357 With the latest change to dec_audio.c (1.32) the demuxers have to set sh_a->samplesize to something != 0.
mosu
parents: 13381
diff changeset
1857 {
907cc2547357 With the latest change to dec_audio.c (1.32) the demuxers have to set sh_a->samplesize to something != 0.
mosu
parents: 13381
diff changeset
1858 sh_a->samplesize = track->a_bps / 8;
907cc2547357 With the latest change to dec_audio.c (1.32) the demuxers have to set sh_a->samplesize to something != 0.
mosu
parents: 13381
diff changeset
1859 sh_a->wf->wBitsPerSample = track->a_bps;
907cc2547357 With the latest change to dec_audio.c (1.32) the demuxers have to set sh_a->samplesize to something != 0.
mosu
parents: 13381
diff changeset
1860 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1861 if (track->a_formattag == 0x0055) /* MP3 || MP2 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1862 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1863 sh_a->wf->nAvgBytesPerSec = 16000;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1864 sh_a->wf->nBlockAlign = 1152;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1865 }
13804
5c0fda3b83c3 DTS uses the format tag 0x2001. Patch by Joakim Plate (joakim ! plate () ecce ! se)
mosu
parents: 13501
diff changeset
1866 else if ((track->a_formattag == 0x2000) || /* AC3 */
5c0fda3b83c3 DTS uses the format tag 0x2001. Patch by Joakim Plate (joakim ! plate () ecce ! se)
mosu
parents: 13501
diff changeset
1867 (track->a_formattag == 0x2001)) /* DTS */
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1868 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1869 sh_a->wf->nAvgBytesPerSec = 16000;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1870 sh_a->wf->nBlockAlign = 1536;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1871 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1872 else if (track->a_formattag == 0x0001) /* PCM || PCM_BE */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1873 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1874 sh_a->wf->nAvgBytesPerSec = sh_a->channels * sh_a->samplerate*2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1875 sh_a->wf->nBlockAlign = sh_a->wf->nAvgBytesPerSec;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1876 if (!strcmp(track->codec_id, MKV_A_PCM_BE))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1877 sh_a->format = mmioFOURCC('t', 'w', 'o', 's');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1878 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1879 else if (!strcmp(track->codec_id, MKV_A_QDMC) ||
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1880 !strcmp(track->codec_id, MKV_A_QDMC2))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1881 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1882 sh_a->wf->nAvgBytesPerSec = 16000;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1883 sh_a->wf->nBlockAlign = 1486;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1884 track->fix_i_bps = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1885 track->qt_last_a_pts = 0.0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1886 if (track->private_data != NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1887 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1888 sh_a->codecdata=(unsigned char *)malloc(track->private_size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1889 memcpy (sh_a->codecdata, track->private_data,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1890 track->private_size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1891 sh_a->codecdata_len = track->private_size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1892 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1893 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1894 else if (track->a_formattag == mmioFOURCC('M', 'P', '4', 'A'))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1895 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1896 int profile, srate_idx;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1897
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1898 sh_a->wf->nAvgBytesPerSec = 16000;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1899 sh_a->wf->nBlockAlign = 1024;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1900
16824
ab1eb8054890 Added support for A_AAC.
mosu
parents: 16750
diff changeset
1901 if (!strcmp (track->codec_id, MKV_A_AAC) &&
ab1eb8054890 Added support for A_AAC.
mosu
parents: 16750
diff changeset
1902 (NULL != track->private_data))
ab1eb8054890 Added support for A_AAC.
mosu
parents: 16750
diff changeset
1903 {
ab1eb8054890 Added support for A_AAC.
mosu
parents: 16750
diff changeset
1904 sh_a->codecdata=(unsigned char *)malloc(track->private_size);
ab1eb8054890 Added support for A_AAC.
mosu
parents: 16750
diff changeset
1905 memcpy (sh_a->codecdata, track->private_data,
ab1eb8054890 Added support for A_AAC.
mosu
parents: 16750
diff changeset
1906 track->private_size);
ab1eb8054890 Added support for A_AAC.
mosu
parents: 16750
diff changeset
1907 sh_a->codecdata_len = track->private_size;
ab1eb8054890 Added support for A_AAC.
mosu
parents: 16750
diff changeset
1908 return 0;
ab1eb8054890 Added support for A_AAC.
mosu
parents: 16750
diff changeset
1909 }
ab1eb8054890 Added support for A_AAC.
mosu
parents: 16750
diff changeset
1910
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1911 /* Recreate the 'private data' */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1912 /* which faad2 uses in its initialization */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1913 srate_idx = aac_get_sample_rate_index (sh_a->samplerate);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1914 if (!strncmp (&track->codec_id[12], "MAIN", 4))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1915 profile = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1916 else if (!strncmp (&track->codec_id[12], "LC", 2))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1917 profile = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1918 else if (!strncmp (&track->codec_id[12], "SSR", 3))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1919 profile = 2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1920 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1921 profile = 3;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1922 sh_a->codecdata = (unsigned char *) malloc (5);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1923 sh_a->codecdata[0] = ((profile+1) << 3) | ((srate_idx&0xE) >> 1);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1924 sh_a->codecdata[1] = ((srate_idx&0x1)<<7)|(track->a_channels<<3);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1925
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1926 if (strstr(track->codec_id, "SBR") != NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1927 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1928 /* HE-AAC (aka SBR AAC) */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1929 sh_a->codecdata_len = 5;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1930
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1931 sh_a->samplerate *= 2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1932 sh_a->wf->nSamplesPerSec *= 2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1933 srate_idx = aac_get_sample_rate_index(sh_a->samplerate);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1934 sh_a->codecdata[2] = AAC_SYNC_EXTENSION_TYPE >> 3;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1935 sh_a->codecdata[3] = ((AAC_SYNC_EXTENSION_TYPE&0x07)<<5) | 5;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1936 sh_a->codecdata[4] = (1 << 7) | (srate_idx << 3);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1937 track->default_duration = 1024.0 / (sh_a->samplerate / 2);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1938 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1939 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1940 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1941 sh_a->codecdata_len = 2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1942 track->default_duration = 1024.0 / (float)sh_a->samplerate;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1943 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1944 }
14843
bbb693d3b130 Fix the ogg fourcc nightmare!!!
rfelker
parents: 14561
diff changeset
1945 else if (track->a_formattag == mmioFOURCC('v', 'r', 'b', 's')) /* VORBIS */
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1946 {
15420
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 15285
diff changeset
1947 sh_a->wf->cbSize = track->private_size;
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 15285
diff changeset
1948 sh_a->wf = (WAVEFORMATEX*)realloc(sh_a->wf, sizeof(WAVEFORMATEX) + sh_a->wf->cbSize);
f3cf481bbcda vorbis extradata is now passed from demuxer to decoder in matroska's way
nicodvb
parents: 15285
diff changeset
1949 memcpy((unsigned char *) (sh_a->wf+1), track->private_data, sh_a->wf->cbSize);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1950 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1951 else if (track->private_size >= sizeof(real_audio_v4_props_t)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1952 && !strncmp (track->codec_id, MKV_A_REALATRC, 7))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1953 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1954 /* Common initialization for all RealAudio codecs */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1955 real_audio_v4_props_t *ra4p;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1956 real_audio_v5_props_t *ra5p;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1957 unsigned char *src;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1958 int codecdata_length, version;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1959
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1960 ra4p = (real_audio_v4_props_t *) track->private_data;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1961 ra5p = (real_audio_v5_props_t *) track->private_data;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1962
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1963 sh_a->wf->nAvgBytesPerSec = 0; /* FIXME !? */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1964 sh_a->wf->nBlockAlign = be2me_16 (ra4p->frame_size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1965
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1966 version = be2me_16 (ra4p->version1);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1967
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1968 if (version == 4)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1969 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1970 src = (unsigned char *) (ra4p + 1);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1971 src += src[0] + 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1972 src += src[0] + 1;
18036
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
1973 track->sub_packet_size = be2me_16 (ra4p->sub_packet_size);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
1974 track->sub_packet_h = be2me_16 (ra4p->sub_packet_h);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
1975 track->coded_framesize = be2me_32 (ra4p->coded_frame_size);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
1976 track->audiopk_size = be2me_16 (ra4p->frame_size);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1977 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1978 else
18036
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
1979 {
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1980 src = (unsigned char *) (ra5p + 1);
18036
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
1981 track->sub_packet_size = be2me_16 (ra5p->sub_packet_size);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
1982 track->sub_packet_h = be2me_16 (ra5p->sub_packet_h);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
1983 track->coded_framesize = be2me_32 (ra5p->coded_frame_size);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
1984 track->audiopk_size = be2me_16 (ra5p->frame_size);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
1985 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1986
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1987 src += 3;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1988 if (version == 5)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1989 src++;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1990 codecdata_length = be2me_32 (*(uint32_t *)src);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1991 src += 4;
18036
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
1992 sh_a->wf->cbSize = codecdata_length;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1993 sh_a->wf = (WAVEFORMATEX *) realloc (sh_a->wf,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1994 sizeof (WAVEFORMATEX) +
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1995 sh_a->wf->cbSize);
18036
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
1996 memcpy(((char *)(sh_a->wf + 1)), src, codecdata_length);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
1997
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
1998 switch (track->a_formattag) {
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
1999 case mmioFOURCC('a', 't', 'r', 'c'):
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2000 sh_a->wf->nAvgBytesPerSec = atrc_fl2bps[be2me_16 (ra4p->flavor)];
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2001 sh_a->wf->nBlockAlign = track->sub_packet_size;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2002 track->audio_buf = malloc(track->sub_packet_h * track->audiopk_size);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2003 track->audio_timestamp = malloc(track->sub_packet_h * sizeof(float));
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2004 break;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2005 case mmioFOURCC('c', 'o', 'o', 'k'):
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2006 sh_a->wf->nAvgBytesPerSec = cook_fl2bps[be2me_16 (ra4p->flavor)];
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2007 sh_a->wf->nBlockAlign = track->sub_packet_size;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2008 track->audio_buf = malloc(track->sub_packet_h * track->audiopk_size);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2009 track->audio_timestamp = malloc(track->sub_packet_h * sizeof(float));
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2010 break;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2011 case mmioFOURCC('s', 'i', 'p', 'r'):
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2012 sh_a->wf->nAvgBytesPerSec = sipr_fl2bps[be2me_16 (ra4p->flavor)];
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2013 sh_a->wf->nBlockAlign = track->coded_framesize;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2014 track->audio_buf = malloc(track->sub_packet_h * track->audiopk_size);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2015 track->audio_timestamp = malloc(track->sub_packet_h * sizeof(float));
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2016 break;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2017 case mmioFOURCC('2', '8', '_', '8'):
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2018 sh_a->wf->nAvgBytesPerSec = 3600;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2019 sh_a->wf->nBlockAlign = track->coded_framesize;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2020 track->audio_buf = malloc(track->sub_packet_h * track->audiopk_size);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2021 track->audio_timestamp = malloc(track->sub_packet_h * sizeof(float));
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2022 break;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2023 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2024
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2025 track->realmedia = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2026 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2027 else if (!strcmp(track->codec_id, MKV_A_FLAC) ||
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2028 (track->a_formattag == 0xf1ac))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2029 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2030 unsigned char *ptr;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2031 int size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2032 free(sh_a->wf);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2033 sh_a->wf = NULL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2034
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2035 if (track->a_formattag == mmioFOURCC('f', 'L', 'a', 'C'))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2036 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2037 ptr = (unsigned char *)track->private_data;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2038 size = track->private_size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2039 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2040 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2041 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2042 sh_a->format = mmioFOURCC('f', 'L', 'a', 'C');
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2043 ptr = (unsigned char *) track->private_data
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2044 + sizeof (WAVEFORMATEX);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2045 size = track->private_size - sizeof (WAVEFORMATEX);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2046 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2047 if (size < 4 || ptr[0] != 'f' || ptr[1] != 'L' ||
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2048 ptr[2] != 'a' || ptr[3] != 'C')
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2049 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2050 dp = new_demux_packet (4);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2051 memcpy (dp->buffer, "fLaC", 4);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2052 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2053 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2054 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2055 dp = new_demux_packet (size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2056 memcpy (dp->buffer, ptr, size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2057 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2058 dp->pts = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2059 dp->flags = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2060 ds_add_packet (demuxer->audio, dp);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2061 }
12101
d6ac3181fdca Fixed the support for the A_MS/ACM CodecID which just stores a WAVEFORMATEX in the track's private data.
mosu
parents: 12073
diff changeset
2062 else if (!track->ms_compat || (track->private_size < sizeof(WAVEFORMATEX)))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2063 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2064 free_sh_audio (sh_a);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2065 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2066 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2067
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2068 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2069 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2070
13126
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2071 /** \brief Parse the private data for VobSub subtitle tracks.
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2072
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2073 This function tries to parse the private data for all VobSub tracks.
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2074 The private data contains the normal text from the original .idx file.
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2075 Things like the palette, subtitle dimensions and custom colors are
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2076 stored here.
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2077
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2078 \param demuxer The generic demuxer.
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2079 */
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2080 static void
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2081 demux_mkv_parse_vobsub_data (demuxer_t *demuxer)
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2082 {
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2083 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2084 mkv_track_t *track;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2085 int i, m, size;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2086 uint8_t *buffer;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2087
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2088 for (i = 0; i < mkv_d->num_tracks; i++)
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2089 {
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2090 track = mkv_d->tracks[i];
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2091 if ((track->type != MATROSKA_TRACK_SUBTITLE) ||
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2092 (track->subtitle_type != MATROSKA_SUBTYPE_VOBSUB))
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2093 continue;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2094
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2095 size = track->private_size;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2096 m = demux_mkv_decode (track,track->private_data,&buffer,&size,2);
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2097 if (buffer && m)
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2098 {
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2099 free (track->private_data);
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2100 track->private_data = buffer;
18507
aca735a7f219 fix parsing of vobsub private data, patch by Evgeniy Stepanov <eugeni P stepanov A gmail P com>
gpoirier
parents: 18404
diff changeset
2101 track->private_size = size;
13126
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2102 }
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2103 if (!demux_mkv_parse_idx (track))
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2104 {
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2105 free (track->private_data);
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2106 track->private_data = NULL;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2107 track->private_size = 0;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2108 }
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2109 }
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2110 }
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2111
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2112 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2113 demux_mkv_open_sub (demuxer_t *demuxer, mkv_track_t *track)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2114 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2115 if (track->subtitle_type != MATROSKA_SUBTYPE_UNKNOWN)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2116 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2117 if (track->subtitle_type == MATROSKA_SUBTYPE_VOBSUB)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2118 {
13126
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2119 if (track->private_data != NULL)
12547
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
2120 {
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
2121 demuxer->sub->sh = malloc(sizeof(mkv_sh_sub_t));
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
2122 if (demuxer->sub->sh != NULL)
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
2123 memcpy(demuxer->sub->sh, &track->sh_sub, sizeof(mkv_sh_sub_t));
a60ba1b93e25 Try to get the "size:" and "palette:" entries for VobSub tracks from the private data.
mosu
parents: 12443
diff changeset
2124 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2125 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2126 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2127 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2128 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2129 mp_msg (MSGT_DEMUX, MSGL_ERR, "[mkv] Subtitle type '%s' is not "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2130 "supported.\n", track->codec_id);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2131 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2132 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2133
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2134 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2135 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2136
17695
3f20b096782d Add audio_delay argument to demux_mkv_seek.
corey
parents: 17308
diff changeset
2137 static void demux_mkv_seek (demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2138
15285
39eb8a327ea9 adds a parameter to the switch_audio command to directly select a track.
reimar
parents: 15154
diff changeset
2139 /** \brief Given a matroska track number and type, find the id that mplayer would ask for.
13501
a5004eb92a79 fix sub_select fiasco with global sub numbering. now multiple sub sources can be managed in essentially one list.
joey
parents: 13424
diff changeset
2140 * \param d The demuxer for which the subtitle id should be returned.
a5004eb92a79 fix sub_select fiasco with global sub numbering. now multiple sub sources can be managed in essentially one list.
joey
parents: 13424
diff changeset
2141 * \param num The matroska track number we are looking up.
15285
39eb8a327ea9 adds a parameter to the switch_audio command to directly select a track.
reimar
parents: 15154
diff changeset
2142 * \param type The track type.
13501
a5004eb92a79 fix sub_select fiasco with global sub numbering. now multiple sub sources can be managed in essentially one list.
joey
parents: 13424
diff changeset
2143 */
15285
39eb8a327ea9 adds a parameter to the switch_audio command to directly select a track.
reimar
parents: 15154
diff changeset
2144 static int demux_mkv_reverse_id(mkv_demuxer_t *d, int num, int type)
13501
a5004eb92a79 fix sub_select fiasco with global sub numbering. now multiple sub sources can be managed in essentially one list.
joey
parents: 13424
diff changeset
2145 {
a5004eb92a79 fix sub_select fiasco with global sub numbering. now multiple sub sources can be managed in essentially one list.
joey
parents: 13424
diff changeset
2146 int i, id;
a5004eb92a79 fix sub_select fiasco with global sub numbering. now multiple sub sources can be managed in essentially one list.
joey
parents: 13424
diff changeset
2147
a5004eb92a79 fix sub_select fiasco with global sub numbering. now multiple sub sources can be managed in essentially one list.
joey
parents: 13424
diff changeset
2148 for (i=0, id=0; i < d->num_tracks; i++)
15285
39eb8a327ea9 adds a parameter to the switch_audio command to directly select a track.
reimar
parents: 15154
diff changeset
2149 if (d->tracks[i] != NULL && d->tracks[i]->type == type) {
13501
a5004eb92a79 fix sub_select fiasco with global sub numbering. now multiple sub sources can be managed in essentially one list.
joey
parents: 13424
diff changeset
2150 if (d->tracks[i]->tnum == num)
a5004eb92a79 fix sub_select fiasco with global sub numbering. now multiple sub sources can be managed in essentially one list.
joey
parents: 13424
diff changeset
2151 return id;
a5004eb92a79 fix sub_select fiasco with global sub numbering. now multiple sub sources can be managed in essentially one list.
joey
parents: 13424
diff changeset
2152 id++;
a5004eb92a79 fix sub_select fiasco with global sub numbering. now multiple sub sources can be managed in essentially one list.
joey
parents: 13424
diff changeset
2153 }
a5004eb92a79 fix sub_select fiasco with global sub numbering. now multiple sub sources can be managed in essentially one list.
joey
parents: 13424
diff changeset
2154
a5004eb92a79 fix sub_select fiasco with global sub numbering. now multiple sub sources can be managed in essentially one list.
joey
parents: 13424
diff changeset
2155 return -1;
a5004eb92a79 fix sub_select fiasco with global sub numbering. now multiple sub sources can be managed in essentially one list.
joey
parents: 13424
diff changeset
2156 }
a5004eb92a79 fix sub_select fiasco with global sub numbering. now multiple sub sources can be managed in essentially one list.
joey
parents: 13424
diff changeset
2157
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
2158 static int
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2159 demux_mkv_open (demuxer_t *demuxer)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2160 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2161 stream_t *s = demuxer->stream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2162 mkv_demuxer_t *mkv_d;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2163 mkv_track_t *track;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2164 int i, version, cont = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2165 char *str;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2166
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2167 #ifdef USE_ICONV
12909
dc8eba991005 fixes a crash and unchecked string-handling in ENCA code.
reimar
parents: 12721
diff changeset
2168 subcp_open(NULL);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2169 #endif
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2170
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2171 stream_seek(s, s->start_pos);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2172 str = ebml_read_header (s, &version);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2173 if (str == NULL || strcmp (str, "matroska") || version > 1)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2174 {
11856
rfelker
parents: 11832
diff changeset
2175 mp_msg (MSGT_DEMUX, MSGL_DBG2, "[mkv] no head found\n");
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2176 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2177 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2178 free (str);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2179
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2180 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] Found the head...\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2181
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2182 if (ebml_read_id (s, NULL) != MATROSKA_ID_SEGMENT)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2183 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2184 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] but no segment :(\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2185 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2186 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2187 ebml_read_length (s, NULL); /* return bytes number until EOF */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2188
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2189 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] + a segment...\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2190
14046
4802041ab8e3 Output more information about vids, aids, sids, alangs and slangs with -identify. Patch by kiriuja <mplayer-patches@en-directo.net>
mosu
parents: 13804
diff changeset
2191 demux_aid_vid_mismatch = 1; // don't identify in new_sh_* since ids don't match
4802041ab8e3 Output more information about vids, aids, sids, alangs and slangs with -identify. Patch by kiriuja <mplayer-patches@en-directo.net>
mosu
parents: 13804
diff changeset
2192
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2193 mkv_d = (mkv_demuxer_t *) malloc (sizeof (mkv_demuxer_t));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2194 memset (mkv_d, 0, sizeof(mkv_demuxer_t));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2195 demuxer->priv = mkv_d;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2196 mkv_d->tc_scale = 1000000;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2197 mkv_d->segment_start = stream_tell (s);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2198 mkv_d->parsed_cues = (off_t *) malloc (sizeof (off_t));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2199 mkv_d->parsed_seekhead = (off_t *) malloc (sizeof (off_t));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2200
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2201 for (i=0; i < SUB_MAX_TEXT; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2202 mkv_d->subs.text[i] = (char *) malloc (256);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2203
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2204 while (!cont)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2205 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2206 switch (ebml_read_id (s, NULL))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2207 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2208 case MATROSKA_ID_INFO:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2209 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] |+ segment information...\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2210 cont = demux_mkv_read_info (demuxer);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2211 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2212
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2213 case MATROSKA_ID_TRACKS:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2214 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] |+ segment tracks...\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2215 cont = demux_mkv_read_tracks (demuxer);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2216 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2217
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2218 case MATROSKA_ID_CUES:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2219 cont = demux_mkv_read_cues (demuxer);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2220 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2221
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2222 case MATROSKA_ID_TAGS:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2223 cont = demux_mkv_read_tags (demuxer);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2224 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2225
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2226 case MATROSKA_ID_SEEKHEAD:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2227 cont = demux_mkv_read_seekhead (demuxer);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2228 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2229
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2230 case MATROSKA_ID_CHAPTERS:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2231 cont = demux_mkv_read_chapters (demuxer);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2232 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2233
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2234 case MATROSKA_ID_CLUSTER:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2235 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2236 int p, l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2237 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] |+ found cluster, headers are "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2238 "parsed completely :)\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2239 /* get the first cluster timecode */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2240 p = stream_tell(s);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2241 l = ebml_read_length (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2242 while (ebml_read_id (s, NULL) != MATROSKA_ID_CLUSTERTIMECODE)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2243 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2244 ebml_read_skip (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2245 if (stream_tell (s) >= p + l)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2246 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2247 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2248 if (stream_tell (s) < p + l)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2249 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2250 uint64_t num = ebml_read_uint (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2251 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2252 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2253 mkv_d->first_tc = num * mkv_d->tc_scale / 1000000.0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2254 mkv_d->has_first_tc = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2255 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2256 stream_seek (s, p - 4);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2257 cont = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2258 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2259 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2260
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2261 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2262 cont = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2263 case MATROSKA_ID_ATTACHMENTS:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2264 case EBML_ID_VOID:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2265 ebml_read_skip (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2266 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2267 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2268 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2269
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2270 display_tracks (mkv_d);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2271
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2272 /* select video track */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2273 track = NULL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2274 if (demuxer->video->id == -1) /* automatically select a video track */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2275 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2276 /* search for a video track that has the 'default' flag set */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2277 for (i=0; i<mkv_d->num_tracks; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2278 if (mkv_d->tracks[i]->type == MATROSKA_TRACK_VIDEO
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2279 && mkv_d->tracks[i]->default_track)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2280 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2281 track = mkv_d->tracks[i];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2282 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2283 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2284
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2285 if (track == NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2286 /* no track has the 'default' flag set */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2287 /* let's take the first video track */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2288 for (i=0; i<mkv_d->num_tracks; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2289 if (mkv_d->tracks[i]->type == MATROSKA_TRACK_VIDEO)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2290 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2291 track = mkv_d->tracks[i];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2292 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2293 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2294 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2295 else if (demuxer->video->id != -2) /* -2 = no video at all */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2296 track = demux_mkv_find_track_by_num (mkv_d, demuxer->video->id,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2297 MATROSKA_TRACK_VIDEO);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2298
11901
01bfcbd73986 Do not open more than one audio/video/subtitle stream at the same time.
mosu
parents: 11899
diff changeset
2299 if (track && !demux_mkv_open_video (demuxer, track))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2300 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2301 mp_msg (MSGT_DEMUX, MSGL_INFO,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2302 "[mkv] Will play video track %u\n", track->tnum);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2303 demuxer->video->id = track->tnum;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2304 demuxer->video->sh = demuxer->v_streams[track->tnum];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2305 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2306 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2307 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2308 mp_msg (MSGT_DEMUX, MSGL_INFO, "[mkv] No video track found/wanted.\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2309 demuxer->video->id = -2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2310 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2311
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2312 /* select audio track */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2313 track = NULL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2314 if (demuxer->audio->id == -1) /* automatically select an audio track */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2315 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2316 /* check if the user specified an audio language */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2317 if (audio_lang != NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2318 track = demux_mkv_find_track_by_language(mkv_d, audio_lang,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2319 MATROSKA_TRACK_AUDIO);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2320 if (track == NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2321 /* no audio language specified, or language not found */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2322 /* search for an audio track that has the 'default' flag set */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2323 for (i=0; i < mkv_d->num_tracks; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2324 if (mkv_d->tracks[i]->type == MATROSKA_TRACK_AUDIO
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2325 && mkv_d->tracks[i]->default_track)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2326 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2327 track = mkv_d->tracks[i];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2328 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2329 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2330
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2331 if (track == NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2332 /* no track has the 'default' flag set */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2333 /* let's take the first audio track */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2334 for (i=0; i < mkv_d->num_tracks; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2335 if (mkv_d->tracks[i]->type == MATROSKA_TRACK_AUDIO)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2336 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2337 track = mkv_d->tracks[i];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2338 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2339 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2340 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2341 else if (demuxer->audio->id != -2) /* -2 = no audio at all */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2342 track = demux_mkv_find_track_by_num (mkv_d, demuxer->audio->id,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2343 MATROSKA_TRACK_AUDIO);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2344
11901
01bfcbd73986 Do not open more than one audio/video/subtitle stream at the same time.
mosu
parents: 11899
diff changeset
2345 if (track && !demux_mkv_open_audio (demuxer, track))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2346 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2347 mp_msg (MSGT_DEMUX, MSGL_INFO,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2348 "[mkv] Will play audio track %u\n", track->tnum);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2349 demuxer->audio->id = track->tnum;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2350 demuxer->audio->sh = demuxer->a_streams[track->tnum];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2351 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2352 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2353 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2354 mp_msg (MSGT_DEMUX, MSGL_INFO, "[mkv] No audio track found/wanted.\n");
11832
b9b330154ae1 Do not deactivate the video stream if no audio stream was wanted/found...
mosu
parents: 11815
diff changeset
2355 demuxer->audio->id = -2;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2356 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2357
13126
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
2358 demux_mkv_parse_vobsub_data (demuxer);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2359 /* DO NOT automatically select a subtitle track and behave like DVD */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2360 /* playback: only show subtitles if the user explicitely wants them. */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2361 track = NULL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2362 if (demuxer->sub->id >= 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2363 track = demux_mkv_find_track_by_num (mkv_d, demuxer->sub->id,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2364 MATROSKA_TRACK_SUBTITLE);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2365 else if (dvdsub_lang != NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2366 track = demux_mkv_find_track_by_language (mkv_d, dvdsub_lang,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2367 MATROSKA_TRACK_SUBTITLE);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2368
11901
01bfcbd73986 Do not open more than one audio/video/subtitle stream at the same time.
mosu
parents: 11899
diff changeset
2369 if (track && !demux_mkv_open_sub (demuxer, track))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2370 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2371 mp_msg (MSGT_DEMUX, MSGL_INFO,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2372 "[mkv] Will display subtitle track %u\n", track->tnum);
15285
39eb8a327ea9 adds a parameter to the switch_audio command to directly select a track.
reimar
parents: 15154
diff changeset
2373 dvdsub_id = demux_mkv_reverse_id(mkv_d, track->tnum, MATROSKA_TRACK_SUBTITLE);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2374 demuxer->sub->id = track->tnum;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2375 }
11901
01bfcbd73986 Do not open more than one audio/video/subtitle stream at the same time.
mosu
parents: 11899
diff changeset
2376 else
01bfcbd73986 Do not open more than one audio/video/subtitle stream at the same time.
mosu
parents: 11899
diff changeset
2377 demuxer->sub->id = -2;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2378
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2379 if (mkv_d->chapters)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2380 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2381 for (i=0; i < (int)mkv_d->num_chapters; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2382 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2383 mkv_d->chapters[i].start -= mkv_d->first_tc;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2384 mkv_d->chapters[i].end -= mkv_d->first_tc;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2385 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2386 if (dvd_last_chapter > 0 && dvd_last_chapter <= mkv_d->num_chapters)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2387 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2388 if (mkv_d->chapters[dvd_last_chapter-1].end != 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2389 mkv_d->stop_timecode = mkv_d->chapters[dvd_last_chapter-1].end;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2390 else if (dvd_last_chapter + 1 <= mkv_d->num_chapters)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2391 mkv_d->stop_timecode = mkv_d->chapters[dvd_last_chapter].start;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2392 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2393 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2394
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2395 if (s->end_pos == 0 || (mkv_d->indexes == NULL && index_mode < 0))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2396 demuxer->seekable = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2397 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2398 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2399 demuxer->movi_start = s->start_pos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2400 demuxer->movi_end = s->end_pos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2401 demuxer->seekable = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2402 if (mkv_d->chapters && dvd_chapter>1 && dvd_chapter<=mkv_d->num_chapters)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2403 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2404 if (!mkv_d->has_first_tc)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2405 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2406 mkv_d->first_tc = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2407 mkv_d->has_first_tc = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2408 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2409 demux_mkv_seek (demuxer,
17695
3f20b096782d Add audio_delay argument to demux_mkv_seek.
corey
parents: 17308
diff changeset
2410 mkv_d->chapters[dvd_chapter-1].start/1000.0, 0.0, 1);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2411 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2412 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2413
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
2414 return DEMUXER_TYPE_MATROSKA;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2415 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2416
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
2417 static void
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2418 demux_close_mkv (demuxer_t *demuxer)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2419 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2420 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2421
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2422 if (mkv_d)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2423 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2424 int i;
14461
1363bbf9d5cc Call subcp_close when closing the demuxer
reimar
parents: 14458
diff changeset
2425 #ifdef USE_ICONV
1363bbf9d5cc Call subcp_close when closing the demuxer
reimar
parents: 14458
diff changeset
2426 subcp_close();
1363bbf9d5cc Call subcp_close when closing the demuxer
reimar
parents: 14458
diff changeset
2427 #endif
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2428 free_cached_dps (demuxer);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2429 if (mkv_d->tracks)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2430 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2431 for (i=0; i<mkv_d->num_tracks; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2432 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2433 if (mkv_d->tracks[i]->codec_id)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2434 free (mkv_d->tracks[i]->codec_id);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2435 if (mkv_d->tracks[i]->language)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2436 free (mkv_d->tracks[i]->language);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2437 if (mkv_d->tracks[i]->private_data)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2438 free (mkv_d->tracks[i]->private_data);
18036
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2439 if (mkv_d->tracks[i]->audio_buf)
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2440 free (mkv_d->tracks[i]->audio_buf);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2441 if (mkv_d->tracks[i]->audio_timestamp)
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2442 free (mkv_d->tracks[i]->audio_timestamp);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2443 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2444 for (i=0; i < SUB_MAX_TEXT; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2445 if (mkv_d->subs.text[i])
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2446 free (mkv_d->subs.text[i]);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2447 free (mkv_d->tracks);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2448 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2449 if (mkv_d->indexes)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2450 free (mkv_d->indexes);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2451 if (mkv_d->cluster_positions)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2452 free (mkv_d->cluster_positions);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2453 if (mkv_d->chapters)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2454 free (mkv_d->chapters);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2455 if (mkv_d->parsed_cues)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2456 free (mkv_d->parsed_cues);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2457 if (mkv_d->parsed_seekhead)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2458 free (mkv_d->parsed_seekhead);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2459 free (mkv_d);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2460 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2461 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2462
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2463 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2464 demux_mkv_read_block_lacing (uint8_t *buffer, uint64_t *size,
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2465 uint8_t *laces, uint32_t **all_lace_sizes)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2466 {
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2467 uint32_t total = 0, *lace_size;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2468 uint8_t flags;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2469 int i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2470
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2471 *all_lace_sizes = NULL;
13131
ab937f4a17ad Cosmetics: fix some compiler warnings.
mosu
parents: 13129
diff changeset
2472 lace_size = NULL;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2473 /* lacing flags */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2474 flags = *buffer++;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2475 (*size)--;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2476
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2477 switch ((flags & 0x06) >> 1)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2478 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2479 case 0: /* no lacing */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2480 *laces = 1;
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2481 lace_size = (uint32_t *)calloc(*laces, sizeof(uint32_t));
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2482 lace_size[0] = *size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2483 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2484
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2485 case 1: /* xiph lacing */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2486 case 2: /* fixed-size lacing */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2487 case 3: /* EBML lacing */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2488 *laces = *buffer++;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2489 (*size)--;
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2490 (*laces)++;
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2491 lace_size = (uint32_t *)calloc(*laces, sizeof(uint32_t));
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2492
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2493 switch ((flags & 0x06) >> 1)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2494 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2495 case 1: /* xiph lacing */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2496 for (i=0; i < *laces-1; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2497 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2498 lace_size[i] = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2499 do
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2500 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2501 lace_size[i] += *buffer;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2502 (*size)--;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2503 } while (*buffer++ == 0xFF);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2504 total += lace_size[i];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2505 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2506 lace_size[i] = *size - total;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2507 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2508
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2509 case 2: /* fixed-size lacing */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2510 for (i=0; i < *laces; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2511 lace_size[i] = *size / *laces;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2512 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2513
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2514 case 3: /* EBML lacing */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2515 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2516 int l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2517 uint64_t num = ebml_read_vlen_uint (buffer, &l);
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2518 if (num == EBML_UINT_INVALID) {
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2519 free(lace_size);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2520 return 1;
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2521 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2522 buffer += l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2523 *size -= l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2524
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2525 total = lace_size[0] = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2526 for (i=1; i < *laces-1; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2527 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2528 int64_t snum;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2529 snum = ebml_read_vlen_int (buffer, &l);
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2530 if (snum == EBML_INT_INVALID) {
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2531 free(lace_size);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2532 return 1;
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2533 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2534 buffer += l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2535 *size -= l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2536 lace_size[i] = lace_size[i-1] + snum;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2537 total += lace_size[i];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2538 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2539 lace_size[i] = *size - total;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2540 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2541 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2542 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2543 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2544 }
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2545 *all_lace_sizes = lace_size;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2546 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2547 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2548
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2549 static void
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2550 handle_subtitles(demuxer_t *demuxer, mkv_track_t *track, char *block,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2551 int64_t size, uint64_t block_duration, uint64_t timecode)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2552 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2553 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2554 char *ptr1, *ptr2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2555 int state, i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2556
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2557 if (block_duration == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2558 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2559 mp_msg (MSGT_DEMUX, MSGL_WARN, "[mkv] Warning: No BlockDuration "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2560 "for subtitle track found.\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2561 return;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2562 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2563
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2564 ptr1 = block;
11812
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2565 while (ptr1 - block <= size && (*ptr1 == '\n' || *ptr1 == '\r'))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2566 ptr1++;
11812
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2567 ptr2 = block + size - 1;
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2568 while (ptr2 >= block && (*ptr2 == '\n' || *ptr2 == '\r'))
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2569 {
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2570 *ptr2 = 0;
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2571 ptr2--;
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2572 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2573
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2574 if (mkv_d->subs.lines > SUB_MAX_TEXT - 2)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2575 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2576 mp_msg (MSGT_DEMUX, MSGL_WARN, "[mkv] Warning: too many sublines "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2577 "to render, skipping\n");
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2578 return;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2579 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2580 ptr2 = mkv_d->subs.text[mkv_d->subs.lines];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2581 state = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2582
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2583 if (track->subtitle_type == MATROSKA_SUBTYPE_SSA)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2584 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2585 /* Find text section. */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2586 for (i=0; i < 8 && *ptr1 != '\0'; ptr1++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2587 if (*ptr1 == ',')
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2588 i++;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2589 if (*ptr1 == '\0') /* Broken line? */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2590 return;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2591
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2592 /* Load text. */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2593 while (ptr1 - block < size)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2594 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2595 if (*ptr1 == '{')
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2596 state = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2597 else if (*ptr1 == '}' && state == 1)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2598 state = 2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2599
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2600 if (state == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2601 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2602 *ptr2++ = *ptr1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2603 if (ptr2 - mkv_d->subs.text[mkv_d->subs.lines] >= 255)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2604 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2605 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2606 ptr1++;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2607
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2608 /* Newline */
17308
59452efe579c Improved handling of text subs in Matroska files with adjacent newlines (\N) resulting in more than SUB_MAX_TEXT lines to display. Patch by Robert Henney (robh () rut ! org).
mosu
parents: 17012
diff changeset
2609 while (*ptr1 == '\\' && ptr1+1-block < size && (*(ptr1+1)|0x20) == 'n')
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2610 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2611 mkv_d->clear_subs_at[mkv_d->subs.lines++]
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2612 = timecode + block_duration;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2613 *ptr2 = '\0';
11808
c4bd86214a20 Fixed the subtitle line overflowing for SSA if there were too many \N in the subs.
mosu
parents: 11807
diff changeset
2614 if (mkv_d->subs.lines >= SUB_MAX_TEXT)
c4bd86214a20 Fixed the subtitle line overflowing for SSA if there were too many \N in the subs.
mosu
parents: 11807
diff changeset
2615 {
17308
59452efe579c Improved handling of text subs in Matroska files with adjacent newlines (\N) resulting in more than SUB_MAX_TEXT lines to display. Patch by Robert Henney (robh () rut ! org).
mosu
parents: 17012
diff changeset
2616 mp_msg (MSGT_DEMUX, MSGL_WARN, "\n[mkv] Warning: too many "
59452efe579c Improved handling of text subs in Matroska files with adjacent newlines (\N) resulting in more than SUB_MAX_TEXT lines to display. Patch by Robert Henney (robh () rut ! org).
mosu
parents: 17012
diff changeset
2617 "sublines to render, skipping after first %i\n",
59452efe579c Improved handling of text subs in Matroska files with adjacent newlines (\N) resulting in more than SUB_MAX_TEXT lines to display. Patch by Robert Henney (robh () rut ! org).
mosu
parents: 17012
diff changeset
2618 SUB_MAX_TEXT);
59452efe579c Improved handling of text subs in Matroska files with adjacent newlines (\N) resulting in more than SUB_MAX_TEXT lines to display. Patch by Robert Henney (robh () rut ! org).
mosu
parents: 17012
diff changeset
2619 mkv_d->subs.lines--;
59452efe579c Improved handling of text subs in Matroska files with adjacent newlines (\N) resulting in more than SUB_MAX_TEXT lines to display. Patch by Robert Henney (robh () rut ! org).
mosu
parents: 17012
diff changeset
2620 ptr1=block+size;
59452efe579c Improved handling of text subs in Matroska files with adjacent newlines (\N) resulting in more than SUB_MAX_TEXT lines to display. Patch by Robert Henney (robh () rut ! org).
mosu
parents: 17012
diff changeset
2621 break;
11808
c4bd86214a20 Fixed the subtitle line overflowing for SSA if there were too many \N in the subs.
mosu
parents: 11807
diff changeset
2622 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2623 ptr2 = mkv_d->subs.text[mkv_d->subs.lines];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2624 ptr1 += 2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2625 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2626
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2627 if (state == 2)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2628 state = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2629 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2630 *ptr2 = '\0';
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2631 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2632 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2633 {
17308
59452efe579c Improved handling of text subs in Matroska files with adjacent newlines (\N) resulting in more than SUB_MAX_TEXT lines to display. Patch by Robert Henney (robh () rut ! org).
mosu
parents: 17012
diff changeset
2634 while (ptr1 - block < size)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2635 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2636 if (*ptr1 == '\n' || *ptr1 == '\r')
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2637 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2638 if (state == 0) /* normal char --> newline */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2639 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2640 *ptr2 = '\0';
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2641 mkv_d->clear_subs_at[mkv_d->subs.lines++]
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2642 = timecode + block_duration;
11808
c4bd86214a20 Fixed the subtitle line overflowing for SSA if there were too many \N in the subs.
mosu
parents: 11807
diff changeset
2643 if (mkv_d->subs.lines >= SUB_MAX_TEXT)
c4bd86214a20 Fixed the subtitle line overflowing for SSA if there were too many \N in the subs.
mosu
parents: 11807
diff changeset
2644 {
17308
59452efe579c Improved handling of text subs in Matroska files with adjacent newlines (\N) resulting in more than SUB_MAX_TEXT lines to display. Patch by Robert Henney (robh () rut ! org).
mosu
parents: 17012
diff changeset
2645 mp_msg (MSGT_DEMUX, MSGL_WARN, "\n[mkv] Warning: too many "
59452efe579c Improved handling of text subs in Matroska files with adjacent newlines (\N) resulting in more than SUB_MAX_TEXT lines to display. Patch by Robert Henney (robh () rut ! org).
mosu
parents: 17012
diff changeset
2646 "sublines to render, skipping after first %i\n",
59452efe579c Improved handling of text subs in Matroska files with adjacent newlines (\N) resulting in more than SUB_MAX_TEXT lines to display. Patch by Robert Henney (robh () rut ! org).
mosu
parents: 17012
diff changeset
2647 SUB_MAX_TEXT);
59452efe579c Improved handling of text subs in Matroska files with adjacent newlines (\N) resulting in more than SUB_MAX_TEXT lines to display. Patch by Robert Henney (robh () rut ! org).
mosu
parents: 17012
diff changeset
2648 mkv_d->subs.lines--;
59452efe579c Improved handling of text subs in Matroska files with adjacent newlines (\N) resulting in more than SUB_MAX_TEXT lines to display. Patch by Robert Henney (robh () rut ! org).
mosu
parents: 17012
diff changeset
2649 ptr1=block+size;
59452efe579c Improved handling of text subs in Matroska files with adjacent newlines (\N) resulting in more than SUB_MAX_TEXT lines to display. Patch by Robert Henney (robh () rut ! org).
mosu
parents: 17012
diff changeset
2650 break;
11808
c4bd86214a20 Fixed the subtitle line overflowing for SSA if there were too many \N in the subs.
mosu
parents: 11807
diff changeset
2651 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2652 ptr2 = mkv_d->subs.text[mkv_d->subs.lines];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2653 state = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2654 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2655 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2656 else if (*ptr1 == '<') /* skip HTML tags */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2657 state = 2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2658 else if (*ptr1 == '>')
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2659 state = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2660 else if (state != 2) /* normal character */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2661 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2662 state = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2663 if ((ptr2 - mkv_d->subs.text[mkv_d->subs.lines]) < 255)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2664 *ptr2++ = *ptr1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2665 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2666 ptr1++;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2667 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2668 *ptr2 = '\0';
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2669 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2670 mkv_d->clear_subs_at[mkv_d->subs.lines++] = timecode + block_duration;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2671
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2672 #ifdef USE_ICONV
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2673 subcp_recode1 (&mkv_d->subs);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2674 #endif
14513
b712f8437a08 set sub_utf8 only when actually using mkv subtitles, will break external
reimar
parents: 14502
diff changeset
2675 sub_utf8 = 1;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2676 vo_sub = &mkv_d->subs;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2677 vo_osd_changed (OSDTYPE_SUBTITLE);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2678 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2679
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2680 static void
11812
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2681 clear_subtitles(demuxer_t *demuxer, uint64_t timecode, int clear_all)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2682 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2683 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2684 int i, lines_cut = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2685 char *tmp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2686
11812
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2687 /* Clear all? */
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2688 if (clear_all)
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2689 {
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2690 lines_cut = mkv_d->subs.lines;
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2691 mkv_d->subs.lines = 0;
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2692 if (lines_cut)
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2693 {
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2694 vo_sub = &mkv_d->subs;
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2695 vo_osd_changed (OSDTYPE_SUBTITLE);
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2696 }
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2697 return;
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2698 }
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2699
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2700 /* Clear the subtitles if they're obsolete now. */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2701 for (i=0; i < mkv_d->subs.lines; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2702 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2703 if (mkv_d->clear_subs_at[i] <= timecode)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2704 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2705 tmp = mkv_d->subs.text[i];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2706 memmove (mkv_d->subs.text+i, mkv_d->subs.text+i+1,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2707 (mkv_d->subs.lines-i-1) * sizeof (*mkv_d->subs.text));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2708 memmove (mkv_d->clear_subs_at+i, mkv_d->clear_subs_at+i+1,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2709 (mkv_d->subs.lines-i-1) * sizeof (*mkv_d->clear_subs_at));
11812
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
2710 mkv_d->subs.text[--mkv_d->subs.lines] = tmp;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2711 i--;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2712 lines_cut = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2713 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2714 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2715 if (lines_cut)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2716 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2717 vo_sub = &mkv_d->subs;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2718 vo_osd_changed (OSDTYPE_SUBTITLE);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2719 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2720 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2721
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2722 // Taken from demux_real.c. Thanks to the original developpers :)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2723 #define SKIP_BITS(n) buffer <<= n
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2724 #define SHOW_BITS(n) ((buffer) >> (32 - (n)))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2725
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2726 static float real_fix_timestamp(mkv_track_t *track, unsigned char *s,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2727 int timestamp) {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2728 float v_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2729 uint32_t buffer = (s[0] << 24) + (s[1] << 16) + (s[2] << 8) + s[3];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2730 int kf = timestamp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2731 int pict_type;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2732 int orig_kf;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2733
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2734 if (!strcmp(track->codec_id, MKV_V_REALV30) ||
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2735 !strcmp(track->codec_id, MKV_V_REALV40)) {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2736
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2737 if (!strcmp(track->codec_id, MKV_V_REALV30)) {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2738 SKIP_BITS(3);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2739 pict_type = SHOW_BITS(2);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2740 SKIP_BITS(2 + 7);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2741 }else{
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2742 SKIP_BITS(1);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2743 pict_type = SHOW_BITS(2);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2744 SKIP_BITS(2 + 7 + 3);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2745 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2746 kf = SHOW_BITS(13); // kf= 2*SHOW_BITS(12);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2747 orig_kf = kf;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2748 if (pict_type <= 1) {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2749 // I frame, sync timestamps:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2750 track->rv_kf_base = timestamp - kf;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2751 mp_msg(MSGT_DEMUX, MSGL_V, "\nTS: base=%08X\n", track->rv_kf_base);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2752 kf = timestamp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2753 } else {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2754 // P/B frame, merge timestamps:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2755 int tmp = timestamp - track->rv_kf_base;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2756 kf |= tmp & (~0x1fff); // combine with packet timestamp
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2757 if (kf < (tmp - 4096)) // workaround wrap-around problems
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2758 kf += 8192;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2759 else if (kf > (tmp + 4096))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2760 kf -= 8192;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2761 kf += track->rv_kf_base;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2762 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2763 if (pict_type != 3) { // P || I frame -> swap timestamps
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2764 int tmp = kf;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2765 kf = track->rv_kf_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2766 track->rv_kf_pts = tmp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2767 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2768 mp_msg(MSGT_DEMUX, MSGL_V, "\nTS: %08X -> %08X (%04X) %d %02X %02X %02X "
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2769 "%02X %5d\n", timestamp, kf, orig_kf, pict_type, s[0], s[1], s[2],
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2770 s[3], kf - (int)(1000.0 * track->rv_pts));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2771 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2772 v_pts = kf * 0.001f;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2773 track->rv_pts = v_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2774
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2775 return v_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2776 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2777
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2778 static void
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2779 handle_realvideo (demuxer_t *demuxer, mkv_track_t *track, uint8_t *buffer,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2780 uint32_t size, int block_bref)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2781 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2782 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2783 demux_packet_t *dp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2784 dp_hdr_t *hdr;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2785 uint8_t chunks;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2786 int isize;
17923
ad7675dee42c Fix for playing RealVideo on PPC/big endian processors. Patch by Emanuele Giaquinta (emanuele ! giaquinta () gmail ! com).
mosu
parents: 17695
diff changeset
2787 #ifdef WORDS_BIGENDIAN
ad7675dee42c Fix for playing RealVideo on PPC/big endian processors. Patch by Emanuele Giaquinta (emanuele ! giaquinta () gmail ! com).
mosu
parents: 17695
diff changeset
2788 uint8_t *p;
ad7675dee42c Fix for playing RealVideo on PPC/big endian processors. Patch by Emanuele Giaquinta (emanuele ! giaquinta () gmail ! com).
mosu
parents: 17695
diff changeset
2789 int i;
ad7675dee42c Fix for playing RealVideo on PPC/big endian processors. Patch by Emanuele Giaquinta (emanuele ! giaquinta () gmail ! com).
mosu
parents: 17695
diff changeset
2790 #endif
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2791
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2792 chunks = *buffer++;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2793 isize = --size - (chunks+1)*8;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2794 dp = new_demux_packet (sizeof (*hdr) + size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2795 memcpy (dp->buffer + sizeof(*hdr), buffer + (chunks+1)*8, isize);
17923
ad7675dee42c Fix for playing RealVideo on PPC/big endian processors. Patch by Emanuele Giaquinta (emanuele ! giaquinta () gmail ! com).
mosu
parents: 17695
diff changeset
2796 #ifdef WORDS_BIGENDIAN
ad7675dee42c Fix for playing RealVideo on PPC/big endian processors. Patch by Emanuele Giaquinta (emanuele ! giaquinta () gmail ! com).
mosu
parents: 17695
diff changeset
2797 p = (uint8_t *)(dp->buffer + sizeof(*hdr) + isize);
ad7675dee42c Fix for playing RealVideo on PPC/big endian processors. Patch by Emanuele Giaquinta (emanuele ! giaquinta () gmail ! com).
mosu
parents: 17695
diff changeset
2798 for (i = 0; i<(chunks+1)*8; i+=4) {
ad7675dee42c Fix for playing RealVideo on PPC/big endian processors. Patch by Emanuele Giaquinta (emanuele ! giaquinta () gmail ! com).
mosu
parents: 17695
diff changeset
2799 p[i] = *((uint8_t *)buffer+i+3);
ad7675dee42c Fix for playing RealVideo on PPC/big endian processors. Patch by Emanuele Giaquinta (emanuele ! giaquinta () gmail ! com).
mosu
parents: 17695
diff changeset
2800 p[i+1] = *((uint8_t *)buffer+i+2);
ad7675dee42c Fix for playing RealVideo on PPC/big endian processors. Patch by Emanuele Giaquinta (emanuele ! giaquinta () gmail ! com).
mosu
parents: 17695
diff changeset
2801 p[i+2] = *((uint8_t *)buffer+i+1);
ad7675dee42c Fix for playing RealVideo on PPC/big endian processors. Patch by Emanuele Giaquinta (emanuele ! giaquinta () gmail ! com).
mosu
parents: 17695
diff changeset
2802 p[i+3] = *((uint8_t *)buffer+i);
ad7675dee42c Fix for playing RealVideo on PPC/big endian processors. Patch by Emanuele Giaquinta (emanuele ! giaquinta () gmail ! com).
mosu
parents: 17695
diff changeset
2803 }
ad7675dee42c Fix for playing RealVideo on PPC/big endian processors. Patch by Emanuele Giaquinta (emanuele ! giaquinta () gmail ! com).
mosu
parents: 17695
diff changeset
2804 #else
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2805 memcpy (dp->buffer + sizeof(*hdr) + isize, buffer, (chunks+1)*8);
17923
ad7675dee42c Fix for playing RealVideo on PPC/big endian processors. Patch by Emanuele Giaquinta (emanuele ! giaquinta () gmail ! com).
mosu
parents: 17695
diff changeset
2806 #endif
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2808 hdr = (dp_hdr_t *) dp->buffer;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2809 hdr->len = isize;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2810 hdr->chunks = chunks;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2811 hdr->timestamp = mkv_d->last_pts * 1000;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2812 hdr->chunktab = sizeof(*hdr) + isize;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2813
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2814 dp->len = sizeof(*hdr) + size;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2815 if (mkv_d->v_skip_to_keyframe)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2816 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2817 dp->pts = mkv_d->last_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2818 track->rv_kf_base = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2819 track->rv_kf_pts = hdr->timestamp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2820 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2821 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2822 dp->pts = real_fix_timestamp (track, dp->buffer + sizeof(*hdr),
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2823 hdr->timestamp);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2824 dp->pos = demuxer->filepos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2825 dp->flags = block_bref ? 0 : 0x10;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2826
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2827 ds_add_packet(demuxer->video, dp);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2828 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2829
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2830 static void
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2831 handle_realaudio (demuxer_t *demuxer, mkv_track_t *track, uint8_t *buffer,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2832 uint32_t size, int block_bref)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2833 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2834 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
18036
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2835 int sps = track->sub_packet_size;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2836 int sph = track->sub_packet_h;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2837 int cfs = track->coded_framesize;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2838 int w = track->audiopk_size;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2839 int spc = track->sub_packet_cnt;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2840 demux_packet_t *dp;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2841 int x;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2842
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2843 if ((track->a_formattag == mmioFOURCC('2', '8', '_', '8')) ||
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2844 (track->a_formattag == mmioFOURCC('c', 'o', 'o', 'k')) ||
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2845 (track->a_formattag == mmioFOURCC('a', 't', 'r', 'c')) ||
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2846 (track->a_formattag == mmioFOURCC('s', 'i', 'p', 'r')))
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2847 {
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2848 // if(!block_bref)
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2849 // spc = track->sub_packet_cnt = 0;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2850 switch (track->a_formattag) {
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2851 case mmioFOURCC('2', '8', '_', '8'):
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2852 for (x = 0; x < sph / 2; x++)
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2853 memcpy(track->audio_buf + x * 2 * w + spc * cfs, buffer + cfs * x, cfs);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2854 break;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2855 case mmioFOURCC('c', 'o', 'o', 'k'):
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2856 case mmioFOURCC('a', 't', 'r', 'c'):
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2857 for (x = 0; x < w / sps; x++)
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2858 memcpy(track->audio_buf + sps * (sph * x + ((sph + 1) / 2) * (spc & 1) + (spc >> 1)), buffer + sps * x, sps);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2859 break;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2860 case mmioFOURCC('s', 'i', 'p', 'r'):
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2861 memcpy(track->audio_buf + spc * w, buffer, w);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2862 if (spc == sph - 1)
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2863 {
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2864 int n;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2865 int bs = sph * w * 2 / 96; // nibbles per subpacket
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2866 // Perform reordering
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2867 for(n=0; n < 38; n++)
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2868 {
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2869 int j;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2870 int i = bs * sipr_swaps[n][0];
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2871 int o = bs * sipr_swaps[n][1];
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2872 // swap nibbles of block 'i' with 'o' TODO: optimize
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2873 for(j = 0;j < bs; j++)
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2874 {
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2875 int x = (i & 1) ? (track->audio_buf[i >> 1] >> 4) : (track->audio_buf[i >> 1] & 0x0F);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2876 int y = (o & 1) ? (track->audio_buf[o >> 1] >> 4) : (track->audio_buf[o >> 1] & 0x0F);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2877 if(o & 1)
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2878 track->audio_buf[o >> 1] = (track->audio_buf[o >> 1] & 0x0F) | (x << 4);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2879 else
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2880 track->audio_buf[o >> 1] = (track->audio_buf[o >> 1] & 0xF0) | x;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2881 if(i & 1)
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2882 track->audio_buf[i >> 1] = (track->audio_buf[i >> 1] & 0x0F) | (y << 4);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2883 else
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2884 track->audio_buf[i >> 1] = (track->audio_buf[i >> 1] & 0xF0) | y;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2885 ++i; ++o;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2886 }
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2887 }
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2888 }
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2889 break;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2890 }
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2891 track->audio_timestamp[track->sub_packet_cnt] = (track->ra_pts == mkv_d->last_pts) ? 0 : (mkv_d->last_pts);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2892 track->ra_pts = mkv_d->last_pts;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2893 if (track->sub_packet_cnt == 0)
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2894 track->audio_filepos = demuxer->filepos;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2895 if (++(track->sub_packet_cnt) == sph)
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2896 {
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2897 int apk_usize = ((WAVEFORMATEX*)((sh_audio_t*)demuxer->audio->sh)->wf)->nBlockAlign;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2898 track->sub_packet_cnt = 0;
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2899 // Release all the audio packets
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2900 for (x = 0; x < sph*w/apk_usize; x++)
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2901 {
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2902 dp = new_demux_packet(apk_usize);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2903 memcpy(dp->buffer, track->audio_buf + x * apk_usize, apk_usize);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2904 /* Put timestamp only on packets that correspond to original audio packets in file */
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2905 dp->pts = (x * apk_usize % w) ? 0 : track->audio_timestamp[x * apk_usize / w];
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2906 dp->pos = track->audio_filepos; // all equal
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2907 dp->flags = x ? 0 : 0x10; // Mark first packet as keyframe
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2908 ds_add_packet(demuxer->audio, dp);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2909 }
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2910 }
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2911 } else { // Not a codec that require reordering
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2912 dp = new_demux_packet (size);
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2913 memcpy(dp->buffer, buffer, size);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2914 if (track->ra_pts == mkv_d->last_pts && !mkv_d->a_skip_to_keyframe)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2915 dp->pts = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2916 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2917 dp->pts = mkv_d->last_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2918 track->ra_pts = mkv_d->last_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2919
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2920 dp->pos = demuxer->filepos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2921 dp->flags = block_bref ? 0 : 0x10;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2922 ds_add_packet (demuxer->audio, dp);
18036
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2923 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2924 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2925
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2926 /** Reorder timecodes and add cached demux packets to the queues.
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2927 *
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2928 * Timecode reordering is needed if a video track contains B frames that
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2929 * are timestamped in display order (e.g. MPEG-1, MPEG-2 or "native" MPEG-4).
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2930 * MPlayer doesn't like timestamps in display order. This function adjusts
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2931 * the timestamp of cached frames (which are exactly one I/P frame followed
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2932 * by one or more B frames) so that they are in coding order again.
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2933 *
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2934 * Example: The track with 25 FPS contains four frames with the timecodes
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2935 * I at 0ms, P at 120ms, B at 40ms and B at 80ms. As soon as the next I
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2936 * or P frame arrives these timecodes can be changed to I at 0ms, P at 40ms,
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2937 * B at 80ms and B at 120ms.
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2938 *
16912
4dea8b8f3b65 sort timestamps instead of assuming conventional B-frame order. (fixes x264 B-pyramid)
lorenm
parents: 16877
diff changeset
2939 * This works for simple H.264 B-frame pyramids, but not for arbitrary orders.
4dea8b8f3b65 sort timestamps instead of assuming conventional B-frame order. (fixes x264 B-pyramid)
lorenm
parents: 16877
diff changeset
2940 *
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2941 * \param demuxer The Matroska demuxer struct for this instance.
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2942 * \param track The track structure whose cache should be handled.
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2943 */
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2944 static void
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2945 flush_cached_dps (demuxer_t *demuxer, mkv_track_t *track)
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2946 {
16912
4dea8b8f3b65 sort timestamps instead of assuming conventional B-frame order. (fixes x264 B-pyramid)
lorenm
parents: 16877
diff changeset
2947 int i, ok;
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2948
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2949 if (track->num_cached_dps == 0)
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2950 return;
16912
4dea8b8f3b65 sort timestamps instead of assuming conventional B-frame order. (fixes x264 B-pyramid)
lorenm
parents: 16877
diff changeset
2951
4dea8b8f3b65 sort timestamps instead of assuming conventional B-frame order. (fixes x264 B-pyramid)
lorenm
parents: 16877
diff changeset
2952 do {
4dea8b8f3b65 sort timestamps instead of assuming conventional B-frame order. (fixes x264 B-pyramid)
lorenm
parents: 16877
diff changeset
2953 ok = 1;
4dea8b8f3b65 sort timestamps instead of assuming conventional B-frame order. (fixes x264 B-pyramid)
lorenm
parents: 16877
diff changeset
2954 for (i = 1; i < track->num_cached_dps; i++)
4dea8b8f3b65 sort timestamps instead of assuming conventional B-frame order. (fixes x264 B-pyramid)
lorenm
parents: 16877
diff changeset
2955 if (track->cached_dps[i - 1]->pts > track->cached_dps[i]->pts) {
4dea8b8f3b65 sort timestamps instead of assuming conventional B-frame order. (fixes x264 B-pyramid)
lorenm
parents: 16877
diff changeset
2956 float tmp_pts = track->cached_dps[i - 1]->pts;
4dea8b8f3b65 sort timestamps instead of assuming conventional B-frame order. (fixes x264 B-pyramid)
lorenm
parents: 16877
diff changeset
2957 track->cached_dps[i - 1]->pts = track->cached_dps[i]->pts;
4dea8b8f3b65 sort timestamps instead of assuming conventional B-frame order. (fixes x264 B-pyramid)
lorenm
parents: 16877
diff changeset
2958 track->cached_dps[i]->pts = tmp_pts;
4dea8b8f3b65 sort timestamps instead of assuming conventional B-frame order. (fixes x264 B-pyramid)
lorenm
parents: 16877
diff changeset
2959 ok = 0;
4dea8b8f3b65 sort timestamps instead of assuming conventional B-frame order. (fixes x264 B-pyramid)
lorenm
parents: 16877
diff changeset
2960 }
4dea8b8f3b65 sort timestamps instead of assuming conventional B-frame order. (fixes x264 B-pyramid)
lorenm
parents: 16877
diff changeset
2961 } while (!ok);
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2962
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2963 for (i = 0; i < track->num_cached_dps; i++)
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2964 ds_add_packet (demuxer->video, track->cached_dps[i]);
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2965 track->num_cached_dps = 0;
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2966 }
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2967
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2968 /** Cache video frames if timecodes have to be reordered.
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2969 *
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2970 * Timecode reordering is needed if a video track contains B frames that
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2971 * are timestamped in display order (e.g. MPEG-1, MPEG-2 or "native" MPEG-4).
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2972 * This function takes in a Matroska block read from the file, allocates a
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2973 * demux packet for it, fills in its values, allocates space for storing
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2974 * pointers to the cached demux packets and adds the packet to it. If
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2975 * the packet contains an I or a P frame then ::flush_cached_dps is called
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2976 * in order to send the old cached frames downstream.
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2977 *
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2978 * \param demuxer The Matroska demuxer struct for this instance.
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2979 * \param track The packet is meant for this track.
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2980 * \param buffer The actual frame contents.
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2981 * \param size The frame size in bytes.
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2982 * \param block_bref A relative timecode (backward reference). If it is \c 0
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2983 * then the frame is an I frame.
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2984 * \param block_fref A relative timecode (forward reference). If it is \c 0
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2985 * then the frame is either an I frame or a P frame depending on the value
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2986 * of \a block_bref. Otherwise it's a B frame.
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2987 */
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2988 static void
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2989 handle_video_bframes (demuxer_t *demuxer, mkv_track_t *track, uint8_t *buffer,
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2990 uint32_t size, int block_bref, int block_fref)
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2991 {
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2992 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2993 demux_packet_t *dp;
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2994
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2995 dp = new_demux_packet (size);
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2996 memcpy(dp->buffer, buffer, size);
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2997 dp->pos = demuxer->filepos;
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2998 dp->pts = mkv_d->last_pts;
14515
35a6c4db00ae More support for AVC in Matroska.
mosu
parents: 14513
diff changeset
2999 if ((track->num_cached_dps > 0) && (dp->pts < track->max_pts))
35a6c4db00ae More support for AVC in Matroska.
mosu
parents: 14513
diff changeset
3000 block_fref = 1;
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3001 if (block_fref == 0) /* I or P frame */
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3002 flush_cached_dps (demuxer, track);
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3003 if (block_bref != 0) /* I frame, don't cache it */
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3004 dp->flags = 0x10;
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3005 if ((track->num_cached_dps + 1) > track->num_allocated_dps)
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3006 {
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3007 track->cached_dps = (demux_packet_t **)
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3008 realloc(track->cached_dps, (track->num_cached_dps + 10) *
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3009 sizeof(demux_packet_t *));
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3010 track->num_allocated_dps += 10;
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3011 }
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3012 track->cached_dps[track->num_cached_dps] = dp;
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3013 track->num_cached_dps++;
14515
35a6c4db00ae More support for AVC in Matroska.
mosu
parents: 14513
diff changeset
3014 if (dp->pts > track->max_pts)
35a6c4db00ae More support for AVC in Matroska.
mosu
parents: 14513
diff changeset
3015 track->max_pts = dp->pts;
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3016 }
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3017
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3018 static int
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3019 handle_block (demuxer_t *demuxer, uint8_t *block, uint64_t length,
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3020 uint64_t block_duration, int64_t block_bref, int64_t block_fref)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3021 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3022 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3023 mkv_track_t *track = NULL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3024 demux_stream_t *ds = NULL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3025 uint64_t old_length;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3026 int64_t tc;
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
3027 uint32_t *lace_size;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3028 uint8_t laces;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3029 int i, num, tmp, use_this_block = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3030 float current_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3031 int16_t time;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3032
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3033 /* first byte(s): track num */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3034 num = ebml_read_vlen_uint (block, &tmp);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3035 block += tmp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3036 /* time (relative to cluster time) */
14489
ca9e98e6c10b Do not access word-sized elements on potentially unaligned memory addresses. RISC processors usually do not like that.
mosu
parents: 14461
diff changeset
3037 time = block[0] << 8 | block[1];
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3038 block += 2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3039 length -= tmp + 2;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3040 old_length = length;
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
3041 if (demux_mkv_read_block_lacing (block, &length, &laces, &lace_size))
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
3042 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3043 block += old_length - length;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3044
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3045 tc = ((time*mkv_d->tc_scale+mkv_d->cluster_tc) /1000000.0 - mkv_d->first_tc);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3046 if (tc < 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3047 tc = 0;
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
3048 if (mkv_d->stop_timecode > 0 && tc > mkv_d->stop_timecode) {
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
3049 free(lace_size);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3050 return -1;
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
3051 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3052 current_pts = tc / 1000.0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3053
11812
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
3054 clear_subtitles(demuxer, tc, 0);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3055
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3056 for (i=0; i<mkv_d->num_tracks; i++)
12721
44895a7161c8 Do not dereference NULL if no track could be found for a block.
mosu
parents: 12550
diff changeset
3057 if (mkv_d->tracks[i]->tnum == num) {
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3058 track = mkv_d->tracks[i];
12721
44895a7161c8 Do not dereference NULL if no track could be found for a block.
mosu
parents: 12550
diff changeset
3059 break;
44895a7161c8 Do not dereference NULL if no track could be found for a block.
mosu
parents: 12550
diff changeset
3060 }
44895a7161c8 Do not dereference NULL if no track could be found for a block.
mosu
parents: 12550
diff changeset
3061 if (track == NULL)
44895a7161c8 Do not dereference NULL if no track could be found for a block.
mosu
parents: 12550
diff changeset
3062 {
44895a7161c8 Do not dereference NULL if no track could be found for a block.
mosu
parents: 12550
diff changeset
3063 free(lace_size);
44895a7161c8 Do not dereference NULL if no track could be found for a block.
mosu
parents: 12550
diff changeset
3064 return 1;
44895a7161c8 Do not dereference NULL if no track could be found for a block.
mosu
parents: 12550
diff changeset
3065 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3066 if (num == demuxer->audio->id)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3067 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3068 ds = demuxer->audio;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3069
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3070 if (mkv_d->a_skip_to_keyframe && block_bref != 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3071 use_this_block = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3072 else if (mkv_d->v_skip_to_keyframe)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3073 use_this_block = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3074
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3075 if (track->fix_i_bps && use_this_block)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3076 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3077 sh_audio_t *sh = (sh_audio_t *) ds->sh;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3078
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3079 if (block_duration != 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3080 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3081 sh->i_bps = length * 1000 / block_duration;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3082 track->fix_i_bps = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3083 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3084 else if (track->qt_last_a_pts == 0.0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3085 track->qt_last_a_pts = current_pts;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3086 else if(track->qt_last_a_pts != current_pts)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3087 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3088 sh->i_bps = length / (current_pts - track->qt_last_a_pts);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3089 track->fix_i_bps = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3090 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3091 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3092 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3093 else if (tc < mkv_d->skip_to_timecode)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3094 use_this_block = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3095 else if (num == demuxer->video->id)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3096 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3097 ds = demuxer->video;
16302
36a018da4c27 Fixed seeking for AVC-in-Matroska (wrong assumption of what kind of references may be present for a non-I-frame).
mosu
parents: 16175
diff changeset
3098 if (mkv_d->v_skip_to_keyframe && (block_bref != 0 || block_fref != 0))
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3099 use_this_block = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3100 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3101 else if (num == demuxer->sub->id)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3102 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3103 ds = demuxer->sub;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3104 if (track->subtitle_type != MATROSKA_SUBTYPE_VOBSUB)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3105 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3106 if (!mkv_d->v_skip_to_keyframe)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3107 handle_subtitles (demuxer, track, block, length,
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3108 block_duration, tc);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3109 use_this_block = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3110 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3111 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3112 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3113 use_this_block = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3114
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3115 if (use_this_block)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3116 {
15701
8816b33b8948 demux_stream_t.pts should not be assigned by the demuxer. Fixes playback of VFR files. Patch by Sam Dennis <sam () malfunction ! screaming ! net>
mosu
parents: 15533
diff changeset
3117 mkv_d->last_pts = current_pts;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3118 mkv_d->last_filepos = demuxer->filepos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3119
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3120 for (i=0; i < laces; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3121 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3122 if (ds == demuxer->video && track->realmedia)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3123 handle_realvideo (demuxer, track, block, lace_size[i], block_bref);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3124 else if (ds == demuxer->audio && track->realmedia)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3125 handle_realaudio (demuxer, track, block, lace_size[i], block_bref);
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3126 else if (ds == demuxer->video && track->reorder_timecodes)
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3127 handle_video_bframes (demuxer, track, block, lace_size[i],
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3128 block_bref, block_fref);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3129 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3130 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3131 int modified, size = lace_size[i];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3132 demux_packet_t *dp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3133 uint8_t *buffer;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3134 modified = demux_mkv_decode (track, block, &buffer, &size, 1);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3135 if (buffer)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3136 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3137 dp = new_demux_packet (size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3138 memcpy (dp->buffer, buffer, size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3139 if (modified)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3140 free (buffer);
18096
f92a441c0442 10l, keyframes must have tag 0x10, not 1.
reimar
parents: 18036
diff changeset
3141 dp->flags = (block_bref == 0 && block_fref == 0) ? 0x10 : 0;
18236
d239a79a0002 Do not give bogus timestamps for laced packets with no default duration. Patch by Uoti Urpala ( uoti ! urpala () pp1 ! inet ! fi ).
mosu
parents: 18096
diff changeset
3142 /* If default_duration is 0, assume no pts value is known
d239a79a0002 Do not give bogus timestamps for laced packets with no default duration. Patch by Uoti Urpala ( uoti ! urpala () pp1 ! inet ! fi ).
mosu
parents: 18096
diff changeset
3143 * for packets after the first one (rather than all pts
d239a79a0002 Do not give bogus timestamps for laced packets with no default duration. Patch by Uoti Urpala ( uoti ! urpala () pp1 ! inet ! fi ).
mosu
parents: 18096
diff changeset
3144 * values being the same) */
d239a79a0002 Do not give bogus timestamps for laced packets with no default duration. Patch by Uoti Urpala ( uoti ! urpala () pp1 ! inet ! fi ).
mosu
parents: 18096
diff changeset
3145 if (i == 0 || track->default_duration)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3146 dp->pts = mkv_d->last_pts + i * track->default_duration;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3147 ds_add_packet (ds, dp);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3148 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3149 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3150 block += lace_size[i];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3151 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3152
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3153 if (ds == demuxer->video)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3154 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3155 mkv_d->v_skip_to_keyframe = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3156 mkv_d->skip_to_timecode = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3157 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3158 else if (ds == demuxer->audio)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3159 mkv_d->a_skip_to_keyframe = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3160
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
3161 free(lace_size);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3162 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3163 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3164
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
3165 free(lace_size);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3166 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3167 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3168
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
3169 static int
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
3170 demux_mkv_fill_buffer (demuxer_t *demuxer, demux_stream_t *ds)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3171 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3172 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3173 stream_t *s = demuxer->stream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3174 uint64_t l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3175 int il, tmp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3176
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3177 while (1)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3178 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3179 while (mkv_d->cluster_size > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3180 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3181 uint64_t block_duration = 0, block_length = 0;
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3182 int64_t block_bref = 0, block_fref = 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3183 uint8_t *block = NULL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3184
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3185 while (mkv_d->blockgroup_size > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3186 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3187 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3188 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3189 case MATROSKA_ID_BLOCKDURATION:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3190 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3191 block_duration = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3192 if (block_duration == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3193 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3194 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3195 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3196
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3197 case MATROSKA_ID_BLOCK:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3198 block_length = ebml_read_length (s, &tmp);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3199 block = (uint8_t *) malloc (block_length);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3200 demuxer->filepos = stream_tell (s);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3201 if (stream_read (s,block,block_length) != (int) block_length)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3202 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3203 l = tmp + block_length;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3204 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3205
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3206 case MATROSKA_ID_REFERENCEBLOCK:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3207 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3208 int64_t num = ebml_read_int (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3209 if (num == EBML_INT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3210 return 0;
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3211 if (num <= 0)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3212 block_bref = num;
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3213 else
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3214 block_fref = num;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3215 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3216 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3217
11934
bef061911390 Exit when an invalid EBML ID has been read (e.g. for files that have been cut off).
mosu
parents: 11901
diff changeset
3218 case EBML_ID_INVALID:
bef061911390 Exit when an invalid EBML ID has been read (e.g. for files that have been cut off).
mosu
parents: 11901
diff changeset
3219 return 0;
bef061911390 Exit when an invalid EBML ID has been read (e.g. for files that have been cut off).
mosu
parents: 11901
diff changeset
3220
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3221 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3222 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3223 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3224 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3225 mkv_d->blockgroup_size -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3226 mkv_d->cluster_size -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3227 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3228
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3229 if (block)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3230 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3231 int res = handle_block (demuxer, block, block_length,
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3232 block_duration, block_bref, block_fref);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3233 free (block);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3234 if (res < 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3235 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3236 if (res)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3237 return 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3238 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3239
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3240 if (mkv_d->cluster_size > 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3241 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3242 switch (ebml_read_id (s, &il))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3243 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3244 case MATROSKA_ID_CLUSTERTIMECODE:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3245 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3246 uint64_t num = ebml_read_uint (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3247 if (num == EBML_UINT_INVALID)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3248 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3249 if (!mkv_d->has_first_tc)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3250 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3251 mkv_d->first_tc = num * mkv_d->tc_scale / 1000000.0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3252 mkv_d->has_first_tc = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3253 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3254 mkv_d->cluster_tc = num * mkv_d->tc_scale;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3255 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3256 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3257
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3258 case MATROSKA_ID_BLOCKGROUP:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3259 mkv_d->blockgroup_size = ebml_read_length (s, &tmp);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3260 l = tmp;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3261 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3262
11934
bef061911390 Exit when an invalid EBML ID has been read (e.g. for files that have been cut off).
mosu
parents: 11901
diff changeset
3263 case EBML_ID_INVALID:
bef061911390 Exit when an invalid EBML ID has been read (e.g. for files that have been cut off).
mosu
parents: 11901
diff changeset
3264 return 0;
bef061911390 Exit when an invalid EBML ID has been read (e.g. for files that have been cut off).
mosu
parents: 11901
diff changeset
3265
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3266 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3267 ebml_read_skip (s, &l);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3268 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3269 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3270 mkv_d->cluster_size -= l + il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3271 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3272 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3273
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3274 if (ebml_read_id (s, &il) != MATROSKA_ID_CLUSTER)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3275 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3276 add_cluster_position(mkv_d, stream_tell(s)-il);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3277 mkv_d->cluster_size = ebml_read_length (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3278 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3279
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3280 return 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3281 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3282
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
3283 static void
17695
3f20b096782d Add audio_delay argument to demux_mkv_seek.
corey
parents: 17308
diff changeset
3284 demux_mkv_seek (demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3285 {
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
3286 free_cached_dps (demuxer);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3287 if (!(flags & 2)) /* time in secs */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3288 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3289 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3290 stream_t *s = demuxer->stream;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3291 int64_t target_timecode = 0, diff, min_diff=0xFFFFFFFL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3292 int i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3293
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3294 if (!(flags & 1)) /* relative seek */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3295 target_timecode = (int64_t) (mkv_d->last_pts * 1000.0);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3296 target_timecode += (int64_t)(rel_seek_secs * 1000.0);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3297 if (target_timecode < 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3298 target_timecode = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3299
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3300 if (mkv_d->indexes == NULL) /* no index was found */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3301 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3302 uint64_t target_filepos, cluster_pos, max_pos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3303
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3304 target_filepos = (uint64_t) (target_timecode * mkv_d->last_filepos
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3305 / (mkv_d->last_pts * 1000.0));
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3306
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3307 max_pos = mkv_d->cluster_positions[mkv_d->num_cluster_pos-1];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3308 if (target_filepos > max_pos)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3309 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3310 if ((off_t) max_pos > stream_tell (s))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3311 stream_seek (s, max_pos);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3312 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3313 stream_seek (s, stream_tell (s) + mkv_d->cluster_size);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3314 /* parse all the clusters upto target_filepos */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3315 while (!s->eof && stream_tell(s) < (off_t) target_filepos)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3316 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3317 switch (ebml_read_id (s, &i))
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3318 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3319 case MATROSKA_ID_CLUSTER:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3320 add_cluster_position(mkv_d, (uint64_t) stream_tell(s)-i);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3321 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3322
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3323 case MATROSKA_ID_CUES:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3324 demux_mkv_read_cues (demuxer);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3325 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3326 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3327 ebml_read_skip (s, NULL);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3328 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3329 if (s->eof)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3330 stream_reset(s);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3331 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3332
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3333 if (mkv_d->indexes == NULL)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3334 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3335 cluster_pos = mkv_d->cluster_positions[0];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3336 /* Let's find the nearest cluster */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3337 for (i=0; i < mkv_d->num_cluster_pos; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3338 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3339 diff = mkv_d->cluster_positions[i] - target_filepos;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3340 if (rel_seek_secs < 0 && diff < 0 && -diff < min_diff)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3341 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3342 cluster_pos = mkv_d->cluster_positions[i];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3343 min_diff = -diff;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3344 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3345 else if (rel_seek_secs > 0
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3346 && (diff < 0 ? -1 * diff : diff) < min_diff)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3347 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3348 cluster_pos = mkv_d->cluster_positions[i];
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3349 min_diff = diff < 0 ? -1 * diff : diff;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3350 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3351 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3352 mkv_d->cluster_size = mkv_d->blockgroup_size = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3353 stream_seek (s, cluster_pos);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3354 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3355 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3356 else
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3357 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3358 mkv_index_t *index = NULL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3359
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3360 /* let's find the entry in the indexes with the smallest */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3361 /* difference to the wanted timecode. */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3362 for (i=0; i < mkv_d->num_indexes; i++)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3363 if (mkv_d->indexes[i].tnum == demuxer->video->id)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3364 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3365 diff = target_timecode - (int64_t) mkv_d->indexes[i].timecode;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3366
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3367 if ((flags & 1 || target_timecode <= mkv_d->last_pts*1000)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3368 && diff >= 0 && diff < min_diff)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3369 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3370 min_diff = diff;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3371 index = mkv_d->indexes + i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3372 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3373 else if (target_timecode > mkv_d->last_pts*1000
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3374 && diff < 0 && -diff < min_diff)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3375 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3376 min_diff = -diff;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3377 index = mkv_d->indexes + i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3378 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3379 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3380
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3381 if (index) /* We've found an entry. */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3382 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3383 mkv_d->cluster_size = mkv_d->blockgroup_size = 0;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3384 stream_seek (s, index->filepos);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3385 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3386 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3387
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3388 if (demuxer->video->id >= 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3389 mkv_d->v_skip_to_keyframe = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3390 if (rel_seek_secs > 0.0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3391 mkv_d->skip_to_timecode = target_timecode;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3392 mkv_d->a_skip_to_keyframe = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3393
11812
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
3394 /* Clear subtitles. */
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
3395 if (target_timecode <= mkv_d->last_pts * 1000)
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
3396 clear_subtitles(demuxer, 0, 1);
322e2b0a1815 Fixed subtitle clearing.
mosu
parents: 11808
diff changeset
3397
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
3398 demux_mkv_fill_buffer(demuxer, NULL);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3399 }
12073
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3400 else if ((demuxer->movi_end <= 0) || !(flags & 1))
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3401 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] seek unsupported flags\n");
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3402 else
12073
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3403 {
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3404 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3405 stream_t *s = demuxer->stream;
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3406 uint64_t target_filepos;
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3407 mkv_index_t *index = NULL;
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3408 int i;
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3409
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3410 if (mkv_d->indexes == NULL) /* no index was found */
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3411 { /* I'm lazy... */
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3412 mp_msg (MSGT_DEMUX, MSGL_V, "[mkv] seek unsupported flags\n");
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3413 return;
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3414 }
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3415
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3416 target_filepos = (uint64_t)(demuxer->movi_end * rel_seek_secs);
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3417 for (i=0; i < mkv_d->num_indexes; i++)
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3418 if (mkv_d->indexes[i].tnum == demuxer->video->id)
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3419 if ((index == NULL) ||
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3420 ((mkv_d->indexes[i].filepos >= target_filepos) &&
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3421 ((index->filepos < target_filepos) ||
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3422 (mkv_d->indexes[i].filepos < index->filepos))))
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3423 index = &mkv_d->indexes[i];
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3424
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3425 if (!index)
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3426 return;
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3427
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3428 mkv_d->cluster_size = mkv_d->blockgroup_size = 0;
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3429 stream_seek (s, index->filepos);
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3430
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3431 if (demuxer->video->id >= 0)
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3432 mkv_d->v_skip_to_keyframe = 1;
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3433 mkv_d->skip_to_timecode = index->timecode;
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3434 mkv_d->a_skip_to_keyframe = 1;
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3435
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3436 /* Clear subtitles. */
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3437 if (index->timecode <= mkv_d->last_pts * 1000)
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3438 clear_subtitles(demuxer, 0, 1);
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3439
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
3440 demux_mkv_fill_buffer(demuxer, NULL);
12073
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
3441 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3442 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3443
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
3444 static int
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3445 demux_mkv_control (demuxer_t *demuxer, int cmd, void *arg)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3446 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3447 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3448
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3449 switch (cmd)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3450 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3451 case DEMUXER_CTRL_GET_TIME_LENGTH:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3452 if (mkv_d->duration == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3453 return DEMUXER_CTRL_DONTKNOW;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3454
16346
6ff303d2876b Make -identify's 'ID_LENGTH=' print a float and not an integer.. The
ods15
parents: 16302
diff changeset
3455 *((double *)arg) = (double)mkv_d->duration;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3456 return DEMUXER_CTRL_OK;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3457
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3458 case DEMUXER_CTRL_GET_PERCENT_POS:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3459 if (mkv_d->duration == 0)
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3460 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3461 return DEMUXER_CTRL_DONTKNOW;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3462 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3463
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3464 *((int *) arg) = (int) (100 * mkv_d->last_pts / mkv_d->duration);
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3465 return DEMUXER_CTRL_OK;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3466
15154
898f68adad2b Online audio switching now supports Matroska too. Patch by Michael Behrisch
gpoirier
parents: 14843
diff changeset
3467 case DEMUXER_CTRL_SWITCH_AUDIO:
898f68adad2b Online audio switching now supports Matroska too. Patch by Michael Behrisch
gpoirier
parents: 14843
diff changeset
3468 if (demuxer->audio && demuxer->audio->sh) {
898f68adad2b Online audio switching now supports Matroska too. Patch by Michael Behrisch
gpoirier
parents: 14843
diff changeset
3469 int i;
898f68adad2b Online audio switching now supports Matroska too. Patch by Michael Behrisch
gpoirier
parents: 14843
diff changeset
3470 demux_stream_t *d_audio = demuxer->audio;
898f68adad2b Online audio switching now supports Matroska too. Patch by Michael Behrisch
gpoirier
parents: 14843
diff changeset
3471 int idx = d_audio->id - 1; // track ids are 1 based
898f68adad2b Online audio switching now supports Matroska too. Patch by Michael Behrisch
gpoirier
parents: 14843
diff changeset
3472 int num = mkv_d->num_tracks;
898f68adad2b Online audio switching now supports Matroska too. Patch by Michael Behrisch
gpoirier
parents: 14843
diff changeset
3473 mkv_track_t *otrack = mkv_d->tracks[idx];
15285
39eb8a327ea9 adds a parameter to the switch_audio command to directly select a track.
reimar
parents: 15154
diff changeset
3474 mkv_track_t *track = 0;
39eb8a327ea9 adds a parameter to the switch_audio command to directly select a track.
reimar
parents: 15154
diff changeset
3475 if (*((int*)arg) < 0)
39eb8a327ea9 adds a parameter to the switch_audio command to directly select a track.
reimar
parents: 15154
diff changeset
3476 for (i = 1; i <= num; i++) {
39eb8a327ea9 adds a parameter to the switch_audio command to directly select a track.
reimar
parents: 15154
diff changeset
3477 track = mkv_d->tracks[(idx+i)%num];
15154
898f68adad2b Online audio switching now supports Matroska too. Patch by Michael Behrisch
gpoirier
parents: 14843
diff changeset
3478 if ((track->type == MATROSKA_TRACK_AUDIO) &&
898f68adad2b Online audio switching now supports Matroska too. Patch by Michael Behrisch
gpoirier
parents: 14843
diff changeset
3479 !strcmp(track->codec_id, otrack->codec_id) &&
15533
ddf15d233d58 Do not switch to audio tracks whose codec private data differs from the main audio track's as this will most likely result in messed up audio output. Patch by Michael Behrisch <list () behrisch ! de>
mosu
parents: 15517
diff changeset
3480 (track->private_size == otrack->private_size) &&
ddf15d233d58 Do not switch to audio tracks whose codec private data differs from the main audio track's as this will most likely result in messed up audio output. Patch by Michael Behrisch <list () behrisch ! de>
mosu
parents: 15517
diff changeset
3481 !memcmp(track->private_data, otrack->private_data, track->private_size) &&
15154
898f68adad2b Online audio switching now supports Matroska too. Patch by Michael Behrisch
gpoirier
parents: 14843
diff changeset
3482 (track->a_channels == otrack->a_channels) &&
898f68adad2b Online audio switching now supports Matroska too. Patch by Michael Behrisch
gpoirier
parents: 14843
diff changeset
3483 (track->a_bps == otrack->a_bps) &&
898f68adad2b Online audio switching now supports Matroska too. Patch by Michael Behrisch
gpoirier
parents: 14843
diff changeset
3484 (track->a_sfreq == otrack->a_sfreq)) {
898f68adad2b Online audio switching now supports Matroska too. Patch by Michael Behrisch
gpoirier
parents: 14843
diff changeset
3485 break;
898f68adad2b Online audio switching now supports Matroska too. Patch by Michael Behrisch
gpoirier
parents: 14843
diff changeset
3486 }
898f68adad2b Online audio switching now supports Matroska too. Patch by Michael Behrisch
gpoirier
parents: 14843
diff changeset
3487 }
15285
39eb8a327ea9 adds a parameter to the switch_audio command to directly select a track.
reimar
parents: 15154
diff changeset
3488 else {
39eb8a327ea9 adds a parameter to the switch_audio command to directly select a track.
reimar
parents: 15154
diff changeset
3489 track = demux_mkv_find_track_by_num (mkv_d, *((int*)arg), MATROSKA_TRACK_AUDIO);
39eb8a327ea9 adds a parameter to the switch_audio command to directly select a track.
reimar
parents: 15154
diff changeset
3490 if (track == NULL ||
39eb8a327ea9 adds a parameter to the switch_audio command to directly select a track.
reimar
parents: 15154
diff changeset
3491 strcmp (track->codec_id, otrack->codec_id) ||
15533
ddf15d233d58 Do not switch to audio tracks whose codec private data differs from the main audio track's as this will most likely result in messed up audio output. Patch by Michael Behrisch <list () behrisch ! de>
mosu
parents: 15517
diff changeset
3492 (track->private_size != otrack->private_size) ||
ddf15d233d58 Do not switch to audio tracks whose codec private data differs from the main audio track's as this will most likely result in messed up audio output. Patch by Michael Behrisch <list () behrisch ! de>
mosu
parents: 15517
diff changeset
3493 memcmp(track->private_data, otrack->private_data, track->private_size) ||
15285
39eb8a327ea9 adds a parameter to the switch_audio command to directly select a track.
reimar
parents: 15154
diff changeset
3494 track->a_channels != otrack->a_channels ||
39eb8a327ea9 adds a parameter to the switch_audio command to directly select a track.
reimar
parents: 15154
diff changeset
3495 track->a_bps != otrack->a_bps ||
39eb8a327ea9 adds a parameter to the switch_audio command to directly select a track.
reimar
parents: 15154
diff changeset
3496 track->a_sfreq != otrack->a_sfreq)
39eb8a327ea9 adds a parameter to the switch_audio command to directly select a track.
reimar
parents: 15154
diff changeset
3497 track = otrack;
39eb8a327ea9 adds a parameter to the switch_audio command to directly select a track.
reimar
parents: 15154
diff changeset
3498 }
39eb8a327ea9 adds a parameter to the switch_audio command to directly select a track.
reimar
parents: 15154
diff changeset
3499 if (track != otrack) {
39eb8a327ea9 adds a parameter to the switch_audio command to directly select a track.
reimar
parents: 15154
diff changeset
3500 d_audio->id = track->tnum;
15154
898f68adad2b Online audio switching now supports Matroska too. Patch by Michael Behrisch
gpoirier
parents: 14843
diff changeset
3501 ds_free_packs(d_audio);
898f68adad2b Online audio switching now supports Matroska too. Patch by Michael Behrisch
gpoirier
parents: 14843
diff changeset
3502 }
898f68adad2b Online audio switching now supports Matroska too. Patch by Michael Behrisch
gpoirier
parents: 14843
diff changeset
3503 }
15285
39eb8a327ea9 adds a parameter to the switch_audio command to directly select a track.
reimar
parents: 15154
diff changeset
3504 *((int*)arg) = demux_mkv_reverse_id (mkv_d, demuxer->audio->id, MATROSKA_TRACK_AUDIO);
15154
898f68adad2b Online audio switching now supports Matroska too. Patch by Michael Behrisch
gpoirier
parents: 14843
diff changeset
3505 return DEMUXER_CTRL_OK;
898f68adad2b Online audio switching now supports Matroska too. Patch by Michael Behrisch
gpoirier
parents: 14843
diff changeset
3506
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3507 default:
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3508 return DEMUXER_CTRL_NOTIMPL;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3509 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3510 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3511
13126
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3512 /** \brief Return the number of subtitle tracks in the file.
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3513
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3514 \param demuxer The demuxer for which the number of subtitle tracks
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3515 should be returned.
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3516 */
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3517 int
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3518 demux_mkv_num_subs (demuxer_t *demuxer)
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3519 {
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3520 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3521 int i, num;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3522
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3523 num = 0;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3524 for (i = 0; i < mkv_d->num_tracks; i++)
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3525 if ((mkv_d->tracks[i]->type == MATROSKA_TRACK_SUBTITLE) &&
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3526 (mkv_d->tracks[i]->subtitle_type != MATROSKA_SUBTYPE_UNKNOWN))
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3527 num++;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3528
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3529 return num;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3530 }
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3531
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3532 /** \brief Change the current subtitle track and return its ID.
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3533
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3534 Changes the current subtitle track. If the new subtitle track is a
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3535 VobSub track then the SPU decoder will be re-initialized.
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3536
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3537 \param demuxer The demuxer whose subtitle track will be changed.
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3538 \param new_num The number of the new subtitle track. The number must be
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3539 between 0 and demux_mkv_num_subs - 1.
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3540
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3541 \returns The Matroska track number of the newly selected track.
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3542 */
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3543 int
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3544 demux_mkv_change_subs (demuxer_t *demuxer, int new_num)
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3545 {
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3546 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3547 mkv_track_t *track;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3548 int i, num;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3549
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3550 num = 0;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3551 track = NULL;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3552 for (i = 0; i < mkv_d->num_tracks; i++)
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3553 {
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3554 if ((mkv_d->tracks[i]->type == MATROSKA_TRACK_SUBTITLE) &&
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3555 (mkv_d->tracks[i]->subtitle_type != MATROSKA_SUBTYPE_UNKNOWN))
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3556 num++;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3557 if (num == (new_num + 1))
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3558 {
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3559 track = mkv_d->tracks[i];
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3560 break;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3561 }
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3562 }
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3563 if (track == NULL)
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3564 return -1;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3565
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3566 if (demuxer->sub->sh == NULL)
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3567 demuxer->sub->sh = malloc(sizeof(mkv_sh_sub_t));
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3568 if (demuxer->sub->sh != NULL)
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3569 memcpy(demuxer->sub->sh, &track->sh_sub, sizeof(mkv_sh_sub_t));
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3570
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3571 return track->tnum;
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3572 }
b59e16a8dfc7 Support for subtitle switching in Matroska.
mosu
parents: 12909
diff changeset
3573
13129
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3574 /** \brief Get the language code for a subtitle track.
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3575
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3576 Retrieves the language code for a subtitle track if it is known.
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3577 If the language code is "und" then do not copy it ("und" = "undefined").
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3578
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3579 \param demuxer The demuxer to work on
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3580 \param track_num The n'th subtitle track to get the language from
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3581 \param lang Store the language here
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3582 \param maxlen The maximum number of characters to copy into lang
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3583 */
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3584 void
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3585 demux_mkv_get_sub_lang(demuxer_t *demuxer, int track_num, char *lang,
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3586 int maxlen)
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3587 {
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3588 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3589 mkv_track_t *track;
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3590 int i, num;
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3591
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3592 num = 0;
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3593 for (i = 0; i < mkv_d->num_tracks; i++)
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3594 {
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3595 track = mkv_d->tracks[i];
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3596 if (track->type == MATROSKA_TRACK_SUBTITLE)
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3597 num++;
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3598 if (num == (track_num + 1))
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3599 {
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3600 if ((track->language != NULL) &&
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3601 strcmp(track->language, "und"))
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3602 strncpy(lang, track->language, maxlen);
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3603 return;
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3604 }
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3605 }
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3606 }
cfce549da2f0 Display the language code for subtitles from Matroska files.
mosu
parents: 13126
diff changeset
3607
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
3608
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
3609 demuxer_desc_t demuxer_desc_matroska = {
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
3610 "Matroska demuxer",
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
3611 "mkv",
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
3612 "Matroska",
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
3613 "Aurelien Jacobs",
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
3614 "based on gstreamer demuxer by Ronald Bultje and demux_mkv.cpp by Moritz Bunkus",
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
3615 DEMUXER_TYPE_MATROSKA,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
3616 1, // safe autodetect
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
3617 demux_mkv_open,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
3618 demux_mkv_fill_buffer,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
3619 NULL,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
3620 demux_close_mkv,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
3621 demux_mkv_seek,
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
3622 demux_mkv_control
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
3623 };