X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=aac_afh.c;h=15e338e5b61efb84d39e24fbff17952137008871;hb=15aeb1f5cc5bf5c4925897d5ae54d2b350822790;hp=7f2a22a223ce733aa4b49d0a60ff63d1b95bf321;hpb=05a15e80c5dae4f94c417210549d07a94a0acc16;p=paraslash.git diff --git a/aac_afh.c b/aac_afh.c index 7f2a22a2..15e338e5 100644 --- a/aac_afh.c +++ b/aac_afh.c @@ -10,11 +10,7 @@ #include #include "para.h" - -/* To get the mp4ff_tag_t and mp4ff_metadata_t typedefs. */ -#define USE_TAGGING -#include - +#include "mp4.h" #include "error.h" #include "portable_io.h" #include "afh.h" @@ -27,25 +23,20 @@ struct aac_afh_context { size_t mapsize; size_t fpos; int32_t track; - mp4ff_t *mp4ff; - mp4AudioSpecificConfig masc; - mp4ff_callback_t cb; + struct mp4ff *mp4ff; + struct mp4ff_callback cb; }; static uint32_t aac_afh_read_cb(void *user_data, void *dest, uint32_t want) { struct aac_afh_context *c = user_data; - uint32_t have, rv; + size_t have, rv; - if (want == 0 || c->fpos >= c->mapsize) { - PARA_INFO_LOG("failed attempt to read %u bytes @%zu\n", want, - c->fpos); - errno = EAGAIN; - return -1; - } + if (want == 0 || c->fpos >= c->mapsize) + return 0; have = c->mapsize - c->fpos; - rv = PARA_MIN(have, want); - PARA_DEBUG_LOG("reading %u bytes @%zu\n", rv, c->fpos); + rv = PARA_MIN(have, (size_t)want); + PARA_DEBUG_LOG("reading %zu bytes @%zu\n", rv, c->fpos); memcpy(dest, c->map + c->fpos, rv); c->fpos += rv; return rv; @@ -58,7 +49,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) { int32_t i, rc, num_tracks = mp4ff_total_tracks(mp4ff); @@ -69,7 +60,8 @@ static int32_t aac_afh_get_track(mp4ff_t *mp4ff, mp4AudioSpecificConfig *masc) mp4ff_get_decoder_config(mp4ff, i, &buf, &buf_size); if (buf) { - rc = NeAACDecAudioSpecificConfig(buf, buf_size, masc); + mp4AudioSpecificConfig masc; + rc = NeAACDecAudioSpecificConfig(buf, buf_size, &masc); free(buf); if (rc < 0) continue; @@ -95,7 +87,7 @@ static int aac_afh_open(const void *map, size_t mapsize, void **afh_context) c->mp4ff = mp4ff_open_read(&c->cb); if (!c->mp4ff) goto free_ctx; - c->track = aac_afh_get_track(c->mp4ff, &c->masc); + c->track = aac_afh_get_track(c->mp4ff); ret = -E_MP4FF_TRACK; if (c->track < 0) goto close_mp4ff; @@ -116,32 +108,17 @@ static void aac_afh_close(void *afh_context) free(c); } -/** - * Libmp4ff function to reposition the file to the given sample. - * - * \param f The opaque handle returned by mp4ff_open_read(). - * \param track The number of the (audio) track. - * \param sample Destination. - * - * We need this function to obtain the offset of the sample within the audio - * file. Unfortunately, it is not exposed in the mp4ff header. - * - * \return This function always returns 0. - */ -int32_t mp4ff_set_sample_position(mp4ff_t *f, const int32_t track, const int32_t sample); - -static int aac_afh_get_chunk(long unsigned chunk_num, void *afh_context, - const char **buf, size_t *len) +static int aac_afh_get_chunk(uint32_t chunk_num, void *afh_context, + const char **buf, uint32_t *len) { struct aac_afh_context *c = afh_context; int32_t ss; size_t offset; assert(chunk_num <= INT_MAX); - /* this function always returns zero */ mp4ff_set_sample_position(c->mp4ff, c->track, chunk_num); offset = c->fpos; - ss = mp4ff_read_sample_getsize(c->mp4ff, c->track, chunk_num); + ss = mp4ff_get_sample_size(c->mp4ff, c->track, chunk_num); if (ss <= 0) return -E_MP4FF_BAD_SAMPLE; assert(ss + offset <= c->mapsize); @@ -150,7 +127,7 @@ static int aac_afh_get_chunk(long unsigned 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); @@ -168,10 +145,9 @@ static int aac_get_file_info(char *map, size_t numbytes, __a_unused int fd, int ret; int32_t rv; struct aac_afh_context *c; - int64_t tmp; + uint64_t milliseconds; const char *buf; - size_t sz; - uint32_t n; + uint32_t n, len; ret = aac_afh_open(map, numbytes, (void **)&c); if (ret < 0) @@ -196,16 +172,14 @@ static int aac_get_file_info(char *map, size_t numbytes, __a_unused int fd, afhi->chunks_total = rv; afhi->max_chunk_size = 0; for (n = 0; n < afhi->chunks_total; n++) { - if (aac_afh_get_chunk(n, c, &buf, &sz) < 0) + if (aac_afh_get_chunk(n, c, &buf, &len) < 0) break; - afhi->max_chunk_size = PARA_MAX((size_t)afhi->max_chunk_size, sz); + afhi->max_chunk_size = PARA_MAX(afhi->max_chunk_size, len); } - - tmp = c->masc.sbr_present_flag == 1? 2048 : 1024; - afhi->seconds_total = tmp * afhi->chunks_total / afhi->frequency; - ms2tv(1000 * tmp / afhi->frequency, &afhi->chunk_tv); - - if (aac_afh_get_chunk(0, c, &buf, &sz) >= 0) + milliseconds = mp4ff_get_duration(c->mp4ff, c->track); + afhi->seconds_total = milliseconds / 1000; + ms2tv(milliseconds / afhi->chunks_total, &afhi->chunk_tv); + if (aac_afh_get_chunk(0, c, &buf, &len) >= 0) numbytes -= buf - map; afhi->bitrate = 8 * numbytes / afhi->seconds_total / 1000; _aac_afh_get_taginfo(c->mp4ff, &afhi->tags); @@ -240,14 +214,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); @@ -259,9 +233,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, @@ -287,13 +261,12 @@ 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) < 0) + if (!mp4ff_meta_get_by_index(mp4ff, i, &tag->item, &tag->value)) goto free_tags; PARA_INFO_LOG("found: %s: %s\n", tag->item, tag->value); if (!strcmp(tag->item, "artist")) @@ -318,7 +291,7 @@ static int aac_afh_rewrite_tags(const char *map, size_t mapsize, if (!found_comment) add_tag(&metadata, "comment", tags->comment); ret = -E_MP4FF_META_WRITE; - if (mp4ff_meta_update(&cb, &metadata) < 0) + if (!mp4ff_meta_update(&cb, &metadata)) goto free_tags; ret = 1; free_tags: