annotate isom.h @ 5165:3d4203b9c2d7 libavformat

check entries against field_size, potential malloc overflow in read_stsz, fix #1357
author bcoudurier
date Mon, 07 Sep 2009 22:42:51 +0000
parents 7b260f4d453d
children 047f527ae157
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1306
8bf9be9bb107 Add official LGPL license headers to the files that were missing them.
diego
parents: 1216
diff changeset
1 /*
8bf9be9bb107 Add official LGPL license headers to the files that were missing them.
diego
parents: 1216
diff changeset
2 * ISO Media common code
4251
77e0c7511d41 cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 4079
diff changeset
3 * copyright (c) 2001 Fabrice Bellard
1306
8bf9be9bb107 Add official LGPL license headers to the files that were missing them.
diego
parents: 1216
diff changeset
4 * copyright (c) 2002 Francois Revol <revol@free.fr>
8bf9be9bb107 Add official LGPL license headers to the files that were missing them.
diego
parents: 1216
diff changeset
5 * copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@free.fr>
8bf9be9bb107 Add official LGPL license headers to the files that were missing them.
diego
parents: 1216
diff changeset
6 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1306
diff changeset
7 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1306
diff changeset
8 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1306
diff changeset
9 * FFmpeg is free software; you can redistribute it and/or
1306
8bf9be9bb107 Add official LGPL license headers to the files that were missing them.
diego
parents: 1216
diff changeset
10 * modify it under the terms of the GNU Lesser General Public
8bf9be9bb107 Add official LGPL license headers to the files that were missing them.
diego
parents: 1216
diff changeset
11 * 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: 1306
diff changeset
12 * version 2.1 of the License, or (at your option) any later version.
1306
8bf9be9bb107 Add official LGPL license headers to the files that were missing them.
diego
parents: 1216
diff changeset
13 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1306
diff changeset
14 * FFmpeg is distributed in the hope that it will be useful,
1306
8bf9be9bb107 Add official LGPL license headers to the files that were missing them.
diego
parents: 1216
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8bf9be9bb107 Add official LGPL license headers to the files that were missing them.
diego
parents: 1216
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8bf9be9bb107 Add official LGPL license headers to the files that were missing them.
diego
parents: 1216
diff changeset
17 * Lesser General Public License for more details.
8bf9be9bb107 Add official LGPL license headers to the files that were missing them.
diego
parents: 1216
diff changeset
18 *
8bf9be9bb107 Add official LGPL license headers to the files that were missing them.
diego
parents: 1216
diff changeset
19 * 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: 1306
diff changeset
20 * License along with FFmpeg; if not, write to the Free Software
1306
8bf9be9bb107 Add official LGPL license headers to the files that were missing them.
diego
parents: 1216
diff changeset
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
8bf9be9bb107 Add official LGPL license headers to the files that were missing them.
diego
parents: 1216
diff changeset
22 */
8bf9be9bb107 Add official LGPL license headers to the files that were missing them.
diego
parents: 1216
diff changeset
23
3852
1b6245500d8c Globally rename the header inclusion guard names.
stefano
parents: 2969
diff changeset
24 #ifndef AVFORMAT_ISOM_H
1b6245500d8c Globally rename the header inclusion guard names.
stefano
parents: 2969
diff changeset
25 #define AVFORMAT_ISOM_H
943
4e7a66723f1d mp4 codecs objecttype handling patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents:
diff changeset
26
4690
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
27 #include "avio.h"
2171
a6d6b2b19341 include all prerequisites in header files
mru
parents: 2045
diff changeset
28 #include "riff.h"
4690
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
29 #include "dv.h"
2171
a6d6b2b19341 include all prerequisites in header files
mru
parents: 2045
diff changeset
30
1216
fec0a3d5408f move common code from mov.c and movenc.c to isom.c
bcoudurier
parents: 1059
diff changeset
31 /* isom.c */
1948
80d330650d35 cosmectics, mov -> mp4
bcoudurier
parents: 1843
diff changeset
32 extern const AVCodecTag ff_mp4_obj_type[];
1843
9cd8cb3275f6 use common tables for mov muxer and demuxer
bcoudurier
parents: 1677
diff changeset
33 extern const AVCodecTag codec_movvideo_tags[];
9cd8cb3275f6 use common tables for mov muxer and demuxer
bcoudurier
parents: 1677
diff changeset
34 extern const AVCodecTag codec_movaudio_tags[];
2969
f3a3115a96e4 Set correct codec type and id for text subtitles.
michael
parents: 2171
diff changeset
35 extern const AVCodecTag ff_codec_movsubtitle_tags[];
1216
fec0a3d5408f move common code from mov.c and movenc.c to isom.c
bcoudurier
parents: 1059
diff changeset
36
fec0a3d5408f move common code from mov.c and movenc.c to isom.c
bcoudurier
parents: 1059
diff changeset
37 int ff_mov_iso639_to_lang(const char *lang, int mp4);
4269
bbb6561a3974 'code' is used to index a table so make it unsigned
aurel
parents: 4251
diff changeset
38 int ff_mov_lang_to_iso639(unsigned code, char *to);
943
4e7a66723f1d mp4 codecs objecttype handling patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
michael
parents:
diff changeset
39
4690
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
40 /* the QuickTime file format is quite convoluted...
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
41 * it has lots of index tables, each indexing something in another one...
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
42 * Here we just use what is needed to read the chunks
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
43 */
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
44
2045
aa5e56700fdf cosmectics, use consistant and homogeneous type names for atoms
bcoudurier
parents: 1948
diff changeset
45 typedef struct {
971
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
46 int count;
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
47 int duration;
4079
82cbec030af5 remove _t in typedef for POSIX compatibility
bcoudurier
parents: 3852
diff changeset
48 } MOVStts;
971
43f85eba04c4 CTTS support patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com>)
michael
parents: 943
diff changeset
49
4690
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
50 typedef struct {
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
51 int first;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
52 int count;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
53 int id;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
54 } MOVStsc;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
55
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
56 typedef struct {
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
57 uint32_t type;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
58 char *path;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
59 } MOVDref;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
60
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
61 typedef struct {
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
62 uint32_t type;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
63 int64_t offset;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
64 int64_t size; /* total size (excluding the size and type fields) */
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
65 } MOVAtom;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
66
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
67 struct MOVParseTableEntry;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
68
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
69 typedef struct {
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
70 unsigned track_id;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
71 uint64_t base_data_offset;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
72 uint64_t moof_offset;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
73 unsigned stsd_id;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
74 unsigned duration;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
75 unsigned size;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
76 unsigned flags;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
77 } MOVFragment;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
78
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
79 typedef struct {
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
80 unsigned track_id;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
81 unsigned stsd_id;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
82 unsigned duration;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
83 unsigned size;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
84 unsigned flags;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
85 } MOVTrackExt;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
86
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
87 typedef struct MOVStreamContext {
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
88 ByteIOContext *pb;
4932
af0ca3f0643f align and update doxygen
bcoudurier
parents: 4930
diff changeset
89 int ffindex; ///< AVStream index
4690
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
90 int next_chunk;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
91 unsigned int chunk_count;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
92 int64_t *chunk_offsets;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
93 unsigned int stts_count;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
94 MOVStts *stts_data;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
95 unsigned int ctts_count;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
96 MOVStts *ctts_data;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
97 unsigned int stsc_count;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
98 MOVStsc *stsc_data;
4933
fc6288f47467 parse 'stps' atom to set keyframe, partial sync sample for mpeg-2 open gop
bcoudurier
parents: 4932
diff changeset
99 unsigned int stps_count;
fc6288f47467 parse 'stps' atom to set keyframe, partial sync sample for mpeg-2 open gop
bcoudurier
parents: 4932
diff changeset
100 unsigned *stps_data; ///< partial sync sample for mpeg-2 open gop
4690
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
101 int ctts_index;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
102 int ctts_sample;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
103 unsigned int sample_size;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
104 unsigned int sample_count;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
105 int *sample_sizes;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
106 unsigned int keyframe_count;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
107 int *keyframes;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
108 int time_scale;
4932
af0ca3f0643f align and update doxygen
bcoudurier
parents: 4930
diff changeset
109 int time_offset; ///< time offset of the first edit list entry
4690
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
110 int current_sample;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
111 unsigned int bytes_per_frame;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
112 unsigned int samples_per_frame;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
113 int dv_audio_container;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
114 int pseudo_stream_id; ///< -1 means demux all ids
4932
af0ca3f0643f align and update doxygen
bcoudurier
parents: 4930
diff changeset
115 int16_t audio_cid; ///< stsd audio compression id
4690
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
116 unsigned drefs_count;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
117 MOVDref *drefs;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
118 int dref_id;
4932
af0ca3f0643f align and update doxygen
bcoudurier
parents: 4930
diff changeset
119 int wrong_dts; ///< dts are wrong due to huge ctts offset (iMovie files)
af0ca3f0643f align and update doxygen
bcoudurier
parents: 4930
diff changeset
120 int width; ///< tkhd width
af0ca3f0643f align and update doxygen
bcoudurier
parents: 4930
diff changeset
121 int height; ///< tkhd height
af0ca3f0643f align and update doxygen
bcoudurier
parents: 4930
diff changeset
122 int dts_shift; ///< dts shift when ctts is negative
4690
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
123 } MOVStreamContext;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
124
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
125 typedef struct MOVContext {
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
126 AVFormatContext *fc;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
127 int time_scale;
4932
af0ca3f0643f align and update doxygen
bcoudurier
parents: 4930
diff changeset
128 int64_t duration; ///< duration of the longest track
af0ca3f0643f align and update doxygen
bcoudurier
parents: 4930
diff changeset
129 int found_moov; ///< 'moov' atom has been found
af0ca3f0643f align and update doxygen
bcoudurier
parents: 4930
diff changeset
130 int found_mdat; ///< 'mdat' atom has been found
4690
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
131 DVDemuxContext *dv_demux;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
132 AVFormatContext *dv_fctx;
4932
af0ca3f0643f align and update doxygen
bcoudurier
parents: 4930
diff changeset
133 int isom; ///< 1 if file is ISO Media (mp4/3gp)
4690
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
134 MOVFragment fragment; ///< current fragment in moof atom
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
135 MOVTrackExt *trex_data;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
136 unsigned trex_count;
4932
af0ca3f0643f align and update doxygen
bcoudurier
parents: 4930
diff changeset
137 int itunes_metadata; ///< metadata are itunes style
4690
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
138 } MOVContext;
2249417477c5 Move MOVContext and related structures from mov.c to isom.h. See "[PATCH]
rbultje
parents: 4269
diff changeset
139
3852
1b6245500d8c Globally rename the header inclusion guard names.
stefano
parents: 2969
diff changeset
140 #endif /* AVFORMAT_ISOM_H */