annotate matroskadec.c @ 3477:8adaa9258dba libavformat

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