2 * Copyright (C) 2006 Andre Noll <maan@tuebingen.mpg.de>
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. */
16 #include "portable_io.h"
19 * Get a new libfaad decoder handle.
21 * \return The handle returned by NeAACDecOpen().
23 NeAACDecHandle aac_open(void)
25 NeAACDecHandle h = NeAACDecOpen();
26 NeAACDecConfigurationPtr c = NeAACDecGetCurrentConfiguration(h);
28 c->defObjectType = LC;
29 c->outputFormat = FAAD_FMT_16BIT;
31 NeAACDecSetConfiguration(h, c);
35 static unsigned long aac_read_decoder_length(char *buf, int *description_len)
39 unsigned long length = 0;
44 length = (length << 7) | (b & 0x7F);
46 ((b & 0x80) && numBytes < 4);
47 *description_len = numBytes;
52 * search for the position and the length of the decoder configuration
54 * \param buf buffer to seach
55 * \param buflen length of \a buf
56 * \param skip Upon succesful return, this contains the offset in \a buf where
57 * the decoder config starts.
58 * \param decoder_length result pointer that is filled in with the length of
59 * the decoder configuration on success.
61 * \return positive on success, negative on errors
63 int aac_find_esds(char *buf, size_t buflen, size_t *skip,
64 unsigned long *decoder_length)
68 for (i = 0; i + 4 < buflen; i++) {
72 if (p[0] != 'e' || p[1] != 's' || p[2] != 'd' || p[3] != 's')
76 PARA_INFO_LOG("found esds@%zu, next: %x\n", i, (unsigned)*p);
82 PARA_INFO_LOG("next: %x\n", (unsigned)*p);
87 PARA_INFO_LOG("next: %x\n", (unsigned)*p);
92 *decoder_length = aac_read_decoder_length(p, &description_len);
93 PARA_INFO_LOG("decoder length: %lu\n", *decoder_length);
102 * search for the first entry in the stco table
104 * \param buf buffer to seach
105 * \param buflen length of \a buf
106 * \param skip Upon succesful return, this contains the number
107 * of bytes to skip from the input buffer.
109 * \return the position of the first entry in the table on success,
112 ssize_t aac_find_entry_point(char *buf, size_t buflen, size_t *skip)
117 for (i = 0; i + 20 < buflen; i++) {
120 if (p[0] != 's' || p[1] != 't' || p[2] != 'c' || p[3] != 'o')
122 PARA_INFO_LOG("found stco@%zu\n", i);
124 ret = read_u32_be(buf + i); /* first offset */
126 PARA_INFO_LOG("entry point: %zd\n", ret);
130 PARA_WARNING_LOG("stco not found, buflen: %zu\n", buflen);