ex

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mp4ffint.h Source File

mp4ffint.h

00001 /*
00002 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
00003 ** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
00004 **  
00005 ** This program is free software; you can redistribute it and/or modify
00006 ** it under the terms of the GNU General Public License as published by
00007 ** the Free Software Foundation; either version 2 of the License, or
00008 ** (at your option) any later version.
00009 ** 
00010 ** This program is distributed in the hope that it will be useful,
00011 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 ** GNU General Public License for more details.
00014 ** 
00015 ** You should have received a copy of the GNU General Public License
00016 ** along with this program; if not, write to the Free Software 
00017 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 **
00019 ** Any non-GPL usage of this software or parts of this software is strictly
00020 ** forbidden.
00021 **
00022 ** The "appropriate copyright message" mentioned in section 2c of the GPLv2
00023 ** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
00024 **
00025 ** Commercial non-GPL licensing of this software is possible.
00026 ** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
00027 **
00028 ** $Id: mp4ffint.h,v 1.26 2009/01/25 20:14:34 menno Exp $
00029 **/
00030 
00031 #ifndef MP4FF_INTERNAL_H
00032 #define MP4FF_INTERNAL_H
00033 
00034 #ifdef __cplusplus
00035 extern "C" {
00036 #endif /* __cplusplus */
00037 
00038 #include "mp4ff_int_types.h"
00039 #include <stdlib.h>
00040 
00041 //#define MAX_TRACKS 1024
00042 #define MAX_TRACKS 128  //modify by bolv
00043 #define TRACK_UNKNOWN 0
00044 #define TRACK_AUDIO   1
00045 #define TRACK_VIDEO   2
00046 #define TRACK_SYSTEM  3
00047 
00048 
00049 #define SUBATOMIC 128
00050 
00051 /* atoms without subatoms */
00052 #define ATOM_FTYP 129
00053 #define ATOM_MDAT 130
00054 #define ATOM_MVHD 131
00055 #define ATOM_TKHD 132
00056 #define ATOM_TREF 133
00057 #define ATOM_MDHD 134
00058 #define ATOM_VMHD 135
00059 #define ATOM_SMHD 136
00060 #define ATOM_HMHD 137
00061 #define ATOM_STSD 138
00062 #define ATOM_STTS 139
00063 #define ATOM_STSZ 140
00064 #define ATOM_STZ2 141
00065 #define ATOM_STCO 142
00066 #define ATOM_STSC 143
00067 #define ATOM_MP4A 144
00068 #define ATOM_MP4V 145
00069 #define ATOM_MP4S 146
00070 #define ATOM_ESDS 147
00071 #define ATOM_META 148 /* iTunes Metadata box */
00072 #define ATOM_NAME 149 /* iTunes Metadata name box */
00073 #define ATOM_DATA 150 /* iTunes Metadata data box */
00074 #define ATOM_CTTS 151
00075 #define ATOM_FRMA 152
00076 #define ATOM_IVIV 153
00077 #define ATOM_PRIV 154
00078 #define ATOM_USER 155
00079 #define ATOM_KEY  156
00080 
00081 #define ATOM_ALBUM_ARTIST   157
00082 #define ATOM_CONTENTGROUP   158
00083 #define ATOM_LYRICS         159
00084 #define ATOM_DESCRIPTION    160
00085 #define ATOM_NETWORK        161
00086 #define ATOM_SHOW           162
00087 #define ATOM_EPISODENAME    163
00088 #define ATOM_SORTTITLE      164
00089 #define ATOM_SORTALBUM      165
00090 #define ATOM_SORTARTIST     166
00091 #define ATOM_SORTALBUMARTIST    167
00092 #define ATOM_SORTWRITER     168
00093 #define ATOM_SORTSHOW       169
00094 #define ATOM_SEASON         170
00095 #define ATOM_EPISODE        171
00096 #define ATOM_PODCAST        172
00097 
00098 #define ATOM_UNKNOWN 255
00099 #define ATOM_FREE ATOM_UNKNOWN
00100 #define ATOM_SKIP ATOM_UNKNOWN
00101 
00102 /* atoms with subatoms */
00103 #define ATOM_MOOV 1
00104 #define ATOM_TRAK 2
00105 #define ATOM_EDTS 3
00106 #define ATOM_MDIA 4
00107 #define ATOM_MINF 5
00108 #define ATOM_STBL 6
00109 #define ATOM_UDTA 7
00110 #define ATOM_ILST 8 /* iTunes Metadata list */
00111 #define ATOM_TITLE 9
00112 #define ATOM_ARTIST 10
00113 #define ATOM_WRITER 11
00114 #define ATOM_ALBUM 12
00115 #define ATOM_DATE 13
00116 #define ATOM_TOOL 14
00117 #define ATOM_COMMENT 15
00118 #define ATOM_GENRE1 16
00119 #define ATOM_TRACK 17
00120 #define ATOM_DISC 18
00121 #define ATOM_COMPILATION 19
00122 #define ATOM_GENRE2 20
00123 #define ATOM_TEMPO 21
00124 #define ATOM_COVER 22
00125 #define ATOM_DRMS 23
00126 #define ATOM_SINF 24
00127 #define ATOM_SCHI 25
00128 
00129 #ifdef HAVE_CONFIG_H
00130 #include "../../config.h"   
00131 #endif
00132 
00133 #if !(defined(_WIN32) || defined(_WIN32_WCE))
00134 #define stricmp strcasecmp
00135 #else
00136 #define stricmp _stricmp
00137 #define strdup _strdup
00138 #endif
00139 
00140 /* file callback structure */
00141 typedef struct
00142 {
00143     uint32_t (*read)(void *user_data, void *buffer, uint32_t length);
00144     uint32_t (*write)(void *udata, void *buffer, uint32_t length);
00145     uint32_t (*seek)(void *user_data, uint64_t position);
00146     uint32_t (*truncate)(void *user_data);
00147     void *user_data;
00148 } mp4ff_callback_t;
00149 
00150 
00151 /* metadata tag structure */
00152 typedef struct
00153 {
00154     char *item;
00155     char *value;
00156 } mp4ff_tag_t;
00157 
00158 /* metadata list structure */
00159 typedef struct
00160 {
00161     mp4ff_tag_t *tags;
00162     uint32_t count;
00163 } mp4ff_metadata_t;
00164 
00165 
00166 typedef struct
00167 {
00168     int32_t type;
00169     int32_t channelCount;
00170     int32_t sampleSize;
00171     uint16_t sampleRate;
00172     int32_t audioType;
00173 
00174     /* stsd */
00175     int32_t stsd_entry_count;
00176 
00177     /* stsz */
00178     int32_t stsz_sample_size;
00179     int32_t stsz_sample_count;
00180     int32_t *stsz_table;
00181     /*  add by bolv  */
00182     int32_t stsz_table_offset;//the offset of the start of stsz_table into the file
00183     /*  add by bolv  */
00184 
00185     /* stts */
00186     int32_t stts_entry_count;
00187     int32_t *stts_sample_count;
00188     int32_t *stts_sample_delta;
00189 
00190     /* stsc */
00191     int32_t stsc_entry_count;
00192     int32_t *stsc_first_chunk;
00193     int32_t *stsc_samples_per_chunk;
00194     int32_t *stsc_sample_desc_index;
00195 
00196     /* stco */
00197     int32_t stco_entry_count;
00198     int32_t *stco_chunk_offset;
00199     /*  add by bolv  */
00200     int32_t stco_current_chunk;  //Current chunk ID,the minimum is 1
00201     int32_t stco_current_chunk_first_sample;
00202     int32_t stco_current_chunk_samples;
00203     int32_t stco_current_chunk_offset;
00204     /*  add by bolv  */
00205 
00206     /* ctts */
00207     int32_t ctts_entry_count;
00208     int32_t *ctts_sample_count;
00209     int32_t *ctts_sample_offset;
00210 
00211     /* esde */
00212     uint8_t *decoderConfig;
00213     int32_t decoderConfigLen;
00214 
00215     uint32_t maxBitrate;
00216     uint32_t avgBitrate;
00217 
00218     uint32_t timeScale;
00219     uint64_t duration;
00220 
00221 } mp4ff_track_t;
00222 
00223 /* mp4 main file structure */
00224 typedef struct
00225 {
00226     /* stream to read from */
00227     mp4ff_callback_t *stream;
00228     int64_t current_position;
00229     int64_t last_position;//add by bolv
00230 
00231     int32_t moov_read;
00232     uint64_t moov_offset;
00233     uint64_t moov_size;
00234     uint8_t last_atom;
00235     uint64_t file_size;
00236 
00237     /* mvhd */
00238     int32_t time_scale;
00239     int32_t duration;
00240 
00241     /* incremental track index while reading the file */
00242     int32_t total_tracks;
00243 
00244     /* track data */
00245     mp4ff_track_t *track[MAX_TRACKS];
00246 
00247     /* metadata */
00248     mp4ff_metadata_t tags;
00249 } mp4ff_t;
00250 
00251 
00252 
00253 
00254 /* mp4util.c */
00255 int32_t mp4ff_read_data(mp4ff_t *f, int8_t *data, uint32_t size);
00256 int32_t mp4ff_write_data(mp4ff_t *f, int8_t *data, uint32_t size);
00257 uint64_t mp4ff_read_int64(mp4ff_t *f);
00258 uint32_t mp4ff_read_int32(mp4ff_t *f);
00259 uint32_t mp4ff_read_int24(mp4ff_t *f);
00260 uint16_t mp4ff_read_int16(mp4ff_t *f);
00261 uint8_t mp4ff_read_char(mp4ff_t *f);
00262 int32_t mp4ff_write_int32(mp4ff_t *f,const uint32_t data);
00263 uint32_t mp4ff_read_mp4_descr_length(mp4ff_t *f);
00264 int64_t mp4ff_position(const mp4ff_t *f);
00265 int32_t mp4ff_set_position(mp4ff_t *f, const int64_t position);
00266 int32_t mp4ff_truncate(mp4ff_t * f);
00267 char * mp4ff_read_string(mp4ff_t * f,uint32_t length);
00268 
00269 /* mp4atom.c */
00270 static int32_t mp4ff_atom_get_size(const int8_t *data);
00271 static int32_t mp4ff_atom_compare(const int8_t a1, const int8_t b1, const int8_t c1, const int8_t d1,
00272                                   const int8_t a2, const int8_t b2, const int8_t c2, const int8_t d2);
00273 static uint8_t mp4ff_atom_name_to_type(const int8_t a, const int8_t b, const int8_t c, const int8_t d);
00274 uint64_t mp4ff_atom_read_header(mp4ff_t *f, uint8_t *atom_type, uint8_t *header_size);
00275 static int32_t mp4ff_read_stsz(mp4ff_t *f);
00276 static int32_t rda_mp4ff_read_stsz(mp4ff_t *f);//add by bolv
00277 static int32_t mp4ff_read_esds(mp4ff_t *f);
00278 static int32_t mp4ff_read_mp4a(mp4ff_t *f);
00279 static int32_t mp4ff_read_stsd(mp4ff_t *f);
00280 static int32_t mp4ff_read_stsc(mp4ff_t *f);
00281 static int32_t mp4ff_read_stco(mp4ff_t *f);
00282 static int32_t mp4ff_read_stts(mp4ff_t *f);
00283 #ifdef USE_TAGGING
00284 static int32_t mp4ff_read_meta(mp4ff_t *f, const uint64_t size);
00285 #endif
00286 int32_t mp4ff_atom_read(mp4ff_t *f, const int32_t size, const uint8_t atom_type);
00287 
00288 /* mp4sample.c */
00289 static int32_t mp4ff_chunk_of_sample(const mp4ff_t *f, const int32_t track, const int32_t sample,
00290                                      int32_t *chunk_sample, int32_t *chunk);
00291 int32_t rda_mp4ff_chunk_of_sample(const mp4ff_t *f, const int32_t track, const int32_t sample);//add by bolv
00292 
00293 static int32_t mp4ff_chunk_to_offset(const mp4ff_t *f, const int32_t track, const int32_t chunk);
00294 int32_t rda_mp4ff_chunk_to_offset(const mp4ff_t *f, const int32_t track, const int32_t chunk);//add by bolv
00295 static int32_t mp4ff_sample_range_size(const mp4ff_t *f, const int32_t track,
00296                                        const int32_t chunk_sample, const int32_t sample);
00297 static int32_t rda_mp4ff_sample_range_size(const mp4ff_t *f, const int32_t track,
00298                                        const int32_t chunk_sample, const int32_t sample);//add by bolv
00299 static int32_t mp4ff_sample_to_offset(const mp4ff_t *f, const int32_t track, const int32_t sample);
00300 int32_t mp4ff_audio_frame_size(const mp4ff_t *f, const int32_t track, const int32_t sample);
00301 int32_t rda_mp4ff_audio_frame_size(const mp4ff_t *f, const int32_t track, const int32_t sample);//add by bolv
00302 int32_t mp4ff_set_sample_position(mp4ff_t *f, const int32_t track, const int32_t sample);
00303 int32_t rda_mp4ff_set_sample_position(mp4ff_t *f, const int32_t track, const int32_t sample);//add by bolv
00304 int32_t rda_mp4ff_get_sample_position_and_size(mp4ff_t *f, const int32_t track, const int32_t sample, int32_t *offset, int32_t *size);//add by bolv
00305 
00306 #ifdef USE_TAGGING
00307 /* mp4meta.c */
00308 static int32_t mp4ff_tag_add_field(mp4ff_metadata_t *tags, const char *item, const char *value);
00309 static int32_t mp4ff_tag_set_field(mp4ff_metadata_t *tags, const char *item, const char *value);
00310 static int32_t mp4ff_set_metadata_name(mp4ff_t *f, const uint8_t atom_type, char **name);
00311 static int32_t mp4ff_parse_tag(mp4ff_t *f, const uint8_t parent_atom_type, const int32_t size);
00312 static int32_t mp4ff_meta_find_by_name(const mp4ff_t *f, const char *item, char **value);
00313 int32_t mp4ff_parse_metadata(mp4ff_t *f, const int32_t size);
00314 int32_t mp4ff_tag_delete(mp4ff_metadata_t *tags);
00315 int32_t mp4ff_meta_get_num_items(const mp4ff_t *f);
00316 int32_t mp4ff_meta_get_by_index(const mp4ff_t *f, uint32_t index,
00317                             char **item, char **value);
00318 int32_t mp4ff_meta_get_title(const mp4ff_t *f, char **value);
00319 int32_t mp4ff_meta_get_artist(const mp4ff_t *f, char **value);
00320 int32_t mp4ff_meta_get_writer(const mp4ff_t *f, char **value);
00321 int32_t mp4ff_meta_get_album(const mp4ff_t *f, char **value);
00322 int32_t mp4ff_meta_get_date(const mp4ff_t *f, char **value);
00323 int32_t mp4ff_meta_get_tool(const mp4ff_t *f, char **value);
00324 int32_t mp4ff_meta_get_comment(const mp4ff_t *f, char **value);
00325 int32_t mp4ff_meta_get_genre(const mp4ff_t *f, char **value);
00326 int32_t mp4ff_meta_get_track(const mp4ff_t *f, char **value);
00327 int32_t mp4ff_meta_get_disc(const mp4ff_t *f, char **value);
00328 int32_t mp4ff_meta_get_compilation(const mp4ff_t *f, char **value);
00329 int32_t mp4ff_meta_get_tempo(const mp4ff_t *f, char **value);
00330 int32_t mp4ff_meta_get_coverart(const mp4ff_t *f, char **value);
00331 #endif
00332 
00333 /* mp4ff.c */
00334 mp4ff_t *mp4ff_open_read(mp4ff_callback_t *f);
00335 #ifdef USE_TAGGING
00336 mp4ff_t *mp4ff_open_edit(mp4ff_callback_t *f);
00337 #endif
00338 void mp4ff_close(mp4ff_t *ff);
00339 //void mp4ff_track_add(mp4ff_t *f);
00340 int32_t parse_sub_atoms(mp4ff_t *f, const uint64_t total_size,int meta_only);
00341 int32_t parse_atoms(mp4ff_t *f,int meta_only);
00342 
00343 int32_t mp4ff_get_sample_duration(const mp4ff_t *f, const int32_t track, const int32_t sample);
00344 int64_t mp4ff_get_sample_position(const mp4ff_t *f, const int32_t track, const int32_t sample);
00345 int32_t mp4ff_get_sample_offset(const mp4ff_t *f, const int32_t track, const int32_t sample);
00346 int32_t mp4ff_find_sample(const mp4ff_t *f, const int32_t track, const int64_t offset,int32_t * toskip);
00347 
00348 int32_t mp4ff_read_sample(mp4ff_t *f, const int32_t track, const int32_t sample,
00349                           uint8_t **audio_buffer,  uint32_t *bytes);
00350 int32_t rda_mp4ff_read_sample(mp4ff_t *f, const int32_t track, const int32_t sample,
00351                           uint8_t **audio_buffer,  uint32_t *bytes);//add by bolv
00352 int32_t rda_mp4ff_read_sample_adts(mp4ff_t *f, const int32_t track, const int32_t sample,
00353                           uint8_t **audio_buffer,  uint32_t *bytes);//add by bolv
00354 int32_t mp4ff_get_decoder_config(const mp4ff_t *f, const int32_t track,
00355                                  uint8_t** ppBuf, uint32_t* pBufSize);
00356 int32_t mp4ff_total_tracks(const mp4ff_t *f);
00357 int32_t rda_mp4ff_get_aac_track(const mp4ff_t *f);//add by bolv
00358 int32_t mp4ff_time_scale(const mp4ff_t *f, const int32_t track);
00359 int32_t mp4ff_num_samples(const mp4ff_t *f, const int32_t track);
00360 
00361 uint32_t mp4ff_meta_genre_to_index(const char * genrestr);//returns 1-based index, 0 if not found
00362 const char * mp4ff_meta_index_to_genre(uint32_t idx);//returns pointer to static string
00363 
00364 
00365 #ifdef __cplusplus
00366 }
00367 #endif /* __cplusplus */
00368 
00369 #endif