From: Andre Noll Date: Mon, 9 Aug 2021 21:55:12 +0000 (+0200) Subject: mp4: Avoid typedefs for data structures. X-Git-Tag: v0.7.1~7^2~113 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=66491ab8498a5b57930fae018d0022579c2c17bb;p=paraslash.git mp4: Avoid typedefs for data structures. They only obfuscate the type. --- diff --git a/aac_afh.c b/aac_afh.c index c2daf5b5..dd9247d7 100644 --- a/aac_afh.c +++ b/aac_afh.c @@ -23,9 +23,9 @@ struct aac_afh_context { size_t mapsize; size_t fpos; int32_t track; - mp4ff_t *mp4ff; + struct mp4ff *mp4ff; mp4AudioSpecificConfig masc; - mp4ff_callback_t cb; + struct mp4ff_callback cb; }; static uint32_t aac_afh_read_cb(void *user_data, void *dest, uint32_t want) @@ -50,7 +50,7 @@ static uint32_t aac_afh_seek_cb(void *user_data, uint64_t pos) return 0; } -static int32_t aac_afh_get_track(mp4ff_t *mp4ff, mp4AudioSpecificConfig *masc) +static int32_t aac_afh_get_track(struct mp4ff *mp4ff, mp4AudioSpecificConfig *masc) { int32_t i, rc, num_tracks = mp4ff_total_tracks(mp4ff); @@ -127,7 +127,7 @@ static int aac_afh_get_chunk(uint32_t chunk_num, void *afh_context, return 1; } -static void _aac_afh_get_taginfo(const mp4ff_t *mp4ff, struct taginfo *tags) +static void _aac_afh_get_taginfo(const struct mp4ff *mp4ff, struct taginfo *tags) { mp4ff_meta_get_artist(mp4ff, &tags->artist); mp4ff_meta_get_title(mp4ff, &tags->title); @@ -216,14 +216,14 @@ static uint32_t aac_afh_meta_truncate_cb(void *user_data) return ftruncate(fd, offset); } -static void replace_tag(mp4ff_tag_t *tag, const char *new_val, bool *found) +static void replace_tag(struct mp4ff_tag *tag, const char *new_val, bool *found) { free(tag->value); tag->value = para_strdup(new_val); *found = true; } -static void add_tag(mp4ff_metadata_t *md, const char *item, const char *value) +static void add_tag(struct mp4ff_metadata *md, const char *item, const char *value) { md->tags[md->count].item = para_strdup(item); md->tags[md->count].value = para_strdup(value); @@ -235,9 +235,9 @@ static int aac_afh_rewrite_tags(const char *map, size_t mapsize, { int ret, i; int32_t rv; - mp4ff_metadata_t metadata; - mp4ff_t *mp4ff; - mp4ff_callback_t cb = { + struct mp4ff_metadata metadata; + struct mp4ff *mp4ff; + struct mp4ff_callback cb = { .read = aac_afh_meta_read_cb, .seek = aac_afh_meta_seek_cb, .write = aac_afh_meta_write_cb, @@ -263,9 +263,9 @@ static int aac_afh_rewrite_tags(const char *map, size_t mapsize, metadata.count = rv; PARA_NOTICE_LOG("%d metadata item(s) found\n", rv); - metadata.tags = para_malloc((metadata.count + 5) * sizeof(mp4ff_tag_t)); + metadata.tags = para_malloc((metadata.count + 5) * sizeof(struct mp4ff_tag)); for (i = 0; i < metadata.count; i++) { - mp4ff_tag_t *tag = metadata.tags + i; + struct mp4ff_tag *tag = metadata.tags + i; ret = -E_MP4FF_META_READ; if (!mp4ff_meta_get_by_index(mp4ff, i, &tag->item, &tag->value)) diff --git a/mp4.c b/mp4.c index 345775b2..b6fbabcd 100644 --- a/mp4.c +++ b/mp4.c @@ -12,12 +12,12 @@ #include "string.h" #include "mp4.h" -int32_t mp4ff_total_tracks(const mp4ff_t * f) +int32_t mp4ff_total_tracks(const struct mp4ff *f) { return f->total_tracks; } -static int32_t read_data(mp4ff_t * f, void *data, uint32_t size) +static int32_t read_data(struct mp4ff *f, void *data, uint32_t size) { int32_t result = 1; @@ -31,7 +31,7 @@ static int32_t read_data(mp4ff_t * f, void *data, uint32_t size) return result; } -static uint64_t read_int64(mp4ff_t * f) +static uint64_t read_int64(struct mp4ff *f) { uint8_t data[8]; @@ -298,7 +298,7 @@ static uint8_t atom_name_to_type(const int8_t a, const int8_t b, } /* read atom header, return atom size, atom size is with header included */ -static uint64_t atom_read_header(mp4ff_t * f, uint8_t * atom_type, +static uint64_t atom_read_header(struct mp4ff *f, uint8_t * atom_type, uint8_t * header_size) { uint64_t size; @@ -322,7 +322,7 @@ static uint64_t atom_read_header(mp4ff_t * f, uint8_t * atom_type, return size; } -static int64_t get_position(const mp4ff_t * f) +static int64_t get_position(const struct mp4ff *f) { return f->current_position; } @@ -348,7 +348,7 @@ static int need_parse_when_meta_only(uint8_t atom_type) } } -static int32_t set_position(mp4ff_t * f, const int64_t position) +static int32_t set_position(struct mp4ff *f, const int64_t position) { f->stream->seek(f->stream->user_data, position); f->current_position = position; @@ -356,7 +356,7 @@ static int32_t set_position(mp4ff_t * f, const int64_t position) return 0; } -static void track_add(mp4ff_t * f) +static void track_add(struct mp4ff *f) { f->total_tracks++; @@ -365,17 +365,17 @@ static void track_add(mp4ff_t * f) f->error++; return; } - f->track[f->total_tracks - 1] = para_calloc(sizeof (mp4ff_track_t)); + f->track[f->total_tracks - 1] = para_calloc(sizeof(struct mp4ff_track)); } -static uint8_t read_char(mp4ff_t * f) +static uint8_t read_char(struct mp4ff *f) { uint8_t output; read_data(f, &output, 1); return output; } -static uint32_t read_int24(mp4ff_t * f) +static uint32_t read_int24(struct mp4ff *f) { int8_t data[4]; @@ -383,7 +383,7 @@ static uint32_t read_int24(mp4ff_t * f) return read_u24_be(data); } -static uint32_t read_int32(mp4ff_t * f) +static uint32_t read_int32(struct mp4ff *f) { int8_t data[4]; @@ -391,10 +391,10 @@ static uint32_t read_int32(mp4ff_t * f) return read_u32_be(data); } -static int32_t read_stsz(mp4ff_t * f) +static int32_t read_stsz(struct mp4ff *f) { int32_t i; - mp4ff_track_t *t; + struct mp4ff_track *t; if (f->total_tracks == 0) return f->error++; @@ -411,10 +411,10 @@ static int32_t read_stsz(mp4ff_t * f) return 0; } -static int32_t read_stts(mp4ff_t * f) +static int32_t read_stts(struct mp4ff *f) { int32_t i; - mp4ff_track_t *t; + struct mp4ff_track *t; /* CVE-2017-9223 */ if (f->total_tracks == 0) @@ -438,10 +438,10 @@ static int32_t read_stts(mp4ff_t * f) return 1; } -static int32_t read_ctts(mp4ff_t * f) +static int32_t read_ctts(struct mp4ff *f) { int32_t i; - mp4ff_track_t *t; + struct mp4ff_track *t; if (f->total_tracks == 0) return f->error++; @@ -466,10 +466,10 @@ static int32_t read_ctts(mp4ff_t * f) return 1; } -static int32_t read_stsc(mp4ff_t * f) +static int32_t read_stsc(struct mp4ff *f) { int32_t i; - mp4ff_track_t *t; + struct mp4ff_track *t; if (f->total_tracks == 0) return f->error++; @@ -493,10 +493,10 @@ static int32_t read_stsc(mp4ff_t * f) return 0; } -static int32_t read_stco(mp4ff_t * f) +static int32_t read_stco(struct mp4ff *f) { int32_t i; - mp4ff_track_t *t; + struct mp4ff_track *t; if (f->total_tracks == 0) return f->error++; @@ -513,7 +513,7 @@ static int32_t read_stco(mp4ff_t * f) return 0; } -static uint16_t read_int16(mp4ff_t * f) +static uint16_t read_int16(struct mp4ff *f) { int8_t data[2]; @@ -521,7 +521,7 @@ static uint16_t read_int16(mp4ff_t * f) return read_u16_be(data); } -static uint32_t read_mp4_descr_length(mp4ff_t * f) +static uint32_t read_mp4_descr_length(struct mp4ff *f) { uint8_t b; uint8_t numBytes = 0; @@ -535,11 +535,11 @@ static uint32_t read_mp4_descr_length(mp4ff_t * f) return length; } -static int32_t read_esds(mp4ff_t * f) +static int32_t read_esds(struct mp4ff *f) { uint8_t tag; uint32_t temp; - mp4ff_track_t *t; + struct mp4ff_track *t; if (f->total_tracks == 0) return f->error++; @@ -589,12 +589,12 @@ static int32_t read_esds(mp4ff_t * f) return 0; } -static int32_t read_mp4a(mp4ff_t * f) +static int32_t read_mp4a(struct mp4ff *f) { int32_t i; uint8_t atom_type = 0; uint8_t header_size = 0; - mp4ff_track_t *t; + struct mp4ff_track *t; if (f->total_tracks == 0) return f->error++; @@ -624,11 +624,11 @@ static int32_t read_mp4a(mp4ff_t * f) return 0; } -static int32_t read_stsd(mp4ff_t * f) +static int32_t read_stsd(struct mp4ff *f) { int32_t i; uint8_t header_size = 0; - mp4ff_track_t *t; + struct mp4ff_track *t; /* CVE-2017-9218 */ if (f->total_tracks == 0) @@ -664,7 +664,7 @@ static int32_t read_stsd(mp4ff_t * f) return 0; } -static int32_t read_mvhd(mp4ff_t * f) +static int32_t read_mvhd(struct mp4ff *f) { int32_t i; @@ -690,7 +690,7 @@ static int32_t read_mvhd(mp4ff_t * f) return 0; } -static int32_t tag_add_field(mp4ff_metadata_t * tags, const char *item, +static int32_t tag_add_field(struct mp4ff_metadata *tags, const char *item, const char *value, int32_t len) { void *backup = (void *) tags->tags; @@ -698,8 +698,8 @@ static int32_t tag_add_field(mp4ff_metadata_t * tags, const char *item, if (!item || (item && !*item) || !value) return 0; - tags->tags = (mp4ff_tag_t *) realloc(tags->tags, - (tags->count + 1) * sizeof (mp4ff_tag_t)); + tags->tags = (struct mp4ff_tag *)realloc(tags->tags, + (tags->count + 1) * sizeof(struct mp4ff_tag)); if (!tags->tags) { free(backup); return 0; @@ -758,7 +758,7 @@ static const char *meta_index_to_genre(uint32_t idx) } } -static char *read_string(mp4ff_t *f, uint32_t length) +static char *read_string(struct mp4ff *f, uint32_t length) { char *str = para_malloc(length + 1); if ((uint32_t)read_data(f, str, length) != length) { @@ -906,7 +906,7 @@ static uint32_t min_body_size(const uint8_t atom_type) } } -static int32_t parse_tag(mp4ff_t * f, const uint8_t parent, +static int32_t parse_tag(struct mp4ff *f, const uint8_t parent, const int32_t size) { uint8_t atom_type; @@ -998,10 +998,10 @@ static int32_t parse_tag(mp4ff_t * f, const uint8_t parent, return 1; } -static int32_t read_mdhd(mp4ff_t * f) +static int32_t read_mdhd(struct mp4ff *f) { uint32_t version; - mp4ff_track_t *t; + struct mp4ff_track *t; /* CVE-2017-9221 */ if (f->total_tracks == 0) @@ -1029,7 +1029,7 @@ static int32_t read_mdhd(mp4ff_t * f) return 1; } -static int32_t parse_metadata(mp4ff_t * f, const int32_t size) +static int32_t parse_metadata(struct mp4ff *f, const int32_t size) { uint64_t subsize, sumsize = 0; uint8_t atom_type; @@ -1046,7 +1046,7 @@ static int32_t parse_metadata(mp4ff_t * f, const int32_t size) return 0; } -static int32_t read_meta(mp4ff_t * f, const uint64_t size) +static int32_t read_meta(struct mp4ff *f, const uint64_t size) { uint64_t subsize, sumsize = 0; uint8_t atom_type; @@ -1070,7 +1070,7 @@ static int32_t read_meta(mp4ff_t * f, const uint64_t size) return 0; } -static int32_t atom_read(mp4ff_t *f, const int32_t size, +static int32_t atom_read(struct mp4ff *f, const int32_t size, const uint8_t atom_type) { uint64_t dest_position = get_position(f) + size - 8; @@ -1108,7 +1108,7 @@ static int32_t atom_read(mp4ff_t *f, const int32_t size, } /* parse atoms that are sub atoms of other atoms */ -static int32_t parse_sub_atoms(mp4ff_t * f, const uint64_t total_size, int meta_only) +static int32_t parse_sub_atoms(struct mp4ff *f, const uint64_t total_size, int meta_only) { uint64_t size; uint8_t atom_type = 0; @@ -1142,7 +1142,7 @@ static int32_t parse_sub_atoms(mp4ff_t * f, const uint64_t total_size, int meta_ } /* parse root atoms */ -static int32_t parse_atoms(mp4ff_t * f, int meta_only) +static int32_t parse_atoms(struct mp4ff *f, int meta_only) { uint64_t size; uint8_t atom_type = 0; @@ -1175,7 +1175,7 @@ static int32_t parse_atoms(mp4ff_t * f, int meta_only) return 0; } -void mp4ff_get_decoder_config(const mp4ff_t * f, const int track, +void mp4ff_get_decoder_config(const struct mp4ff *f, const int track, unsigned char **ppBuf, unsigned int *pBufSize) { if (track >= f->total_tracks) { @@ -1196,9 +1196,9 @@ void mp4ff_get_decoder_config(const mp4ff_t * f, const int track, } } -mp4ff_t *mp4ff_open_read(mp4ff_callback_t * f) +struct mp4ff *mp4ff_open_read(struct mp4ff_callback *f) { - mp4ff_t *ff = para_calloc(sizeof(mp4ff_t)); + struct mp4ff *ff = para_calloc(sizeof(struct mp4ff)); ff->stream = f; @@ -1212,7 +1212,7 @@ mp4ff_t *mp4ff_open_read(mp4ff_callback_t * f) return ff; } -static int32_t tag_delete(mp4ff_metadata_t * tags) +static int32_t tag_delete(struct mp4ff_metadata *tags) { uint32_t i; @@ -1227,7 +1227,7 @@ static int32_t tag_delete(mp4ff_metadata_t * tags) return 0; } -void mp4ff_close(mp4ff_t * ff) +void mp4ff_close(struct mp4ff *ff) { int32_t i; @@ -1251,7 +1251,7 @@ void mp4ff_close(mp4ff_t * ff) free(ff); } -static int32_t chunk_of_sample(const mp4ff_t * f, const int32_t track, +static int32_t chunk_of_sample(const struct mp4ff *f, const int32_t track, const int32_t sample, int32_t * chunk_sample, int32_t * chunk) { int32_t total_entries = 0; @@ -1297,10 +1297,10 @@ static int32_t chunk_of_sample(const mp4ff_t * f, const int32_t track, return 0; } -static int32_t chunk_to_offset(const mp4ff_t * f, const int32_t track, +static int32_t chunk_to_offset(const struct mp4ff *f, const int32_t track, const int32_t chunk) { - const mp4ff_track_t *p_track = f->track[track]; + const struct mp4ff_track *p_track = f->track[track]; if (p_track->stco_entry_count && (chunk > p_track->stco_entry_count)) { return p_track->stco_chunk_offset[p_track->stco_entry_count - @@ -1314,11 +1314,11 @@ static int32_t chunk_to_offset(const mp4ff_t * f, const int32_t track, return 0; } -static int32_t sample_range_size(const mp4ff_t * f, const int32_t track, +static int32_t sample_range_size(const struct mp4ff *f, const int32_t track, const int32_t chunk_sample, const int32_t sample) { int32_t i, total; - const mp4ff_track_t *p_track = f->track[track]; + const struct mp4ff_track *p_track = f->track[track]; if (p_track->stsz_sample_size) { return (sample - chunk_sample) * p_track->stsz_sample_size; @@ -1334,7 +1334,7 @@ static int32_t sample_range_size(const mp4ff_t * f, const int32_t track, return total; } -static int32_t sample_to_offset(const mp4ff_t * f, const int32_t track, +static int32_t sample_to_offset(const struct mp4ff *f, const int32_t track, const int32_t sample) { int32_t chunk, chunk_sample, chunk_offset1, chunk_offset2; @@ -1347,33 +1347,33 @@ static int32_t sample_to_offset(const mp4ff_t * f, const int32_t track, return chunk_offset2; } -void mp4ff_set_sample_position(mp4ff_t *f, const int32_t track, +void mp4ff_set_sample_position(struct mp4ff *f, const int32_t track, const int32_t sample) { int32_t offset = sample_to_offset(f, track, sample); set_position(f, offset); } -int32_t mp4ff_get_sample_size(const mp4ff_t *f, int track, int sample) +int32_t mp4ff_get_sample_size(const struct mp4ff *f, int track, int sample) { - const mp4ff_track_t *t = f->track[track]; + const struct mp4ff_track *t = f->track[track]; if (t->stsz_sample_size != 0) return t->stsz_sample_size; return t->stsz_table[sample]; } -uint32_t mp4ff_get_sample_rate(const mp4ff_t * f, const int32_t track) +uint32_t mp4ff_get_sample_rate(const struct mp4ff *f, const int32_t track) { return f->track[track]->sampleRate; } -uint32_t mp4ff_get_channel_count(const mp4ff_t * f, const int32_t track) +uint32_t mp4ff_get_channel_count(const struct mp4ff *f, const int32_t track) { return f->track[track]->channelCount; } -int32_t mp4ff_num_samples(const mp4ff_t * f, const int32_t track) +int32_t mp4ff_num_samples(const struct mp4ff *f, const int32_t track) { int32_t i; int32_t total = 0; @@ -1384,9 +1384,9 @@ int32_t mp4ff_num_samples(const mp4ff_t * f, const int32_t track) return total; } -mp4ff_t *mp4ff_open_read_metaonly(mp4ff_callback_t * f) +struct mp4ff *mp4ff_open_read_metaonly(struct mp4ff_callback *f) { - mp4ff_t *ff = para_calloc(sizeof(mp4ff_t)); + struct mp4ff *ff = para_calloc(sizeof(struct mp4ff)); ff->stream = f; @@ -1400,12 +1400,12 @@ mp4ff_t *mp4ff_open_read_metaonly(mp4ff_callback_t * f) return ff; } -int32_t mp4ff_meta_get_num_items(const mp4ff_t * f) +int32_t mp4ff_meta_get_num_items(const struct mp4ff *f) { return f->tags.count; } -int32_t mp4ff_meta_get_by_index(const mp4ff_t * f, uint32_t index, +int32_t mp4ff_meta_get_by_index(const struct mp4ff *f, uint32_t index, char **item, char **value) { if (index >= f->tags.count) { @@ -1419,7 +1419,7 @@ int32_t mp4ff_meta_get_by_index(const mp4ff_t * f, uint32_t index, } } -static uint32_t find_atom(mp4ff_t * f, uint64_t base, uint32_t size, +static uint32_t find_atom(struct mp4ff *f, uint64_t base, uint32_t size, const char *name) { uint32_t remaining = size; @@ -1448,7 +1448,7 @@ static uint32_t find_atom(mp4ff_t * f, uint64_t base, uint32_t size, return 0; } -static uint32_t find_atom_v2(mp4ff_t * f, uint64_t base, uint32_t size, +static uint32_t find_atom_v2(struct mp4ff *f, uint64_t base, uint32_t size, const char *name, uint32_t extraheaders, const char *name_inside) { uint64_t first_base = (uint64_t) (-1); @@ -1484,20 +1484,20 @@ static uint32_t find_atom_v2(mp4ff_t * f, uint64_t base, uint32_t size, return 0; } -typedef struct { +struct membuffer { void *data; unsigned written; unsigned allocated; unsigned error; -} membuffer; +}; #define stricmp strcasecmp -static membuffer *membuffer_create(void) +static struct membuffer *membuffer_create(void) { const unsigned initial_size = 256; - membuffer *buf = para_malloc(sizeof (membuffer)); + struct membuffer *buf = para_malloc(sizeof(*buf)); buf->data = para_malloc(initial_size); buf->written = 0; buf->allocated = initial_size; @@ -1506,7 +1506,7 @@ static membuffer *membuffer_create(void) return buf; } -static unsigned membuffer_write(membuffer * buf, const void *ptr, unsigned bytes) +static unsigned membuffer_write(struct membuffer *buf, const void *ptr, unsigned bytes) { unsigned dest_size = buf->written + bytes; @@ -1535,12 +1535,12 @@ static unsigned membuffer_write(membuffer * buf, const void *ptr, unsigned bytes return bytes; } -static unsigned membuffer_write_atom_name(membuffer * buf, const char *data) +static unsigned membuffer_write_atom_name(struct membuffer *buf, const char *data) { return membuffer_write(buf, data, 4) == 4 ? 1 : 0; } -static unsigned membuffer_write_int16(membuffer * buf, uint16_t data) +static unsigned membuffer_write_int16(struct membuffer *buf, uint16_t data) { uint8_t temp[2]; @@ -1548,14 +1548,14 @@ static unsigned membuffer_write_int16(membuffer * buf, uint16_t data) return membuffer_write(buf, temp, 2); } -static unsigned membuffer_write_int32(membuffer * buf, uint32_t data) +static unsigned membuffer_write_int32(struct membuffer *buf, uint32_t data) { uint8_t temp[4]; write_u32_be(temp, data); return membuffer_write(buf, temp, 4); } -static void membuffer_write_track_tag(membuffer * buf, const char *name, +static void membuffer_write_track_tag(struct membuffer *buf, const char *name, uint32_t index, uint32_t total) { membuffer_write_int32(buf, @@ -1574,7 +1574,7 @@ static void membuffer_write_track_tag(membuffer * buf, const char *name, membuffer_write_int16(buf, 0); } -static void membuffer_write_int16_tag(membuffer * buf, const char *name, +static void membuffer_write_int16_tag(struct membuffer *buf, const char *name, uint16_t value) { membuffer_write_int32(buf, @@ -1605,12 +1605,12 @@ static uint32_t meta_genre_to_index(const char *genrestr) return 0; } -typedef struct { +struct stdmeta_entry { const char *atom; const char *name; -} stdmeta_entry; +}; -static stdmeta_entry stdmetas[] = { +struct stdmeta_entry stdmetas[] = { {"\xA9" "nam", "title"}, {"\xA9" "ART", "artist"}, {"\xA9" "wrt", "writer"}, @@ -1633,7 +1633,7 @@ static const char *find_standard_meta(const char *name) //returns atom name if f return 0; } -static void membuffer_write_std_tag(membuffer * buf, const char *name, +static void membuffer_write_std_tag(struct membuffer *buf, const char *name, const char *value) { uint32_t flags = 1; @@ -1656,7 +1656,7 @@ static void membuffer_write_std_tag(membuffer * buf, const char *name, membuffer_write(buf, value, strlen(value)); } -static void membuffer_write_custom_tag(membuffer * buf, const char *name, +static void membuffer_write_custom_tag(struct membuffer *buf, const char *name, const char *value) { membuffer_write_int32(buf, @@ -1682,23 +1682,23 @@ static void membuffer_write_custom_tag(membuffer * buf, const char *name, membuffer_write(buf, value, strlen(value)); } -static unsigned membuffer_error(const membuffer * buf) +static unsigned membuffer_error(const struct membuffer *buf) { return buf->error; } -static void membuffer_free(membuffer * buf) +static void membuffer_free(struct membuffer *buf) { free(buf->data); free(buf); } -static unsigned membuffer_get_size(const membuffer * buf) +static unsigned membuffer_get_size(const struct membuffer *buf) { return buf->written; } -static void *membuffer_detach(membuffer * buf) +static void *membuffer_detach(struct membuffer *buf) { void *ret; @@ -1716,10 +1716,10 @@ static void *membuffer_detach(membuffer * buf) return ret; } -static uint32_t create_ilst(const mp4ff_metadata_t * data, void **out_buffer, +static uint32_t create_ilst(const struct mp4ff_metadata *data, void **out_buffer, uint32_t * out_size) { - membuffer *buf = membuffer_create(); + struct membuffer *buf = membuffer_create(); unsigned metaptr; char *mask = para_calloc(data->count); { @@ -1727,7 +1727,7 @@ static uint32_t create_ilst(const mp4ff_metadata_t * data, void **out_buffer, const char *discnumber_ptr = 0, *totaldiscs_ptr = 0; const char *genre_ptr = 0, *tempo_ptr = 0; for (metaptr = 0; metaptr < data->count; metaptr++) { - mp4ff_tag_t *tag = &data->tags[metaptr]; + struct mp4ff_tag *tag = &data->tags[metaptr]; if (!stricmp(tag->item, "tracknumber") || !stricmp(tag->item, "track")) { if (tracknumber_ptr == 0) tracknumber_ptr = tag->value; @@ -1782,7 +1782,7 @@ static uint32_t create_ilst(const mp4ff_metadata_t * data, void **out_buffer, for (metaptr = 0; metaptr < data->count; metaptr++) { if (!mask[metaptr]) { - mp4ff_tag_t *tag = &data->tags[metaptr]; + struct mp4ff_tag *tag = &data->tags[metaptr]; const char *std_meta_atom = find_standard_meta(tag->item); if (std_meta_atom) { membuffer_write_std_tag(buf, std_meta_atom, @@ -1808,7 +1808,7 @@ static uint32_t create_ilst(const mp4ff_metadata_t * data, void **out_buffer, return 1; } -static void membuffer_write_atom(membuffer * buf, const char *name, unsigned size, +static void membuffer_write_atom(struct membuffer *buf, const char *name, unsigned size, const void *data) { membuffer_write_int32(buf, size + 8); @@ -1816,17 +1816,17 @@ static void membuffer_write_atom(membuffer * buf, const char *name, unsigned siz membuffer_write(buf, data, size); } -static void *membuffer_get_ptr(const membuffer * buf) +static void *membuffer_get_ptr(const struct membuffer *buf) { return buf->data; } -static void membuffer_set_error(membuffer * buf) +static void membuffer_set_error(struct membuffer *buf) { buf->error = 1; } -static unsigned membuffer_transfer_from_file(membuffer * buf, mp4ff_t * src, +static unsigned membuffer_transfer_from_file(struct membuffer *buf, struct mp4ff *src, unsigned bytes) { unsigned oldsize; @@ -1849,10 +1849,10 @@ static unsigned membuffer_transfer_from_file(membuffer * buf, mp4ff_t * src, return bytes; } -static uint32_t create_meta(const mp4ff_metadata_t * data, void **out_buffer, +static uint32_t create_meta(const struct mp4ff_metadata *data, void **out_buffer, uint32_t * out_size) { - membuffer *buf; + struct membuffer *buf; uint32_t ilst_size; void *ilst_buffer; @@ -1871,10 +1871,10 @@ static uint32_t create_meta(const mp4ff_metadata_t * data, void **out_buffer, return 1; } -static uint32_t create_udta(const mp4ff_metadata_t * data, void **out_buffer, +static uint32_t create_udta(const struct mp4ff_metadata *data, void **out_buffer, uint32_t * out_size) { - membuffer *buf; + struct membuffer *buf; uint32_t meta_size; void *meta_buffer; @@ -1898,7 +1898,7 @@ static uint32_t fix_byte_order_32(uint32_t src) return read_u32_be(&src); } -static uint32_t modify_moov(mp4ff_t * f, const mp4ff_metadata_t * data, +static uint32_t modify_moov(struct mp4ff *f, const struct mp4ff_metadata *data, void **out_buffer, uint32_t * out_size) { uint64_t total_base = f->moov_offset + 8; @@ -1914,7 +1914,7 @@ static uint32_t modify_moov(mp4ff_t * f, const mp4ff_metadata_t * data, int32_t size_delta; if (!find_atom_v2(f, total_base, total_size, "udta", 0, "meta")) { - membuffer *buf; + struct membuffer *buf; void *new_udta_buffer; uint32_t new_udta_size; if (!create_udta(data, &new_udta_buffer, &new_udta_size)) @@ -1937,7 +1937,7 @@ static uint32_t modify_moov(mp4ff_t * f, const mp4ff_metadata_t * data, udta_offset = get_position(f); udta_size = read_int32(f); if (!find_atom_v2 (f, udta_offset + 8, udta_size - 8, "meta", 4, "ilst")) { - membuffer *buf; + struct membuffer *buf; void *new_meta_buffer; uint32_t new_meta_size; if (!create_meta(data, &new_meta_buffer, &new_meta_size)) @@ -2012,7 +2012,7 @@ static uint32_t modify_moov(mp4ff_t * f, const mp4ff_metadata_t * data, return 1; } -static int32_t write_data(mp4ff_t * f, void *data, uint32_t size) +static int32_t write_data(struct mp4ff *f, void *data, uint32_t size) { int32_t result = 1; @@ -2023,24 +2023,24 @@ static int32_t write_data(mp4ff_t * f, void *data, uint32_t size) return result; } -static int32_t write_int32(mp4ff_t * f, const uint32_t data) +static int32_t write_int32(struct mp4ff *f, const uint32_t data) { int8_t temp[4]; write_u32_be(temp, data); return write_data(f, temp, sizeof(temp)); } -static int32_t truncate_stream(mp4ff_t * f) +static int32_t truncate_stream(struct mp4ff *f) { return f->stream->truncate(f->stream->user_data); } -int32_t mp4ff_meta_update(mp4ff_callback_t * f, const mp4ff_metadata_t * data) +int32_t mp4ff_meta_update(struct mp4ff_callback *f, const struct mp4ff_metadata *data) { void *new_moov_data; uint32_t new_moov_size; - mp4ff_t *ff = para_calloc(sizeof(mp4ff_t)); + struct mp4ff *ff = para_calloc(sizeof(struct mp4ff)); ff->stream = f; set_position(ff, 0); @@ -2078,7 +2078,7 @@ int32_t mp4ff_meta_update(mp4ff_callback_t * f, const mp4ff_metadata_t * data) /* find a metadata item by name */ /* returns 0 if item found, 1 if no such item */ -static int32_t meta_find_by_name(const mp4ff_t * f, const char *item, +static int32_t meta_find_by_name(const struct mp4ff *f, const char *item, char **value) { uint32_t i; @@ -2096,27 +2096,27 @@ static int32_t meta_find_by_name(const mp4ff_t * f, const char *item, return 0; } -int32_t mp4ff_meta_get_artist(const mp4ff_t * f, char **value) +int32_t mp4ff_meta_get_artist(const struct mp4ff *f, char **value) { return meta_find_by_name(f, "artist", value); } -int32_t mp4ff_meta_get_title(const mp4ff_t * f, char **value) +int32_t mp4ff_meta_get_title(const struct mp4ff *f, char **value) { return meta_find_by_name(f, "title", value); } -int32_t mp4ff_meta_get_date(const mp4ff_t * f, char **value) +int32_t mp4ff_meta_get_date(const struct mp4ff *f, char **value) { return meta_find_by_name(f, "date", value); } -int32_t mp4ff_meta_get_album(const mp4ff_t * f, char **value) +int32_t mp4ff_meta_get_album(const struct mp4ff *f, char **value) { return meta_find_by_name(f, "album", value); } -int32_t mp4ff_meta_get_comment(const mp4ff_t * f, char **value) +int32_t mp4ff_meta_get_comment(const struct mp4ff *f, char **value) { return meta_find_by_name(f, "comment", value); } diff --git a/mp4.h b/mp4.h index 28cfbce4..216a6c04 100644 --- a/mp4.h +++ b/mp4.h @@ -1,15 +1,13 @@ -typedef struct -{ +struct mp4ff_callback { uint32_t (*read)(void *user_data, void *buffer, uint32_t length); uint32_t (*write)(void *udata, void *buffer, uint32_t length); uint32_t (*seek)(void *user_data, uint64_t position); uint32_t (*truncate)(void *user_data); void *user_data; uint32_t read_error; -} mp4ff_callback_t; +}; -typedef struct -{ +struct mp4ff_track { int32_t type; int32_t channelCount; int32_t sampleSize; @@ -54,28 +52,25 @@ typedef struct uint32_t timeScale; uint64_t duration; -} mp4ff_track_t; +}; #define MAX_TRACKS 1024 -typedef struct -{ +struct mp4ff_tag { char *item; char *value; uint32_t len; -} mp4ff_tag_t; +}; -typedef struct -{ - mp4ff_tag_t *tags; +struct mp4ff_metadata { + struct mp4ff_tag *tags; uint32_t count; -} mp4ff_metadata_t; +}; /* mp4 main file structure */ -typedef struct -{ +struct mp4ff { /* stream to read from */ - mp4ff_callback_t *stream; + struct mp4ff_callback *stream; int64_t current_position; uint64_t moov_offset; @@ -92,31 +87,31 @@ typedef struct int32_t total_tracks; /* track data */ - mp4ff_track_t *track[MAX_TRACKS]; + struct mp4ff_track *track[MAX_TRACKS]; /* metadata */ - mp4ff_metadata_t tags; -} mp4ff_t; + struct mp4ff_metadata tags; +}; -void mp4ff_set_sample_position(mp4ff_t *f, const int32_t track, const int32_t sample); -int32_t mp4ff_total_tracks(const mp4ff_t *f); -void mp4ff_get_decoder_config(const mp4ff_t *f, const int track, +void mp4ff_set_sample_position(struct mp4ff *f, const int32_t track, const int32_t sample); +int32_t mp4ff_total_tracks(const struct mp4ff *f); +void mp4ff_get_decoder_config(const struct mp4ff *f, const int track, unsigned char** ppBuf, unsigned int* pBufSize); -mp4ff_t *mp4ff_open_read(mp4ff_callback_t *f); -void mp4ff_close(mp4ff_t *f); -int32_t mp4ff_get_sample_size(const mp4ff_t *f, int track, int sample); -uint32_t mp4ff_get_sample_rate(const mp4ff_t *f, const int32_t track); -uint32_t mp4ff_get_channel_count(const mp4ff_t * f,const int32_t track); -int32_t mp4ff_num_samples(const mp4ff_t *f, const int track); -mp4ff_t *mp4ff_open_read_metaonly(mp4ff_callback_t *f); - -int mp4ff_meta_get_by_index(const mp4ff_t *f, unsigned int index, +struct mp4ff *mp4ff_open_read(struct mp4ff_callback *f); +void mp4ff_close(struct mp4ff *f); +int32_t mp4ff_get_sample_size(const struct mp4ff *f, int track, int sample); +uint32_t mp4ff_get_sample_rate(const struct mp4ff *f, const int32_t track); +uint32_t mp4ff_get_channel_count(const struct mp4ff * f,const int32_t track); +int32_t mp4ff_num_samples(const struct mp4ff *f, const int track); +struct mp4ff *mp4ff_open_read_metaonly(struct mp4ff_callback *f); + +int mp4ff_meta_get_by_index(const struct mp4ff *f, unsigned int index, char **item, char **value); -int32_t mp4ff_meta_update(mp4ff_callback_t *f,const mp4ff_metadata_t * data); - -int mp4ff_meta_get_num_items(const mp4ff_t *f); -int mp4ff_meta_get_artist(const mp4ff_t *f, char **value); -int mp4ff_meta_get_title(const mp4ff_t *f, char **value); -int mp4ff_meta_get_date(const mp4ff_t *f, char **value); -int mp4ff_meta_get_album(const mp4ff_t *f, char **value); -int mp4ff_meta_get_comment(const mp4ff_t *f, char **value); +int32_t mp4ff_meta_update(struct mp4ff_callback *f,const struct mp4ff_metadata * data); + +int mp4ff_meta_get_num_items(const struct mp4ff *f); +int mp4ff_meta_get_artist(const struct mp4ff *f, char **value); +int mp4ff_meta_get_title(const struct mp4ff *f, char **value); +int mp4ff_meta_get_date(const struct mp4ff *f, char **value); +int mp4ff_meta_get_album(const struct mp4ff *f, char **value); +int mp4ff_meta_get_comment(const struct mp4ff *f, char **value);