2 * Copyright (C) 2006 Andre Noll <maan@systemlinux.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
19 * based in parts on libfaad, Copyright (C) 2003-2005 M. Bakker,
23 /** \file aac_common.c common functions of aac_afh and aadcec */
30 * get a new libfaad decoder handle
33 NeAACDecHandle aac_open(void)
35 NeAACDecHandle h = NeAACDecOpen();
36 NeAACDecConfigurationPtr c = NeAACDecGetCurrentConfiguration(h);
38 c->defObjectType = LC;
39 c->outputFormat = FAAD_FMT_16BIT;
41 NeAACDecSetConfiguration(h, c);
45 static int aac_read_decoder_length(unsigned char *buf, int *description_len)
54 length = (length << 7) | (b & 0x7F);
56 ((b & 0x80) && numBytes < 4);
57 *description_len = numBytes;
62 * search for the position and the length of the decoder configuration
64 * \param buf buffer to seach
65 * \param buflen length of \a buf
66 * \param skip Upon succesful return, this contains the offset in \a buf where
67 * the decoder config starts.
69 * \return The length of the decoder configuration
71 ssize_t aac_find_esds(unsigned char *buf, size_t buflen, size_t *skip)
75 for (i = 0; i + 4 < buflen; i++) {
76 unsigned char *p = buf + i;
77 int decoder_length, description_len;
79 if (p[0] != 'e' || p[1] != 's' || p[2] != 'd' || p[3] != 's')
83 PARA_INFO_LOG("found esds@%zu, next: %x\n", i, *p);
89 PARA_INFO_LOG("next: %x\n", *p);
94 PARA_INFO_LOG("next: %x\n", *p);
99 decoder_length = aac_read_decoder_length(p, &description_len);
100 PARA_INFO_LOG("decoder length: %d\n", decoder_length);
101 i += description_len;
103 return decoder_length;
109 * search for the first entry in the stco table
111 * \param buf buffer to seach
112 * \param buflen length of \a buf
113 * \param skip Upon succesful return, this contains the number
114 * of bytes to skip from the input buffer.
116 * \return the position of the first entry in the table on success,
119 ssize_t aac_find_entry_point(unsigned char *buf, size_t buflen, size_t *skip)
124 for (i = 0; i + 20 < buflen; i++) {
125 unsigned char *p = buf + i;
127 if (p[0] != 's' || p[1] != 't' || p[2] != 'c' || p[3] != 'o')
129 PARA_INFO_LOG("found stco@%zu\n", i);
131 ret = aac_read_int32(buf + i); /* first offset */
133 PARA_INFO_LOG("entry point: %zd\n", ret);
137 PARA_WARNING_LOG("stco not found, buflen: %zu\n", buflen);