2 * Copyright (C) 2006-2007 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
21 NeAACDecHandle aac_open(void)
23 NeAACDecHandle h = NeAACDecOpen();
24 NeAACDecConfigurationPtr c = NeAACDecGetCurrentConfiguration(h);
26 c->defObjectType = LC;
27 c->outputFormat = FAAD_FMT_16BIT;
29 NeAACDecSetConfiguration(h, c);
33 static unsigned long aac_read_decoder_length(unsigned char *buf, int *description_len)
37 unsigned long length = 0;
42 length = (length << 7) | (b & 0x7F);
44 ((b & 0x80) && numBytes < 4);
45 *description_len = numBytes;
50 * search for the position and the length of the decoder configuration
52 * \param buf buffer to seach
53 * \param buflen length of \a buf
54 * \param skip Upon succesful return, this contains the offset in \a buf where
55 * the decoder config starts.
56 * \param decoder_length result pointer that is filled in with the length of
57 * the decoder configuration on success.
59 * \return positive on success, negative on errors
61 int aac_find_esds(unsigned char *buf, size_t buflen, size_t *skip,
62 unsigned long *decoder_length)
66 for (i = 0; i + 4 < buflen; i++) {
67 unsigned char *p = buf + i;
70 if (p[0] != 'e' || p[1] != 's' || p[2] != 'd' || p[3] != 's')
74 PARA_INFO_LOG("found esds@%zu, next: %x\n", i, *p);
80 PARA_INFO_LOG("next: %x\n", *p);
85 PARA_INFO_LOG("next: %x\n", *p);
90 *decoder_length = aac_read_decoder_length(p, &description_len);
91 PARA_INFO_LOG("decoder length: %lu\n", *decoder_length);
100 * search for the first entry in the stco table
102 * \param buf buffer to seach
103 * \param buflen length of \a buf
104 * \param skip Upon succesful return, this contains the number
105 * of bytes to skip from the input buffer.
107 * \return the position of the first entry in the table on success,
110 ssize_t aac_find_entry_point(unsigned char *buf, size_t buflen, size_t *skip)
115 for (i = 0; i + 20 < buflen; i++) {
116 unsigned char *p = buf + i;
118 if (p[0] != 's' || p[1] != 't' || p[2] != 'c' || p[3] != 'o')
120 PARA_INFO_LOG("found stco@%zu\n", i);
122 ret = aac_read_int32(buf + i); /* first offset */
124 PARA_INFO_LOG("entry point: %zd\n", ret);
128 PARA_WARNING_LOG("stco not found, buflen: %zu\n", buflen);