annotate libmpdemux/demux_mkv.c @ 36898:049db0aeea85

Implement missing vpotmeter for the Win32 GUI. This item hasn't been rendered so far, and therefore neither its value would be set nor was there a mouse control.
author ib
date Wed, 12 Mar 2014 11:23:31 +0000
parents 92dd1764392a
children
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 /*
29238
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28468
diff changeset
2 * Matroska demuxer
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28468
diff changeset
3 * Copyright (C) 2004 Aurelien Jacobs <aurel@gnuage.org>
11807
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
29238
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28468
diff changeset
5 * and on demux_mkv.cpp from Moritz Bunkus.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28468
diff changeset
6 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28468
diff changeset
7 * This file is part of MPlayer.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28468
diff changeset
8 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28468
diff changeset
9 * MPlayer is free software; you can redistribute it and/or modify
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28468
diff changeset
10 * it under the terms of the GNU General Public License as published by
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28468
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28468
diff changeset
12 * (at your option) any later version.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28468
diff changeset
13 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28468
diff changeset
14 * MPlayer is distributed in the hope that it will be useful,
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28468
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28468
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28468
diff changeset
17 * GNU General Public License for more details.
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28468
diff changeset
18 *
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28468
diff changeset
19 * You should have received a copy of the GNU General Public License along
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28468
diff changeset
20 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
d643e4643313 Add standard license header to all files in libmpdemux.
diego
parents: 28468
diff changeset
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
22 */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
23
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
24 #include "config.h"
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 #include <stdlib.h>
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
27 #include <stdio.h>
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
28 #include <ctype.h>
18558
4928dd61f136 Fix potential integer overflows in memory allocation.
rtogni
parents: 18507
diff changeset
29 #include <inttypes.h>
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
30
22605
4d81dbdf46b9 Add explicit location for headers from the stream/ directory.
diego
parents: 22445
diff changeset
31 #include "stream/stream.h"
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
32 #include "demuxer.h"
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
33 #include "stheader.h"
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
34 #include "ebml.h"
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
35 #include "matroska.h"
30573
02420b32391b Add separate header for real_fix_timestamp(); avoids forward declarations.
diego
parents: 30085
diff changeset
36 #include "demux_real.h"
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
37
32461
bc43cf7638e6 Move ass_mp.[ch] to the sub directory.
cigaes
parents: 32459
diff changeset
38 #include "sub/ass_mp.h"
20680
d1a5b0ebf56f add MSGTR_MPDEMUX_MKV for demux_mkv.c
kraymer
parents: 20477
diff changeset
39 #include "mp_msg.h"
d1a5b0ebf56f add MSGTR_MPDEMUX_MKV for demux_mkv.c
kraymer
parents: 20477
diff changeset
40 #include "help_mp.h"
d1a5b0ebf56f add MSGTR_MPDEMUX_MKV for demux_mkv.c
kraymer
parents: 20477
diff changeset
41
32459
1a605463f62b Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
cigaes
parents: 32454
diff changeset
42 #include "sub/vobsub.h"
32454
69d3be4d52a2 Create a new directory, "sub", for subtitles and OSD related code.
cigaes
parents: 32225
diff changeset
43 #include "sub/subreader.h"
32467
fbe5c829c69b Move libvo/sub.[ch] from libvo to sub.
cigaes
parents: 32461
diff changeset
44 #include "sub/sub.h"
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
45
22616
09dc129234a0 Matroska seeking fixes
uau
parents: 22606
diff changeset
46 #include "libavutil/common.h"
09dc129234a0 Matroska seeking fixes
uau
parents: 22606
diff changeset
47
27341
e7c989f7a7c9 Start unifying names of internal preprocessor directives.
diego
parents: 26752
diff changeset
48 #ifdef CONFIG_QTX_CODECS
22606
97343cedd966 Use explicit path for headers from the loader/ directory.
diego
parents: 22605
diff changeset
49 #include "loader/qtx/qtxsdk/components.h"
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
50 #endif
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
51
28440
2218218264cb Convert CONFIG_ZLIB into a 0/1 option.
diego
parents: 28413
diff changeset
52 #if CONFIG_ZLIB
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
53 #include <zlib.h>
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
54 #endif
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
55
22081
fde1ddcc04c7 Make mkv demuxer use ffmpeg LZO as well.
reimar
parents: 22011
diff changeset
56 #include "libavutil/lzo.h"
23386
585d2136f018 Get rid of __attribute__((__packed__)) in Matroska demuxer
reimar
parents: 23310
diff changeset
57 #include "libavutil/intreadwrite.h"
23703
9fb716ab06a3 Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents: 23630
diff changeset
58 #include "libavutil/avstring.h"
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
59
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
60 static const unsigned char sipr_swaps[38][2] = {
18036
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
61 {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
62 {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
63 {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
64 {42,87},{43,65},{45,59},{48,79},{49,93},{51,89},{55,95},{61,76},{67,83},
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
65 {77,80}
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
66 };
18036
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
67
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
68 // Map flavour to bytes per second
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
69 #define SIPR_FLAVORS 4
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
70 #define ATRC_FLAVORS 8
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
71 #define COOK_FLAVORS 34
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
72 static const int sipr_fl2bps[SIPR_FLAVORS] = { 813, 1062, 625, 2000 };
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
73 static const int atrc_fl2bps[ATRC_FLAVORS] = {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
74 8269, 11714, 13092, 16538, 18260, 22050, 33075, 44100 };
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
75 static const int cook_fl2bps[COOK_FLAVORS] = {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
76 1000, 1378, 2024, 2584, 4005, 5513, 8010, 4005, 750, 2498,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
77 4048, 5513, 8010, 11973, 8010, 2584, 4005, 2067, 2584, 2584,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
78 4005, 4005, 5513, 5513, 8010, 12059, 1550, 8010, 12059, 5513,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
79 12016, 16408, 22911, 33506
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
80 };
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
81
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
82 typedef struct {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
83 uint32_t order, type, scope;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
84 uint32_t comp_algo;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
85 uint8_t *comp_settings;
32220
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
86 size_t comp_settings_len;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
87 } mkv_content_encoding_t;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
88
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
89 typedef struct mkv_track {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
90 int tnum;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
91 char *name;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
92
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
93 char *codec_id;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
94 int ms_compat;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
95 char *language;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
96
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
97 int type;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
98
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
99 uint32_t v_width, v_height, v_dwidth, v_dheight;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
100 float v_frate;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
101
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
102 uint32_t a_formattag;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
103 uint32_t a_channels, a_bps;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
104 float a_sfreq;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
105
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
106 float default_duration;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
107
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
108 int default_track;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
109
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
110 void *private_data;
32220
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
111 size_t private_size;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
112
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
113 /* stuff for realmedia */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
114 int realmedia;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
115 int64_t rv_kf_base;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
116 int rv_kf_pts;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
117 float rv_pts; /* previous video timestamp */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
118 float ra_pts; /* previous audio timestamp */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
119
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
120 /** realaudio descrambling */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
121 int sub_packet_size; ///< sub packet size, per stream
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
122 int sub_packet_h; ///< number of coded frames per block
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
123 int coded_framesize; ///< coded frame size, per stream
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
124 int audiopk_size; ///< audio packet size
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
125 unsigned char *audio_buf; ///< place to store reordered audio data
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
126 float *audio_timestamp; ///< timestamp for each audio packet
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
127 int sub_packet_cnt; ///< number of subpacket already received
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
128 int audio_filepos; ///< file position of first audio packet in block
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
129
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
130 /* stuff for quicktime */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
131 int fix_i_bps;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
132 float qt_last_a_pts;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
133
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
134 int subtitle_type;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
135
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
136 /* The timecodes of video frames might have to be reordered if they're
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
137 in display order (the timecodes, not the frames themselves!). In this
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
138 case demux packets have to be cached with the help of these variables. */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
139 int reorder_timecodes;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
140 demux_packet_t **cached_dps;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
141 int num_cached_dps, num_allocated_dps;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
142 float max_pts;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
143
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
144 /* generic content encoding support */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
145 mkv_content_encoding_t *encodings;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
146 int num_encodings;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
147
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
148 /* For VobSubs and SSA/ASS */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
149 sh_sub_t *sh_sub;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
150 } mkv_track_t;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
151
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
152 typedef struct mkv_index {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
153 int tnum;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
154 uint64_t timecode, filepos;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
155 } mkv_index_t;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
156
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
157 typedef struct mkv_demuxer {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
158 off_t segment_start;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
159
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
160 float duration, last_pts;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
161 uint64_t last_filepos;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
162
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
163 mkv_track_t **tracks;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
164 int num_tracks;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
165
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
166 uint64_t tc_scale, cluster_tc, first_tc;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
167 int has_first_tc;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
168
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
169 uint64_t cluster_size;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
170 uint64_t blockgroup_size;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
171
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
172 mkv_index_t *indexes;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
173 int num_indexes;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
174
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
175 off_t *parsed_cues;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
176 int parsed_cues_num;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
177 off_t *parsed_seekhead;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
178 int parsed_seekhead_num;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
179
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
180 uint64_t *cluster_positions;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
181 int num_cluster_pos;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
182
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
183 int64_t skip_to_timecode;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
184 int v_skip_to_keyframe, a_skip_to_keyframe;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
185
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
186 int64_t stop_timecode;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
187
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
188 int last_aid;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
189 int audio_tracks[MAX_A_STREAMS];
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
190 } mkv_demuxer_t;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
191
23386
585d2136f018 Get rid of __attribute__((__packed__)) in Matroska demuxer
reimar
parents: 23310
diff changeset
192 #define REALHEADER_SIZE 16
585d2136f018 Get rid of __attribute__((__packed__)) in Matroska demuxer
reimar
parents: 23310
diff changeset
193 #define RVPROPERTIES_SIZE 34
585d2136f018 Get rid of __attribute__((__packed__)) in Matroska demuxer
reimar
parents: 23310
diff changeset
194 #define RAPROPERTIES4_SIZE 56
585d2136f018 Get rid of __attribute__((__packed__)) in Matroska demuxer
reimar
parents: 23310
diff changeset
195 #define RAPROPERTIES5_SIZE 70
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
196
20140
1861d40674ca Simplify (by using realloc with NULL parameter) and refactor code to grow
reimar
parents: 20137
diff changeset
197 /**
1861d40674ca Simplify (by using realloc with NULL parameter) and refactor code to grow
reimar
parents: 20137
diff changeset
198 * \brief ensures there is space for at least one additional element
29691
183ea012e25b Change grow_array argument from void ** to void *, this avoids a aliasing
reimar
parents: 29490
diff changeset
199 * \param arrayp array to grow
20140
1861d40674ca Simplify (by using realloc with NULL parameter) and refactor code to grow
reimar
parents: 20137
diff changeset
200 * \param nelem current number of elements in array
1861d40674ca Simplify (by using realloc with NULL parameter) and refactor code to grow
reimar
parents: 20137
diff changeset
201 * \param elsize size of one array element
1861d40674ca Simplify (by using realloc with NULL parameter) and refactor code to grow
reimar
parents: 20137
diff changeset
202 */
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
203 static void av_noinline grow_array(void *arrayp, int nelem, size_t elsize)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
204 {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
205 void **array = arrayp;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
206 void *oldp = *array;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
207 if (nelem & 31)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
208 return;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
209 if (nelem > UINT_MAX / elsize - 32)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
210 *array = NULL;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
211 else
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
212 *array = realloc(*array, (nelem + 32) * elsize);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
213 if (!*array)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
214 free(oldp);
20140
1861d40674ca Simplify (by using realloc with NULL parameter) and refactor code to grow
reimar
parents: 20137
diff changeset
215 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
216
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
217 static mkv_track_t *demux_mkv_find_track_by_num(mkv_demuxer_t *d, int n,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
218 int type)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
219 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
220 int i, id;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
221
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
222 for (i = 0, id = 0; i < d->num_tracks; i++)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
223 if (d->tracks[i] != NULL && d->tracks[i]->type == type)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
224 if (id++ == n)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
225 return d->tracks[i];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
226
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
227 return NULL;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
228 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
229
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
230 static void add_cluster_position(mkv_demuxer_t *mkv_d, uint64_t position)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
231 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
232 int i = mkv_d->num_cluster_pos;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
233
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
234 while (i--)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
235 if (mkv_d->cluster_positions[i] == position)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
236 return;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
237
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
238 grow_array(&mkv_d->cluster_positions, mkv_d->num_cluster_pos,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
239 sizeof(uint64_t));
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
240 if (!mkv_d->cluster_positions) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
241 mkv_d->num_cluster_pos = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
242 return;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
243 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
244 mkv_d->cluster_positions[mkv_d->num_cluster_pos++] = position;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
245 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
246
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
247
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
248 #define AAC_SYNC_EXTENSION_TYPE 0x02b7
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
249 static int aac_get_sample_rate_index(uint32_t sample_rate)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
250 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
251 static const int srates[] = {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
252 92017, 75132, 55426, 46009, 37566, 27713,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
253 23004, 18783, 13856, 11502, 9391, 0
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
254 };
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
255 int i = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
256 while (sample_rate < srates[i])
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
257 i++;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
258 return i;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
259 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
260
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
261 /** \brief Free cached demux packets
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
262 *
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
263 * 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
264 * 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
265 * itself.
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
266 *
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
267 * \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
268 */
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
269 static void free_cached_dps(demuxer_t *demuxer)
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
270 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
271 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
272 mkv_track_t *track;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
273 int i, k;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
274
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
275 for (k = 0; k < mkv_d->num_tracks; k++) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
276 track = mkv_d->tracks[k];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
277 for (i = 0; i < track->num_cached_dps; i++)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
278 free_demux_packet(track->cached_dps[i]);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
279 free(track->cached_dps);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
280 track->cached_dps = NULL;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
281 track->num_cached_dps = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
282 track->num_allocated_dps = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
283 track->max_pts = 0;
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
284 }
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
285 }
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
286
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
287 static int demux_mkv_decode(mkv_track_t *track, uint8_t *src,
32220
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
288 uint8_t **dest, size_t *size, uint32_t type)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
289 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
290 int i, result;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
291 int modified = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
292
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
293 *dest = src;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
294 if (track->num_encodings <= 0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
295 return 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
296
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
297 for (i = 0; i < track->num_encodings; i++) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
298 if (!(track->encodings[i].scope & type))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
299 continue;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
300
28440
2218218264cb Convert CONFIG_ZLIB into a 0/1 option.
diego
parents: 28413
diff changeset
301 #if CONFIG_ZLIB
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
302 if (track->encodings[i].comp_algo == 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
303 /* zlib encoded track */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
304 z_stream zstream;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
305
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
306 zstream.zalloc = (alloc_func) 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
307 zstream.zfree = (free_func) 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
308 zstream.opaque = (voidpf) 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
309 if (inflateInit(&zstream) != Z_OK) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
310 mp_msg(MSGT_DEMUX, MSGL_WARN,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
311 MSGTR_MPDEMUX_MKV_ZlibInitializationFailed);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
312 return modified;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
313 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
314 zstream.next_in = (Bytef *) src;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
315 zstream.avail_in = *size;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
316
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
317 modified = 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
318 *dest = NULL;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
319 zstream.avail_out = *size;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
320 do {
32224
23ba595c0292 Matroska allows data to be compressed multiple times, thus ensure
reimar
parents: 32223
diff changeset
321 if (*size > SIZE_MAX - 4000 - AV_LZO_INPUT_PADDING)
32220
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
322 goto zlib_fail;
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
323
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
324 *size += 4000;
32224
23ba595c0292 Matroska allows data to be compressed multiple times, thus ensure
reimar
parents: 32223
diff changeset
325 *dest = realloc(*dest, *size + AV_LZO_INPUT_PADDING);
32225
8ebdc8466b2f Check for realloc failure. Ignore the memleak this causes since
reimar
parents: 32224
diff changeset
326 if (!*dest)
8ebdc8466b2f Check for realloc failure. Ignore the memleak this causes since
reimar
parents: 32224
diff changeset
327 goto zlib_fail;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
328 zstream.next_out = (Bytef *) (*dest + zstream.total_out);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
329 result = inflate(&zstream, Z_NO_FLUSH);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
330 if (result != Z_OK && result != Z_STREAM_END) {
32220
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
331 zlib_fail:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
332 mp_msg(MSGT_DEMUX, MSGL_WARN,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
333 MSGTR_MPDEMUX_MKV_ZlibDecompressionFailed);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
334 free(*dest);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
335 *dest = NULL;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
336 inflateEnd(&zstream);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
337 return modified;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
338 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
339 zstream.avail_out += 4000;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
340 } while (zstream.avail_out == 4000 && zstream.avail_in != 0
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
341 && result != Z_STREAM_END);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
342
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
343 *size = zstream.total_out;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
344 inflateEnd(&zstream);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
345 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
346 #endif
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
347 if (track->encodings[i].comp_algo == 2) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
348 /* lzo encoded track */
32221
4034fb538bc1 Fix decoded length calculation of LZO decompression in demux_mkv.
reimar
parents: 32220
diff changeset
349 int out_avail;
32220
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
350 int dstlen = *size > SIZE_MAX/3 ? *size : *size * 3;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
351
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
352 *dest = NULL;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
353 while (1) {
32224
23ba595c0292 Matroska allows data to be compressed multiple times, thus ensure
reimar
parents: 32223
diff changeset
354 // Max of both because we might decompress the input multiple
23ba595c0292 Matroska allows data to be compressed multiple times, thus ensure
reimar
parents: 32223
diff changeset
355 // times. Makes no sense but is possible.
23ba595c0292 Matroska allows data to be compressed multiple times, thus ensure
reimar
parents: 32223
diff changeset
356 int padding = FFMAX(AV_LZO_OUTPUT_PADDING, AV_LZO_INPUT_PADDING);
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
357 int srclen = *size;
32224
23ba595c0292 Matroska allows data to be compressed multiple times, thus ensure
reimar
parents: 32223
diff changeset
358 if (dstlen > SIZE_MAX - padding)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
359 goto lzo_fail;
32224
23ba595c0292 Matroska allows data to be compressed multiple times, thus ensure
reimar
parents: 32223
diff changeset
360 *dest = realloc(*dest, dstlen + padding);
32225
8ebdc8466b2f Check for realloc failure. Ignore the memleak this causes since
reimar
parents: 32224
diff changeset
361 if (!*dest)
8ebdc8466b2f Check for realloc failure. Ignore the memleak this causes since
reimar
parents: 32224
diff changeset
362 goto lzo_fail;
32221
4034fb538bc1 Fix decoded length calculation of LZO decompression in demux_mkv.
reimar
parents: 32220
diff changeset
363 out_avail = dstlen;
4034fb538bc1 Fix decoded length calculation of LZO decompression in demux_mkv.
reimar
parents: 32220
diff changeset
364 result = av_lzo1x_decode(*dest, &out_avail, src, &srclen);
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
365 if (result == 0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
366 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
367 if (!(result & AV_LZO_OUTPUT_FULL)) {
32222
bceb1da0fe8f Fix label indentation.
reimar
parents: 32221
diff changeset
368 lzo_fail:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
369 mp_msg(MSGT_DEMUX, MSGL_WARN,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
370 MSGTR_MPDEMUX_MKV_LzoDecompressionFailed);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
371 free(*dest);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
372 *dest = NULL;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
373 return modified;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
374 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
375 mp_msg(MSGT_DEMUX, MSGL_DBG2,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
376 "[mkv] lzo decompression buffer too small.\n");
32224
23ba595c0292 Matroska allows data to be compressed multiple times, thus ensure
reimar
parents: 32223
diff changeset
377 if (dstlen > (SIZE_MAX - padding)/2)
32220
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
378 goto lzo_fail;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
379 dstlen *= 2;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
380 }
32221
4034fb538bc1 Fix decoded length calculation of LZO decompression in demux_mkv.
reimar
parents: 32220
diff changeset
381 *size = dstlen - out_avail;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
382 }
34398
9120eb514454 Add support of compression algorithm 3 (header stripping) in mkv demuxer.
iive
parents: 33011
diff changeset
383 else if (track->encodings[i].comp_algo == 3)
9120eb514454 Add support of compression algorithm 3 (header stripping) in mkv demuxer.
iive
parents: 33011
diff changeset
384 {
9120eb514454 Add support of compression algorithm 3 (header stripping) in mkv demuxer.
iive
parents: 33011
diff changeset
385 *dest = malloc (*size + track->encodings[i].comp_settings_len);
9120eb514454 Add support of compression algorithm 3 (header stripping) in mkv demuxer.
iive
parents: 33011
diff changeset
386 memcpy(*dest, track->encodings[i].comp_settings,
9120eb514454 Add support of compression algorithm 3 (header stripping) in mkv demuxer.
iive
parents: 33011
diff changeset
387 track->encodings[i].comp_settings_len);
9120eb514454 Add support of compression algorithm 3 (header stripping) in mkv demuxer.
iive
parents: 33011
diff changeset
388 memcpy(*dest + track->encodings[i].comp_settings_len, src, *size);
9120eb514454 Add support of compression algorithm 3 (header stripping) in mkv demuxer.
iive
parents: 33011
diff changeset
389 *size += track->encodings[i].comp_settings_len;
9120eb514454 Add support of compression algorithm 3 (header stripping) in mkv demuxer.
iive
parents: 33011
diff changeset
390 modified = 1;
9120eb514454 Add support of compression algorithm 3 (header stripping) in mkv demuxer.
iive
parents: 33011
diff changeset
391 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
392 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
393
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
394 return modified;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
395 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
396
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
397
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
398 static int demux_mkv_read_info(demuxer_t *demuxer)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
399 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
400 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
401 stream_t *s = demuxer->stream;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
402 uint64_t length, l;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
403 int il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
404 uint64_t tc_scale = 1000000;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
405 long double duration = 0.;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
406
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
407 length = ebml_read_length(s, NULL);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
408 while (length > 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
409 switch (ebml_read_id(s, &il)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
410 case MATROSKA_ID_TIMECODESCALE:
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
411 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
412 uint64_t num = ebml_read_uint(s, &l);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
413 if (num == EBML_UINT_INVALID)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
414 return 1;
19809
99d375aab4db Fix movie duration calculation in case when TimecodeScale element comes after
eugeni
parents: 19645
diff changeset
415 tc_scale = num;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
416 mp_msg(MSGT_DEMUX, MSGL_V,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
417 "[mkv] | + timecode scale: %" PRIu64 "\n", tc_scale);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
418 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
419 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
420
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
421 case MATROSKA_ID_DURATION:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
422 {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
423 long double num = ebml_read_float(s, &l);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
424 if (num == EBML_FLOAT_INVALID)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
425 return 1;
19809
99d375aab4db Fix movie duration calculation in case when TimecodeScale element comes after
eugeni
parents: 19645
diff changeset
426 duration = num;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
427 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + duration: %.3Lfs\n",
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
428 duration * tc_scale / 1000000000.0);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
429 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
430 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
431
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
432 default:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
433 ebml_read_skip(s, &l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
434 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
435 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
436 length -= l + il;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
437 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
438 mkv_d->tc_scale = tc_scale;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
439 mkv_d->duration = duration * tc_scale / 1000000000.0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
440 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
441 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
442
20133
6d6c0840113f Free track encodings on error or demuxer close
reimar
parents: 20130
diff changeset
443 /**
6d6c0840113f Free track encodings on error or demuxer close
reimar
parents: 20130
diff changeset
444 * \brief free array of kv_content_encoding_t
6d6c0840113f Free track encodings on error or demuxer close
reimar
parents: 20130
diff changeset
445 * \param encodings pointer to array
6d6c0840113f Free track encodings on error or demuxer close
reimar
parents: 20130
diff changeset
446 * \param numencodings number of encodings in array
6d6c0840113f Free track encodings on error or demuxer close
reimar
parents: 20130
diff changeset
447 */
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
448 static void demux_mkv_free_encodings(mkv_content_encoding_t *encodings,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
449 int numencodings)
20133
6d6c0840113f Free track encodings on error or demuxer close
reimar
parents: 20130
diff changeset
450 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
451 while (numencodings-- > 0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
452 free(encodings[numencodings].comp_settings);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
453 free(encodings);
20133
6d6c0840113f Free track encodings on error or demuxer close
reimar
parents: 20130
diff changeset
454 }
6d6c0840113f Free track encodings on error or demuxer close
reimar
parents: 20130
diff changeset
455
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
456 static int demux_mkv_read_trackencodings(demuxer_t *demuxer,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
457 mkv_track_t *track)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
458 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
459 stream_t *s = demuxer->stream;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
460 mkv_content_encoding_t *ce, e;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
461 uint64_t len, length, l;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
462 int il, n;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
463
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
464 ce = malloc(sizeof(*ce));
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
465 n = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
466
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
467 len = length = ebml_read_length(s, &il);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
468 len += il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
469 while (length > 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
470 switch (ebml_read_id(s, &il)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
471 case MATROSKA_ID_CONTENTENCODING:
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
472 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
473 uint64_t len;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
474 int i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
475
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
476 memset(&e, 0, sizeof(e));
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
477 e.scope = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
478
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
479 len = ebml_read_length(s, &i);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
480 l = len + i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
481
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
482 while (len > 0) {
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
483 uint64_t num, l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
484 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
485
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
486 switch (ebml_read_id(s, &il)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
487 case MATROSKA_ID_CONTENTENCODINGORDER:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
488 num = ebml_read_uint(s, &l);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
489 if (num == EBML_UINT_INVALID)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
490 goto err_out;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
491 e.order = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
492 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
493
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
494 case MATROSKA_ID_CONTENTENCODINGSCOPE:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
495 num = ebml_read_uint(s, &l);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
496 if (num == EBML_UINT_INVALID)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
497 goto err_out;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
498 e.scope = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
499 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
500
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
501 case MATROSKA_ID_CONTENTENCODINGTYPE:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
502 num = ebml_read_uint(s, &l);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
503 if (num == EBML_UINT_INVALID)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
504 goto err_out;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
505 e.type = num;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
506 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
507
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
508 case MATROSKA_ID_CONTENTCOMPRESSION:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
509 {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
510 uint64_t le;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
511
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
512 le = ebml_read_length(s, &i);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
513 l = le + i;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
514
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
515 while (le > 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
516 uint64_t l;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
517 int il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
518
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
519 switch (ebml_read_id(s, &il)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
520 case MATROSKA_ID_CONTENTCOMPALGO:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
521 num = ebml_read_uint(s, &l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
522 if (num == EBML_UINT_INVALID)
20133
6d6c0840113f Free track encodings on error or demuxer close
reimar
parents: 20130
diff changeset
523 goto err_out;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
524 e.comp_algo = num;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
525 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
526
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
527 case MATROSKA_ID_CONTENTCOMPSETTINGS:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
528 l = ebml_read_length(s, &i);
32220
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
529 if (l > SIZE_MAX)
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
530 goto err_out;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
531 e.comp_settings = malloc(l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
532 stream_read(s, e.comp_settings, l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
533 e.comp_settings_len = l;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
534 l += i;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
535 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
536
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
537 default:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
538 ebml_read_skip(s, &l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
539 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
540 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
541 le -= l + il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
542 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
543
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
544 if (e.type == 1) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
545 mp_msg(MSGT_DEMUX, MSGL_WARN,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
546 MSGTR_MPDEMUX_MKV_TrackEncrypted,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
547 track->tnum);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
548 } else if (e.type != 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
549 mp_msg(MSGT_DEMUX, MSGL_WARN,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
550 MSGTR_MPDEMUX_MKV_UnknownContentEncoding,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
551 track->tnum);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
552 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
553
34398
9120eb514454 Add support of compression algorithm 3 (header stripping) in mkv demuxer.
iive
parents: 33011
diff changeset
554 if (e.comp_algo != 0 && e.comp_algo != 2 && e.comp_algo != 3) {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
555 mp_msg(MSGT_DEMUX, MSGL_WARN,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
556 MSGTR_MPDEMUX_MKV_UnknownCompression,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
557 track->tnum, e.comp_algo);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
558 }
28440
2218218264cb Convert CONFIG_ZLIB into a 0/1 option.
diego
parents: 28413
diff changeset
559 #if !CONFIG_ZLIB
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
560 else if (e.comp_algo == 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
561 mp_msg(MSGT_DEMUX, MSGL_WARN,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
562 MSGTR_MPDEMUX_MKV_ZlibCompressionUnsupported,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
563 track->tnum);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
564 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
565 #endif
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
566
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
567 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
568 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
569
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
570 default:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
571 ebml_read_skip(s, &l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
572 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
573 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
574 len -= l + il;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
575 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
576 for (i = 0; i < n; i++)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
577 if (e.order <= ce[i].order)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
578 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
579 ce = realloc(ce, (n + 1) * sizeof(*ce));
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
580 memmove(ce + i + 1, ce + i, (n - i) * sizeof(*ce));
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
581 memcpy(ce + i, &e, sizeof(e));
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
582 n++;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
583 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
584 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
585
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
586 default:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
587 ebml_read_skip(s, &l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
588 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
589 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
590
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
591 length -= l + il;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
592 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
593
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
594 track->encodings = ce;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
595 track->num_encodings = n;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
596 return len;
20133
6d6c0840113f Free track encodings on error or demuxer close
reimar
parents: 20130
diff changeset
597
6d6c0840113f Free track encodings on error or demuxer close
reimar
parents: 20130
diff changeset
598 err_out:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
599 demux_mkv_free_encodings(ce, n);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
600 return 0;
11807
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
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
603 static int demux_mkv_read_trackaudio(demuxer_t *demuxer, mkv_track_t *track)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
604 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
605 stream_t *s = demuxer->stream;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
606 uint64_t len, length, l;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
607 int il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
608
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
609 track->a_sfreq = 8000.0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
610 track->a_channels = 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
611
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
612 len = length = ebml_read_length(s, &il);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
613 len += il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
614 while (length > 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
615 switch (ebml_read_id(s, &il)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
616 case MATROSKA_ID_AUDIOSAMPLINGFREQ:
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
617 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
618 long double num = ebml_read_float(s, &l);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
619 if (num == EBML_FLOAT_INVALID)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
620 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
621 track->a_sfreq = num;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
622 mp_msg(MSGT_DEMUX, MSGL_V,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
623 "[mkv] | + Sampling frequency: %f\n", track->a_sfreq);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
624 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
625 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
626
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
627 case MATROSKA_ID_AUDIOBITDEPTH:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
628 {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
629 uint64_t num = ebml_read_uint(s, &l);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
630 if (num == EBML_UINT_INVALID)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
631 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
632 track->a_bps = num;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
633 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Bit depth: %u\n",
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
634 track->a_bps);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
635 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
636 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
637
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
638 case MATROSKA_ID_AUDIOCHANNELS:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
639 {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
640 uint64_t num = ebml_read_uint(s, &l);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
641 if (num == EBML_UINT_INVALID)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
642 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
643 track->a_channels = num;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
644 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Channels: %u\n",
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
645 track->a_channels);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
646 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
647 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
648
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
649 default:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
650 ebml_read_skip(s, &l);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
651 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
652 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
653 length -= l + il;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
654 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
655 return len;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
656 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
657
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
658 static int demux_mkv_read_trackvideo(demuxer_t *demuxer, mkv_track_t *track)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
659 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
660 stream_t *s = demuxer->stream;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
661 uint64_t len, length, l;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
662 int il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
663
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
664 len = length = ebml_read_length(s, &il);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
665 len += il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
666 while (length > 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
667 switch (ebml_read_id(s, &il)) {
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
668 case MATROSKA_ID_VIDEOFRAMERATE:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
669 {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
670 long double num = ebml_read_float(s, &l);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
671 if (num == EBML_FLOAT_INVALID)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
672 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
673 track->v_frate = num;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
674 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Frame rate: %f\n",
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
675 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
676 if (track->v_frate > 0)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
677 track->default_duration = 1 / track->v_frate;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
678 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
679 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
680
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
681 case MATROSKA_ID_VIDEODISPLAYWIDTH:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
682 {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
683 uint64_t num = ebml_read_uint(s, &l);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
684 if (num == EBML_UINT_INVALID)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
685 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
686 track->v_dwidth = num;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
687 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Display width: %u\n",
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
688 track->v_dwidth);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
689 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
690 }
11807
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 case MATROSKA_ID_VIDEODISPLAYHEIGHT:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
693 {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
694 uint64_t num = ebml_read_uint(s, &l);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
695 if (num == EBML_UINT_INVALID)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
696 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
697 track->v_dheight = num;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
698 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Display height: %u\n",
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
699 track->v_dheight);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
700 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
701 }
11807
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 case MATROSKA_ID_VIDEOPIXELWIDTH:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
704 {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
705 uint64_t num = ebml_read_uint(s, &l);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
706 if (num == EBML_UINT_INVALID)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
707 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
708 track->v_width = num;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
709 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Pixel width: %u\n",
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
710 track->v_width);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
711 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
712 }
11807
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 case MATROSKA_ID_VIDEOPIXELHEIGHT:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
715 {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
716 uint64_t num = ebml_read_uint(s, &l);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
717 if (num == EBML_UINT_INVALID)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
718 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
719 track->v_height = num;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
720 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Pixel height: %u\n",
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
721 track->v_height);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
722 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
723 }
11807
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 default:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
726 ebml_read_skip(s, &l);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
727 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
728 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
729 length -= l + il;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
730 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
731 return len;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
732 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
733
20135
7079d029d27c Free track data if error occurs while reading trackentry
reimar
parents: 20133
diff changeset
734 /**
7079d029d27c Free track data if error occurs while reading trackentry
reimar
parents: 20133
diff changeset
735 * \brief free any data associated with given track
7079d029d27c Free track data if error occurs while reading trackentry
reimar
parents: 20133
diff changeset
736 * \param track track of which to free data
7079d029d27c Free track data if error occurs while reading trackentry
reimar
parents: 20133
diff changeset
737 */
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
738 static void demux_mkv_free_trackentry(mkv_track_t *track)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
739 {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
740 free(track->name);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
741 free(track->codec_id);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
742 free(track->language);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
743 free(track->private_data);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
744 free(track->audio_buf);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
745 free(track->audio_timestamp);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
746 demux_mkv_free_encodings(track->encodings, track->num_encodings);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
747 free(track);
20135
7079d029d27c Free track data if error occurs while reading trackentry
reimar
parents: 20133
diff changeset
748 }
7079d029d27c Free track data if error occurs while reading trackentry
reimar
parents: 20133
diff changeset
749
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
750 static int demux_mkv_read_trackentry(demuxer_t *demuxer)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
751 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
752 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
753 stream_t *s = demuxer->stream;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
754 mkv_track_t *track;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
755 uint64_t len, length, l;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
756 int il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
757
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
758 track = calloc(1, sizeof(*track));
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
759 /* set default values */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
760 track->default_track = 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
761 track->name = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
762 track->language = strdup("eng");
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
763
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
764 len = length = ebml_read_length(s, &il);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
765 len += il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
766 while (length > 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
767 switch (ebml_read_id(s, &il)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
768 case MATROSKA_ID_TRACKNUMBER:
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
769 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
770 uint64_t num = ebml_read_uint(s, &l);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
771 if (num == EBML_UINT_INVALID)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
772 goto err_out;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
773 track->tnum = num;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
774 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Track number: %u\n",
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
775 track->tnum);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
776 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
777 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
778
19640
521f71200591 Display track names in matroska files.
eugeni
parents: 19621
diff changeset
779 case MATROSKA_ID_TRACKNAME:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
780 track->name = ebml_read_utf8(s, &l);
19640
521f71200591 Display track names in matroska files.
eugeni
parents: 19621
diff changeset
781 if (track->name == NULL)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
782 goto err_out;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
783 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Name: %s\n",
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
784 track->name);
19640
521f71200591 Display track names in matroska files.
eugeni
parents: 19621
diff changeset
785 break;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
786
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
787 case MATROSKA_ID_TRACKTYPE:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
788 {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
789 uint64_t num = ebml_read_uint(s, &l);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
790 if (num == EBML_UINT_INVALID)
36534
9222b4fbe1c8 mkv: replace a missed "return 0" by "goto err_out".
reimar
parents: 36316
diff changeset
791 goto err_out;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
792 track->type = num;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
793 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Track type: ");
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
794 switch (track->type) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
795 case MATROSKA_TRACK_AUDIO:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
796 mp_msg(MSGT_DEMUX, MSGL_V, "Audio\n");
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
797 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
798 case MATROSKA_TRACK_VIDEO:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
799 mp_msg(MSGT_DEMUX, MSGL_V, "Video\n");
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
800 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
801 case MATROSKA_TRACK_SUBTITLE:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
802 mp_msg(MSGT_DEMUX, MSGL_V, "Subtitle\n");
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
803 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
804 default:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
805 mp_msg(MSGT_DEMUX, MSGL_V, "unknown\n");
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
806 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
807 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
808 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
809 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
810
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
811 case MATROSKA_ID_TRACKAUDIO:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
812 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Audio track\n");
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
813 l = demux_mkv_read_trackaudio(demuxer, track);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
814 if (l == 0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
815 goto err_out;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
816 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
817
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
818 case MATROSKA_ID_TRACKVIDEO:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
819 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Video track\n");
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
820 l = demux_mkv_read_trackvideo(demuxer, track);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
821 if (l == 0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
822 goto err_out;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
823 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
824
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
825 case MATROSKA_ID_CODECID:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
826 track->codec_id = ebml_read_ascii(s, &l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
827 if (track->codec_id == NULL)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
828 goto err_out;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
829 if (!strcmp(track->codec_id, MKV_V_MSCOMP)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
830 || !strcmp(track->codec_id, MKV_A_ACM))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
831 track->ms_compat = 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
832 else if (!strcmp(track->codec_id, MKV_S_VOBSUB))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
833 track->subtitle_type = MATROSKA_SUBTYPE_VOBSUB;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
834 else if (!strcmp(track->codec_id, MKV_S_TEXTSSA)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
835 || !strcmp(track->codec_id, MKV_S_TEXTASS)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
836 || !strcmp(track->codec_id, MKV_S_SSA)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
837 || !strcmp(track->codec_id, MKV_S_ASS)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
838 track->subtitle_type = MATROSKA_SUBTYPE_SSA;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
839 } else if (!strcmp(track->codec_id, MKV_S_TEXTASCII))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
840 track->subtitle_type = MATROSKA_SUBTYPE_TEXT;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
841 if (!strcmp(track->codec_id, MKV_S_TEXTUTF8)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
842 track->subtitle_type = MATROSKA_SUBTYPE_TEXT;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
843 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
844 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Codec ID: %s\n",
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
845 track->codec_id);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
846 break;
11807
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 case MATROSKA_ID_CODECPRIVATE:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
849 {
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
850 int x;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
851 uint64_t num = ebml_read_length(s, &x);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
852 // audit: cheap guard against overflows later..
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
853 if (num > SIZE_MAX - 1000)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
854 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
855 l = x + num;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
856 track->private_data = malloc(num + AV_LZO_INPUT_PADDING);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
857 if (stream_read(s, track->private_data, num) != (int) num)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
858 goto err_out;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
859 track->private_size = num;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
860 mp_msg(MSGT_DEMUX, MSGL_V,
32223
c6e682837c8a Fix format string to match type.
reimar
parents: 32222
diff changeset
861 "[mkv] | + CodecPrivate, length " "%zu\n",
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
862 track->private_size);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
863 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
864 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
865
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
866 case MATROSKA_ID_TRACKLANGUAGE:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
867 free(track->language);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
868 track->language = ebml_read_utf8(s, &l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
869 if (track->language == NULL)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
870 goto err_out;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
871 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Language: %s\n",
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
872 track->language);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
873 break;
11807
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 case MATROSKA_ID_TRACKFLAGDEFAULT:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
876 {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
877 uint64_t num = ebml_read_uint(s, &l);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
878 if (num == EBML_UINT_INVALID)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
879 goto err_out;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
880 track->default_track = num;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
881 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Default flag: %u\n",
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
882 track->default_track);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
883 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
884 }
11807
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 case MATROSKA_ID_TRACKDEFAULTDURATION:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
887 {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
888 uint64_t num = ebml_read_uint(s, &l);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
889 if (num == EBML_UINT_INVALID)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
890 goto err_out;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
891 if (num == 0)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
892 mp_msg(MSGT_DEMUX, MSGL_V,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
893 "[mkv] | + Default duration: 0");
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
894 else {
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
895 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
896 track->default_duration = num / 1000000000.0;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
897 mp_msg(MSGT_DEMUX, MSGL_V,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
898 "[mkv] | + Default duration: "
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
899 "%.3fms ( = %.3f fps)\n", num / 1000000.0,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
900 track->v_frate);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
901 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
902 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
903 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
904
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
905 case MATROSKA_ID_TRACKENCODINGS:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
906 l = demux_mkv_read_trackencodings(demuxer, track);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
907 if (l == 0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
908 goto err_out;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
909 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
910
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
911 default:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
912 ebml_read_skip(s, &l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
913 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
914 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
915 length -= l + il;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
916 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
917
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
918 mkv_d->tracks[mkv_d->num_tracks++] = track;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
919 return len;
20135
7079d029d27c Free track data if error occurs while reading trackentry
reimar
parents: 20133
diff changeset
920
7079d029d27c Free track data if error occurs while reading trackentry
reimar
parents: 20133
diff changeset
921 err_out:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
922 demux_mkv_free_trackentry(track);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
923 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
924 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
925
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
926 static int demux_mkv_read_tracks(demuxer_t *demuxer)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
927 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
928 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
929 stream_t *s = demuxer->stream;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
930 uint64_t length, l;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
931 int il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
932
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
933 mkv_d->tracks = malloc(sizeof(*mkv_d->tracks));
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
934 mkv_d->num_tracks = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
935
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
936 length = ebml_read_length(s, NULL);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
937 while (length > 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
938 switch (ebml_read_id(s, &il)) {
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
939 case MATROSKA_ID_TRACKENTRY:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
940 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + a track...\n");
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
941 mkv_d->tracks = realloc(mkv_d->tracks, (mkv_d->num_tracks + 1)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
942 * sizeof(*mkv_d->tracks));
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
943 l = demux_mkv_read_trackentry(demuxer);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
944 if (l == 0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
945 return 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
946 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
947
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
948 default:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
949 ebml_read_skip(s, &l);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
950 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
951 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
952 length -= l + il;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
953 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
954 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
955 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
956
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
957 static int demux_mkv_read_cues(demuxer_t *demuxer)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
958 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
959 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
960 stream_t *s = demuxer->stream;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
961 uint64_t length, l, time, track, pos;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
962 off_t off;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
963 int i, il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
964
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
965 if (index_mode == 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
966 ebml_read_skip(s, NULL);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
967 return 0;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
968 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
969 off = stream_tell(s);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
970 for (i = 0; i < mkv_d->parsed_cues_num; i++)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
971 if (mkv_d->parsed_cues[i] == off) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
972 ebml_read_skip(s, NULL);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
973 return 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
974 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
975 mkv_d->parsed_cues = realloc(mkv_d->parsed_cues,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
976 (mkv_d->parsed_cues_num + 1) * sizeof(off_t));
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
977 mkv_d->parsed_cues[mkv_d->parsed_cues_num++] = off;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
978
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
979 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] /---- [ parsing cues ] -----------\n");
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
980 length = ebml_read_length(s, NULL);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
981
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
982 while (length > 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
983 time = track = pos = EBML_UINT_INVALID;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
984
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
985 switch (ebml_read_id(s, &il)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
986 case MATROSKA_ID_POINTENTRY:
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
987 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
988 uint64_t len;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
989
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
990 len = ebml_read_length(s, &i);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
991 l = len + i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
992
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
993 while (len > 0) {
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
994 uint64_t l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
995 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
996
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
997 switch (ebml_read_id(s, &il)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
998 case MATROSKA_ID_CUETIME:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
999 time = ebml_read_uint(s, &l);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1000 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1001
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1002 case MATROSKA_ID_CUETRACKPOSITION:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1003 {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1004 uint64_t le;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1005
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1006 le = ebml_read_length(s, &i);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1007 l = le + i;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1008
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1009 while (le > 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1010 uint64_t l;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1011 int il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1012
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1013 switch (ebml_read_id(s, &il)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1014 case MATROSKA_ID_CUETRACK:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1015 track = ebml_read_uint(s, &l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1016 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1017
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1018 case MATROSKA_ID_CUECLUSTERPOSITION:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1019 pos = ebml_read_uint(s, &l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1020 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1021
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1022 default:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1023 ebml_read_skip(s, &l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1024 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1025 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1026 le -= l + il;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1027 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1028 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1029 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1030
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1031 default:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1032 ebml_read_skip(s, &l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1033 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1034 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1035 len -= l + il;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1036 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1037 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1038 }
11807
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 default:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1041 ebml_read_skip(s, &l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1042 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1043 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1044
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1045 length -= l + il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1046
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1047 if (time != EBML_UINT_INVALID && track != EBML_UINT_INVALID
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1048 && pos != EBML_UINT_INVALID) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1049 grow_array(&mkv_d->indexes, mkv_d->num_indexes,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1050 sizeof(mkv_index_t));
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1051 if (!mkv_d->indexes) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1052 mkv_d->num_indexes = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1053 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1054 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1055 mkv_d->indexes[mkv_d->num_indexes].tnum = track;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1056 mkv_d->indexes[mkv_d->num_indexes].timecode = time;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1057 mkv_d->indexes[mkv_d->num_indexes].filepos = mkv_d->segment_start
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1058 + pos;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1059 mp_msg(MSGT_DEMUX, MSGL_DBG2,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1060 "[mkv] |+ found cue point " "for track %" PRIu64
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1061 ": timecode %" PRIu64 ", filepos: %" PRIu64 "\n", track,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1062 time, mkv_d->segment_start + pos);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1063 mkv_d->num_indexes++;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1064 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1065 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1066
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1067 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] \\---- [ parsing cues ] -----------\n");
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1068 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1069 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1070
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1071 static int demux_mkv_read_chapters(demuxer_t *demuxer)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1072 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1073 stream_t *s = demuxer->stream;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1074 uint64_t length, l;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1075 int il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1076
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1077 if (demuxer->chapters) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1078 ebml_read_skip(s, NULL);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1079 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1080 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1081
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1082 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] /---- [ parsing chapters ] ---------\n");
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1083 length = ebml_read_length(s, NULL);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1084
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1085 while (length > 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1086 switch (ebml_read_id(s, &il)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1087 case MATROSKA_ID_EDITIONENTRY:
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1088 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1089 uint64_t len;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1090 int i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1091
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1092 len = ebml_read_length(s, &i);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1093 l = len + i;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1094
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1095 while (len > 0) {
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1096 uint64_t l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1097 int il;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1098
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1099 switch (ebml_read_id(s, &il)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1100 case MATROSKA_ID_CHAPTERATOM:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1101 {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1102 uint64_t len, start = 0, end = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1103 char *name = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1104 int i;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1105 int cid;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1106
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1107 len = ebml_read_length(s, &i);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1108 l = len + i;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1109
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1110 while (len > 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1111 uint64_t l;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1112 int il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1113
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1114 switch (ebml_read_id(s, &il)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1115 case MATROSKA_ID_CHAPTERTIMESTART:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1116 start = ebml_read_uint(s, &l) / 1000000;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1117 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1118
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1119 case MATROSKA_ID_CHAPTERTIMEEND:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1120 end = ebml_read_uint(s, &l) / 1000000;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1121 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1122
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1123 case MATROSKA_ID_CHAPTERDISPLAY:
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1124 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1125 uint64_t len;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1126 int i;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1127
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1128 len = ebml_read_length(s, &i);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1129 l = len + i;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1130 while (len > 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1131 uint64_t l;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1132 int il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1133
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1134 switch (ebml_read_id(s, &il)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1135 case MATROSKA_ID_CHAPSTRING:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1136 name = ebml_read_utf8(s, &l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1137 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1138 default:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1139 ebml_read_skip(s, &l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1140 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1141 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1142 len -= l + il;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1143 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1144 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1145 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1146
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1147 default:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1148 ebml_read_skip(s, &l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1149 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1150 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1151 len -= l + il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1152 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1153
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1154 if (!name)
19342
4e68a3881201 Add matroska chapter seeking capability.
eugeni
parents: 19154
diff changeset
1155 name = strdup("(unnamed)");
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
1156
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1157 cid = demuxer_add_chapter(demuxer, name, start, end);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1158
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1159 mp_msg(MSGT_DEMUX, MSGL_V,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1160 "[mkv] Chapter %u from %02d:%02d:%02d."
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1161 "%03d to %02d:%02d:%02d.%03d, %s\n", cid,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1162 (int) (start / 60 / 60 / 1000),
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1163 (int) ((start / 60 / 1000) % 60),
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1164 (int) ((start / 1000) % 60),
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1165 (int) (start % 1000),
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1166 (int) (end / 60 / 60 / 1000),
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1167 (int) ((end / 60 / 1000) % 60),
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1168 (int) ((end / 1000) % 60),
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1169 (int) (end % 1000), name);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1170
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1171 free(name);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1172 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1173 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1174
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1175 default:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1176 ebml_read_skip(s, &l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1177 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1178 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1179 len -= l + il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1180 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1181 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1182 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1183
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1184 default:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1185 ebml_read_skip(s, &l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1186 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1187 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1188
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1189 length -= l + il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1190 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1191
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1192 mp_msg(MSGT_DEMUX, MSGL_V,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1193 "[mkv] \\---- [ parsing chapters ] ---------\n");
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1194 return 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1195 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1196
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1197 static int demux_mkv_read_tags(demuxer_t *demuxer)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1198 {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1199 ebml_read_skip(demuxer->stream, NULL);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1200 return 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1201 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1202
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1203 static int demux_mkv_read_attachments(demuxer_t *demuxer)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1204 {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1205 stream_t *s = demuxer->stream;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1206 uint64_t length, l;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1207 int il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1208
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1209 mp_msg(MSGT_DEMUX, MSGL_V,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1210 "[mkv] /---- [ parsing attachments ] ---------\n");
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1211 length = ebml_read_length(s, NULL);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1212
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1213 while (length > 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1214 switch (ebml_read_id(s, &il)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1215 case MATROSKA_ID_ATTACHEDFILE:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1216 {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1217 uint64_t len;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1218 int i;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1219 char *name = NULL;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1220 char *mime = NULL;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1221 char *data = NULL;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1222 int data_size = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1223
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1224 len = ebml_read_length(s, &i);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1225 l = len + i;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1226
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1227 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + an attachment...\n");
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1228
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1229 while (len > 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1230 uint64_t l;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1231 int il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1232
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1233 switch (ebml_read_id(s, &il)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1234 case MATROSKA_ID_FILENAME:
36553
e5e36c2a0055 demux_mkv: Fix massive memleaks in attachment parsing.
reimar
parents: 36534
diff changeset
1235 free(name);
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1236 name = ebml_read_utf8(s, &l);
36553
e5e36c2a0055 demux_mkv: Fix massive memleaks in attachment parsing.
reimar
parents: 36534
diff changeset
1237 if (name == NULL) {
e5e36c2a0055 demux_mkv: Fix massive memleaks in attachment parsing.
reimar
parents: 36534
diff changeset
1238 free(mime);
e5e36c2a0055 demux_mkv: Fix massive memleaks in attachment parsing.
reimar
parents: 36534
diff changeset
1239 free(data);
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1240 return 0;
36553
e5e36c2a0055 demux_mkv: Fix massive memleaks in attachment parsing.
reimar
parents: 36534
diff changeset
1241 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1242 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + FileName: %s\n",
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1243 name);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1244 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1245
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1246 case MATROSKA_ID_FILEMIMETYPE:
36553
e5e36c2a0055 demux_mkv: Fix massive memleaks in attachment parsing.
reimar
parents: 36534
diff changeset
1247 free(mime);
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1248 mime = ebml_read_ascii(s, &l);
36553
e5e36c2a0055 demux_mkv: Fix massive memleaks in attachment parsing.
reimar
parents: 36534
diff changeset
1249 if (mime == NULL) {
e5e36c2a0055 demux_mkv: Fix massive memleaks in attachment parsing.
reimar
parents: 36534
diff changeset
1250 free(name);
e5e36c2a0055 demux_mkv: Fix massive memleaks in attachment parsing.
reimar
parents: 36534
diff changeset
1251 free(data);
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1252 return 0;
36553
e5e36c2a0055 demux_mkv: Fix massive memleaks in attachment parsing.
reimar
parents: 36534
diff changeset
1253 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1254 mp_msg(MSGT_DEMUX, MSGL_V,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1255 "[mkv] | + FileMimeType: %s\n", mime);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1256 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1257
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1258 case MATROSKA_ID_FILEDATA:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1259 {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1260 int x;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1261 uint64_t num = ebml_read_length(s, &x);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1262 l = x + num;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1263 free(data);
36553
e5e36c2a0055 demux_mkv: Fix massive memleaks in attachment parsing.
reimar
parents: 36534
diff changeset
1264 if (num > SIZE_MAX) {
e5e36c2a0055 demux_mkv: Fix massive memleaks in attachment parsing.
reimar
parents: 36534
diff changeset
1265 free(name);
e5e36c2a0055 demux_mkv: Fix massive memleaks in attachment parsing.
reimar
parents: 36534
diff changeset
1266 free(mime);
32220
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1267 return 0;
36553
e5e36c2a0055 demux_mkv: Fix massive memleaks in attachment parsing.
reimar
parents: 36534
diff changeset
1268 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1269 data = malloc(num);
36553
e5e36c2a0055 demux_mkv: Fix massive memleaks in attachment parsing.
reimar
parents: 36534
diff changeset
1270 if (!data || stream_read(s, data, num) != (int) num) {
e5e36c2a0055 demux_mkv: Fix massive memleaks in attachment parsing.
reimar
parents: 36534
diff changeset
1271 free(name);
e5e36c2a0055 demux_mkv: Fix massive memleaks in attachment parsing.
reimar
parents: 36534
diff changeset
1272 free(mime);
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1273 free(data);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1274 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1275 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1276 data_size = num;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1277 mp_msg(MSGT_DEMUX, MSGL_V,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1278 "[mkv] | + FileData, length " "%u\n",
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1279 data_size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1280 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1281 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1282
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1283 default:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1284 ebml_read_skip(s, &l);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1285 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1286 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1287 len -= l + il;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1288 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1289
36580
0462f5c5aa00 demux_mkv: use a default mime-type if none was specified.
reimar
parents: 36553
diff changeset
1290 demuxer_add_attachment(demuxer, name, mime ? mime : "application/octet-stream", data, data_size);
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1291 mp_msg(MSGT_DEMUX, MSGL_V,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1292 "[mkv] Attachment: %s, %s, %u bytes\n", name, mime,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1293 data_size);
36553
e5e36c2a0055 demux_mkv: Fix massive memleaks in attachment parsing.
reimar
parents: 36534
diff changeset
1294 free(name);
e5e36c2a0055 demux_mkv: Fix massive memleaks in attachment parsing.
reimar
parents: 36534
diff changeset
1295 free(mime);
e5e36c2a0055 demux_mkv: Fix massive memleaks in attachment parsing.
reimar
parents: 36534
diff changeset
1296 free(data);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1297 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1298 }
11807
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 default:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1301 ebml_read_skip(s, &l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1302 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1303 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1304 length -= l + il;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1305 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1306
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1307 mp_msg(MSGT_DEMUX, MSGL_V,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1308 "[mkv] \\---- [ parsing attachments ] ---------\n");
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1309 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1310 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1311
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1312 static int demux_mkv_read_seekhead(demuxer_t *demuxer)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1313 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1314 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1315 stream_t *s = demuxer->stream;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1316 uint64_t length, l, seek_pos, saved_pos, num;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1317 uint32_t seek_id;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1318 int i, il, res = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1319 off_t off;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1320
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1321 off = stream_tell(s);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1322 for (i = 0; i < mkv_d->parsed_seekhead_num; i++)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1323 if (mkv_d->parsed_seekhead[i] == off) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1324 ebml_read_skip(s, NULL);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1325 return 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1326 }
32220
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1327 if (mkv_d->parsed_seekhead_num >= INT_MAX ||
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1328 mkv_d->parsed_seekhead_num > SIZE_MAX/sizeof(off_t))
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1329 return 0;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1330 mkv_d->parsed_seekhead = realloc(mkv_d->parsed_seekhead,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1331 (mkv_d->parsed_seekhead_num + 1)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1332 * sizeof(off_t));
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1333 mkv_d->parsed_seekhead[mkv_d->parsed_seekhead_num++] = off;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1334
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1335 mp_msg(MSGT_DEMUX, MSGL_V,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1336 "[mkv] /---- [ parsing seek head ] ---------\n");
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1337 length = ebml_read_length(s, NULL);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1338 /* off now holds the position of the next element after the seek head. */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1339 off = stream_tell(s) + length;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1340 while (length > 0 && !res) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1341
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1342 seek_id = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1343 seek_pos = EBML_UINT_INVALID;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1344
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1345 switch (ebml_read_id(s, &il)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1346 case MATROSKA_ID_SEEKENTRY:
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents: 18934
diff changeset
1347 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1348 uint64_t len;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1349
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1350 len = ebml_read_length(s, &i);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1351 l = len + i;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1352
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1353 while (len > 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1354 uint64_t l;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1355 int il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1356
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1357 switch (ebml_read_id(s, &il)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1358 case MATROSKA_ID_SEEKID:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1359 num = ebml_read_uint(s, &l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1360 if (num != EBML_UINT_INVALID)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1361 seek_id = num;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1362 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1363
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1364 case MATROSKA_ID_SEEKPOSITION:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1365 seek_pos = ebml_read_uint(s, &l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1366 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1367
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1368 default:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1369 ebml_read_skip(s, &l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1370 break;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents: 18934
diff changeset
1371 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1372 len -= l + il;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents: 18934
diff changeset
1373 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents: 18934
diff changeset
1374
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1375 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1376 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1377
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1378 default:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1379 ebml_read_skip(s, &l);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents: 18934
diff changeset
1380 break;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents: 18934
diff changeset
1381 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1382 length -= l + il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1383
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1384 if (seek_id == 0 || seek_id == MATROSKA_ID_CLUSTER
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1385 || seek_pos == EBML_UINT_INVALID
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1386 || ((mkv_d->segment_start + seek_pos) >=
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1387 (uint64_t) demuxer->movi_end))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1388 continue;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1389
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1390 saved_pos = stream_tell(s);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1391 if (!stream_seek(s, mkv_d->segment_start + seek_pos))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1392 res = 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1393 else {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1394 if (ebml_read_id(s, &il) != seek_id)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1395 res = 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1396 else
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1397 switch (seek_id) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1398 case MATROSKA_ID_CUES:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1399 if (demux_mkv_read_cues(demuxer))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1400 res = 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1401 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1402
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1403 case MATROSKA_ID_TAGS:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1404 if (demux_mkv_read_tags(demuxer))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1405 res = 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1406 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1407
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1408 case MATROSKA_ID_SEEKHEAD:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1409 if (demux_mkv_read_seekhead(demuxer))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1410 res = 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1411 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1412
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1413 case MATROSKA_ID_CHAPTERS:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1414 if (demux_mkv_read_chapters(demuxer))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1415 res = 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1416 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1417 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1418 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1419
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1420 stream_seek(s, saved_pos);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents: 18934
diff changeset
1421 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1422 if (res) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1423 /* If there was an error then try to skip this seek head. */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1424 if (stream_seek(s, off))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1425 res = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1426 } else if (length > 0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1427 stream_seek(s, stream_tell(s) + length);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1428 mp_msg(MSGT_DEMUX, MSGL_V,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1429 "[mkv] \\---- [ parsing seek head ] ---------\n");
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1430 return res;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents: 18934
diff changeset
1431 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents: 18934
diff changeset
1432
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1433 static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1434 int vid);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1435 static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1436 int aid);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1437 static int demux_mkv_open_sub(demuxer_t *demuxer, mkv_track_t *track,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1438 int sid);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1439
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1440 static void display_create_tracks(demuxer_t *demuxer)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1441 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1442 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1443 int i, vid = 0, aid = 0, sid = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1444
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1445 for (i = 0; i < mkv_d->num_tracks; i++) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1446 char *type = "unknown", str[32];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1447 *str = '\0';
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1448 switch (mkv_d->tracks[i]->type) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1449 case MATROSKA_TRACK_VIDEO:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1450 type = "video";
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1451 demux_mkv_open_video(demuxer, mkv_d->tracks[i], vid);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1452 if (mkv_d->tracks[i]->name)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1453 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VID_%d_NAME=%s\n", vid,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1454 mkv_d->tracks[i]->name);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1455 sprintf(str, "-vid %u", vid++);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1456 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1457 case MATROSKA_TRACK_AUDIO:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1458 type = "audio";
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1459 demux_mkv_open_audio(demuxer, mkv_d->tracks[i], aid);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1460 if (mkv_d->tracks[i]->name)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1461 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AID_%d_NAME=%s\n", aid,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1462 mkv_d->tracks[i]->name);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1463 sprintf(str, "-aid %u, -alang %.5s", aid++,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1464 mkv_d->tracks[i]->language);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1465 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1466 case MATROSKA_TRACK_SUBTITLE:
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1467 type = "subtitles";
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1468 demux_mkv_open_sub(demuxer, mkv_d->tracks[i], sid);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1469 if (mkv_d->tracks[i]->name)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1470 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SID_%d_NAME=%s\n", sid,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1471 mkv_d->tracks[i]->name);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1472 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SID_%d_LANG=%s\n", sid,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1473 mkv_d->tracks[i]->language);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1474 sprintf(str, "-sid %u, -slang %.5s", sid++,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1475 mkv_d->tracks[i]->language);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1476 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1477 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1478 if (mkv_d->tracks[i]->name)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1479 mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_MPDEMUX_MKV_TrackIDName,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1480 mkv_d->tracks[i]->tnum, type, mkv_d->tracks[i]->codec_id,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1481 mkv_d->tracks[i]->name, str);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1482 else
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1483 mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_MPDEMUX_MKV_TrackID,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1484 mkv_d->tracks[i]->tnum, type, mkv_d->tracks[i]->codec_id,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1485 str);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1486 }
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
23270
f094c9256137 Avoid code duplication in mkv demuxer for standard fourcc/extradata handling
reimar
parents: 23187
diff changeset
1489 typedef struct {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1490 char *id;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1491 int fourcc;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1492 int extradata;
23270
f094c9256137 Avoid code duplication in mkv demuxer for standard fourcc/extradata handling
reimar
parents: 23187
diff changeset
1493 } videocodec_info_t;
f094c9256137 Avoid code duplication in mkv demuxer for standard fourcc/extradata handling
reimar
parents: 23187
diff changeset
1494
f094c9256137 Avoid code duplication in mkv demuxer for standard fourcc/extradata handling
reimar
parents: 23187
diff changeset
1495 static const videocodec_info_t vinfo[] = {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1496 {MKV_V_MPEG1, mmioFOURCC('m', 'p', 'g', '1'), 0},
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1497 {MKV_V_MPEG2, mmioFOURCC('m', 'p', 'g', '2'), 0},
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1498 {MKV_V_MPEG4_SP, mmioFOURCC('m', 'p', '4', 'v'), 1},
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1499 {MKV_V_MPEG4_ASP, mmioFOURCC('m', 'p', '4', 'v'), 1},
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1500 {MKV_V_MPEG4_AP, mmioFOURCC('m', 'p', '4', 'v'), 1},
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1501 {MKV_V_MPEG4_AVC, mmioFOURCC('a', 'v', 'c', '1'), 1},
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1502 {MKV_V_THEORA, mmioFOURCC('t', 'h', 'e', 'o'), 1},
31263
6428a4b38763 Add webm/VP8 support to native matroska demuxer.
reimar
parents: 31210
diff changeset
1503 {MKV_V_VP8, mmioFOURCC('V', 'P', '8', '0'), 0},
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1504 {NULL, 0, 0}
23270
f094c9256137 Avoid code duplication in mkv demuxer for standard fourcc/extradata handling
reimar
parents: 23187
diff changeset
1505 };
f094c9256137 Avoid code duplication in mkv demuxer for standard fourcc/extradata handling
reimar
parents: 23187
diff changeset
1506
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1507 static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1508 int vid)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1509 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1510 BITMAPINFOHEADER *bih;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1511 void *ImageDesc = NULL;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1512 sh_video_t *sh_v;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1513
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1514 if (track->ms_compat) { /* MS compatibility mode */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1515 BITMAPINFOHEADER *src;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1516
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1517 if (track->private_data == NULL
32220
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1518 || track->private_size >= INT_MAX - 1000
32111
7c8d240d37a6 Replace sizeof(type)
reimar
parents: 31609
diff changeset
1519 || track->private_size < sizeof(*bih))
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1520 return 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1521
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1522 src = (BITMAPINFOHEADER *) track->private_data;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1523 bih = calloc(1, track->private_size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1524 bih->biSize = le2me_32(src->biSize);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1525 bih->biWidth = le2me_32(src->biWidth);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1526 bih->biHeight = le2me_32(src->biHeight);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1527 bih->biPlanes = le2me_16(src->biPlanes);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1528 bih->biBitCount = le2me_16(src->biBitCount);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1529 bih->biCompression = le2me_32(src->biCompression);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1530 bih->biSizeImage = le2me_32(src->biSizeImage);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1531 bih->biXPelsPerMeter = le2me_32(src->biXPelsPerMeter);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1532 bih->biYPelsPerMeter = le2me_32(src->biYPelsPerMeter);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1533 bih->biClrUsed = le2me_32(src->biClrUsed);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1534 bih->biClrImportant = le2me_32(src->biClrImportant);
32111
7c8d240d37a6 Replace sizeof(type)
reimar
parents: 31609
diff changeset
1535 memcpy(bih + 1,
7c8d240d37a6 Replace sizeof(type)
reimar
parents: 31609
diff changeset
1536 src + 1,
7c8d240d37a6 Replace sizeof(type)
reimar
parents: 31609
diff changeset
1537 track->private_size - sizeof(*bih));
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1538
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1539 if (track->v_width == 0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1540 track->v_width = bih->biWidth;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1541 if (track->v_height == 0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1542 track->v_height = bih->biHeight;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1543 } else {
32111
7c8d240d37a6 Replace sizeof(type)
reimar
parents: 31609
diff changeset
1544 bih = calloc(1, sizeof(*bih));
7c8d240d37a6 Replace sizeof(type)
reimar
parents: 31609
diff changeset
1545 bih->biSize = sizeof(*bih);
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1546 bih->biWidth = track->v_width;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1547 bih->biHeight = track->v_height;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1548 bih->biBitCount = 24;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1549 bih->biSizeImage = bih->biWidth * bih->biHeight * bih->biBitCount / 8;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1550
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1551 if (track->private_size >= RVPROPERTIES_SIZE
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1552 && (!strcmp(track->codec_id, MKV_V_REALV10)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1553 || !strcmp(track->codec_id, MKV_V_REALV20)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1554 || !strcmp(track->codec_id, MKV_V_REALV30)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1555 || !strcmp(track->codec_id, MKV_V_REALV40))) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1556 unsigned char *dst, *src;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1557 uint32_t type2;
32220
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1558 size_t cnt;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1559
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1560 src = (uint8_t *) track->private_data + RVPROPERTIES_SIZE;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1561
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1562 cnt = track->private_size - RVPROPERTIES_SIZE;
32220
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1563 if (cnt > INT_MAX - sizeof(*bih) - 8) {
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1564 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] Integer overflow!\n");
35341
34c05e3ea263 Fix leaks in case of overflow.
upsuper
parents: 34398
diff changeset
1565 free(bih);
32220
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1566 return 1;
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1567 }
32111
7c8d240d37a6 Replace sizeof(type)
reimar
parents: 31609
diff changeset
1568 bih = realloc(bih, sizeof(*bih) + 8 + cnt);
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1569 bih->biSize = 48 + cnt;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1570 bih->biPlanes = 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1571 type2 = AV_RB32(src - 4);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1572 if (type2 == 0x10003000 || type2 == 0x10003001)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1573 bih->biCompression = mmioFOURCC('R', 'V', '1', '3');
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1574 else
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1575 bih->biCompression =
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1576 mmioFOURCC('R', 'V', track->codec_id[9], '0');
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1577 dst = (unsigned char *) (bih + 1);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1578 // copy type1 and type2 info from rv properties
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1579 memcpy(dst, src - 8, 8);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1580 stream_read(demuxer->stream, dst + 8, cnt);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1581 track->realmedia = 1;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1582
27341
e7c989f7a7c9 Start unifying names of internal preprocessor directives.
diego
parents: 26752
diff changeset
1583 #ifdef CONFIG_QTX_CODECS
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1584 } else if (track->private_size >= sizeof(ImageDescription)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1585 && !strcmp(track->codec_id, MKV_V_QUICKTIME)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1586 ImageDescriptionPtr idesc;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1587
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1588 idesc = (ImageDescriptionPtr) track->private_data;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1589 idesc->idSize = be2me_32(idesc->idSize);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1590 idesc->cType = be2me_32(idesc->cType);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1591 idesc->version = be2me_16(idesc->version);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1592 idesc->revisionLevel = be2me_16(idesc->revisionLevel);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1593 idesc->vendor = be2me_32(idesc->vendor);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1594 idesc->temporalQuality = be2me_32(idesc->temporalQuality);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1595 idesc->spatialQuality = be2me_32(idesc->spatialQuality);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1596 idesc->width = be2me_16(idesc->width);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1597 idesc->height = be2me_16(idesc->height);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1598 idesc->hRes = be2me_32(idesc->hRes);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1599 idesc->vRes = be2me_32(idesc->vRes);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1600 idesc->dataSize = be2me_32(idesc->dataSize);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1601 idesc->frameCount = be2me_16(idesc->frameCount);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1602 idesc->depth = be2me_16(idesc->depth);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1603 idesc->clutID = be2me_16(idesc->clutID);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1604 bih->biPlanes = 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1605 bih->biCompression = idesc->cType;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1606 ImageDesc = idesc;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1607 #endif /* CONFIG_QTX_CODECS */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1608
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1609 } else {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1610 const videocodec_info_t *vi = vinfo;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1611 while (vi->id && strcmp(vi->id, track->codec_id))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1612 vi++;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1613 bih->biCompression = vi->fourcc;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1614 if (vi->extradata && track->private_data
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1615 && (track->private_size > 0)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1616 bih->biSize += track->private_size;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1617 bih = realloc(bih, bih->biSize);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1618 memcpy(bih + 1, track->private_data, track->private_size);
19154
2895b9807ff3 Native MPEG4 SP/ASP/AP support in Matroska.
rathann
parents: 18984
diff changeset
1619 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1620 track->reorder_timecodes = user_correct_pts == 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1621 if (!vi->id) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1622 mp_msg(MSGT_DEMUX, MSGL_WARN, MSGTR_MPDEMUX_MKV_UnknownCodecID,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1623 track->codec_id, track->tnum);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1624 free(bih);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1625 return 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1626 }
11807
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 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1629
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1630 sh_v = new_sh_video_vid(demuxer, track->tnum, vid);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1631 sh_v->bih = bih;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1632 sh_v->format = sh_v->bih->biCompression;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1633 if (track->v_frate == 0.0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1634 track->v_frate = 25.0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1635 sh_v->fps = track->v_frate;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1636 sh_v->frametime = 1 / track->v_frate;
36316
139f2b064ef9 Don't subsequently calculate original_aspect from last movie_aspect.
ib
parents: 35341
diff changeset
1637 sh_v->original_aspect = 0;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1638 if (!track->realmedia) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1639 sh_v->disp_w = track->v_width;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1640 sh_v->disp_h = track->v_height;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1641 if (track->v_dheight)
36316
139f2b064ef9 Don't subsequently calculate original_aspect from last movie_aspect.
ib
parents: 35341
diff changeset
1642 sh_v->original_aspect = (float) track->v_dwidth / (float) track->v_dheight;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1643 } else {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1644 // vd_realvid.c will set aspect to disp_w/disp_h and rederive
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1645 // disp_w and disp_h from the RealVideo stream contents returned
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1646 // by the Real DLLs. If DisplayWidth/DisplayHeight was not set in
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1647 // the Matroska file then it has already been set to PixelWidth/Height
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1648 // by check_track_information.
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1649 sh_v->disp_w = track->v_dwidth;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1650 sh_v->disp_h = track->v_dheight;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1651 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1652 sh_v->ImageDesc = ImageDesc;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1653 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Aspect: %f\n", sh_v->aspect);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1654
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1655 return 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1656 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1657
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1658 static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1659 int aid)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1660 {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1661 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
31609
cd81fce1f010 Make the stream language an argument to the stream creation function
reimar
parents: 31602
diff changeset
1662 sh_audio_t *sh_a = new_sh_audio_aid(demuxer, track->tnum, aid,
cd81fce1f010 Make the stream language an argument to the stream creation function
reimar
parents: 31602
diff changeset
1663 track->language);
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1664 demux_packet_t *dp;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1665 if (!sh_a)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1666 return 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1667 mkv_d->audio_tracks[mkv_d->last_aid] = track->tnum;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1668
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1669 sh_a->default_track = track->default_track;
32111
7c8d240d37a6 Replace sizeof(type)
reimar
parents: 31609
diff changeset
1670 sh_a->wf = malloc(sizeof(*sh_a->wf));
32113
e21b0baab10c Replace several sizeof(WAVEFORMATEX)
reimar
parents: 32112
diff changeset
1671 if (track->ms_compat && (track->private_size >= sizeof(*sh_a->wf))) {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1672 WAVEFORMATEX *wf = (WAVEFORMATEX *) track->private_data;
32220
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1673 if (track->private_size > USHRT_MAX + sizeof(WAVEFORMATEX)) {
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1674 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] Integer overflow!\n");
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1675 free_sh_audio(demuxer, track->tnum);
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1676 return 1;
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1677 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1678 sh_a->wf = realloc(sh_a->wf, track->private_size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1679 sh_a->wf->wFormatTag = le2me_16(wf->wFormatTag);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1680 sh_a->wf->nChannels = le2me_16(wf->nChannels);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1681 sh_a->wf->nSamplesPerSec = le2me_32(wf->nSamplesPerSec);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1682 sh_a->wf->nAvgBytesPerSec = le2me_32(wf->nAvgBytesPerSec);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1683 sh_a->wf->nBlockAlign = le2me_16(wf->nBlockAlign);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1684 sh_a->wf->wBitsPerSample = le2me_16(wf->wBitsPerSample);
32113
e21b0baab10c Replace several sizeof(WAVEFORMATEX)
reimar
parents: 32112
diff changeset
1685 sh_a->wf->cbSize = track->private_size - sizeof(*sh_a->wf);
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1686 memcpy(sh_a->wf + 1, wf + 1,
32113
e21b0baab10c Replace several sizeof(WAVEFORMATEX)
reimar
parents: 32112
diff changeset
1687 track->private_size - sizeof(*sh_a->wf));
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1688 if (track->a_sfreq == 0.0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1689 track->a_sfreq = sh_a->wf->nSamplesPerSec;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1690 if (track->a_channels == 0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1691 track->a_channels = sh_a->wf->nChannels;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1692 if (track->a_bps == 0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1693 track->a_bps = sh_a->wf->wBitsPerSample;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1694 track->a_formattag = sh_a->wf->wFormatTag;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1695 } else {
32113
e21b0baab10c Replace several sizeof(WAVEFORMATEX)
reimar
parents: 32112
diff changeset
1696 memset(sh_a->wf, 0, sizeof(*sh_a->wf));
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1697 if (!strcmp(track->codec_id, MKV_A_MP3)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1698 || !strcmp(track->codec_id, MKV_A_MP2))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1699 track->a_formattag = 0x0055;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1700 else if (!strncmp(track->codec_id, MKV_A_AC3, strlen(MKV_A_AC3)))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1701 track->a_formattag = 0x2000;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1702 else if (!strcmp(track->codec_id, MKV_A_DTS))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1703 track->a_formattag = 0x2001;
33011
e9a733c1e2a1 Support E-AC3 in deprecated native matroska demuxer.
cehoyos
parents: 32467
diff changeset
1704 else if (!strcmp(track->codec_id, MKV_A_EAC3))
e9a733c1e2a1 Support E-AC3 in deprecated native matroska demuxer.
cehoyos
parents: 32467
diff changeset
1705 track->a_formattag = mmioFOURCC('E', 'A', 'C', '3');
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1706 else if (!strcmp(track->codec_id, MKV_A_PCM)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1707 || !strcmp(track->codec_id, MKV_A_PCM_BE))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1708 track->a_formattag = 0x0001;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1709 else if (!strcmp(track->codec_id, MKV_A_AAC_2MAIN)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1710 || !strncmp(track->codec_id, MKV_A_AAC_2LC,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1711 strlen(MKV_A_AAC_2LC))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1712 || !strcmp(track->codec_id, MKV_A_AAC_2SSR)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1713 || !strcmp(track->codec_id, MKV_A_AAC_4MAIN)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1714 || !strncmp(track->codec_id, MKV_A_AAC_4LC,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1715 strlen(MKV_A_AAC_4LC))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1716 || !strcmp(track->codec_id, MKV_A_AAC_4SSR)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1717 || !strcmp(track->codec_id, MKV_A_AAC_4LTP)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1718 || !strcmp(track->codec_id, MKV_A_AAC))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1719 track->a_formattag = mmioFOURCC('M', 'P', '4', 'A');
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1720 else if (!strcmp(track->codec_id, MKV_A_VORBIS)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1721 if (track->private_data == NULL)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1722 return 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1723 track->a_formattag = mmioFOURCC('v', 'r', 'b', 's');
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1724 } else if (!strcmp(track->codec_id, MKV_A_QDMC))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1725 track->a_formattag = mmioFOURCC('Q', 'D', 'M', 'C');
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1726 else if (!strcmp(track->codec_id, MKV_A_QDMC2))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1727 track->a_formattag = mmioFOURCC('Q', 'D', 'M', '2');
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1728 else if (!strcmp(track->codec_id, MKV_A_WAVPACK))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1729 track->a_formattag = mmioFOURCC('W', 'V', 'P', 'K');
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1730 else if (!strcmp(track->codec_id, MKV_A_TRUEHD))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1731 track->a_formattag = mmioFOURCC('T', 'R', 'H', 'D');
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1732 else if (!strcmp(track->codec_id, MKV_A_FLAC)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1733 if (track->private_data == NULL || track->private_size == 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1734 mp_msg(MSGT_DEMUX, MSGL_WARN,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1735 MSGTR_MPDEMUX_MKV_FlacTrackDoesNotContainValidHeaders);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1736 return 1;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1737 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1738 track->a_formattag = mmioFOURCC('f', 'L', 'a', 'C');
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1739 } else if (track->private_size >= RAPROPERTIES4_SIZE) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1740 if (!strcmp(track->codec_id, MKV_A_REAL28))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1741 track->a_formattag = mmioFOURCC('2', '8', '_', '8');
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1742 else if (!strcmp(track->codec_id, MKV_A_REALATRC))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1743 track->a_formattag = mmioFOURCC('a', 't', 'r', 'c');
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1744 else if (!strcmp(track->codec_id, MKV_A_REALCOOK))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1745 track->a_formattag = mmioFOURCC('c', 'o', 'o', 'k');
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1746 else if (!strcmp(track->codec_id, MKV_A_REALDNET))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1747 track->a_formattag = mmioFOURCC('d', 'n', 'e', 't');
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1748 else if (!strcmp(track->codec_id, MKV_A_REALSIPR))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1749 track->a_formattag = mmioFOURCC('s', 'i', 'p', 'r');
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1750 } else {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1751 mp_msg(MSGT_DEMUX, MSGL_WARN, MSGTR_MPDEMUX_MKV_UnknownAudioCodec,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1752 track->codec_id, track->tnum);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1753 free_sh_audio(demuxer, track->tnum);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1754 return 1;
11807
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 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1757
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1758 sh_a->format = track->a_formattag;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1759 sh_a->wf->wFormatTag = track->a_formattag;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1760 sh_a->channels = track->a_channels;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1761 sh_a->wf->nChannels = track->a_channels;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1762 sh_a->samplerate = (uint32_t) track->a_sfreq;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1763 sh_a->wf->nSamplesPerSec = (uint32_t) track->a_sfreq;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1764 if (track->a_bps == 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1765 sh_a->samplesize = 2;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1766 sh_a->wf->wBitsPerSample = 16;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1767 } else {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1768 sh_a->samplesize = track->a_bps / 8;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1769 sh_a->wf->wBitsPerSample = track->a_bps;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1770 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1771 if (track->a_formattag == 0x0055) { /* MP3 || MP2 */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1772 sh_a->wf->nAvgBytesPerSec = 16000;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1773 sh_a->wf->nBlockAlign = 1152;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1774 } else if ((track->a_formattag == 0x2000) || /* AC3 */
33011
e9a733c1e2a1 Support E-AC3 in deprecated native matroska demuxer.
cehoyos
parents: 32467
diff changeset
1775 (track->a_formattag == mmioFOURCC('E', 'A', 'C', '3')) ||
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1776 (track->a_formattag == 0x2001)) { /* DTS */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1777 free(sh_a->wf);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1778 sh_a->wf = NULL;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1779 } else if (track->a_formattag == 0x0001) { /* PCM || PCM_BE */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1780 sh_a->wf->nAvgBytesPerSec = sh_a->channels * sh_a->samplerate * 2;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1781 sh_a->wf->nBlockAlign = sh_a->wf->nAvgBytesPerSec;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1782 if (!strcmp(track->codec_id, MKV_A_PCM_BE))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1783 sh_a->format = mmioFOURCC('t', 'w', 'o', 's');
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1784 } else if (!strcmp(track->codec_id, MKV_A_QDMC)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1785 || !strcmp(track->codec_id, MKV_A_QDMC2)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1786 sh_a->wf->nAvgBytesPerSec = 16000;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1787 sh_a->wf->nBlockAlign = 1486;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1788 track->fix_i_bps = 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1789 track->qt_last_a_pts = 0.0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1790 if (track->private_data != NULL) {
32220
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1791 if (track->private_size > INT_MAX) {
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1792 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] Integer overflow!\n");
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1793 free_sh_audio(demuxer, track->tnum);
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1794 return 1;
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1795 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1796 sh_a->codecdata = malloc(track->private_size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1797 memcpy(sh_a->codecdata, track->private_data, track->private_size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1798 sh_a->codecdata_len = track->private_size;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1799 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1800 } else if (track->a_formattag == mmioFOURCC('M', 'P', '4', 'A')) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1801 int profile, srate_idx;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1802
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1803 sh_a->wf->nAvgBytesPerSec = 16000;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1804 sh_a->wf->nBlockAlign = 1024;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1805
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1806 if (!strcmp(track->codec_id, MKV_A_AAC)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1807 && (NULL != track->private_data)) {
32220
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1808 if (track->private_size > INT_MAX) {
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1809 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] Integer overflow!\n");
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1810 free_sh_audio(demuxer, track->tnum);
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1811 return 1;
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1812 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1813 sh_a->codecdata = malloc(track->private_size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1814 memcpy(sh_a->codecdata, track->private_data, track->private_size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1815 sh_a->codecdata_len = track->private_size;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1816 return 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1817 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1818
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1819 /* Recreate the 'private data' */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1820 /* which faad2 uses in its initialization */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1821 srate_idx = aac_get_sample_rate_index(sh_a->samplerate);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1822 if (!strncmp(&track->codec_id[12], "MAIN", 4))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1823 profile = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1824 else if (!strncmp(&track->codec_id[12], "LC", 2))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1825 profile = 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1826 else if (!strncmp(&track->codec_id[12], "SSR", 3))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1827 profile = 2;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1828 else
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1829 profile = 3;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1830 sh_a->codecdata = malloc(5);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1831 sh_a->codecdata[0] = ((profile + 1) << 3) | ((srate_idx & 0xE) >> 1);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1832 sh_a->codecdata[1] =
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1833 ((srate_idx & 0x1) << 7) | (track->a_channels << 3);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1834
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1835 if (strstr(track->codec_id, "SBR") != NULL) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1836 /* HE-AAC (aka SBR AAC) */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1837 sh_a->codecdata_len = 5;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1838
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1839 sh_a->samplerate *= 2;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1840 sh_a->wf->nSamplesPerSec *= 2;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1841 srate_idx = aac_get_sample_rate_index(sh_a->samplerate);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1842 sh_a->codecdata[2] = AAC_SYNC_EXTENSION_TYPE >> 3;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1843 sh_a->codecdata[3] = ((AAC_SYNC_EXTENSION_TYPE & 0x07) << 5) | 5;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1844 sh_a->codecdata[4] = (1 << 7) | (srate_idx << 3);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1845 track->default_duration = 1024.0 / (sh_a->samplerate / 2);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1846 } else {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1847 sh_a->codecdata_len = 2;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1848 track->default_duration = 1024.0 / (float) sh_a->samplerate;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1849 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1850 } else if (track->a_formattag == mmioFOURCC('v', 'r', 'b', 's')) { /* VORBIS */
32220
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1851 if (track->private_size > USHRT_MAX) {
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1852 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] Integer overflow!\n");
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1853 free_sh_audio(demuxer, track->tnum);
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1854 return 1;
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1855 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1856 sh_a->wf->cbSize = track->private_size;
32113
e21b0baab10c Replace several sizeof(WAVEFORMATEX)
reimar
parents: 32112
diff changeset
1857 sh_a->wf = realloc(sh_a->wf, sizeof(*sh_a->wf) + sh_a->wf->cbSize);
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1858 memcpy((unsigned char *) (sh_a->wf + 1), track->private_data,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1859 sh_a->wf->cbSize);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1860 } else if (track->private_size >= RAPROPERTIES4_SIZE
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1861 && !strncmp(track->codec_id, MKV_A_REALATRC, 7)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1862 /* Common initialization for all RealAudio codecs */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1863 unsigned char *src = track->private_data;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1864 int codecdata_length, version;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1865 int flavor;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1866
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1867 sh_a->wf->nAvgBytesPerSec = 0; /* FIXME !? */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1868
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1869 version = AV_RB16(src + 4);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1870 flavor = AV_RB16(src + 22);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1871 track->coded_framesize = AV_RB32(src + 24);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1872 track->sub_packet_h = AV_RB16(src + 40);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1873 sh_a->wf->nBlockAlign = track->audiopk_size = AV_RB16(src + 42);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1874 track->sub_packet_size = AV_RB16(src + 44);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1875 if (version == 4) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1876 src += RAPROPERTIES4_SIZE;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1877 src += src[0] + 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1878 src += src[0] + 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1879 } else
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1880 src += RAPROPERTIES5_SIZE;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1881
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1882 src += 3;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1883 if (version == 5)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1884 src++;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1885 codecdata_length = AV_RB32(src);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1886 src += 4;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1887 sh_a->wf->cbSize = codecdata_length;
32113
e21b0baab10c Replace several sizeof(WAVEFORMATEX)
reimar
parents: 32112
diff changeset
1888 sh_a->wf = realloc(sh_a->wf, sizeof(*sh_a->wf) + sh_a->wf->cbSize);
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1889 memcpy(((char *) (sh_a->wf + 1)), src, codecdata_length);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1890
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1891 switch (track->a_formattag) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1892 case mmioFOURCC('a', 't', 'r', 'c'):
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1893 sh_a->wf->nAvgBytesPerSec = atrc_fl2bps[flavor];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1894 sh_a->wf->nBlockAlign = track->sub_packet_size;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1895 track->audio_buf =
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1896 malloc(track->sub_packet_h * track->audiopk_size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1897 track->audio_timestamp =
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1898 malloc(track->sub_packet_h * sizeof(float));
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1899 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1900 case mmioFOURCC('c', 'o', 'o', 'k'):
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1901 sh_a->wf->nAvgBytesPerSec = cook_fl2bps[flavor];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1902 sh_a->wf->nBlockAlign = track->sub_packet_size;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1903 track->audio_buf =
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1904 malloc(track->sub_packet_h * track->audiopk_size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1905 track->audio_timestamp =
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1906 malloc(track->sub_packet_h * sizeof(float));
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1907 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1908 case mmioFOURCC('s', 'i', 'p', 'r'):
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1909 sh_a->wf->nAvgBytesPerSec = sipr_fl2bps[flavor];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1910 sh_a->wf->nBlockAlign = track->coded_framesize;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1911 track->audio_buf =
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1912 malloc(track->sub_packet_h * track->audiopk_size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1913 track->audio_timestamp =
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1914 malloc(track->sub_packet_h * sizeof(float));
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1915 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1916 case mmioFOURCC('2', '8', '_', '8'):
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1917 sh_a->wf->nAvgBytesPerSec = 3600;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1918 sh_a->wf->nBlockAlign = track->coded_framesize;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1919 track->audio_buf =
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1920 malloc(track->sub_packet_h * track->audiopk_size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1921 track->audio_timestamp =
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1922 malloc(track->sub_packet_h * sizeof(float));
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1923 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1924 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1925
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1926 track->realmedia = 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1927 } else if (!strcmp(track->codec_id, MKV_A_FLAC)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1928 || (track->a_formattag == 0xf1ac)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1929 unsigned char *ptr;
32220
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1930 size_t size;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1931 free(sh_a->wf);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1932 sh_a->wf = NULL;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1933
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1934 if (track->a_formattag == mmioFOURCC('f', 'L', 'a', 'C')) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1935 ptr = track->private_data;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1936 size = track->private_size;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1937 } else {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1938 sh_a->format = mmioFOURCC('f', 'L', 'a', 'C');
32113
e21b0baab10c Replace several sizeof(WAVEFORMATEX)
reimar
parents: 32112
diff changeset
1939 ptr = (unsigned char *) track->private_data + sizeof(*sh_a->wf);
e21b0baab10c Replace several sizeof(WAVEFORMATEX)
reimar
parents: 32112
diff changeset
1940 size = track->private_size - sizeof(*sh_a->wf);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1941 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1942 if (size < 4 || ptr[0] != 'f' || ptr[1] != 'L' || ptr[2] != 'a'
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1943 || ptr[3] != 'C') {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1944 dp = new_demux_packet(4);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1945 memcpy(dp->buffer, "fLaC", 4);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1946 } else {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1947 dp = new_demux_packet(size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1948 memcpy(dp->buffer, ptr, size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1949 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1950 dp->pts = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1951 dp->flags = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1952 ds_add_packet(demuxer->audio, dp);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1953 } else if (track->a_formattag == mmioFOURCC('W', 'V', 'P', 'K') ||
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1954 track->a_formattag == mmioFOURCC('T', 'R', 'H', 'D')) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1955 /* do nothing, still works */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1956 } else if (!track->ms_compat
32113
e21b0baab10c Replace several sizeof(WAVEFORMATEX)
reimar
parents: 32112
diff changeset
1957 || (track->private_size < sizeof(*sh_a->wf))) {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1958 free_sh_audio(demuxer, track->tnum);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1959 return 1;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1960 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1961
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1962 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1963 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1964
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1965 static int demux_mkv_open_sub(demuxer_t *demuxer, mkv_track_t *track,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1966 int sid)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1967 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1968 if (track->subtitle_type != MATROSKA_SUBTYPE_UNKNOWN) {
32220
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1969 size_t size;
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1970 int m;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1971 uint8_t *buffer;
31609
cd81fce1f010 Make the stream language an argument to the stream creation function
reimar
parents: 31602
diff changeset
1972 sh_sub_t *sh = new_sh_sub_sid(demuxer, track->tnum, sid, track->language);
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1973 track->sh_sub = sh;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1974 sh->type = 't';
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1975 if (track->subtitle_type == MATROSKA_SUBTYPE_VOBSUB)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1976 sh->type = 'v';
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1977 if (track->subtitle_type == MATROSKA_SUBTYPE_SSA)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1978 sh->type = 'a';
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1979 size = track->private_size;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1980 m = demux_mkv_decode(track, track->private_data, &buffer, &size, 2);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1981 if (buffer && m) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1982 free(track->private_data);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1983 track->private_data = buffer;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1984 track->private_size = size;
25651
3d5fb36693ac Factorize private data decoding for subtitle tracks in mkv demuxer.
eugeni
parents: 25432
diff changeset
1985 }
32220
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1986 if (track->private_size > INT_MAX) {
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1987 mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] Integer overflow!\n");
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1988 return 1;
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
1989 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1990 sh->extradata = malloc(track->private_size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1991 memcpy(sh->extradata, track->private_data, track->private_size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1992 sh->extradata_len = track->private_size;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1993 sh->default_track = track->default_track;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1994 } else {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1995 mp_msg(MSGT_DEMUX, MSGL_ERR,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1996 MSGTR_MPDEMUX_MKV_SubtitleTypeNotSupported, track->codec_id);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1997 return 1;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
1998 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
1999
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2000 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2001 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2002
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2003 static int demux_mkv_open(demuxer_t *demuxer)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2004 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2005 stream_t *s = demuxer->stream;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2006 mkv_demuxer_t *mkv_d;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2007 mkv_track_t *track;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2008 int i, version, cont = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2009 char *str;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2010
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2011 stream_seek(s, s->start_pos);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2012 str = ebml_read_header(s, &version);
31263
6428a4b38763 Add webm/VP8 support to native matroska demuxer.
reimar
parents: 31210
diff changeset
2013 if (str == NULL || (strcmp(str, "matroska") && strcmp(str, "webm")) || version > 2) {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2014 mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] no head found\n");
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2015 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2016 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2017 free(str);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2018
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2019 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Found the head...\n");
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2020
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2021 if (ebml_read_id(s, NULL) != MATROSKA_ID_SEGMENT) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2022 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] but no segment :(\n");
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2023 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2024 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2025 ebml_read_length(s, NULL); /* return bytes number until EOF */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2026
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2027 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] + a segment...\n");
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2028
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2029 mkv_d = calloc(1, sizeof(mkv_demuxer_t));
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2030 demuxer->priv = mkv_d;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2031 mkv_d->tc_scale = 1000000;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2032 mkv_d->segment_start = stream_tell(s);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2033 mkv_d->parsed_cues = malloc(sizeof(off_t));
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2034 mkv_d->parsed_seekhead = malloc(sizeof(off_t));
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2035
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2036 while (!cont) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2037 switch (ebml_read_id(s, NULL)) {
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2038 case MATROSKA_ID_INFO:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2039 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] |+ segment information...\n");
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2040 cont = demux_mkv_read_info(demuxer);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2041 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2042
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2043 case MATROSKA_ID_TRACKS:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2044 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] |+ segment tracks...\n");
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2045 cont = demux_mkv_read_tracks(demuxer);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2046 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2047
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2048 case MATROSKA_ID_CUES:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2049 cont = demux_mkv_read_cues(demuxer);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2050 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2051
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2052 case MATROSKA_ID_TAGS:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2053 cont = demux_mkv_read_tags(demuxer);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2054 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2055
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2056 case MATROSKA_ID_SEEKHEAD:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2057 cont = demux_mkv_read_seekhead(demuxer);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2058 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2059
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2060 case MATROSKA_ID_CHAPTERS:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2061 cont = demux_mkv_read_chapters(demuxer);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2062 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2063
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents: 18934
diff changeset
2064 case MATROSKA_ID_ATTACHMENTS:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2065 cont = demux_mkv_read_attachments(demuxer);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2066 break;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents: 18934
diff changeset
2067
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2068 case MATROSKA_ID_CLUSTER:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2069 {
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2070 int p, l;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2071 mp_msg(MSGT_DEMUX, MSGL_V,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2072 "[mkv] |+ found cluster, headers are "
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2073 "parsed completely :)\n");
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2074 /* get the first cluster timecode */
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2075 p = stream_tell(s);
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2076 l = ebml_read_length(s, NULL);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2077 while (ebml_read_id(s, NULL) != MATROSKA_ID_CLUSTERTIMECODE) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2078 ebml_read_skip(s, NULL);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2079 if (stream_tell(s) >= p + l)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2080 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2081 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2082 if (stream_tell(s) < p + l) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2083 uint64_t num = ebml_read_uint(s, NULL);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2084 if (num == EBML_UINT_INVALID)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2085 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2086 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
2087 mkv_d->has_first_tc = 1;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2088 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2089 stream_seek(s, p - 4);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2090 cont = 1;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2091 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2092 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2093
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2094 default:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2095 cont = 1;
36641
598ef7d90b78 Document switch case fallthroughs.
reimar
parents: 36580
diff changeset
2096 /* Fallthrough to skip data */
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2097 case EBML_ID_VOID:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2098 ebml_read_skip(s, NULL);
18754
e0077bdf5ee5 feed any audio track present in the mux; switch to any of the available audio tracks
nicodvb
parents: 18708
diff changeset
2099 break;
e0077bdf5ee5 feed any audio track present in the mux; switch to any of the available audio tracks
nicodvb
parents: 18708
diff changeset
2100 }
e0077bdf5ee5 feed any audio track present in the mux; switch to any of the available audio tracks
nicodvb
parents: 18708
diff changeset
2101 }
e0077bdf5ee5 feed any audio track present in the mux; switch to any of the available audio tracks
nicodvb
parents: 18708
diff changeset
2102
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2103 display_create_tracks(demuxer);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2104
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2105 /* select video track */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2106 track = NULL;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2107 if (demuxer->video->id == -1) { /* automatically select a video track */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2108 /* search for a video track that has the 'default' flag set */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2109 for (i = 0; i < mkv_d->num_tracks; i++)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2110 if (mkv_d->tracks[i]->type == MATROSKA_TRACK_VIDEO
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2111 && mkv_d->tracks[i]->default_track) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2112 track = mkv_d->tracks[i];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2113 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2114 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2115
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2116 if (track == NULL)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2117 /* no track has the 'default' flag set */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2118 /* let's take the first video track */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2119 for (i = 0; i < mkv_d->num_tracks; i++)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2120 if (mkv_d->tracks[i]->type == MATROSKA_TRACK_VIDEO) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2121 track = mkv_d->tracks[i];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2122 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2123 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2124 } else if (demuxer->video->id != -2) /* -2 = no video at all */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2125 track = demux_mkv_find_track_by_num(mkv_d, demuxer->video->id,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2126 MATROSKA_TRACK_VIDEO);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2127
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2128 if (track && demuxer->v_streams[track->tnum]) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2129 mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_MPDEMUX_MKV_WillPlayVideoTrack,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2130 track->tnum);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2131 demuxer->video->id = track->tnum;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2132 demuxer->video->sh = demuxer->v_streams[track->tnum];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2133 } else {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2134 mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_MPDEMUX_MKV_NoVideoTrackFound);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2135 demuxer->video->id = -2;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2136 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2137
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2138 /* select audio track */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2139 track = NULL;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2140 if (track == NULL)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2141 /* search for an audio track that has the 'default' flag set */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2142 for (i = 0; i < mkv_d->num_tracks; i++)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2143 if (mkv_d->tracks[i]->type == MATROSKA_TRACK_AUDIO
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2144 && mkv_d->tracks[i]->default_track) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2145 track = mkv_d->tracks[i];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2146 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2147 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2148
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2149 if (track == NULL)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2150 /* no track has the 'default' flag set */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2151 /* let's take the first audio track */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2152 for (i = 0; i < mkv_d->num_tracks; i++)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2153 if (mkv_d->tracks[i]->type == MATROSKA_TRACK_AUDIO) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2154 track = mkv_d->tracks[i];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2155 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2156 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2157
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2158 if (track && demuxer->a_streams[track->tnum]) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2159 demuxer->audio->id = track->tnum;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2160 demuxer->audio->sh = demuxer->a_streams[track->tnum];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2161 } else {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2162 mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_MPDEMUX_MKV_NoAudioTrackFound);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2163 demuxer->audio->id = -2;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2164 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2165
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2166
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2167 if (demuxer->audio->id != -2)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2168 for (i = 0; i < mkv_d->num_tracks; i++) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2169 if (mkv_d->tracks[i]->type != MATROSKA_TRACK_AUDIO)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2170 continue;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2171 if (demuxer->a_streams[track->tnum]) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2172 mkv_d->last_aid++;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2173 if (mkv_d->last_aid == MAX_A_STREAMS)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2174 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2175 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2176 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2178 if (demuxer->chapters) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2179 for (i = 0; i < (int) demuxer->num_chapters; i++) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2180 demuxer->chapters[i].start -= mkv_d->first_tc;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2181 demuxer->chapters[i].end -= mkv_d->first_tc;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2182 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2183 if (dvd_last_chapter > 0 && dvd_last_chapter <= demuxer->num_chapters) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2184 if (demuxer->chapters[dvd_last_chapter - 1].end != 0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2185 mkv_d->stop_timecode =
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2186 demuxer->chapters[dvd_last_chapter - 1].end;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2187 else if (dvd_last_chapter + 1 <= demuxer->num_chapters)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2188 mkv_d->stop_timecode =
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2189 demuxer->chapters[dvd_last_chapter].start;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2190 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2191 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2192
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2193 if (s->end_pos == 0 || (mkv_d->indexes == NULL && index_mode < 0))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2194 demuxer->seekable = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2195 else {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2196 demuxer->movi_start = s->start_pos;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2197 demuxer->movi_end = s->end_pos;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2198 demuxer->seekable = 1;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2199 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2200
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2201 return DEMUXER_TYPE_MATROSKA;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2202 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2203
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2204 static void demux_close_mkv(demuxer_t *demuxer)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2205 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2206 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2207
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2208 if (mkv_d) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2209 int i;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2210 free_cached_dps(demuxer);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2211 if (mkv_d->tracks) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2212 for (i = 0; i < mkv_d->num_tracks; i++)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2213 demux_mkv_free_trackentry(mkv_d->tracks[i]);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2214 free(mkv_d->tracks);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2215 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2216 free(mkv_d->indexes);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2217 free(mkv_d->cluster_positions);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2218 free(mkv_d->parsed_cues);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2219 free(mkv_d->parsed_seekhead);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2220 free(mkv_d);
11807
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 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2223
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2224 static int demux_mkv_read_block_lacing(uint8_t *buffer, uint64_t *size,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2225 uint8_t *laces,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2226 uint32_t **all_lace_sizes)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2227 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2228 uint32_t total = 0, *lace_size;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2229 uint8_t flags;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2230 int i;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2231
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2232 *all_lace_sizes = NULL;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2233 lace_size = NULL;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2234 /* lacing flags */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2235 flags = *buffer++;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2236 (*size)--;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2237
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2238 switch ((flags & 0x06) >> 1) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2239 case 0: /* no lacing */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2240 *laces = 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2241 lace_size = calloc(*laces, sizeof(uint32_t));
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2242 lace_size[0] = *size;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2243 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2244
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2245 case 1: /* xiph lacing */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2246 case 2: /* fixed-size lacing */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2247 case 3: /* EBML lacing */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2248 *laces = *buffer++;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2249 (*size)--;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2250 (*laces)++;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2251 lace_size = calloc(*laces, sizeof(uint32_t));
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2252
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2253 switch ((flags & 0x06) >> 1) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2254 case 1: /* xiph lacing */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2255 for (i = 0; i < *laces - 1; i++) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2256 lace_size[i] = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2257 do {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2258 lace_size[i] += *buffer;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2259 (*size)--;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2260 } while (*buffer++ == 0xFF);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2261 total += lace_size[i];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2262 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2263 lace_size[i] = *size - total;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2264 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2265
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2266 case 2: /* fixed-size lacing */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2267 for (i = 0; i < *laces; i++)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2268 lace_size[i] = *size / *laces;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2269 break;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2270
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2271 case 3: /* EBML lacing */
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2272 {
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2273 int l;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2274 uint64_t num = ebml_read_vlen_uint(buffer, &l);
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2275 if (num == EBML_UINT_INVALID) {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2276 free(lace_size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2277 return 1;
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2278 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2279 buffer += l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2280 *size -= l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2281
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2282 total = lace_size[0] = num;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2283 for (i = 1; i < *laces - 1; i++) {
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2284 int64_t snum;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2285 snum = ebml_read_vlen_int(buffer, &l);
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2286 if (snum == EBML_INT_INVALID) {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2287 free(lace_size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2288 return 1;
12065
cabb28717cd6 Removed the limitation to max. eight laced blocks.
mosu
parents: 12041
diff changeset
2289 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2290 buffer += l;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2291 *size -= l;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2292 lace_size[i] = lace_size[i - 1] + snum;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2293 total += lace_size[i];
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2294 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2295 lace_size[i] = *size - total;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2296 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2297 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2298 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2299 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2300 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2301 *all_lace_sizes = lace_size;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2302 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2303 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2304
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2305 static void handle_subtitles(demuxer_t *demuxer, mkv_track_t *track,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2306 char *block, int64_t size,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2307 uint64_t block_duration, uint64_t timecode)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2308 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2309 demux_packet_t *dp;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2310
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2311 if (block_duration == 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2312 mp_msg(MSGT_DEMUX, MSGL_WARN,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2313 MSGTR_MPDEMUX_MKV_NoBlockDurationForSubtitleTrackFound);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2314 return;
11807
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
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2317 sub_utf8 = 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2318 dp = new_demux_packet(size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2319 memcpy(dp->buffer, block, size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2320 dp->pts = timecode / 1000.0f;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2321 dp->endpts = (timecode + block_duration) / 1000.0f;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2322 ds_add_packet(demuxer->sub, dp);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2323 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2324
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2325 static void handle_realvideo(demuxer_t *demuxer, mkv_track_t *track,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2326 uint8_t *buffer, uint32_t size, int block_bref)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2327 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2328 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2329 demux_packet_t *dp;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2330 uint32_t timestamp = mkv_d->last_pts * 1000;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2331
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2332 dp = new_demux_packet(size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2333 memcpy(dp->buffer, buffer, size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2334
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2335 if (mkv_d->v_skip_to_keyframe) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2336 dp->pts = mkv_d->last_pts;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2337 track->rv_kf_base = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2338 track->rv_kf_pts = timestamp;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2339 } else
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2340 dp->pts =
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2341 real_fix_timestamp(dp->buffer, timestamp,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2342 ((sh_video_t *) demuxer->video->sh)->bih->
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2343 biCompression, &track->rv_kf_base,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2344 &track->rv_kf_pts, NULL);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2345 dp->pos = demuxer->filepos;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2346 dp->flags = block_bref ? 0 : 0x10;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2347
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2348 ds_add_packet(demuxer->video, dp);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2349 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2350
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2351 static void handle_realaudio(demuxer_t *demuxer, mkv_track_t *track,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2352 uint8_t *buffer, uint32_t size, int block_bref)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2353 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2354 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2355 int sps = track->sub_packet_size;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2356 int sph = track->sub_packet_h;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2357 int cfs = track->coded_framesize;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2358 int w = track->audiopk_size;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2359 int spc = track->sub_packet_cnt;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2360 demux_packet_t *dp;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2361 int x;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2362
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2363 if ((track->a_formattag == mmioFOURCC('2', '8', '_', '8'))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2364 || (track->a_formattag == mmioFOURCC('c', 'o', 'o', 'k'))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2365 || (track->a_formattag == mmioFOURCC('a', 't', 'r', 'c'))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2366 || (track->a_formattag == mmioFOURCC('s', 'i', 'p', 'r'))) {
18036
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2367 // if(!block_bref)
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2368 // spc = track->sub_packet_cnt = 0;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2369 switch (track->a_formattag) {
18036
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2370 case mmioFOURCC('2', '8', '_', '8'):
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2371 for (x = 0; x < sph / 2; x++)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2372 memcpy(track->audio_buf + x * 2 * w + spc * cfs,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2373 buffer + cfs * x, cfs);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2374 break;
18036
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2375 case mmioFOURCC('c', 'o', 'o', 'k'):
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2376 case mmioFOURCC('a', 't', 'r', 'c'):
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2377 for (x = 0; x < w / sps; x++)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2378 memcpy(track->audio_buf +
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2379 sps * (sph * x + ((sph + 1) / 2) * (spc & 1) +
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2380 (spc >> 1)), buffer + sps * x, sps);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2381 break;
18036
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2382 case mmioFOURCC('s', 'i', 'p', 'r'):
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2383 memcpy(track->audio_buf + spc * w, buffer, w);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2384 if (spc == sph - 1) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2385 int n;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2386 int bs = sph * w * 2 / 96; // nibbles per subpacket
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2387 // Perform reordering
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2388 for (n = 0; n < 38; n++) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2389 int j;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2390 int i = bs * sipr_swaps[n][0];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2391 int o = bs * sipr_swaps[n][1];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2392 // swap nibbles of block 'i' with 'o' TODO: optimize
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2393 for (j = 0; j < bs; j++) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2394 int x = (i & 1) ?
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2395 (track->audio_buf[i >> 1] >> 4) :
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2396 (track->audio_buf[i >> 1] & 0x0F);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2397 int y = (o & 1) ?
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2398 (track->audio_buf[o >> 1] >> 4) :
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2399 (track->audio_buf[o >> 1] & 0x0F);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2400 if (o & 1)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2401 track->audio_buf[o >> 1] =
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2402 (track->audio_buf[o >> 1] & 0x0F) | (x << 4);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2403 else
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2404 track->audio_buf[o >> 1] =
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2405 (track->audio_buf[o >> 1] & 0xF0) | x;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2406 if (i & 1)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2407 track->audio_buf[i >> 1] =
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2408 (track->audio_buf[i >> 1] & 0x0F) | (y << 4);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2409 else
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2410 track->audio_buf[i >> 1] =
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2411 (track->audio_buf[i >> 1] & 0xF0) | y;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2412 ++i;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2413 ++o;
18036
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2414 }
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2415 }
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2416 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2417 break;
18036
3406a28698cf Fix RealAudio codecs (add descrambling)
rtognimp
parents: 17923
diff changeset
2418 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2419 track->audio_timestamp[track->sub_packet_cnt] =
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2420 (track->ra_pts == mkv_d->last_pts) ? 0 : (mkv_d->last_pts);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2421 track->ra_pts = mkv_d->last_pts;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2422 if (track->sub_packet_cnt == 0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2423 track->audio_filepos = demuxer->filepos;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2424 if (++(track->sub_packet_cnt) == sph) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2425 int apk_usize =
32112
741bcef4ad3a Remove a useless cast.
reimar
parents: 32111
diff changeset
2426 ((sh_audio_t *) demuxer->audio->sh)->wf->nBlockAlign;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2427 track->sub_packet_cnt = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2428 // Release all the audio packets
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2429 for (x = 0; x < sph * w / apk_usize; x++) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2430 dp = new_demux_packet(apk_usize);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2431 memcpy(dp->buffer, track->audio_buf + x * apk_usize,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2432 apk_usize);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2433 /* Put timestamp only on packets that correspond to original
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2434 * audio packets in file */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2435 dp->pts = (x * apk_usize % w) ? 0 :
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2436 track->audio_timestamp[x * apk_usize / w];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2437 dp->pos = track->audio_filepos; // all equal
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2438 dp->flags = x ? 0 : 0x10; // Mark first packet as keyframe
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2439 ds_add_packet(demuxer->audio, dp);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2440 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2441 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2442 } else { // Not a codec that require reordering
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2443 dp = new_demux_packet(size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2444 memcpy(dp->buffer, buffer, size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2445 if (track->ra_pts == mkv_d->last_pts && !mkv_d->a_skip_to_keyframe)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2446 dp->pts = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2447 else
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2448 dp->pts = mkv_d->last_pts;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2449 track->ra_pts = mkv_d->last_pts;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2450
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2451 dp->pos = demuxer->filepos;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2452 dp->flags = block_bref ? 0 : 0x10;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2453 ds_add_packet(demuxer->audio, dp);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2454 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2455 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2456
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2457 /** 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
2458 *
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2459 * 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
2460 * 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
2461 * 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
2462 * 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
2463 * 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
2464 *
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2465 * 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
2466 * 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
2467 * 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
2468 * B at 80ms and B at 120ms.
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2469 *
16912
4dea8b8f3b65 sort timestamps instead of assuming conventional B-frame order. (fixes x264 B-pyramid)
lorenm
parents: 16877
diff changeset
2470 * 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
2471 *
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2472 * \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
2473 * \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
2474 */
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2475 static void flush_cached_dps(demuxer_t *demuxer, mkv_track_t *track)
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2476 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2477 int i, ok;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2478
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2479 if (track->num_cached_dps == 0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2480 return;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2481
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2482 do {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2483 ok = 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2484 for (i = 1; i < track->num_cached_dps; i++)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2485 if (track->cached_dps[i - 1]->pts > track->cached_dps[i]->pts) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2486 float tmp_pts = track->cached_dps[i - 1]->pts;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2487 track->cached_dps[i - 1]->pts = track->cached_dps[i]->pts;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2488 track->cached_dps[i]->pts = tmp_pts;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2489 ok = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2490 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2491 } while (!ok);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2492
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2493 for (i = 0; i < track->num_cached_dps; i++)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2494 ds_add_packet(demuxer->video, track->cached_dps[i]);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2495 track->num_cached_dps = 0;
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2496 }
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2497
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2498 /** 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
2499 *
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2500 * 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
2501 * 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
2502 * 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
2503 * 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
2504 * 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
2505 * 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
2506 * 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
2507 *
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2508 * \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
2509 * \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
2510 * \param buffer The actual frame contents.
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2511 * \param size The frame size in bytes.
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2512 * \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
2513 * then the frame is an I frame.
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2514 * \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
2515 * 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
2516 * 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
2517 */
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2518 static void handle_video_bframes(demuxer_t *demuxer, mkv_track_t *track,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2519 uint8_t *buffer, uint32_t size,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2520 int block_bref, int block_fref)
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2521 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2522 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2523 demux_packet_t *dp;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2524
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2525 dp = new_demux_packet(size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2526 memcpy(dp->buffer, buffer, size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2527 dp->pos = demuxer->filepos;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2528 dp->pts = mkv_d->last_pts;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2529 if ((track->num_cached_dps > 0) && (dp->pts < track->max_pts))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2530 block_fref = 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2531 if (block_fref == 0) /* I or P frame */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2532 flush_cached_dps(demuxer, track);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2533 if (block_bref != 0) /* I frame, don't cache it */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2534 dp->flags = 0x10;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2535 if ((track->num_cached_dps + 1) > track->num_allocated_dps) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2536 track->cached_dps = (demux_packet_t **)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2537 realloc(track->cached_dps,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2538 (track->num_cached_dps + 10) * sizeof(demux_packet_t *));
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2539 track->num_allocated_dps += 10;
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2540 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2541 track->cached_dps[track->num_cached_dps] = dp;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2542 track->num_cached_dps++;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2543 if (dp->pts > track->max_pts)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2544 track->max_pts = dp->pts;
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2545 }
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2546
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2547 static int handle_block(demuxer_t *demuxer, uint8_t *block, uint64_t length,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2548 uint64_t block_duration, int64_t block_bref,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2549 int64_t block_fref, uint8_t simpleblock)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2550 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2551 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2552 mkv_track_t *track = NULL;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2553 demux_stream_t *ds = NULL;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2554 uint64_t old_length;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2555 int64_t tc;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2556 uint32_t *lace_size;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2557 uint8_t laces, flags;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2558 int i, num, tmp, use_this_block = 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2559 float current_pts;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2560 int16_t time;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2561
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2562 /* first byte(s): track num */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2563 num = ebml_read_vlen_uint(block, &tmp);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2564 block += tmp;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2565 /* time (relative to cluster time) */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2566 time = block[0] << 8 | block[1];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2567 block += 2;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2568 length -= tmp + 2;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2569 old_length = length;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2570 flags = block[0];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2571 if (demux_mkv_read_block_lacing(block, &length, &laces, &lace_size))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2572 return 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2573 block += old_length - length;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2574
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2575 tc = ((time * mkv_d->tc_scale + mkv_d->cluster_tc) / 1000000.0 -
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2576 mkv_d->first_tc);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2577 if (tc < 0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2578 tc = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2579 if (mkv_d->stop_timecode > 0 && tc > mkv_d->stop_timecode) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2580 free(lace_size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2581 return -1;
12721
44895a7161c8 Do not dereference NULL if no track could be found for a block.
mosu
parents: 12550
diff changeset
2582 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2583 current_pts = tc / 1000.0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2584
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2585 for (i = 0; i < mkv_d->num_tracks; i++)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2586 if (mkv_d->tracks[i]->tnum == num) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2587 track = mkv_d->tracks[i];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2588 break;
19977
8ada6970000a Add matroska v2 (SimpleBlock) support.
eugeni
parents: 19812
diff changeset
2589 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2590 if (track == NULL) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2591 free(lace_size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2592 return 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2593 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2594 if (num == demuxer->audio->id) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2595 ds = demuxer->audio;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2596
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2597 if (mkv_d->a_skip_to_keyframe) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2598 if (simpleblock) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2599 if (!(flags & 0x80)) /*current frame isn't a keyframe */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2600 use_this_block = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2601 } else if (block_bref != 0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2602 use_this_block = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2603 } else if (mkv_d->v_skip_to_keyframe)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2604 use_this_block = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2605
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2606 if (track->fix_i_bps && use_this_block) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2607 sh_audio_t *sh = (sh_audio_t *) ds->sh;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2608
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2609 if (block_duration != 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2610 sh->i_bps = length * 1000 / block_duration;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2611 track->fix_i_bps = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2612 } else if (track->qt_last_a_pts == 0.0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2613 track->qt_last_a_pts = current_pts;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2614 else if (track->qt_last_a_pts != current_pts) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2615 sh->i_bps = length / (current_pts - track->qt_last_a_pts);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2616 track->fix_i_bps = 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2617 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2618 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2619 } else if (tc < mkv_d->skip_to_timecode)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2620 use_this_block = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2621 else if (num == demuxer->video->id) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2622 ds = demuxer->video;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2623 if (mkv_d->v_skip_to_keyframe) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2624 if (simpleblock) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2625 if (!(flags & 0x80)) /*current frame isn't a keyframe */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2626 use_this_block = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2627 } else if (block_bref != 0 || block_fref != 0)
19977
8ada6970000a Add matroska v2 (SimpleBlock) support.
eugeni
parents: 19812
diff changeset
2628 use_this_block = 0;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2629 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2630 } else if (num == demuxer->sub->id) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2631 ds = demuxer->sub;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2632 if (track->subtitle_type != MATROSKA_SUBTYPE_VOBSUB) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2633 if (!mkv_d->v_skip_to_keyframe)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2634 handle_subtitles(demuxer, track, block, length, block_duration,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2635 tc);
19977
8ada6970000a Add matroska v2 (SimpleBlock) support.
eugeni
parents: 19812
diff changeset
2636 use_this_block = 0;
8ada6970000a Add matroska v2 (SimpleBlock) support.
eugeni
parents: 19812
diff changeset
2637 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2638 } else
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2639 use_this_block = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2640
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2641 if (use_this_block) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2642 mkv_d->last_pts = current_pts;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2643 mkv_d->last_filepos = demuxer->filepos;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2644
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2645 for (i = 0; i < laces; i++) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2646 if (ds == demuxer->video && track->realmedia)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2647 handle_realvideo(demuxer, track, block, lace_size[i],
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2648 block_bref);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2649 else if (ds == demuxer->audio && track->realmedia)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2650 handle_realaudio(demuxer, track, block, lace_size[i],
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2651 block_bref);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2652 else if (ds == demuxer->video && track->reorder_timecodes)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2653 handle_video_bframes(demuxer, track, block, lace_size[i],
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2654 block_bref, block_fref);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2655 else {
32220
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
2656 int modified;
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
2657 size_t size = lace_size[i];
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2658 demux_packet_t *dp;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2659 uint8_t *buffer;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2660 modified = demux_mkv_decode(track, block, &buffer, &size, 1);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2661 if (buffer) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2662 dp = new_demux_packet(size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2663 memcpy(dp->buffer, buffer, size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2664 if (modified)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2665 free(buffer);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2666 dp->flags = (block_bref == 0
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2667 && block_fref == 0) ? 0x10 : 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2668 /* If default_duration is 0, assume no pts value is known
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2669 * for packets after the first one (rather than all pts
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2670 * values being the same) */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2671 if (i == 0 || track->default_duration)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2672 dp->pts =
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2673 mkv_d->last_pts + i * track->default_duration;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2674 ds_add_packet(ds, dp);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2675 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2676 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2677 block += lace_size[i];
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2678 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2679
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2680 if (ds == demuxer->video) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2681 mkv_d->v_skip_to_keyframe = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2682 mkv_d->skip_to_timecode = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2683 } else if (ds == demuxer->audio)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2684 mkv_d->a_skip_to_keyframe = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2685
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2686 free(lace_size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2687 return 1;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2688 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2689
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2690 free(lace_size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2691 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2692 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2693
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2694 static int 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
2695 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2696 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2697 stream_t *s = demuxer->stream;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2698 uint64_t l;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2699 int il, tmp;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2700
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2701 while (1) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2702 while (mkv_d->cluster_size > 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2703 uint64_t block_duration = 0, block_length = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2704 int64_t block_bref = 0, block_fref = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2705 uint8_t *block = NULL;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2706
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2707 while (mkv_d->blockgroup_size > 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2708 switch (ebml_read_id(s, &il)) {
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2709 case MATROSKA_ID_BLOCKDURATION:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2710 block_duration = ebml_read_uint(s, &l);
23704
ce80673fbf0d Add some missing frees.
reimar
parents: 23703
diff changeset
2711 if (block_duration == EBML_UINT_INVALID) {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2712 free(block);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2713 return 0;
23704
ce80673fbf0d Add some missing frees.
reimar
parents: 23703
diff changeset
2714 }
19810
7dfc3d2bb54b Fix block duration calculation in mkv demuxer.
eugeni
parents: 19809
diff changeset
2715 block_duration *= mkv_d->tc_scale / 1000000.0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2716 break;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2717
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2718 case MATROSKA_ID_BLOCK:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2719 block_length = ebml_read_length(s, &tmp);
20155
c903e0d80f02 More possible memleaks.
reimar
parents: 20154
diff changeset
2720 free(block);
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2721 if (block_length > SIZE_MAX - AV_LZO_INPUT_PADDING)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2722 return 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2723 block = malloc(block_length + AV_LZO_INPUT_PADDING);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2724 demuxer->filepos = stream_tell(s);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2725 if (stream_read(s, block, block_length) !=
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2726 (int) block_length) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2727 free(block);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2728 return 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2729 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2730 l = tmp + block_length;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2731 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2732
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2733 case MATROSKA_ID_REFERENCEBLOCK:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2734 {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2735 int64_t num = ebml_read_int(s, &l);
23704
ce80673fbf0d Add some missing frees.
reimar
parents: 23703
diff changeset
2736 if (num == EBML_INT_INVALID) {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2737 free(block);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2738 return 0;
23704
ce80673fbf0d Add some missing frees.
reimar
parents: 23703
diff changeset
2739 }
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2740 if (num <= 0)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2741 block_bref = num;
14054
53ea955d19fa Added support for MPEG-1 and MPEG-2 in Matroska.
mosu
parents: 14046
diff changeset
2742 else
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2743 block_fref = num;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2744 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2745 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2746
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
2747 case EBML_ID_INVALID:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2748 free(block);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2749 return 0;
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
2750
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2751 default:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2752 ebml_read_skip(s, &l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2753 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2754 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2755 mkv_d->blockgroup_size -= l + il;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2756 mkv_d->cluster_size -= l + il;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2757 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2758
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2759 if (block) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2760 int res = handle_block(demuxer, block, block_length,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2761 block_duration, block_bref, block_fref,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2762 0);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2763 free(block);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2764 if (res < 0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2765 return 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2766 if (res)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2767 return 1;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2768 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2769
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2770 if (mkv_d->cluster_size > 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2771 switch (ebml_read_id(s, &il)) {
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2772 case MATROSKA_ID_CLUSTERTIMECODE:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2773 {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2774 uint64_t num = ebml_read_uint(s, &l);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2775 if (num == EBML_UINT_INVALID)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2776 return 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2777 if (!mkv_d->has_first_tc) {
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2778 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
2779 mkv_d->has_first_tc = 1;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2780 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2781 mkv_d->cluster_tc = num * mkv_d->tc_scale;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2782 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2783 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2784
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2785 case MATROSKA_ID_BLOCKGROUP:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2786 mkv_d->blockgroup_size = ebml_read_length(s, &tmp);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2787 l = tmp;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2788 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2789
19977
8ada6970000a Add matroska v2 (SimpleBlock) support.
eugeni
parents: 19812
diff changeset
2790 case MATROSKA_ID_SIMPLEBLOCK:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2791 {
19977
8ada6970000a Add matroska v2 (SimpleBlock) support.
eugeni
parents: 19812
diff changeset
2792 int res;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2793 block_length = ebml_read_length(s, &tmp);
32220
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
2794 if (block_length > SIZE_MAX)
2494181f252b Add many integer overflow checks to mkv demuxer.
reimar
parents: 32209
diff changeset
2795 return 0;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2796 block = malloc(block_length);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2797 demuxer->filepos = stream_tell(s);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2798 if (stream_read(s, block, block_length) !=
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2799 (int) block_length) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2800 free(block);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2801 return 0;
20155
c903e0d80f02 More possible memleaks.
reimar
parents: 20154
diff changeset
2802 }
19977
8ada6970000a Add matroska v2 (SimpleBlock) support.
eugeni
parents: 19812
diff changeset
2803 l = tmp + block_length;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2804 res = handle_block(demuxer, block, block_length,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2805 block_duration, block_bref,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2806 block_fref, 1);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2807 free(block);
19977
8ada6970000a Add matroska v2 (SimpleBlock) support.
eugeni
parents: 19812
diff changeset
2808 mkv_d->cluster_size -= l + il;
8ada6970000a Add matroska v2 (SimpleBlock) support.
eugeni
parents: 19812
diff changeset
2809 if (res < 0)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2810 return 0;
19977
8ada6970000a Add matroska v2 (SimpleBlock) support.
eugeni
parents: 19812
diff changeset
2811 else if (res)
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2812 return 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2813 else
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2814 mkv_d->cluster_size += l + il;
19977
8ada6970000a Add matroska v2 (SimpleBlock) support.
eugeni
parents: 19812
diff changeset
2815 break;
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2816 }
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
2817 case EBML_ID_INVALID:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2818 return 0;
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
2819
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2820 default:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2821 ebml_read_skip(s, &l);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2822 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2823 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2824 mkv_d->cluster_size -= l + il;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2825 }
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
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2828 if (ebml_read_id(s, &il) != MATROSKA_ID_CLUSTER)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2829 return 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2830 add_cluster_position(mkv_d, stream_tell(s) - il);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2831 mkv_d->cluster_size = ebml_read_length(s, NULL);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2832 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2833
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2834 return 0;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2835 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2836
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2837 static void demux_mkv_seek(demuxer_t *demuxer, float rel_seek_secs,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2838 float audio_delay, int flags)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2839 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2840 free_cached_dps(demuxer);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2841 if (!(flags & SEEK_FACTOR)) { /* time in secs */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2842 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2843 stream_t *s = demuxer->stream;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2844 int64_t target_timecode = 0, diff, min_diff = 0xFFFFFFFFFFFFFFFLL;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2845 int i;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2846
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2847 if (!(flags & SEEK_ABSOLUTE)) /* relative seek */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2848 target_timecode = (int64_t) (mkv_d->last_pts * 1000.0);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2849 target_timecode += (int64_t) (rel_seek_secs * 1000.0);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2850 if (target_timecode < 0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2851 target_timecode = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2852
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2853 if (mkv_d->indexes == NULL) { /* no index was found */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2854 uint64_t target_filepos, cluster_pos, max_pos;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2855
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2856 target_filepos =
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2857 (uint64_t) (target_timecode * mkv_d->last_filepos /
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2858 (mkv_d->last_pts * 1000.0));
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2859
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2860 max_pos = mkv_d->num_cluster_pos ?
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2861 mkv_d->cluster_positions[mkv_d->num_cluster_pos - 1] : 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2862 if (target_filepos > max_pos) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2863 if ((off_t) max_pos > stream_tell(s))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2864 stream_seek(s, max_pos);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2865 else
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2866 stream_seek(s, stream_tell(s) + mkv_d->cluster_size);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2867 /* parse all the clusters upto target_filepos */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2868 while (!s->eof && stream_tell(s) < (off_t) target_filepos) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2869 switch (ebml_read_id(s, &i)) {
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2870 case MATROSKA_ID_CLUSTER:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2871 add_cluster_position(mkv_d,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2872 (uint64_t) stream_tell(s) - i);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2873 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2874
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2875 case MATROSKA_ID_CUES:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2876 demux_mkv_read_cues(demuxer);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2877 break;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2878 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2879 ebml_read_skip(s, NULL);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2880 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2881 if (s->eof)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2882 stream_reset(s);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2883 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2884
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2885 if (mkv_d->indexes == NULL) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2886 cluster_pos = mkv_d->cluster_positions[0];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2887 /* Let's find the nearest cluster */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2888 for (i = 0; i < mkv_d->num_cluster_pos; i++) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2889 diff = mkv_d->cluster_positions[i] - target_filepos;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2890 if (rel_seek_secs < 0 && diff < 0 && -diff < min_diff) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2891 cluster_pos = mkv_d->cluster_positions[i];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2892 min_diff = -diff;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2893 } else if (rel_seek_secs > 0
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2894 && (diff < 0 ? -1 * diff : diff) < min_diff) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2895 cluster_pos = mkv_d->cluster_positions[i];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2896 min_diff = diff < 0 ? -1 * diff : diff;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2897 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2898 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2899 mkv_d->cluster_size = mkv_d->blockgroup_size = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2900 stream_seek(s, cluster_pos);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2901 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2902 } else {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2903 mkv_index_t *index = NULL;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2904 int seek_id = (demuxer->video->id < 0) ?
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2905 demuxer->audio->id : demuxer->video->id;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2906
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2907 /* let's find the entry in the indexes with the smallest */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2908 /* difference to the wanted timecode. */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2909 for (i = 0; i < mkv_d->num_indexes; i++)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2910 if (mkv_d->indexes[i].tnum == seek_id) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2911 diff =
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2912 target_timecode + mkv_d->first_tc -
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2913 (int64_t) mkv_d->indexes[i].timecode *
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2914 mkv_d->tc_scale / 1000000.0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2915
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2916 if ((flags & SEEK_ABSOLUTE
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2917 || target_timecode <= mkv_d->last_pts * 1000)) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2918 // Absolute seek or seek backward: find the last index
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2919 // position before target time
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2920 if (diff < 0 || diff >= min_diff)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2921 continue;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2922 } else {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2923 // Relative seek forward: find the first index position
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2924 // after target time. If no such index exists, find last
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2925 // position between current position and target time.
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2926 if (diff <= 0) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2927 if (min_diff <= 0 && diff <= min_diff)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2928 continue;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2929 } else if (diff >=
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2930 FFMIN(target_timecode - mkv_d->last_pts,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2931 min_diff))
22616
09dc129234a0 Matroska seeking fixes
uau
parents: 22606
diff changeset
2932 continue;
09dc129234a0 Matroska seeking fixes
uau
parents: 22606
diff changeset
2933 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2934 min_diff = diff;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2935 index = mkv_d->indexes + i;
22616
09dc129234a0 Matroska seeking fixes
uau
parents: 22606
diff changeset
2936 }
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2937
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2938 if (index) { /* We've found an entry. */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2939 mkv_d->cluster_size = mkv_d->blockgroup_size = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2940 stream_seek(s, index->filepos);
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2941 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2942 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2943
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2944 if (demuxer->video->id >= 0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2945 mkv_d->v_skip_to_keyframe = 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2946 if (rel_seek_secs > 0.0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2947 mkv_d->skip_to_timecode = target_timecode;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2948 mkv_d->a_skip_to_keyframe = 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2949
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2950 demux_mkv_fill_buffer(demuxer, NULL);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2951 } else if ((demuxer->movi_end <= 0) || !(flags & SEEK_ABSOLUTE))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2952 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] seek unsupported flags\n");
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2953 else {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2954 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2955 stream_t *s = demuxer->stream;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2956 uint64_t target_filepos;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2957 mkv_index_t *index = NULL;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2958 int i;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2959
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2960 if (mkv_d->indexes == NULL) { /* no index was found *//* I'm lazy... */
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2961 mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] seek unsupported flags\n");
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2962 return;
12073
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
2963 }
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
2964
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2965 target_filepos = (uint64_t) (demuxer->movi_end * rel_seek_secs);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2966 for (i = 0; i < mkv_d->num_indexes; i++)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2967 if (mkv_d->indexes[i].tnum == demuxer->video->id)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2968 if ((index == NULL)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2969 || ((mkv_d->indexes[i].filepos >= target_filepos)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2970 && ((index->filepos < target_filepos)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2971 || (mkv_d->indexes[i].filepos < index->filepos))))
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2972 index = &mkv_d->indexes[i];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2973
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2974 if (!index)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2975 return;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2976
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2977 mkv_d->cluster_size = mkv_d->blockgroup_size = 0;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2978 stream_seek(s, index->filepos);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2979
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2980 if (demuxer->video->id >= 0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2981 mkv_d->v_skip_to_keyframe = 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2982 mkv_d->skip_to_timecode = index->timecode;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2983 mkv_d->a_skip_to_keyframe = 1;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2984
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2985 demux_mkv_fill_buffer(demuxer, NULL);
12073
0ef56fc11e4e Implemented "seek to position".
mosu
parents: 12065
diff changeset
2986 }
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2987 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2988
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2989 static int demux_mkv_control(demuxer_t *demuxer, int cmd, void *arg)
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2990 {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2991 mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2992
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2993 switch (cmd) {
25919
382672c7480a Allow demuxers to choose a default value for correct_pts
reimar
parents: 25883
diff changeset
2994 case DEMUXER_CTRL_CORRECT_PTS:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2995 return DEMUXER_CTRL_OK;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
2996 case DEMUXER_CTRL_GET_TIME_LENGTH:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2997 if (mkv_d->duration == 0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2998 return DEMUXER_CTRL_DONTKNOW;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
2999
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3000 *((double *) arg) = (double) mkv_d->duration;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3001 return DEMUXER_CTRL_OK;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3002
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3003 case DEMUXER_CTRL_GET_PERCENT_POS:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3004 if (mkv_d->duration == 0) {
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3005 return DEMUXER_CTRL_DONTKNOW;
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3006 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3007
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3008 *((int *) arg) = (int) (100 * mkv_d->last_pts / mkv_d->duration);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3009 return DEMUXER_CTRL_OK;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3010
15154
898f68adad2b Online audio switching now supports Matroska too. Patch by Michael Behrisch
gpoirier
parents: 14843
diff changeset
3011 case DEMUXER_CTRL_SWITCH_AUDIO:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3012 if (demuxer->audio && demuxer->audio->sh) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3013 sh_audio_t *sh = demuxer->a_streams[demuxer->audio->id];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3014 int aid = *(int *) arg;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3015 if (aid < 0)
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3016 aid = (sh->aid + 1) % mkv_d->last_aid;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3017 if (aid != sh->aid) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3018 mkv_track_t *track =
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3019 demux_mkv_find_track_by_num(mkv_d, aid,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3020 MATROSKA_TRACK_AUDIO);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3021 if (track) {
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3022 demuxer->audio->id = track->tnum;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3023 sh = demuxer->a_streams[demuxer->audio->id];
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3024 ds_free_packs(demuxer->audio);
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3025 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3026 }
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3027 *(int *) arg = sh->aid;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3028 } else
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3029 *(int *) arg = -2;
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3030 return DEMUXER_CTRL_OK;
15154
898f68adad2b Online audio switching now supports Matroska too. Patch by Michael Behrisch
gpoirier
parents: 14843
diff changeset
3031
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3032 default:
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3033 return DEMUXER_CTRL_NOTIMPL;
11807
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3034 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3035 }
9a81d7b4c0b6 Added the new C based Matroska demuxer by Aurelien Jacobs.
mosu
parents:
diff changeset
3036
25707
d4fe6e23283e Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents: 25658
diff changeset
3037 const demuxer_desc_t demuxer_desc_matroska = {
31177
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3038 "Matroska demuxer",
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3039 "mkv",
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3040 "Matroska",
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3041 "Aurelien Jacobs",
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3042 "",
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3043 DEMUXER_TYPE_MATROSKA,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3044 1, // safe autodetect
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3045 demux_mkv_open,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3046 demux_mkv_fill_buffer,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3047 NULL,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3048 demux_close_mkv,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3049 demux_mkv_seek,
9175a9a22051 cosmetics: Reformat in K&R coding style.
diego
parents: 31176
diff changeset
3050 demux_mkv_control
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 15701
diff changeset
3051 };