annotate matroskadec.c @ 3648:07f046bf6849 libavformat

matroskadec: move declaration to upper block
author aurel
date Tue, 05 Aug 2008 00:40:49 +0000
parents 98eb4eb368fa
children 71da9d010bae
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
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
171 typedef struct MatroskaLevel {
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
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
176 typedef struct MatroskaDemuxContext {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
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
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
184 /* timescale in the file */
3641
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
185 uint64_t time_scale;
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
186 double duration;
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
187 char *title;
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
188 EbmlList tracks;
3640
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
189 EbmlList attachments;
3639
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
190 EbmlList chapters;
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
191 EbmlList index;
3644
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
192 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
193
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
194 /* 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
195 * for ( = that are available to the calling program). */
2147
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
196 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
197
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
198 /* 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
199 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
200
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
201 /* 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
202 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
203
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
204 /* 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
205 AVPacket **packets;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
206 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
207
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
208 /* have we already parse metadata/cues/clusters? */
2147
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
209 int metadata_parsed;
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
210 int index_parsed;
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
211 int done;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
212
2014
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
213 /* 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
214 int skip_to_keyframe;
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
215 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
216 } MatroskaDemuxContext;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
217
3413
b7f86452706e matroskadec: move ARRAY_SIZE() macro at top of the file
aurel
parents: 3409
diff changeset
218 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(*x))
b7f86452706e matroskadec: move ARRAY_SIZE() macro at top of the file
aurel
parents: 3409
diff changeset
219
3633
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
220 static EbmlSyntax ebml_header[] = {
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
221 { 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
222 { 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
223 { 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
224 { 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
225 { 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
226 { EBML_ID_EBMLVERSION, EBML_NONE },
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
227 { EBML_ID_DOCTYPEVERSION, EBML_NONE },
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
228 { EBML_ID_VOID, EBML_NONE },
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
229 { 0 }
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
230 };
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
231
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
232 static EbmlSyntax ebml_syntax[] = {
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
233 { 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
234 { 0 }
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
235 };
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
236
3641
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
237 static EbmlSyntax matroska_info[] = {
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
238 { 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
239 { MATROSKA_ID_DURATION, EBML_FLOAT, 0, offsetof(MatroskaDemuxContext,duration) },
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
240 { MATROSKA_ID_TITLE, EBML_UTF8, 0, offsetof(MatroskaDemuxContext,title) },
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
241 { MATROSKA_ID_WRITINGAPP, EBML_NONE },
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
242 { MATROSKA_ID_MUXINGAPP, EBML_NONE },
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
243 { MATROSKA_ID_DATEUTC, EBML_NONE },
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
244 { MATROSKA_ID_SEGMENTUID, EBML_NONE },
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
245 { EBML_ID_VOID, EBML_NONE },
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
246 { 0 }
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
247 };
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
248
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
249 static EbmlSyntax matroska_track_video[] = {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
250 { MATROSKA_ID_VIDEOFRAMERATE, EBML_FLOAT,0, offsetof(MatroskaTrackVideo,frame_rate) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
251 { MATROSKA_ID_VIDEODISPLAYWIDTH, EBML_UINT, 0, offsetof(MatroskaTrackVideo,display_width) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
252 { MATROSKA_ID_VIDEODISPLAYHEIGHT, EBML_UINT, 0, offsetof(MatroskaTrackVideo,display_height) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
253 { MATROSKA_ID_VIDEOPIXELWIDTH, EBML_UINT, 0, offsetof(MatroskaTrackVideo,pixel_width) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
254 { MATROSKA_ID_VIDEOPIXELHEIGHT, EBML_UINT, 0, offsetof(MatroskaTrackVideo,pixel_height) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
255 { MATROSKA_ID_VIDEOCOLORSPACE, EBML_UINT, 0, offsetof(MatroskaTrackVideo,fourcc) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
256 { MATROSKA_ID_VIDEOFLAGINTERLACED,EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
257 { MATROSKA_ID_VIDEOSTEREOMODE, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
258 { MATROSKA_ID_VIDEOASPECTRATIO, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
259 { EBML_ID_VOID, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
260 { 0 }
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
261 };
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
262
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
263 static EbmlSyntax matroska_track_audio[] = {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
264 { 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
265 { MATROSKA_ID_AUDIOOUTSAMPLINGFREQ,EBML_FLOAT,0,offsetof(MatroskaTrackAudio,out_samplerate) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
266 { MATROSKA_ID_AUDIOBITDEPTH, EBML_UINT, 0, offsetof(MatroskaTrackAudio,bitdepth) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
267 { MATROSKA_ID_AUDIOCHANNELS, EBML_UINT, 0, offsetof(MatroskaTrackAudio,channels), {.u=1} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
268 { EBML_ID_VOID, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
269 { 0 }
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
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
272 static EbmlSyntax matroska_track_encoding_compression[] = {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
273 { MATROSKA_ID_ENCODINGCOMPALGO, EBML_UINT, 0, offsetof(MatroskaTrackCompression,algo), {.u=0} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
274 { MATROSKA_ID_ENCODINGCOMPSETTINGS,EBML_BIN, 0, offsetof(MatroskaTrackCompression,settings) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
275 { EBML_ID_VOID, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
276 { 0 }
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
277 };
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 static EbmlSyntax matroska_track_encoding[] = {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
280 { MATROSKA_ID_ENCODINGSCOPE, EBML_UINT, 0, offsetof(MatroskaTrackEncoding,scope), {.u=1} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
281 { MATROSKA_ID_ENCODINGTYPE, EBML_UINT, 0, offsetof(MatroskaTrackEncoding,type), {.u=0} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
282 { 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
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_encodings[] = {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
288 { 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
289 { EBML_ID_VOID, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
290 { 0 }
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
291 };
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
292
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
293 static EbmlSyntax matroska_track[] = {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
294 { MATROSKA_ID_TRACKNUMBER, EBML_UINT, 0, offsetof(MatroskaTrack,num) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
295 { MATROSKA_ID_TRACKTYPE, EBML_UINT, 0, offsetof(MatroskaTrack,type) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
296 { MATROSKA_ID_CODECID, EBML_STR, 0, offsetof(MatroskaTrack,codec_id) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
297 { MATROSKA_ID_CODECPRIVATE, EBML_BIN, 0, offsetof(MatroskaTrack,codec_priv) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
298 { MATROSKA_ID_TRACKLANGUAGE, EBML_UTF8, 0, offsetof(MatroskaTrack,language), {.s="eng"} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
299 { MATROSKA_ID_TRACKDEFAULTDURATION, EBML_UINT, 0, offsetof(MatroskaTrack,default_duration) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
300 { 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
301 { 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
302 { 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
303 { 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
304 { MATROSKA_ID_TRACKCONTENTENCODINGS,EBML_NEST, 0, 0, {.n=matroska_track_encodings} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
305 { MATROSKA_ID_TRACKUID, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
306 { MATROSKA_ID_TRACKNAME, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
307 { MATROSKA_ID_TRACKFLAGENABLED, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
308 { MATROSKA_ID_TRACKFLAGFORCED, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
309 { MATROSKA_ID_TRACKFLAGLACING, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
310 { MATROSKA_ID_CODECNAME, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
311 { MATROSKA_ID_CODECDECODEALL, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
312 { MATROSKA_ID_CODECINFOURL, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
313 { MATROSKA_ID_CODECDOWNLOADURL, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
314 { MATROSKA_ID_TRACKMINCACHE, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
315 { MATROSKA_ID_TRACKMAXCACHE, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
316 { EBML_ID_VOID, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
317 { 0 }
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
318 };
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
319
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
320 static EbmlSyntax matroska_tracks[] = {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
321 { 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
322 { EBML_ID_VOID, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
323 { 0 }
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
324 };
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
325
3640
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
326 static EbmlSyntax matroska_attachment[] = {
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
327 { MATROSKA_ID_FILENAME, EBML_UTF8, 0, offsetof(MatroskaAttachement,filename) },
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
328 { MATROSKA_ID_FILEMIMETYPE, EBML_STR, 0, offsetof(MatroskaAttachement,mime) },
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
329 { MATROSKA_ID_FILEDATA, EBML_BIN, 0, offsetof(MatroskaAttachement,bin) },
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
330 { MATROSKA_ID_FILEUID, EBML_NONE },
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
331 { EBML_ID_VOID, EBML_NONE },
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
332 { 0 }
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
333 };
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
334
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
335 static EbmlSyntax matroska_attachments[] = {
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
336 { 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
337 { EBML_ID_VOID, EBML_NONE },
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
338 { 0 }
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
339 };
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
340
3639
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
341 static EbmlSyntax matroska_chapter_display[] = {
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
342 { MATROSKA_ID_CHAPSTRING, EBML_UTF8, 0, offsetof(MatroskaChapter,title) },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
343 { EBML_ID_VOID, EBML_NONE },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
344 { 0 }
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
345 };
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
346
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
347 static EbmlSyntax matroska_chapter_entry[] = {
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
348 { 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
349 { 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
350 { MATROSKA_ID_CHAPTERUID, EBML_UINT, 0, offsetof(MatroskaChapter,uid) },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
351 { MATROSKA_ID_CHAPTERDISPLAY, EBML_NEST, 0, 0, {.n=matroska_chapter_display} },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
352 { MATROSKA_ID_CHAPTERFLAGHIDDEN, EBML_NONE },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
353 { EBML_ID_VOID, EBML_NONE },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
354 { 0 }
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
355 };
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
356
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
357 static EbmlSyntax matroska_chapter[] = {
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
358 { 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
359 { MATROSKA_ID_EDITIONUID, EBML_NONE },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
360 { MATROSKA_ID_EDITIONFLAGHIDDEN, EBML_NONE },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
361 { MATROSKA_ID_EDITIONFLAGDEFAULT, EBML_NONE },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
362 { EBML_ID_VOID, EBML_NONE },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
363 { 0 }
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
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
366 static EbmlSyntax matroska_chapters[] = {
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
367 { MATROSKA_ID_EDITIONENTRY, EBML_NEST, 0, 0, {.n=matroska_chapter} },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
368 { EBML_ID_VOID, EBML_NONE },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
369 { 0 }
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
370 };
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
371
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
372 static EbmlSyntax matroska_index_pos[] = {
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
373 { MATROSKA_ID_CUETRACK, EBML_UINT, 0, offsetof(MatroskaIndexPos,track) },
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
374 { MATROSKA_ID_CUECLUSTERPOSITION, EBML_UINT, 0, offsetof(MatroskaIndexPos,pos) },
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
375 { EBML_ID_VOID, EBML_NONE },
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
376 { 0 }
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
377 };
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
378
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
379 static EbmlSyntax matroska_index_entry[] = {
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
380 { MATROSKA_ID_CUETIME, EBML_UINT, 0, offsetof(MatroskaIndex,time) },
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
381 { 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
382 { EBML_ID_VOID, EBML_NONE },
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
383 { 0 }
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
384 };
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 static EbmlSyntax matroska_index[] = {
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
387 { 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
388 { EBML_ID_VOID, EBML_NONE },
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
389 { 0 }
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
390 };
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
391
3638
5897e0c8a1eb matroskadec: use generic parser to parse tags
aurel
parents: 3637
diff changeset
392 static EbmlSyntax matroska_tags[] = {
5897e0c8a1eb matroskadec: use generic parser to parse tags
aurel
parents: 3637
diff changeset
393 { EBML_ID_VOID, EBML_NONE },
5897e0c8a1eb matroskadec: use generic parser to parse tags
aurel
parents: 3637
diff changeset
394 { 0 }
5897e0c8a1eb matroskadec: use generic parser to parse tags
aurel
parents: 3637
diff changeset
395 };
5897e0c8a1eb matroskadec: use generic parser to parse tags
aurel
parents: 3637
diff changeset
396
3644
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
397 static EbmlSyntax matroska_seekhead_entry[] = {
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
398 { MATROSKA_ID_SEEKID, EBML_UINT, 0, offsetof(MatroskaSeekhead,id) },
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
399 { MATROSKA_ID_SEEKPOSITION, EBML_UINT, 0, offsetof(MatroskaSeekhead,pos), {.u=-1} },
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
400 { EBML_ID_VOID, EBML_NONE },
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
401 { 0 }
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
402 };
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
403
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
404 static EbmlSyntax matroska_seekhead[] = {
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
405 { 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
406 { EBML_ID_VOID, EBML_NONE },
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
407 { 0 }
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
408 };
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
409
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
410 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
411 * The first few functions handle EBML file parsing. The rest
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
412 * is the document interpretation. Matroska really just is a
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
413 * EBML file.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
414 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
415
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
416 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
417 * 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
418 * 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
419 * 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
420 * element reading.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
421 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
422
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
423 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
424 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
425 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
426 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
427 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
428 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
429
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
430 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
431 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
432
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
433 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
434 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
435 num++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
436 } else {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
437 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
438 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
439 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
440
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
441 return num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
442 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
443
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
444 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
445 * Read: 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
446 * 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
447 * 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
448 * "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
449 * number.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
450 * 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
451 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
452
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
453 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
454 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
455 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
456 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
457 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
458 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
459 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
460 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
461
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
462 /* 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
463 * 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
464 * 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
465 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
466 /* 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
467 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
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 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
470 "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
471 pos, pos);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
472 }
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
473 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
474 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
475
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
476 /* 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
477 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
478 read++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
479 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
480 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
481 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
482 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
483 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
484 "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
485 (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
486 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
487 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
488
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
489 /* read out length */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
490 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
491 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
492 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
493
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
494 *number = total;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
495
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
496 return read;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
497 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
498
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
499 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
500 * 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
501 * 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
502 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
503
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
504 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
505 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
506 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
507 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
508 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
509 int read;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
510 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
511
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
512 /* 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
513 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
514 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
515 *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
516 *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
517 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
518 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
519
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
520 /* 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
521 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
522 return read;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
523 *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
524
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
525 /* level tracking */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
526 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
527 *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
528
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
529 return read;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
530 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
531
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
532 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
533 * 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
534 * 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
535 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
536
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
537 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
538 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
539 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
540 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
541 /* 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
542 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
543
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
544 /* 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
545 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
546 }
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 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
549 * 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
550 * 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
551 * 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
552 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
553
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
554 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
555 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
556 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
557 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
558 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
559
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
560 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
561 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
562
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
563 return id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
564 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
565
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
566 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
567 * 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
568 * 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
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 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
572 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
573 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
574 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
575 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
576
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
577 /* 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
578 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
579
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
580 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
581 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
582
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
583 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
584 * 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
585 * 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
586 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
587
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
588 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
589 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
590 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
591 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
592 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
593 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
594 int res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
595
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
596 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
597 (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
598 return res;
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 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
601
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
602 return 0;
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
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
605 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
606 * 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
607 * 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
608 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
609
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
610 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
611 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
612 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
613 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
614 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
615 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
616 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
617 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
618
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
619 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
620 (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
621 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
622 size = rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
623 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
624 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
625 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
626 "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
627 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
628 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
629 }
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 /* 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
632 *num = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
633 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
634 *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
635
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
636 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
637 }
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 * Read the next element as a signed int.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
641 * 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
642 */
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_sint (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
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 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
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 size, n = 1, negative = 0, res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
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 sint element size %d at position %"PRId64" (0x%"PRIx64")\n",
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
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 if ((*num = get_byte(pb)) & 0x80) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
665 negative = 1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
666 *num &= ~0x80;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
667 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
668 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
669 *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
670
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
671 /* make signed */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
672 if (negative)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
673 *num = *num - (1LL << ((8 * size) - 1));
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
674
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
675 return 0;
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
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
678 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
679 * 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
680 * 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
681 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
682
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
683 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
684 ebml_read_float (MatroskaDemuxContext *matroska,
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
685 uint32_t *id,
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
686 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
687 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
688 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
689 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
690 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
691
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
692 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
693 (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
694 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
695 size = rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
696
824
779b1e87b865 more non portable float parsing code ...
michael
parents: 820
diff changeset
697 if (size == 4) {
779b1e87b865 more non portable float parsing code ...
michael
parents: 820
diff changeset
698 *num= av_int2flt(get_be32(pb));
779b1e87b865 more non portable float parsing code ...
michael
parents: 820
diff changeset
699 } else if(size==8){
779b1e87b865 more non portable float parsing code ...
michael
parents: 820
diff changeset
700 *num= av_int2dbl(get_be64(pb));
779b1e87b865 more non portable float parsing code ...
michael
parents: 820
diff changeset
701 } else{
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
702 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
703 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
704 "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
705 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
706 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
707 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
708
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
709 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
710 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
711
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
712 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
713 * 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
714 * 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
715 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
716
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
717 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
718 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
719 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
720 char **str)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
721 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
722 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
723 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
724 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
725
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
726 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
727 (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
728 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
729 size = rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
730
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
731 /* 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
732 * byte more, read the string and NULL-terminate it ourselves. */
639
0b52743104ac integer overflows, heap corruption
michael
parents: 496
diff changeset
733 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
734 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
735 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
736 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
737 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
738 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
739 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
740 "Read error at pos. %"PRIu64" (0x%"PRIx64")\n", pos, pos);
3416
f386245ae6f7 matroskadec: fix potential mem leak
aurel
parents: 3415
diff changeset
741 av_free(*str);
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
742 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
743 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
744 (*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
745
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
746 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
747 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
748
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
749 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
750 * Read the next element as a UTF-8 string.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
751 * 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
752 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
753
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
754 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
755 ebml_read_utf8 (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
756 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
757 char **str)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
758 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
759 return ebml_read_ascii(matroska, id, str);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
760 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
761
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
762 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
763 * 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
764 * 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
765 * 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
766 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
767
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
768 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
769 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
770 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
771 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
772 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
773 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
774 MatroskaLevel *level;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
775 int res;
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 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
778 (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
779 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
780
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
781 /* protect... (Heaven forbids that the '>' is true) */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
782 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
783 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
784 "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
785 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
786 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
787
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
788 /* remember level */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
789 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
790 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
791 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
792
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
793 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
794 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
795
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
796 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
797 * 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
798 * 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
799 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
800
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
801 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
802 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
803 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
804 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
805 int *size)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
806 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
807 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
808 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
809 int res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
810
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
811 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
812 (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
813 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
814 *size = rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
815
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
816 if (!(*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
817 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
818 "Memory allocation error\n");
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2264
diff changeset
819 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
820 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
821
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
822 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
823 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
824 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
825 "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
826 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
827 }
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 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
830 }
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 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
833 * 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
834 * 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
835 * 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
836 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
837
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
838 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
839 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
840 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
841 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
842 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
843 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
844 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
845
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
846 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
847 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
848
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
849 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
850 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
851 read++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
852 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
853 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
854 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
855 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
856
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
857 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
858 num_ffs++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
859 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
860 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
861 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
862 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
863 num_ffs++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
864 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
865 n++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
866 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
867
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
868 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
869 *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
870 else
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
871 *num = total;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
872
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
873 return read;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
874 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
875
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
876 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
877 * 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
878 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
879
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
880 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
881 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
882 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
883 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
884 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
885 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
886 int res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
887
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
888 /* 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
889 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
890 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
891
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
892 /* 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
893 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
894 *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
895 else
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
896 *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
897
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
898 return res;
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
2011
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
901
3636
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
902 static MatroskaTrack *
2011
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
903 matroska_find_track_by_num (MatroskaDemuxContext *matroska,
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
904 int num)
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
905 {
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
906 MatroskaTrack *tracks = matroska->tracks.elem;
2011
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
907 int i;
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
908
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
909 for (i=0; i < matroska->tracks.nb_elem; i++)
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
910 if (tracks[i].num == num)
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
911 return &tracks[i];
3636
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
912
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
913 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
914 return NULL;
2011
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
915 }
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
916
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
917
380
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 * 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
920 * 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
921 */
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 int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
924 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
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 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
928 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
929 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
930 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
931 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
932 (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
933 matroska->packets =
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
934 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
935 sizeof(AVPacket *));
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
936 } else {
1530
f65cd8910a5c simplify free()+set to NULL using av_freep()
aurel
parents: 1490
diff changeset
937 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
938 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
939 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
940 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
941 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
942
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
943 return -1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
944 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
945
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
946 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
947 * 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
948 * 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
949 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
950
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
951 static void
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
952 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
953 AVPacket *pkt)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
954 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
955 matroska->packets =
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
956 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
957 sizeof(AVPacket *));
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
958 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
959 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
960 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
961
2871
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
962 /*
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
963 * Free all packets in our internal queue.
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
964 */
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
965 static void
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
966 matroska_clear_queue (MatroskaDemuxContext *matroska)
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
967 {
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
968 if (matroska->packets) {
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
969 int n;
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
970 for (n = 0; n < matroska->num_packets; n++) {
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
971 av_free_packet(matroska->packets[n]);
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
972 av_free(matroska->packets[n]);
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
973 }
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
974 av_free(matroska->packets);
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
975 matroska->packets = NULL;
2881
dc2e92d4a903 move num_packets=0 where it belongs
aurel
parents: 2873
diff changeset
976 matroska->num_packets = 0;
2871
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
977 }
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
978 }
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
979
1904
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
980
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
981 /*
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
982 * Autodetecting...
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
983 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
984
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
985 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
986 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
987 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
988 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
989 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
990 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
991
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
992 /* ebml header? */
2185
7dd08e645d92 use intreadwrite functions in matroskadec
aurel
parents: 2175
diff changeset
993 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
994 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
995
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
996 /* 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
997 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
998 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
999 size++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1000 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
1001 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1002 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
1003 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1004 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
1005 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
1006 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
1007
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1008 /* 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
1009 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
1010 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1011
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1012 /* 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
1013 * 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
1014 * 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
1015 * Not fully fool-proof, but good enough. */
1828
f1397cd39ec3 fix an off-by-one error in probing function
aurel
parents: 1673
diff changeset
1016 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
1017 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
1018 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
1019
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1020 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1021 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1022
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1023 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1024 * From here on, it's all XML-style DTD stuff... Needs no comments.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1025 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1026
3632
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1027 static int ebml_parse(MatroskaDemuxContext *matroska, EbmlSyntax *syntax,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1028 void *data, uint32_t expected_id, int once);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1029
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1030 static int ebml_parse_elem(MatroskaDemuxContext *matroska,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1031 EbmlSyntax *syntax, void *data)
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 uint32_t id = syntax->id;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1034 EbmlBin *bin;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1035 int res;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1036
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1037 data = (char *)data + syntax->data_offset;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1038 if (syntax->list_elem_size) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1039 EbmlList *list = data;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1040 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
1041 data = (char*)list->elem + list->nb_elem*syntax->list_elem_size;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1042 memset(data, 0, syntax->list_elem_size);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1043 list->nb_elem++;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1044 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1045 bin = data;
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 switch (syntax->type) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1048 case EBML_UINT: return ebml_read_uint (matroska, &id, data);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1049 case EBML_FLOAT: return ebml_read_float(matroska, &id, data);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1050 case EBML_STR:
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1051 case EBML_UTF8: av_free(*(char **)data);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1052 return ebml_read_ascii(matroska, &id, data);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1053 case EBML_BIN: av_free(bin->data);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1054 bin->pos = url_ftell(matroska->ctx->pb);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1055 return ebml_read_binary(matroska, &id, &bin->data,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1056 &bin->size);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1057 case EBML_NEST: if ((res=ebml_read_master(matroska, &id)) < 0)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1058 return res;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1059 if (id == MATROSKA_ID_SEGMENT)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1060 matroska->segment_start = url_ftell(matroska->ctx->pb);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1061 return ebml_parse(matroska, syntax->def.n, data, 0, 0);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1062 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
1063 case EBML_STOP: *(int *)data = 1; return 1;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1064 default: return ebml_read_skip(matroska);
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
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1068 static int ebml_parse_id(MatroskaDemuxContext *matroska, EbmlSyntax *syntax,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1069 uint32_t id, void *data)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1070 {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1071 int i;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1072 for (i=0; syntax[i].id; i++)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1073 if (id == syntax[i].id)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1074 break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1075 if (!syntax[i].id)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1076 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
1077 return ebml_parse_elem(matroska, &syntax[i], data);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1078 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1079
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1080 static int ebml_parse(MatroskaDemuxContext *matroska, EbmlSyntax *syntax,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1081 void *data, uint32_t expected_id, int once)
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 int i, res = 0;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1084 uint32_t id = 0;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1085
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1086 for (i=0; syntax[i].id; i++)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1087 switch (syntax[i].type) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1088 case EBML_UINT:
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1089 *(uint64_t *)((char *)data+syntax[i].data_offset) = syntax[i].def.u;
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 case EBML_FLOAT:
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1092 *(double *)((char *)data+syntax[i].data_offset) = syntax[i].def.f;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1093 break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1094 case EBML_STR:
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1095 case EBML_UTF8:
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1096 *(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
1097 break;
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
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1100 if (expected_id) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1101 res = ebml_read_master(matroska, &id);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1102 if (id != expected_id)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1103 return AVERROR_INVALIDDATA;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1104 if (id == MATROSKA_ID_SEGMENT)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1105 matroska->segment_start = url_ftell(matroska->ctx->pb);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1106 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1107
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1108 while (!res) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1109 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1110 res = AVERROR(EIO);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1111 break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1112 } else if (matroska->level_up) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1113 matroska->level_up--;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1114 break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1115 }
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 res = ebml_parse_id(matroska, syntax, id, data);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1118 if (once)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1119 break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1120
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1121
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1122 if (matroska->level_up) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1123 matroska->level_up--;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1124 break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1125 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1126 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1127
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1128 return res;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1129 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1130
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1131 static void ebml_free(EbmlSyntax *syntax, void *data)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1132 {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1133 int i, j;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1134 for (i=0; syntax[i].id; i++) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1135 void *data_off = (char *)data + syntax[i].data_offset;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1136 switch (syntax[i].type) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1137 case EBML_STR:
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1138 case EBML_UTF8: av_freep(data_off); break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1139 case EBML_BIN: av_freep(&((EbmlBin *)data_off)->data); break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1140 case EBML_NEST:
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1141 if (syntax[i].list_elem_size) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1142 EbmlList *list = data_off;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1143 char *ptr = list->elem;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1144 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
1145 ebml_free(syntax[i].def.n, ptr);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1146 av_free(list->elem);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1147 } else
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1148 ebml_free(syntax[i].def.n, data_off);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1149 default: break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1150 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1151 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1152 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
1153
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1154 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1155 matroska_parse_info (MatroskaDemuxContext *matroska)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1156 {
3641
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
1157 int res = ebml_parse(matroska, matroska_info, matroska, MATROSKA_ID_INFO, 0);
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
1158
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
1159 if (matroska->duration)
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
1160 matroska->ctx->duration = matroska->duration * matroska->time_scale
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
1161 * 1000 / AV_TIME_BASE;
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
1162 if (matroska->title)
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
1163 strncpy(matroska->ctx->title, matroska->title,
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
1164 sizeof(matroska->ctx->title)-1);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1165
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1166 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1167 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1168
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1169 static int
3494
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1170 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
1171 {
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1172 MatroskaTrackEncoding *encodings = track->encodings.elem;
3494
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1173 uint8_t* data = *buf;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1174 int isize = *buf_size;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1175 uint8_t* pkt_data = NULL;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1176 int pkt_size = isize;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1177 int result = 0;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1178 int olen;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1179
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1180 switch (encodings[0].compression.algo) {
3494
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1181 case MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP:
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1182 return encodings[0].compression.settings.size;
3494
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1183 case MATROSKA_TRACK_ENCODING_COMP_LZO:
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1184 do {
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1185 olen = pkt_size *= 3;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1186 pkt_data = av_realloc(pkt_data,
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1187 pkt_size+LZO_OUTPUT_PADDING);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1188 result = lzo1x_decode(pkt_data, &olen, data, &isize);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1189 } while (result==LZO_OUTPUT_FULL && pkt_size<10000000);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1190 if (result)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1191 goto failed;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1192 pkt_size -= olen;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1193 break;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1194 #ifdef CONFIG_ZLIB
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1195 case MATROSKA_TRACK_ENCODING_COMP_ZLIB: {
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1196 z_stream zstream = {0};
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1197 if (inflateInit(&zstream) != Z_OK)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1198 return -1;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1199 zstream.next_in = data;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1200 zstream.avail_in = isize;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1201 do {
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1202 pkt_size *= 3;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1203 pkt_data = av_realloc(pkt_data, pkt_size);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1204 zstream.avail_out = pkt_size - zstream.total_out;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1205 zstream.next_out = pkt_data + zstream.total_out;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1206 result = inflate(&zstream, Z_NO_FLUSH);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1207 } while (result==Z_OK && pkt_size<10000000);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1208 pkt_size = zstream.total_out;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1209 inflateEnd(&zstream);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1210 if (result != Z_STREAM_END)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1211 goto failed;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1212 break;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1213 }
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1214 #endif
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1215 #ifdef CONFIG_BZLIB
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1216 case MATROSKA_TRACK_ENCODING_COMP_BZLIB: {
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1217 bz_stream bzstream = {0};
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1218 if (BZ2_bzDecompressInit(&bzstream, 0, 0) != BZ_OK)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1219 return -1;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1220 bzstream.next_in = data;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1221 bzstream.avail_in = isize;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1222 do {
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1223 pkt_size *= 3;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1224 pkt_data = av_realloc(pkt_data, pkt_size);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1225 bzstream.avail_out = pkt_size - bzstream.total_out_lo32;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1226 bzstream.next_out = pkt_data + bzstream.total_out_lo32;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1227 result = BZ2_bzDecompress(&bzstream);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1228 } while (result==BZ_OK && pkt_size<10000000);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1229 pkt_size = bzstream.total_out_lo32;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1230 BZ2_bzDecompressEnd(&bzstream);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1231 if (result != BZ_STREAM_END)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1232 goto failed;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1233 break;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1234 }
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1235 #endif
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1236 }
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1237
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1238 *buf = pkt_data;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1239 *buf_size = pkt_size;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1240 return 0;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1241 failed:
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1242 av_free(pkt_data);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1243 return -1;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1244 }
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1245
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1246 static int
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1247 matroska_parse_tracks (MatroskaDemuxContext *matroska)
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1248 {
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1249 MatroskaTrack *tracks;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1250 int i, res;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1251
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1252 res = ebml_parse(matroska, matroska_tracks, matroska, MATROSKA_ID_TRACKS, 0);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1253
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1254 tracks = matroska->tracks.elem;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1255 for (i=0; i<matroska->tracks.nb_elem; i++) {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1256 MatroskaTrack *track = &tracks[i];
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1257 EbmlList *encodings_list = &tracks->encodings;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1258 MatroskaTrackEncoding *encodings = encodings_list->elem;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1259
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1260 if (track->type != MATROSKA_TRACK_TYPE_VIDEO &&
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1261 track->type != MATROSKA_TRACK_TYPE_AUDIO &&
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1262 track->type != MATROSKA_TRACK_TYPE_SUBTITLE) {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1263 av_log(matroska->ctx, AV_LOG_INFO,
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1264 "Unknown or unsupported track type %"PRIu64"\n",
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1265 track->type);
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1266 continue;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1267 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1268
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1269 if (track->type == MATROSKA_TRACK_TYPE_VIDEO) {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1270 if (!track->default_duration)
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1271 track->default_duration = 1000000000/track->video.frame_rate;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1272 if (!track->video.display_width)
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1273 track->video.display_width = track->video.pixel_width;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1274 if (!track->video.display_height)
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1275 track->video.display_height = track->video.pixel_height;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1276 } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1277 if (!track->audio.out_samplerate)
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1278 track->audio.out_samplerate = track->audio.samplerate;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1279 }
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1280 if (encodings_list->nb_elem > 1) {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1281 av_log(matroska->ctx, AV_LOG_ERROR,
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1282 "Multiple combined encodings no supported");
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1283 } else if (encodings_list->nb_elem == 1) {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1284 if (encodings[0].type ||
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1285 (encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP &&
3293
d3818f6d7530 matroskadec: add support for zlib compressed tracks
aurel
parents: 3290
diff changeset
1286 #ifdef CONFIG_ZLIB
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1287 encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_ZLIB &&
3293
d3818f6d7530 matroskadec: add support for zlib compressed tracks
aurel
parents: 3290
diff changeset
1288 #endif
3298
edabe3db2b6e matroskadec: add support for bzlib compressed tracks
aurel
parents: 3294
diff changeset
1289 #ifdef CONFIG_BZLIB
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1290 encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_BZLIB &&
3298
edabe3db2b6e matroskadec: add support for bzlib compressed tracks
aurel
parents: 3294
diff changeset
1291 #endif
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1292 encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_LZO)) {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1293 encodings[0].scope = 0;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1294 av_log(matroska->ctx, AV_LOG_ERROR,
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1295 "Unsupported encoding type");
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1296 } else if (track->codec_priv.size && encodings[0].scope&2) {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1297 uint8_t *codec_priv = track->codec_priv.data;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1298 int offset = matroska_decode_buffer(&track->codec_priv.data,
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1299 &track->codec_priv.size,
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1300 track);
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1301 if (offset < 0) {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1302 track->codec_priv.data = NULL;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1303 track->codec_priv.size = 0;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1304 av_log(matroska->ctx, AV_LOG_ERROR,
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1305 "Failed to decode codec private data\n");
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1306 } else if (offset > 0) {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1307 track->codec_priv.data = av_malloc(track->codec_priv.size + offset);
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1308 memcpy(track->codec_priv.data,
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1309 encodings[0].compression.settings.data, offset);
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1310 memcpy(track->codec_priv.data+offset, codec_priv,
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1311 track->codec_priv.size);
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1312 track->codec_priv.size += offset;
3279
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1313 }
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1314 if (codec_priv != track->codec_priv.data)
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1315 av_free(codec_priv);
3408
da09478c97ce matroskadec: read TrackTimecodeScale and set timebase accordingly
aurel
parents: 3407
diff changeset
1316 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1317 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1318 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1319
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1320 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1321 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1322
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1323 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1324 matroska_parse_index (MatroskaDemuxContext *matroska)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1325 {
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1326 return ebml_parse(matroska, matroska_index, matroska, MATROSKA_ID_CUES, 0);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1327 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1328
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1329 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1330 matroska_parse_metadata (MatroskaDemuxContext *matroska)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1331 {
3638
5897e0c8a1eb matroskadec: use generic parser to parse tags
aurel
parents: 3637
diff changeset
1332 return ebml_parse(matroska, matroska_tags, matroska, MATROSKA_ID_TAGS, 0);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1333 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1334
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1335 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1336 matroska_parse_seekhead (MatroskaDemuxContext *matroska)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1337 {
3644
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1338 return ebml_parse(matroska, matroska_seekhead, matroska, MATROSKA_ID_SEEKHEAD, 0);
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1339 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1340
3644
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1341 static void
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1342 matroska_execute_seekhead(MatroskaDemuxContext *matroska)
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1343 {
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1344 EbmlList *seekhead_list = &matroska->seekhead;
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1345 MatroskaSeekhead *seekhead = seekhead_list->elem;
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1346 uint32_t peek_id_cache = matroska->peek_id;
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1347 uint32_t level_up = matroska->level_up;
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1348 offset_t before_pos = url_ftell(matroska->ctx->pb);
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1349 MatroskaLevel level;
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1350 uint32_t id;
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1351 int i, res;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1352
3644
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1353 for (i=0; i<seekhead_list->nb_elem; i++) {
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1354 if (seekhead[i].pos <= before_pos
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1355 || seekhead[i].id == MATROSKA_ID_SEEKHEAD
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1356 || seekhead[i].id == MATROSKA_ID_CLUSTER)
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1357 continue;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1358
3646
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1359 /* seek */
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1360 if (ebml_read_seek(matroska,
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1361 seekhead[i].pos+matroska->segment_start) < 0)
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1362 continue;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1363
3646
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1364 /* 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
1365 * a dummy. This is a crude hack. */
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1366 if (matroska->num_levels == EBML_MAX_DEPTH) {
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1367 av_log(matroska->ctx, AV_LOG_INFO,
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1368 "Max EBML element depth (%d) reached, "
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1369 "cannot parse further.\n", EBML_MAX_DEPTH);
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1370 break;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1371 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 883
diff changeset
1372
3646
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1373 level.start = 0;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1374 level.length = (uint64_t)-1;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1375 matroska->levels[matroska->num_levels] = level;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1376 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
1377
3646
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1378 /* check ID */
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1379 if (!(id = ebml_peek_id (matroska,
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1380 &matroska->level_up)))
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1381 goto finish;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1382 if (id != seekhead[i].id) {
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1383 av_log(matroska->ctx, AV_LOG_INFO,
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1384 "We looked for ID=0x%x but got "
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1385 "ID=0x%x (pos=%"PRIu64")",
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1386 (int)seekhead[i].id, id, seekhead[i].pos +
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1387 matroska->segment_start);
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1388 goto finish;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1389 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1390
3646
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1391 /* read master + parse */
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1392 switch (id) {
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1393 case MATROSKA_ID_CUES:
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1394 if (!(res = matroska_parse_index(matroska)) ||
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1395 url_feof(matroska->ctx->pb)) {
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1396 matroska->index_parsed = 1;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1397 res = 0;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1398 }
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1399 break;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1400 case MATROSKA_ID_TAGS:
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1401 if (!(res = matroska_parse_metadata(matroska)) ||
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1402 url_feof(matroska->ctx->pb)) {
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1403 matroska->metadata_parsed = 1;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1404 res = 0;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1405 }
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1406 break;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1407 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1408
3646
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1409 finish:
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1410 /* remove dummy level */
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1411 while (matroska->num_levels) {
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1412 uint64_t length = matroska->levels[--matroska->num_levels].length;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1413 if (length == (uint64_t)-1)
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1414 break;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1415 }
3644
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
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
3646
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1418 /* seek back */
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1419 ebml_read_seek(matroska, before_pos);
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1420 matroska->peek_id = peek_id_cache;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1421 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
1422 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1423
2973
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1424 static int
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1425 matroska_parse_attachments(AVFormatContext *s)
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1426 {
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1427 MatroskaDemuxContext *matroska = s->priv_data;
3640
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
1428 EbmlList *attachements_list = &matroska->attachments;
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
1429 MatroskaAttachement *attachements;
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
1430 int i, j, res;
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
1431
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
1432 res = ebml_parse(matroska, matroska_attachments, matroska, MATROSKA_ID_ATTACHMENTS, 0);
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
1433
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
1434 attachements = attachements_list->elem;
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
1435 for (j=0; j<attachements_list->nb_elem; j++) {
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
1436 if (!(attachements[j].filename && attachements[j].mime &&
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
1437 attachements[j].bin.data && attachements[j].bin.size > 0)) {
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
1438 av_log(matroska->ctx, AV_LOG_ERROR, "incomplete attachment\n");
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
1439 } else {
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
1440 AVStream *st = av_new_stream(s, matroska->num_streams++);
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
1441 if (st == NULL)
2973
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1442 break;
3640
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
1443 st->filename = av_strdup(attachements[j].filename);
2973
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1444 st->codec->codec_id = CODEC_ID_NONE;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1445 st->codec->codec_type = CODEC_TYPE_ATTACHMENT;
3640
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
1446 st->codec->extradata = av_malloc(attachements[j].bin.size);
2973
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1447 if(st->codec->extradata == NULL)
3640
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
1448 break;
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
1449 st->codec->extradata_size = attachements[j].bin.size;
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
1450 memcpy(st->codec->extradata, attachements[j].bin.data, attachements[j].bin.size);
2973
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1451
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1452 for (i=0; ff_mkv_mime_tags[i].id != CODEC_ID_NONE; i++) {
3640
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
1453 if (!strncmp(ff_mkv_mime_tags[i].str, attachements[j].mime,
2973
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1454 strlen(ff_mkv_mime_tags[i].str))) {
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1455 st->codec->codec_id = ff_mkv_mime_tags[i].id;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1456 break;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1457 }
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1458 }
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1459 }
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1460 }
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1461
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1462 return res;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1463 }
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1464
3315
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
1465 static int
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
1466 matroska_parse_chapters(AVFormatContext *s)
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
1467 {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
1468 MatroskaDemuxContext *matroska = s->priv_data;
3639
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
1469 EbmlList *chapters_list = &matroska->chapters;
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
1470 MatroskaChapter *chapters;
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
1471 int i, res;
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
1472
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
1473 res = ebml_parse(matroska, matroska_chapters, matroska, MATROSKA_ID_CHAPTERS, 0);
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
1474
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
1475 chapters = chapters_list->elem;
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
1476 for (i=0; i<chapters_list->nb_elem; i++)
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
1477 if (chapters[i].start != AV_NOPTS_VALUE && chapters[i].uid)
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
1478 ff_new_chapter(s, chapters[i].uid, (AVRational){1, 1000000000},
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
1479 chapters[i].start, chapters[i].end,
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
1480 chapters[i].title);
3315
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
1481
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
1482 return res;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
1483 }
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
1484
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1485 static int
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1486 matroska_aac_profile (char *codec_id)
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1487 {
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1488 static const char *aac_profiles[] = {
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1489 "MAIN", "LC", "SSR"
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1490 };
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1491 int profile;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1492
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1493 for (profile=0; profile<ARRAY_SIZE(aac_profiles); profile++)
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1494 if (strstr(codec_id, aac_profiles[profile]))
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1495 break;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1496 return profile + 1;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1497 }
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1498
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1499 static int
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1500 matroska_aac_sri (int samplerate)
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1501 {
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1502 int sri;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1503
3201
1a16b069daca use common aac sample rate tables
aurel
parents: 3199
diff changeset
1504 for (sri=0; sri<ARRAY_SIZE(ff_mpeg4audio_sample_rates); sri++)
1a16b069daca use common aac sample rate tables
aurel
parents: 3199
diff changeset
1505 if (ff_mpeg4audio_sample_rates[sri] == samplerate)
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1506 break;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1507 return sri;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1508 }
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1509
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1510 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1511 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
1512 AVFormatParameters *ap)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1513 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1514 MatroskaDemuxContext *matroska = s->priv_data;
3648
07f046bf6849 matroskadec: move declaration to upper block
aurel
parents: 3647
diff changeset
1515 MatroskaTrack *tracks;
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1516 EbmlList *index_list;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1517 MatroskaIndex *index;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1518 int i, j, last_level, res = 0;
3633
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
1519 Ebml ebml = { 0 };
3648
07f046bf6849 matroskadec: move declaration to upper block
aurel
parents: 3647
diff changeset
1520 AVStream *st;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1521 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
1522
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1523 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
1524
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1525 /* First read the EBML header. */
3633
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
1526 if (ebml_parse(matroska, ebml_syntax, &ebml, 0, 1)
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
1527 || 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
1528 || 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
1529 || 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
1530 av_log(matroska->ctx, AV_LOG_ERROR,
3633
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
1531 "EBML header using unsupported features\n"
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
1532 "(EBML version %"PRIu64", doctype %s, doc version %"PRIu64")\n",
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
1533 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
1534 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
1535 }
3633
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
1536 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
1537
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1538 /* The next thing is a segment. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1539 while (1) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1540 if (!(id = ebml_peek_id(matroska, &last_level)))
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
1541 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
1542 if (id == MATROSKA_ID_SEGMENT)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1543 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1544
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1545 /* oi! */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1546 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1547 "Expected a Segment ID (0x%x), but received 0x%x!\n",
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1548 MATROSKA_ID_SEGMENT, id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1549 if ((res = ebml_read_skip(matroska)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1550 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1551 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1552
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1553 /* We now have a Matroska segment.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1554 * Seeks are from the beginning of the segment,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1555 * after the segment ID/length. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1556 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1557 return res;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
1558 matroska->segment_start = url_ftell(s->pb);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1559
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1560 matroska->time_scale = 1000000;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1561 /* we've found our segment, start reading the different contents in here */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1562 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1563 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
1564 res = 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
1565 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1566 } else if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1567 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1568 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1569 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1570
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1571 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1572 /* stream info */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1573 case MATROSKA_ID_INFO: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1574 res = matroska_parse_info(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1575 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1576 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1577
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1578 /* track info headers */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1579 case MATROSKA_ID_TRACKS: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1580 res = matroska_parse_tracks(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1581 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1582 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1583
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1584 /* stream index */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1585 case MATROSKA_ID_CUES: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1586 if (!matroska->index_parsed) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1587 res = matroska_parse_index(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1588 } else
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1589 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1590 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1591 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1592
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1593 /* metadata */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1594 case MATROSKA_ID_TAGS: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1595 if (!matroska->metadata_parsed) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1596 res = matroska_parse_metadata(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1597 } else
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1598 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1599 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1600 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1601
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1602 /* file index (if seekable, seek to Cues/Tags to parse it) */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1603 case MATROSKA_ID_SEEKHEAD: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1604 res = matroska_parse_seekhead(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1605 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1606 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1607
2973
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1608 case MATROSKA_ID_ATTACHMENTS: {
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1609 res = matroska_parse_attachments(s);
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1610 break;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1611 }
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
1612
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1613 case MATROSKA_ID_CLUSTER: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1614 /* Do not read the master - this will be done in the next
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1615 * call to matroska_read_packet. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1616 res = 1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1617 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1618 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1619
3315
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
1620 case MATROSKA_ID_CHAPTERS: {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
1621 res = matroska_parse_chapters(s);
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
1622 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
1623 }
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
1624
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1625 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1626 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1627 "Unknown matroska file header ID 0x%x\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1628 /* fall-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1629
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1630 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1631 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1632 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1633 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1634
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1635 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1636 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1637 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1638 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1639 }
3644
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1640 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
1641
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1642 /* Have we found a cluster? */
3647
98eb4eb368fa matroskadec: invert a test
aurel
parents: 3646
diff changeset
1643 if (ebml_peek_id(matroska, NULL) != MATROSKA_ID_CLUSTER)
98eb4eb368fa matroskadec: invert a test
aurel
parents: 3646
diff changeset
1644 return -1;
98eb4eb368fa matroskadec: invert a test
aurel
parents: 3646
diff changeset
1645
98eb4eb368fa matroskadec: invert a test
aurel
parents: 3646
diff changeset
1646 {
3648
07f046bf6849 matroskadec: move declaration to upper block
aurel
parents: 3647
diff changeset
1647 tracks = matroska->tracks.elem;
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1648 for (i=0; i < matroska->tracks.nb_elem; i++) {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1649 MatroskaTrack *track = &tracks[i];
1455
e0e7ac1b8601 Ensure codec_id = CODEC_ID_NONE for unknown codecs (don't reuse previous one).
aurel
parents: 1454
diff changeset
1650 enum CodecID codec_id = CODEC_ID_NONE;
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1651 uint8_t *extradata = NULL;
1024
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
1652 int extradata_size = 0;
1531
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
1653 int extradata_offset = 0;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1654
2244
93ffcd9d826f add support for Matroska subtitle tracks
aurel
parents: 2239
diff changeset
1655 /* Apply some sanity checks. */
93ffcd9d826f add support for Matroska subtitle tracks
aurel
parents: 2239
diff changeset
1656 if (track->codec_id == NULL)
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1657 continue;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1658
2905
616fb87724b5 Make ff_mkv_codec_tags lie entirely in .rodata section.
aurel
parents: 2881
diff changeset
1659 for(j=0; ff_mkv_codec_tags[j].id != CODEC_ID_NONE; j++){
2142
3aa1f0f698de split some common code from the mkv demuxer that will be useful to the muxer
aurel
parents: 2023
diff changeset
1660 if(!strncmp(ff_mkv_codec_tags[j].str, track->codec_id,
3aa1f0f698de split some common code from the mkv demuxer that will be useful to the muxer
aurel
parents: 2023
diff changeset
1661 strlen(ff_mkv_codec_tags[j].str))){
3aa1f0f698de split some common code from the mkv demuxer that will be useful to the muxer
aurel
parents: 2023
diff changeset
1662 codec_id= ff_mkv_codec_tags[j].id;
1024
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
1663 break;
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
1664 }
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
1665 }
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
1666
3635
318d5e2f9aed matroskadec: create new AVStream earlier
aurel
parents: 3634
diff changeset
1667 st = track->stream = av_new_stream(s, matroska->num_streams++);
318d5e2f9aed matroskadec: create new AVStream earlier
aurel
parents: 3634
diff changeset
1668 if (st == NULL)
318d5e2f9aed matroskadec: create new AVStream earlier
aurel
parents: 3634
diff changeset
1669 return AVERROR(ENOMEM);
318d5e2f9aed matroskadec: create new AVStream earlier
aurel
parents: 3634
diff changeset
1670
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1671 /* Set the FourCC from the CodecID. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1672 /* This is the MS compatibility mode which stores a
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1673 * BITMAPINFOHEADER in the CodecPrivate. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1674 if (!strcmp(track->codec_id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1675 MATROSKA_CODEC_ID_VIDEO_VFW_FOURCC) &&
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1676 (track->codec_priv.size >= 40) &&
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1677 (track->codec_priv.data != NULL)) {
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1678 /* Offset of biCompression. Stored in LE. */
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1679 track->video.fourcc = AV_RL32(track->codec_priv.data + 16);
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1680 codec_id = codec_get_id(codec_bmp_tags, track->video.fourcc);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1681
1024
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
1682 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1683
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1684 /* This is the MS compatibility mode which stores a
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1685 * WAVEFORMATEX in the CodecPrivate. */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 883
diff changeset
1686 else if (!strcmp(track->codec_id,
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1687 MATROSKA_CODEC_ID_AUDIO_ACM) &&
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1688 (track->codec_priv.size >= 18) &&
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1689 (track->codec_priv.data != NULL)) {
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1690 /* Offset of wFormatTag. Stored in LE. */
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1691 uint16_t tag = AV_RL16(track->codec_priv.data);
1897
abbc781d608a use codec_get_id() instead of deprecated codec_get_[bmp/wav]_id()
aurel
parents: 1832
diff changeset
1692 codec_id = codec_get_id(codec_wav_tags, tag);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1693
1024
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
1694 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1695
3601
c0955bfc27be matroska: add support for V_QUICKTIME track type
aurel
parents: 3495
diff changeset
1696 if (!strcmp(track->codec_id, "V_QUICKTIME") &&
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1697 (track->codec_priv.size >= 86) &&
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1698 (track->codec_priv.data != NULL)) {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1699 track->video.fourcc = AV_RL32(track->codec_priv.data);
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1700 codec_id=codec_get_id(codec_movvideo_tags, track->video.fourcc);
3601
c0955bfc27be matroska: add support for V_QUICKTIME track type
aurel
parents: 3495
diff changeset
1701 }
c0955bfc27be matroska: add support for V_QUICKTIME track type
aurel
parents: 3495
diff changeset
1702
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1703 else if (codec_id == CODEC_ID_AAC && !track->codec_priv.size) {
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1704 int profile = matroska_aac_profile(track->codec_id);
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1705 int sri = matroska_aac_sri(track->audio.samplerate);
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1706 extradata = av_malloc(5);
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1707 if (extradata == NULL)
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2264
diff changeset
1708 return AVERROR(ENOMEM);
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1709 extradata[0] = (profile << 3) | ((sri&0x0E) >> 1);
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1710 extradata[1] = ((sri&0x01) << 7) | (track->audio.channels<<3);
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1711 if (strstr(track->codec_id, "SBR")) {
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1712 sri = matroska_aac_sri(track->audio.out_samplerate);
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1713 extradata[2] = 0x56;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1714 extradata[3] = 0xE5;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1715 extradata[4] = 0x80 | (sri<<3);
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1716 extradata_size = 5;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1717 } else {
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1718 extradata_size = 2;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1719 }
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1720 }
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1721
1534
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
1722 else if (codec_id == CODEC_ID_TTA) {
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
1723 ByteIOContext b;
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
1724 extradata_size = 30;
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
1725 extradata = av_mallocz(extradata_size);
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
1726 if (extradata == NULL)
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2264
diff changeset
1727 return AVERROR(ENOMEM);
1534
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
1728 init_put_byte(&b, extradata, extradata_size, 1,
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
1729 NULL, NULL, NULL, NULL);
3009
9fefe2df6756 Remove incorrect cast found by -Wwrite-strings.
michael
parents: 2973
diff changeset
1730 put_buffer(&b, "TTA1", 4);
1534
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
1731 put_le16(&b, 1);
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1732 put_le16(&b, track->audio.channels);
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1733 put_le16(&b, track->audio.bitdepth);
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1734 put_le32(&b, track->audio.out_samplerate);
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1735 put_le32(&b, matroska->ctx->duration * track->audio.out_samplerate);
1534
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
1736 }
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
1737
1531
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
1738 else if (codec_id == CODEC_ID_RV10 || codec_id == CODEC_ID_RV20 ||
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
1739 codec_id == CODEC_ID_RV30 || codec_id == CODEC_ID_RV40) {
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
1740 extradata_offset = 26;
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1741 track->codec_priv.size -= extradata_offset;
1531
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
1742 }
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
1743
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1744 else if (codec_id == CODEC_ID_RA_144) {
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1745 track->audio.out_samplerate = 8000;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1746 track->audio.channels = 1;
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1747 }
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1748
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1749 else if (codec_id == CODEC_ID_RA_288 ||
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1750 codec_id == CODEC_ID_COOK ||
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1751 codec_id == CODEC_ID_ATRAC3) {
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1752 ByteIOContext b;
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1753
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1754 init_put_byte(&b, track->codec_priv.data,track->codec_priv.size,
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1755 0, NULL, NULL, NULL, NULL);
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1756 url_fskip(&b, 24);
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1757 track->audio.coded_framesize = get_be32(&b);
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1758 url_fskip(&b, 12);
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1759 track->audio.sub_packet_h = get_be16(&b);
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1760 track->audio.frame_size = get_be16(&b);
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1761 track->audio.sub_packet_size = get_be16(&b);
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1762 track->audio.buf = av_malloc(track->audio.frame_size * track->audio.sub_packet_h);
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1763 if (codec_id == CODEC_ID_RA_288) {
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1764 st->codec->block_align = track->audio.coded_framesize;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1765 track->codec_priv.size = 0;
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1766 } else {
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1767 st->codec->block_align = track->audio.sub_packet_size;
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1768 extradata_offset = 78;
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1769 track->codec_priv.size -= extradata_offset;
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1770 }
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1771 }
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1772
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1773 if (codec_id == CODEC_ID_NONE) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1774 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1775 "Unknown/unsupported CodecID %s.\n",
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1776 track->codec_id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1777 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1778
3408
da09478c97ce matroskadec: read TrackTimecodeScale and set timebase accordingly
aurel
parents: 3407
diff changeset
1779 av_set_pts_info(st, 64, matroska->time_scale*track->time_scale, 1000*1000*1000); /* 64 bit pts in ns */
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1780
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
1781 st->codec->codec_id = codec_id;
2009
c0c6474ce5a7 properly set streams start_time
aurel
parents: 2008
diff changeset
1782 st->start_time = 0;
2238
98ac80739c58 properly set AVStream.language according to Matroska track header
aurel
parents: 2202
diff changeset
1783 if (strcmp(track->language, "und"))
3628
5f2e1da55755 matroskadec: use more robust av_strlcpy() instead of strcpy()
aurel
parents: 3601
diff changeset
1784 av_strlcpy(st->language, track->language, 4);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1785
3630
23666678a608 matroskadec: simplify flag default
aurel
parents: 3629
diff changeset
1786 if (track->flag_default)
3120
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3009
diff changeset
1787 st->disposition |= AV_DISPOSITION_DEFAULT;
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3009
diff changeset
1788
1454
d7b946a1ec57 guess matroska files frame rate
aurel
parents: 1452
diff changeset
1789 if (track->default_duration)
d7b946a1ec57 guess matroska files frame rate
aurel
parents: 1452
diff changeset
1790 av_reduce(&st->codec->time_base.num, &st->codec->time_base.den,
2389
cde14f83579b Don't pre-scale default_duration to avoid precision loss in fps calculation.
aurel
parents: 2388
diff changeset
1791 track->default_duration, 1000000000, 30000);
1454
d7b946a1ec57 guess matroska files frame rate
aurel
parents: 1452
diff changeset
1792
692
b0144ebc71dd H.264 and Vorbis support in matroska patch by (M«©ns Rullg«©rd |mru inprovide com)
michael
parents: 652
diff changeset
1793 if(extradata){
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
1794 st->codec->extradata = extradata;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
1795 st->codec->extradata_size = extradata_size;
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1796 } else if(track->codec_priv.data && track->codec_priv.size > 0){
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1797 st->codec->extradata = av_malloc(track->codec_priv.size);
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
1798 if(st->codec->extradata == NULL)
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2264
diff changeset
1799 return AVERROR(ENOMEM);
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1800 st->codec->extradata_size = track->codec_priv.size;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1801 memcpy(st->codec->extradata,
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1802 track->codec_priv.data + extradata_offset,
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1803 track->codec_priv.size);
692
b0144ebc71dd H.264 and Vorbis support in matroska patch by (M«©ns Rullg«©rd |mru inprovide com)
michael
parents: 652
diff changeset
1804 }
b0144ebc71dd H.264 and Vorbis support in matroska patch by (M«©ns Rullg«©rd |mru inprovide com)
michael
parents: 652
diff changeset
1805
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1806 if (track->type == MATROSKA_TRACK_TYPE_VIDEO) {
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
1807 st->codec->codec_type = CODEC_TYPE_VIDEO;
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1808 st->codec->codec_tag = track->video.fourcc;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1809 st->codec->width = track->video.pixel_width;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1810 st->codec->height = track->video.pixel_height;
1021
5661350bf214 fix aspect ratio
michael
parents: 920
diff changeset
1811 av_reduce(&st->codec->sample_aspect_ratio.num,
5661350bf214 fix aspect ratio
michael
parents: 920
diff changeset
1812 &st->codec->sample_aspect_ratio.den,
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1813 st->codec->height * track->video.display_width,
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1814 st->codec-> width * track->video.display_height,
1021
5661350bf214 fix aspect ratio
michael
parents: 920
diff changeset
1815 255);
2023
a3e79d6e4e3c add an enum for need_parsing
aurel
parents: 2015
diff changeset
1816 st->need_parsing = AVSTREAM_PARSE_HEADERS;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1817 } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) {
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
1818 st->codec->codec_type = CODEC_TYPE_AUDIO;
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1819 st->codec->sample_rate = track->audio.out_samplerate;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1820 st->codec->channels = track->audio.channels;
1025
95e8458ae120 duration and subitle fix from the patch by Steve Lhomme
michael
parents: 1024
diff changeset
1821 } else if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE) {
95e8458ae120 duration and subitle fix from the patch by Steve Lhomme
michael
parents: 1024
diff changeset
1822 st->codec->codec_type = CODEC_TYPE_SUBTITLE;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
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 /* What do we do with private data? E.g. for Vorbis. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1826 }
1465
1dccf2603e1d Better way to detect cluster (fix files encoded with Haali's muxer).
aurel
parents: 1459
diff changeset
1827 res = 0;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1828 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1829
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1830 index_list = &matroska->index;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1831 index = index_list->elem;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1832 for (i=0; i<index_list->nb_elem; i++) {
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1833 EbmlList *pos_list = &index[i].pos;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1834 MatroskaIndexPos *pos = pos_list->elem;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1835 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
1836 MatroskaTrack *track = matroska_find_track_by_num(matroska,
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1837 pos[j].track);
3636
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
1838 if (track && track->stream)
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
1839 av_add_index_entry(track->stream,
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1840 pos[j].pos + matroska->segment_start,
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1841 index[i].time*matroska->time_scale/AV_TIME_BASE,
2202
32d675fb5e2e cosmetics: indentation after last commit
aurel
parents: 2201
diff changeset
1842 0, 0, AVINDEX_KEYFRAME);
2012
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1843 }
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
1465
1dccf2603e1d Better way to detect cluster (fix files encoded with Haali's muxer).
aurel
parents: 1459
diff changeset
1846 return res;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1847 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1848
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1849 static int
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
1850 matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int size,
1914
511723932287 calculate pts for laced packets
aurel
parents: 1913
diff changeset
1851 int64_t pos, uint64_t cluster_time, uint64_t duration,
3631
951c7aaaf2a2 matroskadec: remove unused is_bframe flag
aurel
parents: 3630
diff changeset
1852 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
1853 {
3636
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
1854 MatroskaTrack *track;
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
1855 int res = 0;
2013
fc0b19650faa add an intermediate variable (prepare for next patch)
aurel
parents: 2012
diff changeset
1856 AVStream *st;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1857 AVPacket *pkt;
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
1858 uint8_t *origdata = data;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1859 int16_t block_time;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1860 uint32_t *lace_size = NULL;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1861 int n, flags, laces = 0;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1862 uint64_t num;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1863
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1864 /* first byte(s): tracknum */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1865 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
1866 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
1867 av_free(origdata);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1868 return res;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1869 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1870 data += n;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1871 size -= n;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1872
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1873 /* fetch track from num */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1874 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
1875 if (size <= 3 || !track || !track->stream) {
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1876 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
1877 "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
1878 av_free(origdata);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1879 return res;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1880 }
3636
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
1881 st = track->stream;
2013
fc0b19650faa add an intermediate variable (prepare for next patch)
aurel
parents: 2012
diff changeset
1882 if (st->discard >= AVDISCARD_ALL) {
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1883 av_free(origdata);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1884 return res;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1885 }
1914
511723932287 calculate pts for laced packets
aurel
parents: 1913
diff changeset
1886 if (duration == AV_NOPTS_VALUE)
3636
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
1887 duration = track->default_duration / matroska->time_scale;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1888
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1889 /* block_time (relative to cluster time) */
2185
7dd08e645d92 use intreadwrite functions in matroskadec
aurel
parents: 2175
diff changeset
1890 block_time = AV_RB16(data);
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1891 data += 2;
2188
4c2924cebe00 simplify
aurel
parents: 2185
diff changeset
1892 flags = *data++;
4c2924cebe00 simplify
aurel
parents: 2185
diff changeset
1893 size -= 3;
1831
bdca904db5e5 add support for simple blocks (ie. matroska v2)
aurel
parents: 1830
diff changeset
1894 if (is_keyframe == -1)
2415
3aa642c08cde SimpleBlock keyframe flag is the most significant bit
conrad
parents: 2390
diff changeset
1895 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
1896
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
1897 if (matroska->skip_to_keyframe) {
2870
d2c5c911280d fix memory leak (patch by Gabriel Fort«± gforte _at_ wyplay _dot_ com)
aurel
parents: 2805
diff changeset
1898 if (!is_keyframe || st != matroska->skip_to_stream) {
d2c5c911280d fix memory leak (patch by Gabriel Fort«± gforte _at_ wyplay _dot_ com)
aurel
parents: 2805
diff changeset
1899 av_free(origdata);
2014
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
1900 return res;
2870
d2c5c911280d fix memory leak (patch by Gabriel Fort«± gforte _at_ wyplay _dot_ com)
aurel
parents: 2805
diff changeset
1901 }
2014
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
1902 matroska->skip_to_keyframe = 0;
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
1903 }
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
1904
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1905 switch ((flags & 0x06) >> 1) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1906 case 0x0: /* no lacing */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1907 laces = 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1908 lace_size = av_mallocz(sizeof(int));
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1909 lace_size[0] = size;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1910 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1911
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1912 case 0x1: /* xiph lacing */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1913 case 0x2: /* fixed-size lacing */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1914 case 0x3: /* EBML lacing */
3391
39750abd9bab Dead code removal, fixes CID59 RUN2.
michael
parents: 3334
diff changeset
1915 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
1916 laces = (*data) + 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1917 data += 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1918 size -= 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1919 lace_size = av_mallocz(laces * sizeof(int));
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1920
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1921 switch ((flags & 0x06) >> 1) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1922 case 0x1: /* xiph lacing */ {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1923 uint8_t temp;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1924 uint32_t total = 0;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1925 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
1926 while (1) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1927 if (size == 0) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1928 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
1929 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1930 }
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1931 temp = *data;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1932 lace_size[n] += temp;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1933 data += 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1934 size -= 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1935 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
1936 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1937 }
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1938 total += lace_size[n];
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1939 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1940 lace_size[n] = size - total;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1941 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1942 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1943
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1944 case 0x2: /* fixed-size lacing */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1945 for (n = 0; n < laces; n++)
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1946 lace_size[n] = size / laces;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1947 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1948
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1949 case 0x3: /* EBML lacing */ {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1950 uint32_t total;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1951 n = matroska_ebmlnum_uint(data, size, &num);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1952 if (n < 0) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1953 av_log(matroska->ctx, AV_LOG_INFO,
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1954 "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
1955 break;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1956 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1957 data += n;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1958 size -= n;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1959 total = lace_size[0] = num;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1960 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
1961 int64_t snum;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1962 int r;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1963 r = matroska_ebmlnum_sint (data, size, &snum);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1964 if (r < 0) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1965 av_log(matroska->ctx, AV_LOG_INFO,
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1966 "EBML block data error\n");
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1967 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1968 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1969 data += r;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1970 size -= r;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1971 lace_size[n] = lace_size[n - 1] + snum;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1972 total += lace_size[n];
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1973 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1974 lace_size[n] = size - total;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1975 break;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1976 }
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1977 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1978 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1979 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1980
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1981 if (res == 0) {
1911
2ce053f3d996 move timecode calculation out of laces loop
aurel
parents: 1905
diff changeset
1982 uint64_t timecode = AV_NOPTS_VALUE;
2ce053f3d996 move timecode calculation out of laces loop
aurel
parents: 1905
diff changeset
1983
2364
7c31128b23f8 ensure that negative block_time are properly checked
aurel
parents: 2276
diff changeset
1984 if (cluster_time != (uint64_t)-1
7c31128b23f8 ensure that negative block_time are properly checked
aurel
parents: 2276
diff changeset
1985 && (block_time >= 0 || cluster_time >= -block_time))
1911
2ce053f3d996 move timecode calculation out of laces loop
aurel
parents: 1905
diff changeset
1986 timecode = cluster_time + block_time;
2ce053f3d996 move timecode calculation out of laces loop
aurel
parents: 1905
diff changeset
1987
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1988 for (n = 0; n < laces; n++) {
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1989 if (st->codec->codec_id == CODEC_ID_RA_288 ||
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1990 st->codec->codec_id == CODEC_ID_COOK ||
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1991 st->codec->codec_id == CODEC_ID_ATRAC3) {
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1992 int a = st->codec->block_align;
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1993 int sps = track->audio.sub_packet_size;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1994 int cfs = track->audio.coded_framesize;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1995 int h = track->audio.sub_packet_h;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1996 int y = track->audio.sub_packet_cnt;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1997 int w = track->audio.frame_size;
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1998 int x;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1999
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
2000 if (!track->audio.pkt_cnt) {
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2001 if (st->codec->codec_id == CODEC_ID_RA_288)
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2002 for (x=0; x<h/2; x++)
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
2003 memcpy(track->audio.buf+x*2*w+y*cfs,
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2004 data+x*cfs, cfs);
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2005 else
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2006 for (x=0; x<w/sps; x++)
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
2007 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
2008
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
2009 if (++track->audio.sub_packet_cnt >= h) {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
2010 track->audio.sub_packet_cnt = 0;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
2011 track->audio.pkt_cnt = h*w / a;
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2012 }
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2013 }
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
2014 while (track->audio.pkt_cnt) {
2145
3dd44fd1cbf4 cosmetics: indentation
aurel
parents: 2144
diff changeset
2015 pkt = av_mallocz(sizeof(AVPacket));
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2016 av_new_packet(pkt, a);
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
2017 memcpy(pkt->data, track->audio.buf
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
2018 + a * (h*w / a - track->audio.pkt_cnt--), a);
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2019 pkt->pos = pos;
3634
f206f746ff61 matroskadec: store an AVStream pointer instead of a stream index
aurel
parents: 3633
diff changeset
2020 pkt->stream_index = st->index;
2145
3dd44fd1cbf4 cosmetics: indentation
aurel
parents: 2144
diff changeset
2021 matroska_queue_packet(matroska, pkt);
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2022 }
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2023 } else {
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
2024 MatroskaTrackEncoding *encodings = track->encodings.elem;
3494
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
2025 int offset = 0, pkt_size = lace_size[n];
3281
a1d98736c15e matroskadec: add support for lzo compressed tracks
aurel
parents: 3280
diff changeset
2026 uint8_t *pkt_data = data;
a1d98736c15e matroskadec: add support for lzo compressed tracks
aurel
parents: 3280
diff changeset
2027
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
2028 if (encodings && encodings->scope & 1) {
3494
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
2029 offset = matroska_decode_buffer(&pkt_data, &pkt_size,
3636
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
2030 track);
3494
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
2031 if (offset < 0)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
2032 continue;
3279
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
2033 }
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
2034
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2035 pkt = av_mallocz(sizeof(AVPacket));
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2036 /* XXX: prevent data copy... */
3281
a1d98736c15e matroskadec: add support for lzo compressed tracks
aurel
parents: 3280
diff changeset
2037 if (av_new_packet(pkt, pkt_size+offset) < 0) {
3415
89f651b6f12a matroskadec: avoid potential mem leak
aurel
parents: 3414
diff changeset
2038 av_free(pkt);
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2039 res = AVERROR(ENOMEM);
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2040 n = laces-1;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2041 break;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2042 }
3279
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
2043 if (offset)
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
2044 memcpy (pkt->data, encodings->compression.settings.data, offset);
3281
a1d98736c15e matroskadec: add support for lzo compressed tracks
aurel
parents: 3280
diff changeset
2045 memcpy (pkt->data+offset, pkt_data, pkt_size);
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2046
3493
b77ced770a93 matroskadec: fix a memory leak
aurel
parents: 3477
diff changeset
2047 if (pkt_data != data)
b77ced770a93 matroskadec: fix a memory leak
aurel
parents: 3477
diff changeset
2048 av_free(pkt_data);
b77ced770a93 matroskadec: fix a memory leak
aurel
parents: 3477
diff changeset
2049
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2050 if (n == 0)
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2051 pkt->flags = is_keyframe;
3634
f206f746ff61 matroskadec: store an AVStream pointer instead of a stream index
aurel
parents: 3633
diff changeset
2052 pkt->stream_index = st->index;
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2053
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2054 pkt->pts = timecode;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2055 pkt->pos = pos;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2056 pkt->duration = duration;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2057
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2058 matroska_queue_packet(matroska, pkt);
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2059 }
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2060
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2061 if (timecode != AV_NOPTS_VALUE)
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2062 timecode = duration ? timecode + duration : AV_NOPTS_VALUE;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2063 data += lace_size[n];
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2064 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2065 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2066
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2067 av_free(lace_size);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2068 av_free(origdata);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2069 return res;
1829
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2070 }
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2071
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2072 static int
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2073 matroska_parse_blockgroup (MatroskaDemuxContext *matroska,
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2074 uint64_t cluster_time)
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2075 {
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2076 int res = 0;
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2077 uint32_t id;
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2078 int is_keyframe = PKT_FLAG_KEY, last_num_packets = matroska->num_packets;
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2079 uint64_t duration = AV_NOPTS_VALUE;
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2080 uint8_t *data;
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2081 int size = 0;
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2082 int64_t pos = 0;
1829
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2083
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2084 av_log(matroska->ctx, AV_LOG_DEBUG, "parsing blockgroup...\n");
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2085
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2086 while (res == 0) {
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2087 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
2088 res = AVERROR(EIO);
1829
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2089 break;
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2090 } else if (matroska->level_up) {
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2091 matroska->level_up--;
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2092 break;
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2093 }
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2094
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2095 switch (id) {
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2096 /* one block inside the group. Note, block parsing is one
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2097 * of the harder things, so this code is a bit complicated.
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2098 * See http://www.matroska.org/ for documentation. */
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2099 case MATROSKA_ID_BLOCK: {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
2100 pos = url_ftell(matroska->ctx->pb);
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2101 res = ebml_read_binary(matroska, &id, &data, &size);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2102 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2103 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2104
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2105 case MATROSKA_ID_BLOCKDURATION: {
1456
34d0d965a0d0 Add support for block duration.
aurel
parents: 1455
diff changeset
2106 if ((res = ebml_read_uint(matroska, &id, &duration)) < 0)
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2107 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2108 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2109 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2110
1902
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
2111 case MATROSKA_ID_BLOCKREFERENCE: {
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
2112 int64_t num;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2113 /* We've found a reference, so not even the first frame in
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2114 * the lace is a key frame. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2115 is_keyframe = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2116 if (last_num_packets != matroska->num_packets)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2117 matroska->packets[last_num_packets]->flags = 0;
1902
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
2118 if ((res = ebml_read_sint(matroska, &id, &num)) < 0)
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
2119 break;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2120 break;
1902
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
2121 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2122
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2123 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2124 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2125 "Unknown entry 0x%x in blockgroup data\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2126 /* fall-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2127
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2128 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2129 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2130 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2131 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2132
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2133 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2134 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2135 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2136 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2137 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2138
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2139 if (res)
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2140 return res;
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2141
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2142 if (size > 0)
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2143 res = matroska_parse_block(matroska, data, size, pos, cluster_time,
3631
951c7aaaf2a2 matroskadec: remove unused is_bframe flag
aurel
parents: 3630
diff changeset
2144 duration, is_keyframe);
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2145
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2146 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2147 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2148
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2149 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2150 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
2151 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2152 int res = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2153 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
2154 uint64_t cluster_time = 0;
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2155 uint8_t *data;
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2156 int64_t pos;
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2157 int size;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2158
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2159 av_log(matroska->ctx, AV_LOG_DEBUG,
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
2160 "parsing cluster at %"PRId64"\n", url_ftell(matroska->ctx->pb));
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2161
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2162 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2163 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
2164 res = 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
2165 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2166 } else if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2167 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2168 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2169 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2170
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2171 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2172 /* cluster timecode */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2173 case MATROSKA_ID_CLUSTERTIMECODE: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2174 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
2175 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2176 break;
1035
4a33428641e1 fixing timebase
michael
parents: 1034
diff changeset
2177 cluster_time = num;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2178 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2179 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2180
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2181 /* a group of blocks inside a cluster */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2182 case MATROSKA_ID_BLOCKGROUP:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2183 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2184 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2185 res = matroska_parse_blockgroup(matroska, cluster_time);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2186 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2187
1831
bdca904db5e5 add support for simple blocks (ie. matroska v2)
aurel
parents: 1830
diff changeset
2188 case MATROSKA_ID_SIMPLEBLOCK:
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
2189 pos = url_ftell(matroska->ctx->pb);
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2190 res = ebml_read_binary(matroska, &id, &data, &size);
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2191 if (res == 0)
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2192 res = matroska_parse_block(matroska, data, size, pos,
1914
511723932287 calculate pts for laced packets
aurel
parents: 1913
diff changeset
2193 cluster_time, AV_NOPTS_VALUE,
3631
951c7aaaf2a2 matroskadec: remove unused is_bframe flag
aurel
parents: 3630
diff changeset
2194 -1);
1831
bdca904db5e5 add support for simple blocks (ie. matroska v2)
aurel
parents: 1830
diff changeset
2195 break;
bdca904db5e5 add support for simple blocks (ie. matroska v2)
aurel
parents: 1830
diff changeset
2196
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2197 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2198 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2199 "Unknown entry 0x%x in cluster data\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2200 /* fall-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2201
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2202 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2203 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2204 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2205 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2206
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2207 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2208 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2209 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2210 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2211 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2212
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2213 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2214 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2215
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2216 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2217 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
2218 AVPacket *pkt)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2219 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2220 MatroskaDemuxContext *matroska = s->priv_data;
2143
a3d59411106f fix an infinite loop in case one cluster is not enough to demux a packet
aurel
parents: 2142
diff changeset
2221 int res;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2222 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
2223
1899
1324ae790ee0 parse clusters until some packets are queued
aurel
parents: 1898
diff changeset
2224 /* Read stream until we have a packet queued. */
1324ae790ee0 parse clusters until some packets are queued
aurel
parents: 1898
diff changeset
2225 while (matroska_deliver_packet(matroska, pkt)) {
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2226
1900
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2227 /* Have we already reached the end? */
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2228 if (matroska->done)
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
2229 return AVERROR(EIO);
1900
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2230
2143
a3d59411106f fix an infinite loop in case one cluster is not enough to demux a packet
aurel
parents: 2142
diff changeset
2231 res = 0;
1900
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2232 while (res == 0) {
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2233 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
2234 return AVERROR(EIO);
1900
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2235 } else if (matroska->level_up) {
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2236 matroska->level_up--;
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2237 break;
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2238 }
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2239
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2240 switch (id) {
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2241 case MATROSKA_ID_CLUSTER:
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2242 if ((res = ebml_read_master(matroska, &id)) < 0)
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2243 break;
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2244 if ((res = matroska_parse_cluster(matroska)) == 0)
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2245 res = 1; /* Parsed one cluster, let's get out. */
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2246 break;
1900
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2247
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2248 default:
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2249 case EBML_ID_VOID:
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2250 res = ebml_read_skip(matroska);
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2251 break;
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2252 }
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2253
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2254 if (matroska->level_up) {
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2255 matroska->level_up--;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2256 break;
1900
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2257 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2258 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2259
1900
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2260 if (res == -1)
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
2261 matroska->done = 1;
1899
1324ae790ee0 parse clusters until some packets are queued
aurel
parents: 1898
diff changeset
2262 }
1324ae790ee0 parse clusters until some packets are queued
aurel
parents: 1898
diff changeset
2263
1324ae790ee0 parse clusters until some packets are queued
aurel
parents: 1898
diff changeset
2264 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
2265 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2266
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2267 static int
2012
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2268 matroska_read_seek (AVFormatContext *s, int stream_index, int64_t timestamp,
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2269 int flags)
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2270 {
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2271 MatroskaDemuxContext *matroska = s->priv_data;
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2272 AVStream *st = s->streams[stream_index];
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2273 int index;
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2274
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2275 /* find index entry */
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2276 index = av_index_search_timestamp(st, timestamp, flags);
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2277 if (index < 0)
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2278 return 0;
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2279
2872
a9bb4614c0f8 clear internal queue when seeking
aurel
parents: 2871
diff changeset
2280 matroska_clear_queue(matroska);
a9bb4614c0f8 clear internal queue when seeking
aurel
parents: 2871
diff changeset
2281
2012
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2282 /* do the seek */
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
2283 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
2284 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
2285 matroska->skip_to_stream = st;
2012
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2286 matroska->peek_id = 0;
3462
3f87bde8a97c matroskadec: set cur_dts after seek
aurel
parents: 3427
diff changeset
2287 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
2288 return 0;
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2289 }
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2290
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2291 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
2292 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
2293 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2294 MatroskaDemuxContext *matroska = s->priv_data;
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
2295 MatroskaTrack *tracks = matroska->tracks.elem;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2296 int n = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2297
2871
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
2298 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
2299
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
2300 for (n=0; n < matroska->tracks.nb_elem; n++)
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
2301 if (tracks[n].type == MATROSKA_TRACK_TYPE_AUDIO)
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
2302 av_free(tracks[n].audio.buf);
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
2303 ebml_free(matroska_tracks, matroska);
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
2304 ebml_free(matroska_index, matroska);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2305
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2306 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2307 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2308
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
2309 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
2310 "matroska",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3422
diff changeset
2311 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
2312 sizeof(MatroskaDemuxContext),
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2313 matroska_probe,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2314 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
2315 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
2316 matroska_read_close,
2012
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2317 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
2318 };