X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=aac_afh.c;h=93d3bec8157702b9f769178d4d9c4ed5e81ecd2e;hp=9cab39205d9739736653fa359240aeebaf9508f9;hb=f2fa810c4bac275b4dc3ea9cd8b48d77e204618d;hpb=019f1ffdacd228f6a1e701ef6795c1a65ff02785 diff --git a/aac_afh.c b/aac_afh.c index 9cab3920..93d3bec8 100644 --- a/aac_afh.c +++ b/aac_afh.c @@ -15,8 +15,12 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ -/** \file aac_afh.c para_server's aac audio format handler */ +/* + * based in parts on libfaad, Copyright (C) 2003-2005 M. Bakker, + * Ahead Software AG + */ +/** \file aac_afh.c para_server's aac audio format handler */ #include "server.cmdline.h" #include "server.h" @@ -44,7 +48,32 @@ static void aac_close_audio_file(void) { } -static int read_stsz(unsigned skip) +static int aac_find_stsz(unsigned char *buf, unsigned buflen, unsigned *skip) +{ + int i; + + for (i = 0; i + 16 < buflen; i++) { + unsigned char *p = buf + i; + unsigned sample_count, sample_size; + + if (p[0] != 's' || p[1] != 't' || p[2] != 's' || p[3] != 'z') + continue; + PARA_INFO_LOG("found stsz@%d\n", i); + i += 8; + sample_size = aac_read_int32(buf + i); + PARA_INFO_LOG("sample size: %d\n", sample_size); + i += 4; + sample_count = aac_read_int32(buf + i); + i += 4; + PARA_INFO_LOG("sample count: %d\n", sample_count); + *skip = i; + return sample_count; + } + PARA_WARNING_LOG("stsz not found, buflen: %d\n", buflen); + return -E_STSZ; +} + +static int read_chunk_table(unsigned skip) { int ret, i; long unsigned sum = 0; @@ -83,7 +112,6 @@ static int read_stsz(unsigned skip) } - /* * Init m4a file and write some tech data to given pointers. */ @@ -125,11 +153,12 @@ static int aac_get_file_info(FILE *file, char *info_str, long unsigned *frames, } else PARA_WARNING_LOG("no mp4ASC %s\n", ""); - ret = read_stsz(skip); + ret = read_chunk_table(skip); if (ret < 0) return ret; + *frames = num_chunks; for (;;) { - ret = aac_find_stco(inbuf, inbuf_len, &skip); + ret = aac_find_entry_point(inbuf, inbuf_len, &skip); if (ret >= 0) break; ret = read(fileno(infile), inbuf, inbuf_size); @@ -137,8 +166,7 @@ static int aac_get_file_info(FILE *file, char *info_str, long unsigned *frames, return -E_AAC_READ; PARA_INFO_LOG("next buffer: %d bytes\n", ret); } - *frames = ret; - entry = aac_read_int32(inbuf + skip); + entry = ret; PARA_INFO_LOG("offset table has %d entries\, entry: %zd\n", num_chunks, entry); #if 1 @@ -164,7 +192,8 @@ static int aac_get_file_info(FILE *file, char *info_str, long unsigned *frames, */ static int aac_reposition_stream(long unsigned request) { - return -E_AAC_REPOS; + return 1; +// return -E_AAC_REPOS; } static __must_check int para_fread(void *ptr, size_t size, size_t nmemb, FILE *stream) @@ -177,7 +206,7 @@ static __must_check int para_fread(void *ptr, size_t size, size_t nmemb, FILE *s return -E_FREAD; } -char *aac_read_chunk(long unsigned current_chunk, ssize_t *len) +static char *aac_read_chunk(long unsigned current_chunk, ssize_t *len) { int ret; size_t pos;