2 * Copyright (C) 2006-2012 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 * based in parts on libfaad, Copyright (C) 2003-2005 M. Bakker,
11 /** \file aac_common.c Common functions of aac_afh and aadcec. */
18 * Get a new libfaad decoder handle.
20 * \return The handle returned by NeAACDecOpen().
22 NeAACDecHandle
aac_open(void)
24 NeAACDecHandle h
= NeAACDecOpen();
25 NeAACDecConfigurationPtr c
= NeAACDecGetCurrentConfiguration(h
);
27 c
->defObjectType
= LC
;
28 c
->outputFormat
= FAAD_FMT_16BIT
;
30 NeAACDecSetConfiguration(h
, c
);
34 static unsigned long aac_read_decoder_length(unsigned char *buf
, int *description_len
)
38 unsigned long length
= 0;
43 length
= (length
<< 7) | (b
& 0x7F);
45 ((b
& 0x80) && numBytes
< 4);
46 *description_len
= numBytes
;
51 * search for the position and the length of the decoder configuration
53 * \param buf buffer to seach
54 * \param buflen length of \a buf
55 * \param skip Upon succesful return, this contains the offset in \a buf where
56 * the decoder config starts.
57 * \param decoder_length result pointer that is filled in with the length of
58 * the decoder configuration on success.
60 * \return positive on success, negative on errors
62 int aac_find_esds(unsigned char *buf
, size_t buflen
, size_t *skip
,
63 unsigned long *decoder_length
)
67 for (i
= 0; i
+ 4 < buflen
; i
++) {
68 unsigned char *p
= buf
+ i
;
71 if (p
[0] != 'e' || p
[1] != 's' || p
[2] != 'd' || p
[3] != 's')
75 PARA_INFO_LOG("found esds@%zu, next: %x\n", i
, *p
);
81 PARA_INFO_LOG("next: %x\n", *p
);
86 PARA_INFO_LOG("next: %x\n", *p
);
91 *decoder_length
= aac_read_decoder_length(p
, &description_len
);
92 PARA_INFO_LOG("decoder length: %lu\n", *decoder_length
);
101 * search for the first entry in the stco table
103 * \param buf buffer to seach
104 * \param buflen length of \a buf
105 * \param skip Upon succesful return, this contains the number
106 * of bytes to skip from the input buffer.
108 * \return the position of the first entry in the table on success,
111 ssize_t
aac_find_entry_point(unsigned char *buf
, size_t buflen
, size_t *skip
)
116 for (i
= 0; i
+ 20 < buflen
; i
++) {
117 unsigned char *p
= buf
+ i
;
119 if (p
[0] != 's' || p
[1] != 't' || p
[2] != 'c' || p
[3] != 'o')
121 PARA_INFO_LOG("found stco@%zu\n", i
);
123 ret
= aac_read_int32(buf
+ i
); /* first offset */
125 PARA_INFO_LOG("entry point: %zd\n", ret
);
129 PARA_WARNING_LOG("stco not found, buflen: %zu\n", buflen
);