From c1424e4c5beab718e88f7c278ffae5a4bd1e85db Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 11 Mar 2007 18:11:37 +0100 Subject: [PATCH] aac_afh.c: free the inbuffer already in aac_get_file_info() No need to wait for this until the audio file gets closed. This patch also fixes two occurences of a bug where the length of the input buffer was not set correctly. --- aac_afh.c | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/aac_afh.c b/aac_afh.c index 58e23857..8d1ff684 100644 --- a/aac_afh.c +++ b/aac_afh.c @@ -43,8 +43,6 @@ static void aac_close_audio_file(void) return; fclose(infile); infile = NULL; - free(inbuf); - inbuf = NULL; } static int aac_find_stsz(unsigned char *buf, unsigned buflen, size_t *skip) @@ -84,6 +82,7 @@ static int read_chunk_table(struct audio_format_info *afi, 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; @@ -93,7 +92,8 @@ static int read_chunk_table(struct audio_format_info *afi, size_t skip) 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; @@ -140,35 +140,41 @@ static int aac_get_file_info(FILE *file, struct audio_format_info *afi) 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; @@ -180,7 +186,10 @@ static int aac_get_file_info(FILE *file, struct audio_format_info *afi) 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}; -- 2.39.5