annotate matroskadec.c @ 4141:657498d1307e libavformat

Add a few error checks to rm_assemble_video_frame()
author michael
date Tue, 30 Dec 2008 20:51:18 +0000
parents c8318261427d
children 7d2f3f1b68d8
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 /*
3685
c077c928bfe6 matroskadec: update copyright year and related comments
aurel
parents: 3684
diff changeset
2 * Matroska file demuxer
3692
e8f67b6063c3 misc spelling/grammar fixes
diego
parents: 3691
diff changeset
3 * Copyright (c) 2003-2008 The FFmpeg Project
380
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>
3685
c077c928bfe6 matroskadec: update copyright year and related comments
aurel
parents: 3684
diff changeset
27 * totally reworked by Aurelien Jacobs <aurel@gnuage.org>
3692
e8f67b6063c3 misc spelling/grammar fixes
diego
parents: 3691
diff changeset
28 * Specs available on the Matroska project page: http://www.matroska.org/.
380
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
3894
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
31 #include <stdio.h>
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
32 #include "avformat.h"
1897
abbc781d608a use codec_get_id() instead of deprecated codec_get_[bmp/wav]_id()
aurel
parents: 1832
diff changeset
33 /* 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
34 #include "riff.h"
3601
c0955bfc27be matroska: add support for V_QUICKTIME track type
aurel
parents: 3495
diff changeset
35 #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
36 #include "matroska.h"
3201
1a16b069daca use common aac sample rate tables
aurel
parents: 3199
diff changeset
37 #include "libavcodec/mpeg4audio.h"
3286
6f61c3b36632 Use full path for #includes from another directory.
diego
parents: 3283
diff changeset
38 #include "libavutil/intfloat_readwrite.h"
3628
5f2e1da55755 matroskadec: use more robust av_strlcpy() instead of strcpy()
aurel
parents: 3601
diff changeset
39 #include "libavutil/avstring.h"
3281
a1d98736c15e matroskadec: add support for lzo compressed tracks
aurel
parents: 3280
diff changeset
40 #include "libavutil/lzo.h"
3293
d3818f6d7530 matroskadec: add support for zlib compressed tracks
aurel
parents: 3290
diff changeset
41 #ifdef CONFIG_ZLIB
d3818f6d7530 matroskadec: add support for zlib compressed tracks
aurel
parents: 3290
diff changeset
42 #include <zlib.h>
d3818f6d7530 matroskadec: add support for zlib compressed tracks
aurel
parents: 3290
diff changeset
43 #endif
3298
edabe3db2b6e matroskadec: add support for bzlib compressed tracks
aurel
parents: 3294
diff changeset
44 #ifdef CONFIG_BZLIB
edabe3db2b6e matroskadec: add support for bzlib compressed tracks
aurel
parents: 3294
diff changeset
45 #include <bzlib.h>
edabe3db2b6e matroskadec: add support for bzlib compressed tracks
aurel
parents: 3294
diff changeset
46 #endif
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
47
3632
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
48 typedef enum {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
49 EBML_NONE,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
50 EBML_UINT,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
51 EBML_FLOAT,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
52 EBML_STR,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
53 EBML_UTF8,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
54 EBML_BIN,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
55 EBML_NEST,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
56 EBML_PASS,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
57 EBML_STOP,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
58 } EbmlType;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
59
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
60 typedef const struct EbmlSyntax {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
61 uint32_t id;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
62 EbmlType type;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
63 int list_elem_size;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
64 int data_offset;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
65 union {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
66 uint64_t u;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
67 double f;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
68 const char *s;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
69 const struct EbmlSyntax *n;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
70 } def;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
71 } EbmlSyntax;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
72
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
73 typedef struct {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
74 int nb_elem;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
75 void *elem;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
76 } EbmlList;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
77
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
78 typedef struct {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
79 int size;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
80 uint8_t *data;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
81 int64_t pos;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
82 } EbmlBin;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
83
3633
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
84 typedef struct {
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
85 uint64_t version;
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
86 uint64_t max_size;
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
87 uint64_t id_length;
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
88 char *doctype;
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
89 uint64_t doctype_version;
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
90 } Ebml;
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
91
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
92 typedef struct {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
93 uint64_t algo;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
94 EbmlBin settings;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
95 } MatroskaTrackCompression;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
96
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
97 typedef struct {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
98 uint64_t scope;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
99 uint64_t type;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
100 MatroskaTrackCompression compression;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
101 } MatroskaTrackEncoding;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
102
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
103 typedef struct {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
104 double frame_rate;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
105 uint64_t display_width;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
106 uint64_t display_height;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
107 uint64_t pixel_width;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
108 uint64_t pixel_height;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
109 uint64_t fourcc;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
110 } MatroskaTrackVideo;
2147
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
111
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
112 typedef struct {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
113 double samplerate;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
114 double out_samplerate;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
115 uint64_t bitdepth;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
116 uint64_t channels;
2147
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
117
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
118 /* real audio header (extracted from extradata) */
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
119 int coded_framesize;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
120 int sub_packet_h;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
121 int frame_size;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
122 int sub_packet_size;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
123 int sub_packet_cnt;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
124 int pkt_cnt;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
125 uint8_t *buf;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
126 } MatroskaTrackAudio;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
127
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
128 typedef struct {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
129 uint64_t num;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
130 uint64_t type;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
131 char *codec_id;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
132 EbmlBin codec_priv;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
133 char *language;
3408
da09478c97ce matroskadec: read TrackTimecodeScale and set timebase accordingly
aurel
parents: 3407
diff changeset
134 double time_scale;
1912
98a74cfd12d4 scale duration and default_duration
aurel
parents: 1911
diff changeset
135 uint64_t default_duration;
3630
23666678a608 matroskadec: simplify flag default
aurel
parents: 3629
diff changeset
136 uint64_t flag_default;
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
137 MatroskaTrackVideo video;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
138 MatroskaTrackAudio audio;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
139 EbmlList encodings;
3634
f206f746ff61 matroskadec: store an AVStream pointer instead of a stream index
aurel
parents: 3633
diff changeset
140
f206f746ff61 matroskadec: store an AVStream pointer instead of a stream index
aurel
parents: 3633
diff changeset
141 AVStream *stream;
3915
7643d7c3fcf6 matroskadec: ensure that overlapping subtitles are not added to the index
aurel
parents: 3914
diff changeset
142 int64_t end_timecode;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
143 } MatroskaTrack;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
144
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
145 typedef struct {
3640
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
146 char *filename;
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
147 char *mime;
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
148 EbmlBin bin;
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
149 } MatroskaAttachement;
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
150
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
151 typedef struct {
3639
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
152 uint64_t start;
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
153 uint64_t end;
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
154 uint64_t uid;
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
155 char *title;
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
156 } MatroskaChapter;
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
157
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
158 typedef struct {
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
159 uint64_t track;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
160 uint64_t pos;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
161 } MatroskaIndexPos;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
162
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
163 typedef struct {
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
164 uint64_t time;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
165 EbmlList pos;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
166 } MatroskaIndex;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
167
3644
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
168 typedef struct {
3702
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
169 char *name;
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
170 char *string;
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
171 EbmlList sub;
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
172 } MatroskaTag;
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
173
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
174 typedef struct {
3644
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
175 uint64_t id;
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
176 uint64_t pos;
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
177 } MatroskaSeekhead;
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
178
3658
04ffed56f400 matroskadec: remove unused struct name
aurel
parents: 3657
diff changeset
179 typedef struct {
2147
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
180 uint64_t start;
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
181 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
182 } MatroskaLevel;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
183
3658
04ffed56f400 matroskadec: remove unused struct name
aurel
parents: 3657
diff changeset
184 typedef struct {
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
185 AVFormatContext *ctx;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
186
3692
e8f67b6063c3 misc spelling/grammar fixes
diego
parents: 3691
diff changeset
187 /* EBML stuff */
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
188 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
189 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
190 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
191
3641
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
192 uint64_t time_scale;
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
193 double duration;
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
194 char *title;
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
195 EbmlList tracks;
3640
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
196 EbmlList attachments;
3639
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
197 EbmlList chapters;
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
198 EbmlList index;
3702
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
199 EbmlList tags;
3644
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
200 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
201
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
202 /* byte position of the segment inside the stream */
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3972
diff changeset
203 int64_t segment_start;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
204
3692
e8f67b6063c3 misc spelling/grammar fixes
diego
parents: 3691
diff changeset
205 /* the packet queue */
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
206 AVPacket **packets;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
207 int num_packets;
3954
0ebebd2ba034 matroskadec: merge ASS events which share the same pts in the same AVPavket
aurel
parents: 3953
diff changeset
208 AVPacket *prev_pkt;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
209
2147
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
210 int done;
3651
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
211 int has_cluster_id;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
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;
3914
f7a20cf5438f matroskadec: after seeking, skip up to the desired timestamp instead of
aurel
parents: 3913
diff changeset
215 uint64_t skip_to_timecode;
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
3653
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
218 typedef struct {
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
219 uint64_t duration;
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
220 int64_t reference;
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
221 EbmlBin bin;
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
222 } MatroskaBlock;
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
223
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
224 typedef struct {
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
225 uint64_t timecode;
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
226 EbmlList blocks;
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
227 } MatroskaCluster;
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
228
3633
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
229 static EbmlSyntax ebml_header[] = {
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
230 { 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
231 { 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
232 { 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
233 { 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
234 { 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
235 { EBML_ID_EBMLVERSION, EBML_NONE },
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
236 { EBML_ID_DOCTYPEVERSION, EBML_NONE },
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
237 { 0 }
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
238 };
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
239
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
240 static EbmlSyntax ebml_syntax[] = {
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
241 { EBML_ID_HEADER, EBML_NEST, 0, 0, {.n=ebml_header} },
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
242 { 0 }
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
243 };
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
244
3641
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
245 static EbmlSyntax matroska_info[] = {
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
246 { MATROSKA_ID_TIMECODESCALE, EBML_UINT, 0, offsetof(MatroskaDemuxContext,time_scale), {.u=1000000} },
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
247 { MATROSKA_ID_DURATION, EBML_FLOAT, 0, offsetof(MatroskaDemuxContext,duration) },
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
248 { MATROSKA_ID_TITLE, EBML_UTF8, 0, offsetof(MatroskaDemuxContext,title) },
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
249 { MATROSKA_ID_WRITINGAPP, EBML_NONE },
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
250 { MATROSKA_ID_MUXINGAPP, EBML_NONE },
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
251 { MATROSKA_ID_DATEUTC, EBML_NONE },
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
252 { MATROSKA_ID_SEGMENTUID, EBML_NONE },
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
253 { 0 }
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
254 };
2788411945cf matroskadec: use generic parser to parse info
aurel
parents: 3640
diff changeset
255
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
256 static EbmlSyntax matroska_track_video[] = {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
257 { MATROSKA_ID_VIDEOFRAMERATE, EBML_FLOAT,0, offsetof(MatroskaTrackVideo,frame_rate) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
258 { MATROSKA_ID_VIDEODISPLAYWIDTH, EBML_UINT, 0, offsetof(MatroskaTrackVideo,display_width) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
259 { MATROSKA_ID_VIDEODISPLAYHEIGHT, EBML_UINT, 0, offsetof(MatroskaTrackVideo,display_height) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
260 { MATROSKA_ID_VIDEOPIXELWIDTH, EBML_UINT, 0, offsetof(MatroskaTrackVideo,pixel_width) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
261 { MATROSKA_ID_VIDEOPIXELHEIGHT, EBML_UINT, 0, offsetof(MatroskaTrackVideo,pixel_height) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
262 { MATROSKA_ID_VIDEOCOLORSPACE, EBML_UINT, 0, offsetof(MatroskaTrackVideo,fourcc) },
3717
f65dc584662d matroskadec: list some more ebml IDs found in the wild and that we ignore
aurel
parents: 3713
diff changeset
263 { MATROSKA_ID_VIDEOPIXELCROPB, EBML_NONE },
f65dc584662d matroskadec: list some more ebml IDs found in the wild and that we ignore
aurel
parents: 3713
diff changeset
264 { MATROSKA_ID_VIDEOPIXELCROPT, EBML_NONE },
f65dc584662d matroskadec: list some more ebml IDs found in the wild and that we ignore
aurel
parents: 3713
diff changeset
265 { MATROSKA_ID_VIDEOPIXELCROPL, EBML_NONE },
f65dc584662d matroskadec: list some more ebml IDs found in the wild and that we ignore
aurel
parents: 3713
diff changeset
266 { MATROSKA_ID_VIDEOPIXELCROPR, EBML_NONE },
f65dc584662d matroskadec: list some more ebml IDs found in the wild and that we ignore
aurel
parents: 3713
diff changeset
267 { MATROSKA_ID_VIDEODISPLAYUNIT, EBML_NONE },
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
268 { MATROSKA_ID_VIDEOFLAGINTERLACED,EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
269 { MATROSKA_ID_VIDEOSTEREOMODE, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
270 { MATROSKA_ID_VIDEOASPECTRATIO, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
271 { 0 }
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
272 };
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
273
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
274 static EbmlSyntax matroska_track_audio[] = {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
275 { 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
276 { MATROSKA_ID_AUDIOOUTSAMPLINGFREQ,EBML_FLOAT,0,offsetof(MatroskaTrackAudio,out_samplerate) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
277 { MATROSKA_ID_AUDIOBITDEPTH, EBML_UINT, 0, offsetof(MatroskaTrackAudio,bitdepth) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
278 { MATROSKA_ID_AUDIOCHANNELS, EBML_UINT, 0, offsetof(MatroskaTrackAudio,channels), {.u=1} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
279 { 0 }
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
280 };
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
281
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
282 static EbmlSyntax matroska_track_encoding_compression[] = {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
283 { MATROSKA_ID_ENCODINGCOMPALGO, EBML_UINT, 0, offsetof(MatroskaTrackCompression,algo), {.u=0} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
284 { MATROSKA_ID_ENCODINGCOMPSETTINGS,EBML_BIN, 0, offsetof(MatroskaTrackCompression,settings) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
285 { 0 }
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
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
288 static EbmlSyntax matroska_track_encoding[] = {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
289 { MATROSKA_ID_ENCODINGSCOPE, EBML_UINT, 0, offsetof(MatroskaTrackEncoding,scope), {.u=1} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
290 { MATROSKA_ID_ENCODINGTYPE, EBML_UINT, 0, offsetof(MatroskaTrackEncoding,type), {.u=0} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
291 { MATROSKA_ID_ENCODINGCOMPRESSION,EBML_NEST, 0, offsetof(MatroskaTrackEncoding,compression), {.n=matroska_track_encoding_compression} },
3717
f65dc584662d matroskadec: list some more ebml IDs found in the wild and that we ignore
aurel
parents: 3713
diff changeset
292 { MATROSKA_ID_ENCODINGORDER, EBML_NONE },
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
293 { 0 }
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
294 };
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
295
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
296 static EbmlSyntax matroska_track_encodings[] = {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
297 { 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
298 { 0 }
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
299 };
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
300
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
301 static EbmlSyntax matroska_track[] = {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
302 { MATROSKA_ID_TRACKNUMBER, EBML_UINT, 0, offsetof(MatroskaTrack,num) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
303 { MATROSKA_ID_TRACKTYPE, EBML_UINT, 0, offsetof(MatroskaTrack,type) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
304 { MATROSKA_ID_CODECID, EBML_STR, 0, offsetof(MatroskaTrack,codec_id) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
305 { MATROSKA_ID_CODECPRIVATE, EBML_BIN, 0, offsetof(MatroskaTrack,codec_priv) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
306 { MATROSKA_ID_TRACKLANGUAGE, EBML_UTF8, 0, offsetof(MatroskaTrack,language), {.s="eng"} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
307 { MATROSKA_ID_TRACKDEFAULTDURATION, EBML_UINT, 0, offsetof(MatroskaTrack,default_duration) },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
308 { MATROSKA_ID_TRACKTIMECODESCALE, EBML_FLOAT,0, offsetof(MatroskaTrack,time_scale), {.f=1.0} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
309 { MATROSKA_ID_TRACKFLAGDEFAULT, EBML_UINT, 0, offsetof(MatroskaTrack,flag_default), {.u=1} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
310 { MATROSKA_ID_TRACKVIDEO, EBML_NEST, 0, offsetof(MatroskaTrack,video), {.n=matroska_track_video} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
311 { MATROSKA_ID_TRACKAUDIO, EBML_NEST, 0, offsetof(MatroskaTrack,audio), {.n=matroska_track_audio} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
312 { MATROSKA_ID_TRACKCONTENTENCODINGS,EBML_NEST, 0, 0, {.n=matroska_track_encodings} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
313 { MATROSKA_ID_TRACKUID, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
314 { MATROSKA_ID_TRACKNAME, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
315 { MATROSKA_ID_TRACKFLAGENABLED, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
316 { MATROSKA_ID_TRACKFLAGFORCED, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
317 { MATROSKA_ID_TRACKFLAGLACING, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
318 { MATROSKA_ID_CODECNAME, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
319 { MATROSKA_ID_CODECDECODEALL, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
320 { MATROSKA_ID_CODECINFOURL, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
321 { MATROSKA_ID_CODECDOWNLOADURL, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
322 { MATROSKA_ID_TRACKMINCACHE, EBML_NONE },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
323 { MATROSKA_ID_TRACKMAXCACHE, EBML_NONE },
3717
f65dc584662d matroskadec: list some more ebml IDs found in the wild and that we ignore
aurel
parents: 3713
diff changeset
324 { MATROSKA_ID_TRACKMAXBLKADDID, EBML_NONE },
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
325 { 0 }
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
326 };
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
327
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
328 static EbmlSyntax matroska_tracks[] = {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
329 { MATROSKA_ID_TRACKENTRY, EBML_NEST, sizeof(MatroskaTrack), offsetof(MatroskaDemuxContext,tracks), {.n=matroska_track} },
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
330 { 0 }
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
331 };
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
332
3640
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
333 static EbmlSyntax matroska_attachment[] = {
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
334 { MATROSKA_ID_FILENAME, EBML_UTF8, 0, offsetof(MatroskaAttachement,filename) },
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
335 { MATROSKA_ID_FILEMIMETYPE, EBML_STR, 0, offsetof(MatroskaAttachement,mime) },
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
336 { MATROSKA_ID_FILEDATA, EBML_BIN, 0, offsetof(MatroskaAttachement,bin) },
3717
f65dc584662d matroskadec: list some more ebml IDs found in the wild and that we ignore
aurel
parents: 3713
diff changeset
337 { MATROSKA_ID_FILEDESC, EBML_NONE },
3640
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
338 { MATROSKA_ID_FILEUID, EBML_NONE },
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
339 { 0 }
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
340 };
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
341
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
342 static EbmlSyntax matroska_attachments[] = {
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
343 { 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
344 { 0 }
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
345 };
122a7c807f80 matroskadec: use generic parser to parse attachments
aurel
parents: 3639
diff changeset
346
3639
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
347 static EbmlSyntax matroska_chapter_display[] = {
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
348 { MATROSKA_ID_CHAPSTRING, EBML_UTF8, 0, offsetof(MatroskaChapter,title) },
3717
f65dc584662d matroskadec: list some more ebml IDs found in the wild and that we ignore
aurel
parents: 3713
diff changeset
349 { MATROSKA_ID_CHAPLANG, EBML_NONE },
3639
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
350 { 0 }
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
351 };
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
352
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
353 static EbmlSyntax matroska_chapter_entry[] = {
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
354 { 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
355 { 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
356 { MATROSKA_ID_CHAPTERUID, EBML_UINT, 0, offsetof(MatroskaChapter,uid) },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
357 { MATROSKA_ID_CHAPTERDISPLAY, EBML_NEST, 0, 0, {.n=matroska_chapter_display} },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
358 { MATROSKA_ID_CHAPTERFLAGHIDDEN, EBML_NONE },
3717
f65dc584662d matroskadec: list some more ebml IDs found in the wild and that we ignore
aurel
parents: 3713
diff changeset
359 { MATROSKA_ID_CHAPTERFLAGENABLED, EBML_NONE },
f65dc584662d matroskadec: list some more ebml IDs found in the wild and that we ignore
aurel
parents: 3713
diff changeset
360 { MATROSKA_ID_CHAPTERPHYSEQUIV, EBML_NONE },
f65dc584662d matroskadec: list some more ebml IDs found in the wild and that we ignore
aurel
parents: 3713
diff changeset
361 { MATROSKA_ID_CHAPTERATOM, EBML_NONE },
3639
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
362 { 0 }
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
363 };
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
364
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
365 static EbmlSyntax matroska_chapter[] = {
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
366 { MATROSKA_ID_CHAPTERATOM, EBML_NEST, sizeof(MatroskaChapter), offsetof(MatroskaDemuxContext,chapters), {.n=matroska_chapter_entry} },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
367 { MATROSKA_ID_EDITIONUID, EBML_NONE },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
368 { MATROSKA_ID_EDITIONFLAGHIDDEN, EBML_NONE },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
369 { MATROSKA_ID_EDITIONFLAGDEFAULT, EBML_NONE },
3717
f65dc584662d matroskadec: list some more ebml IDs found in the wild and that we ignore
aurel
parents: 3713
diff changeset
370 { MATROSKA_ID_EDITIONFLAGORDERED, EBML_NONE },
3639
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
371 { 0 }
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
372 };
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
373
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
374 static EbmlSyntax matroska_chapters[] = {
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
375 { MATROSKA_ID_EDITIONENTRY, EBML_NEST, 0, 0, {.n=matroska_chapter} },
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
376 { 0 }
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
377 };
74787fc857be matroskadec: use generic parser to parse chapters
aurel
parents: 3638
diff changeset
378
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
379 static EbmlSyntax matroska_index_pos[] = {
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
380 { MATROSKA_ID_CUETRACK, EBML_UINT, 0, offsetof(MatroskaIndexPos,track) },
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
381 { MATROSKA_ID_CUECLUSTERPOSITION, EBML_UINT, 0, offsetof(MatroskaIndexPos,pos) },
3717
f65dc584662d matroskadec: list some more ebml IDs found in the wild and that we ignore
aurel
parents: 3713
diff changeset
382 { MATROSKA_ID_CUEBLOCKNUMBER, EBML_NONE },
3637
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_entry[] = {
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
387 { MATROSKA_ID_CUETIME, EBML_UINT, 0, offsetof(MatroskaIndex,time) },
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
388 { 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
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
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
392 static EbmlSyntax matroska_index[] = {
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
393 { 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
394 { 0 }
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
395 };
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
396
3702
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
397 static EbmlSyntax matroska_simpletag[] = {
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
398 { MATROSKA_ID_TAGNAME, EBML_UTF8, 0, offsetof(MatroskaTag,name) },
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
399 { MATROSKA_ID_TAGSTRING, EBML_UTF8, 0, offsetof(MatroskaTag,string) },
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
400 { MATROSKA_ID_SIMPLETAG, EBML_NEST, sizeof(MatroskaTag), offsetof(MatroskaTag,sub), {.n=matroska_simpletag} },
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
401 { MATROSKA_ID_TAGLANG, EBML_NONE },
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
402 { MATROSKA_ID_TAGDEFAULT, EBML_NONE },
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
403 { 0 }
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
404 };
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
405
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
406 static EbmlSyntax matroska_tag[] = {
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
407 { MATROSKA_ID_SIMPLETAG, EBML_NEST, sizeof(MatroskaTag), 0, {.n=matroska_simpletag} },
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
408 { MATROSKA_ID_TAGTARGETS, EBML_NONE },
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
409 { 0 }
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
410 };
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
411
3638
5897e0c8a1eb matroskadec: use generic parser to parse tags
aurel
parents: 3637
diff changeset
412 static EbmlSyntax matroska_tags[] = {
3702
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
413 { MATROSKA_ID_TAG, EBML_NEST, 0, offsetof(MatroskaDemuxContext,tags), {.n=matroska_tag} },
3638
5897e0c8a1eb matroskadec: use generic parser to parse tags
aurel
parents: 3637
diff changeset
414 { 0 }
5897e0c8a1eb matroskadec: use generic parser to parse tags
aurel
parents: 3637
diff changeset
415 };
5897e0c8a1eb matroskadec: use generic parser to parse tags
aurel
parents: 3637
diff changeset
416
3644
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
417 static EbmlSyntax matroska_seekhead_entry[] = {
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
418 { MATROSKA_ID_SEEKID, EBML_UINT, 0, offsetof(MatroskaSeekhead,id) },
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
419 { MATROSKA_ID_SEEKPOSITION, EBML_UINT, 0, offsetof(MatroskaSeekhead,pos), {.u=-1} },
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
420 { 0 }
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
421 };
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
422
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
423 static EbmlSyntax matroska_seekhead[] = {
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
424 { 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
425 { 0 }
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
426 };
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
427
3651
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
428 static EbmlSyntax matroska_segment[] = {
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
429 { MATROSKA_ID_INFO, EBML_NEST, 0, 0, {.n=matroska_info } },
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
430 { MATROSKA_ID_TRACKS, EBML_NEST, 0, 0, {.n=matroska_tracks } },
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
431 { MATROSKA_ID_ATTACHMENTS, EBML_NEST, 0, 0, {.n=matroska_attachments} },
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
432 { MATROSKA_ID_CHAPTERS, EBML_NEST, 0, 0, {.n=matroska_chapters } },
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
433 { MATROSKA_ID_CUES, EBML_NEST, 0, 0, {.n=matroska_index } },
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
434 { MATROSKA_ID_TAGS, EBML_NEST, 0, 0, {.n=matroska_tags } },
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
435 { MATROSKA_ID_SEEKHEAD, EBML_NEST, 0, 0, {.n=matroska_seekhead } },
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
436 { MATROSKA_ID_CLUSTER, EBML_STOP, 0, offsetof(MatroskaDemuxContext,has_cluster_id) },
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
437 { 0 }
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
438 };
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
439
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
440 static EbmlSyntax matroska_segments[] = {
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
441 { MATROSKA_ID_SEGMENT, EBML_NEST, 0, 0, {.n=matroska_segment } },
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
442 { 0 }
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
443 };
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
444
3653
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
445 static EbmlSyntax matroska_blockgroup[] = {
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
446 { MATROSKA_ID_BLOCK, EBML_BIN, 0, offsetof(MatroskaBlock,bin) },
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
447 { MATROSKA_ID_SIMPLEBLOCK, EBML_BIN, 0, offsetof(MatroskaBlock,bin) },
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
448 { MATROSKA_ID_BLOCKDURATION, EBML_UINT, 0, offsetof(MatroskaBlock,duration), {.u=AV_NOPTS_VALUE} },
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
449 { MATROSKA_ID_BLOCKREFERENCE, EBML_UINT, 0, offsetof(MatroskaBlock,reference) },
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
450 { 0 }
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
451 };
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
452
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
453 static EbmlSyntax matroska_cluster[] = {
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
454 { MATROSKA_ID_CLUSTERTIMECODE,EBML_UINT,0, offsetof(MatroskaCluster,timecode) },
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
455 { MATROSKA_ID_BLOCKGROUP, EBML_NEST, sizeof(MatroskaBlock), offsetof(MatroskaCluster,blocks), {.n=matroska_blockgroup} },
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
456 { MATROSKA_ID_SIMPLEBLOCK, EBML_PASS, sizeof(MatroskaBlock), offsetof(MatroskaCluster,blocks), {.n=matroska_blockgroup} },
3717
f65dc584662d matroskadec: list some more ebml IDs found in the wild and that we ignore
aurel
parents: 3713
diff changeset
457 { MATROSKA_ID_CLUSTERPOSITION,EBML_NONE },
f65dc584662d matroskadec: list some more ebml IDs found in the wild and that we ignore
aurel
parents: 3713
diff changeset
458 { MATROSKA_ID_CLUSTERPREVSIZE,EBML_NONE },
3653
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
459 { 0 }
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
460 };
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
461
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
462 static EbmlSyntax matroska_clusters[] = {
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
463 { MATROSKA_ID_CLUSTER, EBML_NEST, 0, 0, {.n=matroska_cluster} },
3717
f65dc584662d matroskadec: list some more ebml IDs found in the wild and that we ignore
aurel
parents: 3713
diff changeset
464 { MATROSKA_ID_INFO, EBML_NONE },
f65dc584662d matroskadec: list some more ebml IDs found in the wild and that we ignore
aurel
parents: 3713
diff changeset
465 { MATROSKA_ID_CUES, EBML_NONE },
f65dc584662d matroskadec: list some more ebml IDs found in the wild and that we ignore
aurel
parents: 3713
diff changeset
466 { MATROSKA_ID_TAGS, EBML_NONE },
f65dc584662d matroskadec: list some more ebml IDs found in the wild and that we ignore
aurel
parents: 3713
diff changeset
467 { MATROSKA_ID_SEEKHEAD, EBML_NONE },
3653
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
468 { 0 }
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
469 };
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
470
3702
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
471 #define SIZE_OFF(x) sizeof(((AVFormatContext*)0)->x),offsetof(AVFormatContext,x)
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
472 const struct {
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
473 const char name[16];
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
474 int size;
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
475 int offset;
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
476 } metadata[] = {
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
477 { "TITLE", SIZE_OFF(title) },
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
478 { "ARTIST", SIZE_OFF(author) },
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
479 { "WRITTEN_BY", SIZE_OFF(author) },
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
480 { "LEAD_PERFORMER", SIZE_OFF(author) },
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
481 { "COPYRIGHT", SIZE_OFF(copyright) },
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
482 { "COMMENT", SIZE_OFF(comment) },
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
483 { "ALBUM", SIZE_OFF(album) },
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
484 { "DATE_WRITTEN", SIZE_OFF(year) },
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
485 { "DATE_RELEASED", SIZE_OFF(year) },
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
486 { "PART_NUMBER", SIZE_OFF(track) },
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
487 { "GENRE", SIZE_OFF(genre) },
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
488 };
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
489
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
490 /*
3692
e8f67b6063c3 misc spelling/grammar fixes
diego
parents: 3691
diff changeset
491 * Return: Whether we reached the end of a level in the hierarchy or not.
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
492 */
3674
a335cbe1fc1c matroskadec: simplify check for hierarchy level
aurel
parents: 3673
diff changeset
493 static int ebml_level_end(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
494 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
495 ByteIOContext *pb = matroska->ctx->pb;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3972
diff changeset
496 int64_t pos = url_ftell(pb);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
497
3674
a335cbe1fc1c matroskadec: simplify check for hierarchy level
aurel
parents: 3673
diff changeset
498 if (matroska->num_levels > 0) {
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
499 MatroskaLevel *level = &matroska->levels[matroska->num_levels - 1];
3674
a335cbe1fc1c matroskadec: simplify check for hierarchy level
aurel
parents: 3673
diff changeset
500 if (pos - level->start >= level->length) {
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
501 matroska->num_levels--;
3674
a335cbe1fc1c matroskadec: simplify check for hierarchy level
aurel
parents: 3673
diff changeset
502 return 1;
380
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 }
3674
a335cbe1fc1c matroskadec: simplify check for hierarchy level
aurel
parents: 3673
diff changeset
505 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
506 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
507
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 * 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
510 * 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
511 * 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
512 * "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
513 * number.
3692
e8f67b6063c3 misc spelling/grammar fixes
diego
parents: 3691
diff changeset
514 * Returns: number of bytes read, < 0 on error
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
515 */
3688
eb4649280c36 matroskadec: implement matroska_ebmlnum_uint() using ebml_read_num()
aurel
parents: 3687
diff changeset
516 static int ebml_read_num(MatroskaDemuxContext *matroska, ByteIOContext *pb,
3673
b0188029f916 matroskadec: cosmetics: consistent style for function declarations
aurel
parents: 3672
diff changeset
517 int max_size, uint64_t *number)
380
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 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
520 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
521
3692
e8f67b6063c3 misc spelling/grammar fixes
diego
parents: 3691
diff changeset
522 /* The first byte tells us the length in bytes - get_byte() can normally
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
523 * 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
524 * 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
525 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
526 /* 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
527 if (!url_feof(pb)) {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3972
diff changeset
528 int64_t pos = url_ftell(pb);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
529 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
530 "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
531 pos, pos);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
532 }
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
533 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
534 }
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 /* 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
537 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
538 read++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
539 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
540 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
541 if (read > max_size) {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3972
diff changeset
542 int64_t pos = url_ftell(pb) - 1;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
543 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
544 "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
545 (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
546 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
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 /* 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
550 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
551 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
552 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
553
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
554 *number = total;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
555
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
556 return read;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
557 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
558
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
559 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
560 * 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
561 * 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
562 */
3673
b0188029f916 matroskadec: cosmetics: consistent style for function declarations
aurel
parents: 3672
diff changeset
563 static int ebml_read_uint(ByteIOContext *pb, int size, uint64_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
564 {
3670
04b4e89c09d6 matroskadec: extract common code out of ebml_read_*()
aurel
parents: 3669
diff changeset
565 int n = 0;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
566
3669
836de2dd2615 matroskadec: simplify/cleanup error logging in ebml_read_*()
aurel
parents: 3668
diff changeset
567 if (size < 1 || size > 8)
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
568 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
569
3692
e8f67b6063c3 misc spelling/grammar fixes
diego
parents: 3691
diff changeset
570 /* big-endian ordering; build up number */
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
571 *num = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
572 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
573 *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
574
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
575 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
576 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
577
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
578 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
579 * 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
580 * 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
581 */
3673
b0188029f916 matroskadec: cosmetics: consistent style for function declarations
aurel
parents: 3672
diff changeset
582 static int ebml_read_float(ByteIOContext *pb, int size, 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
583 {
824
779b1e87b865 more non portable float parsing code ...
michael
parents: 820
diff changeset
584 if (size == 4) {
779b1e87b865 more non portable float parsing code ...
michael
parents: 820
diff changeset
585 *num= av_int2flt(get_be32(pb));
779b1e87b865 more non portable float parsing code ...
michael
parents: 820
diff changeset
586 } else if(size==8){
779b1e87b865 more non portable float parsing code ...
michael
parents: 820
diff changeset
587 *num= av_int2dbl(get_be64(pb));
3669
836de2dd2615 matroskadec: simplify/cleanup error logging in ebml_read_*()
aurel
parents: 3668
diff changeset
588 } else
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
589 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
590
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
591 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
592 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
593
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
594 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
595 * 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
596 * 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
597 */
3673
b0188029f916 matroskadec: cosmetics: consistent style for function declarations
aurel
parents: 3672
diff changeset
598 static int ebml_read_ascii(ByteIOContext *pb, int size, char **str)
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
599 {
3670
04b4e89c09d6 matroskadec: extract common code out of ebml_read_*()
aurel
parents: 3669
diff changeset
600 av_free(*str);
3692
e8f67b6063c3 misc spelling/grammar fixes
diego
parents: 3691
diff changeset
601 /* EBML strings are usually not 0-terminated, so we allocate one
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
602 * byte more, read the string and NULL-terminate it ourselves. */
3670
04b4e89c09d6 matroskadec: extract common code out of ebml_read_*()
aurel
parents: 3669
diff changeset
603 if (!(*str = av_malloc(size + 1)))
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2264
diff changeset
604 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
605 if (get_buffer(pb, (uint8_t *) *str, size) != size) {
3416
f386245ae6f7 matroskadec: fix potential mem leak
aurel
parents: 3415
diff changeset
606 av_free(*str);
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
607 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
608 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
609 (*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
610
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
611 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
612 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
613
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
614 /*
3684
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
615 * Read the next element as binary data.
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
616 * 0 is success, < 0 is failure.
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
617 */
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
618 static int ebml_read_binary(ByteIOContext *pb, int length, EbmlBin *bin)
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
619 {
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
620 av_free(bin->data);
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
621 if (!(bin->data = av_malloc(length)))
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
622 return AVERROR(ENOMEM);
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
623
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
624 bin->size = length;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
625 bin->pos = url_ftell(pb);
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
626 if (get_buffer(pb, bin->data, length) != length)
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
627 return AVERROR(EIO);
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
628
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
629 return 0;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
630 }
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
631
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
632 /*
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
633 * 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
634 * 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
635 * 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
636 */
3673
b0188029f916 matroskadec: cosmetics: consistent style for function declarations
aurel
parents: 3672
diff changeset
637 static int ebml_read_master(MatroskaDemuxContext *matroska, int length)
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
638 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
639 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
640 MatroskaLevel *level;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
641
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
642 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
643 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
644 "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
645 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
646 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
647
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
648 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
649 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
650 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
651
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
652 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
653 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
654
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
655 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
656 * Read signed/unsigned "EBML" numbers.
3692
e8f67b6063c3 misc spelling/grammar fixes
diego
parents: 3691
diff changeset
657 * Return: number of bytes processed, < 0 on error
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
658 */
3688
eb4649280c36 matroskadec: implement matroska_ebmlnum_uint() using ebml_read_num()
aurel
parents: 3687
diff changeset
659 static int matroska_ebmlnum_uint(MatroskaDemuxContext *matroska,
eb4649280c36 matroskadec: implement matroska_ebmlnum_uint() using ebml_read_num()
aurel
parents: 3687
diff changeset
660 uint8_t *data, uint32_t size, uint64_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
661 {
3688
eb4649280c36 matroskadec: implement matroska_ebmlnum_uint() using ebml_read_num()
aurel
parents: 3687
diff changeset
662 ByteIOContext pb;
eb4649280c36 matroskadec: implement matroska_ebmlnum_uint() using ebml_read_num()
aurel
parents: 3687
diff changeset
663 init_put_byte(&pb, data, size, 0, NULL, NULL, NULL, NULL);
eb4649280c36 matroskadec: implement matroska_ebmlnum_uint() using ebml_read_num()
aurel
parents: 3687
diff changeset
664 return ebml_read_num(matroska, &pb, 8, num);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
665 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
666
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 * 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
669 */
3688
eb4649280c36 matroskadec: implement matroska_ebmlnum_uint() using ebml_read_num()
aurel
parents: 3687
diff changeset
670 static int matroska_ebmlnum_sint(MatroskaDemuxContext *matroska,
eb4649280c36 matroskadec: implement matroska_ebmlnum_uint() using ebml_read_num()
aurel
parents: 3687
diff changeset
671 uint8_t *data, uint32_t size, 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
672 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
673 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
674 int res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
675
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
676 /* read as unsigned number first */
3688
eb4649280c36 matroskadec: implement matroska_ebmlnum_uint() using ebml_read_num()
aurel
parents: 3687
diff changeset
677 if ((res = matroska_ebmlnum_uint(matroska, data, size, &unum)) < 0)
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
678 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
679
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
680 /* make signed (weird way) */
3689
bce0dc931087 matroskadec: simplify matroska_ebmlnum_sint()
aurel
parents: 3688
diff changeset
681 *num = unum - ((1LL << (7*res - 1)) - 1);
380
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 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
684 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
685
3632
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
686 static int ebml_parse_elem(MatroskaDemuxContext *matroska,
3684
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
687 EbmlSyntax *syntax, void *data);
3632
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
688
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
689 static int ebml_parse_id(MatroskaDemuxContext *matroska, EbmlSyntax *syntax,
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
690 uint32_t id, void *data)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
691 {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
692 int i;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
693 for (i=0; syntax[i].id; i++)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
694 if (id == syntax[i].id)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
695 break;
3745
47807c439186 matroskadec: handle EBML_ID_VOID and EBML_ID_CRC32 in a generic way
aurel
parents: 3717
diff changeset
696 if (!syntax[i].id && id != EBML_ID_VOID && id != EBML_ID_CRC32)
3632
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
697 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
698 return ebml_parse_elem(matroska, &syntax[i], data);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
699 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
700
3677
0aed3a6e4e81 matroskadec: new ebml_parse() function, centralize ebml_read_element_id() calls
aurel
parents: 3676
diff changeset
701 static int ebml_parse(MatroskaDemuxContext *matroska, EbmlSyntax *syntax,
0aed3a6e4e81 matroskadec: new ebml_parse() function, centralize ebml_read_element_id() calls
aurel
parents: 3676
diff changeset
702 void *data)
0aed3a6e4e81 matroskadec: new ebml_parse() function, centralize ebml_read_element_id() calls
aurel
parents: 3676
diff changeset
703 {
3690
50c074bc02b4 matroskadec: expand useless ebml_read_element_id() wrapper
aurel
parents: 3689
diff changeset
704 uint64_t id;
50c074bc02b4 matroskadec: expand useless ebml_read_element_id() wrapper
aurel
parents: 3689
diff changeset
705 int res = ebml_read_num(matroska, matroska->ctx->pb, 4, &id);
50c074bc02b4 matroskadec: expand useless ebml_read_element_id() wrapper
aurel
parents: 3689
diff changeset
706 id |= 1 << 7*res;
3677
0aed3a6e4e81 matroskadec: new ebml_parse() function, centralize ebml_read_element_id() calls
aurel
parents: 3676
diff changeset
707 return res < 0 ? res : ebml_parse_id(matroska, syntax, id, data);
0aed3a6e4e81 matroskadec: new ebml_parse() function, centralize ebml_read_element_id() calls
aurel
parents: 3676
diff changeset
708 }
0aed3a6e4e81 matroskadec: new ebml_parse() function, centralize ebml_read_element_id() calls
aurel
parents: 3676
diff changeset
709
3676
d2ff1b7ad060 matroskadec: rename ebml_parse() to ebml_parse_nest()
aurel
parents: 3675
diff changeset
710 static int ebml_parse_nest(MatroskaDemuxContext *matroska, EbmlSyntax *syntax,
3679
039a28684d43 matroskadec: remove now unused parameter 'once' from ebml_parse_nest()
aurel
parents: 3678
diff changeset
711 void *data)
3632
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
712 {
3675
736c7c66234a matroskadec: don't care about the number of bytes read by ebml_read_element_id()
aurel
parents: 3674
diff changeset
713 int i, res = 0;
3632
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
714
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
715 for (i=0; syntax[i].id; i++)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
716 switch (syntax[i].type) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
717 case EBML_UINT:
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
718 *(uint64_t *)((char *)data+syntax[i].data_offset) = syntax[i].def.u;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
719 break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
720 case EBML_FLOAT:
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
721 *(double *)((char *)data+syntax[i].data_offset) = syntax[i].def.f;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
722 break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
723 case EBML_STR:
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
724 case EBML_UTF8:
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
725 *(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
726 break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
727 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
728
3679
039a28684d43 matroskadec: remove now unused parameter 'once' from ebml_parse_nest()
aurel
parents: 3678
diff changeset
729 while (!res && !ebml_level_end(matroska))
3677
0aed3a6e4e81 matroskadec: new ebml_parse() function, centralize ebml_read_element_id() calls
aurel
parents: 3676
diff changeset
730 res = ebml_parse(matroska, syntax, data);
3632
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
731
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
732 return res;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
733 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
734
3684
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
735 static int ebml_parse_elem(MatroskaDemuxContext *matroska,
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
736 EbmlSyntax *syntax, void *data)
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
737 {
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
738 ByteIOContext *pb = matroska->ctx->pb;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
739 uint32_t id = syntax->id;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
740 uint64_t length;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
741 int res;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
742
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
743 data = (char *)data + syntax->data_offset;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
744 if (syntax->list_elem_size) {
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
745 EbmlList *list = data;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
746 list->elem = av_realloc(list->elem, (list->nb_elem+1)*syntax->list_elem_size);
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
747 data = (char*)list->elem + list->nb_elem*syntax->list_elem_size;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
748 memset(data, 0, syntax->list_elem_size);
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
749 list->nb_elem++;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
750 }
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
751
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
752 if (syntax->type != EBML_PASS && syntax->type != EBML_STOP)
3688
eb4649280c36 matroskadec: implement matroska_ebmlnum_uint() using ebml_read_num()
aurel
parents: 3687
diff changeset
753 if ((res = ebml_read_num(matroska, pb, 8, &length)) < 0)
3684
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
754 return res;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
755
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
756 switch (syntax->type) {
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
757 case EBML_UINT: res = ebml_read_uint (pb, length, data); break;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
758 case EBML_FLOAT: res = ebml_read_float (pb, length, data); break;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
759 case EBML_STR:
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
760 case EBML_UTF8: res = ebml_read_ascii (pb, length, data); break;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
761 case EBML_BIN: res = ebml_read_binary(pb, length, data); break;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
762 case EBML_NEST: if ((res=ebml_read_master(matroska, length)) < 0)
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
763 return res;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
764 if (id == MATROSKA_ID_SEGMENT)
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
765 matroska->segment_start = url_ftell(matroska->ctx->pb);
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
766 return ebml_parse_nest(matroska, syntax->def.n, data);
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
767 case EBML_PASS: return ebml_parse_id(matroska, syntax->def.n, id, data);
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
768 case EBML_STOP: *(int *)data = 1; return 1;
3747
b8f428926617 matroskadec: stop parsing when skipping en element crossing over the end of file
aurel
parents: 3746
diff changeset
769 default: return url_fseek(pb,length,SEEK_CUR)<0 ? AVERROR(EIO) : 0;
3684
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
770 }
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
771 if (res == AVERROR_INVALIDDATA)
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
772 av_log(matroska->ctx, AV_LOG_ERROR, "Invalid element\n");
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
773 else if (res == AVERROR(EIO))
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
774 av_log(matroska->ctx, AV_LOG_ERROR, "Read error\n");
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
775 return res;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
776 }
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
777
3632
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
778 static void ebml_free(EbmlSyntax *syntax, void *data)
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
779 {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
780 int i, j;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
781 for (i=0; syntax[i].id; i++) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
782 void *data_off = (char *)data + syntax[i].data_offset;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
783 switch (syntax[i].type) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
784 case EBML_STR:
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
785 case EBML_UTF8: av_freep(data_off); break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
786 case EBML_BIN: av_freep(&((EbmlBin *)data_off)->data); break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
787 case EBML_NEST:
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
788 if (syntax[i].list_elem_size) {
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
789 EbmlList *list = data_off;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
790 char *ptr = list->elem;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
791 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
792 ebml_free(syntax[i].def.n, ptr);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
793 av_free(list->elem);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
794 } else
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
795 ebml_free(syntax[i].def.n, data_off);
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
796 default: break;
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
797 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
798 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
799 }
a43869dda583 matroskadec: add an ebml generic parser
aurel
parents: 3631
diff changeset
800
3684
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
801
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
802 /*
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
803 * Autodetecting...
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
804 */
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
805 static int matroska_probe(AVProbeData *p)
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
806 {
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
807 uint64_t total = 0;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
808 int len_mask = 0x80, size = 1, n = 1;
3768
185fc71a641c Mark "matroska" probe data string constant.
reimar
parents: 3762
diff changeset
809 static const char probe_data[] = "matroska";
3684
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
810
3692
e8f67b6063c3 misc spelling/grammar fixes
diego
parents: 3691
diff changeset
811 /* EBML header? */
3684
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
812 if (AV_RB32(p->buf) != EBML_ID_HEADER)
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
813 return 0;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
814
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
815 /* length of header */
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
816 total = p->buf[4];
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
817 while (size <= 8 && !(total & len_mask)) {
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
818 size++;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
819 len_mask >>= 1;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
820 }
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
821 if (size > 8)
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
822 return 0;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
823 total &= (len_mask - 1);
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
824 while (n < size)
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
825 total = (total << 8) | p->buf[4 + n++];
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
826
3692
e8f67b6063c3 misc spelling/grammar fixes
diego
parents: 3691
diff changeset
827 /* Does the probe data contain the whole header? */
3684
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
828 if (p->buf_size < 4 + size + total)
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
829 return 0;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
830
3692
e8f67b6063c3 misc spelling/grammar fixes
diego
parents: 3691
diff changeset
831 /* The header must contain the document type 'matroska'. For now,
3684
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
832 * we don't parse the whole header but simply check for the
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
833 * availability of that array of characters inside the header.
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
834 * Not fully fool-proof, but good enough. */
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
835 for (n = 4+size; n <= 4+size+total-(sizeof(probe_data)-1); n++)
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
836 if (!memcmp(p->buf+n, probe_data, sizeof(probe_data)-1))
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
837 return AVPROBE_SCORE_MAX;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
838
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
839 return 0;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
840 }
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
841
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
842 static MatroskaTrack *matroska_find_track_by_num(MatroskaDemuxContext *matroska,
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
843 int num)
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
844 {
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
845 MatroskaTrack *tracks = matroska->tracks.elem;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
846 int i;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
847
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
848 for (i=0; i < matroska->tracks.nb_elem; i++)
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
849 if (tracks[i].num == num)
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
850 return &tracks[i];
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
851
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
852 av_log(matroska->ctx, AV_LOG_ERROR, "Invalid track number %d\n", num);
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
853 return NULL;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
854 }
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
855
3673
b0188029f916 matroskadec: cosmetics: consistent style for function declarations
aurel
parents: 3672
diff changeset
856 static int matroska_decode_buffer(uint8_t** buf, int* buf_size,
b0188029f916 matroskadec: cosmetics: consistent style for function declarations
aurel
parents: 3672
diff changeset
857 MatroskaTrack *track)
3494
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
858 {
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
859 MatroskaTrackEncoding *encodings = track->encodings.elem;
3494
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
860 uint8_t* data = *buf;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
861 int isize = *buf_size;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
862 uint8_t* pkt_data = NULL;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
863 int pkt_size = isize;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
864 int result = 0;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
865 int olen;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
866
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
867 switch (encodings[0].compression.algo) {
3494
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
868 case MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP:
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
869 return encodings[0].compression.settings.size;
3494
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
870 case MATROSKA_TRACK_ENCODING_COMP_LZO:
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
871 do {
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
872 olen = pkt_size *= 3;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
873 pkt_data = av_realloc(pkt_data,
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
874 pkt_size+LZO_OUTPUT_PADDING);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
875 result = lzo1x_decode(pkt_data, &olen, data, &isize);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
876 } while (result==LZO_OUTPUT_FULL && pkt_size<10000000);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
877 if (result)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
878 goto failed;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
879 pkt_size -= olen;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
880 break;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
881 #ifdef CONFIG_ZLIB
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
882 case MATROSKA_TRACK_ENCODING_COMP_ZLIB: {
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
883 z_stream zstream = {0};
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
884 if (inflateInit(&zstream) != Z_OK)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
885 return -1;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
886 zstream.next_in = data;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
887 zstream.avail_in = isize;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
888 do {
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
889 pkt_size *= 3;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
890 pkt_data = av_realloc(pkt_data, pkt_size);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
891 zstream.avail_out = pkt_size - zstream.total_out;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
892 zstream.next_out = pkt_data + zstream.total_out;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
893 result = inflate(&zstream, Z_NO_FLUSH);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
894 } while (result==Z_OK && pkt_size<10000000);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
895 pkt_size = zstream.total_out;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
896 inflateEnd(&zstream);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
897 if (result != Z_STREAM_END)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
898 goto failed;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
899 break;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
900 }
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
901 #endif
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
902 #ifdef CONFIG_BZLIB
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
903 case MATROSKA_TRACK_ENCODING_COMP_BZLIB: {
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
904 bz_stream bzstream = {0};
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
905 if (BZ2_bzDecompressInit(&bzstream, 0, 0) != BZ_OK)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
906 return -1;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
907 bzstream.next_in = data;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
908 bzstream.avail_in = isize;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
909 do {
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
910 pkt_size *= 3;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
911 pkt_data = av_realloc(pkt_data, pkt_size);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
912 bzstream.avail_out = pkt_size - bzstream.total_out_lo32;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
913 bzstream.next_out = pkt_data + bzstream.total_out_lo32;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
914 result = BZ2_bzDecompress(&bzstream);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
915 } while (result==BZ_OK && pkt_size<10000000);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
916 pkt_size = bzstream.total_out_lo32;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
917 BZ2_bzDecompressEnd(&bzstream);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
918 if (result != BZ_STREAM_END)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
919 goto failed;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
920 break;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
921 }
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
922 #endif
3748
6b469866ffda matroskadec: fail cleanly when the required compression lib is not compiled in
aurel
parents: 3747
diff changeset
923 default:
6b469866ffda matroskadec: fail cleanly when the required compression lib is not compiled in
aurel
parents: 3747
diff changeset
924 return -1;
3494
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
925 }
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
926
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
927 *buf = pkt_data;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
928 *buf_size = pkt_size;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
929 return 0;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
930 failed:
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
931 av_free(pkt_data);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
932 return -1;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
933 }
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
934
3894
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
935 static void matroska_fix_ass_packet(MatroskaDemuxContext *matroska,
3951
9315ab7b1c0d matroskadec: pass duration as parameter of matroska_fix_ass_packet()
aurel
parents: 3922
diff changeset
936 AVPacket *pkt, uint64_t display_duration)
3894
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
937 {
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
938 char *line, *layer, *ptr = pkt->data, *end = ptr+pkt->size;
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
939 for (; *ptr!=',' && ptr<end-1; ptr++);
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
940 if (*ptr == ',')
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
941 layer = ++ptr;
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
942 for (; *ptr!=',' && ptr<end-1; ptr++);
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
943 if (*ptr == ',') {
3951
9315ab7b1c0d matroskadec: pass duration as parameter of matroska_fix_ass_packet()
aurel
parents: 3922
diff changeset
944 int64_t end_pts = pkt->pts + display_duration;
3894
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
945 int sc = matroska->time_scale * pkt->pts / 10000000;
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
946 int ec = matroska->time_scale * end_pts / 10000000;
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
947 int sh, sm, ss, eh, em, es, len;
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
948 sh = sc/360000; sc -= 360000*sh;
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
949 sm = sc/ 6000; sc -= 6000*sm;
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
950 ss = sc/ 100; sc -= 100*ss;
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
951 eh = ec/360000; ec -= 360000*eh;
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
952 em = ec/ 6000; ec -= 6000*em;
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
953 es = ec/ 100; ec -= 100*es;
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
954 *ptr++ = '\0';
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
955 len = 50 + end-ptr + FF_INPUT_BUFFER_PADDING_SIZE;
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
956 if (!(line = av_malloc(len)))
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
957 return;
3953
f1a9ff04eb4b matroskadec: ass events lines must end with a DOS style EOL
aurel
parents: 3952
diff changeset
958 snprintf(line,len,"Dialogue: %s,%d:%02d:%02d.%02d,%d:%02d:%02d.%02d,%s\r\n",
3894
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
959 layer, sh, sm, ss, sc, eh, em, es, ec, ptr);
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
960 av_free(pkt->data);
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
961 pkt->data = line;
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
962 pkt->size = strlen(line);
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
963 }
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
964 }
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
965
3954
0ebebd2ba034 matroskadec: merge ASS events which share the same pts in the same AVPavket
aurel
parents: 3953
diff changeset
966 static void matroska_merge_packets(AVPacket *out, AVPacket *in)
0ebebd2ba034 matroskadec: merge ASS events which share the same pts in the same AVPavket
aurel
parents: 3953
diff changeset
967 {
0ebebd2ba034 matroskadec: merge ASS events which share the same pts in the same AVPavket
aurel
parents: 3953
diff changeset
968 out->data = av_realloc(out->data, out->size+in->size);
0ebebd2ba034 matroskadec: merge ASS events which share the same pts in the same AVPavket
aurel
parents: 3953
diff changeset
969 memcpy(out->data+out->size, in->data, in->size);
0ebebd2ba034 matroskadec: merge ASS events which share the same pts in the same AVPavket
aurel
parents: 3953
diff changeset
970 out->size += in->size;
0ebebd2ba034 matroskadec: merge ASS events which share the same pts in the same AVPavket
aurel
parents: 3953
diff changeset
971 av_destruct_packet(in);
0ebebd2ba034 matroskadec: merge ASS events which share the same pts in the same AVPavket
aurel
parents: 3953
diff changeset
972 av_free(in);
0ebebd2ba034 matroskadec: merge ASS events which share the same pts in the same AVPavket
aurel
parents: 3953
diff changeset
973 }
0ebebd2ba034 matroskadec: merge ASS events which share the same pts in the same AVPavket
aurel
parents: 3953
diff changeset
974
3702
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
975 static void matroska_convert_tags(AVFormatContext *s, EbmlList *list)
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
976 {
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
977 MatroskaTag *tags = list->elem;
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
978 int i, j;
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
979
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
980 for (i=0; i < list->nb_elem; i++) {
4001
fcb9de59245f uses FF_ARRAY_ELEMS() where appropriate
aurel
parents: 3973
diff changeset
981 for (j=0; j < FF_ARRAY_ELEMS(metadata); j++){
3702
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
982 if (!strcmp(tags[i].name, metadata[j].name)) {
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
983 int *ptr = (int *)((char *)s + metadata[j].offset);
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
984 if (*ptr) continue;
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
985 if (metadata[j].size > sizeof(int))
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
986 av_strlcpy((char *)ptr, tags[i].string, metadata[j].size);
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
987 else
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
988 *ptr = atoi(tags[i].string);
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
989 }
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
990 }
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
991 if (tags[i].sub.nb_elem)
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
992 matroska_convert_tags(s, &tags[i].sub);
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
993 }
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
994 }
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
995
3673
b0188029f916 matroskadec: cosmetics: consistent style for function declarations
aurel
parents: 3672
diff changeset
996 static void matroska_execute_seekhead(MatroskaDemuxContext *matroska)
3644
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
997 {
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
998 EbmlList *seekhead_list = &matroska->seekhead;
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
999 MatroskaSeekhead *seekhead = seekhead_list->elem;
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1000 uint32_t level_up = matroska->level_up;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3972
diff changeset
1001 int64_t before_pos = url_ftell(matroska->ctx->pb);
3644
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1002 MatroskaLevel level;
3652
a22da874fc50 matroskadec: use generic parser inside matroska_execute_seekhead()
aurel
parents: 3651
diff changeset
1003 int i;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1004
3644
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1005 for (i=0; i<seekhead_list->nb_elem; i++) {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3972
diff changeset
1006 int64_t offset = seekhead[i].pos + matroska->segment_start;
3682
1332d68c8210 matroskadec: remove now useless wrapper ebml_read_seek()
aurel
parents: 3681
diff changeset
1007
3644
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1008 if (seekhead[i].pos <= before_pos
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1009 || seekhead[i].id == MATROSKA_ID_SEEKHEAD
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1010 || seekhead[i].id == MATROSKA_ID_CLUSTER)
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1011 continue;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1012
3646
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1013 /* seek */
3682
1332d68c8210 matroskadec: remove now useless wrapper ebml_read_seek()
aurel
parents: 3681
diff changeset
1014 if (url_fseek(matroska->ctx->pb, offset, SEEK_SET) != offset)
3646
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1015 continue;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1016
3692
e8f67b6063c3 misc spelling/grammar fixes
diego
parents: 3691
diff changeset
1017 /* We don't want to lose our seekhead level, so we add
3646
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1018 * a dummy. This is a crude hack. */
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1019 if (matroska->num_levels == EBML_MAX_DEPTH) {
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1020 av_log(matroska->ctx, AV_LOG_INFO,
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1021 "Max EBML element depth (%d) reached, "
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1022 "cannot parse further.\n", EBML_MAX_DEPTH);
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1023 break;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1024 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 883
diff changeset
1025
3646
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1026 level.start = 0;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1027 level.length = (uint64_t)-1;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1028 matroska->levels[matroska->num_levels] = level;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1029 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
1030
3677
0aed3a6e4e81 matroskadec: new ebml_parse() function, centralize ebml_read_element_id() calls
aurel
parents: 3676
diff changeset
1031 ebml_parse(matroska, matroska_segment, matroska);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1032
3646
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1033 /* remove dummy level */
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1034 while (matroska->num_levels) {
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1035 uint64_t length = matroska->levels[--matroska->num_levels].length;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1036 if (length == (uint64_t)-1)
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1037 break;
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1038 }
3644
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1039 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1040
3646
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1041 /* seek back */
3682
1332d68c8210 matroskadec: remove now useless wrapper ebml_read_seek()
aurel
parents: 3681
diff changeset
1042 url_fseek(matroska->ctx->pb, before_pos, SEEK_SET);
3646
370243aa26c0 matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents: 3645
diff changeset
1043 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
1044 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1045
3673
b0188029f916 matroskadec: cosmetics: consistent style for function declarations
aurel
parents: 3672
diff changeset
1046 static int matroska_aac_profile(char *codec_id)
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1047 {
3762
beb15b4fd4c4 matroskadec: make aac_profiles array const
aurel
parents: 3759
diff changeset
1048 static const char * const aac_profiles[] = { "MAIN", "LC", "SSR" };
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1049 int profile;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1050
4001
fcb9de59245f uses FF_ARRAY_ELEMS() where appropriate
aurel
parents: 3973
diff changeset
1051 for (profile=0; profile<FF_ARRAY_ELEMS(aac_profiles); profile++)
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1052 if (strstr(codec_id, aac_profiles[profile]))
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1053 break;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1054 return profile + 1;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1055 }
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1056
3673
b0188029f916 matroskadec: cosmetics: consistent style for function declarations
aurel
parents: 3672
diff changeset
1057 static int matroska_aac_sri(int samplerate)
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1058 {
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1059 int sri;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1060
4001
fcb9de59245f uses FF_ARRAY_ELEMS() where appropriate
aurel
parents: 3973
diff changeset
1061 for (sri=0; sri<FF_ARRAY_ELEMS(ff_mpeg4audio_sample_rates); sri++)
3201
1a16b069daca use common aac sample rate tables
aurel
parents: 3199
diff changeset
1062 if (ff_mpeg4audio_sample_rates[sri] == samplerate)
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1063 break;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1064 return sri;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1065 }
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
1066
3673
b0188029f916 matroskadec: cosmetics: consistent style for function declarations
aurel
parents: 3672
diff changeset
1067 static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1068 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1069 MatroskaDemuxContext *matroska = s->priv_data;
3650
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1070 EbmlList *attachements_list = &matroska->attachments;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1071 MatroskaAttachement *attachements;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1072 EbmlList *chapters_list = &matroska->chapters;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1073 MatroskaChapter *chapters;
3648
07f046bf6849 matroskadec: move declaration to upper block
aurel
parents: 3647
diff changeset
1074 MatroskaTrack *tracks;
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1075 EbmlList *index_list;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1076 MatroskaIndex *index;
4027
11fbf47f3e16 matroskadec: fix index timestamps for some broken files
aurel
parents: 4001
diff changeset
1077 int index_scale = 1;
3633
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
1078 Ebml ebml = { 0 };
3648
07f046bf6849 matroskadec: move declaration to upper block
aurel
parents: 3647
diff changeset
1079 AVStream *st;
3651
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
1080 int i, j;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1081
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1082 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
1083
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1084 /* First read the EBML header. */
3678
fd968e67ac6a matroskadec: directly use ebml_parse() or ebml_parse_id() where it's enough
aurel
parents: 3677
diff changeset
1085 if (ebml_parse(matroska, ebml_syntax, &ebml)
3633
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
1086 || 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
1087 || 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
1088 || 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
1089 av_log(matroska->ctx, AV_LOG_ERROR,
3633
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
1090 "EBML header using unsupported features\n"
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
1091 "(EBML version %"PRIu64", doctype %s, doc version %"PRIu64")\n",
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
1092 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
1093 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
1094 }
3633
7a44217312bb matroskadec: use generic ebml parser to parse ebml header
aurel
parents: 3632
diff changeset
1095 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
1096
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1097 /* The next thing is a segment. */
3678
fd968e67ac6a matroskadec: directly use ebml_parse() or ebml_parse_id() where it's enough
aurel
parents: 3677
diff changeset
1098 if (ebml_parse(matroska, matroska_segments, matroska) < 0)
3651
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
1099 return -1;
3644
1990951ffa35 matroskadec: use generic parser to parse seekhead
aurel
parents: 3643
diff changeset
1100 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
1101
3650
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1102 if (matroska->duration)
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1103 matroska->ctx->duration = matroska->duration * matroska->time_scale
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1104 * 1000 / AV_TIME_BASE;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1105 if (matroska->title)
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1106 strncpy(matroska->ctx->title, matroska->title,
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1107 sizeof(matroska->ctx->title)-1);
3702
b4f34511ccd3 matroskadec: add basic tags support (metadata)
aurel
parents: 3696
diff changeset
1108 matroska_convert_tags(s, &matroska->tags);
3650
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1109
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1110 tracks = matroska->tracks.elem;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1111 for (i=0; i < matroska->tracks.nb_elem; i++) {
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1112 MatroskaTrack *track = &tracks[i];
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1113 enum CodecID codec_id = CODEC_ID_NONE;
3650
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1114 EbmlList *encodings_list = &tracks->encodings;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1115 MatroskaTrackEncoding *encodings = encodings_list->elem;
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1116 uint8_t *extradata = NULL;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1117 int extradata_size = 0;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1118 int extradata_offset = 0;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1119
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1120 /* Apply some sanity checks. */
3650
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1121 if (track->type != MATROSKA_TRACK_TYPE_VIDEO &&
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1122 track->type != MATROSKA_TRACK_TYPE_AUDIO &&
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1123 track->type != MATROSKA_TRACK_TYPE_SUBTITLE) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1124 av_log(matroska->ctx, AV_LOG_INFO,
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1125 "Unknown or unsupported track type %"PRIu64"\n",
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1126 track->type);
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1127 continue;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1128 }
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1129 if (track->codec_id == NULL)
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1130 continue;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1131
3650
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1132 if (track->type == MATROSKA_TRACK_TYPE_VIDEO) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1133 if (!track->default_duration)
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1134 track->default_duration = 1000000000/track->video.frame_rate;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1135 if (!track->video.display_width)
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1136 track->video.display_width = track->video.pixel_width;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1137 if (!track->video.display_height)
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1138 track->video.display_height = track->video.pixel_height;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1139 } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1140 if (!track->audio.out_samplerate)
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1141 track->audio.out_samplerate = track->audio.samplerate;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1142 }
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1143 if (encodings_list->nb_elem > 1) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1144 av_log(matroska->ctx, AV_LOG_ERROR,
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1145 "Multiple combined encodings no supported");
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1146 } else if (encodings_list->nb_elem == 1) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1147 if (encodings[0].type ||
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1148 (encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP &&
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1149 #ifdef CONFIG_ZLIB
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1150 encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_ZLIB &&
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1151 #endif
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1152 #ifdef CONFIG_BZLIB
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1153 encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_BZLIB &&
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1154 #endif
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1155 encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_LZO)) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1156 encodings[0].scope = 0;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1157 av_log(matroska->ctx, AV_LOG_ERROR,
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1158 "Unsupported encoding type");
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1159 } else if (track->codec_priv.size && encodings[0].scope&2) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1160 uint8_t *codec_priv = track->codec_priv.data;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1161 int offset = matroska_decode_buffer(&track->codec_priv.data,
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1162 &track->codec_priv.size,
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1163 track);
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1164 if (offset < 0) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1165 track->codec_priv.data = NULL;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1166 track->codec_priv.size = 0;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1167 av_log(matroska->ctx, AV_LOG_ERROR,
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1168 "Failed to decode codec private data\n");
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1169 } else if (offset > 0) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1170 track->codec_priv.data = av_malloc(track->codec_priv.size + offset);
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1171 memcpy(track->codec_priv.data,
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1172 encodings[0].compression.settings.data, offset);
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1173 memcpy(track->codec_priv.data+offset, codec_priv,
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1174 track->codec_priv.size);
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1175 track->codec_priv.size += offset;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1176 }
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1177 if (codec_priv != track->codec_priv.data)
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1178 av_free(codec_priv);
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1179 }
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1180 }
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1181
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1182 for(j=0; ff_mkv_codec_tags[j].id != CODEC_ID_NONE; j++){
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1183 if(!strncmp(ff_mkv_codec_tags[j].str, track->codec_id,
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1184 strlen(ff_mkv_codec_tags[j].str))){
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1185 codec_id= ff_mkv_codec_tags[j].id;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1186 break;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1187 }
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1188 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1189
3691
b91cad3c97e8 matroskadec: remove useless num_streams
aurel
parents: 3690
diff changeset
1190 st = track->stream = av_new_stream(s, 0);
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1191 if (st == NULL)
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1192 return AVERROR(ENOMEM);
1024
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
1193
3687
494a55f131f3 matroska: expand useless define for MS compat codec id strings
aurel
parents: 3685
diff changeset
1194 if (!strcmp(track->codec_id, "V_MS/VFW/FOURCC")
3662
7222dc75f80e matroskadec: cosmetics: placement of 'else if'
aurel
parents: 3661
diff changeset
1195 && track->codec_priv.size >= 40
7222dc75f80e matroskadec: cosmetics: placement of 'else if'
aurel
parents: 3661
diff changeset
1196 && track->codec_priv.data != NULL) {
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1197 track->video.fourcc = AV_RL32(track->codec_priv.data + 16);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1198 codec_id = codec_get_id(codec_bmp_tags, track->video.fourcc);
3687
494a55f131f3 matroska: expand useless define for MS compat codec id strings
aurel
parents: 3685
diff changeset
1199 } else if (!strcmp(track->codec_id, "A_MS/ACM")
3662
7222dc75f80e matroskadec: cosmetics: placement of 'else if'
aurel
parents: 3661
diff changeset
1200 && track->codec_priv.size >= 18
7222dc75f80e matroskadec: cosmetics: placement of 'else if'
aurel
parents: 3661
diff changeset
1201 && track->codec_priv.data != NULL) {
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1202 uint16_t tag = AV_RL16(track->codec_priv.data);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1203 codec_id = codec_get_id(codec_wav_tags, tag);
3662
7222dc75f80e matroskadec: cosmetics: placement of 'else if'
aurel
parents: 3661
diff changeset
1204 } else if (!strcmp(track->codec_id, "V_QUICKTIME")
7222dc75f80e matroskadec: cosmetics: placement of 'else if'
aurel
parents: 3661
diff changeset
1205 && (track->codec_priv.size >= 86)
7222dc75f80e matroskadec: cosmetics: placement of 'else if'
aurel
parents: 3661
diff changeset
1206 && (track->codec_priv.data != NULL)) {
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1207 track->video.fourcc = AV_RL32(track->codec_priv.data);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1208 codec_id=codec_get_id(codec_movvideo_tags, track->video.fourcc);
3746
d9d8ee457c22 matroska: add support for most variants of PCM
aurel
parents: 3745
diff changeset
1209 } else if (codec_id == CODEC_ID_PCM_S16BE) {
d9d8ee457c22 matroska: add support for most variants of PCM
aurel
parents: 3745
diff changeset
1210 switch (track->audio.bitdepth) {
d9d8ee457c22 matroska: add support for most variants of PCM
aurel
parents: 3745
diff changeset
1211 case 8: codec_id = CODEC_ID_PCM_U8; break;
d9d8ee457c22 matroska: add support for most variants of PCM
aurel
parents: 3745
diff changeset
1212 case 24: codec_id = CODEC_ID_PCM_S24BE; break;
d9d8ee457c22 matroska: add support for most variants of PCM
aurel
parents: 3745
diff changeset
1213 case 32: codec_id = CODEC_ID_PCM_S32BE; break;
d9d8ee457c22 matroska: add support for most variants of PCM
aurel
parents: 3745
diff changeset
1214 }
d9d8ee457c22 matroska: add support for most variants of PCM
aurel
parents: 3745
diff changeset
1215 } else if (codec_id == CODEC_ID_PCM_S16LE) {
d9d8ee457c22 matroska: add support for most variants of PCM
aurel
parents: 3745
diff changeset
1216 switch (track->audio.bitdepth) {
d9d8ee457c22 matroska: add support for most variants of PCM
aurel
parents: 3745
diff changeset
1217 case 8: codec_id = CODEC_ID_PCM_U8; break;
d9d8ee457c22 matroska: add support for most variants of PCM
aurel
parents: 3745
diff changeset
1218 case 24: codec_id = CODEC_ID_PCM_S24LE; break;
d9d8ee457c22 matroska: add support for most variants of PCM
aurel
parents: 3745
diff changeset
1219 case 32: codec_id = CODEC_ID_PCM_S32LE; break;
d9d8ee457c22 matroska: add support for most variants of PCM
aurel
parents: 3745
diff changeset
1220 }
d9d8ee457c22 matroska: add support for most variants of PCM
aurel
parents: 3745
diff changeset
1221 } else if (codec_id==CODEC_ID_PCM_F32LE && track->audio.bitdepth==64) {
d9d8ee457c22 matroska: add support for most variants of PCM
aurel
parents: 3745
diff changeset
1222 codec_id = CODEC_ID_PCM_F64LE;
3662
7222dc75f80e matroskadec: cosmetics: placement of 'else if'
aurel
parents: 3661
diff changeset
1223 } else if (codec_id == CODEC_ID_AAC && !track->codec_priv.size) {
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1224 int profile = matroska_aac_profile(track->codec_id);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1225 int sri = matroska_aac_sri(track->audio.samplerate);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1226 extradata = av_malloc(5);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1227 if (extradata == NULL)
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1228 return AVERROR(ENOMEM);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1229 extradata[0] = (profile << 3) | ((sri&0x0E) >> 1);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1230 extradata[1] = ((sri&0x01) << 7) | (track->audio.channels<<3);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1231 if (strstr(track->codec_id, "SBR")) {
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1232 sri = matroska_aac_sri(track->audio.out_samplerate);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1233 extradata[2] = 0x56;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1234 extradata[3] = 0xE5;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1235 extradata[4] = 0x80 | (sri<<3);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1236 extradata_size = 5;
3655
e178e2725a59 matroskadec: cosmetics: remove useless braces
aurel
parents: 3654
diff changeset
1237 } else
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1238 extradata_size = 2;
3662
7222dc75f80e matroskadec: cosmetics: placement of 'else if'
aurel
parents: 3661
diff changeset
1239 } else if (codec_id == CODEC_ID_TTA) {
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1240 ByteIOContext b;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1241 extradata_size = 30;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1242 extradata = av_mallocz(extradata_size);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1243 if (extradata == NULL)
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1244 return AVERROR(ENOMEM);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1245 init_put_byte(&b, extradata, extradata_size, 1,
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1246 NULL, NULL, NULL, NULL);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1247 put_buffer(&b, "TTA1", 4);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1248 put_le16(&b, 1);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1249 put_le16(&b, track->audio.channels);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1250 put_le16(&b, track->audio.bitdepth);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1251 put_le32(&b, track->audio.out_samplerate);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1252 put_le32(&b, matroska->ctx->duration * track->audio.out_samplerate);
3662
7222dc75f80e matroskadec: cosmetics: placement of 'else if'
aurel
parents: 3661
diff changeset
1253 } else if (codec_id == CODEC_ID_RV10 || codec_id == CODEC_ID_RV20 ||
7222dc75f80e matroskadec: cosmetics: placement of 'else if'
aurel
parents: 3661
diff changeset
1254 codec_id == CODEC_ID_RV30 || codec_id == CODEC_ID_RV40) {
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1255 extradata_offset = 26;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1256 track->codec_priv.size -= extradata_offset;
3662
7222dc75f80e matroskadec: cosmetics: placement of 'else if'
aurel
parents: 3661
diff changeset
1257 } else if (codec_id == CODEC_ID_RA_144) {
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1258 track->audio.out_samplerate = 8000;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1259 track->audio.channels = 1;
3662
7222dc75f80e matroskadec: cosmetics: placement of 'else if'
aurel
parents: 3661
diff changeset
1260 } else if (codec_id == CODEC_ID_RA_288 || codec_id == CODEC_ID_COOK ||
7222dc75f80e matroskadec: cosmetics: placement of 'else if'
aurel
parents: 3661
diff changeset
1261 codec_id == CODEC_ID_ATRAC3) {
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1262 ByteIOContext b;
1534
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
1263
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1264 init_put_byte(&b, track->codec_priv.data,track->codec_priv.size,
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1265 0, NULL, NULL, NULL, NULL);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1266 url_fskip(&b, 24);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1267 track->audio.coded_framesize = get_be32(&b);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1268 url_fskip(&b, 12);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1269 track->audio.sub_packet_h = get_be16(&b);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1270 track->audio.frame_size = get_be16(&b);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1271 track->audio.sub_packet_size = get_be16(&b);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1272 track->audio.buf = av_malloc(track->audio.frame_size * track->audio.sub_packet_h);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1273 if (codec_id == CODEC_ID_RA_288) {
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1274 st->codec->block_align = track->audio.coded_framesize;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1275 track->codec_priv.size = 0;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1276 } else {
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1277 st->codec->block_align = track->audio.sub_packet_size;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1278 extradata_offset = 78;
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1279 track->codec_priv.size -= extradata_offset;
1531
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
1280 }
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1281 }
1531
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
1282
3655
e178e2725a59 matroskadec: cosmetics: remove useless braces
aurel
parents: 3654
diff changeset
1283 if (codec_id == CODEC_ID_NONE)
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1284 av_log(matroska->ctx, AV_LOG_INFO,
3659
e888db995d49 matroskadec: cosmetics
aurel
parents: 3658
diff changeset
1285 "Unknown/unsupported CodecID %s.\n", track->codec_id);
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1286
3912
32652a9c2624 matroskadec: sanitize track time_scale before using it
aurel
parents: 3899
diff changeset
1287 if (track->time_scale < 0.01)
32652a9c2624 matroskadec: sanitize track time_scale before using it
aurel
parents: 3899
diff changeset
1288 track->time_scale = 1.0;
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1289 av_set_pts_info(st, 64, matroska->time_scale*track->time_scale, 1000*1000*1000); /* 64 bit pts in ns */
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1290
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1291 st->codec->codec_id = codec_id;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1292 st->start_time = 0;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1293 if (strcmp(track->language, "und"))
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1294 av_strlcpy(st->language, track->language, 4);
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1295
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1296 if (track->flag_default)
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1297 st->disposition |= AV_DISPOSITION_DEFAULT;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1298
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1299 if (track->default_duration)
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1300 av_reduce(&st->codec->time_base.num, &st->codec->time_base.den,
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1301 track->default_duration, 1000000000, 30000);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1302
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1303 if(extradata){
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1304 st->codec->extradata = extradata;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1305 st->codec->extradata_size = extradata_size;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1306 } else if(track->codec_priv.data && track->codec_priv.size > 0){
4124
c8318261427d Allocate and clear FF_INPUT_BUFFER_PADDING_SIZE bytes at the end of mkv
astrange
parents: 4027
diff changeset
1307 st->codec->extradata = av_mallocz(track->codec_priv.size +
c8318261427d Allocate and clear FF_INPUT_BUFFER_PADDING_SIZE bytes at the end of mkv
astrange
parents: 4027
diff changeset
1308 FF_INPUT_BUFFER_PADDING_SIZE);
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1309 if(st->codec->extradata == NULL)
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1310 return AVERROR(ENOMEM);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1311 st->codec->extradata_size = track->codec_priv.size;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1312 memcpy(st->codec->extradata,
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1313 track->codec_priv.data + extradata_offset,
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1314 track->codec_priv.size);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1315 }
692
b0144ebc71dd H.264 and Vorbis support in matroska patch by (M«©ns Rullg«©rd |mru inprovide com)
michael
parents: 652
diff changeset
1316
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1317 if (track->type == MATROSKA_TRACK_TYPE_VIDEO) {
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1318 st->codec->codec_type = CODEC_TYPE_VIDEO;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1319 st->codec->codec_tag = track->video.fourcc;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1320 st->codec->width = track->video.pixel_width;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1321 st->codec->height = track->video.pixel_height;
3759
27537074f2a9 convert every muxer/demuxer to write/read sample_aspect_ratio from/to
aurel
parents: 3748
diff changeset
1322 av_reduce(&st->sample_aspect_ratio.num,
27537074f2a9 convert every muxer/demuxer to write/read sample_aspect_ratio from/to
aurel
parents: 3748
diff changeset
1323 &st->sample_aspect_ratio.den,
3649
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1324 st->codec->height * track->video.display_width,
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1325 st->codec-> width * track->video.display_height,
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1326 255);
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1327 st->need_parsing = AVSTREAM_PARSE_HEADERS;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1328 } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) {
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1329 st->codec->codec_type = CODEC_TYPE_AUDIO;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1330 st->codec->sample_rate = track->audio.out_samplerate;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1331 st->codec->channels = track->audio.channels;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1332 } else if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE) {
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1333 st->codec->codec_type = CODEC_TYPE_SUBTITLE;
71da9d010bae matroskadec: cosmetics: indentation of matroska_read_header()
aurel
parents: 3648
diff changeset
1334 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1335 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1336
3650
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1337 attachements = attachements_list->elem;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1338 for (j=0; j<attachements_list->nb_elem; j++) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1339 if (!(attachements[j].filename && attachements[j].mime &&
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1340 attachements[j].bin.data && attachements[j].bin.size > 0)) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1341 av_log(matroska->ctx, AV_LOG_ERROR, "incomplete attachment\n");
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1342 } else {
3691
b91cad3c97e8 matroskadec: remove useless num_streams
aurel
parents: 3690
diff changeset
1343 AVStream *st = av_new_stream(s, 0);
3650
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1344 if (st == NULL)
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1345 break;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1346 st->filename = av_strdup(attachements[j].filename);
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1347 st->codec->codec_id = CODEC_ID_NONE;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1348 st->codec->codec_type = CODEC_TYPE_ATTACHMENT;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1349 st->codec->extradata = av_malloc(attachements[j].bin.size);
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1350 if(st->codec->extradata == NULL)
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1351 break;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1352 st->codec->extradata_size = attachements[j].bin.size;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1353 memcpy(st->codec->extradata, attachements[j].bin.data, attachements[j].bin.size);
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1354
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1355 for (i=0; ff_mkv_mime_tags[i].id != CODEC_ID_NONE; i++) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1356 if (!strncmp(ff_mkv_mime_tags[i].str, attachements[j].mime,
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1357 strlen(ff_mkv_mime_tags[i].str))) {
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1358 st->codec->codec_id = ff_mkv_mime_tags[i].id;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1359 break;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1360 }
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1361 }
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1362 }
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1363 }
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1364
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1365 chapters = chapters_list->elem;
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1366 for (i=0; i<chapters_list->nb_elem; i++)
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1367 if (chapters[i].start != AV_NOPTS_VALUE && chapters[i].uid)
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1368 ff_new_chapter(s, chapters[i].uid, (AVRational){1, 1000000000},
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1369 chapters[i].start, chapters[i].end,
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1370 chapters[i].title);
f31190f3d234 matroskadec: move context settings to matroska_read_header()
aurel
parents: 3649
diff changeset
1371
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1372 index_list = &matroska->index;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1373 index = index_list->elem;
4027
11fbf47f3e16 matroskadec: fix index timestamps for some broken files
aurel
parents: 4001
diff changeset
1374 if (index_list->nb_elem
11fbf47f3e16 matroskadec: fix index timestamps for some broken files
aurel
parents: 4001
diff changeset
1375 && index[0].time > 100000000000000/matroska->time_scale) {
11fbf47f3e16 matroskadec: fix index timestamps for some broken files
aurel
parents: 4001
diff changeset
1376 av_log(matroska->ctx, AV_LOG_WARNING, "Working around broken index.\n");
11fbf47f3e16 matroskadec: fix index timestamps for some broken files
aurel
parents: 4001
diff changeset
1377 index_scale = matroska->time_scale;
11fbf47f3e16 matroskadec: fix index timestamps for some broken files
aurel
parents: 4001
diff changeset
1378 }
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1379 for (i=0; i<index_list->nb_elem; i++) {
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1380 EbmlList *pos_list = &index[i].pos;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1381 MatroskaIndexPos *pos = pos_list->elem;
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1382 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
1383 MatroskaTrack *track = matroska_find_track_by_num(matroska,
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1384 pos[j].track);
3636
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
1385 if (track && track->stream)
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
1386 av_add_index_entry(track->stream,
3637
c2d2760cfba0 matroskadec: use generic parser to parse index
aurel
parents: 3636
diff changeset
1387 pos[j].pos + matroska->segment_start,
4027
11fbf47f3e16 matroskadec: fix index timestamps for some broken files
aurel
parents: 4001
diff changeset
1388 index[i].time/index_scale, 0, 0,
11fbf47f3e16 matroskadec: fix index timestamps for some broken files
aurel
parents: 4001
diff changeset
1389 AVINDEX_KEYFRAME);
2012
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1390 }
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1391 }
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1392
3651
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
1393 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
1394 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1395
3684
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1396 /*
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1397 * Put one packet in an application-supplied AVPacket struct.
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1398 * Returns 0 on success or -1 on failure.
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1399 */
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1400 static int matroska_deliver_packet(MatroskaDemuxContext *matroska,
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1401 AVPacket *pkt)
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1402 {
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1403 if (matroska->num_packets > 0) {
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1404 memcpy(pkt, matroska->packets[0], sizeof(AVPacket));
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1405 av_free(matroska->packets[0]);
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1406 if (matroska->num_packets > 1) {
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1407 memmove(&matroska->packets[0], &matroska->packets[1],
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1408 (matroska->num_packets - 1) * sizeof(AVPacket *));
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1409 matroska->packets =
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1410 av_realloc(matroska->packets, (matroska->num_packets - 1) *
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1411 sizeof(AVPacket *));
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1412 } else {
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1413 av_freep(&matroska->packets);
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1414 }
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1415 matroska->num_packets--;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1416 return 0;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1417 }
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1418
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1419 return -1;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1420 }
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1421
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1422 /*
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1423 * Free all packets in our internal queue.
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1424 */
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1425 static void matroska_clear_queue(MatroskaDemuxContext *matroska)
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1426 {
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1427 if (matroska->packets) {
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1428 int n;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1429 for (n = 0; n < matroska->num_packets; n++) {
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1430 av_free_packet(matroska->packets[n]);
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1431 av_free(matroska->packets[n]);
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1432 }
3696
4aef467adb6b matroskadec: use av_freep(&x) instead of av_free(x);x=NULL
aurel
parents: 3695
diff changeset
1433 av_freep(&matroska->packets);
3684
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1434 matroska->num_packets = 0;
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1435 }
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1436 }
2350faade9fb matroskadec: reorder some functions in a more logical order
aurel
parents: 3683
diff changeset
1437
3673
b0188029f916 matroskadec: cosmetics: consistent style for function declarations
aurel
parents: 3672
diff changeset
1438 static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data,
b0188029f916 matroskadec: cosmetics: consistent style for function declarations
aurel
parents: 3672
diff changeset
1439 int size, int64_t pos, uint64_t cluster_time,
3897
5aa1cbbd79e0 matroskadec: ensure that the timecode added to the index are is the one
aurel
parents: 3894
diff changeset
1440 uint64_t duration, int is_keyframe,
5aa1cbbd79e0 matroskadec: ensure that the timecode added to the index are is the one
aurel
parents: 3894
diff changeset
1441 int64_t cluster_pos)
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1442 {
3913
253050919116 matroskadec: move timecode calculation a little earlier
aurel
parents: 3912
diff changeset
1443 uint64_t timecode = AV_NOPTS_VALUE;
3636
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
1444 MatroskaTrack *track;
3899
5901b4ccda4a matroskadec: remove now useless vstream and is_video_key_frame
aurel
parents: 3898
diff changeset
1445 int res = 0;
2013
fc0b19650faa add an intermediate variable (prepare for next patch)
aurel
parents: 2012
diff changeset
1446 AVStream *st;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1447 AVPacket *pkt;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1448 int16_t block_time;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1449 uint32_t *lace_size = NULL;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1450 int n, flags, laces = 0;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1451 uint64_t num;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1452
3688
eb4649280c36 matroskadec: implement matroska_ebmlnum_uint() using ebml_read_num()
aurel
parents: 3687
diff changeset
1453 if ((n = matroska_ebmlnum_uint(matroska, data, size, &num)) < 0) {
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1454 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
1455 return res;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1456 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1457 data += n;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1458 size -= n;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1459
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1460 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
1461 if (size <= 3 || !track || !track->stream) {
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1462 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
1463 "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
1464 return res;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1465 }
3636
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
1466 st = track->stream;
3655
e178e2725a59 matroskadec: cosmetics: remove useless braces
aurel
parents: 3654
diff changeset
1467 if (st->discard >= AVDISCARD_ALL)
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1468 return res;
1914
511723932287 calculate pts for laced packets
aurel
parents: 1913
diff changeset
1469 if (duration == AV_NOPTS_VALUE)
3636
1f8f906eb49e matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents: 3635
diff changeset
1470 duration = track->default_duration / matroska->time_scale;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1471
2185
7dd08e645d92 use intreadwrite functions in matroskadec
aurel
parents: 2175
diff changeset
1472 block_time = AV_RB16(data);
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1473 data += 2;
2188
4c2924cebe00 simplify
aurel
parents: 2185
diff changeset
1474 flags = *data++;
4c2924cebe00 simplify
aurel
parents: 2185
diff changeset
1475 size -= 3;
1831
bdca904db5e5 add support for simple blocks (ie. matroska v2)
aurel
parents: 1830
diff changeset
1476 if (is_keyframe == -1)
2415
3aa642c08cde SimpleBlock keyframe flag is the most significant bit
conrad
parents: 2390
diff changeset
1477 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
1478
3913
253050919116 matroskadec: move timecode calculation a little earlier
aurel
parents: 3912
diff changeset
1479 if (cluster_time != (uint64_t)-1
253050919116 matroskadec: move timecode calculation a little earlier
aurel
parents: 3912
diff changeset
1480 && (block_time >= 0 || cluster_time >= -block_time)) {
253050919116 matroskadec: move timecode calculation a little earlier
aurel
parents: 3912
diff changeset
1481 timecode = cluster_time + block_time;
3915
7643d7c3fcf6 matroskadec: ensure that overlapping subtitles are not added to the index
aurel
parents: 3914
diff changeset
1482 if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE
7643d7c3fcf6 matroskadec: ensure that overlapping subtitles are not added to the index
aurel
parents: 3914
diff changeset
1483 && timecode < track->end_timecode)
7643d7c3fcf6 matroskadec: ensure that overlapping subtitles are not added to the index
aurel
parents: 3914
diff changeset
1484 is_keyframe = 0; /* overlapping subtitles are not key frame */
3922
56dc585dcda4 matroskadec: simplify, first_timecode is already in the index
aurel
parents: 3921
diff changeset
1485 if (is_keyframe)
3913
253050919116 matroskadec: move timecode calculation a little earlier
aurel
parents: 3912
diff changeset
1486 av_add_index_entry(st, cluster_pos, timecode, 0,0,AVINDEX_KEYFRAME);
3915
7643d7c3fcf6 matroskadec: ensure that overlapping subtitles are not added to the index
aurel
parents: 3914
diff changeset
1487 track->end_timecode = FFMAX(track->end_timecode, timecode+duration);
3913
253050919116 matroskadec: move timecode calculation a little earlier
aurel
parents: 3912
diff changeset
1488 }
253050919116 matroskadec: move timecode calculation a little earlier
aurel
parents: 3912
diff changeset
1489
3916
4a7174c2b34e matroskadec: demux relevant subtitle packets after a seek
aurel
parents: 3915
diff changeset
1490 if (matroska->skip_to_keyframe && track->type != MATROSKA_TRACK_TYPE_SUBTITLE) {
3914
f7a20cf5438f matroskadec: after seeking, skip up to the desired timestamp instead of
aurel
parents: 3913
diff changeset
1491 if (!is_keyframe || timecode < matroska->skip_to_timecode)
2014
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
1492 return res;
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
1493 matroska->skip_to_keyframe = 0;
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
1494 }
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
1495
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1496 switch ((flags & 0x06) >> 1) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1497 case 0x0: /* no lacing */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1498 laces = 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1499 lace_size = av_mallocz(sizeof(int));
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1500 lace_size[0] = size;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1501 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1502
3692
e8f67b6063c3 misc spelling/grammar fixes
diego
parents: 3691
diff changeset
1503 case 0x1: /* Xiph lacing */
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1504 case 0x2: /* fixed-size lacing */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1505 case 0x3: /* EBML lacing */
3391
39750abd9bab Dead code removal, fixes CID59 RUN2.
michael
parents: 3334
diff changeset
1506 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
1507 laces = (*data) + 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1508 data += 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1509 size -= 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1510 lace_size = av_mallocz(laces * sizeof(int));
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1511
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1512 switch ((flags & 0x06) >> 1) {
3692
e8f67b6063c3 misc spelling/grammar fixes
diego
parents: 3691
diff changeset
1513 case 0x1: /* Xiph lacing */ {
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1514 uint8_t temp;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1515 uint32_t total = 0;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1516 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
1517 while (1) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1518 if (size == 0) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1519 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
1520 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1521 }
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1522 temp = *data;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1523 lace_size[n] += temp;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1524 data += 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1525 size -= 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1526 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
1527 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1528 }
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1529 total += lace_size[n];
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1530 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1531 lace_size[n] = size - total;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1532 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1533 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1534
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1535 case 0x2: /* fixed-size lacing */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1536 for (n = 0; n < laces; n++)
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1537 lace_size[n] = size / laces;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1538 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1539
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1540 case 0x3: /* EBML lacing */ {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1541 uint32_t total;
3688
eb4649280c36 matroskadec: implement matroska_ebmlnum_uint() using ebml_read_num()
aurel
parents: 3687
diff changeset
1542 n = matroska_ebmlnum_uint(matroska, data, size, &num);
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1543 if (n < 0) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1544 av_log(matroska->ctx, AV_LOG_INFO,
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1545 "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
1546 break;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1547 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1548 data += n;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1549 size -= n;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1550 total = lace_size[0] = num;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1551 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
1552 int64_t snum;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1553 int r;
3688
eb4649280c36 matroskadec: implement matroska_ebmlnum_uint() using ebml_read_num()
aurel
parents: 3687
diff changeset
1554 r = matroska_ebmlnum_sint(matroska, data, size, &snum);
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1555 if (r < 0) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1556 av_log(matroska->ctx, AV_LOG_INFO,
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1557 "EBML block data error\n");
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1558 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1559 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1560 data += r;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1561 size -= r;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1562 lace_size[n] = lace_size[n - 1] + snum;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1563 total += lace_size[n];
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1564 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1565 lace_size[n] = size - total;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1566 break;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1567 }
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1568 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1569 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1570 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1571
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1572 if (res == 0) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1573 for (n = 0; n < laces; n++) {
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1574 if (st->codec->codec_id == CODEC_ID_RA_288 ||
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1575 st->codec->codec_id == CODEC_ID_COOK ||
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1576 st->codec->codec_id == CODEC_ID_ATRAC3) {
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1577 int a = st->codec->block_align;
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1578 int sps = track->audio.sub_packet_size;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1579 int cfs = track->audio.coded_framesize;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1580 int h = track->audio.sub_packet_h;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1581 int y = track->audio.sub_packet_cnt;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1582 int w = track->audio.frame_size;
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1583 int x;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1584
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1585 if (!track->audio.pkt_cnt) {
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1586 if (st->codec->codec_id == CODEC_ID_RA_288)
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1587 for (x=0; x<h/2; x++)
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1588 memcpy(track->audio.buf+x*2*w+y*cfs,
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1589 data+x*cfs, cfs);
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1590 else
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1591 for (x=0; x<w/sps; x++)
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1592 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
1593
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1594 if (++track->audio.sub_packet_cnt >= h) {
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1595 track->audio.sub_packet_cnt = 0;
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1596 track->audio.pkt_cnt = h*w / a;
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1597 }
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1598 }
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1599 while (track->audio.pkt_cnt) {
2145
3dd44fd1cbf4 cosmetics: indentation
aurel
parents: 2144
diff changeset
1600 pkt = av_mallocz(sizeof(AVPacket));
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1601 av_new_packet(pkt, a);
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1602 memcpy(pkt->data, track->audio.buf
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1603 + a * (h*w / a - track->audio.pkt_cnt--), a);
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1604 pkt->pos = pos;
3634
f206f746ff61 matroskadec: store an AVStream pointer instead of a stream index
aurel
parents: 3633
diff changeset
1605 pkt->stream_index = st->index;
3695
5825a6cfd3bd matroskadec: replace matroska_queue_packet with a single call to dynarray_add
aurel
parents: 3692
diff changeset
1606 dynarray_add(&matroska->packets,&matroska->num_packets,pkt);
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
1607 }
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1608 } else {
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1609 MatroskaTrackEncoding *encodings = track->encodings.elem;
3494
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1610 int offset = 0, pkt_size = lace_size[n];
3281
a1d98736c15e matroskadec: add support for lzo compressed tracks
aurel
parents: 3280
diff changeset
1611 uint8_t *pkt_data = data;
a1d98736c15e matroskadec: add support for lzo compressed tracks
aurel
parents: 3280
diff changeset
1612
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1613 if (encodings && encodings->scope & 1) {
3659
e888db995d49 matroskadec: cosmetics
aurel
parents: 3658
diff changeset
1614 offset = matroska_decode_buffer(&pkt_data,&pkt_size, track);
3494
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1615 if (offset < 0)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1616 continue;
3279
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1617 }
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1618
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1619 pkt = av_mallocz(sizeof(AVPacket));
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1620 /* XXX: prevent data copy... */
3281
a1d98736c15e matroskadec: add support for lzo compressed tracks
aurel
parents: 3280
diff changeset
1621 if (av_new_packet(pkt, pkt_size+offset) < 0) {
3415
89f651b6f12a matroskadec: avoid potential mem leak
aurel
parents: 3414
diff changeset
1622 av_free(pkt);
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1623 res = AVERROR(ENOMEM);
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1624 n = laces-1;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1625 break;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1626 }
3279
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1627 if (offset)
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1628 memcpy (pkt->data, encodings->compression.settings.data, offset);
3281
a1d98736c15e matroskadec: add support for lzo compressed tracks
aurel
parents: 3280
diff changeset
1629 memcpy (pkt->data+offset, pkt_data, pkt_size);
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1630
3493
b77ced770a93 matroskadec: fix a memory leak
aurel
parents: 3477
diff changeset
1631 if (pkt_data != data)
b77ced770a93 matroskadec: fix a memory leak
aurel
parents: 3477
diff changeset
1632 av_free(pkt_data);
b77ced770a93 matroskadec: fix a memory leak
aurel
parents: 3477
diff changeset
1633
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1634 if (n == 0)
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1635 pkt->flags = is_keyframe;
3634
f206f746ff61 matroskadec: store an AVStream pointer instead of a stream index
aurel
parents: 3633
diff changeset
1636 pkt->stream_index = st->index;
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1637
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1638 pkt->pts = timecode;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1639 pkt->pos = pos;
3952
9808dea139a1 matroskadec: set duration only for CODEC_ID_TEXT subtitles
aurel
parents: 3951
diff changeset
1640 if (st->codec->codec_id == CODEC_ID_TEXT)
3892
8f1928b41f45 matroska: subtitle display duration must be stored in pkt->convergence_duration
aurel
parents: 3786
diff changeset
1641 pkt->convergence_duration = duration;
3952
9808dea139a1 matroskadec: set duration only for CODEC_ID_TEXT subtitles
aurel
parents: 3951
diff changeset
1642 else if (track->type != MATROSKA_TRACK_TYPE_SUBTITLE)
3892
8f1928b41f45 matroska: subtitle display duration must be stored in pkt->convergence_duration
aurel
parents: 3786
diff changeset
1643 pkt->duration = duration;
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1644
3894
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
1645 if (st->codec->codec_id == CODEC_ID_SSA)
3951
9315ab7b1c0d matroskadec: pass duration as parameter of matroska_fix_ass_packet()
aurel
parents: 3922
diff changeset
1646 matroska_fix_ass_packet(matroska, pkt, duration);
3894
30c8c9f53b9d matroskadec: fix ASS subtitle track packets before emitting them
aurel
parents: 3892
diff changeset
1647
3954
0ebebd2ba034 matroskadec: merge ASS events which share the same pts in the same AVPavket
aurel
parents: 3953
diff changeset
1648 if (matroska->prev_pkt &&
3971
eed7b7cb02a9 matroskadec: don't merge packets which have no timestamp
aurel
parents: 3954
diff changeset
1649 timecode != AV_NOPTS_VALUE &&
3954
0ebebd2ba034 matroskadec: merge ASS events which share the same pts in the same AVPavket
aurel
parents: 3953
diff changeset
1650 matroska->prev_pkt->pts == timecode &&
0ebebd2ba034 matroskadec: merge ASS events which share the same pts in the same AVPavket
aurel
parents: 3953
diff changeset
1651 matroska->prev_pkt->stream_index == st->index)
0ebebd2ba034 matroskadec: merge ASS events which share the same pts in the same AVPavket
aurel
parents: 3953
diff changeset
1652 matroska_merge_packets(matroska->prev_pkt, pkt);
0ebebd2ba034 matroskadec: merge ASS events which share the same pts in the same AVPavket
aurel
parents: 3953
diff changeset
1653 else {
3972
c7a831579a13 matroskadec: cosmetics: indentation
aurel
parents: 3971
diff changeset
1654 dynarray_add(&matroska->packets,&matroska->num_packets,pkt);
3954
0ebebd2ba034 matroskadec: merge ASS events which share the same pts in the same AVPavket
aurel
parents: 3953
diff changeset
1655 matroska->prev_pkt = pkt;
0ebebd2ba034 matroskadec: merge ASS events which share the same pts in the same AVPavket
aurel
parents: 3953
diff changeset
1656 }
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1657 }
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1658
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1659 if (timecode != AV_NOPTS_VALUE)
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
1660 timecode = duration ? timecode + duration : AV_NOPTS_VALUE;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1661 data += lace_size[n];
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1662 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1663 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1664
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
1665 av_free(lace_size);
3899
5901b4ccda4a matroskadec: remove now useless vstream and is_video_key_frame
aurel
parents: 3898
diff changeset
1666 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
1667 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1668
3673
b0188029f916 matroskadec: cosmetics: consistent style for function declarations
aurel
parents: 3672
diff changeset
1669 static int matroska_parse_cluster(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
1670 {
3653
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
1671 MatroskaCluster cluster = { 0 };
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
1672 EbmlList *blocks_list;
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
1673 MatroskaBlock *blocks;
3897
5aa1cbbd79e0 matroskadec: ensure that the timecode added to the index are is the one
aurel
parents: 3894
diff changeset
1674 int i, res;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3972
diff changeset
1675 int64_t pos = url_ftell(matroska->ctx->pb);
3954
0ebebd2ba034 matroskadec: merge ASS events which share the same pts in the same AVPavket
aurel
parents: 3953
diff changeset
1676 matroska->prev_pkt = NULL;
3680
8aa88bbf5f01 matroskadec: don't try to re-read already parsed ID in matroska_parse_cluster()
aurel
parents: 3679
diff changeset
1677 if (matroska->has_cluster_id){
3692
e8f67b6063c3 misc spelling/grammar fixes
diego
parents: 3691
diff changeset
1678 /* For the first cluster we parse, its ID was already read as
3680
8aa88bbf5f01 matroskadec: don't try to re-read already parsed ID in matroska_parse_cluster()
aurel
parents: 3679
diff changeset
1679 part of matroska_read_header(), so don't read it again */
8aa88bbf5f01 matroskadec: don't try to re-read already parsed ID in matroska_parse_cluster()
aurel
parents: 3679
diff changeset
1680 res = ebml_parse_id(matroska, matroska_clusters,
8aa88bbf5f01 matroskadec: don't try to re-read already parsed ID in matroska_parse_cluster()
aurel
parents: 3679
diff changeset
1681 MATROSKA_ID_CLUSTER, &cluster);
3773
2533332ca752 matroskadec: on the fly index construction for index-less files
aurel
parents: 3772
diff changeset
1682 pos -= 4; /* sizeof the ID which was already read */
3680
8aa88bbf5f01 matroskadec: don't try to re-read already parsed ID in matroska_parse_cluster()
aurel
parents: 3679
diff changeset
1683 matroska->has_cluster_id = 0;
8aa88bbf5f01 matroskadec: don't try to re-read already parsed ID in matroska_parse_cluster()
aurel
parents: 3679
diff changeset
1684 } else
8aa88bbf5f01 matroskadec: don't try to re-read already parsed ID in matroska_parse_cluster()
aurel
parents: 3679
diff changeset
1685 res = ebml_parse(matroska, matroska_clusters, &cluster);
3653
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
1686 blocks_list = &cluster.blocks;
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
1687 blocks = blocks_list->elem;
3713
b337fe64a31f matroskadec: parse available blocks even when cluster parsing failed
aurel
parents: 3702
diff changeset
1688 for (i=0; i<blocks_list->nb_elem; i++)
3898
da23c86d54ec matroskadec: remove useless braces
aurel
parents: 3897
diff changeset
1689 if (blocks[i].bin.size > 0)
3653
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
1690 res=matroska_parse_block(matroska,
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
1691 blocks[i].bin.data, blocks[i].bin.size,
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
1692 blocks[i].bin.pos, cluster.timecode,
3897
5aa1cbbd79e0 matroskadec: ensure that the timecode added to the index are is the one
aurel
parents: 3894
diff changeset
1693 blocks[i].duration, !blocks[i].reference,
5aa1cbbd79e0 matroskadec: ensure that the timecode added to the index are is the one
aurel
parents: 3894
diff changeset
1694 pos);
3653
9db1fca3bd30 matroskadec: use generic parser to parse clusters
aurel
parents: 3652
diff changeset
1695 ebml_free(matroska_cluster, &cluster);
3771
9e9dce9660e4 matroskadec: move setting of matroska->done inside matroska_parse_cluster()
aurel
parents: 3768
diff changeset
1696 if (res < 0) matroska->done = 1;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1697 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1698 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1699
3673
b0188029f916 matroskadec: cosmetics: consistent style for function declarations
aurel
parents: 3672
diff changeset
1700 static int matroska_read_packet(AVFormatContext *s, AVPacket *pkt)
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1701 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1702 MatroskaDemuxContext *matroska = s->priv_data;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1703
1899
1324ae790ee0 parse clusters until some packets are queued
aurel
parents: 1898
diff changeset
1704 while (matroska_deliver_packet(matroska, pkt)) {
1900
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
1705 if (matroska->done)
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
1706 return AVERROR(EIO);
3771
9e9dce9660e4 matroskadec: move setting of matroska->done inside matroska_parse_cluster()
aurel
parents: 3768
diff changeset
1707 matroska_parse_cluster(matroska);
1899
1324ae790ee0 parse clusters until some packets are queued
aurel
parents: 1898
diff changeset
1708 }
1324ae790ee0 parse clusters until some packets are queued
aurel
parents: 1898
diff changeset
1709
1324ae790ee0 parse clusters until some packets are queued
aurel
parents: 1898
diff changeset
1710 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
1711 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1712
3673
b0188029f916 matroskadec: cosmetics: consistent style for function declarations
aurel
parents: 3672
diff changeset
1713 static int matroska_read_seek(AVFormatContext *s, int stream_index,
b0188029f916 matroskadec: cosmetics: consistent style for function declarations
aurel
parents: 3672
diff changeset
1714 int64_t timestamp, int flags)
2012
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1715 {
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1716 MatroskaDemuxContext *matroska = s->priv_data;
3916
4a7174c2b34e matroskadec: demux relevant subtitle packets after a seek
aurel
parents: 3915
diff changeset
1717 MatroskaTrack *tracks = matroska->tracks.elem;
2012
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1718 AVStream *st = s->streams[stream_index];
3916
4a7174c2b34e matroskadec: demux relevant subtitle packets after a seek
aurel
parents: 3915
diff changeset
1719 int i, index, index_sub, index_min;
2012
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1720
3922
56dc585dcda4 matroskadec: simplify, first_timecode is already in the index
aurel
parents: 3921
diff changeset
1721 if (!st->nb_index_entries)
56dc585dcda4 matroskadec: simplify, first_timecode is already in the index
aurel
parents: 3921
diff changeset
1722 return 0;
56dc585dcda4 matroskadec: simplify, first_timecode is already in the index
aurel
parents: 3921
diff changeset
1723 timestamp = FFMAX(timestamp, st->index_entries[0].timestamp);
3772
7814581e98ff matroskadec: don't try to seek to negative timestamp
aurel
parents: 3771
diff changeset
1724
3785
fd49d42b918f matroskadec: seek to the last position known in the index before resorting to
aurel
parents: 3782
diff changeset
1725 if ((index = av_index_search_timestamp(st, timestamp, flags)) < 0) {
3922
56dc585dcda4 matroskadec: simplify, first_timecode is already in the index
aurel
parents: 3921
diff changeset
1726 url_fseek(s->pb, st->index_entries[st->nb_index_entries-1].pos, SEEK_SET);
3786
33a94467ea2b matroskadec: cosmetics: indentation
aurel
parents: 3785
diff changeset
1727 while ((index = av_index_search_timestamp(st, timestamp, flags)) < 0) {
33a94467ea2b matroskadec: cosmetics: indentation
aurel
parents: 3785
diff changeset
1728 matroska_clear_queue(matroska);
33a94467ea2b matroskadec: cosmetics: indentation
aurel
parents: 3785
diff changeset
1729 if (matroska_parse_cluster(matroska) < 0)
33a94467ea2b matroskadec: cosmetics: indentation
aurel
parents: 3785
diff changeset
1730 break;
33a94467ea2b matroskadec: cosmetics: indentation
aurel
parents: 3785
diff changeset
1731 }
3785
fd49d42b918f matroskadec: seek to the last position known in the index before resorting to
aurel
parents: 3782
diff changeset
1732 }
3774
fa5cc40e0164 matroskadec: full seeking support in index-less files
aurel
parents: 3773
diff changeset
1733
fa5cc40e0164 matroskadec: full seeking support in index-less files
aurel
parents: 3773
diff changeset
1734 matroska_clear_queue(matroska);
2012
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1735 if (index < 0)
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1736 return 0;
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1737
3916
4a7174c2b34e matroskadec: demux relevant subtitle packets after a seek
aurel
parents: 3915
diff changeset
1738 index_min = index;
4a7174c2b34e matroskadec: demux relevant subtitle packets after a seek
aurel
parents: 3915
diff changeset
1739 for (i=0; i < matroska->tracks.nb_elem; i++) {
4a7174c2b34e matroskadec: demux relevant subtitle packets after a seek
aurel
parents: 3915
diff changeset
1740 tracks[i].end_timecode = 0;
4a7174c2b34e matroskadec: demux relevant subtitle packets after a seek
aurel
parents: 3915
diff changeset
1741 if (tracks[i].type == MATROSKA_TRACK_TYPE_SUBTITLE
4a7174c2b34e matroskadec: demux relevant subtitle packets after a seek
aurel
parents: 3915
diff changeset
1742 && !tracks[i].stream->discard != AVDISCARD_ALL) {
4a7174c2b34e matroskadec: demux relevant subtitle packets after a seek
aurel
parents: 3915
diff changeset
1743 index_sub = av_index_search_timestamp(tracks[i].stream, st->index_entries[index].timestamp, AVSEEK_FLAG_BACKWARD);
4a7174c2b34e matroskadec: demux relevant subtitle packets after a seek
aurel
parents: 3915
diff changeset
1744 if (index_sub >= 0
4a7174c2b34e matroskadec: demux relevant subtitle packets after a seek
aurel
parents: 3915
diff changeset
1745 && st->index_entries[index_sub].pos < st->index_entries[index_min].pos
4a7174c2b34e matroskadec: demux relevant subtitle packets after a seek
aurel
parents: 3915
diff changeset
1746 && st->index_entries[index].timestamp - st->index_entries[index_sub].timestamp < 30000000000/matroska->time_scale)
4a7174c2b34e matroskadec: demux relevant subtitle packets after a seek
aurel
parents: 3915
diff changeset
1747 index_min = index_sub;
4a7174c2b34e matroskadec: demux relevant subtitle packets after a seek
aurel
parents: 3915
diff changeset
1748 }
4a7174c2b34e matroskadec: demux relevant subtitle packets after a seek
aurel
parents: 3915
diff changeset
1749 }
4a7174c2b34e matroskadec: demux relevant subtitle packets after a seek
aurel
parents: 3915
diff changeset
1750
4a7174c2b34e matroskadec: demux relevant subtitle packets after a seek
aurel
parents: 3915
diff changeset
1751 url_fseek(s->pb, st->index_entries[index_min].pos, SEEK_SET);
2014
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
1752 matroska->skip_to_keyframe = !(flags & AVSEEK_FLAG_ANY);
3914
f7a20cf5438f matroskadec: after seeking, skip up to the desired timestamp instead of
aurel
parents: 3913
diff changeset
1753 matroska->skip_to_timecode = st->index_entries[index].timestamp;
3775
f4eb5cc927f9 matroskadec: unset matroska->done when seeking
aurel
parents: 3774
diff changeset
1754 matroska->done = 0;
3462
3f87bde8a97c matroskadec: set cur_dts after seek
aurel
parents: 3427
diff changeset
1755 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
1756 return 0;
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1757 }
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1758
3673
b0188029f916 matroskadec: cosmetics: consistent style for function declarations
aurel
parents: 3672
diff changeset
1759 static int matroska_read_close(AVFormatContext *s)
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1760 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1761 MatroskaDemuxContext *matroska = s->priv_data;
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1762 MatroskaTrack *tracks = matroska->tracks.elem;
3656
9a2d1f2a39ee matroskadec: remove useless initialization
aurel
parents: 3655
diff changeset
1763 int n;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1764
2871
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
1765 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
1766
3642
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1767 for (n=0; n < matroska->tracks.nb_elem; n++)
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1768 if (tracks[n].type == MATROSKA_TRACK_TYPE_AUDIO)
842752a20c3c matroskadec: use generic parser to parse tracks
aurel
parents: 3641
diff changeset
1769 av_free(tracks[n].audio.buf);
3651
57c346e50442 matroskadec: use generic parser to parse matroska from toplevel
aurel
parents: 3650
diff changeset
1770 ebml_free(matroska_segment, matroska);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1771
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1772 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1773 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1774
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
1775 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
1776 "matroska",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3422
diff changeset
1777 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
1778 sizeof(MatroskaDemuxContext),
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1779 matroska_probe,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1780 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
1781 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
1782 matroska_read_close,
2012
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
1783 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
1784 };