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_ccomon.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
;
61 int aac_find_esds(unsigned char *buf
, unsigned buflen
, int *skip
)
65 for (i
= 0; i
+ 4 < buflen
; i
++) {
66 unsigned char *p
= buf
+ i
;
67 int decoder_length
, description_len
;
69 if (p
[0] != 'e' || p
[1] != 's' || p
[2] != 'd' || p
[3] != 's')
73 PARA_INFO_LOG("found esds@%d, next: %x\n", i
, *p
);
79 PARA_INFO_LOG("next: %x\n", *p
);
84 PARA_INFO_LOG("next: %x\n", *p
);
89 decoder_length
= aac_read_decoder_length(p
, &description_len
);
90 PARA_INFO_LOG("decoder length: %d\n", decoder_length
);
93 return decoder_length
;
98 unsigned aac_read_int32(unsigned char *buf
)
100 uint8_t *d
= (uint8_t*)buf
;
101 return (d
[0] << 24) | (d
[1] << 16) | (d
[2] << 8) | d
[3];
105 * search for the first entry in the stco table
107 * \param buf buffer to seach
108 * \param buflen length of \a buf
109 * \param skip Upon succesful return, this contains the number
110 * of bytes to skip from the input buffer.
112 * \return the position of the first entry in the table on success,
116 int aac_find_entry_point(unsigned char *buf
, unsigned buflen
, int *skip
)
120 for (i
= 0; i
+ 20 < buflen
; i
++) {
121 unsigned char *p
= buf
+ i
;
123 if (p
[0] != 's' || p
[1] != 't' || p
[2] != 'c' || p
[3] != 'o')
125 PARA_INFO_LOG("found stco@%d\n", i
);
127 ret
= aac_read_int32(buf
+ i
); /* first offset */
129 PARA_INFO_LOG("num entries: %d\n", ret
);
133 PARA_WARNING_LOG("stco not found, buflen: %d\n", buflen
);