annotate matroska.c @ 1912:98a74cfd12d4 libavformat

scale duration and default_duration
author aurel
date Tue, 13 Mar 2007 00:01:24 +0000
parents 2ce053f3d996
children 1c1df2f4090b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2 * Matroska file demuxer (no muxer yet)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3 * Copyright (c) 2003-2004 The ffmpeg Project
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1332
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1332
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1332
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1332
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1332
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
15 * Lesser General Public License for more details.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
16 *
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1332
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 887
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
20 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
21
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
22 /**
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
23 * @file matroska.c
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
24 * Matroska file demuxer
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
25 * by Ronald Bultje <rbultje@ronald.bitfreak.net>
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
26 * with a little help from Moritz Bunkus <moritz@bunkus.org>
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
27 * Specs available on the matroska project page:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
28 * http://www.matroska.org/.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
29 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
30
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
31 #include "avformat.h"
1897
abbc781d608a use codec_get_id() instead of deprecated codec_get_[bmp/wav]_id()
aurel
parents: 1832
diff changeset
32 /* For codec_get_id(). */
1172
6a5e58d2114b move common stuff from avienc.c and wav.c to new file riff.c
mru
parents: 1169
diff changeset
33 #include "riff.h"
920
12bc7d91ee8b add missing #includes
mru
parents: 896
diff changeset
34 #include "intfloat_readwrite.h"
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
35
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
36 /* EBML version supported */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
37 #define EBML_VERSION 1
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
38
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
39 /* top-level master-IDs */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
40 #define EBML_ID_HEADER 0x1A45DFA3
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
41
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
42 /* IDs in the HEADER master */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
43 #define EBML_ID_EBMLVERSION 0x4286
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
44 #define EBML_ID_EBMLREADVERSION 0x42F7
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
45 #define EBML_ID_EBMLMAXIDLENGTH 0x42F2
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
46 #define EBML_ID_EBMLMAXSIZELENGTH 0x42F3
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
47 #define EBML_ID_DOCTYPE 0x4282
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
48 #define EBML_ID_DOCTYPEVERSION 0x4287
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
49 #define EBML_ID_DOCTYPEREADVERSION 0x4285
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
50
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
51 /* general EBML types */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
52 #define EBML_ID_VOID 0xEC
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
53
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
54 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
55 * Matroska element IDs. max. 32-bit.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
56 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
57
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
58 /* toplevel segment */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
59 #define MATROSKA_ID_SEGMENT 0x18538067
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
60
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
61 /* matroska top-level master IDs */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
62 #define MATROSKA_ID_INFO 0x1549A966
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
63 #define MATROSKA_ID_TRACKS 0x1654AE6B
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
64 #define MATROSKA_ID_CUES 0x1C53BB6B
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
65 #define MATROSKA_ID_TAGS 0x1254C367
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
66 #define MATROSKA_ID_SEEKHEAD 0x114D9B74
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
67 #define MATROSKA_ID_CLUSTER 0x1F43B675
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
68
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
69 /* IDs in the info master */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
70 #define MATROSKA_ID_TIMECODESCALE 0x2AD7B1
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
71 #define MATROSKA_ID_DURATION 0x4489
1459
571b1b1c7984 Allow reading matroska title.
aurel
parents: 1458
diff changeset
72 #define MATROSKA_ID_TITLE 0x7BA9
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
73 #define MATROSKA_ID_WRITINGAPP 0x5741
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
74 #define MATROSKA_ID_MUXINGAPP 0x4D80
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
75 #define MATROSKA_ID_DATEUTC 0x4461
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
76
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
77 /* ID in the tracks master */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
78 #define MATROSKA_ID_TRACKENTRY 0xAE
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
79
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
80 /* IDs in the trackentry master */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
81 #define MATROSKA_ID_TRACKNUMBER 0xD7
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
82 #define MATROSKA_ID_TRACKUID 0x73C5
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
83 #define MATROSKA_ID_TRACKTYPE 0x83
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
84 #define MATROSKA_ID_TRACKAUDIO 0xE1
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
85 #define MATROSKA_ID_TRACKVIDEO 0xE0
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
86 #define MATROSKA_ID_CODECID 0x86
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
87 #define MATROSKA_ID_CODECPRIVATE 0x63A2
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
88 #define MATROSKA_ID_CODECNAME 0x258688
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
89 #define MATROSKA_ID_CODECINFOURL 0x3B4040
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
90 #define MATROSKA_ID_CODECDOWNLOADURL 0x26B240
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
91 #define MATROSKA_ID_TRACKNAME 0x536E
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
92 #define MATROSKA_ID_TRACKLANGUAGE 0x22B59C
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
93 #define MATROSKA_ID_TRACKFLAGENABLED 0xB9
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
94 #define MATROSKA_ID_TRACKFLAGDEFAULT 0x88
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
95 #define MATROSKA_ID_TRACKFLAGLACING 0x9C
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
96 #define MATROSKA_ID_TRACKMINCACHE 0x6DE7
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
97 #define MATROSKA_ID_TRACKMAXCACHE 0x6DF8
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
98 #define MATROSKA_ID_TRACKDEFAULTDURATION 0x23E383
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
99
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
100 /* IDs in the trackvideo master */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
101 #define MATROSKA_ID_VIDEOFRAMERATE 0x2383E3
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
102 #define MATROSKA_ID_VIDEODISPLAYWIDTH 0x54B0
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
103 #define MATROSKA_ID_VIDEODISPLAYHEIGHT 0x54BA
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
104 #define MATROSKA_ID_VIDEOPIXELWIDTH 0xB0
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
105 #define MATROSKA_ID_VIDEOPIXELHEIGHT 0xBA
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
106 #define MATROSKA_ID_VIDEOFLAGINTERLACED 0x9A
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
107 #define MATROSKA_ID_VIDEOSTEREOMODE 0x53B9
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
108 #define MATROSKA_ID_VIDEOASPECTRATIO 0x54B3
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
109 #define MATROSKA_ID_VIDEOCOLOURSPACE 0x2EB524
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
110
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
111 /* IDs in the trackaudio master */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
112 #define MATROSKA_ID_AUDIOSAMPLINGFREQ 0xB5
1467
24c082e20a6a add audio output sampling freqency reading in matroska
aurel
parents: 1465
diff changeset
113 #define MATROSKA_ID_AUDIOOUTSAMPLINGFREQ 0x78B5
24c082e20a6a add audio output sampling freqency reading in matroska
aurel
parents: 1465
diff changeset
114
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
115 #define MATROSKA_ID_AUDIOBITDEPTH 0x6264
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
116 #define MATROSKA_ID_AUDIOCHANNELS 0x9F
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
117
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
118 /* ID in the cues master */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
119 #define MATROSKA_ID_POINTENTRY 0xBB
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
120
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
121 /* IDs in the pointentry master */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
122 #define MATROSKA_ID_CUETIME 0xB3
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
123 #define MATROSKA_ID_CUETRACKPOSITION 0xB7
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
124
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
125 /* IDs in the cuetrackposition master */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
126 #define MATROSKA_ID_CUETRACK 0xF7
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
127 #define MATROSKA_ID_CUECLUSTERPOSITION 0xF1
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
128
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
129 /* IDs in the tags master */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
130 /* TODO */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
131
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
132 /* IDs in the seekhead master */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
133 #define MATROSKA_ID_SEEKENTRY 0x4DBB
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
134
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
135 /* IDs in the seekpoint master */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
136 #define MATROSKA_ID_SEEKID 0x53AB
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
137 #define MATROSKA_ID_SEEKPOSITION 0x53AC
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
138
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
139 /* IDs in the cluster master */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
140 #define MATROSKA_ID_CLUSTERTIMECODE 0xE7
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
141 #define MATROSKA_ID_BLOCKGROUP 0xA0
1831
bdca904db5e5 add support for simple blocks (ie. matroska v2)
aurel
parents: 1830
diff changeset
142 #define MATROSKA_ID_SIMPLEBLOCK 0xA3
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
143
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
144 /* IDs in the blockgroup master */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
145 #define MATROSKA_ID_BLOCK 0xA1
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
146 #define MATROSKA_ID_BLOCKDURATION 0x9B
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
147 #define MATROSKA_ID_BLOCKREFERENCE 0xFB
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
148
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
149 typedef enum {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
150 MATROSKA_TRACK_TYPE_VIDEO = 0x1,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
151 MATROSKA_TRACK_TYPE_AUDIO = 0x2,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
152 MATROSKA_TRACK_TYPE_COMPLEX = 0x3,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
153 MATROSKA_TRACK_TYPE_LOGO = 0x10,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
154 MATROSKA_TRACK_TYPE_SUBTITLE = 0x11,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
155 MATROSKA_TRACK_TYPE_CONTROL = 0x20,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
156 } MatroskaTrackType;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
157
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
158 typedef enum {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
159 MATROSKA_EYE_MODE_MONO = 0x0,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
160 MATROSKA_EYE_MODE_RIGHT = 0x1,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
161 MATROSKA_EYE_MODE_LEFT = 0x2,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
162 MATROSKA_EYE_MODE_BOTH = 0x3,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
163 } MatroskaEyeMode;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
164
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
165 typedef enum {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
166 MATROSKA_ASPECT_RATIO_MODE_FREE = 0x0,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
167 MATROSKA_ASPECT_RATIO_MODE_KEEP = 0x1,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
168 MATROSKA_ASPECT_RATIO_MODE_FIXED = 0x2,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
169 } MatroskaAspectRatioMode;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
170
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
171 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
172 * These aren't in any way "matroska-form" things,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
173 * it's just something I use in the muxer/demuxer.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
174 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
175
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
176 typedef enum {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
177 MATROSKA_TRACK_ENABLED = (1<<0),
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
178 MATROSKA_TRACK_DEFAULT = (1<<1),
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
179 MATROSKA_TRACK_LACING = (1<<2),
1532
4eb3d2701215 matroska: split real video frames so that each packet contains only one slice
aurel
parents: 1531
diff changeset
180 MATROSKA_TRACK_REAL_V = (1<<4),
1904
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
181 MATROSKA_TRACK_REORDER = (1<<8),
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
182 MATROSKA_TRACK_SHIFT = (1<<16)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
183 } MatroskaTrackFlags;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
184
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
185 typedef enum {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
186 MATROSKA_VIDEOTRACK_INTERLACED = (MATROSKA_TRACK_SHIFT<<0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
187 } MatroskaVideoTrackFlags;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
188
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
189 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
190 * Matroska Codec IDs. Strings.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
191 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
192
1024
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
193 typedef struct CodecTags{
1123
6992dd78ff68 Add (mostly) const to variable and parameter declaration, where a char* was
diego
parents: 1120
diff changeset
194 const char *str;
1024
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
195 enum CodecID id;
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
196 }CodecTags;
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
197
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
198 #define MATROSKA_CODEC_ID_VIDEO_VFW_FOURCC "V_MS/VFW/FOURCC"
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
199 #define MATROSKA_CODEC_ID_AUDIO_ACM "A_MS/ACM"
1024
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
200
1123
6992dd78ff68 Add (mostly) const to variable and parameter declaration, where a char* was
diego
parents: 1120
diff changeset
201 static CodecTags codec_tags[]={
1024
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
202 // {"V_MS/VFW/FOURCC" , CODEC_ID_NONE},
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
203 {"V_UNCOMPRESSED" , CODEC_ID_RAWVIDEO},
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
204 {"V_MPEG4/ISO/SP" , CODEC_ID_MPEG4},
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
205 {"V_MPEG4/ISO/ASP" , CODEC_ID_MPEG4},
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
206 {"V_MPEG4/ISO/AP" , CODEC_ID_MPEG4},
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
207 {"V_MPEG4/ISO/AVC" , CODEC_ID_H264},
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
208 {"V_MPEG4/MS/V3" , CODEC_ID_MSMPEG4V3},
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
209 {"V_MPEG1" , CODEC_ID_MPEG1VIDEO},
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
210 {"V_MPEG2" , CODEC_ID_MPEG2VIDEO},
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
211 {"V_MJPEG" , CODEC_ID_MJPEG},
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
212 {"V_REAL/RV10" , CODEC_ID_RV10},
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
213 {"V_REAL/RV20" , CODEC_ID_RV20},
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
214 {"V_REAL/RV30" , CODEC_ID_RV30},
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
215 {"V_REAL/RV40" , CODEC_ID_RV40},
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
216 /* TODO: Real/Quicktime */
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
217
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
218 // {"A_MS/ACM" , CODEC_ID_NONE},
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
219 {"A_MPEG/L1" , CODEC_ID_MP3},
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
220 {"A_MPEG/L2" , CODEC_ID_MP3},
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
221 {"A_MPEG/L3" , CODEC_ID_MP3},
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
222 {"A_PCM/INT/BIG" , CODEC_ID_PCM_U16BE},
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
223 {"A_PCM/INT/LIT" , CODEC_ID_PCM_U16LE},
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
224 // {"A_PCM/FLOAT/IEEE" , CODEC_ID_NONE},
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
225 {"A_AC3" , CODEC_ID_AC3},
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
226 {"A_DTS" , CODEC_ID_DTS},
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
227 {"A_VORBIS" , CODEC_ID_VORBIS},
1475
a83e86c05295 Add A_AAC codec identifier support in matroska.
aurel
parents: 1472
diff changeset
228 {"A_AAC" , CODEC_ID_AAC},
1537
8110f1a20f2a add support for FLAC in matroska
aurel
parents: 1534
diff changeset
229 {"A_FLAC" , CODEC_ID_FLAC},
1451
48cfca624912 WavPack support in Matroska
kostya
parents: 1358
diff changeset
230 {"A_WAVPACK4" , CODEC_ID_WAVPACK},
1534
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
231 {"A_TTA1" , CODEC_ID_TTA},
1024
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
232 {NULL , CODEC_ID_NONE}
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
233 /* TODO: AC3-9/10 (?), Real, Musepack, Quicktime */
1024
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
234 };
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
235
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
236 /* max. depth in the EBML tree structure */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
237 #define EBML_MAX_DEPTH 16
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
238
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
239 typedef struct Track {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
240 MatroskaTrackType type;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
241
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
242 /* Unique track number and track ID. stream_index is the index that
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
243 * the calling app uses for this track. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
244 uint32_t num,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
245 uid,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
246 stream_index;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
247
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
248 char *name,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
249 *language;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
250
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
251 char *codec_id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
252 *codec_name;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
253
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
254 unsigned char *codec_priv;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
255 int codec_priv_size;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
256
1912
98a74cfd12d4 scale duration and default_duration
aurel
parents: 1911
diff changeset
257 uint64_t default_duration;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
258 MatroskaTrackFlags flags;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
259 } MatroskaTrack;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
260
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
261 typedef struct MatroskaVideoTrack {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
262 MatroskaTrack track;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
263
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
264 int pixel_width,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
265 pixel_height,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
266 display_width,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
267 display_height;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
268
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
269 uint32_t fourcc;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
270
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
271 MatroskaAspectRatioMode ar_mode;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
272 MatroskaEyeMode eye_mode;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
273
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
274 //..
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
275 } MatroskaVideoTrack;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
276
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
277 typedef struct MatroskaAudioTrack {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
278 MatroskaTrack track;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
279
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
280 int channels,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
281 bitdepth,
1467
24c082e20a6a add audio output sampling freqency reading in matroska
aurel
parents: 1465
diff changeset
282 internal_samplerate,
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
283 samplerate;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
284 //..
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
285 } MatroskaAudioTrack;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
286
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
287 typedef struct MatroskaSubtitleTrack {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
288 MatroskaTrack track;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
289
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
290 //..
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
291 } MatroskaSubtitleTrack;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
292
1832
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
293 #define MAX_TRACK_SIZE (FFMAX(FFMAX(sizeof(MatroskaVideoTrack), \
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
294 sizeof(MatroskaAudioTrack)), \
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
295 sizeof(MatroskaSubtitleTrack)))
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
296
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
297 typedef struct MatroskaLevel {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
298 uint64_t start, length;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
299 } MatroskaLevel;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
300
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
301 typedef struct MatroskaDemuxIndex {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
302 uint64_t pos; /* of the corresponding *cluster*! */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
303 uint16_t track; /* reference to 'num' */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
304 uint64_t time; /* in nanoseconds */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
305 } MatroskaDemuxIndex;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
306
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
307 typedef struct MatroskaDemuxContext {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
308 AVFormatContext *ctx;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
309
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
310 /* ebml stuff */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
311 int num_levels;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
312 MatroskaLevel levels[EBML_MAX_DEPTH];
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
313 int level_up;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
314
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
315 /* matroska stuff */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
316 char *writing_app,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
317 *muxing_app;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
318 int64_t created;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
319
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
320 /* timescale in the file */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
321 int64_t time_scale;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
322
1025
95e8458ae120 duration and subitle fix from the patch by Steve Lhomme
michael
parents: 1024
diff changeset
323 /* position (time, ns) */
95e8458ae120 duration and subitle fix from the patch by Steve Lhomme
michael
parents: 1024
diff changeset
324 int64_t pos;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
325
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
326 /* num_streams is the number of streams that av_new_stream() was called
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
327 * for ( = that are available to the calling program). */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
328 int num_tracks, num_streams;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
329 MatroskaTrack *tracks[MAX_STREAMS];
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
330
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
331 /* cache for ID peeking */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
332 uint32_t peek_id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
333
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
334 /* byte position of the segment inside the stream */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
335 offset_t segment_start;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
336
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
337 /* The packet queue. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
338 AVPacket **packets;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
339 int num_packets;
1904
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
340 /* Second packet queue used to reorder pts of some video track. */
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
341 AVPacket **packets_reorder;
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
342 int num_packets_reorder;
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
343 uint64_t reorder_max_pts;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
344
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
345 /* have we already parse metadata/cues/clusters? */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
346 int metadata_parsed,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
347 index_parsed,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
348 done;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
349
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
350 /* The index for seeking. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
351 int num_indexes;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
352 MatroskaDemuxIndex *index;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
353 } MatroskaDemuxContext;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
354
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
355 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
356 * The first few functions handle EBML file parsing. The rest
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
357 * is the document interpretation. Matroska really just is a
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
358 * EBML file.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
359 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
360
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
361 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
362 * Return: the amount of levels in the hierarchy that the
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
363 * current element lies higher than the previous one.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
364 * The opposite isn't done - that's auto-done using master
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
365 * element reading.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
366 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
367
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
368 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
369 ebml_read_element_level_up (MatroskaDemuxContext *matroska)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
370 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
371 ByteIOContext *pb = &matroska->ctx->pb;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
372 offset_t pos = url_ftell(pb);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
373 int num = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
374
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
375 while (matroska->num_levels > 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
376 MatroskaLevel *level = &matroska->levels[matroska->num_levels - 1];
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
377
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
378 if (pos >= level->start + level->length) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
379 matroska->num_levels--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
380 num++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
381 } else {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
382 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
383 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
384 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
385
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
386 return num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
387 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
388
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
389 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
390 * Read: an "EBML number", which is defined as a variable-length
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
391 * array of bytes. The first byte indicates the length by giving a
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
392 * number of 0-bits followed by a one. The position of the first
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
393 * "one" bit inside the first byte indicates the length of this
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
394 * number.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
395 * Returns: num. of bytes read. < 0 on error.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
396 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
397
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
398 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
399 ebml_read_num (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
400 int max_size,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
401 uint64_t *number)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
402 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
403 ByteIOContext *pb = &matroska->ctx->pb;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
404 int len_mask = 0x80, read = 1, n = 1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
405 int64_t total = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
406
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
407 /* the first byte tells us the length in bytes - get_byte() can normally
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
408 * return 0, but since that's not a valid first ebmlID byte, we can
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
409 * use it safely here to catch EOS. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
410 if (!(total = get_byte(pb))) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
411 /* we might encounter EOS here */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
412 if (!url_feof(pb)) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
413 offset_t pos = url_ftell(pb);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
414 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
415 "Read error at pos. %"PRIu64" (0x%"PRIx64")\n",
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
416 pos, pos);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
417 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
418 return AVERROR_IO; /* EOS or actual I/O error */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
419 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
420
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
421 /* get the length of the EBML number */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
422 while (read <= max_size && !(total & len_mask)) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
423 read++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
424 len_mask >>= 1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
425 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
426 if (read > max_size) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
427 offset_t pos = url_ftell(pb) - 1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
428 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
429 "Invalid EBML number size tag 0x%02x at pos %"PRIu64" (0x%"PRIx64")\n",
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
430 (uint8_t) total, pos, pos);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
431 return AVERROR_INVALIDDATA;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
432 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
433
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
434 /* read out length */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
435 total &= ~len_mask;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
436 while (n++ < read)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
437 total = (total << 8) | get_byte(pb);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
438
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
439 *number = total;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
440
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
441 return read;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
442 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
443
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
444 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
445 * Read: the element content data ID.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
446 * Return: the number of bytes read or < 0 on error.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
447 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
448
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
449 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
450 ebml_read_element_id (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
451 uint32_t *id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
452 int *level_up)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
453 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
454 int read;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
455 uint64_t total;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
456
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
457 /* if we re-call this, use our cached ID */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
458 if (matroska->peek_id != 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
459 if (level_up)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
460 *level_up = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
461 *id = matroska->peek_id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
462 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
463 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
464
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
465 /* read out the "EBML number", include tag in ID */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
466 if ((read = ebml_read_num(matroska, 4, &total)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
467 return read;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
468 *id = matroska->peek_id = total | (1 << (read * 7));
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
469
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
470 /* level tracking */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
471 if (level_up)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
472 *level_up = ebml_read_element_level_up(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
473
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
474 return read;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
475 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
476
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
477 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
478 * Read: element content length.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
479 * Return: the number of bytes read or < 0 on error.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
480 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
481
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
482 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
483 ebml_read_element_length (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
484 uint64_t *length)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
485 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
486 /* clear cache since we're now beyond that data point */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
487 matroska->peek_id = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
488
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
489 /* read out the "EBML number", include tag in ID */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
490 return ebml_read_num(matroska, 8, length);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
491 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
492
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
493 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
494 * Return: the ID of the next element, or 0 on error.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
495 * Level_up contains the amount of levels that this
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
496 * next element lies higher than the previous one.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
497 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
498
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
499 static uint32_t
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
500 ebml_peek_id (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
501 int *level_up)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
502 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
503 uint32_t id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
504
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
505 assert(level_up != NULL);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
506
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
507 if (ebml_read_element_id(matroska, &id, level_up) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
508 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
509
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
510 return id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
511 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
512
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
513 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
514 * Seek to a given offset.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
515 * 0 is success, -1 is failure.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
516 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
517
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
518 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
519 ebml_read_seek (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
520 offset_t offset)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
521 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
522 ByteIOContext *pb = &matroska->ctx->pb;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
523
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
524 /* clear ID cache, if any */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
525 matroska->peek_id = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
526
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
527 return (url_fseek(pb, offset, SEEK_SET) == offset) ? 0 : -1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
528 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
529
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
530 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
531 * Skip the next element.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
532 * 0 is success, -1 is failure.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
533 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
534
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
535 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
536 ebml_read_skip (MatroskaDemuxContext *matroska)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
537 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
538 ByteIOContext *pb = &matroska->ctx->pb;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
539 uint32_t id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
540 uint64_t length;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
541 int res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
542
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
543 if ((res = ebml_read_element_id(matroska, &id, NULL)) < 0 ||
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
544 (res = ebml_read_element_length(matroska, &length)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
545 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
546
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
547 url_fskip(pb, length);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
548
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
549 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
550 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
551
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
552 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
553 * Read the next element as an unsigned int.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
554 * 0 is success, < 0 is failure.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
555 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
556
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
557 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
558 ebml_read_uint (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
559 uint32_t *id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
560 uint64_t *num)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
561 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
562 ByteIOContext *pb = &matroska->ctx->pb;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
563 int n = 0, size, res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
564 uint64_t rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
565
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
566 if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 ||
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
567 (res = ebml_read_element_length(matroska, &rlength)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
568 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
569 size = rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
570 if (size < 1 || size > 8) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
571 offset_t pos = url_ftell(pb);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
572 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
573 "Invalid uint element size %d at position %"PRId64" (0x%"PRIx64")\n",
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
574 size, pos, pos);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
575 return AVERROR_INVALIDDATA;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
576 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
577
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
578 /* big-endian ordening; build up number */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
579 *num = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
580 while (n++ < size)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
581 *num = (*num << 8) | get_byte(pb);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
582
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
583 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
584 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
585
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
586 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
587 * Read the next element as a signed int.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
588 * 0 is success, < 0 is failure.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
589 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
590
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
591 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
592 ebml_read_sint (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
593 uint32_t *id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
594 int64_t *num)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
595 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
596 ByteIOContext *pb = &matroska->ctx->pb;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
597 int size, n = 1, negative = 0, res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
598 uint64_t rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
599
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
600 if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 ||
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
601 (res = ebml_read_element_length(matroska, &rlength)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
602 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
603 size = rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
604 if (size < 1 || size > 8) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
605 offset_t pos = url_ftell(pb);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
606 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
607 "Invalid sint element size %d at position %"PRId64" (0x%"PRIx64")\n",
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
608 size, pos, pos);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
609 return AVERROR_INVALIDDATA;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
610 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
611 if ((*num = get_byte(pb)) & 0x80) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
612 negative = 1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
613 *num &= ~0x80;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
614 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
615 while (n++ < size)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
616 *num = (*num << 8) | get_byte(pb);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
617
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
618 /* make signed */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
619 if (negative)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
620 *num = *num - (1LL << ((8 * size) - 1));
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
621
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
622 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
623 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
624
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
625 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
626 * Read the next element as a float.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
627 * 0 is success, < 0 is failure.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
628 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
629
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
630 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
631 ebml_read_float (MatroskaDemuxContext *matroska,
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
632 uint32_t *id,
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
633 double *num)
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
634 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
635 ByteIOContext *pb = &matroska->ctx->pb;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
636 int size, res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
637 uint64_t rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
638
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
639 if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 ||
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
640 (res = ebml_read_element_length(matroska, &rlength)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
641 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
642 size = rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
643
824
779b1e87b865 more non portable float parsing code ...
michael
parents: 820
diff changeset
644 if (size == 4) {
779b1e87b865 more non portable float parsing code ...
michael
parents: 820
diff changeset
645 *num= av_int2flt(get_be32(pb));
779b1e87b865 more non portable float parsing code ...
michael
parents: 820
diff changeset
646 } else if(size==8){
779b1e87b865 more non portable float parsing code ...
michael
parents: 820
diff changeset
647 *num= av_int2dbl(get_be64(pb));
779b1e87b865 more non portable float parsing code ...
michael
parents: 820
diff changeset
648 } else{
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
649 offset_t pos = url_ftell(pb);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
650 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
651 "Invalid float element size %d at position %"PRIu64" (0x%"PRIx64")\n",
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
652 size, pos, pos);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
653 return AVERROR_INVALIDDATA;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
654 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
655
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
656 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
657 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
658
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
659 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
660 * Read the next element as an ASCII string.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
661 * 0 is success, < 0 is failure.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
662 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
663
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
664 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
665 ebml_read_ascii (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
666 uint32_t *id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
667 char **str)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
668 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
669 ByteIOContext *pb = &matroska->ctx->pb;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
670 int size, res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
671 uint64_t rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
672
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
673 if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 ||
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
674 (res = ebml_read_element_length(matroska, &rlength)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
675 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
676 size = rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
677
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
678 /* ebml strings are usually not 0-terminated, so we allocate one
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
679 * byte more, read the string and NULL-terminate it ourselves. */
639
0b52743104ac integer overflows, heap corruption
michael
parents: 496
diff changeset
680 if (size < 0 || !(*str = av_malloc(size + 1))) {
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
681 av_log(matroska->ctx, AV_LOG_ERROR, "Memory allocation failed\n");
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
682 return AVERROR_NOMEM;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
683 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
684 if (get_buffer(pb, (uint8_t *) *str, size) != size) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
685 offset_t pos = url_ftell(pb);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
686 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
687 "Read error at pos. %"PRIu64" (0x%"PRIx64")\n", pos, pos);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
688 return AVERROR_IO;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
689 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
690 (*str)[size] = '\0';
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
691
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
692 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
693 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
694
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
695 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
696 * Read the next element as a UTF-8 string.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
697 * 0 is success, < 0 is failure.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
698 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
699
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
700 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
701 ebml_read_utf8 (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
702 uint32_t *id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
703 char **str)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
704 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
705 return ebml_read_ascii(matroska, id, str);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
706 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
707
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
708 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
709 * Read the next element as a date (nanoseconds since 1/1/2000).
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
710 * 0 is success, < 0 is failure.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
711 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
712
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
713 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
714 ebml_read_date (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
715 uint32_t *id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
716 int64_t *date)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
717 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
718 return ebml_read_sint(matroska, id, date);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
719 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
720
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
721 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
722 * Read the next element, but only the header. The contents
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
723 * are supposed to be sub-elements which can be read separately.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
724 * 0 is success, < 0 is failure.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
725 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
726
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
727 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
728 ebml_read_master (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
729 uint32_t *id)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
730 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
731 ByteIOContext *pb = &matroska->ctx->pb;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
732 uint64_t length;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
733 MatroskaLevel *level;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
734 int res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
735
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
736 if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 ||
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
737 (res = ebml_read_element_length(matroska, &length)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
738 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
739
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
740 /* protect... (Heaven forbids that the '>' is true) */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
741 if (matroska->num_levels >= EBML_MAX_DEPTH) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
742 av_log(matroska->ctx, AV_LOG_ERROR,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
743 "File moves beyond max. allowed depth (%d)\n", EBML_MAX_DEPTH);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
744 return AVERROR_NOTSUPP;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
745 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
746
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
747 /* remember level */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
748 level = &matroska->levels[matroska->num_levels++];
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
749 level->start = url_ftell(pb);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
750 level->length = length;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
751
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
752 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
753 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
754
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
755 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
756 * Read the next element as binary data.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
757 * 0 is success, < 0 is failure.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
758 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
759
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
760 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
761 ebml_read_binary (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
762 uint32_t *id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
763 uint8_t **binary,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
764 int *size)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
765 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
766 ByteIOContext *pb = &matroska->ctx->pb;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
767 uint64_t rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
768 int res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
769
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
770 if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 ||
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
771 (res = ebml_read_element_length(matroska, &rlength)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
772 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
773 *size = rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
774
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
775 if (!(*binary = av_malloc(*size))) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
776 av_log(matroska->ctx, AV_LOG_ERROR,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
777 "Memory allocation error\n");
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
778 return AVERROR_NOMEM;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
779 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
780
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
781 if (get_buffer(pb, *binary, *size) != *size) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
782 offset_t pos = url_ftell(pb);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
783 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
784 "Read error at pos. %"PRIu64" (0x%"PRIx64")\n", pos, pos);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
785 return AVERROR_IO;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
786 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
787
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
788 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
789 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
790
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
791 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
792 * Read signed/unsigned "EBML" numbers.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
793 * Return: number of bytes processed, < 0 on error.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
794 * XXX: use ebml_read_num().
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
795 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
796
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
797 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
798 matroska_ebmlnum_uint (uint8_t *data,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
799 uint32_t size,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
800 uint64_t *num)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
801 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
802 int len_mask = 0x80, read = 1, n = 1, num_ffs = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
803 uint64_t total;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
804
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
805 if (size <= 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
806 return AVERROR_INVALIDDATA;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
807
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
808 total = data[0];
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
809 while (read <= 8 && !(total & len_mask)) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
810 read++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
811 len_mask >>= 1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
812 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
813 if (read > 8)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
814 return AVERROR_INVALIDDATA;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
815
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
816 if ((total &= (len_mask - 1)) == len_mask - 1)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
817 num_ffs++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
818 if (size < read)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
819 return AVERROR_INVALIDDATA;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
820 while (n < read) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
821 if (data[n] == 0xff)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
822 num_ffs++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
823 total = (total << 8) | data[n];
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
824 n++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
825 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
826
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
827 if (read == num_ffs)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
828 *num = (uint64_t)-1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
829 else
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
830 *num = total;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
831
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
832 return read;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
833 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
834
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
835 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
836 * Same as above, but signed.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
837 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
838
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
839 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
840 matroska_ebmlnum_sint (uint8_t *data,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
841 uint32_t size,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
842 int64_t *num)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
843 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
844 uint64_t unum;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
845 int res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
846
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
847 /* read as unsigned number first */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
848 if ((res = matroska_ebmlnum_uint(data, size, &unum)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
849 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
850
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
851 /* make signed (weird way) */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
852 if (unum == (uint64_t)-1)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
853 *num = INT64_MAX;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
854 else
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
855 *num = unum - ((1LL << ((7 * res) - 1)) - 1);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
856
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
857 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
858 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
859
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
860 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
861 * Read an EBML header.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
862 * 0 is success, < 0 is failure.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
863 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
864
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
865 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
866 ebml_read_header (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
867 char **doctype,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
868 int *version)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
869 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
870 uint32_t id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
871 int level_up, res = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
872
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
873 /* default init */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
874 if (doctype)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
875 *doctype = NULL;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
876 if (version)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
877 *version = 1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
878
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
879 if (!(id = ebml_peek_id(matroska, &level_up)) ||
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
880 level_up != 0 || id != EBML_ID_HEADER) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
881 av_log(matroska->ctx, AV_LOG_ERROR,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
882 "This is not an EBML file (id=0x%x/0x%x)\n", id, EBML_ID_HEADER);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
883 return AVERROR_INVALIDDATA;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
884 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
885 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
886 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
887
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
888 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
889 if (!(id = ebml_peek_id(matroska, &level_up)))
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
890 return AVERROR_IO;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
891
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
892 /* end-of-header */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
893 if (level_up)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
894 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
895
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
896 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
897 /* is our read version uptodate? */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
898 case EBML_ID_EBMLREADVERSION: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
899 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
900
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
901 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
902 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
903 if (num > EBML_VERSION) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
904 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
905 "EBML version %"PRIu64" (> %d) is not supported\n",
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
906 num, EBML_VERSION);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
907 return AVERROR_INVALIDDATA;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
908 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
909 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
910 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
911
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
912 /* we only handle 8 byte lengths at max */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
913 case EBML_ID_EBMLMAXSIZELENGTH: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
914 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
915
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
916 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
917 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
918 if (num > sizeof(uint64_t)) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
919 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
920 "Integers of size %"PRIu64" (> %zd) not supported\n",
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
921 num, sizeof(uint64_t));
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
922 return AVERROR_INVALIDDATA;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
923 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
924 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
925 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
926
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
927 /* we handle 4 byte IDs at max */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
928 case EBML_ID_EBMLMAXIDLENGTH: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
929 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
930
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
931 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
932 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
933 if (num > sizeof(uint32_t)) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
934 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
935 "IDs of size %"PRIu64" (> %zu) not supported\n",
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
936 num, sizeof(uint32_t));
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
937 return AVERROR_INVALIDDATA;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
938 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
939 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
940 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
941
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
942 case EBML_ID_DOCTYPE: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
943 char *text;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
944
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
945 if ((res = ebml_read_ascii(matroska, &id, &text)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
946 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
947 if (doctype) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
948 if (*doctype)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
949 av_free(*doctype);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
950 *doctype = text;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
951 } else
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
952 av_free(text);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
953 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
954 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
955
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
956 case EBML_ID_DOCTYPEREADVERSION: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
957 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
958
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
959 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
960 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
961 if (version)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
962 *version = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
963 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
964 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
965
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
966 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
967 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
968 "Unknown data type 0x%x in EBML header", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
969 /* pass-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
970
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
971 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
972 /* we ignore these two, as they don't tell us anything we
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
973 * care about */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
974 case EBML_ID_EBMLVERSION:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
975 case EBML_ID_DOCTYPEVERSION:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
976 res = ebml_read_skip (matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
977 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
978 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
979 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
980
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
981 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
982 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
983
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
984 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
985 * Put one packet in an application-supplied AVPacket struct.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
986 * Returns 0 on success or -1 on failure.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
987 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
988
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
989 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
990 matroska_deliver_packet (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
991 AVPacket *pkt)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
992 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
993 if (matroska->num_packets > 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
994 memcpy(pkt, matroska->packets[0], sizeof(AVPacket));
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
995 av_free(matroska->packets[0]);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
996 if (matroska->num_packets > 1) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
997 memmove(&matroska->packets[0], &matroska->packets[1],
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
998 (matroska->num_packets - 1) * sizeof(AVPacket *));
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
999 matroska->packets =
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1000 av_realloc(matroska->packets, (matroska->num_packets - 1) *
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1001 sizeof(AVPacket *));
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1002 } else {
1530
f65cd8910a5c simplify free()+set to NULL using av_freep()
aurel
parents: 1490
diff changeset
1003 av_freep(&matroska->packets);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1004 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1005 matroska->num_packets--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1006 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1007 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1008
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1009 return -1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1010 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1011
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1012 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1013 * Put a packet into our internal queue. Will be delivered to the
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1014 * user/application during the next get_packet() call.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1015 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1016
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1017 static void
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1018 matroska_queue_packet (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1019 AVPacket *pkt)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1020 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1021 matroska->packets =
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1022 av_realloc(matroska->packets, (matroska->num_packets + 1) *
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1023 sizeof(AVPacket *));
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1024 matroska->packets[matroska->num_packets] = pkt;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1025 matroska->num_packets++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1026 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1027
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1028 /*
1904
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1029 * Put a packet into our internal reordering queue. Will be moved to the
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1030 * main packet queue when enough packets are available to reorder pts.
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1031 */
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1032
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1033 static void
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1034 matroska_queue_packet_reordered (MatroskaDemuxContext *matroska,
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1035 AVPacket *pkt,
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1036 int is_bframe)
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1037 {
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1038 if (matroska->num_packets_reorder && !is_bframe
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1039 && pkt->pts > matroska->reorder_max_pts) {
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1040 /* reorder pts */
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1041 int i, j, k = 1;
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1042 for (j=matroska->num_packets_reorder-1; j && k; j--) {
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1043 k = 0;
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1044 for (i=0; i<j; i++) {
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1045 if (matroska->packets_reorder[i]->pts > matroska->packets_reorder[i+1]->pts) {
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1046 FFSWAP(uint64_t, matroska->packets_reorder[i]->pts, matroska->packets_reorder[i+1]->pts);
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1047 k = 1;
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1048 }
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1049 }
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1050 }
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1051 /* then really queue the packets */
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1052 for (i=0; i<matroska->num_packets_reorder; i++)
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1053 matroska_queue_packet (matroska, matroska->packets_reorder[i]);
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1054 matroska->num_packets_reorder = 0;
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1055 }
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1056 matroska->packets_reorder =
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1057 av_realloc(matroska->packets_reorder,
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1058 (matroska->num_packets_reorder + 1) * sizeof(AVPacket *));
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1059 matroska->packets_reorder[matroska->num_packets_reorder++] = pkt;
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1060 if (pkt->pts > matroska->reorder_max_pts)
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1061 matroska->reorder_max_pts = pkt->pts;
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1062 }
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1063
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1064
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
1065 /*
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1066 * Autodetecting...
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1067 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1068
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1069 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1070 matroska_probe (AVProbeData *p)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1071 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1072 uint64_t total = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1073 int len_mask = 0x80, size = 1, n = 1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1074 uint8_t probe_data[] = { 'm', 'a', 't', 'r', 'o', 's', 'k', 'a' };
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1075
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1076 if (p->buf_size < 5)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1077 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1078
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1079 /* ebml header? */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1080 if ((p->buf[0] << 24 | p->buf[1] << 16 |
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1081 p->buf[2] << 8 | p->buf[3]) != EBML_ID_HEADER)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1082 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1083
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1084 /* length of header */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1085 total = p->buf[4];
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1086 while (size <= 8 && !(total & len_mask)) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1087 size++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1088 len_mask >>= 1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1089 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1090 if (size > 8)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1091 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1092 total &= (len_mask - 1);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1093 while (n < size)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1094 total = (total << 8) | p->buf[4 + n++];
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1095
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1096 /* does the probe data contain the whole header? */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1097 if (p->buf_size < 4 + size + total)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1098 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1099
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1100 /* the header must contain the document type 'matroska'. For now,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1101 * we don't parse the whole header but simply check for the
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1102 * availability of that array of characters inside the header.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1103 * Not fully fool-proof, but good enough. */
1828
f1397cd39ec3 fix an off-by-one error in probing function
aurel
parents: 1673
diff changeset
1104 for (n = 4 + size; n <= 4 + size + total - sizeof(probe_data); n++)
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1105 if (!memcmp (&p->buf[n], probe_data, sizeof(probe_data)))
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1106 return AVPROBE_SCORE_MAX;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1107
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1108 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1109 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1110
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1111 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1112 * From here on, it's all XML-style DTD stuff... Needs no comments.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1113 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1114
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1115 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1116 matroska_parse_info (MatroskaDemuxContext *matroska)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1117 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1118 int res = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1119 uint32_t id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1120
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1121 av_log(matroska->ctx, AV_LOG_DEBUG, "Parsing info...\n");
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1122
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1123 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1124 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1125 res = AVERROR_IO;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1126 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1127 } else if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1128 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1129 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1130 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1131
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1132 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1133 /* cluster timecode */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1134 case MATROSKA_ID_TIMECODESCALE: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1135 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1136 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1137 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1138 matroska->time_scale = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1139 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1140 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1141
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1142 case MATROSKA_ID_DURATION: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1143 double num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1144 if ((res = ebml_read_float(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1145 break;
1025
95e8458ae120 duration and subitle fix from the patch by Steve Lhomme
michael
parents: 1024
diff changeset
1146 matroska->ctx->duration = num * matroska->time_scale * 1000 / AV_TIME_BASE;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1147 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1148 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1149
1459
571b1b1c7984 Allow reading matroska title.
aurel
parents: 1458
diff changeset
1150 case MATROSKA_ID_TITLE: {
571b1b1c7984 Allow reading matroska title.
aurel
parents: 1458
diff changeset
1151 char *text;
571b1b1c7984 Allow reading matroska title.
aurel
parents: 1458
diff changeset
1152 if ((res = ebml_read_utf8(matroska, &id, &text)) < 0)
571b1b1c7984 Allow reading matroska title.
aurel
parents: 1458
diff changeset
1153 break;
571b1b1c7984 Allow reading matroska title.
aurel
parents: 1458
diff changeset
1154 strncpy(matroska->ctx->title, text,
571b1b1c7984 Allow reading matroska title.
aurel
parents: 1458
diff changeset
1155 sizeof(matroska->ctx->title)-1);
571b1b1c7984 Allow reading matroska title.
aurel
parents: 1458
diff changeset
1156 av_free(text);
571b1b1c7984 Allow reading matroska title.
aurel
parents: 1458
diff changeset
1157 break;
571b1b1c7984 Allow reading matroska title.
aurel
parents: 1458
diff changeset
1158 }
571b1b1c7984 Allow reading matroska title.
aurel
parents: 1458
diff changeset
1159
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1160 case MATROSKA_ID_WRITINGAPP: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1161 char *text;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1162 if ((res = ebml_read_utf8(matroska, &id, &text)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1163 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1164 matroska->writing_app = text;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1165 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1166 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1167
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1168 case MATROSKA_ID_MUXINGAPP: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1169 char *text;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1170 if ((res = ebml_read_utf8(matroska, &id, &text)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1171 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1172 matroska->muxing_app = text;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1173 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1174 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1175
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1176 case MATROSKA_ID_DATEUTC: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1177 int64_t time;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1178 if ((res = ebml_read_date(matroska, &id, &time)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1179 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1180 matroska->created = time;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1181 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1182 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1183
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1184 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1185 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1186 "Unknown entry 0x%x in info header\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1187 /* fall-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1188
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1189 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1190 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1191 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1192 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1193
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1194 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1195 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1196 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1197 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1198 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1199
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1200 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1201 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1202
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1203 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1204 matroska_add_stream (MatroskaDemuxContext *matroska)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1205 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1206 int res = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1207 uint32_t id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1208 MatroskaTrack *track;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1209
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1210 av_log(matroska->ctx, AV_LOG_DEBUG, "parsing track, adding stream..,\n");
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1211
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1212 /* Allocate a generic track. As soon as we know its type we'll realloc. */
1832
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
1213 track = av_mallocz(MAX_TRACK_SIZE);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1214 matroska->num_tracks++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1215
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1216 /* start with the master */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1217 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1218 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1219
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1220 /* try reading the trackentry headers */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1221 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1222 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1223 res = AVERROR_IO;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1224 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1225 } else if (matroska->level_up > 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1226 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1227 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1228 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1229
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1230 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1231 /* track number (unique stream ID) */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1232 case MATROSKA_ID_TRACKNUMBER: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1233 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1234 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1235 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1236 track->num = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1237 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1238 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1239
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1240 /* track UID (unique identifier) */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1241 case MATROSKA_ID_TRACKUID: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1242 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1243 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1244 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1245 track->uid = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1246 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1247 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1248
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1249 /* track type (video, audio, combined, subtitle, etc.) */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1250 case MATROSKA_ID_TRACKTYPE: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1251 uint64_t num;
1832
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
1252 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
1253 break;
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
1254 if (track->type && track->type != num) {
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1255 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1256 "More than one tracktype in an entry - skip\n");
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1257 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1258 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1259 track->type = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1260
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1261 switch (track->type) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1262 case MATROSKA_TRACK_TYPE_VIDEO:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1263 case MATROSKA_TRACK_TYPE_AUDIO:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1264 case MATROSKA_TRACK_TYPE_SUBTITLE:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1265 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1266 case MATROSKA_TRACK_TYPE_COMPLEX:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1267 case MATROSKA_TRACK_TYPE_LOGO:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1268 case MATROSKA_TRACK_TYPE_CONTROL:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1269 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1270 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1271 "Unknown or unsupported track type 0x%x\n",
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1272 track->type);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1273 track->type = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1274 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1275 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1276 matroska->tracks[matroska->num_tracks - 1] = track;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1277 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1278 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1279
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1280 /* tracktype specific stuff for video */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1281 case MATROSKA_ID_TRACKVIDEO: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1282 MatroskaVideoTrack *videotrack;
1832
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
1283 if (!track->type)
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
1284 track->type = MATROSKA_TRACK_TYPE_VIDEO;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1285 if (track->type != MATROSKA_TRACK_TYPE_VIDEO) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1286 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1287 "video data in non-video track - ignoring\n");
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1288 res = AVERROR_INVALIDDATA;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1289 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1290 } else if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1291 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1292 videotrack = (MatroskaVideoTrack *)track;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1293
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1294 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1295 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1296 res = AVERROR_IO;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1297 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1298 } else if (matroska->level_up > 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1299 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1300 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1301 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1302
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1303 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1304 /* fixme, this should be one-up, but I get it here */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1305 case MATROSKA_ID_TRACKDEFAULTDURATION: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1306 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1307 if ((res = ebml_read_uint (matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1308 &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1309 break;
1912
98a74cfd12d4 scale duration and default_duration
aurel
parents: 1911
diff changeset
1310 track->default_duration = num/matroska->time_scale;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1311 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1312 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1313
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1314 /* video framerate */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1315 case MATROSKA_ID_VIDEOFRAMERATE: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1316 double num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1317 if ((res = ebml_read_float(matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1318 &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1319 break;
1912
98a74cfd12d4 scale duration and default_duration
aurel
parents: 1911
diff changeset
1320 track->default_duration = 1000000000/(matroska->time_scale*num);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1321 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1322 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1323
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1324 /* width of the size to display the video at */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1325 case MATROSKA_ID_VIDEODISPLAYWIDTH: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1326 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1327 if ((res = ebml_read_uint(matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1328 &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1329 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1330 videotrack->display_width = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1331 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1332 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1333
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1334 /* height of the size to display the video at */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1335 case MATROSKA_ID_VIDEODISPLAYHEIGHT: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1336 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1337 if ((res = ebml_read_uint(matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1338 &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1339 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1340 videotrack->display_height = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1341 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1342 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1343
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1344 /* width of the video in the file */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1345 case MATROSKA_ID_VIDEOPIXELWIDTH: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1346 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1347 if ((res = ebml_read_uint(matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1348 &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1349 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1350 videotrack->pixel_width = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1351 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1352 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1353
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1354 /* height of the video in the file */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1355 case MATROSKA_ID_VIDEOPIXELHEIGHT: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1356 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1357 if ((res = ebml_read_uint(matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1358 &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1359 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1360 videotrack->pixel_height = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1361 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1362 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1363
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1364 /* whether the video is interlaced */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1365 case MATROSKA_ID_VIDEOFLAGINTERLACED: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1366 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1367 if ((res = ebml_read_uint(matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1368 &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1369 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1370 if (num)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1371 track->flags |=
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1372 MATROSKA_VIDEOTRACK_INTERLACED;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1373 else
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1374 track->flags &=
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1375 ~MATROSKA_VIDEOTRACK_INTERLACED;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1376 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1377 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1378
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1379 /* stereo mode (whether the video has two streams,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1380 * where one is for the left eye and the other for
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1381 * the right eye, which creates a 3D-like
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1382 * effect) */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1383 case MATROSKA_ID_VIDEOSTEREOMODE: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1384 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1385 if ((res = ebml_read_uint(matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1386 &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1387 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1388 if (num != MATROSKA_EYE_MODE_MONO &&
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1389 num != MATROSKA_EYE_MODE_LEFT &&
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1390 num != MATROSKA_EYE_MODE_RIGHT &&
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1391 num != MATROSKA_EYE_MODE_BOTH) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1392 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1393 "Ignoring unknown eye mode 0x%x\n",
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1394 (uint32_t) num);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1395 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1396 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1397 videotrack->eye_mode = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1398 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1399 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1400
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1401 /* aspect ratio behaviour */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1402 case MATROSKA_ID_VIDEOASPECTRATIO: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1403 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1404 if ((res = ebml_read_uint(matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1405 &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1406 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1407 if (num != MATROSKA_ASPECT_RATIO_MODE_FREE &&
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1408 num != MATROSKA_ASPECT_RATIO_MODE_KEEP &&
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1409 num != MATROSKA_ASPECT_RATIO_MODE_FIXED) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1410 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1411 "Ignoring unknown aspect ratio 0x%x\n",
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1412 (uint32_t) num);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1413 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1414 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1415 videotrack->ar_mode = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1416 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1417 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1418
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1419 /* colourspace (only matters for raw video)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1420 * fourcc */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1421 case MATROSKA_ID_VIDEOCOLOURSPACE: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1422 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1423 if ((res = ebml_read_uint(matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1424 &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1425 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1426 videotrack->fourcc = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1427 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1428 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1429
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1430 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1431 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1432 "Unknown video track header entry "
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1433 "0x%x - ignoring\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1434 /* pass-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1435
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1436 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1437 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1438 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1439 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1440
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1441 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1442 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1443 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1444 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1445 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1446 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1447 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1448
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1449 /* tracktype specific stuff for audio */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1450 case MATROSKA_ID_TRACKAUDIO: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1451 MatroskaAudioTrack *audiotrack;
1832
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
1452 if (!track->type)
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
1453 track->type = MATROSKA_TRACK_TYPE_AUDIO;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1454 if (track->type != MATROSKA_TRACK_TYPE_AUDIO) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1455 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1456 "audio data in non-audio track - ignoring\n");
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1457 res = AVERROR_INVALIDDATA;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1458 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1459 } else if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1460 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1461 audiotrack = (MatroskaAudioTrack *)track;
1832
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
1462 audiotrack->channels = 1;
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
1463 audiotrack->samplerate = 8000;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1464
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1465 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1466 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1467 res = AVERROR_IO;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1468 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1469 } else if (matroska->level_up > 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1470 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1471 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1472 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1473
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1474 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1475 /* samplerate */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1476 case MATROSKA_ID_AUDIOSAMPLINGFREQ: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1477 double num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1478 if ((res = ebml_read_float(matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1479 &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1480 break;
1467
24c082e20a6a add audio output sampling freqency reading in matroska
aurel
parents: 1465
diff changeset
1481 audiotrack->internal_samplerate =
24c082e20a6a add audio output sampling freqency reading in matroska
aurel
parents: 1465
diff changeset
1482 audiotrack->samplerate = num;
24c082e20a6a add audio output sampling freqency reading in matroska
aurel
parents: 1465
diff changeset
1483 break;
24c082e20a6a add audio output sampling freqency reading in matroska
aurel
parents: 1465
diff changeset
1484 }
24c082e20a6a add audio output sampling freqency reading in matroska
aurel
parents: 1465
diff changeset
1485
24c082e20a6a add audio output sampling freqency reading in matroska
aurel
parents: 1465
diff changeset
1486 case MATROSKA_ID_AUDIOOUTSAMPLINGFREQ: {
24c082e20a6a add audio output sampling freqency reading in matroska
aurel
parents: 1465
diff changeset
1487 double num;
24c082e20a6a add audio output sampling freqency reading in matroska
aurel
parents: 1465
diff changeset
1488 if ((res = ebml_read_float(matroska, &id,
24c082e20a6a add audio output sampling freqency reading in matroska
aurel
parents: 1465
diff changeset
1489 &num)) < 0)
24c082e20a6a add audio output sampling freqency reading in matroska
aurel
parents: 1465
diff changeset
1490 break;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1491 audiotrack->samplerate = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1492 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1493 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1494
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1495 /* bitdepth */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1496 case MATROSKA_ID_AUDIOBITDEPTH: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1497 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1498 if ((res = ebml_read_uint(matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1499 &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1500 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1501 audiotrack->bitdepth = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1502 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1503 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1504
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1505 /* channels */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1506 case MATROSKA_ID_AUDIOCHANNELS: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1507 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1508 if ((res = ebml_read_uint(matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1509 &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1510 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1511 audiotrack->channels = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1512 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1513 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1514
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1515 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1516 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1517 "Unknown audio track header entry "
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1518 "0x%x - ignoring\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1519 /* pass-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1520
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1521 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1522 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1523 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1524 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1525
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1526 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1527 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1528 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1529 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1530 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1531 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1532 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1533
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1534 /* codec identifier */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1535 case MATROSKA_ID_CODECID: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1536 char *text;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1537 if ((res = ebml_read_ascii(matroska, &id, &text)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1538 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1539 track->codec_id = text;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1540 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1541 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1542
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1543 /* codec private data */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1544 case MATROSKA_ID_CODECPRIVATE: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1545 uint8_t *data;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1546 int size;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1547 if ((res = ebml_read_binary(matroska, &id, &data, &size) < 0))
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1548 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1549 track->codec_priv = data;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1550 track->codec_priv_size = size;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1551 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1552 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1553
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1554 /* name of the codec */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1555 case MATROSKA_ID_CODECNAME: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1556 char *text;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1557 if ((res = ebml_read_utf8(matroska, &id, &text)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1558 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1559 track->codec_name = text;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1560 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1561 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1562
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1563 /* name of this track */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1564 case MATROSKA_ID_TRACKNAME: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1565 char *text;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1566 if ((res = ebml_read_utf8(matroska, &id, &text)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1567 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1568 track->name = text;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1569 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1570 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1571
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1572 /* language (matters for audio/subtitles, mostly) */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1573 case MATROSKA_ID_TRACKLANGUAGE: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1574 char *text;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1575 if ((res = ebml_read_utf8(matroska, &id, &text)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1576 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1577 track->language = text;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1578 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1579 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1580
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1581 /* whether this is actually used */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1582 case MATROSKA_ID_TRACKFLAGENABLED: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1583 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1584 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1585 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1586 if (num)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1587 track->flags |= MATROSKA_TRACK_ENABLED;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1588 else
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1589 track->flags &= ~MATROSKA_TRACK_ENABLED;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1590 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1591 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1592
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1593 /* whether it's the default for this track type */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1594 case MATROSKA_ID_TRACKFLAGDEFAULT: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1595 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1596 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1597 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1598 if (num)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1599 track->flags |= MATROSKA_TRACK_DEFAULT;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1600 else
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1601 track->flags &= ~MATROSKA_TRACK_DEFAULT;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1602 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1603 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1604
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1605 /* lacing (like MPEG, where blocks don't end/start on frame
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1606 * boundaries) */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1607 case MATROSKA_ID_TRACKFLAGLACING: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1608 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1609 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1610 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1611 if (num)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1612 track->flags |= MATROSKA_TRACK_LACING;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1613 else
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1614 track->flags &= ~MATROSKA_TRACK_LACING;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1615 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1616 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1617
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1618 /* default length (in time) of one data block in this track */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1619 case MATROSKA_ID_TRACKDEFAULTDURATION: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1620 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1621 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1622 break;
1912
98a74cfd12d4 scale duration and default_duration
aurel
parents: 1911
diff changeset
1623 track->default_duration = num / matroska->time_scale;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1624 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1625 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1626
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1627 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1628 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1629 "Unknown track header entry 0x%x - ignoring\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1630 /* pass-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1631
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1632 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1633 /* we ignore these because they're nothing useful. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1634 case MATROSKA_ID_CODECINFOURL:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1635 case MATROSKA_ID_CODECDOWNLOADURL:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1636 case MATROSKA_ID_TRACKMINCACHE:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1637 case MATROSKA_ID_TRACKMAXCACHE:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1638 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1639 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1640 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1641
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1642 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1643 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1644 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1645 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1646 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1647
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1648 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1649 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1650
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1651 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1652 matroska_parse_tracks (MatroskaDemuxContext *matroska)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1653 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1654 int res = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1655 uint32_t id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1656
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1657 av_log(matroska->ctx, AV_LOG_DEBUG, "parsing tracks...\n");
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1658
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1659 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1660 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1661 res = AVERROR_IO;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1662 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1663 } else if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1664 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1665 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1666 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1667
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1668 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1669 /* one track within the "all-tracks" header */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1670 case MATROSKA_ID_TRACKENTRY:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1671 res = matroska_add_stream(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1672 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1673
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1674 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1675 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1676 "Unknown entry 0x%x in track header\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1677 /* fall-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1678
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1679 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1680 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1681 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1682 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1683
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1684 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1685 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1686 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1687 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1688 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1689
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1690 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1691 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1692
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1693 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1694 matroska_parse_index (MatroskaDemuxContext *matroska)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1695 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1696 int res = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1697 uint32_t id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1698 MatroskaDemuxIndex idx;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1699
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1700 av_log(matroska->ctx, AV_LOG_DEBUG, "parsing index...\n");
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1701
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1702 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1703 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1704 res = AVERROR_IO;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1705 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1706 } else if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1707 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1708 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1709 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1710
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1711 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1712 /* one single index entry ('point') */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1713 case MATROSKA_ID_POINTENTRY:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1714 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1715 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1716
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1717 /* in the end, we hope to fill one entry with a
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1718 * timestamp, a file position and a tracknum */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1719 idx.pos = (uint64_t) -1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1720 idx.time = (uint64_t) -1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1721 idx.track = (uint16_t) -1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1722
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1723 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1724 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1725 res = AVERROR_IO;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1726 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1727 } else if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1728 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1729 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1730 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1731
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1732 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1733 /* one single index entry ('point') */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1734 case MATROSKA_ID_CUETIME: {
1332
7474cc6383d4 fix some signedness warnings
mru
parents: 1172
diff changeset
1735 uint64_t time;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1736 if ((res = ebml_read_uint(matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1737 &time)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1738 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1739 idx.time = time * matroska->time_scale;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1740 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1741 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1742
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 883
diff changeset
1743 /* position in the file + track to which it
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1744 * belongs */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1745 case MATROSKA_ID_CUETRACKPOSITION:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1746 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1747 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1748
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1749 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1750 if (!(id = ebml_peek_id (matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1751 &matroska->level_up))) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1752 res = AVERROR_IO;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1753 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1754 } else if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1755 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1756 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1757 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1758
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1759 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1760 /* track number */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1761 case MATROSKA_ID_CUETRACK: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1762 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1763 if ((res = ebml_read_uint(matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1764 &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1765 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1766 idx.track = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1767 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1768 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1769
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1770 /* position in file */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1771 case MATROSKA_ID_CUECLUSTERPOSITION: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1772 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1773 if ((res = ebml_read_uint(matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1774 &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1775 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1776 idx.pos = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1777 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1778 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1779
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1780 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1781 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1782 "Unknown entry 0x%x in "
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1783 "CuesTrackPositions\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1784 /* fall-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1785
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1786 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1787 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1788 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1789 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1790
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1791 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1792 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1793 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1794 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1795 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1796
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1797 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1798
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1799 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1800 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1801 "Unknown entry 0x%x in cuespoint "
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1802 "index\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1803 /* fall-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1804
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1805 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1806 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1807 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1808 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1809
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1810 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1811 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1812 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1813 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1814 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1815
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1816 /* so let's see if we got what we wanted */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1817 if (idx.pos != (uint64_t) -1 &&
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1818 idx.time != (uint64_t) -1 &&
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1819 idx.track != (uint16_t) -1) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1820 if (matroska->num_indexes % 32 == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1821 /* re-allocate bigger index */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1822 matroska->index =
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1823 av_realloc(matroska->index,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1824 (matroska->num_indexes + 32) *
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1825 sizeof(MatroskaDemuxIndex));
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1826 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1827 matroska->index[matroska->num_indexes] = idx;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1828 matroska->num_indexes++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1829 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1830 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1831
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1832 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1833 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1834 "Unknown entry 0x%x in cues header\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1835 /* fall-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1836
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1837 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1838 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1839 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1840 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1841
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1842 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1843 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1844 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1845 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1846 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1847
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1848 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1849 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1850
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1851 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1852 matroska_parse_metadata (MatroskaDemuxContext *matroska)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1853 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1854 int res = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1855 uint32_t id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1856
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1857 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1858 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1859 res = AVERROR_IO;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1860 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1861 } else if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1862 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1863 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1864 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1865
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1866 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1867 /* Hm, this is unsupported... */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1868 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1869 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1870 "Unknown entry 0x%x in metadata header\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1871 /* fall-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1872
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1873 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1874 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1875 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1876 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1877
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1878 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1879 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1880 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1881 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1882 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1883
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1884 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1885 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1886
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1887 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1888 matroska_parse_seekhead (MatroskaDemuxContext *matroska)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1889 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1890 int res = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1891 uint32_t id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1892
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1893 av_log(matroska->ctx, AV_LOG_DEBUG, "parsing seekhead...\n");
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1894
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1895 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1896 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1897 res = AVERROR_IO;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1898 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1899 } else if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1900 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1901 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1902 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1903
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1904 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1905 case MATROSKA_ID_SEEKENTRY: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1906 uint32_t seek_id = 0, peek_id_cache = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1907 uint64_t seek_pos = (uint64_t) -1, t;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1908
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1909 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1910 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1911
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1912 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1913 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1914 res = AVERROR_IO;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1915 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1916 } else if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1917 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1918 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1919 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1920
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1921 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1922 case MATROSKA_ID_SEEKID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1923 res = ebml_read_uint(matroska, &id, &t);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1924 seek_id = t;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1925 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1926
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1927 case MATROSKA_ID_SEEKPOSITION:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1928 res = ebml_read_uint(matroska, &id, &seek_pos);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1929 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1930
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1931 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1932 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1933 "Unknown seekhead ID 0x%x\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1934 /* fall-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1935
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1936 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1937 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1938 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1939 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1940
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1941 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1942 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1943 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1944 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1945 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1946
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1947 if (!seek_id || seek_pos == (uint64_t) -1) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1948 av_log(matroska->ctx, AV_LOG_INFO,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
1949 "Incomplete seekhead entry (0x%x/%"PRIu64")\n",
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1950 seek_id, seek_pos);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1951 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1952 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1953
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1954 switch (seek_id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1955 case MATROSKA_ID_CUES:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1956 case MATROSKA_ID_TAGS: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1957 uint32_t level_up = matroska->level_up;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1958 offset_t before_pos;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1959 uint64_t length;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1960 MatroskaLevel level;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1961
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1962 /* remember the peeked ID and the current position */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1963 peek_id_cache = matroska->peek_id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1964 before_pos = url_ftell(&matroska->ctx->pb);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1965
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1966 /* seek */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1967 if ((res = ebml_read_seek(matroska, seek_pos +
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1968 matroska->segment_start)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1969 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1970
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1971 /* we don't want to lose our seekhead level, so we add
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1972 * a dummy. This is a crude hack. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1973 if (matroska->num_levels == EBML_MAX_DEPTH) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1974 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1975 "Max EBML element depth (%d) reached, "
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1976 "cannot parse further.\n", EBML_MAX_DEPTH);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1977 return AVERROR_UNKNOWN;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1978 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 883
diff changeset
1979
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1980 level.start = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1981 level.length = (uint64_t)-1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1982 matroska->levels[matroska->num_levels] = level;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1983 matroska->num_levels++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1984
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1985 /* check ID */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1986 if (!(id = ebml_peek_id (matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1987 &matroska->level_up)))
1490
1bf0132b9dff Allows playback of truncated matroska files.
aurel
parents: 1476
diff changeset
1988 goto finish;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1989 if (id != seek_id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1990 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1991 "We looked for ID=0x%x but got "
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
1992 "ID=0x%x (pos=%"PRIu64")",
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1993 seek_id, id, seek_pos +
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1994 matroska->segment_start);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1995 goto finish;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1996 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1997
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1998 /* read master + parse */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1999 if ((res = ebml_read_master(matroska, &id)) < 0)
1490
1bf0132b9dff Allows playback of truncated matroska files.
aurel
parents: 1476
diff changeset
2000 goto finish;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2001 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2002 case MATROSKA_ID_CUES:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2003 if (!(res = matroska_parse_index(matroska)) ||
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2004 url_feof(&matroska->ctx->pb)) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2005 matroska->index_parsed = 1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2006 res = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2007 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2008 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2009 case MATROSKA_ID_TAGS:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2010 if (!(res = matroska_parse_metadata(matroska)) ||
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2011 url_feof(&matroska->ctx->pb)) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2012 matroska->metadata_parsed = 1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2013 res = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2014 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2015 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2016 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2017
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2018 finish:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2019 /* remove dummy level */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2020 while (matroska->num_levels) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2021 matroska->num_levels--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2022 length =
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2023 matroska->levels[matroska->num_levels].length;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2024 if (length == (uint64_t)-1)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2025 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2026 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2027
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2028 /* seek back */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2029 if ((res = ebml_read_seek(matroska, before_pos)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2030 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2031 matroska->peek_id = peek_id_cache;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2032 matroska->level_up = level_up;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2033 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2034 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2035
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2036 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2037 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2038 "Ignoring seekhead entry for ID=0x%x\n",
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2039 seek_id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2040 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2041 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2042
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2043 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2044 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2045
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2046 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2047 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2048 "Unknown seekhead ID 0x%x\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2049 /* fall-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2050
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2051 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2052 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2053 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2054 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2055
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2056 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2057 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2058 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2059 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2060 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2061
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2062 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2063 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2064
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2065 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(*x))
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2066
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2067 static int
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2068 matroska_aac_profile (char *codec_id)
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2069 {
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2070 static const char *aac_profiles[] = {
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2071 "MAIN", "LC", "SSR"
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2072 };
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2073 int profile;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2074
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2075 for (profile=0; profile<ARRAY_SIZE(aac_profiles); profile++)
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2076 if (strstr(codec_id, aac_profiles[profile]))
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2077 break;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2078 return profile + 1;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2079 }
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2080
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2081 static int
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2082 matroska_aac_sri (int samplerate)
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2083 {
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2084 static const int aac_sample_rates[] = {
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2085 96000, 88200, 64000, 48000, 44100, 32000,
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2086 24000, 22050, 16000, 12000, 11025, 8000,
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2087 };
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2088 int sri;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2089
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2090 for (sri=0; sri<ARRAY_SIZE(aac_sample_rates); sri++)
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2091 if (aac_sample_rates[sri] == samplerate)
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2092 break;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2093 return sri;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2094 }
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2095
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2096 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2097 matroska_read_header (AVFormatContext *s,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2098 AVFormatParameters *ap)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2099 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2100 MatroskaDemuxContext *matroska = s->priv_data;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2101 char *doctype;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2102 int version, last_level, res = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2103 uint32_t id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2104
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2105 matroska->ctx = s;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2106
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2107 /* First read the EBML header. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2108 doctype = NULL;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2109 if ((res = ebml_read_header(matroska, &doctype, &version)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2110 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2111 if ((doctype == NULL) || strcmp(doctype, "matroska")) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2112 av_log(matroska->ctx, AV_LOG_ERROR,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2113 "Wrong EBML doctype ('%s' != 'matroska').\n",
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2114 doctype ? doctype : "(none)");
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2115 if (doctype)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2116 av_free(doctype);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2117 return AVERROR_NOFMT;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2118 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2119 av_free(doctype);
1831
bdca904db5e5 add support for simple blocks (ie. matroska v2)
aurel
parents: 1830
diff changeset
2120 if (version > 2) {
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2121 av_log(matroska->ctx, AV_LOG_ERROR,
1831
bdca904db5e5 add support for simple blocks (ie. matroska v2)
aurel
parents: 1830
diff changeset
2122 "Matroska demuxer version 2 too old for file version %d\n",
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2123 version);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2124 return AVERROR_NOFMT;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2125 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2126
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2127 /* The next thing is a segment. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2128 while (1) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2129 if (!(id = ebml_peek_id(matroska, &last_level)))
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2130 return AVERROR_IO;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2131 if (id == MATROSKA_ID_SEGMENT)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2132 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2133
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2134 /* oi! */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2135 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2136 "Expected a Segment ID (0x%x), but received 0x%x!\n",
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2137 MATROSKA_ID_SEGMENT, id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2138 if ((res = ebml_read_skip(matroska)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2139 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2140 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2141
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2142 /* We now have a Matroska segment.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2143 * Seeks are from the beginning of the segment,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2144 * after the segment ID/length. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2145 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2146 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2147 matroska->segment_start = url_ftell(&s->pb);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2148
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2149 matroska->time_scale = 1000000;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2150 /* we've found our segment, start reading the different contents in here */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2151 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2152 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2153 res = AVERROR_IO;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2154 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2155 } else if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2156 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2157 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2158 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2159
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2160 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2161 /* stream info */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2162 case MATROSKA_ID_INFO: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2163 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2164 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2165 res = matroska_parse_info(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2166 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2167 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2168
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2169 /* track info headers */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2170 case MATROSKA_ID_TRACKS: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2171 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2172 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2173 res = matroska_parse_tracks(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2174 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2175 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2176
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2177 /* stream index */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2178 case MATROSKA_ID_CUES: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2179 if (!matroska->index_parsed) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2180 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2181 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2182 res = matroska_parse_index(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2183 } else
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2184 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2185 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2186 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2187
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2188 /* metadata */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2189 case MATROSKA_ID_TAGS: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2190 if (!matroska->metadata_parsed) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2191 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2192 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2193 res = matroska_parse_metadata(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2194 } else
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2195 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2196 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2197 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2198
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2199 /* file index (if seekable, seek to Cues/Tags to parse it) */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2200 case MATROSKA_ID_SEEKHEAD: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2201 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2202 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2203 res = matroska_parse_seekhead(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2204 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2205 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2206
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2207 case MATROSKA_ID_CLUSTER: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2208 /* Do not read the master - this will be done in the next
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2209 * call to matroska_read_packet. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2210 res = 1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2211 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2212 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2213
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2214 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2215 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2216 "Unknown matroska file header ID 0x%x\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2217 /* fall-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2218
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2219 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2220 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2221 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2222 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2223
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2224 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2225 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2226 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2227 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2228 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2229
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2230 /* Have we found a cluster? */
1465
1dccf2603e1d Better way to detect cluster (fix files encoded with Haali's muxer).
aurel
parents: 1459
diff changeset
2231 if (ebml_peek_id(matroska, NULL) == MATROSKA_ID_CLUSTER) {
1024
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
2232 int i, j;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2233 MatroskaTrack *track;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2234 AVStream *st;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2235
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2236 for (i = 0; i < matroska->num_tracks; i++) {
1455
e0e7ac1b8601 Ensure codec_id = CODEC_ID_NONE for unknown codecs (don't reuse previous one).
aurel
parents: 1454
diff changeset
2237 enum CodecID codec_id = CODEC_ID_NONE;
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2238 uint8_t *extradata = NULL;
1024
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
2239 int extradata_size = 0;
1531
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
2240 int extradata_offset = 0;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2241 track = matroska->tracks[i];
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2242
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2243 /* libavformat does not really support subtitles.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2244 * Also apply some sanity checks. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2245 if ((track->type == MATROSKA_TRACK_TYPE_SUBTITLE) ||
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2246 (track->codec_id == NULL))
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2247 continue;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2248
1024
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
2249 for(j=0; codec_tags[j].str; j++){
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2250 if(!strncmp(codec_tags[j].str, track->codec_id,
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2251 strlen(codec_tags[j].str))){
1024
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
2252 codec_id= codec_tags[j].id;
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
2253 break;
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
2254 }
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
2255 }
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
2256
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2257 /* Set the FourCC from the CodecID. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2258 /* This is the MS compatibility mode which stores a
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2259 * BITMAPINFOHEADER in the CodecPrivate. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2260 if (!strcmp(track->codec_id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2261 MATROSKA_CODEC_ID_VIDEO_VFW_FOURCC) &&
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2262 (track->codec_priv_size >= 40) &&
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2263 (track->codec_priv != NULL)) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2264 unsigned char *p;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2265
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2266 /* Offset of biCompression. Stored in LE. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2267 p = (unsigned char *)track->codec_priv + 16;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2268 ((MatroskaVideoTrack *)track)->fourcc = (p[3] << 24) |
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2269 (p[2] << 16) | (p[1] << 8) | p[0];
1897
abbc781d608a use codec_get_id() instead of deprecated codec_get_[bmp/wav]_id()
aurel
parents: 1832
diff changeset
2270 codec_id = codec_get_id(codec_bmp_tags, ((MatroskaVideoTrack *)track)->fourcc);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2271
1024
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
2272 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2273
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2274 /* This is the MS compatibility mode which stores a
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2275 * WAVEFORMATEX in the CodecPrivate. */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 883
diff changeset
2276 else if (!strcmp(track->codec_id,
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2277 MATROSKA_CODEC_ID_AUDIO_ACM) &&
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2278 (track->codec_priv_size >= 18) &&
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2279 (track->codec_priv != NULL)) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2280 unsigned char *p;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2281 uint16_t tag;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2282
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2283 /* Offset of wFormatTag. Stored in LE. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2284 p = (unsigned char *)track->codec_priv;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2285 tag = (p[1] << 8) | p[0];
1897
abbc781d608a use codec_get_id() instead of deprecated codec_get_[bmp/wav]_id()
aurel
parents: 1832
diff changeset
2286 codec_id = codec_get_id(codec_wav_tags, tag);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2287
1024
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
2288 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2289
1904
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
2290 else if (codec_id == CODEC_ID_MPEG1VIDEO ||
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
2291 codec_id == CODEC_ID_MPEG2VIDEO ||
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
2292 codec_id == CODEC_ID_MPEG4 ||
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
2293 codec_id == CODEC_ID_MSMPEG4V3 ||
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
2294 codec_id == CODEC_ID_H264) {
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
2295 track->flags |= MATROSKA_TRACK_REORDER;
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
2296 }
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
2297
1475
a83e86c05295 Add A_AAC codec identifier support in matroska.
aurel
parents: 1472
diff changeset
2298 else if (codec_id == CODEC_ID_AAC && !track->codec_priv_size) {
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2299 MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *) track;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2300 int profile = matroska_aac_profile(track->codec_id);
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2301 int sri = matroska_aac_sri(audiotrack->internal_samplerate);
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2302 extradata = av_malloc(5);
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2303 if (extradata == NULL)
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2304 return AVERROR_NOMEM;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2305 extradata[0] = (profile << 3) | ((sri&0x0E) >> 1);
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2306 extradata[1] = ((sri&0x01) << 7) | (audiotrack->channels<<3);
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2307 if (strstr(track->codec_id, "SBR")) {
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2308 sri = matroska_aac_sri(audiotrack->samplerate);
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2309 extradata[2] = 0x56;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2310 extradata[3] = 0xE5;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2311 extradata[4] = 0x80 | (sri<<3);
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2312 extradata_size = 5;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2313 } else {
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2314 extradata_size = 2;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2315 }
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2316 }
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2317
1534
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2318 else if (codec_id == CODEC_ID_TTA) {
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2319 MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *) track;
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2320 ByteIOContext b;
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2321 extradata_size = 30;
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2322 extradata = av_mallocz(extradata_size);
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2323 if (extradata == NULL)
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2324 return AVERROR_NOMEM;
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2325 init_put_byte(&b, extradata, extradata_size, 1,
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2326 NULL, NULL, NULL, NULL);
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2327 put_buffer(&b, (uint8_t *) "TTA1", 4);
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2328 put_le16(&b, 1);
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2329 put_le16(&b, audiotrack->channels);
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2330 put_le16(&b, audiotrack->bitdepth);
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2331 put_le32(&b, audiotrack->samplerate);
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2332 put_le32(&b, matroska->ctx->duration * audiotrack->samplerate);
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2333 }
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2334
1531
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
2335 else if (codec_id == CODEC_ID_RV10 || codec_id == CODEC_ID_RV20 ||
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
2336 codec_id == CODEC_ID_RV30 || codec_id == CODEC_ID_RV40) {
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
2337 extradata_offset = 26;
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
2338 track->codec_priv_size -= extradata_offset;
1532
4eb3d2701215 matroska: split real video frames so that each packet contains only one slice
aurel
parents: 1531
diff changeset
2339 track->flags |= MATROSKA_TRACK_REAL_V;
1531
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
2340 }
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
2341
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2342 if (codec_id == CODEC_ID_NONE) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2343 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2344 "Unknown/unsupported CodecID %s.\n",
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2345 track->codec_id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2346 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2347
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2348 track->stream_index = matroska->num_streams;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2349
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2350 matroska->num_streams++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2351 st = av_new_stream(s, track->stream_index);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2352 if (st == NULL)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2353 return AVERROR_NOMEM;
1035
4a33428641e1 fixing timebase
michael
parents: 1034
diff changeset
2354 av_set_pts_info(st, 64, matroska->time_scale, 1000*1000*1000); /* 64 bit pts in ns */
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2355
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2356 st->codec->codec_id = codec_id;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2357
1454
d7b946a1ec57 guess matroska files frame rate
aurel
parents: 1452
diff changeset
2358 if (track->default_duration)
d7b946a1ec57 guess matroska files frame rate
aurel
parents: 1452
diff changeset
2359 av_reduce(&st->codec->time_base.num, &st->codec->time_base.den,
1912
98a74cfd12d4 scale duration and default_duration
aurel
parents: 1911
diff changeset
2360 track->default_duration, 1000, 30000);
1454
d7b946a1ec57 guess matroska files frame rate
aurel
parents: 1452
diff changeset
2361
692
b0144ebc71dd H.264 and Vorbis support in matroska patch by (M«©ns Rullg«©rd |mru inprovide com)
michael
parents: 652
diff changeset
2362 if(extradata){
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2363 st->codec->extradata = extradata;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2364 st->codec->extradata_size = extradata_size;
692
b0144ebc71dd H.264 and Vorbis support in matroska patch by (M«©ns Rullg«©rd |mru inprovide com)
michael
parents: 652
diff changeset
2365 } else if(track->codec_priv && track->codec_priv_size > 0){
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2366 st->codec->extradata = av_malloc(track->codec_priv_size);
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2367 if(st->codec->extradata == NULL)
692
b0144ebc71dd H.264 and Vorbis support in matroska patch by (M«©ns Rullg«©rd |mru inprovide com)
michael
parents: 652
diff changeset
2368 return AVERROR_NOMEM;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2369 st->codec->extradata_size = track->codec_priv_size;
1531
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
2370 memcpy(st->codec->extradata,track->codec_priv+extradata_offset,
692
b0144ebc71dd H.264 and Vorbis support in matroska patch by (M«©ns Rullg«©rd |mru inprovide com)
michael
parents: 652
diff changeset
2371 track->codec_priv_size);
b0144ebc71dd H.264 and Vorbis support in matroska patch by (M«©ns Rullg«©rd |mru inprovide com)
michael
parents: 652
diff changeset
2372 }
b0144ebc71dd H.264 and Vorbis support in matroska patch by (M«©ns Rullg«©rd |mru inprovide com)
michael
parents: 652
diff changeset
2373
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2374 if (track->type == MATROSKA_TRACK_TYPE_VIDEO) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2375 MatroskaVideoTrack *videotrack = (MatroskaVideoTrack *)track;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2376
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2377 st->codec->codec_type = CODEC_TYPE_VIDEO;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2378 st->codec->codec_tag = videotrack->fourcc;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2379 st->codec->width = videotrack->pixel_width;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2380 st->codec->height = videotrack->pixel_height;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2381 if (videotrack->display_width == 0)
1021
5661350bf214 fix aspect ratio
michael
parents: 920
diff changeset
2382 videotrack->display_width= videotrack->pixel_width;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2383 if (videotrack->display_height == 0)
1021
5661350bf214 fix aspect ratio
michael
parents: 920
diff changeset
2384 videotrack->display_height= videotrack->pixel_height;
5661350bf214 fix aspect ratio
michael
parents: 920
diff changeset
2385 av_reduce(&st->codec->sample_aspect_ratio.num,
5661350bf214 fix aspect ratio
michael
parents: 920
diff changeset
2386 &st->codec->sample_aspect_ratio.den,
5661350bf214 fix aspect ratio
michael
parents: 920
diff changeset
2387 st->codec->height * videotrack->display_width,
5661350bf214 fix aspect ratio
michael
parents: 920
diff changeset
2388 st->codec-> width * videotrack->display_height,
5661350bf214 fix aspect ratio
michael
parents: 920
diff changeset
2389 255);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2390 } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2391 MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *)track;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2392
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2393 st->codec->codec_type = CODEC_TYPE_AUDIO;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2394 st->codec->sample_rate = audiotrack->samplerate;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2395 st->codec->channels = audiotrack->channels;
1025
95e8458ae120 duration and subitle fix from the patch by Steve Lhomme
michael
parents: 1024
diff changeset
2396 } else if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE) {
95e8458ae120 duration and subitle fix from the patch by Steve Lhomme
michael
parents: 1024
diff changeset
2397 st->codec->codec_type = CODEC_TYPE_SUBTITLE;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2398 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2399
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2400 /* What do we do with private data? E.g. for Vorbis. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2401 }
1465
1dccf2603e1d Better way to detect cluster (fix files encoded with Haali's muxer).
aurel
parents: 1459
diff changeset
2402 res = 0;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2403 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2404
1465
1dccf2603e1d Better way to detect cluster (fix files encoded with Haali's muxer).
aurel
parents: 1459
diff changeset
2405 return res;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2406 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2407
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2408 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2409 matroska_find_track_by_num (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2410 int num)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2411 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2412 int i;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2413
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2414 for (i = 0; i < matroska->num_tracks; i++)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2415 if (matroska->tracks[i]->num == num)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2416 return i;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2417
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2418 return -1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2419 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2420
1532
4eb3d2701215 matroska: split real video frames so that each packet contains only one slice
aurel
parents: 1531
diff changeset
2421 static inline int
4eb3d2701215 matroska: split real video frames so that each packet contains only one slice
aurel
parents: 1531
diff changeset
2422 rv_offset(uint8_t *data, int slice, int slices)
4eb3d2701215 matroska: split real video frames so that each packet contains only one slice
aurel
parents: 1531
diff changeset
2423 {
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1544
diff changeset
2424 return AV_RL32(data+8*slice+4) + 8*slices;
1532
4eb3d2701215 matroska: split real video frames so that each packet contains only one slice
aurel
parents: 1531
diff changeset
2425 }
4eb3d2701215 matroska: split real video frames so that each packet contains only one slice
aurel
parents: 1531
diff changeset
2426
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2427 static int
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2428 matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int size,
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2429 int64_t pos, uint64_t cluster_time,
1902
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
2430 int is_keyframe, int is_bframe,
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
2431 int *ptrack, AVPacket **ppkt)
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2432 {
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2433 int res = 0;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2434 int track;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2435 AVPacket *pkt;
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2436 uint8_t *origdata = data;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2437 int16_t block_time;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2438 uint32_t *lace_size = NULL;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2439 int n, flags, laces = 0;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2440 uint64_t num;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2441
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2442 /* first byte(s): tracknum */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2443 if ((n = matroska_ebmlnum_uint(data, size, &num)) < 0) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2444 av_log(matroska->ctx, AV_LOG_ERROR, "EBML block data error\n");
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2445 av_free(origdata);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2446 return res;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2447 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2448 data += n;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2449 size -= n;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2450
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2451 /* fetch track from num */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2452 track = matroska_find_track_by_num(matroska, num);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2453 if (ptrack) *ptrack = track;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2454 if (size <= 3 || track < 0 || track >= matroska->num_tracks) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2455 av_log(matroska->ctx, AV_LOG_INFO,
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2456 "Invalid stream %d or size %u\n", track, size);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2457 av_free(origdata);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2458 return res;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2459 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2460 if(matroska->ctx->streams[ matroska->tracks[track]->stream_index ]->discard >= AVDISCARD_ALL){
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2461 av_free(origdata);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2462 return res;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2463 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2464
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2465 /* block_time (relative to cluster time) */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2466 block_time = (data[0] << 8) | data[1];
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2467 data += 2;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2468 size -= 2;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2469 flags = *data;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2470 data += 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2471 size -= 1;
1831
bdca904db5e5 add support for simple blocks (ie. matroska v2)
aurel
parents: 1830
diff changeset
2472 if (is_keyframe == -1)
bdca904db5e5 add support for simple blocks (ie. matroska v2)
aurel
parents: 1830
diff changeset
2473 is_keyframe = flags & 1 ? PKT_FLAG_KEY : 0;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2474 switch ((flags & 0x06) >> 1) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2475 case 0x0: /* no lacing */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2476 laces = 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2477 lace_size = av_mallocz(sizeof(int));
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2478 lace_size[0] = size;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2479 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2480
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2481 case 0x1: /* xiph lacing */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2482 case 0x2: /* fixed-size lacing */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2483 case 0x3: /* EBML lacing */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2484 if (size == 0) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2485 res = -1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2486 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2487 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2488 laces = (*data) + 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2489 data += 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2490 size -= 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2491 lace_size = av_mallocz(laces * sizeof(int));
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2492
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2493 switch ((flags & 0x06) >> 1) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2494 case 0x1: /* xiph lacing */ {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2495 uint8_t temp;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2496 uint32_t total = 0;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2497 for (n = 0; res == 0 && n < laces - 1; n++) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2498 while (1) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2499 if (size == 0) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2500 res = -1;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2501 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2502 }
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2503 temp = *data;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2504 lace_size[n] += temp;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2505 data += 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2506 size -= 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2507 if (temp != 0xff)
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2508 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2509 }
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2510 total += lace_size[n];
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2511 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2512 lace_size[n] = size - total;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2513 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2514 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2515
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2516 case 0x2: /* fixed-size lacing */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2517 for (n = 0; n < laces; n++)
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2518 lace_size[n] = size / laces;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2519 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2520
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2521 case 0x3: /* EBML lacing */ {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2522 uint32_t total;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2523 n = matroska_ebmlnum_uint(data, size, &num);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2524 if (n < 0) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2525 av_log(matroska->ctx, AV_LOG_INFO,
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2526 "EBML block data error\n");
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2527 break;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2528 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2529 data += n;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2530 size -= n;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2531 total = lace_size[0] = num;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2532 for (n = 1; res == 0 && n < laces - 1; n++) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2533 int64_t snum;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2534 int r;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2535 r = matroska_ebmlnum_sint (data, size, &snum);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2536 if (r < 0) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2537 av_log(matroska->ctx, AV_LOG_INFO,
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2538 "EBML block data error\n");
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2539 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2540 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2541 data += r;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2542 size -= r;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2543 lace_size[n] = lace_size[n - 1] + snum;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2544 total += lace_size[n];
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2545 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2546 lace_size[n] = size - total;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2547 break;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2548 }
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2549 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2550 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2551 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2552
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2553 if (res == 0) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2554 int real_v = matroska->tracks[track]->flags & MATROSKA_TRACK_REAL_V;
1911
2ce053f3d996 move timecode calculation out of laces loop
aurel
parents: 1905
diff changeset
2555 uint64_t timecode = AV_NOPTS_VALUE;
2ce053f3d996 move timecode calculation out of laces loop
aurel
parents: 1905
diff changeset
2556
2ce053f3d996 move timecode calculation out of laces loop
aurel
parents: 1905
diff changeset
2557 if (cluster_time != (uint64_t)-1 && cluster_time + block_time >= 0)
2ce053f3d996 move timecode calculation out of laces loop
aurel
parents: 1905
diff changeset
2558 timecode = cluster_time + block_time;
2ce053f3d996 move timecode calculation out of laces loop
aurel
parents: 1905
diff changeset
2559
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2560 for (n = 0; n < laces; n++) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2561 int slice, slices = 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2562
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2563 if (real_v) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2564 slices = *data++ + 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2565 lace_size[n]--;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2566 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2567 /* FIXME: duration */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2568
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2569 for (slice=0; slice<slices; slice++) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2570 int slice_size, slice_offset = 0;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2571 if (real_v)
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2572 slice_offset = rv_offset(data, slice, slices);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2573 if (slice+1 == slices)
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2574 slice_size = lace_size[n] - slice_offset;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2575 else
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2576 slice_size = rv_offset(data, slice+1, slices) - slice_offset;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2577 pkt = av_mallocz(sizeof(AVPacket));
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2578 if (ppkt) *ppkt = pkt;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2579 /* XXX: prevent data copy... */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2580 if (av_new_packet(pkt, slice_size) < 0) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2581 res = AVERROR_NOMEM;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2582 n = laces-1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2583 break;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2584 }
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2585 memcpy (pkt->data, data+slice_offset, slice_size);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2586
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2587 if (n == 0)
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2588 pkt->flags = is_keyframe;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2589 pkt->stream_index = matroska->tracks[track]->stream_index;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2590
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2591 pkt->pts = timecode;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2592 pkt->pos = pos;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2593
1904
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
2594 if (matroska->tracks[track]->flags & MATROSKA_TRACK_REORDER)
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
2595 matroska_queue_packet_reordered(matroska, pkt, is_bframe);
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
2596 else
1905
54d1bdcb47e2 cosmetic: indent after last commit
aurel
parents: 1904
diff changeset
2597 matroska_queue_packet(matroska, pkt);
1911
2ce053f3d996 move timecode calculation out of laces loop
aurel
parents: 1905
diff changeset
2598
2ce053f3d996 move timecode calculation out of laces loop
aurel
parents: 1905
diff changeset
2599 timecode = AV_NOPTS_VALUE;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2600 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2601 data += lace_size[n];
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2602 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2603 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2604
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2605 av_free(lace_size);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2606 av_free(origdata);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2607 return res;
1829
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2608 }
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2609
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2610 static int
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2611 matroska_parse_blockgroup (MatroskaDemuxContext *matroska,
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2612 uint64_t cluster_time)
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2613 {
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2614 int res = 0;
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2615 uint32_t id;
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2616 AVPacket *pkt = NULL;
1902
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
2617 int is_bframe = 0;
1829
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2618 int is_keyframe = PKT_FLAG_KEY, last_num_packets = matroska->num_packets;
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2619 uint64_t duration = AV_NOPTS_VALUE;
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2620 int track = -1;
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2621 uint8_t *data;
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2622 int size = 0;
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2623 int64_t pos = 0;
1829
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2624
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2625 av_log(matroska->ctx, AV_LOG_DEBUG, "parsing blockgroup...\n");
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2626
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2627 while (res == 0) {
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2628 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2629 res = AVERROR_IO;
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2630 break;
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2631 } else if (matroska->level_up) {
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2632 matroska->level_up--;
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2633 break;
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2634 }
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2635
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2636 switch (id) {
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2637 /* one block inside the group. Note, block parsing is one
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2638 * of the harder things, so this code is a bit complicated.
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2639 * See http://www.matroska.org/ for documentation. */
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2640 case MATROSKA_ID_BLOCK: {
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2641 pos = url_ftell(&matroska->ctx->pb);
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2642 res = ebml_read_binary(matroska, &id, &data, &size);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2643 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2644 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2645
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2646 case MATROSKA_ID_BLOCKDURATION: {
1456
34d0d965a0d0 Add support for block duration.
aurel
parents: 1455
diff changeset
2647 if ((res = ebml_read_uint(matroska, &id, &duration)) < 0)
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2648 break;
1912
98a74cfd12d4 scale duration and default_duration
aurel
parents: 1911
diff changeset
2649 duration /= matroska->time_scale;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2650 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2651 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2652
1902
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
2653 case MATROSKA_ID_BLOCKREFERENCE: {
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
2654 int64_t num;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2655 /* We've found a reference, so not even the first frame in
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2656 * the lace is a key frame. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2657 is_keyframe = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2658 if (last_num_packets != matroska->num_packets)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2659 matroska->packets[last_num_packets]->flags = 0;
1902
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
2660 if ((res = ebml_read_sint(matroska, &id, &num)) < 0)
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
2661 break;
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
2662 if (num > 0)
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
2663 is_bframe = 1;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2664 break;
1902
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
2665 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2666
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2667 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2668 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2669 "Unknown entry 0x%x in blockgroup data\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2670 /* fall-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2671
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2672 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2673 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2674 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2675 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2676
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2677 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2678 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2679 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2680 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2681 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2682
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2683 if (res)
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2684 return res;
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2685
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2686 if (size > 0)
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2687 res = matroska_parse_block(matroska, data, size, pos, cluster_time,
1902
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
2688 is_keyframe, is_bframe, &track, &pkt);
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2689
1456
34d0d965a0d0 Add support for block duration.
aurel
parents: 1455
diff changeset
2690 if (pkt)
34d0d965a0d0 Add support for block duration.
aurel
parents: 1455
diff changeset
2691 {
34d0d965a0d0 Add support for block duration.
aurel
parents: 1455
diff changeset
2692 if (duration != AV_NOPTS_VALUE)
34d0d965a0d0 Add support for block duration.
aurel
parents: 1455
diff changeset
2693 pkt->duration = duration;
34d0d965a0d0 Add support for block duration.
aurel
parents: 1455
diff changeset
2694 else if (track >= 0 && track < matroska->num_tracks)
1912
98a74cfd12d4 scale duration and default_duration
aurel
parents: 1911
diff changeset
2695 pkt->duration = matroska->tracks[track]->default_duration;
1456
34d0d965a0d0 Add support for block duration.
aurel
parents: 1455
diff changeset
2696 }
34d0d965a0d0 Add support for block duration.
aurel
parents: 1455
diff changeset
2697
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2698 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2699 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2700
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2701 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2702 matroska_parse_cluster (MatroskaDemuxContext *matroska)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2703 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2704 int res = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2705 uint32_t id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2706 uint64_t cluster_time = 0;
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2707 uint8_t *data;
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2708 int64_t pos;
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2709 int size;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2710
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2711 av_log(matroska->ctx, AV_LOG_DEBUG,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
2712 "parsing cluster at %"PRId64"\n", url_ftell(&matroska->ctx->pb));
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2713
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2714 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2715 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2716 res = AVERROR_IO;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2717 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2718 } else if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2719 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2720 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2721 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2722
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2723 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2724 /* cluster timecode */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2725 case MATROSKA_ID_CLUSTERTIMECODE: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2726 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2727 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2728 break;
1035
4a33428641e1 fixing timebase
michael
parents: 1034
diff changeset
2729 cluster_time = num;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2730 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2731 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2732
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2733 /* a group of blocks inside a cluster */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2734 case MATROSKA_ID_BLOCKGROUP:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2735 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2736 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2737 res = matroska_parse_blockgroup(matroska, cluster_time);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2738 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2739
1831
bdca904db5e5 add support for simple blocks (ie. matroska v2)
aurel
parents: 1830
diff changeset
2740 case MATROSKA_ID_SIMPLEBLOCK:
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2741 pos = url_ftell(&matroska->ctx->pb);
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2742 res = ebml_read_binary(matroska, &id, &data, &size);
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2743 if (res == 0)
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2744 res = matroska_parse_block(matroska, data, size, pos,
1902
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
2745 cluster_time, -1,0, NULL, NULL);
1831
bdca904db5e5 add support for simple blocks (ie. matroska v2)
aurel
parents: 1830
diff changeset
2746 break;
bdca904db5e5 add support for simple blocks (ie. matroska v2)
aurel
parents: 1830
diff changeset
2747
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2748 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2749 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2750 "Unknown entry 0x%x in cluster data\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2751 /* fall-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2752
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2753 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2754 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2755 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2756 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2757
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2758 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2759 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2760 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2761 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2762 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2763
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2764 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2765 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2766
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2767 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2768 matroska_read_packet (AVFormatContext *s,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2769 AVPacket *pkt)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2770 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2771 MatroskaDemuxContext *matroska = s->priv_data;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2772 int res = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2773 uint32_t id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2774
1899
1324ae790ee0 parse clusters until some packets are queued
aurel
parents: 1898
diff changeset
2775 /* Read stream until we have a packet queued. */
1324ae790ee0 parse clusters until some packets are queued
aurel
parents: 1898
diff changeset
2776 while (matroska_deliver_packet(matroska, pkt)) {
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2777
1900
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2778 /* Have we already reached the end? */
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2779 if (matroska->done)
1899
1324ae790ee0 parse clusters until some packets are queued
aurel
parents: 1898
diff changeset
2780 return AVERROR_IO;
1900
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2781
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2782 while (res == 0) {
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2783 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2784 return AVERROR_IO;
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2785 } else if (matroska->level_up) {
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2786 matroska->level_up--;
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2787 break;
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2788 }
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2789
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2790 switch (id) {
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2791 case MATROSKA_ID_CLUSTER:
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2792 if ((res = ebml_read_master(matroska, &id)) < 0)
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2793 break;
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2794 if ((res = matroska_parse_cluster(matroska)) == 0)
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2795 res = 1; /* Parsed one cluster, let's get out. */
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2796 break;
1900
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2797
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2798 default:
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2799 case EBML_ID_VOID:
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2800 res = ebml_read_skip(matroska);
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2801 break;
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2802 }
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2803
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2804 if (matroska->level_up) {
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2805 matroska->level_up--;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2806 break;
1900
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2807 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2808 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2809
1900
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2810 if (res == -1)
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2811 matroska->done = 1;
1899
1324ae790ee0 parse clusters until some packets are queued
aurel
parents: 1898
diff changeset
2812 }
1324ae790ee0 parse clusters until some packets are queued
aurel
parents: 1898
diff changeset
2813
1324ae790ee0 parse clusters until some packets are queued
aurel
parents: 1898
diff changeset
2814 return 0;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2815 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2816
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2817 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2818 matroska_read_close (AVFormatContext *s)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2819 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2820 MatroskaDemuxContext *matroska = s->priv_data;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2821 int n = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2822
1458
7d13d9e4d783 cosmetics: reindent after last commit
aurel
parents: 1457
diff changeset
2823 av_free(matroska->writing_app);
7d13d9e4d783 cosmetics: reindent after last commit
aurel
parents: 1457
diff changeset
2824 av_free(matroska->muxing_app);
7d13d9e4d783 cosmetics: reindent after last commit
aurel
parents: 1457
diff changeset
2825 av_free(matroska->index);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2826
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2827 if (matroska->packets != NULL) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2828 for (n = 0; n < matroska->num_packets; n++) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2829 av_free_packet(matroska->packets[n]);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2830 av_free(matroska->packets[n]);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2831 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2832 av_free(matroska->packets);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2833 }
1904
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
2834 if (matroska->packets_reorder) {
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
2835 for (n = 0; n < matroska->num_packets_reorder; n++) {
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
2836 av_free_packet(matroska->packets_reorder[n]);
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
2837 av_free(matroska->packets_reorder[n]);
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
2838 }
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
2839 av_free(matroska->packets_reorder);
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
2840 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2841
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2842 for (n = 0; n < matroska->num_tracks; n++) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2843 MatroskaTrack *track = matroska->tracks[n];
1458
7d13d9e4d783 cosmetics: reindent after last commit
aurel
parents: 1457
diff changeset
2844 av_free(track->codec_id);
7d13d9e4d783 cosmetics: reindent after last commit
aurel
parents: 1457
diff changeset
2845 av_free(track->codec_name);
7d13d9e4d783 cosmetics: reindent after last commit
aurel
parents: 1457
diff changeset
2846 av_free(track->codec_priv);
7d13d9e4d783 cosmetics: reindent after last commit
aurel
parents: 1457
diff changeset
2847 av_free(track->name);
7d13d9e4d783 cosmetics: reindent after last commit
aurel
parents: 1457
diff changeset
2848 av_free(track->language);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2849
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2850 av_free(track);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2851 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2852
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2853 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2854 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2855
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
2856 AVInputFormat matroska_demuxer = {
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2857 "matroska",
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2858 "Matroska file format",
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2859 sizeof(MatroskaDemuxContext),
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2860 matroska_probe,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2861 matroska_read_header,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2862 matroska_read_packet,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2863 matroska_read_close,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2864 };