static int aac_afh_open(const void *map, size_t mapsize, void **afh_context)
{
int ret;
- struct aac_afh_context *c = para_malloc(sizeof(*c));
+ struct aac_afh_context *c = alloc(sizeof(*c));
c->map = map;
c->mapsize = mapsize;
c->cb.seek = aac_afh_seek_cb;
c->cb.user_data = c;
- ret = mp4_open_read(&c->cb, &c->mp4);
+ ret = mp4_open(&c->cb, &c->mp4);
if (ret < 0)
goto free_ctx;
*afh_context = c;
const char **buf, uint32_t *len)
{
struct aac_afh_context *c = afh_context;
- int32_t ss;
+ uint32_t ss;
size_t offset;
int ret;
if (ret < 0)
return ret;
offset = c->fpos;
- ss = mp4_get_sample_size(c->mp4, chunk_num);
- if (ss <= 0)
- return -E_MP4_BAD_SAMPLE;
- assert(ss + offset <= c->mapsize);
+ ret = mp4_get_sample_size(c->mp4, chunk_num, &ss);
+ if (ret < 0)
+ return ret;
+ if (ss + offset > c->mapsize) /* file got truncated?! */
+ return -E_MP4_CORRUPT;
*buf = c->map + offset;
*len = ss;
return 1;
struct afh_info *afhi)
{
int ret;
- int32_t rv;
struct aac_afh_context *c;
uint64_t milliseconds;
const char *buf;
if (ret < 0)
return ret;
- ret = -E_MP4_BAD_SAMPLERATE;
- rv = mp4_get_sample_rate(c->mp4);
- if (rv <= 0)
- goto close;
- afhi->frequency = rv;
-
- ret = -E_MP4_BAD_CHANNEL_COUNT;
- rv = mp4_get_channel_count(c->mp4);
- if (rv <= 0)
- goto close;
- afhi->channels = rv;
-
- ret = -E_MP4_BAD_SAMPLE_COUNT;
- rv = mp4_num_samples(c->mp4);
- if (rv <= 0)
- goto close;
- afhi->chunks_total = rv;
+ afhi->frequency = mp4_get_sample_rate(c->mp4);
+ assert(afhi->frequency > 0);
+ afhi->channels = mp4_get_channel_count(c->mp4);
+ assert(afhi->channels > 0);
+ afhi->chunks_total = mp4_num_samples(c->mp4);
+ assert(afhi->chunks_total > 0);
+
afhi->max_chunk_size = 0;
for (n = 0; n < afhi->chunks_total; n++) {
- if (aac_afh_get_chunk(n, c, &buf, &len) < 0)
- break;
+ ret = aac_afh_get_chunk(n, c, &buf, &len);
+ if (ret < 0)
+ goto out;
afhi->max_chunk_size = PARA_MAX(afhi->max_chunk_size, len);
}
milliseconds = mp4_get_duration(c->mp4);
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;
+ if (aac_afh_get_chunk(0, c, &buf, &len) < 0)
+ goto out;
+ numbytes -= buf - map;
afhi->bitrate = 8 * numbytes / afhi->seconds_total / 1000;
aac_afh_get_taginfo(c->mp4, &afhi->tags);
ret = 1;
-close:
+out:
aac_afh_close(c);
return ret;
}
replace_or_add_tag("album", tags->album, metadata);
replace_or_add_tag("date", tags->year, metadata);
replace_or_add_tag("comment", tags->comment, metadata);
- ret = mp4_meta_update(mp4);
+ ret = mp4_update_meta(mp4);
mp4_close(mp4);
return ret;
}