1020
|
1 /*
|
|
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
|
|
3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
|
|
4 **
|
|
5 ** This program is free software; you can redistribute it and/or modify
|
|
6 ** it under the terms of the GNU General Public License as published by
|
|
7 ** the Free Software Foundation; either version 2 of the License, or
|
|
8 ** (at your option) any later version.
|
|
9 **
|
|
10 ** This program is distributed in the hope that it will be useful,
|
|
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 ** GNU General Public License for more details.
|
|
14 **
|
|
15 ** You should have received a copy of the GNU General Public License
|
|
16 ** along with this program; if not, write to the Free Software
|
|
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
18 **
|
|
19 ** Any non-GPL usage of this software or parts of this software is strictly
|
|
20 ** forbidden.
|
|
21 **
|
|
22 ** Commercial non-GPL licensing of this software is possible.
|
|
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
|
|
24 **
|
|
25 ** $Id: mp4ffint.h,v 1.15 2004/01/14 20:50:22 menno Exp $
|
|
26 **/
|
|
27
|
|
28 #ifndef MP4FF_INTERNAL_H
|
|
29 #define MP4FF_INTERNAL_H
|
|
30
|
|
31 #ifdef __cplusplus
|
|
32 extern "C" {
|
|
33 #endif /* __cplusplus */
|
|
34
|
|
35 #include "mp4ff_int_types.h"
|
|
36
|
|
37
|
|
38 #ifdef _WIN32
|
|
39 #define ITUNES_DRM
|
|
40 #endif
|
|
41
|
|
42
|
|
43 #define MAX_TRACKS 1024
|
|
44 #define TRACK_UNKNOWN 0
|
|
45 #define TRACK_AUDIO 1
|
|
46 #define TRACK_VIDEO 2
|
|
47 #define TRACK_SYSTEM 3
|
|
48
|
|
49
|
|
50 #define SUBATOMIC 128
|
|
51
|
|
52 /* atoms without subatoms */
|
|
53 #define ATOM_FTYP 129
|
|
54 #define ATOM_MDAT 130
|
|
55 #define ATOM_MVHD 131
|
|
56 #define ATOM_TKHD 132
|
|
57 #define ATOM_TREF 133
|
|
58 #define ATOM_MDHD 134
|
|
59 #define ATOM_VMHD 135
|
|
60 #define ATOM_SMHD 136
|
|
61 #define ATOM_HMHD 137
|
|
62 #define ATOM_STSD 138
|
|
63 #define ATOM_STTS 139
|
|
64 #define ATOM_STSZ 140
|
|
65 #define ATOM_STZ2 141
|
|
66 #define ATOM_STCO 142
|
|
67 #define ATOM_STSC 143
|
|
68 #define ATOM_MP4A 144
|
|
69 #define ATOM_MP4V 145
|
|
70 #define ATOM_MP4S 146
|
|
71 #define ATOM_ESDS 147
|
|
72 #define ATOM_META 148 /* iTunes Metadata box */
|
|
73 #define ATOM_NAME 149 /* iTunes Metadata name box */
|
|
74 #define ATOM_DATA 150 /* iTunes Metadata data box */
|
|
75 #define ATOM_CTTS 151
|
|
76 #define ATOM_FRMA 152
|
|
77 #define ATOM_IVIV 153
|
|
78 #define ATOM_PRIV 154
|
|
79
|
|
80 #define ATOM_UNKNOWN 255
|
|
81 #define ATOM_FREE ATOM_UNKNOWN
|
|
82 #define ATOM_SKIP ATOM_UNKNOWN
|
|
83
|
|
84 /* atoms with subatoms */
|
|
85 #define ATOM_MOOV 1
|
|
86 #define ATOM_TRAK 2
|
|
87 #define ATOM_EDTS 3
|
|
88 #define ATOM_MDIA 4
|
|
89 #define ATOM_MINF 5
|
|
90 #define ATOM_STBL 6
|
|
91 #define ATOM_UDTA 7
|
|
92 #define ATOM_ILST 8 /* iTunes Metadata list */
|
|
93 #define ATOM_TITLE 9
|
|
94 #define ATOM_ARTIST 10
|
|
95 #define ATOM_WRITER 11
|
|
96 #define ATOM_ALBUM 12
|
|
97 #define ATOM_DATE 13
|
|
98 #define ATOM_TOOL 14
|
|
99 #define ATOM_COMMENT 15
|
|
100 #define ATOM_GENRE1 16
|
|
101 #define ATOM_TRACK 17
|
|
102 #define ATOM_DISC 18
|
|
103 #define ATOM_COMPILATION 19
|
|
104 #define ATOM_GENRE2 20
|
|
105 #define ATOM_TEMPO 21
|
|
106 #define ATOM_COVER 22
|
|
107 #define ATOM_DRMS 23
|
|
108 #define ATOM_SINF 24
|
|
109 #define ATOM_SCHI 25
|
|
110
|
|
111 #ifdef HAVE_CONFIG_H
|
|
112 #include "config.h"
|
|
113 #endif
|
|
114
|
|
115 #ifndef _WIN32
|
|
116 #define stricmp strcasecmp
|
|
117 #endif
|
|
118
|
|
119 /* file callback structure */
|
|
120 typedef struct
|
|
121 {
|
|
122 uint32_t (*read)(void *user_data, void *buffer, uint32_t length);
|
|
123 uint32_t (*write)(void *udata, void *buffer, uint32_t length);
|
|
124 uint32_t (*seek)(void *user_data, uint64_t position);
|
|
125 uint32_t (*truncate)(void *user_data);
|
|
126 void *user_data;
|
|
127 } mp4ff_callback_t;
|
|
128
|
|
129
|
|
130 /* metadata tag structure */
|
|
131 typedef struct
|
|
132 {
|
|
133 char *item;
|
|
134 char *value;
|
|
135 } mp4ff_tag_t;
|
|
136
|
|
137 /* metadata list structure */
|
|
138 typedef struct
|
|
139 {
|
|
140 mp4ff_tag_t *tags;
|
|
141 uint32_t count;
|
|
142 } mp4ff_metadata_t;
|
|
143
|
|
144
|
|
145 typedef struct
|
|
146 {
|
|
147 int32_t type;
|
|
148 int32_t channelCount;
|
|
149 int32_t sampleSize;
|
|
150 uint16_t sampleRate;
|
|
151 int32_t audioType;
|
|
152
|
|
153 /* stsd */
|
|
154 int32_t stsd_entry_count;
|
|
155
|
|
156 /* stsz */
|
|
157 int32_t stsz_sample_size;
|
|
158 int32_t stsz_sample_count;
|
|
159 int32_t *stsz_table;
|
|
160
|
|
161 /* stts */
|
|
162 int32_t stts_entry_count;
|
|
163 int32_t *stts_sample_count;
|
|
164 int32_t *stts_sample_delta;
|
|
165
|
|
166 /* stsc */
|
|
167 int32_t stsc_entry_count;
|
|
168 int32_t *stsc_first_chunk;
|
|
169 int32_t *stsc_samples_per_chunk;
|
|
170 int32_t *stsc_sample_desc_index;
|
|
171
|
|
172 /* stsc */
|
|
173 int32_t stco_entry_count;
|
|
174 int32_t *stco_chunk_offset;
|
|
175
|
|
176 /* ctts */
|
|
177 int32_t ctts_entry_count;
|
|
178 int32_t *ctts_sample_count;
|
|
179 int32_t *ctts_sample_offset;
|
|
180
|
|
181 /* esde */
|
|
182 uint8_t *decoderConfig;
|
|
183 int32_t decoderConfigLen;
|
|
184
|
|
185 uint32_t maxBitrate;
|
|
186 uint32_t avgBitrate;
|
|
187
|
|
188 uint32_t timeScale;
|
|
189 uint64_t duration;
|
|
190
|
|
191 #ifdef ITUNES_DRM
|
|
192 /* drms */
|
|
193 void *p_drms;
|
|
194 #endif
|
|
195
|
|
196 } mp4ff_track_t;
|
|
197
|
|
198 /* mp4 main file structure */
|
|
199 typedef struct
|
|
200 {
|
|
201 /* stream to read from */
|
|
202 mp4ff_callback_t *stream;
|
|
203 int64_t current_position;
|
|
204
|
|
205 int32_t moov_read;
|
|
206 uint64_t moov_offset;
|
|
207 uint64_t moov_size;
|
|
208 uint8_t last_atom;
|
|
209 uint64_t file_size;
|
|
210
|
|
211 /* mvhd */
|
|
212 int32_t time_scale;
|
|
213 int32_t duration;
|
|
214
|
|
215 /* incremental track index while reading the file */
|
|
216 int32_t total_tracks;
|
|
217
|
|
218 /* track data */
|
|
219 mp4ff_track_t *track[MAX_TRACKS];
|
|
220
|
|
221 /* metadata */
|
|
222 mp4ff_metadata_t tags;
|
|
223 } mp4ff_t;
|
|
224
|
|
225
|
|
226
|
|
227
|
|
228 /* mp4util.c */
|
|
229 int32_t mp4ff_read_data(mp4ff_t *f, int8_t *data, uint32_t size);
|
|
230 int32_t mp4ff_write_data(mp4ff_t *f, int8_t *data, uint32_t size);
|
|
231 uint64_t mp4ff_read_int64(mp4ff_t *f);
|
|
232 uint32_t mp4ff_read_int32(mp4ff_t *f);
|
|
233 uint32_t mp4ff_read_int24(mp4ff_t *f);
|
|
234 uint16_t mp4ff_read_int16(mp4ff_t *f);
|
|
235 uint8_t mp4ff_read_char(mp4ff_t *f);
|
|
236 int32_t mp4ff_write_int32(mp4ff_t *f,const uint32_t data);
|
|
237 uint32_t mp4ff_read_mp4_descr_length(mp4ff_t *f);
|
|
238 int64_t mp4ff_position(const mp4ff_t *f);
|
|
239 int32_t mp4ff_set_position(mp4ff_t *f, const int64_t position);
|
|
240 int32_t mp4ff_truncate(mp4ff_t * f);
|
|
241 char * mp4ff_read_string(mp4ff_t * f,uint32_t length);
|
|
242
|
|
243 /* mp4atom.c */
|
|
244 int32_t mp4ff_atom_get_size(const int8_t *data);
|
|
245 int32_t mp4ff_atom_compare(const int8_t a1, const int8_t b1, const int8_t c1, const int8_t d1,
|
|
246 const int8_t a2, const int8_t b2, const int8_t c2, const int8_t d2);
|
|
247 uint8_t mp4ff_atom_name_to_type(const int8_t a, const int8_t b, const int8_t c, const int8_t d);
|
|
248 uint64_t mp4ff_atom_read_header(mp4ff_t *f, uint8_t *atom_type, uint8_t *header_size);
|
|
249 int32_t mp4ff_read_stsz(mp4ff_t *f);
|
|
250 int32_t mp4ff_read_esds(mp4ff_t *f);
|
|
251 int32_t mp4ff_read_mp4a(mp4ff_t *f);
|
|
252 int32_t mp4ff_read_stsd(mp4ff_t *f);
|
|
253 int32_t mp4ff_read_stsc(mp4ff_t *f);
|
|
254 int32_t mp4ff_read_stco(mp4ff_t *f);
|
|
255 int32_t mp4ff_read_stts(mp4ff_t *f);
|
|
256 #ifdef USE_TAGGING
|
|
257 int32_t mp4ff_read_meta(mp4ff_t *f, const uint64_t size);
|
|
258 #endif
|
|
259 int32_t mp4ff_atom_read(mp4ff_t *f, const int32_t size, const uint8_t atom_type);
|
|
260
|
|
261 /* mp4sample.c */
|
|
262 int32_t mp4ff_chunk_of_sample(const mp4ff_t *f, const int32_t track, const int32_t sample,
|
|
263 int32_t *chunk_sample, int32_t *chunk);
|
|
264 int32_t mp4ff_chunk_to_offset(const mp4ff_t *f, const int32_t track, const int32_t chunk);
|
|
265 int32_t mp4ff_sample_range_size(const mp4ff_t *f, const int32_t track,
|
|
266 const int32_t chunk_sample, const int32_t sample);
|
|
267 int32_t mp4ff_sample_to_offset(const mp4ff_t *f, const int32_t track, const int32_t sample);
|
|
268 int32_t mp4ff_audio_frame_size(const mp4ff_t *f, const int32_t track, const int32_t sample);
|
|
269 int32_t mp4ff_set_sample_position(mp4ff_t *f, const int32_t track, const int32_t sample);
|
|
270
|
|
271 #ifdef USE_TAGGING
|
|
272 /* mp4meta.c */
|
|
273 int32_t mp4ff_tag_add_field(mp4ff_metadata_t *tags, const char *item, const char *value);
|
|
274 int32_t mp4ff_tag_set_field(mp4ff_metadata_t *tags, const char *item, const char *value);
|
|
275 int32_t mp4ff_set_metadata_name(mp4ff_t *f, const uint8_t atom_type, char **name);
|
|
276 int32_t mp4ff_parse_tag(mp4ff_t *f, const uint8_t parent_atom_type, const int32_t size);
|
|
277 int32_t mp4ff_meta_find_by_name(const mp4ff_t *f, const char *item, char **value);
|
|
278 int32_t mp4ff_parse_metadata(mp4ff_t *f, const int32_t size);
|
|
279 int32_t mp4ff_tag_delete(mp4ff_metadata_t *tags);
|
|
280 int32_t mp4ff_meta_get_num_items(const mp4ff_t *f);
|
|
281 int32_t mp4ff_meta_get_by_index(const mp4ff_t *f, uint32_t index,
|
|
282 char **item, char **value);
|
|
283 int32_t mp4ff_meta_get_title(const mp4ff_t *f, char **value);
|
|
284 int32_t mp4ff_meta_get_artist(const mp4ff_t *f, char **value);
|
|
285 int32_t mp4ff_meta_get_writer(const mp4ff_t *f, char **value);
|
|
286 int32_t mp4ff_meta_get_album(const mp4ff_t *f, char **value);
|
|
287 int32_t mp4ff_meta_get_date(const mp4ff_t *f, char **value);
|
|
288 int32_t mp4ff_meta_get_tool(const mp4ff_t *f, char **value);
|
|
289 int32_t mp4ff_meta_get_comment(const mp4ff_t *f, char **value);
|
|
290 int32_t mp4ff_meta_get_genre(const mp4ff_t *f, char **value);
|
|
291 int32_t mp4ff_meta_get_track(const mp4ff_t *f, char **value);
|
|
292 int32_t mp4ff_meta_get_disc(const mp4ff_t *f, char **value);
|
|
293 int32_t mp4ff_meta_get_compilation(const mp4ff_t *f, char **value);
|
|
294 int32_t mp4ff_meta_get_tempo(const mp4ff_t *f, char **value);
|
|
295 int32_t mp4ff_meta_get_coverart(const mp4ff_t *f, char **value);
|
|
296 #endif
|
|
297
|
|
298 /* mp4ff.c */
|
|
299 mp4ff_t *mp4ff_open_read(mp4ff_callback_t *f);
|
|
300 #ifdef USE_TAGGING
|
|
301 mp4ff_t *mp4ff_open_edit(mp4ff_callback_t *f);
|
|
302 #endif
|
|
303 void mp4ff_close(mp4ff_t *ff);
|
|
304 void mp4ff_track_add(mp4ff_t *f);
|
|
305 int32_t parse_sub_atoms(mp4ff_t *f, const uint64_t total_size);
|
|
306 int32_t parse_atoms(mp4ff_t *f);
|
|
307
|
|
308 int32_t mp4ff_get_sample_duration(const mp4ff_t *f, const int32_t track, const int32_t sample);
|
|
309 int64_t mp4ff_get_sample_position(const mp4ff_t *f, const int32_t track, const int32_t sample);
|
|
310 int32_t mp4ff_get_sample_offset(const mp4ff_t *f, const int32_t track, const int32_t sample);
|
|
311 int32_t mp4ff_find_sample(const mp4ff_t *f, const int32_t track, const int64_t offset,int32_t * toskip);
|
|
312
|
|
313 int32_t mp4ff_read_sample(mp4ff_t *f, const int32_t track, const int32_t sample,
|
|
314 uint8_t **audio_buffer, uint32_t *bytes);
|
|
315 int32_t mp4ff_get_decoder_config(const mp4ff_t *f, const int32_t track,
|
|
316 uint8_t** ppBuf, uint32_t* pBufSize);
|
|
317 int32_t mp4ff_total_tracks(const mp4ff_t *f);
|
|
318 int32_t mp4ff_time_scale(const mp4ff_t *f, const int32_t track);
|
|
319 int32_t mp4ff_num_samples(const mp4ff_t *f, const int32_t track);
|
|
320
|
|
321 uint32_t mp4ff_meta_genre_to_index(const char * genrestr);//returns 1-based index, 0 if not found
|
|
322 const char * mp4ff_meta_index_to_genre(uint32_t idx);//returns pointer to string
|
|
323
|
|
324
|
|
325 #ifdef __cplusplus
|
|
326 }
|
|
327 #endif /* __cplusplus */
|
|
328
|
|
329 #endif
|