annotate libmpdemux/demux_mkv.c @ 30571:7031b2cf61ca

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