annotate matroskadec.c @ 3661:7cba55954d0e libavformat

matroskadec: remove some useless empty lines
author aurel
date Tue, 05 Aug 2008 00:41:28 +0000
parents 503366e5ae28
children 7222dc75f80e
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 /**
2175
9438e2e7faf2 Fix @file in matroskadec.c, it was still matroska.c
reimar
parents: 2147
diff changeset
23 * @file matroskadec.c
380
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"
3601
c0955bfc27be matroska: add support for V_QUICKTIME track type
aurel
parents: 3495
diff changeset
34 #include "isom.h"
2142
3aa1f0f698de split some common code from the mkv demuxer that will be useful to the muxer
aurel
parents: 2023
diff changeset
35 #include "matroska.h"
3201
1a16b069daca use common aac sample rate tables
aurel
parents: 3199
diff changeset
36 #include "libavcodec/mpeg4audio.h"
3286
6f61c3b36632 Use full path for #includes from another directory.
diego
parents: 3283
diff changeset
37 #include "libavutil/intfloat_readwrite.h"
3628
5f2e1da55755 matroskadec: use more robust av_strlcpy() instead of strcpy()
aurel
parents: 3601
diff changeset
38 #include "libavutil/avstring.h"
3281
a1d98736c15e matroskadec: add support for lzo compressed tracks
aurel
parents: 3280
diff changeset
39 #include "libavutil/lzo.h"
3293
d3818f6d7530 matroskadec: add support for zlib compressed tracks
aurel
parents: 3290
diff changeset
40 #ifdef CONFIG_ZLIB
d3818f6d7530 matroskadec: add support for zlib compressed tracks
aurel
parents: 3290
diff changeset
41 #include <zlib.h>
d3818f6d7530 matroskadec: add support for zlib compressed tracks
aurel
parents: 3290
diff changeset
42 #endif
3298
edabe3db2b6e matroskadec: add support for bzlib compressed tracks
aurel
parents: 3294
diff changeset
43 #ifdef CONFIG_BZLIB
edabe3db2b6e matroskadec: add support for bzlib compressed tracks
aurel
parents: 3294
diff changeset
44 #include <bzlib.h>
edabe3db2b6e matroskadec: add support for bzlib compressed tracks
aurel
parents: 3294
diff changeset
45 #endif
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
46
3632
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
47 typedef enum {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
48 EBML_NONE,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
49 EBML_UINT,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
50 EBML_FLOAT,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
51 EBML_STR,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
52 EBML_UTF8,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
53 EBML_BIN,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
54 EBML_NEST,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
55 EBML_PASS,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
56 EBML_STOP,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
57 } EbmlType;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
58
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
59 typedef const struct EbmlSyntax {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
60 uint32_t id;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
61 EbmlType type;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
62 int list_elem_size;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
63 int data_offset;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
64 union {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
65 uint64_t u;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
66 double f;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
67 const char *s;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
68 const struct EbmlSyntax *n;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
69 } def;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
70 } EbmlSyntax;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
71
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
72 typedef struct {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
73 int nb_elem;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
74 void *elem;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
75 } EbmlList;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
76
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
77 typedef struct {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
78 int size;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
79 uint8_t *data;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
80 int64_t pos;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
81 } EbmlBin;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
82
3633
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
83 typedef struct {
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
84 uint64_t version;
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
85 uint64_t max_size;
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
86 uint64_t id_length;
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
87 char *doctype;
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
88 uint64_t doctype_version;
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
89 } Ebml;
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
90
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
91 typedef struct {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
92 uint64_t algo;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
93 EbmlBin settings;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
94 } MatroskaTrackCompression;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
95
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
96 typedef struct {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
97 uint64_t scope;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
98 uint64_t type;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
99 MatroskaTrackCompression compression;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
100 } MatroskaTrackEncoding;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
101
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
102 typedef struct {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
103 double frame_rate;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
104 uint64_t display_width;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
105 uint64_t display_height;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
106 uint64_t pixel_width;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
107 uint64_t pixel_height;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
108 uint64_t fourcc;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
109 } MatroskaTrackVideo;
2147
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
110
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
111 typedef struct {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
112 double samplerate;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
113 double out_samplerate;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
114 uint64_t bitdepth;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
115 uint64_t channels;
2147
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
116
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
117 /* real audio header (extracted from extradata) */
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
118 int coded_framesize;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
119 int sub_packet_h;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
120 int frame_size;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
121 int sub_packet_size;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
122 int sub_packet_cnt;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
123 int pkt_cnt;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
124 uint8_t *buf;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
125 } MatroskaTrackAudio;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
126
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
127 typedef struct {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
128 uint64_t num;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
129 uint64_t type;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
130 char *codec_id;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
131 EbmlBin codec_priv;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
132 char *language;
3408
da09478c97ce matroskadec: read TrackTimecodeScale and set timebase accordingly
aurel
parents: 3407
diff changeset
133 double time_scale;
1912
98a74cfd12d4 scale duration and default_duration
aurel
parents: 1911
diff changeset
134 uint64_t default_duration;
3630
23666678a608 matroskadec: simplify flag default
aurel
parents: 3629
diff changeset
135 uint64_t flag_default;
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
136 MatroskaTrackVideo video;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
137 MatroskaTrackAudio audio;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
138 EbmlList encodings;
3634
f206f746ff61 matroskadec: store an AVStream pointer instead of a stream index
aurel
parents: 3633
diff changeset
139
f206f746ff61 matroskadec: store an AVStream pointer instead of a stream index
aurel
parents: 3633
diff changeset
140 AVStream *stream;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
141 } MatroskaTrack;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
142
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
143 typedef struct {
3640
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
144 char *filename;
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
145 char *mime;
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
146 EbmlBin bin;
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
147 } MatroskaAttachement;
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
148
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
149 typedef struct {
3639
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
150 uint64_t start;
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
151 uint64_t end;
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
152 uint64_t uid;
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
153 char *title;
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
154 } MatroskaChapter;
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
155
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
156 typedef struct {
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
157 uint64_t track;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
158 uint64_t pos;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
159 } MatroskaIndexPos;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
160
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
161 typedef struct {
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
162 uint64_t time;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
163 EbmlList pos;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
164 } MatroskaIndex;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
165
3644
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
166 typedef struct {
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
167 uint64_t id;
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
168 uint64_t pos;
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
169 } MatroskaSeekhead;
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
170
3658
04ffed56f400 matroskadec: remove unused struct name
aurel
parents: 3657
diff changeset
171 typedef struct {
2147
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
172 uint64_t start;
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
173 uint64_t length;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
174 } MatroskaLevel;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
175
3658
04ffed56f400 matroskadec: remove unused struct name
aurel
parents: 3657
diff changeset
176 typedef struct {
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
177 AVFormatContext *ctx;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
178
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
179 /* ebml stuff */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
180 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
181 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
182 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
183
3641
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
184 uint64_t time_scale;
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
185 double duration;
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
186 char *title;
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
187 EbmlList tracks;
3640
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
188 EbmlList attachments;
3639
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
189 EbmlList chapters;
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
190 EbmlList index;
3644
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
191 EbmlList seekhead;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
192
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
193 /* 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
194 * for ( = that are available to the calling program). */
2147
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
195 int num_streams;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
196
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
197 /* 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
198 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
199
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
200 /* 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
201 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
202
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
203 /* 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
204 AVPacket **packets;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
205 int num_packets;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
206
2147
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
207 int done;
3651
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
208 int has_cluster_id;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
209
2014
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
210 /* What to skip before effectively reading a packet. */
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
211 int skip_to_keyframe;
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
212 AVStream *skip_to_stream;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
213 } MatroskaDemuxContext;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
214
3653
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
215 typedef struct {
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
216 uint64_t duration;
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
217 int64_t reference;
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
218 EbmlBin bin;
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
219 } MatroskaBlock;
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
220
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
221 typedef struct {
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
222 uint64_t timecode;
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
223 EbmlList blocks;
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
224 } MatroskaCluster;
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
225
3413
b7f86452706e matroskadec: move ARRAY_SIZE() macro at top of the file
aurel
parents: 3409
diff changeset
226 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(*x))
b7f86452706e matroskadec: move ARRAY_SIZE() macro at top of the file
aurel
parents: 3409
diff changeset
227
3633
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
228 static EbmlSyntax ebml_header[] = {
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
229 { EBML_ID_EBMLREADVERSION, EBML_UINT, 0, offsetof(Ebml,version), {.u=EBML_VERSION} },
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
230 { EBML_ID_EBMLMAXSIZELENGTH, EBML_UINT, 0, offsetof(Ebml,max_size), {.u=8} },
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
231 { EBML_ID_EBMLMAXIDLENGTH, EBML_UINT, 0, offsetof(Ebml,id_length), {.u=4} },
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
232 { EBML_ID_DOCTYPE, EBML_STR, 0, offsetof(Ebml,doctype), {.s="(none)"} },
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
233 { EBML_ID_DOCTYPEREADVERSION, EBML_UINT, 0, offsetof(Ebml,doctype_version), {.u=1} },
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
234 { EBML_ID_EBMLVERSION, EBML_NONE },
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
235 { EBML_ID_DOCTYPEVERSION, EBML_NONE },
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
236 { EBML_ID_VOID, EBML_NONE },
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
237 { 0 }
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
238 };
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
239
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
240 static EbmlSyntax ebml_syntax[] = {
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
241 { EBML_ID_HEADER, EBML_NEST, 0, 0, {.n=ebml_header} },
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
242 { 0 }
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
243 };
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
244
3641
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
245 static EbmlSyntax matroska_info[] = {
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
246 { MATROSKA_ID_TIMECODESCALE, EBML_UINT, 0, offsetof(MatroskaDemuxContext,time_scale), {.u=1000000} },
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
247 { MATROSKA_ID_DURATION, EBML_FLOAT, 0, offsetof(MatroskaDemuxContext,duration) },
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
248 { MATROSKA_ID_TITLE, EBML_UTF8, 0, offsetof(MatroskaDemuxContext,title) },
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
249 { MATROSKA_ID_WRITINGAPP, EBML_NONE },
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
250 { MATROSKA_ID_MUXINGAPP, EBML_NONE },
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
251 { MATROSKA_ID_DATEUTC, EBML_NONE },
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
252 { MATROSKA_ID_SEGMENTUID, EBML_NONE },
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
253 { EBML_ID_VOID, EBML_NONE },
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
254 { 0 }
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
255 };
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
256
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
257 static EbmlSyntax matroska_track_video[] = {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
258 { MATROSKA_ID_VIDEOFRAMERATE, EBML_FLOAT,0, offsetof(MatroskaTrackVideo,frame_rate) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
259 { MATROSKA_ID_VIDEODISPLAYWIDTH, EBML_UINT, 0, offsetof(MatroskaTrackVideo,display_width) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
260 { MATROSKA_ID_VIDEODISPLAYHEIGHT, EBML_UINT, 0, offsetof(MatroskaTrackVideo,display_height) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
261 { MATROSKA_ID_VIDEOPIXELWIDTH, EBML_UINT, 0, offsetof(MatroskaTrackVideo,pixel_width) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
262 { MATROSKA_ID_VIDEOPIXELHEIGHT, EBML_UINT, 0, offsetof(MatroskaTrackVideo,pixel_height) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
263 { MATROSKA_ID_VIDEOCOLORSPACE, EBML_UINT, 0, offsetof(MatroskaTrackVideo,fourcc) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
264 { MATROSKA_ID_VIDEOFLAGINTERLACED,EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
265 { MATROSKA_ID_VIDEOSTEREOMODE, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
266 { MATROSKA_ID_VIDEOASPECTRATIO, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
267 { EBML_ID_VOID, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
268 { 0 }
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
269 };
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
270
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
271 static EbmlSyntax matroska_track_audio[] = {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
272 { MATROSKA_ID_AUDIOSAMPLINGFREQ, EBML_FLOAT,0, offsetof(MatroskaTrackAudio,samplerate), {.f=8000.0} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
273 { MATROSKA_ID_AUDIOOUTSAMPLINGFREQ,EBML_FLOAT,0,offsetof(MatroskaTrackAudio,out_samplerate) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
274 { MATROSKA_ID_AUDIOBITDEPTH, EBML_UINT, 0, offsetof(MatroskaTrackAudio,bitdepth) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
275 { MATROSKA_ID_AUDIOCHANNELS, EBML_UINT, 0, offsetof(MatroskaTrackAudio,channels), {.u=1} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
276 { EBML_ID_VOID, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
277 { 0 }
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
278 };
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
279
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
280 static EbmlSyntax matroska_track_encoding_compression[] = {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
281 { MATROSKA_ID_ENCODINGCOMPALGO, EBML_UINT, 0, offsetof(MatroskaTrackCompression,algo), {.u=0} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
282 { MATROSKA_ID_ENCODINGCOMPSETTINGS,EBML_BIN, 0, offsetof(MatroskaTrackCompression,settings) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
283 { EBML_ID_VOID, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
284 { 0 }
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
285 };
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
286
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
287 static EbmlSyntax matroska_track_encoding[] = {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
288 { MATROSKA_ID_ENCODINGSCOPE, EBML_UINT, 0, offsetof(MatroskaTrackEncoding,scope), {.u=1} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
289 { MATROSKA_ID_ENCODINGTYPE, EBML_UINT, 0, offsetof(MatroskaTrackEncoding,type), {.u=0} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
290 { MATROSKA_ID_ENCODINGCOMPRESSION,EBML_NEST, 0, offsetof(MatroskaTrackEncoding,compression), {.n=matroska_track_encoding_compression} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
291 { EBML_ID_VOID, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
292 { 0 }
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
293 };
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
294
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
295 static EbmlSyntax matroska_track_encodings[] = {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
296 { MATROSKA_ID_TRACKCONTENTENCODING, EBML_NEST, sizeof(MatroskaTrackEncoding), offsetof(MatroskaTrack,encodings), {.n=matroska_track_encoding} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
297 { EBML_ID_VOID, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
298 { 0 }
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
299 };
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
300
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
301 static EbmlSyntax matroska_track[] = {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
302 { MATROSKA_ID_TRACKNUMBER, EBML_UINT, 0, offsetof(MatroskaTrack,num) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
303 { MATROSKA_ID_TRACKTYPE, EBML_UINT, 0, offsetof(MatroskaTrack,type) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
304 { MATROSKA_ID_CODECID, EBML_STR, 0, offsetof(MatroskaTrack,codec_id) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
305 { MATROSKA_ID_CODECPRIVATE, EBML_BIN, 0, offsetof(MatroskaTrack,codec_priv) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
306 { MATROSKA_ID_TRACKLANGUAGE, EBML_UTF8, 0, offsetof(MatroskaTrack,language), {.s="eng"} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
307 { MATROSKA_ID_TRACKDEFAULTDURATION, EBML_UINT, 0, offsetof(MatroskaTrack,default_duration) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
308 { MATROSKA_ID_TRACKTIMECODESCALE, EBML_FLOAT,0, offsetof(MatroskaTrack,time_scale), {.f=1.0} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
309 { MATROSKA_ID_TRACKFLAGDEFAULT, EBML_UINT, 0, offsetof(MatroskaTrack,flag_default), {.u=1} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
310 { MATROSKA_ID_TRACKVIDEO, EBML_NEST, 0, offsetof(MatroskaTrack,video), {.n=matroska_track_video} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
311 { MATROSKA_ID_TRACKAUDIO, EBML_NEST, 0, offsetof(MatroskaTrack,audio), {.n=matroska_track_audio} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
312 { MATROSKA_ID_TRACKCONTENTENCODINGS,EBML_NEST, 0, 0, {.n=matroska_track_encodings} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
313 { MATROSKA_ID_TRACKUID, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
314 { MATROSKA_ID_TRACKNAME, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
315 { MATROSKA_ID_TRACKFLAGENABLED, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
316 { MATROSKA_ID_TRACKFLAGFORCED, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
317 { MATROSKA_ID_TRACKFLAGLACING, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
318 { MATROSKA_ID_CODECNAME, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
319 { MATROSKA_ID_CODECDECODEALL, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
320 { MATROSKA_ID_CODECINFOURL, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
321 { MATROSKA_ID_CODECDOWNLOADURL, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
322 { MATROSKA_ID_TRACKMINCACHE, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
323 { MATROSKA_ID_TRACKMAXCACHE, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
324 { EBML_ID_VOID, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
325 { 0 }
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
326 };
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
327
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
328 static EbmlSyntax matroska_tracks[] = {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
329 { MATROSKA_ID_TRACKENTRY, EBML_NEST, sizeof(MatroskaTrack), offsetof(MatroskaDemuxContext,tracks), {.n=matroska_track} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
330 { EBML_ID_VOID, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
331 { 0 }
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
332 };
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
333
3640
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
334 static EbmlSyntax matroska_attachment[] = {
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
335 { MATROSKA_ID_FILENAME, EBML_UTF8, 0, offsetof(MatroskaAttachement,filename) },
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
336 { MATROSKA_ID_FILEMIMETYPE, EBML_STR, 0, offsetof(MatroskaAttachement,mime) },
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
337 { MATROSKA_ID_FILEDATA, EBML_BIN, 0, offsetof(MatroskaAttachement,bin) },
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
338 { MATROSKA_ID_FILEUID, EBML_NONE },
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
339 { EBML_ID_VOID, EBML_NONE },
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
340 { 0 }
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
341 };
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
342
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
343 static EbmlSyntax matroska_attachments[] = {
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
344 { MATROSKA_ID_ATTACHEDFILE, EBML_NEST, sizeof(MatroskaAttachement), offsetof(MatroskaDemuxContext,attachments), {.n=matroska_attachment} },
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
345 { EBML_ID_VOID, EBML_NONE },
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
346 { 0 }
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
347 };
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
348
3639
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
349 static EbmlSyntax matroska_chapter_display[] = {
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
350 { MATROSKA_ID_CHAPSTRING, EBML_UTF8, 0, offsetof(MatroskaChapter,title) },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
351 { EBML_ID_VOID, EBML_NONE },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
352 { 0 }
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
353 };
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
354
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
355 static EbmlSyntax matroska_chapter_entry[] = {
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
356 { MATROSKA_ID_CHAPTERTIMESTART, EBML_UINT, 0, offsetof(MatroskaChapter,start), {.u=AV_NOPTS_VALUE} },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
357 { MATROSKA_ID_CHAPTERTIMEEND, EBML_UINT, 0, offsetof(MatroskaChapter,end), {.u=AV_NOPTS_VALUE} },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
358 { MATROSKA_ID_CHAPTERUID, EBML_UINT, 0, offsetof(MatroskaChapter,uid) },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
359 { MATROSKA_ID_CHAPTERDISPLAY, EBML_NEST, 0, 0, {.n=matroska_chapter_display} },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
360 { MATROSKA_ID_CHAPTERFLAGHIDDEN, EBML_NONE },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
361 { EBML_ID_VOID, EBML_NONE },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
362 { 0 }
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
363 };
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
364
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
365 static EbmlSyntax matroska_chapter[] = {
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
366 { MATROSKA_ID_CHAPTERATOM, EBML_NEST, sizeof(MatroskaChapter), offsetof(MatroskaDemuxContext,chapters), {.n=matroska_chapter_entry} },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
367 { MATROSKA_ID_EDITIONUID, EBML_NONE },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
368 { MATROSKA_ID_EDITIONFLAGHIDDEN, EBML_NONE },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
369 { MATROSKA_ID_EDITIONFLAGDEFAULT, EBML_NONE },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
370 { EBML_ID_VOID, EBML_NONE },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
371 { 0 }
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
372 };
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
373
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
374 static EbmlSyntax matroska_chapters[] = {
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
375 { MATROSKA_ID_EDITIONENTRY, EBML_NEST, 0, 0, {.n=matroska_chapter} },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
376 { EBML_ID_VOID, EBML_NONE },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
377 { 0 }
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
378 };
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
379
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
380 static EbmlSyntax matroska_index_pos[] = {
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
381 { MATROSKA_ID_CUETRACK, EBML_UINT, 0, offsetof(MatroskaIndexPos,track) },
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
382 { MATROSKA_ID_CUECLUSTERPOSITION, EBML_UINT, 0, offsetof(MatroskaIndexPos,pos) },
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
383 { EBML_ID_VOID, EBML_NONE },
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
384 { 0 }
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
385 };
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
386
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
387 static EbmlSyntax matroska_index_entry[] = {
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
388 { MATROSKA_ID_CUETIME, EBML_UINT, 0, offsetof(MatroskaIndex,time) },
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
389 { MATROSKA_ID_CUETRACKPOSITION, EBML_NEST, sizeof(MatroskaIndexPos), offsetof(MatroskaIndex,pos), {.n=matroska_index_pos} },
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
390 { EBML_ID_VOID, EBML_NONE },
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
391 { 0 }
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
392 };
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
393
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
394 static EbmlSyntax matroska_index[] = {
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
395 { MATROSKA_ID_POINTENTRY, EBML_NEST, sizeof(MatroskaIndex), offsetof(MatroskaDemuxContext,index), {.n=matroska_index_entry} },
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
396 { EBML_ID_VOID, EBML_NONE },
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
397 { 0 }
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
398 };
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
399
3638
5897e0c8a1eb matroskadec: use generic parser to parse tags
aurel
parents: 3637
diff changeset
400 static EbmlSyntax matroska_tags[] = {
5897e0c8a1eb matroskadec: use generic parser to parse tags
aurel
parents: 3637
diff changeset
401 { EBML_ID_VOID, EBML_NONE },
5897e0c8a1eb matroskadec: use generic parser to parse tags
aurel
parents: 3637
diff changeset
402 { 0 }
5897e0c8a1eb matroskadec: use generic parser to parse tags
aurel
parents: 3637
diff changeset
403 };
5897e0c8a1eb matroskadec: use generic parser to parse tags
aurel
parents: 3637
diff changeset
404
3644
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
405 static EbmlSyntax matroska_seekhead_entry[] = {
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
406 { MATROSKA_ID_SEEKID, EBML_UINT, 0, offsetof(MatroskaSeekhead,id) },
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
407 { MATROSKA_ID_SEEKPOSITION, EBML_UINT, 0, offsetof(MatroskaSeekhead,pos), {.u=-1} },
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
408 { EBML_ID_VOID, EBML_NONE },
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
409 { 0 }
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
410 };
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
411
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
412 static EbmlSyntax matroska_seekhead[] = {
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
413 { MATROSKA_ID_SEEKENTRY, EBML_NEST, sizeof(MatroskaSeekhead), offsetof(MatroskaDemuxContext,seekhead), {.n=matroska_seekhead_entry} },
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
414 { EBML_ID_VOID, EBML_NONE },
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
415 { 0 }
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
416 };
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
417
3651
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
418 static EbmlSyntax matroska_segment[] = {
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
419 { MATROSKA_ID_INFO, EBML_NEST, 0, 0, {.n=matroska_info } },
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
420 { MATROSKA_ID_TRACKS, EBML_NEST, 0, 0, {.n=matroska_tracks } },
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
421 { MATROSKA_ID_ATTACHMENTS, EBML_NEST, 0, 0, {.n=matroska_attachments} },
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
422 { MATROSKA_ID_CHAPTERS, EBML_NEST, 0, 0, {.n=matroska_chapters } },
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
423 { MATROSKA_ID_CUES, EBML_NEST, 0, 0, {.n=matroska_index } },
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
424 { MATROSKA_ID_TAGS, EBML_NEST, 0, 0, {.n=matroska_tags } },
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
425 { MATROSKA_ID_SEEKHEAD, EBML_NEST, 0, 0, {.n=matroska_seekhead } },
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
426 { MATROSKA_ID_CLUSTER, EBML_STOP, 0, offsetof(MatroskaDemuxContext,has_cluster_id) },
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
427 { EBML_ID_VOID, EBML_NONE },
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
428 { 0 }
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
429 };
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
430
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
431 static EbmlSyntax matroska_segments[] = {
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
432 { MATROSKA_ID_SEGMENT, EBML_NEST, 0, 0, {.n=matroska_segment } },
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
433 { 0 }
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
434 };
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
435
3653
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
436 static EbmlSyntax matroska_blockgroup[] = {
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
437 { MATROSKA_ID_BLOCK, EBML_BIN, 0, offsetof(MatroskaBlock,bin) },
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
438 { MATROSKA_ID_SIMPLEBLOCK, EBML_BIN, 0, offsetof(MatroskaBlock,bin) },
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
439 { MATROSKA_ID_BLOCKDURATION, EBML_UINT, 0, offsetof(MatroskaBlock,duration), {.u=AV_NOPTS_VALUE} },
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
440 { MATROSKA_ID_BLOCKREFERENCE, EBML_UINT, 0, offsetof(MatroskaBlock,reference) },
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
441 { EBML_ID_VOID, EBML_NONE },
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
442 { 0 }
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
443 };
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
444
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
445 static EbmlSyntax matroska_cluster[] = {
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
446 { MATROSKA_ID_CLUSTERTIMECODE,EBML_UINT,0, offsetof(MatroskaCluster,timecode) },
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
447 { MATROSKA_ID_BLOCKGROUP, EBML_NEST, sizeof(MatroskaBlock), offsetof(MatroskaCluster,blocks), {.n=matroska_blockgroup} },
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
448 { MATROSKA_ID_SIMPLEBLOCK, EBML_PASS, sizeof(MatroskaBlock), offsetof(MatroskaCluster,blocks), {.n=matroska_blockgroup} },
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
449 { EBML_ID_VOID, EBML_NONE },
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
450 { 0 }
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
451 };
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
452
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
453 static EbmlSyntax matroska_clusters[] = {
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
454 { MATROSKA_ID_CLUSTER, EBML_NEST, 0, 0, {.n=matroska_cluster} },
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
455 { 0 }
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
456 };
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
457
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
458 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
459 * 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
460 * 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
461 * 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
462 * element reading.
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 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
465 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
466 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
467 ByteIOContext *pb = 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
468 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
469 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
470
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
471 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
472 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
473
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
474 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
475 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
476 num++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
477 } else {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
478 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
479 }
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 return num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
483 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
484
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 * 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
487 * 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
488 * 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
489 * "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
490 * number.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
491 * 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
492 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
493 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
494 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
495 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
496 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
497 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
498 ByteIOContext *pb = 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
499 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
500 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
501
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
502 /* 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
503 * 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
504 * 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
505 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
506 /* 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
507 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
508 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
509 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
510 "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
511 pos, pos);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
512 }
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
513 return AVERROR(EIO); /* EOS or actual I/O error */
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
514 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
515
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
516 /* 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
517 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
518 read++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
519 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
520 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
521 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
522 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
523 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
524 "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
525 (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
526 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
527 }
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 /* 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
530 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
531 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
532 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
533
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
534 *number = total;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
535
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
536 return read;
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
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
539 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
540 * 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
541 * 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
542 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
543 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
544 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
545 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
546 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
547 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
548 int read;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
549 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
550
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
551 /* 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
552 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
553 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
554 *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
555 *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
556 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
557 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
558
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
559 /* 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
560 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
561 return read;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
562 *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
563
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
564 /* level tracking */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
565 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
566 *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
567
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
568 return read;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
569 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
570
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
571 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
572 * 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
573 * 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
574 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
575 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
576 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
577 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
578 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
579 /* 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
580 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
581
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
582 /* 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
583 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
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 * 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
588 * 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
589 * 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
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 uint32_t
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
592 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
593 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
594 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
595 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
596
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
597 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
598 return 0;
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 return id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
601 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
602
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
603 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
604 * 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
605 * 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
606 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
607 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
608 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
609 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
610 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
611 ByteIOContext *pb = 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
612
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
613 /* 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
614 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
615
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
616 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
617 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
618
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
619 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
620 * 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
621 * 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
622 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
623 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
624 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
625 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
626 ByteIOContext *pb = 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
627 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
628 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
629 int res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
630
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
631 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
632 (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
633 return res;
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 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
636
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
637 return 0;
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
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
640 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
641 * 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
642 * 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
643 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
644 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
645 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
646 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
647 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
648 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
649 ByteIOContext *pb = 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
650 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
651 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
652
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
653 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
654 (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
655 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
656 size = rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
657 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
658 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
659 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
660 "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
661 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
662 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
663 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
664
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
665 /* 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
666 *num = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
667 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
668 *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
669
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
670 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
671 }
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 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
674 * 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
675 * 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
676 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
677 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
678 ebml_read_float (MatroskaDemuxContext *matroska,
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
679 uint32_t *id,
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
680 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
681 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
682 ByteIOContext *pb = 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
683 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
684 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
685
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
686 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
687 (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
688 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
689 size = rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
690
824
779b1e87b865 more non portable float parsing code ...
michael
parents: 820
diff changeset
691 if (size == 4) {
779b1e87b865 more non portable float parsing code ...
michael
parents: 820
diff changeset
692 *num= av_int2flt(get_be32(pb));
779b1e87b865 more non portable float parsing code ...
michael
parents: 820
diff changeset
693 } else if(size==8){
779b1e87b865 more non portable float parsing code ...
michael
parents: 820
diff changeset
694 *num= av_int2dbl(get_be64(pb));
779b1e87b865 more non portable float parsing code ...
michael
parents: 820
diff changeset
695 } else{
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
696 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
697 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
698 "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
699 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
700 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
701 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
702
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
703 return 0;
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
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 * 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
708 * 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
709 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
710 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
711 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
712 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
713 char **str)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
714 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
715 ByteIOContext *pb = 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
716 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
717 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
718
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
719 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
720 (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
721 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
722 size = rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
723
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
724 /* 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
725 * byte more, read the string and NULL-terminate it ourselves. */
639
0b52743104ac integer overflows, heap corruption
michael
parents: 496
diff changeset
726 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
727 av_log(matroska->ctx, AV_LOG_ERROR, "Memory allocation failed\n");
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2264
diff changeset
728 return AVERROR(ENOMEM);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
729 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
730 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
731 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
732 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
733 "Read error at pos. %"PRIu64" (0x%"PRIx64")\n", pos, pos);
3416
f386245ae6f7 matroskadec: fix potential mem leak
aurel
parents: 3415
diff changeset
734 av_free(*str);
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
735 return AVERROR(EIO);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
736 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
737 (*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
738
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
739 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
740 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
741
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
742 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
743 * 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
744 * 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
745 * 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
746 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
747 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
748 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
749 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
750 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
751 ByteIOContext *pb = 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
752 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
753 MatroskaLevel *level;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
754 int res;
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 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
757 (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
758 return res;
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 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
761 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
762 "File moves beyond max. allowed depth (%d)\n", EBML_MAX_DEPTH);
2276
3c1e2d519277 Replace all occurrences of AVERROR_NOTSUPP with AVERROR(ENOSYS).
takis
parents: 2274
diff changeset
763 return AVERROR(ENOSYS);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
764 }
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 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
767 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
768 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
769
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
770 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
771 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
772
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
773 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
774 * 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
775 * 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
776 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
777 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
778 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
779 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
780 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
781 int *size)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
782 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
783 ByteIOContext *pb = 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
784 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
785 int res;
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 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
788 (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
789 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
790 *size = rlength;
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 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
793 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
794 "Memory allocation error\n");
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2264
diff changeset
795 return AVERROR(ENOMEM);
380
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
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
798 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
799 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
800 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
801 "Read error at pos. %"PRIu64" (0x%"PRIx64")\n", pos, pos);
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
802 return AVERROR(EIO);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
803 }
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 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
806 }
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 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
809 * 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
810 * 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
811 * 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
812 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
813 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
814 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
815 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
816 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
817 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
818 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
819 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
820
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
821 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
822 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
823
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
824 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
825 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
826 read++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
827 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
828 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
829 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
830 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
831
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
832 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
833 num_ffs++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
834 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
835 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
836 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
837 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
838 num_ffs++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
839 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
840 n++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
841 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
842
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
843 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
844 *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
845 else
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
846 *num = total;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
847
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
848 return read;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
849 }
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 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
852 * 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
853 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
854 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
855 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
856 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
857 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
858 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
859 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
860 int res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
861
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
862 /* 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
863 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
864 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
865
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
866 /* 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
867 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
868 *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
869 else
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
870 *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
871
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
872 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
873 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
874
2011
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
875
3636
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
876 static MatroskaTrack *
2011
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
877 matroska_find_track_by_num (MatroskaDemuxContext *matroska,
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
878 int num)
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
879 {
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
880 MatroskaTrack *tracks = matroska->tracks.elem;
2011
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
881 int i;
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
882
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
883 for (i=0; i < matroska->tracks.nb_elem; i++)
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
884 if (tracks[i].num == num)
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
885 return &tracks[i];
3636
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
886
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
887 av_log(matroska->ctx, AV_LOG_ERROR, "Invalid track number %d\n", num);
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
888 return NULL;
2011
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
889 }
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
890
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
891
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
892 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
893 * 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
894 * 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
895 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
896 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
897 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
898 AVPacket *pkt)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
899 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
900 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
901 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
902 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
903 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
904 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
905 (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
906 matroska->packets =
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
907 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
908 sizeof(AVPacket *));
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
909 } else {
1530
f65cd8910a5c simplify free()+set to NULL using av_freep()
aurel
parents: 1490
diff changeset
910 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
911 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
912 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
913 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
914 }
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 return -1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
917 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
918
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
919 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
920 * 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
921 * 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
922 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
923 static void
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
924 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
925 AVPacket *pkt)
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 matroska->packets =
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
928 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
929 sizeof(AVPacket *));
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
930 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
931 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
932 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
933
2871
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
934 /*
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
935 * Free all packets in our internal queue.
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
936 */
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
937 static void
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
938 matroska_clear_queue (MatroskaDemuxContext *matroska)
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
939 {
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
940 if (matroska->packets) {
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
941 int n;
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
942 for (n = 0; n < matroska->num_packets; n++) {
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
943 av_free_packet(matroska->packets[n]);
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
944 av_free(matroska->packets[n]);
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
945 }
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
946 av_free(matroska->packets);
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
947 matroska->packets = NULL;
2881
dc2e92d4a903 move num_packets=0 where it belongs
aurel
parents: 2873
diff changeset
948 matroska->num_packets = 0;
2871
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
949 }
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
950 }
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
951
1904
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
952
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
953 /*
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
954 * Autodetecting...
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 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
957 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
958 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
959 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
960 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
961 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
962
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
963 /* ebml header? */
2185
7dd08e645d92 use intreadwrite functions in matroskadec
aurel
parents: 2175
diff changeset
964 if (AV_RB32(p->buf) != EBML_ID_HEADER)
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
965 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
966
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
967 /* 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
968 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
969 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
970 size++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
971 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
972 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
973 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
974 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
975 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
976 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
977 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
978
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
979 /* 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
980 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
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 /* 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
984 * 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
985 * 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
986 * Not fully fool-proof, but good enough. */
1828
f1397cd39ec3 fix an off-by-one error in probing function
aurel
parents: 1673
diff changeset
987 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
988 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
989 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
990
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
991 return 0;
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
3632
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
994 static int ebml_parse(MatroskaDemuxContext *matroska, EbmlSyntax *syntax,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
995 void *data, uint32_t expected_id, int once);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
996
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
997 static int ebml_parse_elem(MatroskaDemuxContext *matroska,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
998 EbmlSyntax *syntax, void *data)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
999 {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1000 uint32_t id = syntax->id;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1001 EbmlBin *bin;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1002 int res;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1003
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1004 data = (char *)data + syntax->data_offset;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1005 if (syntax->list_elem_size) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1006 EbmlList *list = data;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1007 list->elem = av_realloc(list->elem, (list->nb_elem+1)*syntax->list_elem_size);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1008 data = (char*)list->elem + list->nb_elem*syntax->list_elem_size;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1009 memset(data, 0, syntax->list_elem_size);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1010 list->nb_elem++;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1011 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1012 bin = data;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1013
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1014 switch (syntax->type) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1015 case EBML_UINT: return ebml_read_uint (matroska, &id, data);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1016 case EBML_FLOAT: return ebml_read_float(matroska, &id, data);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1017 case EBML_STR:
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1018 case EBML_UTF8: av_free(*(char **)data);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1019 return ebml_read_ascii(matroska, &id, data);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1020 case EBML_BIN: av_free(bin->data);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1021 bin->pos = url_ftell(matroska->ctx->pb);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1022 return ebml_read_binary(matroska, &id, &bin->data,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1023 &bin->size);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1024 case EBML_NEST: if ((res=ebml_read_master(matroska, &id)) < 0)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1025 return res;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1026 if (id == MATROSKA_ID_SEGMENT)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1027 matroska->segment_start = url_ftell(matroska->ctx->pb);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1028 return ebml_parse(matroska, syntax->def.n, data, 0, 0);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1029 case EBML_PASS: return ebml_parse(matroska, syntax->def.n, data, 0, 1);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1030 case EBML_STOP: *(int *)data = 1; return 1;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1031 default: return ebml_read_skip(matroska);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1032 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1033 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1034
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1035 static int ebml_parse_id(MatroskaDemuxContext *matroska, EbmlSyntax *syntax,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1036 uint32_t id, void *data)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1037 {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1038 int i;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1039 for (i=0; syntax[i].id; i++)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1040 if (id == syntax[i].id)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1041 break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1042 if (!syntax[i].id)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1043 av_log(matroska->ctx, AV_LOG_INFO, "Unknown entry 0x%X\n", id);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1044 return ebml_parse_elem(matroska, &syntax[i], data);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1045 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1046
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1047 static int ebml_parse(MatroskaDemuxContext *matroska, EbmlSyntax *syntax,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1048 void *data, uint32_t expected_id, int once)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1049 {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1050 int i, res = 0;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1051 uint32_t id = 0;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1052
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1053 for (i=0; syntax[i].id; i++)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1054 switch (syntax[i].type) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1055 case EBML_UINT:
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1056 *(uint64_t *)((char *)data+syntax[i].data_offset) = syntax[i].def.u;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1057 break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1058 case EBML_FLOAT:
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1059 *(double *)((char *)data+syntax[i].data_offset) = syntax[i].def.f;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1060 break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1061 case EBML_STR:
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1062 case EBML_UTF8:
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1063 *(char **)((char *)data+syntax[i].data_offset) = av_strdup(syntax[i].def.s);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1064 break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1065 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1066
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1067 if (expected_id) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1068 res = ebml_read_master(matroska, &id);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1069 if (id != expected_id)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1070 return AVERROR_INVALIDDATA;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1071 if (id == MATROSKA_ID_SEGMENT)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1072 matroska->segment_start = url_ftell(matroska->ctx->pb);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1073 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1074
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1075 while (!res) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1076 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1077 res = AVERROR(EIO);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1078 break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1079 } else if (matroska->level_up) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1080 matroska->level_up--;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1081 break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1082 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1083
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1084 res = ebml_parse_id(matroska, syntax, id, data);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1085 if (once)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1086 break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1087
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1088 if (matroska->level_up) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1089 matroska->level_up--;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1090 break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1091 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1092 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1093
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1094 return res;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1095 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1096
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1097 static void ebml_free(EbmlSyntax *syntax, void *data)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1098 {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1099 int i, j;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1100 for (i=0; syntax[i].id; i++) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1101 void *data_off = (char *)data + syntax[i].data_offset;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1102 switch (syntax[i].type) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1103 case EBML_STR:
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1104 case EBML_UTF8: av_freep(data_off); break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1105 case EBML_BIN: av_freep(&((EbmlBin *)data_off)->data); break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1106 case EBML_NEST:
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1107 if (syntax[i].list_elem_size) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1108 EbmlList *list = data_off;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1109 char *ptr = list->elem;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1110 for (j=0; j<list->nb_elem; j++, ptr+=syntax[i].list_elem_size)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1111 ebml_free(syntax[i].def.n, ptr);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1112 av_free(list->elem);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1113 } else
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1114 ebml_free(syntax[i].def.n, data_off);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1115 default: break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1116 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1117 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1118 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1119
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1120 static int
3494
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1121 matroska_decode_buffer(uint8_t** buf, int* buf_size, MatroskaTrack *track)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1122 {
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1123 MatroskaTrackEncoding *encodings = track->encodings.elem;
3494
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1124 uint8_t* data = *buf;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1125 int isize = *buf_size;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1126 uint8_t* pkt_data = NULL;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1127 int pkt_size = isize;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1128 int result = 0;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1129 int olen;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1130
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1131 switch (encodings[0].compression.algo) {
3494
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1132 case MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP:
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1133 return encodings[0].compression.settings.size;
3494
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1134 case MATROSKA_TRACK_ENCODING_COMP_LZO:
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1135 do {
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1136 olen = pkt_size *= 3;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1137 pkt_data = av_realloc(pkt_data,
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1138 pkt_size+LZO_OUTPUT_PADDING);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1139 result = lzo1x_decode(pkt_data, &olen, data, &isize);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1140 } while (result==LZO_OUTPUT_FULL && pkt_size<10000000);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1141 if (result)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1142 goto failed;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1143 pkt_size -= olen;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1144 break;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1145 #ifdef CONFIG_ZLIB
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1146 case MATROSKA_TRACK_ENCODING_COMP_ZLIB: {
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1147 z_stream zstream = {0};
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1148 if (inflateInit(&zstream) != Z_OK)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1149 return -1;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1150 zstream.next_in = data;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1151 zstream.avail_in = isize;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1152 do {
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1153 pkt_size *= 3;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1154 pkt_data = av_realloc(pkt_data, pkt_size);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1155 zstream.avail_out = pkt_size - zstream.total_out;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1156 zstream.next_out = pkt_data + zstream.total_out;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1157 result = inflate(&zstream, Z_NO_FLUSH);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1158 } while (result==Z_OK && pkt_size<10000000);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1159 pkt_size = zstream.total_out;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1160 inflateEnd(&zstream);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1161 if (result != Z_STREAM_END)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1162 goto failed;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1163 break;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1164 }
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1165 #endif
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1166 #ifdef CONFIG_BZLIB
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1167 case MATROSKA_TRACK_ENCODING_COMP_BZLIB: {
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1168 bz_stream bzstream = {0};
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1169 if (BZ2_bzDecompressInit(&bzstream, 0, 0) != BZ_OK)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1170 return -1;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1171 bzstream.next_in = data;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1172 bzstream.avail_in = isize;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1173 do {
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1174 pkt_size *= 3;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1175 pkt_data = av_realloc(pkt_data, pkt_size);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1176 bzstream.avail_out = pkt_size - bzstream.total_out_lo32;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1177 bzstream.next_out = pkt_data + bzstream.total_out_lo32;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1178 result = BZ2_bzDecompress(&bzstream);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1179 } while (result==BZ_OK && pkt_size<10000000);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1180 pkt_size = bzstream.total_out_lo32;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1181 BZ2_bzDecompressEnd(&bzstream);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1182 if (result != BZ_STREAM_END)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1183 goto failed;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1184 break;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1185 }
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1186 #endif
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1187 }
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1188
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1189 *buf = pkt_data;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1190 *buf_size = pkt_size;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1191 return 0;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1192 failed:
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1193 av_free(pkt_data);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1194 return -1;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1195 }
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1196
3644
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1197 static void
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1198 matroska_execute_seekhead(MatroskaDemuxContext *matroska)
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1199 {
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1200 EbmlList *seekhead_list = &matroska->seekhead;
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1201 MatroskaSeekhead *seekhead = seekhead_list->elem;
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1202 uint32_t peek_id_cache = matroska->peek_id;
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1203 uint32_t level_up = matroska->level_up;
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1204 offset_t before_pos = url_ftell(matroska->ctx->pb);
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1205 MatroskaLevel level;
3652
a22da874fc50 matroskadec: use generic parser inside matroska_execute_seekhead()
aurel
parents: 3651
diff changeset
1206 int i;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1207
3644
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1208 for (i=0; i<seekhead_list->nb_elem; i++) {
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1209 if (seekhead[i].pos <= before_pos
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1210 || seekhead[i].id == MATROSKA_ID_SEEKHEAD
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1211 || seekhead[i].id == MATROSKA_ID_CLUSTER)
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1212 continue;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1213
3646
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1214 /* seek */
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1215 if (ebml_read_seek(matroska,
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1216 seekhead[i].pos+matroska->segment_start) < 0)
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1217 continue;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1218
3646
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1219 /* we don't want to lose our seekhead level, so we add
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1220 * a dummy. This is a crude hack. */
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1221 if (matroska->num_levels == EBML_MAX_DEPTH) {
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1222 av_log(matroska->ctx, AV_LOG_INFO,
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1223 "Max EBML element depth (%d) reached, "
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1224 "cannot parse further.\n", EBML_MAX_DEPTH);
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1225 break;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1226 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 883
diff changeset
1227
3646
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1228 level.start = 0;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1229 level.length = (uint64_t)-1;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1230 matroska->levels[matroska->num_levels] = level;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1231 matroska->num_levels++;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1232
3652
a22da874fc50 matroskadec: use generic parser inside matroska_execute_seekhead()
aurel
parents: 3651
diff changeset
1233 ebml_parse_id(matroska, matroska_segment, seekhead[i].id, matroska);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1234
3646
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1235 /* remove dummy level */
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1236 while (matroska->num_levels) {
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1237 uint64_t length = matroska->levels[--matroska->num_levels].length;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1238 if (length == (uint64_t)-1)
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1239 break;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1240 }
3644
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1241 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1242
3646
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1243 /* seek back */
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1244 ebml_read_seek(matroska, before_pos);
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1245 matroska->peek_id = peek_id_cache;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1246 matroska->level_up = 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
1247 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1248
2973
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1249 static int
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1250 matroska_aac_profile (char *codec_id)
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1251 {
3659
e888db995d49 matroskadec: cosmetics
aurel
parents: 3658
diff changeset
1252 static const char *aac_profiles[] = { "MAIN", "LC", "SSR" };
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1253 int profile;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1254
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1255 for (profile=0; profile<ARRAY_SIZE(aac_profiles); profile++)
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1256 if (strstr(codec_id, aac_profiles[profile]))
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1257 break;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1258 return profile + 1;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1259 }
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1260
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1261 static int
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1262 matroska_aac_sri (int samplerate)
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1263 {
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1264 int sri;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1265
3201
1a16b069daca use common aac sample rate tables
aurel
parents: 3199
diff changeset
1266 for (sri=0; sri<ARRAY_SIZE(ff_mpeg4audio_sample_rates); sri++)
1a16b069daca use common aac sample rate tables
aurel
parents: 3199
diff changeset
1267 if (ff_mpeg4audio_sample_rates[sri] == samplerate)
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1268 break;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1269 return sri;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1270 }
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1271
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1272 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1273 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
1274 AVFormatParameters *ap)
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 MatroskaDemuxContext *matroska = s->priv_data;
3650
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1277 EbmlList *attachements_list = &matroska->attachments;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1278 MatroskaAttachement *attachements;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1279 EbmlList *chapters_list = &matroska->chapters;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1280 MatroskaChapter *chapters;
3648
07f046bf6849 matroskadec: move declaration to upper block
aurel
parents: 3647
diff changeset
1281 MatroskaTrack *tracks;
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1282 EbmlList *index_list;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1283 MatroskaIndex *index;
3633
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
1284 Ebml ebml = { 0 };
3648
07f046bf6849 matroskadec: move declaration to upper block
aurel
parents: 3647
diff changeset
1285 AVStream *st;
3651
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
1286 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
1287
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1288 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
1289
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1290 /* First read the EBML header. */
3633
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
1291 if (ebml_parse(matroska, ebml_syntax, &ebml, 0, 1)
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
1292 || ebml.version > EBML_VERSION || ebml.max_size > sizeof(uint64_t)
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
1293 || ebml.id_length > sizeof(uint32_t) || strcmp(ebml.doctype, "matroska")
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
1294 || ebml.doctype_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
1295 av_log(matroska->ctx, AV_LOG_ERROR,
3633
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
1296 "EBML header using unsupported features\n"
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
1297 "(EBML version %"PRIu64", doctype %s, doc version %"PRIu64")\n",
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
1298 ebml.version, ebml.doctype, ebml.doctype_version);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1299 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
1300 }
3633
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
1301 ebml_free(ebml_syntax, &ebml);
380
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 /* The next thing is a segment. */
3651
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
1304 if (ebml_parse(matroska, matroska_segments, matroska, 0, 1) < 0)
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
1305 return -1;
3644
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1306 matroska_execute_seekhead(matroska);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1307
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1308 /* Have we found a cluster? */
3647
98eb4eb368fa matroskadec: invert a test
aurel
parents: 3646
diff changeset
1309 if (ebml_peek_id(matroska, NULL) != MATROSKA_ID_CLUSTER)
98eb4eb368fa matroskadec: invert a test
aurel
parents: 3646
diff changeset
1310 return -1;
98eb4eb368fa matroskadec: invert a test
aurel
parents: 3646
diff changeset
1311
3650
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1312 if (matroska->duration)
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1313 matroska->ctx->duration = matroska->duration * matroska->time_scale
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1314 * 1000 / AV_TIME_BASE;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1315 if (matroska->title)
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1316 strncpy(matroska->ctx->title, matroska->title,
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1317 sizeof(matroska->ctx->title)-1);
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1318
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1319 tracks = matroska->tracks.elem;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1320 for (i=0; i < matroska->tracks.nb_elem; i++) {
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1321 MatroskaTrack *track = &tracks[i];
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1322 enum CodecID codec_id = CODEC_ID_NONE;
3650
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1323 EbmlList *encodings_list = &tracks->encodings;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1324 MatroskaTrackEncoding *encodings = encodings_list->elem;
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1325 uint8_t *extradata = NULL;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1326 int extradata_size = 0;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1327 int extradata_offset = 0;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1328
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1329 /* Apply some sanity checks. */
3650
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1330 if (track->type != MATROSKA_TRACK_TYPE_VIDEO &&
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1331 track->type != MATROSKA_TRACK_TYPE_AUDIO &&
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1332 track->type != MATROSKA_TRACK_TYPE_SUBTITLE) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1333 av_log(matroska->ctx, AV_LOG_INFO,
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1334 "Unknown or unsupported track type %"PRIu64"\n",
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1335 track->type);
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1336 continue;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1337 }
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1338 if (track->codec_id == NULL)
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1339 continue;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1340
3650
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1341 if (track->type == MATROSKA_TRACK_TYPE_VIDEO) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1342 if (!track->default_duration)
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1343 track->default_duration = 1000000000/track->video.frame_rate;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1344 if (!track->video.display_width)
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1345 track->video.display_width = track->video.pixel_width;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1346 if (!track->video.display_height)
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1347 track->video.display_height = track->video.pixel_height;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1348 } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1349 if (!track->audio.out_samplerate)
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1350 track->audio.out_samplerate = track->audio.samplerate;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1351 }
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1352 if (encodings_list->nb_elem > 1) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1353 av_log(matroska->ctx, AV_LOG_ERROR,
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1354 "Multiple combined encodings no supported");
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1355 } else if (encodings_list->nb_elem == 1) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1356 if (encodings[0].type ||
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1357 (encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP &&
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1358 #ifdef CONFIG_ZLIB
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1359 encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_ZLIB &&
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1360 #endif
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1361 #ifdef CONFIG_BZLIB
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1362 encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_BZLIB &&
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1363 #endif
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1364 encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_LZO)) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1365 encodings[0].scope = 0;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1366 av_log(matroska->ctx, AV_LOG_ERROR,
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1367 "Unsupported encoding type");
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1368 } else if (track->codec_priv.size && encodings[0].scope&2) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1369 uint8_t *codec_priv = track->codec_priv.data;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1370 int offset = matroska_decode_buffer(&track->codec_priv.data,
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1371 &track->codec_priv.size,
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1372 track);
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1373 if (offset < 0) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1374 track->codec_priv.data = NULL;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1375 track->codec_priv.size = 0;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1376 av_log(matroska->ctx, AV_LOG_ERROR,
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1377 "Failed to decode codec private data\n");
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1378 } else if (offset > 0) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1379 track->codec_priv.data = av_malloc(track->codec_priv.size + offset);
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1380 memcpy(track->codec_priv.data,
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1381 encodings[0].compression.settings.data, offset);
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1382 memcpy(track->codec_priv.data+offset, codec_priv,
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1383 track->codec_priv.size);
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1384 track->codec_priv.size += offset;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1385 }
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1386 if (codec_priv != track->codec_priv.data)
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1387 av_free(codec_priv);
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1388 }
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1389 }
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1390
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1391 for(j=0; ff_mkv_codec_tags[j].id != CODEC_ID_NONE; j++){
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1392 if(!strncmp(ff_mkv_codec_tags[j].str, track->codec_id,
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1393 strlen(ff_mkv_codec_tags[j].str))){
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1394 codec_id= ff_mkv_codec_tags[j].id;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1395 break;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1396 }
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1397 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1398
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1399 st = track->stream = av_new_stream(s, matroska->num_streams++);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1400 if (st == NULL)
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1401 return AVERROR(ENOMEM);
1024
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
1402
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1403 if (!strcmp(track->codec_id,
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1404 MATROSKA_CODEC_ID_VIDEO_VFW_FOURCC) &&
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1405 (track->codec_priv.size >= 40) &&
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1406 (track->codec_priv.data != NULL)) {
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1407 track->video.fourcc = AV_RL32(track->codec_priv.data + 16);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1408 codec_id = codec_get_id(codec_bmp_tags, track->video.fourcc);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1409 }
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1410 else if (!strcmp(track->codec_id,
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1411 MATROSKA_CODEC_ID_AUDIO_ACM) &&
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1412 (track->codec_priv.size >= 18) &&
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1413 (track->codec_priv.data != NULL)) {
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1414 uint16_t tag = AV_RL16(track->codec_priv.data);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1415 codec_id = codec_get_id(codec_wav_tags, tag);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1416 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1417
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1418 else if (!strcmp(track->codec_id, "V_QUICKTIME") &&
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1419 (track->codec_priv.size >= 86) &&
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1420 (track->codec_priv.data != NULL)) {
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1421 track->video.fourcc = AV_RL32(track->codec_priv.data);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1422 codec_id=codec_get_id(codec_movvideo_tags, track->video.fourcc);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1423 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1424
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1425 else if (codec_id == CODEC_ID_AAC && !track->codec_priv.size) {
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1426 int profile = matroska_aac_profile(track->codec_id);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1427 int sri = matroska_aac_sri(track->audio.samplerate);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1428 extradata = av_malloc(5);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1429 if (extradata == NULL)
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1430 return AVERROR(ENOMEM);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1431 extradata[0] = (profile << 3) | ((sri&0x0E) >> 1);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1432 extradata[1] = ((sri&0x01) << 7) | (track->audio.channels<<3);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1433 if (strstr(track->codec_id, "SBR")) {
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1434 sri = matroska_aac_sri(track->audio.out_samplerate);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1435 extradata[2] = 0x56;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1436 extradata[3] = 0xE5;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1437 extradata[4] = 0x80 | (sri<<3);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1438 extradata_size = 5;
3655
e178e2725a59 matroskadec: cosmetics: remove useless braces
aurel
parents: 3654
diff changeset
1439 } else
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1440 extradata_size = 2;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1441 }
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1442 else if (codec_id == CODEC_ID_TTA) {
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1443 ByteIOContext b;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1444 extradata_size = 30;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1445 extradata = av_mallocz(extradata_size);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1446 if (extradata == NULL)
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1447 return AVERROR(ENOMEM);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1448 init_put_byte(&b, extradata, extradata_size, 1,
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1449 NULL, NULL, NULL, NULL);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1450 put_buffer(&b, "TTA1", 4);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1451 put_le16(&b, 1);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1452 put_le16(&b, track->audio.channels);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1453 put_le16(&b, track->audio.bitdepth);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1454 put_le32(&b, track->audio.out_samplerate);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1455 put_le32(&b, matroska->ctx->duration * track->audio.out_samplerate);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1456 }
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1457 else if (codec_id == CODEC_ID_RV10 || codec_id == CODEC_ID_RV20 ||
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1458 codec_id == CODEC_ID_RV30 || codec_id == CODEC_ID_RV40) {
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1459 extradata_offset = 26;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1460 track->codec_priv.size -= extradata_offset;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1461 }
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1462 else if (codec_id == CODEC_ID_RA_144) {
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1463 track->audio.out_samplerate = 8000;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1464 track->audio.channels = 1;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1465 }
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1466 else if (codec_id == CODEC_ID_RA_288 ||
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1467 codec_id == CODEC_ID_COOK ||
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1468 codec_id == CODEC_ID_ATRAC3) {
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1469 ByteIOContext b;
1534
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
1470
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1471 init_put_byte(&b, track->codec_priv.data,track->codec_priv.size,
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1472 0, NULL, NULL, NULL, NULL);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1473 url_fskip(&b, 24);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1474 track->audio.coded_framesize = get_be32(&b);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1475 url_fskip(&b, 12);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1476 track->audio.sub_packet_h = get_be16(&b);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1477 track->audio.frame_size = get_be16(&b);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1478 track->audio.sub_packet_size = get_be16(&b);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1479 track->audio.buf = av_malloc(track->audio.frame_size * track->audio.sub_packet_h);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1480 if (codec_id == CODEC_ID_RA_288) {
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1481 st->codec->block_align = track->audio.coded_framesize;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1482 track->codec_priv.size = 0;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1483 } else {
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1484 st->codec->block_align = track->audio.sub_packet_size;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1485 extradata_offset = 78;
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1486 track->codec_priv.size -= extradata_offset;
1531
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
1487 }
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1488 }
1531
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
1489
3655
e178e2725a59 matroskadec: cosmetics: remove useless braces
aurel
parents: 3654
diff changeset
1490 if (codec_id == CODEC_ID_NONE)
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1491 av_log(matroska->ctx, AV_LOG_INFO,
3659
e888db995d49 matroskadec: cosmetics
aurel
parents: 3658
diff changeset
1492 "Unknown/unsupported CodecID %s.\n", track->codec_id);
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1493
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1494 av_set_pts_info(st, 64, matroska->time_scale*track->time_scale, 1000*1000*1000); /* 64 bit pts in ns */
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1495
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1496 st->codec->codec_id = codec_id;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1497 st->start_time = 0;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1498 if (strcmp(track->language, "und"))
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1499 av_strlcpy(st->language, track->language, 4);
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1500
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1501 if (track->flag_default)
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1502 st->disposition |= AV_DISPOSITION_DEFAULT;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1503
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1504 if (track->default_duration)
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1505 av_reduce(&st->codec->time_base.num, &st->codec->time_base.den,
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1506 track->default_duration, 1000000000, 30000);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1507
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1508 if(extradata){
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1509 st->codec->extradata = extradata;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1510 st->codec->extradata_size = extradata_size;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1511 } else if(track->codec_priv.data && track->codec_priv.size > 0){
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1512 st->codec->extradata = av_malloc(track->codec_priv.size);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1513 if(st->codec->extradata == NULL)
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1514 return AVERROR(ENOMEM);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1515 st->codec->extradata_size = track->codec_priv.size;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1516 memcpy(st->codec->extradata,
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1517 track->codec_priv.data + extradata_offset,
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1518 track->codec_priv.size);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1519 }
692
b0144ebc71dd H.264 and Vorbis support in matroska patch by (M«©ns Rullg«©rd |mru inprovide com)
michael
parents: 652
diff changeset
1520
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1521 if (track->type == MATROSKA_TRACK_TYPE_VIDEO) {
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1522 st->codec->codec_type = CODEC_TYPE_VIDEO;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1523 st->codec->codec_tag = track->video.fourcc;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1524 st->codec->width = track->video.pixel_width;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1525 st->codec->height = track->video.pixel_height;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1526 av_reduce(&st->codec->sample_aspect_ratio.num,
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1527 &st->codec->sample_aspect_ratio.den,
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1528 st->codec->height * track->video.display_width,
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1529 st->codec-> width * track->video.display_height,
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1530 255);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1531 st->need_parsing = AVSTREAM_PARSE_HEADERS;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1532 } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) {
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1533 st->codec->codec_type = CODEC_TYPE_AUDIO;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1534 st->codec->sample_rate = track->audio.out_samplerate;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1535 st->codec->channels = track->audio.channels;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1536 } else if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE) {
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1537 st->codec->codec_type = CODEC_TYPE_SUBTITLE;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1538 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1539 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1540
3650
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1541 attachements = attachements_list->elem;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1542 for (j=0; j<attachements_list->nb_elem; j++) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1543 if (!(attachements[j].filename && attachements[j].mime &&
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1544 attachements[j].bin.data && attachements[j].bin.size > 0)) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1545 av_log(matroska->ctx, AV_LOG_ERROR, "incomplete attachment\n");
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1546 } else {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1547 AVStream *st = av_new_stream(s, matroska->num_streams++);
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1548 if (st == NULL)
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1549 break;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1550 st->filename = av_strdup(attachements[j].filename);
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1551 st->codec->codec_id = CODEC_ID_NONE;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1552 st->codec->codec_type = CODEC_TYPE_ATTACHMENT;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1553 st->codec->extradata = av_malloc(attachements[j].bin.size);
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1554 if(st->codec->extradata == NULL)
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1555 break;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1556 st->codec->extradata_size = attachements[j].bin.size;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1557 memcpy(st->codec->extradata, attachements[j].bin.data, attachements[j].bin.size);
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1558
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1559 for (i=0; ff_mkv_mime_tags[i].id != CODEC_ID_NONE; i++) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1560 if (!strncmp(ff_mkv_mime_tags[i].str, attachements[j].mime,
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1561 strlen(ff_mkv_mime_tags[i].str))) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1562 st->codec->codec_id = ff_mkv_mime_tags[i].id;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1563 break;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1564 }
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1565 }
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1566 }
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1567 }
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1568
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1569 chapters = chapters_list->elem;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1570 for (i=0; i<chapters_list->nb_elem; i++)
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1571 if (chapters[i].start != AV_NOPTS_VALUE && chapters[i].uid)
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1572 ff_new_chapter(s, chapters[i].uid, (AVRational){1, 1000000000},
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1573 chapters[i].start, chapters[i].end,
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1574 chapters[i].title);
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1575
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1576 index_list = &matroska->index;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1577 index = index_list->elem;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1578 for (i=0; i<index_list->nb_elem; i++) {
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1579 EbmlList *pos_list = &index[i].pos;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1580 MatroskaIndexPos *pos = pos_list->elem;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1581 for (j=0; j<pos_list->nb_elem; j++) {
3636
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
1582 MatroskaTrack *track = matroska_find_track_by_num(matroska,
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1583 pos[j].track);
3636
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
1584 if (track && track->stream)
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
1585 av_add_index_entry(track->stream,
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1586 pos[j].pos + matroska->segment_start,
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1587 index[i].time*matroska->time_scale/AV_TIME_BASE,
2202
32d675fb5e2e cosmetics: indentation after last commit
aurel
parents: 2201
diff changeset
1588 0, 0, AVINDEX_KEYFRAME);
2012
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1589 }
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1590 }
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1591
3651
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
1592 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
1593 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1594
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1595 static int
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
1596 matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int size,
1914
511723932287 calculate pts for laced packets
aurel
parents: 1913
diff changeset
1597 int64_t pos, uint64_t cluster_time, uint64_t duration,
3631
951c7aaaf2a2 matroskadec: remove unused is_bframe flag
aurel
parents: 3630
diff changeset
1598 int is_keyframe)
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1599 {
3636
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
1600 MatroskaTrack *track;
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
1601 int res = 0;
2013
fc0b19650faa add an intermediate variable (prepare for next patch)
aurel
parents: 2012
diff changeset
1602 AVStream *st;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1603 AVPacket *pkt;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1604 int16_t block_time;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1605 uint32_t *lace_size = NULL;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1606 int n, flags, laces = 0;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1607 uint64_t num;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1608
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1609 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
1610 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
1611 return res;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1612 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1613 data += n;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1614 size -= n;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1615
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1616 track = matroska_find_track_by_num(matroska, num);
3636
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
1617 if (size <= 3 || !track || !track->stream) {
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1618 av_log(matroska->ctx, AV_LOG_INFO,
3636
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
1619 "Invalid stream %"PRIu64" or size %u\n", num, size);
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1620 return res;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1621 }
3636
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
1622 st = track->stream;
3655
e178e2725a59 matroskadec: cosmetics: remove useless braces
aurel
parents: 3654
diff changeset
1623 if (st->discard >= AVDISCARD_ALL)
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1624 return res;
1914
511723932287 calculate pts for laced packets
aurel
parents: 1913
diff changeset
1625 if (duration == AV_NOPTS_VALUE)
3636
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
1626 duration = track->default_duration / matroska->time_scale;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1627
2185
7dd08e645d92 use intreadwrite functions in matroskadec
aurel
parents: 2175
diff changeset
1628 block_time = AV_RB16(data);
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1629 data += 2;
2188
4c2924cebe00 simplify
aurel
parents: 2185
diff changeset
1630 flags = *data++;
4c2924cebe00 simplify
aurel
parents: 2185
diff changeset
1631 size -= 3;
1831
bdca904db5e5 add support for simple blocks (ie. matroska v2)
aurel
parents: 1830
diff changeset
1632 if (is_keyframe == -1)
2415
3aa642c08cde SimpleBlock keyframe flag is the most significant bit
conrad
parents: 2390
diff changeset
1633 is_keyframe = flags & 0x80 ? PKT_FLAG_KEY : 0;
2014
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
1634
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
1635 if (matroska->skip_to_keyframe) {
3655
e178e2725a59 matroskadec: cosmetics: remove useless braces
aurel
parents: 3654
diff changeset
1636 if (!is_keyframe || st != matroska->skip_to_stream)
2014
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
1637 return res;
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
1638 matroska->skip_to_keyframe = 0;
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
1639 }
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
1640
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1641 switch ((flags & 0x06) >> 1) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1642 case 0x0: /* no lacing */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1643 laces = 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1644 lace_size = av_mallocz(sizeof(int));
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1645 lace_size[0] = size;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1646 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1647
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1648 case 0x1: /* xiph lacing */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1649 case 0x2: /* fixed-size lacing */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1650 case 0x3: /* EBML lacing */
3391
39750abd9bab Dead code removal, fixes CID59 RUN2.
michael
parents: 3334
diff changeset
1651 assert(size>0); // size <=3 is checked before size-=3 above
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1652 laces = (*data) + 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1653 data += 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1654 size -= 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1655 lace_size = av_mallocz(laces * sizeof(int));
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1656
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1657 switch ((flags & 0x06) >> 1) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1658 case 0x1: /* xiph lacing */ {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1659 uint8_t temp;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1660 uint32_t total = 0;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1661 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
1662 while (1) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1663 if (size == 0) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1664 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
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 }
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1667 temp = *data;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1668 lace_size[n] += temp;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1669 data += 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1670 size -= 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1671 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
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 }
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1674 total += lace_size[n];
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1675 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1676 lace_size[n] = size - total;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1677 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1678 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1679
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1680 case 0x2: /* fixed-size lacing */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1681 for (n = 0; n < laces; n++)
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1682 lace_size[n] = size / laces;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1683 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1684
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1685 case 0x3: /* EBML lacing */ {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1686 uint32_t total;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1687 n = matroska_ebmlnum_uint(data, size, &num);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1688 if (n < 0) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1689 av_log(matroska->ctx, AV_LOG_INFO,
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1690 "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
1691 break;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1692 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1693 data += n;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1694 size -= n;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1695 total = lace_size[0] = num;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1696 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
1697 int64_t snum;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1698 int r;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1699 r = matroska_ebmlnum_sint (data, size, &snum);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1700 if (r < 0) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1701 av_log(matroska->ctx, AV_LOG_INFO,
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1702 "EBML block data error\n");
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1703 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1704 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1705 data += r;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1706 size -= r;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1707 lace_size[n] = lace_size[n - 1] + snum;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1708 total += lace_size[n];
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1709 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1710 lace_size[n] = size - total;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1711 break;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1712 }
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1713 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1714 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1715 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1716
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1717 if (res == 0) {
1911
2ce053f3d996 move timecode calculation out of laces loop
aurel
parents: 1905
diff changeset
1718 uint64_t timecode = AV_NOPTS_VALUE;
2ce053f3d996 move timecode calculation out of laces loop
aurel
parents: 1905
diff changeset
1719
2364
7c31128b23f8 ensure that negative block_time are properly checked
aurel
parents: 2276
diff changeset
1720 if (cluster_time != (uint64_t)-1
7c31128b23f8 ensure that negative block_time are properly checked
aurel
parents: 2276
diff changeset
1721 && (block_time >= 0 || cluster_time >= -block_time))
1911
2ce053f3d996 move timecode calculation out of laces loop
aurel
parents: 1905
diff changeset
1722 timecode = cluster_time + block_time;
2ce053f3d996 move timecode calculation out of laces loop
aurel
parents: 1905
diff changeset
1723
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1724 for (n = 0; n < laces; n++) {
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1725 if (st->codec->codec_id == CODEC_ID_RA_288 ||
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1726 st->codec->codec_id == CODEC_ID_COOK ||
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1727 st->codec->codec_id == CODEC_ID_ATRAC3) {
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1728 int a = st->codec->block_align;
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1729 int sps = track->audio.sub_packet_size;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1730 int cfs = track->audio.coded_framesize;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1731 int h = track->audio.sub_packet_h;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1732 int y = track->audio.sub_packet_cnt;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1733 int w = track->audio.frame_size;
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1734 int x;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1735
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1736 if (!track->audio.pkt_cnt) {
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1737 if (st->codec->codec_id == CODEC_ID_RA_288)
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1738 for (x=0; x<h/2; x++)
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1739 memcpy(track->audio.buf+x*2*w+y*cfs,
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1740 data+x*cfs, cfs);
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1741 else
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1742 for (x=0; x<w/sps; x++)
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1743 memcpy(track->audio.buf+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), data+x*sps, sps);
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1744
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1745 if (++track->audio.sub_packet_cnt >= h) {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1746 track->audio.sub_packet_cnt = 0;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1747 track->audio.pkt_cnt = h*w / a;
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1748 }
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1749 }
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1750 while (track->audio.pkt_cnt) {
2145
3dd44fd1cbf4 cosmetics: indentation
aurel
parents: 2144
diff changeset
1751 pkt = av_mallocz(sizeof(AVPacket));
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1752 av_new_packet(pkt, a);
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1753 memcpy(pkt->data, track->audio.buf
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1754 + a * (h*w / a - track->audio.pkt_cnt--), a);
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1755 pkt->pos = pos;
3634
f206f746ff61 matroskadec: store an AVStream pointer instead of a stream index
aurel
parents: 3633
diff changeset
1756 pkt->stream_index = st->index;
2145
3dd44fd1cbf4 cosmetics: indentation
aurel
parents: 2144
diff changeset
1757 matroska_queue_packet(matroska, pkt);
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1758 }
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1759 } else {
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1760 MatroskaTrackEncoding *encodings = track->encodings.elem;
3494
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1761 int offset = 0, pkt_size = lace_size[n];
3281
a1d98736c15e matroskadec: add support for lzo compressed tracks
aurel
parents: 3280
diff changeset
1762 uint8_t *pkt_data = data;
a1d98736c15e matroskadec: add support for lzo compressed tracks
aurel
parents: 3280
diff changeset
1763
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1764 if (encodings && encodings->scope & 1) {
3659
e888db995d49 matroskadec: cosmetics
aurel
parents: 3658
diff changeset
1765 offset = matroska_decode_buffer(&pkt_data,&pkt_size, track);
3494
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1766 if (offset < 0)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1767 continue;
3279
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1768 }
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1769
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1770 pkt = av_mallocz(sizeof(AVPacket));
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1771 /* XXX: prevent data copy... */
3281
a1d98736c15e matroskadec: add support for lzo compressed tracks
aurel
parents: 3280
diff changeset
1772 if (av_new_packet(pkt, pkt_size+offset) < 0) {
3415
89f651b6f12a matroskadec: avoid potential mem leak
aurel
parents: 3414
diff changeset
1773 av_free(pkt);
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1774 res = AVERROR(ENOMEM);
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1775 n = laces-1;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1776 break;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1777 }
3279
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1778 if (offset)
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1779 memcpy (pkt->data, encodings->compression.settings.data, offset);
3281
a1d98736c15e matroskadec: add support for lzo compressed tracks
aurel
parents: 3280
diff changeset
1780 memcpy (pkt->data+offset, pkt_data, pkt_size);
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1781
3493
b77ced770a93 matroskadec: fix a memory leak
aurel
parents: 3477
diff changeset
1782 if (pkt_data != data)
b77ced770a93 matroskadec: fix a memory leak
aurel
parents: 3477
diff changeset
1783 av_free(pkt_data);
b77ced770a93 matroskadec: fix a memory leak
aurel
parents: 3477
diff changeset
1784
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1785 if (n == 0)
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1786 pkt->flags = is_keyframe;
3634
f206f746ff61 matroskadec: store an AVStream pointer instead of a stream index
aurel
parents: 3633
diff changeset
1787 pkt->stream_index = st->index;
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1788
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1789 pkt->pts = timecode;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1790 pkt->pos = pos;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1791 pkt->duration = duration;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1792
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1793 matroska_queue_packet(matroska, pkt);
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1794 }
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1795
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1796 if (timecode != AV_NOPTS_VALUE)
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1797 timecode = duration ? timecode + duration : AV_NOPTS_VALUE;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1798 data += lace_size[n];
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1799 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1800 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1801
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1802 av_free(lace_size);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1803 return res;
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
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1806 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1807 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
1808 {
3653
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
1809 MatroskaCluster cluster = { 0 };
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
1810 EbmlList *blocks_list;
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
1811 MatroskaBlock *blocks;
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
1812 int i, res = ebml_parse(matroska, matroska_clusters, &cluster, 0, 1);
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
1813 blocks_list = &cluster.blocks;
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
1814 blocks = blocks_list->elem;
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
1815 for (i=0; !res && i<blocks_list->nb_elem; i++)
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
1816 if (blocks[i].bin.size > 0)
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
1817 res=matroska_parse_block(matroska,
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
1818 blocks[i].bin.data, blocks[i].bin.size,
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
1819 blocks[i].bin.pos, cluster.timecode,
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
1820 blocks[i].duration, !blocks[i].reference);
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
1821 ebml_free(matroska_cluster, &cluster);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1822 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1823 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1824
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1825 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1826 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
1827 AVPacket *pkt)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1828 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1829 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
1830
1899
1324ae790ee0 parse clusters until some packets are queued
aurel
parents: 1898
diff changeset
1831 while (matroska_deliver_packet(matroska, pkt)) {
1900
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
1832 if (matroska->done)
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
1833 return AVERROR(EIO);
3653
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
1834 if (matroska_parse_cluster(matroska) < 0)
1900
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
1835 matroska->done = 1;
1899
1324ae790ee0 parse clusters until some packets are queued
aurel
parents: 1898
diff changeset
1836 }
1324ae790ee0 parse clusters until some packets are queued
aurel
parents: 1898
diff changeset
1837
1324ae790ee0 parse clusters until some packets are queued
aurel
parents: 1898
diff changeset
1838 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
1839 }
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 static int
2012
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1842 matroska_read_seek (AVFormatContext *s, int stream_index, int64_t timestamp,
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1843 int flags)
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1844 {
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1845 MatroskaDemuxContext *matroska = s->priv_data;
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1846 AVStream *st = s->streams[stream_index];
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1847 int index;
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1848
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1849 index = av_index_search_timestamp(st, timestamp, flags);
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1850 if (index < 0)
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1851 return 0;
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1852
2872
a9bb4614c0f8 clear internal queue when seeking
aurel
parents: 2871
diff changeset
1853 matroska_clear_queue(matroska);
a9bb4614c0f8 clear internal queue when seeking
aurel
parents: 2871
diff changeset
1854
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
1855 url_fseek(s->pb, st->index_entries[index].pos, SEEK_SET);
2014
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
1856 matroska->skip_to_keyframe = !(flags & AVSEEK_FLAG_ANY);
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
1857 matroska->skip_to_stream = st;
2012
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1858 matroska->peek_id = 0;
3462
3f87bde8a97c matroskadec: set cur_dts after seek
aurel
parents: 3427
diff changeset
1859 av_update_cur_dts(s, st, st->index_entries[index].timestamp);
2012
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1860 return 0;
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1861 }
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1862
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1863 static int
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1864 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
1865 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1866 MatroskaDemuxContext *matroska = s->priv_data;
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1867 MatroskaTrack *tracks = matroska->tracks.elem;
3656
9a2d1f2a39ee matroskadec: remove useless initialization
aurel
parents: 3655
diff changeset
1868 int n;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1869
2871
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
1870 matroska_clear_queue(matroska);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1871
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1872 for (n=0; n < matroska->tracks.nb_elem; n++)
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1873 if (tracks[n].type == MATROSKA_TRACK_TYPE_AUDIO)
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1874 av_free(tracks[n].audio.buf);
3651
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
1875 ebml_free(matroska_segment, matroska);
380
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 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1878 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1879
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
1880 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
1881 "matroska",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3422
diff changeset
1882 NULL_IF_CONFIG_SMALL("Matroska file format"),
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1883 sizeof(MatroskaDemuxContext),
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1884 matroska_probe,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1885 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
1886 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
1887 matroska_read_close,
2012
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1888 matroska_read_seek,
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1889 };