2 * Copyright (C) 2006-2007 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 unsigned long aac_read_decoder_length(unsigned char *buf
, int *description_len
)
49 unsigned long length
= 0;
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.
68 * \param decoder_length result pointer that is filled in with the length of
69 * the decoder configuration on success.
71 * \return positive on success, negative on errors
73 int aac_find_esds(unsigned char *buf
, size_t buflen
, size_t *skip
,
74 unsigned long *decoder_length
)
78 for (i
= 0; i
+ 4 < buflen
; i
++) {
79 unsigned char *p
= buf
+ i
;
82 if (p
[0] != 'e' || p
[1] != 's' || p
[2] != 'd' || p
[3] != 's')
86 PARA_INFO_LOG("found esds@%zu, next: %x\n", i
, *p
);
92 PARA_INFO_LOG("next: %x\n", *p
);
97 PARA_INFO_LOG("next: %x\n", *p
);
102 *decoder_length
= aac_read_decoder_length(p
, &description_len
);
103 PARA_INFO_LOG("decoder length: %lu\n", *decoder_length
);
104 i
+= description_len
;
112 * search for the first entry in the stco table
114 * \param buf buffer to seach
115 * \param buflen length of \a buf
116 * \param skip Upon succesful return, this contains the number
117 * of bytes to skip from the input buffer.
119 * \return the position of the first entry in the table on success,
122 ssize_t
aac_find_entry_point(unsigned char *buf
, size_t buflen
, size_t *skip
)
127 for (i
= 0; i
+ 20 < buflen
; i
++) {
128 unsigned char *p
= buf
+ i
;
130 if (p
[0] != 's' || p
[1] != 't' || p
[2] != 'c' || p
[3] != 'o')
132 PARA_INFO_LOG("found stco@%zu\n", i
);
134 ret
= aac_read_int32(buf
+ i
); /* first offset */
136 PARA_INFO_LOG("entry point: %zd\n", ret
);
140 PARA_WARNING_LOG("stco not found, buflen: %zu\n", buflen
);