2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
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.
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.
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.
19 ** Any non-GPL usage of this software or parts of this software is strictly
22 ** Commercial non-GPL licensing of this software is possible.
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
25 ** $Id: mp4ffint.h,v 1.15 2004/01/14 20:50:22 menno Exp $
28 #ifndef MP4FF_INTERNAL_H
29 #define MP4FF_INTERNAL_H
33 #endif /* __cplusplus */
35 #include "mp4ff_int_types.h"
43 #define MAX_TRACKS 1024
44 #define TRACK_UNKNOWN 0
47 #define TRACK_SYSTEM 3
52 /* atoms without subatoms */
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 */
80 #define ATOM_UNKNOWN 255
81 #define ATOM_FREE ATOM_UNKNOWN
82 #define ATOM_SKIP ATOM_UNKNOWN
84 /* atoms with subatoms */
92 #define ATOM_ILST 8 /* iTunes Metadata list */
94 #define ATOM_ARTIST 10
95 #define ATOM_WRITER 11
99 #define ATOM_COMMENT 15
100 #define ATOM_GENRE1 16
101 #define ATOM_TRACK 17
103 #define ATOM_COMPILATION 19
104 #define ATOM_GENRE2 20
105 #define ATOM_TEMPO 21
106 #define ATOM_COVER 22
116 #define stricmp strcasecmp
119 /* file callback structure */
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
);
130 /* metadata tag structure */
137 /* metadata list structure */
148 int32_t channelCount
;
154 int32_t stsd_entry_count
;
157 int32_t stsz_sample_size
;
158 int32_t stsz_sample_count
;
162 int32_t stts_entry_count
;
163 int32_t *stts_sample_count
;
164 int32_t *stts_sample_delta
;
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
;
173 int32_t stco_entry_count
;
174 int32_t *stco_chunk_offset
;
177 int32_t ctts_entry_count
;
178 int32_t *ctts_sample_count
;
179 int32_t *ctts_sample_offset
;
182 uint8_t *decoderConfig
;
183 int32_t decoderConfigLen
;
198 /* mp4 main file structure */
201 /* stream to read from */
202 mp4ff_callback_t
*stream
;
203 int64_t current_position
;
206 uint64_t moov_offset
;
215 /* incremental track index while reading the file */
216 int32_t total_tracks
;
219 mp4ff_track_t
*track
[MAX_TRACKS
];
222 mp4ff_metadata_t tags
;
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
);
244 static int32_t mp4ff_atom_get_size(const int8_t *data
);
245 static 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 static 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 static int32_t mp4ff_read_stsz(mp4ff_t
*f
);
250 static int32_t mp4ff_read_esds(mp4ff_t
*f
);
251 static int32_t mp4ff_read_mp4a(mp4ff_t
*f
);
252 static int32_t mp4ff_read_stsd(mp4ff_t
*f
);
253 static int32_t mp4ff_read_stsc(mp4ff_t
*f
);
254 static int32_t mp4ff_read_stco(mp4ff_t
*f
);
255 static int32_t mp4ff_read_stts(mp4ff_t
*f
);
257 static int32_t mp4ff_read_meta(mp4ff_t
*f
, const uint64_t size
);
259 int32_t mp4ff_atom_read(mp4ff_t
*f
, const int32_t size
, const uint8_t atom_type
);
262 static 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 static int32_t mp4ff_chunk_to_offset(const mp4ff_t
*f
, const int32_t track
, const int32_t chunk
);
265 static 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 static 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
);
273 static int32_t mp4ff_tag_add_field(mp4ff_metadata_t
*tags
, const char *item
, const char *value
);
274 static int32_t mp4ff_tag_set_field(mp4ff_metadata_t
*tags
, const char *item
, const char *value
);
275 static int32_t mp4ff_set_metadata_name(mp4ff_t
*f
, const uint8_t atom_type
, char **name
);
276 static int32_t mp4ff_parse_tag(mp4ff_t
*f
, const uint8_t parent_atom_type
, const int32_t size
);
277 static 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
);
299 mp4ff_t
*mp4ff_open_read(mp4ff_callback_t
*f
);
301 mp4ff_t
*mp4ff_open_edit(mp4ff_callback_t
*f
);
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
);
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
);
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
);
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 static string
327 #endif /* __cplusplus */