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 */
29 NeAACDecHandle
aac_open(void)
31 NeAACDecHandle h
= NeAACDecOpen();
32 NeAACDecConfigurationPtr c
= NeAACDecGetCurrentConfiguration(h
);
34 c
->defObjectType
= LC
;
35 c
->outputFormat
= FAAD_FMT_16BIT
;
37 NeAACDecSetConfiguration(h
, c
);
41 static int aac_read_decoder_length(unsigned char *buf
, int *description_len
)
50 length
= (length
<< 7) | (b
& 0x7F);
52 ((b
& 0x80) && numBytes
< 4);
53 *description_len
= numBytes
;
57 int aac_find_esds(unsigned char *buf
, unsigned buflen
, int *skip
)
61 for (i
= 0; i
+ 4 < buflen
; i
++) {
62 unsigned char *p
= buf
+ i
;
63 int decoder_length
, description_len
;
65 if (p
[0] != 'e' || p
[1] != 's' || p
[2] != 'd' || p
[3] != 's')
69 PARA_INFO_LOG("found esds@%d, next: %x\n", i
, *p
);
75 PARA_INFO_LOG("next: %x\n", *p
);
80 PARA_INFO_LOG("next: %x\n", *p
);
85 decoder_length
= aac_read_decoder_length(p
, &description_len
);
86 PARA_INFO_LOG("decoder length: %d\n", decoder_length
);
89 return decoder_length
;
94 unsigned aac_read_int32(unsigned char *buf
)
96 uint8_t *d
= (uint8_t*)buf
;
97 return (d
[0] << 24) | (d
[1] << 16) | (d
[2] << 8) | d
[3];
101 int aac_find_entry_point(unsigned char *buf
, unsigned buflen
, int *skip
)
105 for (i
= 0; i
+ 20 < buflen
; i
++) {
106 unsigned char *p
= buf
+ i
;
108 if (p
[0] != 's' || p
[1] != 't' || p
[2] != 'c' || p
[3] != 'o')
110 PARA_INFO_LOG("found stco@%d\n", i
);
112 ret
= aac_read_int32(buf
+ i
); /* first offset */
114 PARA_INFO_LOG("num entries: %d\n", ret
);
118 PARA_WARNING_LOG("stco not found, buflen: %d\n", buflen
);