annotate matroskadec.c @ 3628:5f2e1da55755 libavformat

matroskadec: use more robust av_strlcpy() instead of strcpy()
author aurel
date Tue, 05 Aug 2008 00:39:47 +0000
parents c0955bfc27be
children 8f06218b8767
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2 * Matroska file demuxer (no muxer yet)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3 * Copyright (c) 2003-2004 The ffmpeg Project
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1332
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1332
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1332
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1332
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1332
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
15 * Lesser General Public License for more details.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
16 *
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1332
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 887
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
20 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
21
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
22 /**
2175
9438e2e7faf2 Fix @file in matroskadec.c, it was still matroska.c
reimar
parents: 2147
diff changeset
23 * @file matroskadec.c
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
24 * Matroska file demuxer
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
25 * by Ronald Bultje <rbultje@ronald.bitfreak.net>
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
26 * with a little help from Moritz Bunkus <moritz@bunkus.org>
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
27 * Specs available on the matroska project page:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
28 * http://www.matroska.org/.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
29 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
30
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
31 #include "avformat.h"
1897
abbc781d608a use codec_get_id() instead of deprecated codec_get_[bmp/wav]_id()
aurel
parents: 1832
diff changeset
32 /* For codec_get_id(). */
1172
6a5e58d2114b move common stuff from avienc.c and wav.c to new file riff.c
mru
parents: 1169
diff changeset
33 #include "riff.h"
3601
c0955bfc27be matroska: add support for V_QUICKTIME track type
aurel
parents: 3495
diff changeset
34 #include "isom.h"
2142
3aa1f0f698de split some common code from the mkv demuxer that will be useful to the muxer
aurel
parents: 2023
diff changeset
35 #include "matroska.h"
3201
1a16b069daca use common aac sample rate tables
aurel
parents: 3199
diff changeset
36 #include "libavcodec/mpeg4audio.h"
3286
6f61c3b36632 Use full path for #includes from another directory.
diego
parents: 3283
diff changeset
37 #include "libavutil/intfloat_readwrite.h"
3628
5f2e1da55755 matroskadec: use more robust av_strlcpy() instead of strcpy()
aurel
parents: 3601
diff changeset
38 #include "libavutil/avstring.h"
3281
a1d98736c15e matroskadec: add support for lzo compressed tracks
aurel
parents: 3280
diff changeset
39 #include "libavutil/lzo.h"
3293
d3818f6d7530 matroskadec: add support for zlib compressed tracks
aurel
parents: 3290
diff changeset
40 #ifdef CONFIG_ZLIB
d3818f6d7530 matroskadec: add support for zlib compressed tracks
aurel
parents: 3290
diff changeset
41 #include <zlib.h>
d3818f6d7530 matroskadec: add support for zlib compressed tracks
aurel
parents: 3290
diff changeset
42 #endif
3298
edabe3db2b6e matroskadec: add support for bzlib compressed tracks
aurel
parents: 3294
diff changeset
43 #ifdef CONFIG_BZLIB
edabe3db2b6e matroskadec: add support for bzlib compressed tracks
aurel
parents: 3294
diff changeset
44 #include <bzlib.h>
edabe3db2b6e matroskadec: add support for bzlib compressed tracks
aurel
parents: 3294
diff changeset
45 #endif
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
46
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
47 typedef struct Track {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
48 MatroskaTrackType type;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
49
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
50 /* Unique track number and track ID. stream_index is the index that
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
51 * the calling app uses for this track. */
2147
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
52 uint32_t num;
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
53 uint32_t uid;
2201
c514ebfeec49 drop blocks which are part of unsupported tracks
aurel
parents: 2188
diff changeset
54 int stream_index;
2147
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
55
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
56 char *name;
2238
98ac80739c58 properly set AVStream.language according to Matroska track header
aurel
parents: 2202
diff changeset
57 char language[4];
2147
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
58
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
59 char *codec_id;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
60
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
61 unsigned char *codec_priv;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
62 int codec_priv_size;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
63
3408
da09478c97ce matroskadec: read TrackTimecodeScale and set timebase accordingly
aurel
parents: 3407
diff changeset
64 double time_scale;
1912
98a74cfd12d4 scale duration and default_duration
aurel
parents: 1911
diff changeset
65 uint64_t default_duration;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
66 MatroskaTrackFlags flags;
3279
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
67
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
68 int encoding_scope;
3283
82c6e0ec5c4b use enum type instead of int
aurel
parents: 3282
diff changeset
69 MatroskaTrackEncodingCompAlgo encoding_algo;
3279
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
70 uint8_t *encoding_settings;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
71 int encoding_settings_len;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
72 } MatroskaTrack;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
73
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
74 typedef struct MatroskaVideoTrack {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
75 MatroskaTrack track;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
76
2147
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
77 int pixel_width;
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
78 int pixel_height;
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
79 int display_width;
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
80 int display_height;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
81
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
82 uint32_t fourcc;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
83
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
84 //..
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
85 } MatroskaVideoTrack;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
86
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
87 typedef struct MatroskaAudioTrack {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
88 MatroskaTrack track;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
89
2147
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
90 int channels;
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
91 int bitdepth;
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
92 int internal_samplerate;
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
93 int samplerate;
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
94 int block_align;
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
95
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
96 /* real audio header */
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
97 int coded_framesize;
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
98 int sub_packet_h;
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
99 int frame_size;
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
100 int sub_packet_size;
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
101 int sub_packet_cnt;
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
102 int pkt_cnt;
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
103 uint8_t *buf;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
104 //..
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
105 } MatroskaAudioTrack;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
106
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
107 typedef struct MatroskaSubtitleTrack {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
108 MatroskaTrack track;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
109 //..
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
110 } MatroskaSubtitleTrack;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
111
3234
2e2221a3febb Implement FFMAX3(a,b,c) - maximum over three arguments.
voroshil
parents: 3201
diff changeset
112 #define MAX_TRACK_SIZE (FFMAX3(sizeof(MatroskaVideoTrack), \
2e2221a3febb Implement FFMAX3(a,b,c) - maximum over three arguments.
voroshil
parents: 3201
diff changeset
113 sizeof(MatroskaAudioTrack), \
1832
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
114 sizeof(MatroskaSubtitleTrack)))
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
115
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
116 typedef struct MatroskaLevel {
2147
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
117 uint64_t start;
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
118 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
119 } MatroskaLevel;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
120
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
121 typedef struct MatroskaDemuxIndex {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
122 uint64_t pos; /* of the corresponding *cluster*! */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
123 uint16_t track; /* reference to 'num' */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
124 uint64_t time; /* in nanoseconds */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
125 } MatroskaDemuxIndex;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
126
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
127 typedef struct MatroskaDemuxContext {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
128 AVFormatContext *ctx;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
129
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
130 /* ebml stuff */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
131 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
132 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
133 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
134
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
135 /* timescale in the file */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
136 int64_t time_scale;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
137
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
138 /* num_streams is the number of streams that av_new_stream() was called
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
139 * for ( = that are available to the calling program). */
2147
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
140 int num_tracks;
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
141 int num_streams;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
142 MatroskaTrack *tracks[MAX_STREAMS];
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
143
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
144 /* cache for ID peeking */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
145 uint32_t peek_id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
146
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
147 /* byte position of the segment inside the stream */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
148 offset_t segment_start;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
149
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
150 /* The packet queue. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
151 AVPacket **packets;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
152 int num_packets;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
153
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
154 /* have we already parse metadata/cues/clusters? */
2147
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
155 int metadata_parsed;
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
156 int index_parsed;
020cc5d6d6d7 cosmetics: use one type per field in every structs
aurel
parents: 2145
diff changeset
157 int done;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
158
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
159 /* The index for seeking. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
160 int num_indexes;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
161 MatroskaDemuxIndex *index;
2014
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
162
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
163 /* 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
164 int skip_to_keyframe;
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
165 AVStream *skip_to_stream;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
166 } MatroskaDemuxContext;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
167
3413
b7f86452706e matroskadec: move ARRAY_SIZE() macro at top of the file
aurel
parents: 3409
diff changeset
168 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(*x))
b7f86452706e matroskadec: move ARRAY_SIZE() macro at top of the file
aurel
parents: 3409
diff changeset
169
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
170 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
171 * The first few functions handle EBML file parsing. The rest
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
172 * is the document interpretation. Matroska really just is a
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
173 * EBML file.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
174 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
175
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
176 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
177 * Return: the amount of levels in the hierarchy that the
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
178 * current element lies higher than the previous one.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
179 * The opposite isn't done - that's auto-done using master
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
180 * element reading.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
181 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
182
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
183 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
184 ebml_read_element_level_up (MatroskaDemuxContext *matroska)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
185 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
186 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
187 offset_t pos = url_ftell(pb);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
188 int num = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
189
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
190 while (matroska->num_levels > 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
191 MatroskaLevel *level = &matroska->levels[matroska->num_levels - 1];
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
192
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
193 if (pos >= level->start + level->length) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
194 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
195 num++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
196 } else {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
197 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
198 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
199 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
200
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
201 return num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
202 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
203
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
204 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
205 * 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
206 * 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
207 * 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
208 * "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
209 * number.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
210 * Returns: num. of bytes read. < 0 on error.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
211 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
212
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
213 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
214 ebml_read_num (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
215 int max_size,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
216 uint64_t *number)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
217 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
218 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
219 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
220 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
221
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
222 /* the first byte tells us the length in bytes - get_byte() can normally
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
223 * 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
224 * 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
225 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
226 /* 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
227 if (!url_feof(pb)) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
228 offset_t pos = url_ftell(pb);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
229 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
230 "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
231 pos, pos);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
232 }
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
233 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
234 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
235
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
236 /* 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
237 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
238 read++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
239 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
240 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
241 if (read > max_size) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
242 offset_t pos = url_ftell(pb) - 1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
243 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
244 "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
245 (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
246 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
247 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
248
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
249 /* 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
250 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
251 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
252 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
253
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
254 *number = total;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
255
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
256 return read;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
257 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
258
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
259 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
260 * Read: the element content data ID.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
261 * Return: the number of bytes read or < 0 on error.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
262 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
263
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
264 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
265 ebml_read_element_id (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
266 uint32_t *id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
267 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
268 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
269 int read;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
270 uint64_t total;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
271
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
272 /* if we re-call this, use our cached ID */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
273 if (matroska->peek_id != 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
274 if (level_up)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
275 *level_up = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
276 *id = matroska->peek_id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
277 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
278 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
279
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
280 /* read out the "EBML number", include tag in ID */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
281 if ((read = ebml_read_num(matroska, 4, &total)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
282 return read;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
283 *id = matroska->peek_id = total | (1 << (read * 7));
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
284
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
285 /* level tracking */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
286 if (level_up)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
287 *level_up = ebml_read_element_level_up(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
288
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
289 return read;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
290 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
291
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
292 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
293 * Read: element content length.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
294 * Return: the number of bytes read or < 0 on error.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
295 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
296
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
297 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
298 ebml_read_element_length (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
299 uint64_t *length)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
300 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
301 /* clear cache since we're now beyond that data point */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
302 matroska->peek_id = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
303
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
304 /* read out the "EBML number", include tag in ID */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
305 return ebml_read_num(matroska, 8, length);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
306 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
307
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
308 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
309 * Return: the ID of the next element, or 0 on error.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
310 * Level_up contains the amount of levels that this
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
311 * next element lies higher than the previous one.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
312 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
313
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
314 static uint32_t
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
315 ebml_peek_id (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
316 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
317 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
318 uint32_t id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
319
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
320 if (ebml_read_element_id(matroska, &id, level_up) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
321 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
322
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
323 return id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
324 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
325
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
326 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
327 * Seek to a given offset.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
328 * 0 is success, -1 is failure.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
329 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
330
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
331 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
332 ebml_read_seek (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
333 offset_t offset)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
334 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
335 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
336
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
337 /* clear ID cache, if any */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
338 matroska->peek_id = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
339
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
340 return (url_fseek(pb, offset, SEEK_SET) == offset) ? 0 : -1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
341 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
342
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
343 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
344 * Skip the next element.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
345 * 0 is success, -1 is failure.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
346 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
347
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
348 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
349 ebml_read_skip (MatroskaDemuxContext *matroska)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
350 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
351 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
352 uint32_t id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
353 uint64_t length;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
354 int res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
355
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
356 if ((res = ebml_read_element_id(matroska, &id, NULL)) < 0 ||
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
357 (res = ebml_read_element_length(matroska, &length)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
358 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
359
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
360 url_fskip(pb, length);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
361
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
362 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
363 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
364
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
365 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
366 * 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
367 * 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
368 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
369
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
370 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
371 ebml_read_uint (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
372 uint32_t *id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
373 uint64_t *num)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
374 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
375 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
376 int n = 0, size, res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
377 uint64_t rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
378
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
379 if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 ||
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
380 (res = ebml_read_element_length(matroska, &rlength)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
381 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
382 size = rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
383 if (size < 1 || size > 8) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
384 offset_t pos = url_ftell(pb);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
385 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
386 "Invalid uint element size %d at position %"PRId64" (0x%"PRIx64")\n",
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
387 size, pos, pos);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
388 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
389 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
390
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
391 /* big-endian ordening; build up number */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
392 *num = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
393 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
394 *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
395
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
396 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
397 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
398
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
399 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
400 * Read the next element as a signed int.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
401 * 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
402 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
403
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
404 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
405 ebml_read_sint (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
406 uint32_t *id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
407 int64_t *num)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
408 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
409 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
410 int size, n = 1, negative = 0, res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
411 uint64_t rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
412
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
413 if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 ||
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
414 (res = ebml_read_element_length(matroska, &rlength)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
415 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
416 size = rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
417 if (size < 1 || size > 8) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
418 offset_t pos = url_ftell(pb);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
419 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
420 "Invalid sint element size %d at position %"PRId64" (0x%"PRIx64")\n",
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
421 size, pos, pos);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
422 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
423 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
424 if ((*num = get_byte(pb)) & 0x80) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
425 negative = 1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
426 *num &= ~0x80;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
427 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
428 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
429 *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
430
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
431 /* make signed */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
432 if (negative)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
433 *num = *num - (1LL << ((8 * size) - 1));
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
434
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
435 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
436 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
437
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
438 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
439 * 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
440 * 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
441 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
442
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
443 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
444 ebml_read_float (MatroskaDemuxContext *matroska,
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
445 uint32_t *id,
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
446 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
447 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
448 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
449 int size, res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
450 uint64_t rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
451
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
452 if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 ||
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
453 (res = ebml_read_element_length(matroska, &rlength)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
454 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
455 size = rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
456
824
779b1e87b865 more non portable float parsing code ...
michael
parents: 820
diff changeset
457 if (size == 4) {
779b1e87b865 more non portable float parsing code ...
michael
parents: 820
diff changeset
458 *num= av_int2flt(get_be32(pb));
779b1e87b865 more non portable float parsing code ...
michael
parents: 820
diff changeset
459 } else if(size==8){
779b1e87b865 more non portable float parsing code ...
michael
parents: 820
diff changeset
460 *num= av_int2dbl(get_be64(pb));
779b1e87b865 more non portable float parsing code ...
michael
parents: 820
diff changeset
461 } else{
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
462 offset_t pos = url_ftell(pb);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
463 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
464 "Invalid float element size %d at position %"PRIu64" (0x%"PRIx64")\n",
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
465 size, pos, pos);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
466 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
467 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
468
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
469 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
470 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
471
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
472 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
473 * 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
474 * 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
475 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
476
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
477 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
478 ebml_read_ascii (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
479 uint32_t *id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
480 char **str)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
481 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
482 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
483 int size, res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
484 uint64_t rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
485
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
486 if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 ||
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
487 (res = ebml_read_element_length(matroska, &rlength)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
488 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
489 size = rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
490
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
491 /* ebml strings are usually not 0-terminated, so we allocate one
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
492 * byte more, read the string and NULL-terminate it ourselves. */
639
0b52743104ac integer overflows, heap corruption
michael
parents: 496
diff changeset
493 if (size < 0 || !(*str = av_malloc(size + 1))) {
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
494 av_log(matroska->ctx, AV_LOG_ERROR, "Memory allocation failed\n");
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2264
diff changeset
495 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
496 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
497 if (get_buffer(pb, (uint8_t *) *str, size) != size) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
498 offset_t pos = url_ftell(pb);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
499 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
500 "Read error at pos. %"PRIu64" (0x%"PRIx64")\n", pos, pos);
3416
f386245ae6f7 matroskadec: fix potential mem leak
aurel
parents: 3415
diff changeset
501 av_free(*str);
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
502 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
503 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
504 (*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
505
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
506 return 0;
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 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
510 * Read the next element as a UTF-8 string.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
511 * 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
512 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
513
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
514 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
515 ebml_read_utf8 (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
516 uint32_t *id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
517 char **str)
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 return ebml_read_ascii(matroska, id, str);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
520 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
521
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
522 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
523 * 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
524 * 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
525 * 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
526 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
527
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
528 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
529 ebml_read_master (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
530 uint32_t *id)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
531 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
532 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
533 uint64_t length;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
534 MatroskaLevel *level;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
535 int res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
536
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
537 if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 ||
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
538 (res = ebml_read_element_length(matroska, &length)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
539 return res;
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 /* protect... (Heaven forbids that the '>' is true) */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
542 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
543 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
544 "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
545 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
546 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
547
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
548 /* remember level */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
549 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
550 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
551 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
552
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
553 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
554 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
555
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
556 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
557 * Read the next element as binary data.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
558 * 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
559 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
560
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
561 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
562 ebml_read_binary (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
563 uint32_t *id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
564 uint8_t **binary,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
565 int *size)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
566 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
567 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
568 uint64_t rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
569 int res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
570
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
571 if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 ||
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
572 (res = ebml_read_element_length(matroska, &rlength)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
573 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
574 *size = rlength;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
575
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
576 if (!(*binary = av_malloc(*size))) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
577 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
578 "Memory allocation error\n");
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2264
diff changeset
579 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
580 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
581
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
582 if (get_buffer(pb, *binary, *size) != *size) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
583 offset_t pos = url_ftell(pb);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
584 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
585 "Read error at pos. %"PRIu64" (0x%"PRIx64")\n", pos, pos);
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
586 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
587 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
588
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
589 return 0;
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
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 * Read signed/unsigned "EBML" numbers.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
594 * Return: number of bytes processed, < 0 on error.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
595 * XXX: use ebml_read_num().
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
596 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
597
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
598 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
599 matroska_ebmlnum_uint (uint8_t *data,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
600 uint32_t size,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
601 uint64_t *num)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
602 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
603 int len_mask = 0x80, read = 1, n = 1, num_ffs = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
604 uint64_t total;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
605
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
606 if (size <= 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
607 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
608
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
609 total = data[0];
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
610 while (read <= 8 && !(total & len_mask)) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
611 read++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
612 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
613 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
614 if (read > 8)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
615 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
616
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
617 if ((total &= (len_mask - 1)) == len_mask - 1)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
618 num_ffs++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
619 if (size < read)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
620 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
621 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
622 if (data[n] == 0xff)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
623 num_ffs++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
624 total = (total << 8) | data[n];
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
625 n++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
626 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
627
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
628 if (read == num_ffs)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
629 *num = (uint64_t)-1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
630 else
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
631 *num = total;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
632
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
633 return read;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
634 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
635
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
636 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
637 * 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
638 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
639
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
640 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
641 matroska_ebmlnum_sint (uint8_t *data,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
642 uint32_t size,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
643 int64_t *num)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
644 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
645 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
646 int res;
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 /* read as unsigned number first */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
649 if ((res = matroska_ebmlnum_uint(data, size, &unum)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
650 return res;
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 /* make signed (weird way) */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
653 if (unum == (uint64_t)-1)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
654 *num = INT64_MAX;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
655 else
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
656 *num = unum - ((1LL << ((7 * res) - 1)) - 1);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
657
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
658 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
659 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
660
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
661 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
662 * Read an EBML header.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
663 * 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
664 */
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 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
667 ebml_read_header (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
668 char **doctype,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
669 int *version)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
670 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
671 uint32_t id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
672 int level_up, res = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
673
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
674 /* default init */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
675 if (doctype)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
676 *doctype = NULL;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
677 if (version)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
678 *version = 1;
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 if (!(id = ebml_peek_id(matroska, &level_up)) ||
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
681 level_up != 0 || id != EBML_ID_HEADER) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
682 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
683 "This is not an EBML file (id=0x%x/0x%x)\n", id, EBML_ID_HEADER);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
684 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
685 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
686 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
687 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
688
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
689 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
690 if (!(id = ebml_peek_id(matroska, &level_up)))
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
691 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
692
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
693 /* end-of-header */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
694 if (level_up)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
695 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
696
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
697 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
698 /* is our read version uptodate? */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
699 case EBML_ID_EBMLREADVERSION: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
700 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
701
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
702 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
703 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
704 if (num > EBML_VERSION) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
705 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
706 "EBML version %"PRIu64" (> %d) is not supported\n",
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
707 num, EBML_VERSION);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
708 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
709 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
710 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
711 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
712
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
713 /* we only handle 8 byte lengths at max */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
714 case EBML_ID_EBMLMAXSIZELENGTH: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
715 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
716
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
717 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
718 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
719 if (num > sizeof(uint64_t)) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
720 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
721 "Integers of size %"PRIu64" (> %zd) not supported\n",
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
722 num, sizeof(uint64_t));
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
723 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
724 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
725 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
726 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
727
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
728 /* we handle 4 byte IDs at max */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
729 case EBML_ID_EBMLMAXIDLENGTH: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
730 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
731
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
732 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
733 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
734 if (num > sizeof(uint32_t)) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
735 av_log(matroska->ctx, AV_LOG_ERROR,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
736 "IDs of size %"PRIu64" (> %zu) not supported\n",
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
737 num, sizeof(uint32_t));
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
738 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
739 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
740 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
741 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
742
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
743 case EBML_ID_DOCTYPE: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
744 char *text;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
745
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
746 if ((res = ebml_read_ascii(matroska, &id, &text)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
747 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
748 if (doctype) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
749 if (*doctype)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
750 av_free(*doctype);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
751 *doctype = text;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
752 } else
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
753 av_free(text);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
754 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
755 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
756
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
757 case EBML_ID_DOCTYPEREADVERSION: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
758 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
759
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
760 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
761 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
762 if (version)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
763 *version = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
764 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
765 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
766
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
767 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
768 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
769 "Unknown data type 0x%x in EBML header", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
770 /* pass-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
771
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
772 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
773 /* we ignore these two, as they don't tell us anything we
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
774 * care about */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
775 case EBML_ID_EBMLVERSION:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
776 case EBML_ID_DOCTYPEVERSION:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
777 res = ebml_read_skip (matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
778 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
779 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
780 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
781
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
782 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
783 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
784
2011
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
785
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
786 static int
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
787 matroska_find_track_by_num (MatroskaDemuxContext *matroska,
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
788 int num)
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
789 {
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
790 int i;
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
791
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
792 for (i = 0; i < matroska->num_tracks; i++)
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
793 if (matroska->tracks[i]->num == num)
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
794 return i;
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
795
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
796 return -1;
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
797 }
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
798
84abfba4f3bf move matroska_find_track_by_num() upper in the file
aurel
parents: 2010
diff changeset
799
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
800 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
801 * Put one packet in an application-supplied AVPacket struct.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
802 * Returns 0 on success or -1 on failure.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
803 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
804
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
805 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
806 matroska_deliver_packet (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
807 AVPacket *pkt)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
808 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
809 if (matroska->num_packets > 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
810 memcpy(pkt, matroska->packets[0], sizeof(AVPacket));
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
811 av_free(matroska->packets[0]);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
812 if (matroska->num_packets > 1) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
813 memmove(&matroska->packets[0], &matroska->packets[1],
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
814 (matroska->num_packets - 1) * sizeof(AVPacket *));
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
815 matroska->packets =
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
816 av_realloc(matroska->packets, (matroska->num_packets - 1) *
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
817 sizeof(AVPacket *));
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
818 } else {
1530
f65cd8910a5c simplify free()+set to NULL using av_freep()
aurel
parents: 1490
diff changeset
819 av_freep(&matroska->packets);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
820 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
821 matroska->num_packets--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
822 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
823 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
824
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
825 return -1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
826 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
827
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
828 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
829 * Put a packet into our internal queue. Will be delivered to the
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
830 * user/application during the next get_packet() call.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
831 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
832
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
833 static void
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
834 matroska_queue_packet (MatroskaDemuxContext *matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
835 AVPacket *pkt)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
836 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
837 matroska->packets =
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
838 av_realloc(matroska->packets, (matroska->num_packets + 1) *
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
839 sizeof(AVPacket *));
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
840 matroska->packets[matroska->num_packets] = pkt;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
841 matroska->num_packets++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
842 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
843
2871
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
844 /*
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
845 * Free all packets in our internal queue.
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
846 */
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
847 static void
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
848 matroska_clear_queue (MatroskaDemuxContext *matroska)
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
849 {
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
850 if (matroska->packets) {
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
851 int n;
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
852 for (n = 0; n < matroska->num_packets; n++) {
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
853 av_free_packet(matroska->packets[n]);
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
854 av_free(matroska->packets[n]);
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
855 }
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
856 av_free(matroska->packets);
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
857 matroska->packets = NULL;
2881
dc2e92d4a903 move num_packets=0 where it belongs
aurel
parents: 2873
diff changeset
858 matroska->num_packets = 0;
2871
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
859 }
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
860 }
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
861
1904
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
862
df5fe029a504 reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents: 1903
diff changeset
863 /*
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
864 * Autodetecting...
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
865 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
866
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
867 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
868 matroska_probe (AVProbeData *p)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
869 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
870 uint64_t total = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
871 int len_mask = 0x80, size = 1, n = 1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
872 uint8_t probe_data[] = { 'm', 'a', 't', 'r', 'o', 's', 'k', 'a' };
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
873
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
874 /* ebml header? */
2185
7dd08e645d92 use intreadwrite functions in matroskadec
aurel
parents: 2175
diff changeset
875 if (AV_RB32(p->buf) != EBML_ID_HEADER)
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
876 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
877
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
878 /* length of header */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
879 total = p->buf[4];
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
880 while (size <= 8 && !(total & len_mask)) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
881 size++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
882 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
883 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
884 if (size > 8)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
885 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
886 total &= (len_mask - 1);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
887 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
888 total = (total << 8) | p->buf[4 + n++];
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
889
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
890 /* does the probe data contain the whole header? */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
891 if (p->buf_size < 4 + size + total)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
892 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
893
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
894 /* the header must contain the document type 'matroska'. For now,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
895 * we don't parse the whole header but simply check for the
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
896 * availability of that array of characters inside the header.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
897 * Not fully fool-proof, but good enough. */
1828
f1397cd39ec3 fix an off-by-one error in probing function
aurel
parents: 1673
diff changeset
898 for (n = 4 + size; n <= 4 + size + total - sizeof(probe_data); n++)
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
899 if (!memcmp (&p->buf[n], probe_data, sizeof(probe_data)))
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
900 return AVPROBE_SCORE_MAX;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
901
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
902 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
903 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
904
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
905 /*
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
906 * From here on, it's all XML-style DTD stuff... Needs no comments.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
907 */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
908
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
909 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
910 matroska_parse_info (MatroskaDemuxContext *matroska)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
911 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
912 int res = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
913 uint32_t id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
914
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
915 av_log(matroska->ctx, AV_LOG_DEBUG, "Parsing info...\n");
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
916
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
917 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
918 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
919 res = AVERROR(EIO);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
920 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
921 } else if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
922 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
923 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
924 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
925
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
926 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
927 /* cluster timecode */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
928 case MATROSKA_ID_TIMECODESCALE: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
929 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
930 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
931 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
932 matroska->time_scale = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
933 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
934 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
935
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
936 case MATROSKA_ID_DURATION: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
937 double num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
938 if ((res = ebml_read_float(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
939 break;
1025
95e8458ae120 duration and subitle fix from the patch by Steve Lhomme
michael
parents: 1024
diff changeset
940 matroska->ctx->duration = num * matroska->time_scale * 1000 / AV_TIME_BASE;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
941 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
942 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
943
1459
571b1b1c7984 Allow reading matroska title.
aurel
parents: 1458
diff changeset
944 case MATROSKA_ID_TITLE: {
571b1b1c7984 Allow reading matroska title.
aurel
parents: 1458
diff changeset
945 char *text;
571b1b1c7984 Allow reading matroska title.
aurel
parents: 1458
diff changeset
946 if ((res = ebml_read_utf8(matroska, &id, &text)) < 0)
571b1b1c7984 Allow reading matroska title.
aurel
parents: 1458
diff changeset
947 break;
571b1b1c7984 Allow reading matroska title.
aurel
parents: 1458
diff changeset
948 strncpy(matroska->ctx->title, text,
571b1b1c7984 Allow reading matroska title.
aurel
parents: 1458
diff changeset
949 sizeof(matroska->ctx->title)-1);
571b1b1c7984 Allow reading matroska title.
aurel
parents: 1458
diff changeset
950 av_free(text);
571b1b1c7984 Allow reading matroska title.
aurel
parents: 1458
diff changeset
951 break;
571b1b1c7984 Allow reading matroska title.
aurel
parents: 1458
diff changeset
952 }
571b1b1c7984 Allow reading matroska title.
aurel
parents: 1458
diff changeset
953
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
954 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
955 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
956 "Unknown entry 0x%x in info header\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
957 /* fall-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
958
3427
4e5e94c36862 matroskadec: remove some useless code
aurel
parents: 3426
diff changeset
959 case MATROSKA_ID_WRITINGAPP:
4e5e94c36862 matroskadec: remove some useless code
aurel
parents: 3426
diff changeset
960 case MATROSKA_ID_MUXINGAPP:
4e5e94c36862 matroskadec: remove some useless code
aurel
parents: 3426
diff changeset
961 case MATROSKA_ID_DATEUTC:
3407
ffd297928ed8 matroskadec: silently discard some element ID that we don't care about
aurel
parents: 3391
diff changeset
962 case MATROSKA_ID_SEGMENTUID:
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
963 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
964 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
965 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
966 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
967
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
968 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
969 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
970 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
971 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
972 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
973
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
974 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
975 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
976
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
977 static int
3494
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
978 matroska_decode_buffer(uint8_t** buf, int* buf_size, MatroskaTrack *track)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
979 {
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
980 uint8_t* data = *buf;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
981 int isize = *buf_size;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
982 uint8_t* pkt_data = NULL;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
983 int pkt_size = isize;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
984 int result = 0;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
985 int olen;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
986
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
987 switch (track->encoding_algo) {
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
988 case MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP:
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
989 return track->encoding_settings_len;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
990 case MATROSKA_TRACK_ENCODING_COMP_LZO:
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
991 do {
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
992 olen = pkt_size *= 3;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
993 pkt_data = av_realloc(pkt_data,
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
994 pkt_size+LZO_OUTPUT_PADDING);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
995 result = lzo1x_decode(pkt_data, &olen, data, &isize);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
996 } while (result==LZO_OUTPUT_FULL && pkt_size<10000000);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
997 if (result)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
998 goto failed;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
999 pkt_size -= olen;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1000 break;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1001 #ifdef CONFIG_ZLIB
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1002 case MATROSKA_TRACK_ENCODING_COMP_ZLIB: {
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1003 z_stream zstream = {0};
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1004 if (inflateInit(&zstream) != Z_OK)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1005 return -1;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1006 zstream.next_in = data;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1007 zstream.avail_in = isize;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1008 do {
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1009 pkt_size *= 3;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1010 pkt_data = av_realloc(pkt_data, pkt_size);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1011 zstream.avail_out = pkt_size - zstream.total_out;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1012 zstream.next_out = pkt_data + zstream.total_out;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1013 result = inflate(&zstream, Z_NO_FLUSH);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1014 } while (result==Z_OK && pkt_size<10000000);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1015 pkt_size = zstream.total_out;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1016 inflateEnd(&zstream);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1017 if (result != Z_STREAM_END)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1018 goto failed;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1019 break;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1020 }
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1021 #endif
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1022 #ifdef CONFIG_BZLIB
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1023 case MATROSKA_TRACK_ENCODING_COMP_BZLIB: {
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1024 bz_stream bzstream = {0};
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1025 if (BZ2_bzDecompressInit(&bzstream, 0, 0) != BZ_OK)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1026 return -1;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1027 bzstream.next_in = data;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1028 bzstream.avail_in = isize;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1029 do {
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1030 pkt_size *= 3;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1031 pkt_data = av_realloc(pkt_data, pkt_size);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1032 bzstream.avail_out = pkt_size - bzstream.total_out_lo32;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1033 bzstream.next_out = pkt_data + bzstream.total_out_lo32;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1034 result = BZ2_bzDecompress(&bzstream);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1035 } while (result==BZ_OK && pkt_size<10000000);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1036 pkt_size = bzstream.total_out_lo32;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1037 BZ2_bzDecompressEnd(&bzstream);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1038 if (result != BZ_STREAM_END)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1039 goto failed;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1040 break;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1041 }
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1042 #endif
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1043 }
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1044
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1045 *buf = pkt_data;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1046 *buf_size = pkt_size;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1047 return 0;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1048 failed:
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1049 av_free(pkt_data);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1050 return -1;
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1051 }
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1052
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
1053 static int
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1054 matroska_add_stream (MatroskaDemuxContext *matroska)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1055 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1056 int res = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1057 uint32_t id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1058 MatroskaTrack *track;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1059
3414
703f452f00f1 reorganize matroska_add_stream() to fix potential mem leak and buffer overflow
aurel
parents: 3413
diff changeset
1060 /* start with the master */
703f452f00f1 reorganize matroska_add_stream() to fix potential mem leak and buffer overflow
aurel
parents: 3413
diff changeset
1061 if ((res = ebml_read_master(matroska, &id)) < 0)
703f452f00f1 reorganize matroska_add_stream() to fix potential mem leak and buffer overflow
aurel
parents: 3413
diff changeset
1062 return res;
703f452f00f1 reorganize matroska_add_stream() to fix potential mem leak and buffer overflow
aurel
parents: 3413
diff changeset
1063
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1064 av_log(matroska->ctx, AV_LOG_DEBUG, "parsing track, adding stream..,\n");
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1065
3422
6ff296d8b284 adjust comment to reality
aurel
parents: 3421
diff changeset
1066 /* Allocate a generic track. */
1832
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
1067 track = av_mallocz(MAX_TRACK_SIZE);
3421
5667ba68090f matroskadec: sane default value for track->time_scale
aurel
parents: 3416
diff changeset
1068 track->time_scale = 1.0;
2238
98ac80739c58 properly set AVStream.language according to Matroska track header
aurel
parents: 2202
diff changeset
1069 strcpy(track->language, "eng");
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1070
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1071 /* try reading the trackentry headers */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1072 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1073 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
1074 res = AVERROR(EIO);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1075 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1076 } else if (matroska->level_up > 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1077 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1078 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1079 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1080
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1081 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1082 /* track number (unique stream ID) */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1083 case MATROSKA_ID_TRACKNUMBER: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1084 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1085 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1086 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1087 track->num = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1088 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1089 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1090
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1091 /* track UID (unique identifier) */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1092 case MATROSKA_ID_TRACKUID: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1093 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1094 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1095 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1096 track->uid = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1097 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1098 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1099
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1100 /* track type (video, audio, combined, subtitle, etc.) */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1101 case MATROSKA_ID_TRACKTYPE: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1102 uint64_t num;
1832
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
1103 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
1104 break;
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
1105 if (track->type && track->type != num) {
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1106 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1107 "More than one tracktype in an entry - skip\n");
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1108 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1109 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1110 track->type = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1111
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1112 switch (track->type) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1113 case MATROSKA_TRACK_TYPE_VIDEO:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1114 case MATROSKA_TRACK_TYPE_AUDIO:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1115 case MATROSKA_TRACK_TYPE_SUBTITLE:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1116 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1117 case MATROSKA_TRACK_TYPE_COMPLEX:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1118 case MATROSKA_TRACK_TYPE_LOGO:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1119 case MATROSKA_TRACK_TYPE_CONTROL:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1120 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1121 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1122 "Unknown or unsupported track type 0x%x\n",
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1123 track->type);
3290
fa502e142b44 Add MATROSKA_TRACK_TYPE_NONE.
cehoyos
parents: 3286
diff changeset
1124 track->type = MATROSKA_TRACK_TYPE_NONE;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1125 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1126 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1127 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1128 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1129
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1130 /* tracktype specific stuff for video */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1131 case MATROSKA_ID_TRACKVIDEO: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1132 MatroskaVideoTrack *videotrack;
1832
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
1133 if (!track->type)
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
1134 track->type = MATROSKA_TRACK_TYPE_VIDEO;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1135 if (track->type != MATROSKA_TRACK_TYPE_VIDEO) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1136 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1137 "video data in non-video track - ignoring\n");
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1138 res = AVERROR_INVALIDDATA;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1139 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1140 } else if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1141 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1142 videotrack = (MatroskaVideoTrack *)track;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1143
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1144 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1145 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
1146 res = AVERROR(EIO);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1147 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1148 } else if (matroska->level_up > 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1149 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1150 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1151 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1152
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1153 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1154 /* fixme, this should be one-up, but I get it here */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1155 case MATROSKA_ID_TRACKDEFAULTDURATION: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1156 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1157 if ((res = ebml_read_uint (matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1158 &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1159 break;
2389
cde14f83579b Don't pre-scale default_duration to avoid precision loss in fps calculation.
aurel
parents: 2388
diff changeset
1160 track->default_duration = num;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1161 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1162 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1163
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1164 /* video framerate */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1165 case MATROSKA_ID_VIDEOFRAMERATE: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1166 double num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1167 if ((res = ebml_read_float(matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1168 &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1169 break;
2387
108c29584787 calculate default_duration according to framerate only when not already set
aurel
parents: 2364
diff changeset
1170 if (!track->default_duration)
2390
de8377107b07 cosmetic: indentation
aurel
parents: 2389
diff changeset
1171 track->default_duration = 1000000000/num;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1172 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1173 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1174
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1175 /* width of the size to display the video at */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1176 case MATROSKA_ID_VIDEODISPLAYWIDTH: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1177 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1178 if ((res = ebml_read_uint(matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1179 &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1180 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1181 videotrack->display_width = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1182 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1183 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1184
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1185 /* height of the size to display the video at */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1186 case MATROSKA_ID_VIDEODISPLAYHEIGHT: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1187 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1188 if ((res = ebml_read_uint(matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1189 &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1190 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1191 videotrack->display_height = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1192 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1193 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1194
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1195 /* width of the video in the file */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1196 case MATROSKA_ID_VIDEOPIXELWIDTH: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1197 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1198 if ((res = ebml_read_uint(matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1199 &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1200 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1201 videotrack->pixel_width = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1202 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1203 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1204
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1205 /* height of the video in the file */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1206 case MATROSKA_ID_VIDEOPIXELHEIGHT: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1207 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1208 if ((res = ebml_read_uint(matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1209 &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1210 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1211 videotrack->pixel_height = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1212 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1213 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1214
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1215 /* whether the video is interlaced */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1216 case MATROSKA_ID_VIDEOFLAGINTERLACED: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1217 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1218 if ((res = ebml_read_uint(matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1219 &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1220 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1221 if (num)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1222 track->flags |=
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1223 MATROSKA_VIDEOTRACK_INTERLACED;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1224 else
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1225 track->flags &=
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1226 ~MATROSKA_VIDEOTRACK_INTERLACED;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1227 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1228 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1229
2804
c89e331851f3 cosmetics: comment spelling fixes
diego
parents: 2771
diff changeset
1230 /* colorspace (only matters for raw video)
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1231 * fourcc */
2805
888d5439eac6 colour --> color in variable names
diego
parents: 2804
diff changeset
1232 case MATROSKA_ID_VIDEOCOLORSPACE: {
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1233 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1234 if ((res = ebml_read_uint(matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1235 &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1236 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1237 videotrack->fourcc = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1238 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1239 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1240
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1241 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1242 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1243 "Unknown video track header entry "
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1244 "0x%x - ignoring\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1245 /* pass-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1246
3477
8adaa9258dba matroskadec: remove some useless code
aurel
parents: 3462
diff changeset
1247 case MATROSKA_ID_VIDEOSTEREOMODE:
8adaa9258dba matroskadec: remove some useless code
aurel
parents: 3462
diff changeset
1248 case MATROSKA_ID_VIDEOASPECTRATIO:
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1249 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1250 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1251 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1252 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1253
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1254 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1255 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1256 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1257 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1258 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1259 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1260 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1261
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1262 /* tracktype specific stuff for audio */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1263 case MATROSKA_ID_TRACKAUDIO: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1264 MatroskaAudioTrack *audiotrack;
1832
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
1265 if (!track->type)
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
1266 track->type = MATROSKA_TRACK_TYPE_AUDIO;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1267 if (track->type != MATROSKA_TRACK_TYPE_AUDIO) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1268 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1269 "audio data in non-audio track - ignoring\n");
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1270 res = AVERROR_INVALIDDATA;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1271 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1272 } else if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1273 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1274 audiotrack = (MatroskaAudioTrack *)track;
1832
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
1275 audiotrack->channels = 1;
1e51dfa8ef85 don't rely on a specific appearance order for ebml elements at the same level
aurel
parents: 1831
diff changeset
1276 audiotrack->samplerate = 8000;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1277
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1278 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1279 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
1280 res = AVERROR(EIO);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1281 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1282 } else if (matroska->level_up > 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1283 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1284 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1285 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1286
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1287 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1288 /* samplerate */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1289 case MATROSKA_ID_AUDIOSAMPLINGFREQ: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1290 double num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1291 if ((res = ebml_read_float(matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1292 &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1293 break;
1467
24c082e20a6a add audio output sampling freqency reading in matroska
aurel
parents: 1465
diff changeset
1294 audiotrack->internal_samplerate =
24c082e20a6a add audio output sampling freqency reading in matroska
aurel
parents: 1465
diff changeset
1295 audiotrack->samplerate = num;
24c082e20a6a add audio output sampling freqency reading in matroska
aurel
parents: 1465
diff changeset
1296 break;
24c082e20a6a add audio output sampling freqency reading in matroska
aurel
parents: 1465
diff changeset
1297 }
24c082e20a6a add audio output sampling freqency reading in matroska
aurel
parents: 1465
diff changeset
1298
24c082e20a6a add audio output sampling freqency reading in matroska
aurel
parents: 1465
diff changeset
1299 case MATROSKA_ID_AUDIOOUTSAMPLINGFREQ: {
24c082e20a6a add audio output sampling freqency reading in matroska
aurel
parents: 1465
diff changeset
1300 double num;
24c082e20a6a add audio output sampling freqency reading in matroska
aurel
parents: 1465
diff changeset
1301 if ((res = ebml_read_float(matroska, &id,
24c082e20a6a add audio output sampling freqency reading in matroska
aurel
parents: 1465
diff changeset
1302 &num)) < 0)
24c082e20a6a add audio output sampling freqency reading in matroska
aurel
parents: 1465
diff changeset
1303 break;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1304 audiotrack->samplerate = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1305 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1306 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1307
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1308 /* bitdepth */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1309 case MATROSKA_ID_AUDIOBITDEPTH: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1310 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1311 if ((res = ebml_read_uint(matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1312 &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1313 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1314 audiotrack->bitdepth = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1315 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1316 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1317
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1318 /* channels */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1319 case MATROSKA_ID_AUDIOCHANNELS: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1320 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1321 if ((res = ebml_read_uint(matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1322 &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1323 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1324 audiotrack->channels = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1325 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1326 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1327
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1328 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1329 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1330 "Unknown audio track header entry "
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1331 "0x%x - ignoring\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1332 /* pass-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1333
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1334 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1335 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1336 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1337 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1338
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1339 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1340 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1341 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1342 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1343 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1344 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1345 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1346
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1347 /* codec identifier */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1348 case MATROSKA_ID_CODECID: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1349 char *text;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1350 if ((res = ebml_read_ascii(matroska, &id, &text)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1351 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1352 track->codec_id = text;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1353 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1354 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1355
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1356 /* codec private data */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1357 case MATROSKA_ID_CODECPRIVATE: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1358 uint8_t *data;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1359 int size;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1360 if ((res = ebml_read_binary(matroska, &id, &data, &size) < 0))
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1361 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1362 track->codec_priv = data;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1363 track->codec_priv_size = size;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1364 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1365 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1366
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1367 /* name of this track */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1368 case MATROSKA_ID_TRACKNAME: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1369 char *text;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1370 if ((res = ebml_read_utf8(matroska, &id, &text)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1371 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1372 track->name = text;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1373 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1374 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1375
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1376 /* language (matters for audio/subtitles, mostly) */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1377 case MATROSKA_ID_TRACKLANGUAGE: {
2238
98ac80739c58 properly set AVStream.language according to Matroska track header
aurel
parents: 2202
diff changeset
1378 char *text, *end;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1379 if ((res = ebml_read_utf8(matroska, &id, &text)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1380 break;
2238
98ac80739c58 properly set AVStream.language according to Matroska track header
aurel
parents: 2202
diff changeset
1381 if ((end = strchr(text, '-')))
98ac80739c58 properly set AVStream.language according to Matroska track header
aurel
parents: 2202
diff changeset
1382 *end = '\0';
98ac80739c58 properly set AVStream.language according to Matroska track header
aurel
parents: 2202
diff changeset
1383 if (strlen(text) == 3)
98ac80739c58 properly set AVStream.language according to Matroska track header
aurel
parents: 2202
diff changeset
1384 strcpy(track->language, text);
98ac80739c58 properly set AVStream.language according to Matroska track header
aurel
parents: 2202
diff changeset
1385 av_free(text);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1386 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1387 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1388
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1389 /* whether this is actually used */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1390 case MATROSKA_ID_TRACKFLAGENABLED: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1391 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1392 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1393 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1394 if (num)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1395 track->flags |= MATROSKA_TRACK_ENABLED;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1396 else
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1397 track->flags &= ~MATROSKA_TRACK_ENABLED;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1398 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1399 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1400
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1401 /* whether it's the default for this track type */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1402 case MATROSKA_ID_TRACKFLAGDEFAULT: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1403 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1404 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1405 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1406 if (num)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1407 track->flags |= MATROSKA_TRACK_DEFAULT;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1408 else
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1409 track->flags &= ~MATROSKA_TRACK_DEFAULT;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1410 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1411 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1412
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1413 /* lacing (like MPEG, where blocks don't end/start on frame
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1414 * boundaries) */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1415 case MATROSKA_ID_TRACKFLAGLACING: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1416 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1417 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1418 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1419 if (num)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1420 track->flags |= MATROSKA_TRACK_LACING;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1421 else
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1422 track->flags &= ~MATROSKA_TRACK_LACING;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1423 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1424 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1425
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1426 /* default length (in time) of one data block in this track */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1427 case MATROSKA_ID_TRACKDEFAULTDURATION: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1428 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1429 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1430 break;
2389
cde14f83579b Don't pre-scale default_duration to avoid precision loss in fps calculation.
aurel
parents: 2388
diff changeset
1431 track->default_duration = num;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1432 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1433 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1434
3279
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1435 case MATROSKA_ID_TRACKCONTENTENCODINGS: {
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1436 if ((res = ebml_read_master(matroska, &id)) < 0)
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1437 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1438
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1439 while (res == 0) {
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1440 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1441 res = AVERROR(EIO);
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1442 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1443 } else if (matroska->level_up > 0) {
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1444 matroska->level_up--;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1445 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1446 }
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1447
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1448 switch (id) {
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1449 case MATROSKA_ID_TRACKCONTENTENCODING: {
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1450 int encoding_scope = 1;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1451 if ((res = ebml_read_master(matroska, &id)) < 0)
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1452 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1453
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1454 while (res == 0) {
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1455 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1456 res = AVERROR(EIO);
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1457 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1458 } else if (matroska->level_up > 0) {
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1459 matroska->level_up--;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1460 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1461 }
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1462
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1463 switch (id) {
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1464 case MATROSKA_ID_ENCODINGSCOPE: {
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1465 uint64_t num;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1466 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1467 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1468 encoding_scope = num;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1469 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1470 }
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1471
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1472 case MATROSKA_ID_ENCODINGTYPE: {
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1473 uint64_t num;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1474 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1475 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1476 if (num)
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1477 av_log(matroska->ctx, AV_LOG_ERROR,
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1478 "Unsupported encoding type");
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1479 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1480 }
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1481
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1482 case MATROSKA_ID_ENCODINGCOMPRESSION: {
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1483 if ((res = ebml_read_master(matroska, &id)) < 0)
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1484 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1485
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1486 while (res == 0) {
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1487 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1488 res = AVERROR(EIO);
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1489 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1490 } else if (matroska->level_up > 0) {
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1491 matroska->level_up--;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1492 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1493 }
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1494
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1495 switch (id) {
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1496 case MATROSKA_ID_ENCODINGCOMPALGO: {
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1497 uint64_t num;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1498 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1499 break;
3281
a1d98736c15e matroskadec: add support for lzo compressed tracks
aurel
parents: 3280
diff changeset
1500 if (num != MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP &&
3293
d3818f6d7530 matroskadec: add support for zlib compressed tracks
aurel
parents: 3290
diff changeset
1501 #ifdef CONFIG_ZLIB
d3818f6d7530 matroskadec: add support for zlib compressed tracks
aurel
parents: 3290
diff changeset
1502 num != MATROSKA_TRACK_ENCODING_COMP_ZLIB &&
d3818f6d7530 matroskadec: add support for zlib compressed tracks
aurel
parents: 3290
diff changeset
1503 #endif
3298
edabe3db2b6e matroskadec: add support for bzlib compressed tracks
aurel
parents: 3294
diff changeset
1504 #ifdef CONFIG_BZLIB
edabe3db2b6e matroskadec: add support for bzlib compressed tracks
aurel
parents: 3294
diff changeset
1505 num != MATROSKA_TRACK_ENCODING_COMP_BZLIB &&
edabe3db2b6e matroskadec: add support for bzlib compressed tracks
aurel
parents: 3294
diff changeset
1506 #endif
3281
a1d98736c15e matroskadec: add support for lzo compressed tracks
aurel
parents: 3280
diff changeset
1507 num != MATROSKA_TRACK_ENCODING_COMP_LZO)
3279
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1508 av_log(matroska->ctx, AV_LOG_ERROR,
3294
5bfc21e57180 add missing \n in av_log message
aurel
parents: 3293
diff changeset
1509 "Unsupported compression algo\n");
3279
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1510 track->encoding_algo = num;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1511 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1512 }
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1513
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1514 case MATROSKA_ID_ENCODINGCOMPSETTINGS: {
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1515 uint8_t *data;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1516 int size;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1517 if ((res = ebml_read_binary(matroska, &id, &data, &size) < 0))
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1518 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1519 track->encoding_settings = data;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1520 track->encoding_settings_len = size;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1521 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1522 }
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1523
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1524 default:
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1525 av_log(matroska->ctx, AV_LOG_INFO,
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1526 "Unknown compression header entry "
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1527 "0x%x - ignoring\n", id);
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1528 /* pass-through */
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1529
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1530 case EBML_ID_VOID:
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1531 res = ebml_read_skip(matroska);
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1532 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1533 }
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1534
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1535 if (matroska->level_up) {
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1536 matroska->level_up--;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1537 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1538 }
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1539 }
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1540 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1541 }
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1542
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1543 default:
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1544 av_log(matroska->ctx, AV_LOG_INFO,
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1545 "Unknown content encoding header entry "
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1546 "0x%x - ignoring\n", id);
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1547 /* pass-through */
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1548
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1549 case EBML_ID_VOID:
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1550 res = ebml_read_skip(matroska);
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1551 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1552 }
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1553
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1554 if (matroska->level_up) {
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1555 matroska->level_up--;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1556 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1557 }
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1558 }
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1559
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1560 track->encoding_scope = encoding_scope;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1561 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1562 }
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1563
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1564 default:
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1565 av_log(matroska->ctx, AV_LOG_INFO,
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1566 "Unknown content encodings header entry "
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1567 "0x%x - ignoring\n", id);
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1568 /* pass-through */
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1569
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1570 case EBML_ID_VOID:
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1571 res = ebml_read_skip(matroska);
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1572 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1573 }
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1574
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1575 if (matroska->level_up) {
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1576 matroska->level_up--;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1577 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1578 }
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1579 }
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1580 break;
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1581 }
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
1582
3408
da09478c97ce matroskadec: read TrackTimecodeScale and set timebase accordingly
aurel
parents: 3407
diff changeset
1583 case MATROSKA_ID_TRACKTIMECODESCALE: {
da09478c97ce matroskadec: read TrackTimecodeScale and set timebase accordingly
aurel
parents: 3407
diff changeset
1584 double num;
da09478c97ce matroskadec: read TrackTimecodeScale and set timebase accordingly
aurel
parents: 3407
diff changeset
1585 if ((res = ebml_read_float(matroska, &id, &num)) < 0)
da09478c97ce matroskadec: read TrackTimecodeScale and set timebase accordingly
aurel
parents: 3407
diff changeset
1586 break;
da09478c97ce matroskadec: read TrackTimecodeScale and set timebase accordingly
aurel
parents: 3407
diff changeset
1587 track->time_scale = num;
da09478c97ce matroskadec: read TrackTimecodeScale and set timebase accordingly
aurel
parents: 3407
diff changeset
1588 break;
da09478c97ce matroskadec: read TrackTimecodeScale and set timebase accordingly
aurel
parents: 3407
diff changeset
1589 }
da09478c97ce matroskadec: read TrackTimecodeScale and set timebase accordingly
aurel
parents: 3407
diff changeset
1590
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1591 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1592 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1593 "Unknown track header entry 0x%x - ignoring\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1594 /* pass-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1595
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1596 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1597 /* we ignore these because they're nothing useful. */
3407
ffd297928ed8 matroskadec: silently discard some element ID that we don't care about
aurel
parents: 3391
diff changeset
1598 case MATROSKA_ID_TRACKFLAGFORCED:
3477
8adaa9258dba matroskadec: remove some useless code
aurel
parents: 3462
diff changeset
1599 case MATROSKA_ID_CODECNAME:
3407
ffd297928ed8 matroskadec: silently discard some element ID that we don't care about
aurel
parents: 3391
diff changeset
1600 case MATROSKA_ID_CODECDECODEALL:
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1601 case MATROSKA_ID_CODECINFOURL:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1602 case MATROSKA_ID_CODECDOWNLOADURL:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1603 case MATROSKA_ID_TRACKMINCACHE:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1604 case MATROSKA_ID_TRACKMAXCACHE:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1605 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1606 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1607 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1608
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1609 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1610 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1611 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1612 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1613 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1614
3495
ed5686879cdb matroskadec: decode track private data if needed
aurel
parents: 3494
diff changeset
1615 if (track->codec_priv_size && track->encoding_scope & 2) {
ed5686879cdb matroskadec: decode track private data if needed
aurel
parents: 3494
diff changeset
1616 uint8_t *orig_priv = track->codec_priv;
ed5686879cdb matroskadec: decode track private data if needed
aurel
parents: 3494
diff changeset
1617 int offset = matroska_decode_buffer(&track->codec_priv,
ed5686879cdb matroskadec: decode track private data if needed
aurel
parents: 3494
diff changeset
1618 &track->codec_priv_size, track);
ed5686879cdb matroskadec: decode track private data if needed
aurel
parents: 3494
diff changeset
1619 if (offset > 0) {
ed5686879cdb matroskadec: decode track private data if needed
aurel
parents: 3494
diff changeset
1620 track->codec_priv = av_malloc(track->codec_priv_size + offset);
ed5686879cdb matroskadec: decode track private data if needed
aurel
parents: 3494
diff changeset
1621 memcpy(track->codec_priv, track->encoding_settings, offset);
ed5686879cdb matroskadec: decode track private data if needed
aurel
parents: 3494
diff changeset
1622 memcpy(track->codec_priv+offset, orig_priv, track->codec_priv_size);
ed5686879cdb matroskadec: decode track private data if needed
aurel
parents: 3494
diff changeset
1623 track->codec_priv_size += offset;
ed5686879cdb matroskadec: decode track private data if needed
aurel
parents: 3494
diff changeset
1624 av_free(orig_priv);
ed5686879cdb matroskadec: decode track private data if needed
aurel
parents: 3494
diff changeset
1625 } else if (!offset) {
ed5686879cdb matroskadec: decode track private data if needed
aurel
parents: 3494
diff changeset
1626 av_free(orig_priv);
ed5686879cdb matroskadec: decode track private data if needed
aurel
parents: 3494
diff changeset
1627 } else
ed5686879cdb matroskadec: decode track private data if needed
aurel
parents: 3494
diff changeset
1628 av_log(matroska->ctx, AV_LOG_ERROR,
ed5686879cdb matroskadec: decode track private data if needed
aurel
parents: 3494
diff changeset
1629 "Failed to decode codec private data\n");
ed5686879cdb matroskadec: decode track private data if needed
aurel
parents: 3494
diff changeset
1630 }
ed5686879cdb matroskadec: decode track private data if needed
aurel
parents: 3494
diff changeset
1631
3414
703f452f00f1 reorganize matroska_add_stream() to fix potential mem leak and buffer overflow
aurel
parents: 3413
diff changeset
1632 if (track->type && matroska->num_tracks < ARRAY_SIZE(matroska->tracks)) {
703f452f00f1 reorganize matroska_add_stream() to fix potential mem leak and buffer overflow
aurel
parents: 3413
diff changeset
1633 matroska->tracks[matroska->num_tracks++] = track;
703f452f00f1 reorganize matroska_add_stream() to fix potential mem leak and buffer overflow
aurel
parents: 3413
diff changeset
1634 } else {
703f452f00f1 reorganize matroska_add_stream() to fix potential mem leak and buffer overflow
aurel
parents: 3413
diff changeset
1635 av_free(track);
703f452f00f1 reorganize matroska_add_stream() to fix potential mem leak and buffer overflow
aurel
parents: 3413
diff changeset
1636 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1637 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1638 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1639
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1640 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1641 matroska_parse_tracks (MatroskaDemuxContext *matroska)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1642 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1643 int res = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1644 uint32_t id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1645
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1646 av_log(matroska->ctx, AV_LOG_DEBUG, "parsing tracks...\n");
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1647
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1648 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1649 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
1650 res = AVERROR(EIO);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1651 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1652 } else if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1653 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1654 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1655 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1656
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1657 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1658 /* one track within the "all-tracks" header */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1659 case MATROSKA_ID_TRACKENTRY:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1660 res = matroska_add_stream(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1661 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1662
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1663 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1664 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1665 "Unknown entry 0x%x in track header\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1666 /* fall-through */
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 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1669 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1670 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1671 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1672
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1673 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1674 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1675 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1676 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1677 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1678
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1679 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1680 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1681
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1682 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1683 matroska_parse_index (MatroskaDemuxContext *matroska)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1684 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1685 int res = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1686 uint32_t id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1687 MatroskaDemuxIndex idx;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1688
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1689 av_log(matroska->ctx, AV_LOG_DEBUG, "parsing index...\n");
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1690
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1691 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1692 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
1693 res = AVERROR(EIO);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1694 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1695 } else if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1696 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1697 break;
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
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1700 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1701 /* one single index entry ('point') */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1702 case MATROSKA_ID_POINTENTRY:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1703 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1704 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1705
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1706 /* in the end, we hope to fill one entry with a
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1707 * timestamp, a file position and a tracknum */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1708 idx.pos = (uint64_t) -1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1709 idx.time = (uint64_t) -1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1710 idx.track = (uint16_t) -1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1711
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1712 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1713 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
1714 res = AVERROR(EIO);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1715 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1716 } else if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1717 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1718 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1719 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1720
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1721 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1722 /* one single index entry ('point') */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1723 case MATROSKA_ID_CUETIME: {
1332
7474cc6383d4 fix some signedness warnings
mru
parents: 1172
diff changeset
1724 uint64_t time;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1725 if ((res = ebml_read_uint(matroska, &id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1726 &time)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1727 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1728 idx.time = time * matroska->time_scale;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1729 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1730 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1731
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 883
diff changeset
1732 /* position in the file + track to which it
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1733 * belongs */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1734 case MATROSKA_ID_CUETRACKPOSITION:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1735 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1736 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1737
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1738 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1739 if (!(id = ebml_peek_id (matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1740 &matroska->level_up))) {
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
1741 res = AVERROR(EIO);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1742 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1743 } else if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1744 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1745 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1746 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1747
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1748 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1749 /* track number */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1750 case MATROSKA_ID_CUETRACK: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1751 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1752 if ((res = ebml_read_uint(matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1753 &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1754 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1755 idx.track = num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1756 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1757 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1758
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1759 /* position in file */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1760 case MATROSKA_ID_CUECLUSTERPOSITION: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1761 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1762 if ((res = ebml_read_uint(matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1763 &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1764 break;
2010
7190252e8ad0 cluster position is relative to segment_start
aurel
parents: 2009
diff changeset
1765 idx.pos = num+matroska->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
1766 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1767 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1768
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1769 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1770 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1771 "Unknown entry 0x%x in "
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1772 "CuesTrackPositions\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1773 /* fall-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1774
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1775 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1776 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1777 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1778 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1779
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1780 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1781 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1782 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1783 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1784 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1785
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1786 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1787
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1788 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1789 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1790 "Unknown entry 0x%x in cuespoint "
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1791 "index\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1792 /* fall-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1793
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1794 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1795 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1796 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1797 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1798
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1799 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1800 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1801 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1802 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1803 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1804
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1805 /* so let's see if we got what we wanted */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1806 if (idx.pos != (uint64_t) -1 &&
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1807 idx.time != (uint64_t) -1 &&
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1808 idx.track != (uint16_t) -1) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1809 if (matroska->num_indexes % 32 == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1810 /* re-allocate bigger index */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1811 matroska->index =
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1812 av_realloc(matroska->index,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1813 (matroska->num_indexes + 32) *
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1814 sizeof(MatroskaDemuxIndex));
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1815 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1816 matroska->index[matroska->num_indexes] = idx;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1817 matroska->num_indexes++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1818 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1819 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1820
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1821 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1822 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1823 "Unknown entry 0x%x in cues header\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1824 /* fall-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1825
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1826 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1827 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1828 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1829 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1830
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1831 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1832 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1833 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1834 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1835 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1836
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1837 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1838 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1839
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1840 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1841 matroska_parse_metadata (MatroskaDemuxContext *matroska)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1842 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1843 int res = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1844 uint32_t id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1845
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1846 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1847 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
1848 res = AVERROR(EIO);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1849 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1850 } else if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1851 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1852 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1853 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1854
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1855 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1856 /* Hm, this is unsupported... */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1857 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1858 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1859 "Unknown entry 0x%x in metadata header\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1860 /* fall-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1861
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1862 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1863 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1864 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1865 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1866
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1867 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1868 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1869 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1870 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1871 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1872
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1873 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1874 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1875
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1876 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1877 matroska_parse_seekhead (MatroskaDemuxContext *matroska)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1878 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1879 int res = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1880 uint32_t id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1881
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1882 av_log(matroska->ctx, AV_LOG_DEBUG, "parsing seekhead...\n");
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1883
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1884 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1885 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
1886 res = AVERROR(EIO);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1887 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1888 } else if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1889 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1890 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1891 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1892
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1893 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1894 case MATROSKA_ID_SEEKENTRY: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1895 uint32_t seek_id = 0, peek_id_cache = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1896 uint64_t seek_pos = (uint64_t) -1, t;
3425
36cdada322a0 matroskadec: don't remove dummy level when none was added
aurel
parents: 3424
diff changeset
1897 int dummy_level = 0;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1898
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1899 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1900 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1901
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1902 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1903 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
1904 res = AVERROR(EIO);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1905 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1906 } else if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1907 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1908 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1909 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1910
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1911 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1912 case MATROSKA_ID_SEEKID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1913 res = ebml_read_uint(matroska, &id, &t);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1914 seek_id = t;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1915 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1916
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1917 case MATROSKA_ID_SEEKPOSITION:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1918 res = ebml_read_uint(matroska, &id, &seek_pos);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1919 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1920
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1921 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1922 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1923 "Unknown seekhead ID 0x%x\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1924 /* fall-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1925
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1926 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1927 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1928 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1929 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1930
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1931 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1932 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1933 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1934 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1935 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1936
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1937 if (!seek_id || seek_pos == (uint64_t) -1) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1938 av_log(matroska->ctx, AV_LOG_INFO,
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
1939 "Incomplete seekhead entry (0x%x/%"PRIu64")\n",
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1940 seek_id, seek_pos);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1941 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1942 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1943
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1944 switch (seek_id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1945 case MATROSKA_ID_CUES:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1946 case MATROSKA_ID_TAGS: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1947 uint32_t level_up = matroska->level_up;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1948 offset_t before_pos;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1949 uint64_t length;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1950 MatroskaLevel level;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1951
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1952 /* remember the peeked ID and the current position */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1953 peek_id_cache = matroska->peek_id;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
1954 before_pos = url_ftell(matroska->ctx->pb);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1955
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1956 /* seek */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1957 if ((res = ebml_read_seek(matroska, seek_pos +
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1958 matroska->segment_start)) < 0)
3280
30bf0c9f940d matroskadec: fail gracefully when seeking don't work
aurel
parents: 3279
diff changeset
1959 goto finish;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1960
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1961 /* we don't want to lose our seekhead level, so we add
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1962 * a dummy. This is a crude hack. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1963 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
1964 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1965 "Max EBML element depth (%d) reached, "
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1966 "cannot parse further.\n", EBML_MAX_DEPTH);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1967 return AVERROR_UNKNOWN;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1968 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 883
diff changeset
1969
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1970 level.start = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1971 level.length = (uint64_t)-1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1972 matroska->levels[matroska->num_levels] = level;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1973 matroska->num_levels++;
3425
36cdada322a0 matroskadec: don't remove dummy level when none was added
aurel
parents: 3424
diff changeset
1974 dummy_level = 1;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1975
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1976 /* check ID */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1977 if (!(id = ebml_peek_id (matroska,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1978 &matroska->level_up)))
1490
1bf0132b9dff Allows playback of truncated matroska files.
aurel
parents: 1476
diff changeset
1979 goto finish;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1980 if (id != seek_id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1981 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1982 "We looked for ID=0x%x but got "
881
91dcb9da9be6 use PRIxN, %zd, %td formats where needed
mru
parents: 824
diff changeset
1983 "ID=0x%x (pos=%"PRIu64")",
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1984 seek_id, id, seek_pos +
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1985 matroska->segment_start);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1986 goto finish;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1987 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1988
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1989 /* read master + parse */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1990 if ((res = ebml_read_master(matroska, &id)) < 0)
1490
1bf0132b9dff Allows playback of truncated matroska files.
aurel
parents: 1476
diff changeset
1991 goto finish;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1992 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1993 case MATROSKA_ID_CUES:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1994 if (!(res = matroska_parse_index(matroska)) ||
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
1995 url_feof(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
1996 matroska->index_parsed = 1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1997 res = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1998 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
1999 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2000 case MATROSKA_ID_TAGS:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2001 if (!(res = matroska_parse_metadata(matroska)) ||
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
2002 url_feof(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
2003 matroska->metadata_parsed = 1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2004 res = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2005 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2006 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2007 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2008
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2009 finish:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2010 /* remove dummy level */
3425
36cdada322a0 matroskadec: don't remove dummy level when none was added
aurel
parents: 3424
diff changeset
2011 if (dummy_level)
3426
f773e369f158 cosmetics: indentation
aurel
parents: 3425
diff changeset
2012 while (matroska->num_levels) {
f773e369f158 cosmetics: indentation
aurel
parents: 3425
diff changeset
2013 matroska->num_levels--;
f773e369f158 cosmetics: indentation
aurel
parents: 3425
diff changeset
2014 length =
f773e369f158 cosmetics: indentation
aurel
parents: 3425
diff changeset
2015 matroska->levels[matroska->num_levels].length;
f773e369f158 cosmetics: indentation
aurel
parents: 3425
diff changeset
2016 if (length == (uint64_t)-1)
f773e369f158 cosmetics: indentation
aurel
parents: 3425
diff changeset
2017 break;
f773e369f158 cosmetics: indentation
aurel
parents: 3425
diff changeset
2018 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2019
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2020 /* seek back */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2021 if ((res = ebml_read_seek(matroska, before_pos)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2022 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2023 matroska->peek_id = peek_id_cache;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2024 matroska->level_up = level_up;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2025 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2026 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2027
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2028 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2029 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2030 "Ignoring seekhead entry for ID=0x%x\n",
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2031 seek_id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2032 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2033 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2034
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2035 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2036 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2037
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2038 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2039 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2040 "Unknown seekhead ID 0x%x\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2041 /* fall-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2042
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2043 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2044 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2045 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2046 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2047
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2048 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2049 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2050 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2051 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2052 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2053
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2054 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2055 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2056
2973
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2057 static int
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2058 matroska_parse_attachments(AVFormatContext *s)
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2059 {
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2060 MatroskaDemuxContext *matroska = s->priv_data;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2061 int res = 0;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2062 uint32_t id;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2063
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2064 av_log(matroska->ctx, AV_LOG_DEBUG, "parsing attachments...\n");
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2065
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2066 while (res == 0) {
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2067 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2068 res = AVERROR(EIO);
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2069 break;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2070 } else if (matroska->level_up) {
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2071 matroska->level_up--;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2072 break;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2073 }
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2074
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2075 switch (id) {
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2076 case MATROSKA_ID_ATTACHEDFILE: {
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2077 char* name = NULL;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2078 char* mime = NULL;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2079 uint8_t* data = NULL;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2080 int i, data_size = 0;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2081 AVStream *st;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2082
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2083 if ((res = ebml_read_master(matroska, &id)) < 0)
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2084 break;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2085
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2086 while (res == 0) {
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2087 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2088 res = AVERROR(EIO);
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2089 break;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2090 } else if (matroska->level_up) {
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2091 matroska->level_up--;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2092 break;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2093 }
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2094
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2095 switch (id) {
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2096 case MATROSKA_ID_FILENAME:
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2097 res = ebml_read_utf8 (matroska, &id, &name);
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2098 break;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2099
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2100 case MATROSKA_ID_FILEMIMETYPE:
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2101 res = ebml_read_ascii (matroska, &id, &mime);
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2102 break;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2103
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2104 case MATROSKA_ID_FILEDATA:
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2105 res = ebml_read_binary(matroska, &id, &data, &data_size);
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2106 break;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2107
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2108 default:
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2109 av_log(matroska->ctx, AV_LOG_INFO,
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2110 "Unknown attachedfile ID 0x%x\n", id);
3407
ffd297928ed8 matroskadec: silently discard some element ID that we don't care about
aurel
parents: 3391
diff changeset
2111 case MATROSKA_ID_FILEUID:
2973
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2112 case EBML_ID_VOID:
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2113 res = ebml_read_skip(matroska);
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2114 break;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2115 }
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2116
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2117 if (matroska->level_up) {
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2118 matroska->level_up--;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2119 break;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2120 }
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2121 }
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2122
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2123 if (!(name && mime && data && data_size > 0)) {
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2124 av_log(matroska->ctx, AV_LOG_ERROR, "incomplete attachment\n");
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2125 break;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2126 }
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2127
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2128 st = av_new_stream(s, matroska->num_streams++);
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2129 if (st == NULL)
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2130 return AVERROR(ENOMEM);
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2131 st->filename = av_strdup(name);
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2132 st->codec->codec_id = CODEC_ID_NONE;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2133 st->codec->codec_type = CODEC_TYPE_ATTACHMENT;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2134 st->codec->extradata = av_malloc(data_size);
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2135 if(st->codec->extradata == NULL)
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2136 return AVERROR(ENOMEM);
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2137 st->codec->extradata_size = data_size;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2138 memcpy(st->codec->extradata, data, data_size);
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2139
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2140 for (i=0; ff_mkv_mime_tags[i].id != CODEC_ID_NONE; i++) {
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2141 if (!strncmp(ff_mkv_mime_tags[i].str, mime,
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2142 strlen(ff_mkv_mime_tags[i].str))) {
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2143 st->codec->codec_id = ff_mkv_mime_tags[i].id;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2144 break;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2145 }
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2146 }
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2147
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2148 av_log(matroska->ctx, AV_LOG_DEBUG, "new attachment: %s, %s, size %d \n", name, mime, data_size);
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2149 break;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2150 }
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2151
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2152 default:
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2153 av_log(matroska->ctx, AV_LOG_INFO,
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2154 "Unknown attachments ID 0x%x\n", id);
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2155 /* fall-through */
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2156
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2157 case EBML_ID_VOID:
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2158 res = ebml_read_skip(matroska);
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2159 break;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2160 }
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2161
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2162 if (matroska->level_up) {
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2163 matroska->level_up--;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2164 break;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2165 }
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2166 }
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2167
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2168 return res;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2169 }
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2170
3315
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2171 static int
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2172 matroska_parse_chapters(AVFormatContext *s)
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2173 {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2174 MatroskaDemuxContext *matroska = s->priv_data;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2175 int res = 0;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2176 uint32_t id;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2177
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2178 av_log(s, AV_LOG_DEBUG, "parsing chapters...\n");
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2179
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2180 while (res == 0) {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2181 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2182 res = AVERROR(EIO);
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2183 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2184 } else if (matroska->level_up) {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2185 matroska->level_up--;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2186 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2187 }
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2188
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2189 switch (id) {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2190 case MATROSKA_ID_EDITIONENTRY: {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2191 uint64_t end = AV_NOPTS_VALUE, start = AV_NOPTS_VALUE;
3323
4bf98e198eec Add id to AVChapter, untested (where do i find matroska files with chapters?).
michael
parents: 3319
diff changeset
2192 int64_t uid= -1;
3315
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2193 char* title = NULL;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2194 /* if there is more than one chapter edition
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2195 we take only the first one */
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2196 if(s->chapters) {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2197 ebml_read_skip(matroska);
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2198 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2199 }
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2200
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2201 if ((res = ebml_read_master(matroska, &id)) < 0)
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2202 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2203
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2204 while (res == 0) {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2205 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2206 res = AVERROR(EIO);
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2207 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2208 } else if (matroska->level_up) {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2209 matroska->level_up--;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2210 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2211 }
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2212
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2213 switch (id) {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2214 case MATROSKA_ID_CHAPTERATOM:
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2215 if ((res = ebml_read_master(matroska, &id)) < 0)
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2216 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2217
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2218 while (res == 0) {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2219 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2220 res = AVERROR(EIO);
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2221 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2222 } else if (matroska->level_up) {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2223 matroska->level_up--;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2224 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2225 }
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2226
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2227 switch (id) {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2228 case MATROSKA_ID_CHAPTERTIMEEND:
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2229 res = ebml_read_uint(matroska, &id, &end);
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2230 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2231
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2232 case MATROSKA_ID_CHAPTERTIMESTART:
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2233 res = ebml_read_uint(matroska, &id, &start);
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2234 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2235
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2236 case MATROSKA_ID_CHAPTERDISPLAY:
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2237 if ((res = ebml_read_master(matroska, &id)) < 0)
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2238 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2239
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2240 while (res == 0) {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2241 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2242 res = AVERROR(EIO);
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2243 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2244 } else if (matroska->level_up) {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2245 matroska->level_up--;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2246 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2247 }
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2248
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2249 switch (id) {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2250 case MATROSKA_ID_CHAPSTRING:
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2251 res = ebml_read_utf8(matroska, &id, &title);
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2252 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2253
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2254 default:
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2255 av_log(s, AV_LOG_INFO, "Ignoring unknown Chapter display ID 0x%x\n", id);
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2256 case EBML_ID_VOID:
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2257 res = ebml_read_skip(matroska);
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2258 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2259 }
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2260
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2261 if (matroska->level_up) {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2262 matroska->level_up--;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2263 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2264 }
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2265 }
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2266 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2267
3323
4bf98e198eec Add id to AVChapter, untested (where do i find matroska files with chapters?).
michael
parents: 3319
diff changeset
2268 case MATROSKA_ID_CHAPTERUID:
4bf98e198eec Add id to AVChapter, untested (where do i find matroska files with chapters?).
michael
parents: 3319
diff changeset
2269 res = ebml_read_uint(matroska, &id, &uid);
4bf98e198eec Add id to AVChapter, untested (where do i find matroska files with chapters?).
michael
parents: 3319
diff changeset
2270 break;
3315
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2271 default:
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2272 av_log(s, AV_LOG_INFO, "Ignoring unknown Chapter atom ID 0x%x\n", id);
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2273 case MATROSKA_ID_CHAPTERFLAGHIDDEN:
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2274 case EBML_ID_VOID:
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2275 res = ebml_read_skip(matroska);
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2276 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2277 }
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2278
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2279 if (matroska->level_up) {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2280 matroska->level_up--;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2281 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2282 }
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2283 }
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2284
3323
4bf98e198eec Add id to AVChapter, untested (where do i find matroska files with chapters?).
michael
parents: 3319
diff changeset
2285 if (start != AV_NOPTS_VALUE && uid != -1) {
3334
7a823a401282 Pass time_base as argument to new_chapter() as well.
michael
parents: 3330
diff changeset
2286 if(!ff_new_chapter(s, uid, (AVRational){1, 1000000000}, start, end, title))
3330
374e74567a4e Make ff_new_chapter() return AVChapter instead of int so its consistant with
michael
parents: 3323
diff changeset
2287 res= AVERROR(ENOMEM);
3316
842a6746532e matroskadec: allows inserting chapters with unspecified end
aurel
parents: 3315
diff changeset
2288 }
3315
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2289 av_free(title);
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2290 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2291
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2292 default:
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2293 av_log(s, AV_LOG_INFO, "Ignoring unknown Edition entry ID 0x%x\n", id);
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2294 case MATROSKA_ID_EDITIONUID:
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2295 case MATROSKA_ID_EDITIONFLAGHIDDEN:
3407
ffd297928ed8 matroskadec: silently discard some element ID that we don't care about
aurel
parents: 3391
diff changeset
2296 case MATROSKA_ID_EDITIONFLAGDEFAULT:
3315
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2297 case EBML_ID_VOID:
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2298 res = ebml_read_skip(matroska);
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2299 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2300 }
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2301
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2302
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2303 if (matroska->level_up) {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2304 matroska->level_up--;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2305 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2306 }
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2307 }
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2308 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2309 }
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2310
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2311 default:
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2312 av_log(s, AV_LOG_INFO, "Expected an Edition entry (0x%x), but found 0x%x\n", MATROSKA_ID_EDITIONENTRY, id);
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2313 case EBML_ID_VOID:
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2314 res = ebml_read_skip(matroska);
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2315 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2316 }
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2317
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2318 if (matroska->level_up) {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2319 matroska->level_up--;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2320 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2321 }
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2322 }
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2323
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2324 return res;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2325 }
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2326
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2327 static int
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2328 matroska_aac_profile (char *codec_id)
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2329 {
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2330 static const char *aac_profiles[] = {
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2331 "MAIN", "LC", "SSR"
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2332 };
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2333 int profile;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2334
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2335 for (profile=0; profile<ARRAY_SIZE(aac_profiles); profile++)
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2336 if (strstr(codec_id, aac_profiles[profile]))
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2337 break;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2338 return profile + 1;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2339 }
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2340
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2341 static int
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2342 matroska_aac_sri (int samplerate)
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2343 {
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2344 int sri;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2345
3201
1a16b069daca use common aac sample rate tables
aurel
parents: 3199
diff changeset
2346 for (sri=0; sri<ARRAY_SIZE(ff_mpeg4audio_sample_rates); sri++)
1a16b069daca use common aac sample rate tables
aurel
parents: 3199
diff changeset
2347 if (ff_mpeg4audio_sample_rates[sri] == samplerate)
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2348 break;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2349 return sri;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2350 }
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2351
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2352 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2353 matroska_read_header (AVFormatContext *s,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2354 AVFormatParameters *ap)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2355 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2356 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
2357 char *doctype;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2358 int version, last_level, res = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2359 uint32_t id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2360
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2361 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
2362
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2363 /* First read the EBML header. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2364 doctype = NULL;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2365 if ((res = ebml_read_header(matroska, &doctype, &version)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2366 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2367 if ((doctype == NULL) || strcmp(doctype, "matroska")) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2368 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
2369 "Wrong EBML doctype ('%s' != 'matroska').\n",
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2370 doctype ? doctype : "(none)");
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2371 if (doctype)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2372 av_free(doctype);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2373 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
2374 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2375 av_free(doctype);
1831
bdca904db5e5 add support for simple blocks (ie. matroska v2)
aurel
parents: 1830
diff changeset
2376 if (version > 2) {
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2377 av_log(matroska->ctx, AV_LOG_ERROR,
1831
bdca904db5e5 add support for simple blocks (ie. matroska v2)
aurel
parents: 1830
diff changeset
2378 "Matroska demuxer version 2 too old for file version %d\n",
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2379 version);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2380 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
2381 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2382
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2383 /* The next thing is a segment. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2384 while (1) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2385 if (!(id = ebml_peek_id(matroska, &last_level)))
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
2386 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
2387 if (id == MATROSKA_ID_SEGMENT)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2388 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2389
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2390 /* oi! */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2391 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2392 "Expected a Segment ID (0x%x), but received 0x%x!\n",
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2393 MATROSKA_ID_SEGMENT, id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2394 if ((res = ebml_read_skip(matroska)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2395 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2396 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2397
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2398 /* We now have a Matroska segment.
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2399 * Seeks are from the beginning of the segment,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2400 * after the segment ID/length. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2401 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2402 return res;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
2403 matroska->segment_start = url_ftell(s->pb);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2404
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2405 matroska->time_scale = 1000000;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2406 /* we've found our segment, start reading the different contents in here */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2407 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2408 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
2409 res = AVERROR(EIO);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2410 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2411 } else if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2412 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2413 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2414 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2415
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2416 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2417 /* stream info */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2418 case MATROSKA_ID_INFO: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2419 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2420 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2421 res = matroska_parse_info(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2422 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2423 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2424
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2425 /* track info headers */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2426 case MATROSKA_ID_TRACKS: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2427 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2428 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2429 res = matroska_parse_tracks(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2430 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2431 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2432
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2433 /* stream index */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2434 case MATROSKA_ID_CUES: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2435 if (!matroska->index_parsed) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2436 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2437 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2438 res = matroska_parse_index(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2439 } else
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2440 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2441 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2442 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2443
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2444 /* metadata */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2445 case MATROSKA_ID_TAGS: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2446 if (!matroska->metadata_parsed) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2447 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2448 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2449 res = matroska_parse_metadata(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2450 } else
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2451 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2452 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2453 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2454
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2455 /* file index (if seekable, seek to Cues/Tags to parse it) */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2456 case MATROSKA_ID_SEEKHEAD: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2457 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2458 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2459 res = matroska_parse_seekhead(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2460 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2461 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2462
2973
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2463 case MATROSKA_ID_ATTACHMENTS: {
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2464 if ((res = ebml_read_master(matroska, &id)) < 0)
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2465 break;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2466 res = matroska_parse_attachments(s);
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2467 break;
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2468 }
910ac68ab3b5 Add support for Matroska attachments.
aurel
parents: 2905
diff changeset
2469
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2470 case MATROSKA_ID_CLUSTER: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2471 /* Do not read the master - this will be done in the next
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2472 * call to matroska_read_packet. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2473 res = 1;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2474 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2475 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2476
3315
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2477 case MATROSKA_ID_CHAPTERS: {
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2478 if ((res = ebml_read_master(matroska, &id)) < 0)
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2479 return res;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2480 res = matroska_parse_chapters(s);
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2481 break;
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2482 }
22ba37584545 demux chapters out of matroska
aurel
parents: 3298
diff changeset
2483
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2484 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2485 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2486 "Unknown matroska file header ID 0x%x\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2487 /* fall-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2488
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2489 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2490 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2491 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2492 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2493
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2494 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2495 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2496 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2497 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2498 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2499
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2500 /* Have we found a cluster? */
1465
1dccf2603e1d Better way to detect cluster (fix files encoded with Haali's muxer).
aurel
parents: 1459
diff changeset
2501 if (ebml_peek_id(matroska, NULL) == MATROSKA_ID_CLUSTER) {
1024
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
2502 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
2503 MatroskaTrack *track;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2504 AVStream *st;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2505
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2506 for (i = 0; i < matroska->num_tracks; i++) {
1455
e0e7ac1b8601 Ensure codec_id = CODEC_ID_NONE for unknown codecs (don't reuse previous one).
aurel
parents: 1454
diff changeset
2507 enum CodecID codec_id = CODEC_ID_NONE;
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2508 uint8_t *extradata = NULL;
1024
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
2509 int extradata_size = 0;
1531
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
2510 int extradata_offset = 0;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2511 track = matroska->tracks[i];
2201
c514ebfeec49 drop blocks which are part of unsupported tracks
aurel
parents: 2188
diff changeset
2512 track->stream_index = -1;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2513
2244
93ffcd9d826f add support for Matroska subtitle tracks
aurel
parents: 2239
diff changeset
2514 /* Apply some sanity checks. */
93ffcd9d826f add support for Matroska subtitle tracks
aurel
parents: 2239
diff changeset
2515 if (track->codec_id == NULL)
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2516 continue;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2517
2905
616fb87724b5 Make ff_mkv_codec_tags lie entirely in .rodata section.
aurel
parents: 2881
diff changeset
2518 for(j=0; ff_mkv_codec_tags[j].id != CODEC_ID_NONE; j++){
2142
3aa1f0f698de split some common code from the mkv demuxer that will be useful to the muxer
aurel
parents: 2023
diff changeset
2519 if(!strncmp(ff_mkv_codec_tags[j].str, track->codec_id,
3aa1f0f698de split some common code from the mkv demuxer that will be useful to the muxer
aurel
parents: 2023
diff changeset
2520 strlen(ff_mkv_codec_tags[j].str))){
3aa1f0f698de split some common code from the mkv demuxer that will be useful to the muxer
aurel
parents: 2023
diff changeset
2521 codec_id= ff_mkv_codec_tags[j].id;
1024
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
2522 break;
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
2523 }
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
2524 }
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
2525
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2526 /* Set the FourCC from the CodecID. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2527 /* This is the MS compatibility mode which stores a
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2528 * BITMAPINFOHEADER in the CodecPrivate. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2529 if (!strcmp(track->codec_id,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2530 MATROSKA_CODEC_ID_VIDEO_VFW_FOURCC) &&
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2531 (track->codec_priv_size >= 40) &&
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2532 (track->codec_priv != NULL)) {
2185
7dd08e645d92 use intreadwrite functions in matroskadec
aurel
parents: 2175
diff changeset
2533 MatroskaVideoTrack *vtrack = (MatroskaVideoTrack *) track;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2534
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2535 /* Offset of biCompression. Stored in LE. */
2185
7dd08e645d92 use intreadwrite functions in matroskadec
aurel
parents: 2175
diff changeset
2536 vtrack->fourcc = AV_RL32(track->codec_priv + 16);
7dd08e645d92 use intreadwrite functions in matroskadec
aurel
parents: 2175
diff changeset
2537 codec_id = codec_get_id(codec_bmp_tags, vtrack->fourcc);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2538
1024
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
2539 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2540
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2541 /* This is the MS compatibility mode which stores a
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2542 * WAVEFORMATEX in the CodecPrivate. */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 883
diff changeset
2543 else if (!strcmp(track->codec_id,
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2544 MATROSKA_CODEC_ID_AUDIO_ACM) &&
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2545 (track->codec_priv_size >= 18) &&
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2546 (track->codec_priv != NULL)) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2547 uint16_t tag;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2548
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2549 /* Offset of wFormatTag. Stored in LE. */
2185
7dd08e645d92 use intreadwrite functions in matroskadec
aurel
parents: 2175
diff changeset
2550 tag = AV_RL16(track->codec_priv);
1897
abbc781d608a use codec_get_id() instead of deprecated codec_get_[bmp/wav]_id()
aurel
parents: 1832
diff changeset
2551 codec_id = codec_get_id(codec_wav_tags, tag);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2552
1024
144729fd2d6c cleanup codec_id mapping (untested)
michael
parents: 1021
diff changeset
2553 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2554
3601
c0955bfc27be matroska: add support for V_QUICKTIME track type
aurel
parents: 3495
diff changeset
2555 if (!strcmp(track->codec_id, "V_QUICKTIME") &&
c0955bfc27be matroska: add support for V_QUICKTIME track type
aurel
parents: 3495
diff changeset
2556 (track->codec_priv_size >= 86) &&
c0955bfc27be matroska: add support for V_QUICKTIME track type
aurel
parents: 3495
diff changeset
2557 (track->codec_priv != NULL)) {
c0955bfc27be matroska: add support for V_QUICKTIME track type
aurel
parents: 3495
diff changeset
2558 MatroskaVideoTrack *vtrack = (MatroskaVideoTrack *) track;
c0955bfc27be matroska: add support for V_QUICKTIME track type
aurel
parents: 3495
diff changeset
2559
c0955bfc27be matroska: add support for V_QUICKTIME track type
aurel
parents: 3495
diff changeset
2560 vtrack->fourcc = AV_RL32(track->codec_priv);
c0955bfc27be matroska: add support for V_QUICKTIME track type
aurel
parents: 3495
diff changeset
2561 codec_id = codec_get_id(codec_movvideo_tags, vtrack->fourcc);
c0955bfc27be matroska: add support for V_QUICKTIME track type
aurel
parents: 3495
diff changeset
2562 }
c0955bfc27be matroska: add support for V_QUICKTIME track type
aurel
parents: 3495
diff changeset
2563
1475
a83e86c05295 Add A_AAC codec identifier support in matroska.
aurel
parents: 1472
diff changeset
2564 else if (codec_id == CODEC_ID_AAC && !track->codec_priv_size) {
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2565 MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *) track;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2566 int profile = matroska_aac_profile(track->codec_id);
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2567 int sri = matroska_aac_sri(audiotrack->internal_samplerate);
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2568 extradata = av_malloc(5);
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2569 if (extradata == NULL)
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2264
diff changeset
2570 return AVERROR(ENOMEM);
1468
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2571 extradata[0] = (profile << 3) | ((sri&0x0E) >> 1);
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2572 extradata[1] = ((sri&0x01) << 7) | (audiotrack->channels<<3);
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2573 if (strstr(track->codec_id, "SBR")) {
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2574 sri = matroska_aac_sri(audiotrack->samplerate);
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2575 extradata[2] = 0x56;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2576 extradata[3] = 0xE5;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2577 extradata[4] = 0x80 | (sri<<3);
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2578 extradata_size = 5;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2579 } else {
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2580 extradata_size = 2;
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2581 }
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2582 }
3f467725b70f add support for AAC in matroska
aurel
parents: 1467
diff changeset
2583
1534
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2584 else if (codec_id == CODEC_ID_TTA) {
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2585 MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *) track;
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2586 ByteIOContext b;
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2587 extradata_size = 30;
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2588 extradata = av_mallocz(extradata_size);
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2589 if (extradata == NULL)
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2264
diff changeset
2590 return AVERROR(ENOMEM);
1534
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2591 init_put_byte(&b, extradata, extradata_size, 1,
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2592 NULL, NULL, NULL, NULL);
3009
9fefe2df6756 Remove incorrect cast found by -Wwrite-strings.
michael
parents: 2973
diff changeset
2593 put_buffer(&b, "TTA1", 4);
1534
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2594 put_le16(&b, 1);
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2595 put_le16(&b, audiotrack->channels);
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2596 put_le16(&b, audiotrack->bitdepth);
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2597 put_le32(&b, audiotrack->samplerate);
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2598 put_le32(&b, matroska->ctx->duration * audiotrack->samplerate);
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2599 }
4bf9dc98e127 add support for tta in matroska
aurel
parents: 1533
diff changeset
2600
1531
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
2601 else if (codec_id == CODEC_ID_RV10 || codec_id == CODEC_ID_RV20 ||
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
2602 codec_id == CODEC_ID_RV30 || codec_id == CODEC_ID_RV40) {
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
2603 extradata_offset = 26;
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
2604 track->codec_priv_size -= extradata_offset;
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
2605 }
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
2606
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2607 else if (codec_id == CODEC_ID_RA_144) {
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2608 MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *)track;
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2609 audiotrack->samplerate = 8000;
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2610 audiotrack->channels = 1;
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2611 }
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2612
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2613 else if (codec_id == CODEC_ID_RA_288 ||
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2614 codec_id == CODEC_ID_COOK ||
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2615 codec_id == CODEC_ID_ATRAC3) {
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2616 MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *)track;
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2617 ByteIOContext b;
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2618
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2619 init_put_byte(&b, track->codec_priv, track->codec_priv_size, 0,
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2620 NULL, NULL, NULL, NULL);
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2621 url_fskip(&b, 24);
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2622 audiotrack->coded_framesize = get_be32(&b);
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2623 url_fskip(&b, 12);
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2624 audiotrack->sub_packet_h = get_be16(&b);
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2625 audiotrack->frame_size = get_be16(&b);
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2626 audiotrack->sub_packet_size = get_be16(&b);
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2627 audiotrack->buf = av_malloc(audiotrack->frame_size * audiotrack->sub_packet_h);
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2628 if (codec_id == CODEC_ID_RA_288) {
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2629 audiotrack->block_align = audiotrack->coded_framesize;
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2630 track->codec_priv_size = 0;
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2631 } else {
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2632 audiotrack->block_align = audiotrack->sub_packet_size;
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2633 extradata_offset = 78;
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2634 track->codec_priv_size -= extradata_offset;
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2635 }
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2636 }
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2637
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2638 if (codec_id == CODEC_ID_NONE) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2639 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2640 "Unknown/unsupported CodecID %s.\n",
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2641 track->codec_id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2642 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2643
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2644 track->stream_index = matroska->num_streams;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2645
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2646 matroska->num_streams++;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2647 st = av_new_stream(s, track->stream_index);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2648 if (st == NULL)
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2264
diff changeset
2649 return AVERROR(ENOMEM);
3408
da09478c97ce matroskadec: read TrackTimecodeScale and set timebase accordingly
aurel
parents: 3407
diff changeset
2650 av_set_pts_info(st, 64, matroska->time_scale*track->time_scale, 1000*1000*1000); /* 64 bit pts in ns */
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2651
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2652 st->codec->codec_id = codec_id;
2009
c0c6474ce5a7 properly set streams start_time
aurel
parents: 2008
diff changeset
2653 st->start_time = 0;
2238
98ac80739c58 properly set AVStream.language according to Matroska track header
aurel
parents: 2202
diff changeset
2654 if (strcmp(track->language, "und"))
3628
5f2e1da55755 matroskadec: use more robust av_strlcpy() instead of strcpy()
aurel
parents: 3601
diff changeset
2655 av_strlcpy(st->language, track->language, 4);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2656
3120
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3009
diff changeset
2657 if (track->flags & MATROSKA_TRACK_DEFAULT)
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3009
diff changeset
2658 st->disposition |= AV_DISPOSITION_DEFAULT;
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3009
diff changeset
2659
1454
d7b946a1ec57 guess matroska files frame rate
aurel
parents: 1452
diff changeset
2660 if (track->default_duration)
d7b946a1ec57 guess matroska files frame rate
aurel
parents: 1452
diff changeset
2661 av_reduce(&st->codec->time_base.num, &st->codec->time_base.den,
2389
cde14f83579b Don't pre-scale default_duration to avoid precision loss in fps calculation.
aurel
parents: 2388
diff changeset
2662 track->default_duration, 1000000000, 30000);
1454
d7b946a1ec57 guess matroska files frame rate
aurel
parents: 1452
diff changeset
2663
692
b0144ebc71dd H.264 and Vorbis support in matroska patch by (M«©ns Rullg«©rd |mru inprovide com)
michael
parents: 652
diff changeset
2664 if(extradata){
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2665 st->codec->extradata = extradata;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2666 st->codec->extradata_size = extradata_size;
692
b0144ebc71dd H.264 and Vorbis support in matroska patch by (M«©ns Rullg«©rd |mru inprovide com)
michael
parents: 652
diff changeset
2667 } else if(track->codec_priv && track->codec_priv_size > 0){
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2668 st->codec->extradata = av_malloc(track->codec_priv_size);
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2669 if(st->codec->extradata == NULL)
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2264
diff changeset
2670 return AVERROR(ENOMEM);
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2671 st->codec->extradata_size = track->codec_priv_size;
1531
b9caa8a8d77d matroska: properly handle real video extradata
aurel
parents: 1530
diff changeset
2672 memcpy(st->codec->extradata,track->codec_priv+extradata_offset,
692
b0144ebc71dd H.264 and Vorbis support in matroska patch by (M«©ns Rullg«©rd |mru inprovide com)
michael
parents: 652
diff changeset
2673 track->codec_priv_size);
b0144ebc71dd H.264 and Vorbis support in matroska patch by (M«©ns Rullg«©rd |mru inprovide com)
michael
parents: 652
diff changeset
2674 }
b0144ebc71dd H.264 and Vorbis support in matroska patch by (M«©ns Rullg«©rd |mru inprovide com)
michael
parents: 652
diff changeset
2675
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2676 if (track->type == MATROSKA_TRACK_TYPE_VIDEO) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2677 MatroskaVideoTrack *videotrack = (MatroskaVideoTrack *)track;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2678
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2679 st->codec->codec_type = CODEC_TYPE_VIDEO;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2680 st->codec->codec_tag = videotrack->fourcc;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2681 st->codec->width = videotrack->pixel_width;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2682 st->codec->height = videotrack->pixel_height;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2683 if (videotrack->display_width == 0)
1021
5661350bf214 fix aspect ratio
michael
parents: 920
diff changeset
2684 videotrack->display_width= videotrack->pixel_width;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2685 if (videotrack->display_height == 0)
1021
5661350bf214 fix aspect ratio
michael
parents: 920
diff changeset
2686 videotrack->display_height= videotrack->pixel_height;
5661350bf214 fix aspect ratio
michael
parents: 920
diff changeset
2687 av_reduce(&st->codec->sample_aspect_ratio.num,
5661350bf214 fix aspect ratio
michael
parents: 920
diff changeset
2688 &st->codec->sample_aspect_ratio.den,
5661350bf214 fix aspect ratio
michael
parents: 920
diff changeset
2689 st->codec->height * videotrack->display_width,
5661350bf214 fix aspect ratio
michael
parents: 920
diff changeset
2690 st->codec-> width * videotrack->display_height,
5661350bf214 fix aspect ratio
michael
parents: 920
diff changeset
2691 255);
2023
a3e79d6e4e3c add an enum for need_parsing
aurel
parents: 2015
diff changeset
2692 st->need_parsing = AVSTREAM_PARSE_HEADERS;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2693 } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2694 MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *)track;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2695
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2696 st->codec->codec_type = CODEC_TYPE_AUDIO;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2697 st->codec->sample_rate = audiotrack->samplerate;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
2698 st->codec->channels = audiotrack->channels;
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2699 st->codec->block_align = audiotrack->block_align;
1025
95e8458ae120 duration and subitle fix from the patch by Steve Lhomme
michael
parents: 1024
diff changeset
2700 } else if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE) {
95e8458ae120 duration and subitle fix from the patch by Steve Lhomme
michael
parents: 1024
diff changeset
2701 st->codec->codec_type = CODEC_TYPE_SUBTITLE;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2702 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2703
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2704 /* What do we do with private data? E.g. for Vorbis. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2705 }
1465
1dccf2603e1d Better way to detect cluster (fix files encoded with Haali's muxer).
aurel
parents: 1459
diff changeset
2706 res = 0;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2707 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2708
2012
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2709 if (matroska->index_parsed) {
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2710 int i, track, stream;
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2711 for (i=0; i<matroska->num_indexes; i++) {
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2712 MatroskaDemuxIndex *idx = &matroska->index[i];
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2713 track = matroska_find_track_by_num(matroska, idx->track);
3199
df53e261fe4d check return value of matroska_find_track_by_num (fix a segfault)
aurel
parents: 3138
diff changeset
2714 if (track < 0) continue;
2012
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2715 stream = matroska->tracks[track]->stream_index;
3138
ce03321a2cc8 add out of bound stream index checks
aurel
parents: 3137
diff changeset
2716 if (stream >= 0 && stream < matroska->ctx->nb_streams)
2202
32d675fb5e2e cosmetics: indentation after last commit
aurel
parents: 2201
diff changeset
2717 av_add_index_entry(matroska->ctx->streams[stream],
3409
524179afafe7 matroskadec: use the proper timestamp scaling for index entries
aurel
parents: 3408
diff changeset
2718 idx->pos, idx->time/AV_TIME_BASE,
2202
32d675fb5e2e cosmetics: indentation after last commit
aurel
parents: 2201
diff changeset
2719 0, 0, AVINDEX_KEYFRAME);
2012
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2720 }
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2721 }
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
2722
1465
1dccf2603e1d Better way to detect cluster (fix files encoded with Haali's muxer).
aurel
parents: 1459
diff changeset
2723 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
2724 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2725
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2726 static int
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2727 matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int size,
1914
511723932287 calculate pts for laced packets
aurel
parents: 1913
diff changeset
2728 int64_t pos, uint64_t cluster_time, uint64_t duration,
1916
6a5bafd079fd remove no more needed parameters
aurel
parents: 1915
diff changeset
2729 int is_keyframe, int is_bframe)
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2730 {
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2731 int res = 0;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2732 int track;
2013
fc0b19650faa add an intermediate variable (prepare for next patch)
aurel
parents: 2012
diff changeset
2733 AVStream *st;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2734 AVPacket *pkt;
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2735 uint8_t *origdata = data;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2736 int16_t block_time;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2737 uint32_t *lace_size = NULL;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2738 int n, flags, laces = 0;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2739 uint64_t num;
3137
20db4653d696 add a temporary variable to simplify the code
aurel
parents: 3120
diff changeset
2740 int stream_index;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2741
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2742 /* first byte(s): tracknum */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2743 if ((n = matroska_ebmlnum_uint(data, size, &num)) < 0) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2744 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
2745 av_free(origdata);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2746 return res;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2747 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2748 data += n;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2749 size -= n;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2750
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2751 /* fetch track from num */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2752 track = matroska_find_track_by_num(matroska, num);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2753 if (size <= 3 || track < 0 || track >= matroska->num_tracks) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2754 av_log(matroska->ctx, AV_LOG_INFO,
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2755 "Invalid stream %d or size %u\n", track, size);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2756 av_free(origdata);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2757 return res;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2758 }
3137
20db4653d696 add a temporary variable to simplify the code
aurel
parents: 3120
diff changeset
2759 stream_index = matroska->tracks[track]->stream_index;
3138
ce03321a2cc8 add out of bound stream index checks
aurel
parents: 3137
diff changeset
2760 if (stream_index < 0 || stream_index >= matroska->ctx->nb_streams) {
2870
d2c5c911280d fix memory leak (patch by Gabriel Fort«± gforte _at_ wyplay _dot_ com)
aurel
parents: 2805
diff changeset
2761 av_free(origdata);
2201
c514ebfeec49 drop blocks which are part of unsupported tracks
aurel
parents: 2188
diff changeset
2762 return res;
2870
d2c5c911280d fix memory leak (patch by Gabriel Fort«± gforte _at_ wyplay _dot_ com)
aurel
parents: 2805
diff changeset
2763 }
3137
20db4653d696 add a temporary variable to simplify the code
aurel
parents: 3120
diff changeset
2764 st = matroska->ctx->streams[stream_index];
2013
fc0b19650faa add an intermediate variable (prepare for next patch)
aurel
parents: 2012
diff changeset
2765 if (st->discard >= AVDISCARD_ALL) {
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2766 av_free(origdata);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2767 return res;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2768 }
1914
511723932287 calculate pts for laced packets
aurel
parents: 1913
diff changeset
2769 if (duration == AV_NOPTS_VALUE)
2389
cde14f83579b Don't pre-scale default_duration to avoid precision loss in fps calculation.
aurel
parents: 2388
diff changeset
2770 duration = matroska->tracks[track]->default_duration / matroska->time_scale;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2771
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2772 /* block_time (relative to cluster time) */
2185
7dd08e645d92 use intreadwrite functions in matroskadec
aurel
parents: 2175
diff changeset
2773 block_time = AV_RB16(data);
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2774 data += 2;
2188
4c2924cebe00 simplify
aurel
parents: 2185
diff changeset
2775 flags = *data++;
4c2924cebe00 simplify
aurel
parents: 2185
diff changeset
2776 size -= 3;
1831
bdca904db5e5 add support for simple blocks (ie. matroska v2)
aurel
parents: 1830
diff changeset
2777 if (is_keyframe == -1)
2415
3aa642c08cde SimpleBlock keyframe flag is the most significant bit
conrad
parents: 2390
diff changeset
2778 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
2779
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
2780 if (matroska->skip_to_keyframe) {
2870
d2c5c911280d fix memory leak (patch by Gabriel Fort«± gforte _at_ wyplay _dot_ com)
aurel
parents: 2805
diff changeset
2781 if (!is_keyframe || st != matroska->skip_to_stream) {
d2c5c911280d fix memory leak (patch by Gabriel Fort«± gforte _at_ wyplay _dot_ com)
aurel
parents: 2805
diff changeset
2782 av_free(origdata);
2014
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
2783 return res;
2870
d2c5c911280d fix memory leak (patch by Gabriel Fort«± gforte _at_ wyplay _dot_ com)
aurel
parents: 2805
diff changeset
2784 }
2014
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
2785 matroska->skip_to_keyframe = 0;
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
2786 }
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
2787
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2788 switch ((flags & 0x06) >> 1) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2789 case 0x0: /* no lacing */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2790 laces = 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2791 lace_size = av_mallocz(sizeof(int));
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2792 lace_size[0] = size;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2793 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2794
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2795 case 0x1: /* xiph lacing */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2796 case 0x2: /* fixed-size lacing */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2797 case 0x3: /* EBML lacing */
3391
39750abd9bab Dead code removal, fixes CID59 RUN2.
michael
parents: 3334
diff changeset
2798 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
2799 laces = (*data) + 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2800 data += 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2801 size -= 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2802 lace_size = av_mallocz(laces * sizeof(int));
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2803
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2804 switch ((flags & 0x06) >> 1) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2805 case 0x1: /* xiph lacing */ {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2806 uint8_t temp;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2807 uint32_t total = 0;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2808 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
2809 while (1) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2810 if (size == 0) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2811 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
2812 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2813 }
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2814 temp = *data;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2815 lace_size[n] += temp;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2816 data += 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2817 size -= 1;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2818 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
2819 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2820 }
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2821 total += lace_size[n];
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2822 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2823 lace_size[n] = size - total;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2824 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2825 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2826
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2827 case 0x2: /* fixed-size lacing */
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2828 for (n = 0; n < laces; n++)
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2829 lace_size[n] = size / laces;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2830 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2831
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2832 case 0x3: /* EBML lacing */ {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2833 uint32_t total;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2834 n = matroska_ebmlnum_uint(data, size, &num);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2835 if (n < 0) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2836 av_log(matroska->ctx, AV_LOG_INFO,
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2837 "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
2838 break;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2839 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2840 data += n;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2841 size -= n;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2842 total = lace_size[0] = num;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2843 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
2844 int64_t snum;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2845 int r;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2846 r = matroska_ebmlnum_sint (data, size, &snum);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2847 if (r < 0) {
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2848 av_log(matroska->ctx, AV_LOG_INFO,
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2849 "EBML block data error\n");
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2850 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2851 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2852 data += r;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2853 size -= r;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2854 lace_size[n] = lace_size[n - 1] + snum;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2855 total += lace_size[n];
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2856 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2857 lace_size[n] = size - total;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2858 break;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2859 }
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2860 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2861 break;
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2862 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2863
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2864 if (res == 0) {
1911
2ce053f3d996 move timecode calculation out of laces loop
aurel
parents: 1905
diff changeset
2865 uint64_t timecode = AV_NOPTS_VALUE;
2ce053f3d996 move timecode calculation out of laces loop
aurel
parents: 1905
diff changeset
2866
2364
7c31128b23f8 ensure that negative block_time are properly checked
aurel
parents: 2276
diff changeset
2867 if (cluster_time != (uint64_t)-1
7c31128b23f8 ensure that negative block_time are properly checked
aurel
parents: 2276
diff changeset
2868 && (block_time >= 0 || cluster_time >= -block_time))
1911
2ce053f3d996 move timecode calculation out of laces loop
aurel
parents: 1905
diff changeset
2869 timecode = cluster_time + block_time;
2ce053f3d996 move timecode calculation out of laces loop
aurel
parents: 1905
diff changeset
2870
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2871 for (n = 0; n < laces; n++) {
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2872 if (st->codec->codec_id == CODEC_ID_RA_288 ||
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2873 st->codec->codec_id == CODEC_ID_COOK ||
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2874 st->codec->codec_id == CODEC_ID_ATRAC3) {
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2875 MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *)matroska->tracks[track];
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2876 int a = st->codec->block_align;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2877 int sps = audiotrack->sub_packet_size;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2878 int cfs = audiotrack->coded_framesize;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2879 int h = audiotrack->sub_packet_h;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2880 int y = audiotrack->sub_packet_cnt;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2881 int w = audiotrack->frame_size;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2882 int x;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2883
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2884 if (!audiotrack->pkt_cnt) {
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2885 if (st->codec->codec_id == CODEC_ID_RA_288)
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2886 for (x=0; x<h/2; x++)
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2887 memcpy(audiotrack->buf+x*2*w+y*cfs,
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2888 data+x*cfs, cfs);
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2889 else
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2890 for (x=0; x<w/sps; x++)
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2891 memcpy(audiotrack->buf+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), data+x*sps, sps);
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2892
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2893 if (++audiotrack->sub_packet_cnt >= h) {
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2894 audiotrack->sub_packet_cnt = 0;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2895 audiotrack->pkt_cnt = h*w / a;
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2896 }
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2897 }
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2898 while (audiotrack->pkt_cnt) {
2145
3dd44fd1cbf4 cosmetics: indentation
aurel
parents: 2144
diff changeset
2899 pkt = av_mallocz(sizeof(AVPacket));
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2900 av_new_packet(pkt, a);
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2901 memcpy(pkt->data, audiotrack->buf
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2902 + a * (h*w / a - audiotrack->pkt_cnt--), a);
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2903 pkt->pos = pos;
3137
20db4653d696 add a temporary variable to simplify the code
aurel
parents: 3120
diff changeset
2904 pkt->stream_index = stream_index;
2145
3dd44fd1cbf4 cosmetics: indentation
aurel
parents: 2144
diff changeset
2905 matroska_queue_packet(matroska, pkt);
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
2906 }
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2907 } else {
3494
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
2908 int offset = 0, pkt_size = lace_size[n];
3281
a1d98736c15e matroskadec: add support for lzo compressed tracks
aurel
parents: 3280
diff changeset
2909 uint8_t *pkt_data = data;
a1d98736c15e matroskadec: add support for lzo compressed tracks
aurel
parents: 3280
diff changeset
2910
a1d98736c15e matroskadec: add support for lzo compressed tracks
aurel
parents: 3280
diff changeset
2911 if (matroska->tracks[track]->encoding_scope & 1) {
3494
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
2912 offset = matroska_decode_buffer(&pkt_data, &pkt_size,
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
2913 matroska->tracks[track]);
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
2914 if (offset < 0)
8bf1a8e12b43 matroskadec: move buffer decoding code to a separate function
aurel
parents: 3493
diff changeset
2915 continue;
3279
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
2916 }
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
2917
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2918 pkt = av_mallocz(sizeof(AVPacket));
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2919 /* XXX: prevent data copy... */
3281
a1d98736c15e matroskadec: add support for lzo compressed tracks
aurel
parents: 3280
diff changeset
2920 if (av_new_packet(pkt, pkt_size+offset) < 0) {
3415
89f651b6f12a matroskadec: avoid potential mem leak
aurel
parents: 3414
diff changeset
2921 av_free(pkt);
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2922 res = AVERROR(ENOMEM);
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2923 n = laces-1;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2924 break;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2925 }
3279
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
2926 if (offset)
807c5f54e8b5 matroskadec: add support for track content encoding
aurel
parents: 3234
diff changeset
2927 memcpy (pkt->data, matroska->tracks[track]->encoding_settings, offset);
3281
a1d98736c15e matroskadec: add support for lzo compressed tracks
aurel
parents: 3280
diff changeset
2928 memcpy (pkt->data+offset, pkt_data, pkt_size);
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2929
3493
b77ced770a93 matroskadec: fix a memory leak
aurel
parents: 3477
diff changeset
2930 if (pkt_data != data)
b77ced770a93 matroskadec: fix a memory leak
aurel
parents: 3477
diff changeset
2931 av_free(pkt_data);
b77ced770a93 matroskadec: fix a memory leak
aurel
parents: 3477
diff changeset
2932
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2933 if (n == 0)
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2934 pkt->flags = is_keyframe;
3137
20db4653d696 add a temporary variable to simplify the code
aurel
parents: 3120
diff changeset
2935 pkt->stream_index = stream_index;
2657
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2936
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2937 pkt->pts = timecode;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2938 pkt->pos = pos;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2939 pkt->duration = duration;
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2940
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2941 matroska_queue_packet(matroska, pkt);
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2942 }
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2943
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2944 if (timecode != AV_NOPTS_VALUE)
7efaa7166cb1 cosmetics: reindent
aurel
parents: 2654
diff changeset
2945 timecode = duration ? timecode + duration : AV_NOPTS_VALUE;
1830
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2946 data += lace_size[n];
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2947 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2948 }
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2949
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2950 av_free(lace_size);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2951 av_free(origdata);
ae69f36fe685 cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents: 1829
diff changeset
2952 return res;
1829
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2953 }
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2954
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2955 static int
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2956 matroska_parse_blockgroup (MatroskaDemuxContext *matroska,
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2957 uint64_t cluster_time)
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2958 {
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2959 int res = 0;
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2960 uint32_t id;
1902
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
2961 int is_bframe = 0;
1829
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2962 int is_keyframe = PKT_FLAG_KEY, last_num_packets = matroska->num_packets;
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2963 uint64_t duration = AV_NOPTS_VALUE;
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2964 uint8_t *data;
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2965 int size = 0;
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2966 int64_t pos = 0;
1829
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2967
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2968 av_log(matroska->ctx, AV_LOG_DEBUG, "parsing blockgroup...\n");
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2969
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2970 while (res == 0) {
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2971 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
2972 res = AVERROR(EIO);
1829
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2973 break;
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2974 } else if (matroska->level_up) {
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2975 matroska->level_up--;
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2976 break;
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2977 }
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2978
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2979 switch (id) {
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2980 /* one block inside the group. Note, block parsing is one
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2981 * of the harder things, so this code is a bit complicated.
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2982 * See http://www.matroska.org/ for documentation. */
bf82ef5c32b4 split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents: 1828
diff changeset
2983 case MATROSKA_ID_BLOCK: {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
2984 pos = url_ftell(matroska->ctx->pb);
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
2985 res = ebml_read_binary(matroska, &id, &data, &size);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2986 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2987 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2988
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2989 case MATROSKA_ID_BLOCKDURATION: {
1456
34d0d965a0d0 Add support for block duration.
aurel
parents: 1455
diff changeset
2990 if ((res = ebml_read_uint(matroska, &id, &duration)) < 0)
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2991 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2992 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2993 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2994
1902
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
2995 case MATROSKA_ID_BLOCKREFERENCE: {
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
2996 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
2997 /* We've found a reference, so not even the first frame in
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2998 * the lace is a key frame. */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
2999 is_keyframe = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3000 if (last_num_packets != matroska->num_packets)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3001 matroska->packets[last_num_packets]->flags = 0;
1902
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
3002 if ((res = ebml_read_sint(matroska, &id, &num)) < 0)
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
3003 break;
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
3004 if (num > 0)
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
3005 is_bframe = 1;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3006 break;
1902
4225f8dc0098 check if current block contains a B frame and gives this info to parse_block()
aurel
parents: 1901
diff changeset
3007 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3008
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3009 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3010 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3011 "Unknown entry 0x%x in blockgroup data\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3012 /* fall-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3013
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3014 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3015 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3016 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3017 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3018
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3019 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3020 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3021 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3022 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3023 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3024
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
3025 if (res)
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
3026 return res;
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
3027
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
3028 if (size > 0)
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
3029 res = matroska_parse_block(matroska, data, size, pos, cluster_time,
1916
6a5bafd079fd remove no more needed parameters
aurel
parents: 1915
diff changeset
3030 duration, is_keyframe, is_bframe);
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
3031
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3032 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3033 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3034
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3035 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3036 matroska_parse_cluster (MatroskaDemuxContext *matroska)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3037 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3038 int res = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3039 uint32_t id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3040 uint64_t cluster_time = 0;
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
3041 uint8_t *data;
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
3042 int64_t pos;
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
3043 int size;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3044
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3045 av_log(matroska->ctx, AV_LOG_DEBUG,
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
3046 "parsing cluster at %"PRId64"\n", url_ftell(matroska->ctx->pb));
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3047
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3048 while (res == 0) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3049 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
3050 res = AVERROR(EIO);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3051 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3052 } else if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3053 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3054 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3055 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3056
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3057 switch (id) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3058 /* cluster timecode */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3059 case MATROSKA_ID_CLUSTERTIMECODE: {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3060 uint64_t num;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3061 if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3062 break;
1035
4a33428641e1 fixing timebase
michael
parents: 1034
diff changeset
3063 cluster_time = num;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3064 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3065 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3066
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3067 /* a group of blocks inside a cluster */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3068 case MATROSKA_ID_BLOCKGROUP:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3069 if ((res = ebml_read_master(matroska, &id)) < 0)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3070 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3071 res = matroska_parse_blockgroup(matroska, cluster_time);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3072 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3073
1831
bdca904db5e5 add support for simple blocks (ie. matroska v2)
aurel
parents: 1830
diff changeset
3074 case MATROSKA_ID_SIMPLEBLOCK:
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
3075 pos = url_ftell(matroska->ctx->pb);
1901
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
3076 res = ebml_read_binary(matroska, &id, &data, &size);
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
3077 if (res == 0)
3f05dc37b4ec extract ebml_read_binary() out of matroska_parse_block()
aurel
parents: 1900
diff changeset
3078 res = matroska_parse_block(matroska, data, size, pos,
1914
511723932287 calculate pts for laced packets
aurel
parents: 1913
diff changeset
3079 cluster_time, AV_NOPTS_VALUE,
1916
6a5bafd079fd remove no more needed parameters
aurel
parents: 1915
diff changeset
3080 -1, 0);
1831
bdca904db5e5 add support for simple blocks (ie. matroska v2)
aurel
parents: 1830
diff changeset
3081 break;
bdca904db5e5 add support for simple blocks (ie. matroska v2)
aurel
parents: 1830
diff changeset
3082
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3083 default:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3084 av_log(matroska->ctx, AV_LOG_INFO,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3085 "Unknown entry 0x%x in cluster data\n", id);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3086 /* fall-through */
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3087
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3088 case EBML_ID_VOID:
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3089 res = ebml_read_skip(matroska);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3090 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3091 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3092
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3093 if (matroska->level_up) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3094 matroska->level_up--;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3095 break;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3096 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3097 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3098
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3099 return res;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3100 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3101
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3102 static int
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3103 matroska_read_packet (AVFormatContext *s,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3104 AVPacket *pkt)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3105 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3106 MatroskaDemuxContext *matroska = s->priv_data;
2143
a3d59411106f fix an infinite loop in case one cluster is not enough to demux a packet
aurel
parents: 2142
diff changeset
3107 int res;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3108 uint32_t id;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3109
1899
1324ae790ee0 parse clusters until some packets are queued
aurel
parents: 1898
diff changeset
3110 /* Read stream until we have a packet queued. */
1324ae790ee0 parse clusters until some packets are queued
aurel
parents: 1898
diff changeset
3111 while (matroska_deliver_packet(matroska, pkt)) {
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3112
1900
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3113 /* Have we already reached the end? */
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3114 if (matroska->done)
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
3115 return AVERROR(EIO);
1900
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3116
2143
a3d59411106f fix an infinite loop in case one cluster is not enough to demux a packet
aurel
parents: 2142
diff changeset
3117 res = 0;
1900
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3118 while (res == 0) {
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3119 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
3120 return AVERROR(EIO);
1900
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3121 } else if (matroska->level_up) {
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3122 matroska->level_up--;
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3123 break;
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3124 }
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3125
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3126 switch (id) {
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3127 case MATROSKA_ID_CLUSTER:
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3128 if ((res = ebml_read_master(matroska, &id)) < 0)
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3129 break;
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3130 if ((res = matroska_parse_cluster(matroska)) == 0)
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3131 res = 1; /* Parsed one cluster, let's get out. */
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3132 break;
1900
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3133
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3134 default:
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3135 case EBML_ID_VOID:
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3136 res = ebml_read_skip(matroska);
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3137 break;
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3138 }
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3139
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3140 if (matroska->level_up) {
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3141 matroska->level_up--;
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3142 break;
1900
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3143 }
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3144 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3145
1900
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3146 if (res == -1)
55cc48bb357d reindent after last commit
aurel
parents: 1899
diff changeset
3147 matroska->done = 1;
1899
1324ae790ee0 parse clusters until some packets are queued
aurel
parents: 1898
diff changeset
3148 }
1324ae790ee0 parse clusters until some packets are queued
aurel
parents: 1898
diff changeset
3149
1324ae790ee0 parse clusters until some packets are queued
aurel
parents: 1898
diff changeset
3150 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
3151 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3152
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3153 static int
2012
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
3154 matroska_read_seek (AVFormatContext *s, int stream_index, int64_t timestamp,
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
3155 int flags)
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
3156 {
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
3157 MatroskaDemuxContext *matroska = s->priv_data;
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
3158 AVStream *st = s->streams[stream_index];
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
3159 int index;
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
3160
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
3161 /* find index entry */
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
3162 index = av_index_search_timestamp(st, timestamp, flags);
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
3163 if (index < 0)
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
3164 return 0;
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
3165
2872
a9bb4614c0f8 clear internal queue when seeking
aurel
parents: 2871
diff changeset
3166 matroska_clear_queue(matroska);
a9bb4614c0f8 clear internal queue when seeking
aurel
parents: 2871
diff changeset
3167
2012
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
3168 /* do the seek */
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2657
diff changeset
3169 url_fseek(s->pb, st->index_entries[index].pos, SEEK_SET);
2014
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
3170 matroska->skip_to_keyframe = !(flags & AVSEEK_FLAG_ANY);
de75a5a81f28 add support for seeking to a keyframe instead of a random frame
aurel
parents: 2013
diff changeset
3171 matroska->skip_to_stream = st;
2012
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
3172 matroska->peek_id = 0;
3462
3f87bde8a97c matroskadec: set cur_dts after seek
aurel
parents: 3427
diff changeset
3173 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
3174 return 0;
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
3175 }
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
3176
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
3177 static int
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3178 matroska_read_close (AVFormatContext *s)
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3179 {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3180 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
3181 int n = 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3182
1458
7d13d9e4d783 cosmetics: reindent after last commit
aurel
parents: 1457
diff changeset
3183 av_free(matroska->index);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3184
2871
b2f261fccb0b move internal queue freeing code in its own function
aurel
parents: 2870
diff changeset
3185 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
3186
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3187 for (n = 0; n < matroska->num_tracks; n++) {
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3188 MatroskaTrack *track = matroska->tracks[n];
1458
7d13d9e4d783 cosmetics: reindent after last commit
aurel
parents: 1457
diff changeset
3189 av_free(track->codec_id);
7d13d9e4d783 cosmetics: reindent after last commit
aurel
parents: 1457
diff changeset
3190 av_free(track->codec_priv);
7d13d9e4d783 cosmetics: reindent after last commit
aurel
parents: 1457
diff changeset
3191 av_free(track->name);
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3192
2144
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
3193 if (track->type == MATROSKA_TRACK_TYPE_AUDIO) {
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
3194 MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *)track;
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
3195 av_free(audiotrack->buf);
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
3196 }
7fe203e939e5 add support for real audio in matroska
aurel
parents: 2143
diff changeset
3197
380
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3198 av_free(track);
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3199 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3200
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3201 return 0;
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3202 }
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3203
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
3204 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
3205 "matroska",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3422
diff changeset
3206 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
3207 sizeof(MatroskaDemuxContext),
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3208 matroska_probe,
9416dc106e06 matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff changeset
3209 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
3210 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
3211 matroska_read_close,
2012
0829642f7456 add support for seeking in matroska files
aurel
parents: 2011
diff changeset
3212 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
3213 };