return;
fclose(infile);
infile = NULL;
- free(inbuf);
- inbuf = NULL;
}
static int aac_find_stsz(unsigned char *buf, unsigned buflen, size_t *skip)
ret = read(fileno(infile), inbuf, AAC_INBUF_SIZE);
if (ret <= 0)
return -E_AAC_READ;
+ inbuf_len = ret;
PARA_INFO_LOG("next buffer: %d bytes\n", ret);
}
afi->chunks_total = ret;
if (skip + 4 > inbuf_len) {
skip = inbuf_len - skip;
memmove(inbuf, inbuf + inbuf_len - skip, skip);
- ret = read(fileno(infile), inbuf + skip, AAC_INBUF_SIZE - skip);
+ ret = read(fileno(infile), inbuf + skip,
+ AAC_INBUF_SIZE - skip);
if (ret <= 0)
return -E_AAC_READ;
inbuf_len = ret + skip;
infile = file;
ret = read(fileno(infile), inbuf, AAC_INBUF_SIZE);
- if (ret <= 0)
- return -E_AAC_READ;
+ if (ret <= 0) {
+ ret = -E_AAC_READ;
+ goto out;
+ }
inbuf_len = ret;
ret = aac_find_esds(inbuf, inbuf_len, &skip);
if (ret < 0)
- return ret;
+ goto out;
decoder_len = ret;
handle = aac_open();
- ret = NeAACDecInit(handle, inbuf + skip,
- decoder_len, &rate, &channels);
- if (ret < 0)
- return -E_AACDEC_INIT;
+ ret = NeAACDecInit(handle, inbuf + skip, decoder_len, &rate, &channels);
+ if (ret < 0) {
+ ret = -E_AACDEC_INIT;
+ goto out;
+ }
skip += ret;
PARA_INFO_LOG("rate: %lu, channels: %d\n", rate, channels);
- ret = NeAACDecAudioSpecificConfig(inbuf + skip, inbuf_len - skip,
- &mp4ASC);
- if (ret < 0)
- return -E_MP4ASC;
+ ret = -E_MP4ASC;
+ if (NeAACDecAudioSpecificConfig(inbuf + skip, inbuf_len - skip,
+ &mp4ASC) < 0)
+ goto out;
ret = read_chunk_table(afi, skip);
if (ret < 0)
- return ret;
+ goto out;
afi->seconds_total = aac_set_chunk_tv(afi, &mp4ASC);
for (;;) {
ret = aac_find_entry_point(inbuf, inbuf_len, &skip);
if (ret >= 0)
break;
ret = read(fileno(infile), inbuf, AAC_INBUF_SIZE);
- if (ret <= 0)
- return -E_AAC_READ;
+ if (ret <= 0) {
+ ret = -E_AAC_READ;
+ goto out;
+ }
+ inbuf_len = ret;
PARA_INFO_LOG("next buffer: %d bytes\n", ret);
}
afi->chunk_table[0] = ret;
afi->chunks_total,
tv2ms(&afi->chunk_tv));
tv_scale(20, &afi->chunk_tv, &afi->eof_tv);
- return 1;
+ ret = 1;
+out:
+ free(inbuf);
+ return ret;
}
static const char* aac_suffixes[] = {"m4a", "mp4", NULL};