helix-aac.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. /*
  2. * Squeezelite - lightweight headless squeezebox emulator
  3. *
  4. * (c) Adrian Smith 2012-2015, triode1@btinternet.com
  5. * Ralph Irving 2015-2017, ralph_irving@hotmail.com
  6. * Philippe, philippe_44@outlook.com
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "squeezelite.h"
  23. #include <aacdec.h>
  24. // AAC_MAX_SAMPLES is the number of samples for one channel
  25. #define FRAME_BUF (AAC_MAX_NSAMPS*2)
  26. #if BYTES_PER_FRAME == 4
  27. #define ALIGN(n) (n)
  28. #else
  29. #define ALIGN(n) (n << 8)
  30. #endif
  31. #define WRAPBUF_LEN 2048
  32. static unsigned rates[] = { 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350 };
  33. struct chunk_table {
  34. u32_t sample, offset;
  35. };
  36. struct helixaac {
  37. HAACDecoder hAac;
  38. u8_t type;
  39. u8_t *write_buf;
  40. u8_t *wrap_buf;
  41. // following used for mp4 only
  42. u32_t consume;
  43. u32_t pos;
  44. u32_t sample;
  45. u32_t nextchunk;
  46. void *stsc;
  47. u32_t skip;
  48. u64_t samples;
  49. u64_t sttssamples;
  50. bool empty;
  51. struct chunk_table *chunkinfo;
  52. #if !LINKALL
  53. #endif
  54. };
  55. static struct helixaac *a;
  56. extern log_level loglevel;
  57. extern struct buffer *streambuf;
  58. extern struct buffer *outputbuf;
  59. extern struct streamstate stream;
  60. extern struct outputstate output;
  61. extern struct decodestate decode;
  62. extern struct processstate process;
  63. #define LOCK_S mutex_lock(streambuf->mutex)
  64. #define UNLOCK_S mutex_unlock(streambuf->mutex)
  65. #define LOCK_O mutex_lock(outputbuf->mutex)
  66. #define UNLOCK_O mutex_unlock(outputbuf->mutex)
  67. #if PROCESS
  68. #define LOCK_O_direct if (decode.direct) mutex_lock(outputbuf->mutex)
  69. #define UNLOCK_O_direct if (decode.direct) mutex_unlock(outputbuf->mutex)
  70. #define IF_DIRECT(x) if (decode.direct) { x }
  71. #define IF_PROCESS(x) if (!decode.direct) { x }
  72. #else
  73. #define LOCK_O_direct mutex_lock(outputbuf->mutex)
  74. #define UNLOCK_O_direct mutex_unlock(outputbuf->mutex)
  75. #define IF_DIRECT(x) { x }
  76. #define IF_PROCESS(x)
  77. #endif
  78. #if LINKALL
  79. #define HAAC(h, fn, ...) (AAC ## fn)(__VA_ARGS__)
  80. #else
  81. #define HAAC(h, fn, ...) (h)->AAC##fn(__VA_ARGS__)
  82. #endif
  83. // minimal code for mp4 file parsing to extract audio config and find media data
  84. // adapted from faad2/common/mp4ff
  85. u32_t mp4_desc_length(u8_t **buf) {
  86. u8_t b;
  87. u8_t num_bytes = 0;
  88. u32_t length = 0;
  89. do {
  90. b = **buf;
  91. *buf += 1;
  92. num_bytes++;
  93. length = (length << 7) | (b & 0x7f);
  94. } while ((b & 0x80) && num_bytes < 4);
  95. return length;
  96. }
  97. // read mp4 header to extract config data
  98. static int read_mp4_header(unsigned long *samplerate_p, unsigned char *channels_p) {
  99. size_t bytes = min(_buf_used(streambuf), _buf_cont_read(streambuf));
  100. char type[5];
  101. u32_t len;
  102. while (bytes >= 8) {
  103. // count trak to find the first playable one
  104. static unsigned trak, play;
  105. u32_t consume;
  106. len = unpackN((u32_t *)streambuf->readp);
  107. memcpy(type, streambuf->readp + 4, 4);
  108. type[4] = '\0';
  109. if (!strcmp(type, "moov")) {
  110. trak = 0;
  111. play = 0;
  112. }
  113. if (!strcmp(type, "trak")) {
  114. trak++;
  115. }
  116. // extract audio config from within esds and pass to DecInit2
  117. if (!strcmp(type, "esds") && bytes > len) {
  118. u8_t *ptr = streambuf->readp + 12;
  119. AACFrameInfo info;
  120. if (*ptr++ == 0x03) {
  121. mp4_desc_length(&ptr);
  122. ptr += 4;
  123. } else {
  124. ptr += 3;
  125. }
  126. mp4_desc_length(&ptr);
  127. ptr += 13;
  128. if (*ptr++ != 0x05) {
  129. LOG_WARN("error parsing esds");
  130. return -1;
  131. }
  132. mp4_desc_length(&ptr);
  133. info.profile = *ptr >> 3;
  134. info.sampRateCore = (*ptr++ & 0x07) << 1;
  135. info.sampRateCore |= (*ptr >> 7) & 0x01;
  136. info.sampRateCore = rates[info.sampRateCore];
  137. info.nChans = (*ptr & 0x7f) >> 3;
  138. *channels_p = info.nChans;
  139. *samplerate_p = info.sampRateCore;
  140. HAAC(a, SetRawBlockParams, a->hAac, 0, &info);
  141. LOG_DEBUG("playable aac track: %u (p:%x, r:%d, c:%d)", trak, info.profile, info.sampRateCore, info.nChans);
  142. play = trak;
  143. }
  144. // extract the total number of samples from stts
  145. if (!strcmp(type, "stts") && bytes > len) {
  146. u32_t i;
  147. u8_t *ptr = streambuf->readp + 12;
  148. u32_t entries = unpackN((u32_t *)ptr);
  149. ptr += 4;
  150. for (i = 0; i < entries; ++i) {
  151. u32_t count = unpackN((u32_t *)ptr);
  152. u32_t size = unpackN((u32_t *)(ptr + 4));
  153. a->sttssamples += count * size;
  154. ptr += 8;
  155. }
  156. LOG_DEBUG("total number of samples contained in stts: " FMT_u64, a->sttssamples);
  157. }
  158. // stash sample to chunk info, assume it comes before stco
  159. if (!strcmp(type, "stsc") && bytes > len && !a->chunkinfo) {
  160. a->stsc = malloc(len - 12);
  161. if (a->stsc == NULL) {
  162. LOG_WARN("malloc fail");
  163. return -1;
  164. }
  165. memcpy(a->stsc, streambuf->readp + 12, len - 12);
  166. }
  167. // build offsets table from stco and stored stsc
  168. if (!strcmp(type, "stco") && bytes > len && play == trak) {
  169. u32_t i;
  170. // extract chunk offsets
  171. u8_t *ptr = streambuf->readp + 12;
  172. u32_t entries = unpackN((u32_t *)ptr);
  173. ptr += 4;
  174. a->chunkinfo = malloc(sizeof(struct chunk_table) * (entries + 1));
  175. if (a->chunkinfo == NULL) {
  176. LOG_WARN("malloc fail");
  177. return -1;
  178. }
  179. for (i = 0; i < entries; ++i) {
  180. a->chunkinfo[i].offset = unpackN((u32_t *)ptr);
  181. a->chunkinfo[i].sample = 0;
  182. ptr += 4;
  183. }
  184. a->chunkinfo[i].sample = 0;
  185. a->chunkinfo[i].offset = 0;
  186. // fill in first sample id for each chunk from stored stsc
  187. if (a->stsc) {
  188. u32_t stsc_entries = unpackN((u32_t *)a->stsc);
  189. u32_t sample = 0;
  190. u32_t last = 0, last_samples = 0;
  191. u8_t *ptr = (u8_t *)a->stsc + 4;
  192. while (stsc_entries--) {
  193. u32_t first = unpackN((u32_t *)ptr);
  194. u32_t samples = unpackN((u32_t *)(ptr + 4));
  195. if (last) {
  196. for (i = last - 1; i < first - 1; ++i) {
  197. a->chunkinfo[i].sample = sample;
  198. sample += last_samples;
  199. }
  200. }
  201. if (stsc_entries == 0) {
  202. for (i = first - 1; i < entries; ++i) {
  203. a->chunkinfo[i].sample = sample;
  204. sample += samples;
  205. }
  206. }
  207. last = first;
  208. last_samples = samples;
  209. ptr += 12;
  210. }
  211. free(a->stsc);
  212. a->stsc = NULL;
  213. }
  214. }
  215. // found media data, advance to start of first chunk and return
  216. if (!strcmp(type, "mdat")) {
  217. _buf_inc_readp(streambuf, 8);
  218. a->pos += 8;
  219. bytes -= 8;
  220. if (play) {
  221. LOG_DEBUG("type: mdat len: %u pos: %u", len, a->pos);
  222. if (a->chunkinfo && a->chunkinfo[0].offset > a->pos) {
  223. u32_t skip = a->chunkinfo[0].offset - a->pos;
  224. LOG_DEBUG("skipping: %u", skip);
  225. if (skip <= bytes) {
  226. _buf_inc_readp(streambuf, skip);
  227. a->pos += skip;
  228. } else {
  229. a->consume = skip;
  230. }
  231. }
  232. a->sample = a->nextchunk = 1;
  233. return 1;
  234. } else {
  235. LOG_DEBUG("type: mdat len: %u, no playable track found", len);
  236. return -1;
  237. }
  238. }
  239. // parse key-value atoms within ilst ---- entries to get encoder padding within iTunSMPB entry for gapless
  240. if (!strcmp(type, "----") && bytes > len) {
  241. u8_t *ptr = streambuf->readp + 8;
  242. u32_t remain = len - 8, size;
  243. if (!memcmp(ptr + 4, "mean", 4) && (size = unpackN((u32_t *)ptr)) < remain) {
  244. ptr += size; remain -= size;
  245. }
  246. if (!memcmp(ptr + 4, "name", 4) && (size = unpackN((u32_t *)ptr)) < remain && !memcmp(ptr + 12, "iTunSMPB", 8)) {
  247. ptr += size; remain -= size;
  248. }
  249. if (!memcmp(ptr + 4, "data", 4) && remain > 16 + 48) {
  250. // data is stored as hex strings: 0 start end samples
  251. u32_t b, c; u64_t d;
  252. if (sscanf((const char *)(ptr + 16), "%x %x %x " FMT_x64, &b, &b, &c, &d) == 4) {
  253. LOG_DEBUG("iTunSMPB start: %u end: %u samples: " FMT_u64, b, c, d);
  254. if (a->sttssamples && a->sttssamples < b + c + d) {
  255. LOG_DEBUG("reducing samples as stts count is less");
  256. d = a->sttssamples - (b + c);
  257. }
  258. a->skip = b;
  259. a->samples = d;
  260. }
  261. }
  262. }
  263. // default to consuming entire box
  264. consume = len;
  265. // read into these boxes so reduce consume
  266. if (!strcmp(type, "moov") || !strcmp(type, "trak") || !strcmp(type, "mdia") || !strcmp(type, "minf") || !strcmp(type, "stbl") ||
  267. !strcmp(type, "udta") || !strcmp(type, "ilst")) {
  268. consume = 8;
  269. }
  270. // special cases which mix mix data in the enclosing box which we want to read into
  271. if (!strcmp(type, "stsd")) consume = 16;
  272. if (!strcmp(type, "mp4a")) consume = 36;
  273. if (!strcmp(type, "meta")) consume = 12;
  274. // consume rest of box if it has been parsed (all in the buffer) or is not one we want to parse
  275. if (bytes >= consume) {
  276. LOG_DEBUG("type: %s len: %u consume: %u", type, len, consume);
  277. _buf_inc_readp(streambuf, consume);
  278. a->pos += consume;
  279. bytes -= consume;
  280. } else if ( !(!strcmp(type, "esds") || !strcmp(type, "stts") || !strcmp(type, "stsc") ||
  281. !strcmp(type, "stco") || !strcmp(type, "----")) ) {
  282. LOG_DEBUG("type: %s len: %u consume: %u - partial consume: %u", type, len, consume, bytes);
  283. _buf_inc_readp(streambuf, bytes);
  284. a->pos += bytes;
  285. a->consume = consume - bytes;
  286. break;
  287. } else if (len > streambuf->size) {
  288. // can't process an atom larger than streambuf!
  289. LOG_ERROR("atom %s too large for buffer %u %u", type, len, streambuf->size);
  290. return -1;
  291. } else {
  292. // make sure there is 'len' contiguous space
  293. _buf_unwrap(streambuf, len);
  294. break;
  295. }
  296. }
  297. return 0;
  298. }
  299. static decode_state helixaac_decode(void) {
  300. size_t bytes_total, bytes_wrap;
  301. int res, bytes;
  302. static AACFrameInfo info;
  303. ISAMPLE_T *iptr;
  304. u8_t *sptr;
  305. bool endstream;
  306. frames_t frames;
  307. LOCK_S;
  308. bytes_total = _buf_used(streambuf);
  309. bytes_wrap = min(bytes_total, _buf_cont_read(streambuf));
  310. if (stream.state <= DISCONNECT && !bytes_total) {
  311. UNLOCK_S;
  312. return DECODE_COMPLETE;
  313. }
  314. if (a->consume) {
  315. u32_t consume = min(a->consume, bytes_wrap);
  316. LOG_DEBUG("consume: %u of %u", consume, a->consume);
  317. _buf_inc_readp(streambuf, consume);
  318. a->pos += consume;
  319. a->consume -= consume;
  320. UNLOCK_S;
  321. return DECODE_RUNNING;
  322. }
  323. if (decode.new_stream) {
  324. int found = 0;
  325. static unsigned char channels;
  326. static unsigned long samplerate;
  327. if (a->type == '2') {
  328. // adts stream - seek for header
  329. long n = HAAC(a, FindSyncWord, streambuf->readp, bytes_wrap);
  330. LOG_DEBUG("Sync search in %d bytes %d", bytes_wrap, n);
  331. if (n >= 0) {
  332. u8_t *p = streambuf->readp + n;
  333. int bytes = bytes_wrap - n;
  334. if (!HAAC(a, Decode, a->hAac, &p, &bytes, (short*) a->write_buf)) {
  335. HAAC(a, GetLastFrameInfo, a->hAac, &info);
  336. channels = info.nChans;
  337. samplerate = info.sampRateOut;
  338. found = 1;
  339. } else if (n == 0) n++;
  340. HAAC(a, FlushCodec, a->hAac);
  341. bytes_total -= n;
  342. bytes_wrap -= n;
  343. _buf_inc_readp(streambuf, n);
  344. } else {
  345. found = -1;
  346. }
  347. } else {
  348. // mp4 - read header
  349. found = read_mp4_header(&samplerate, &channels);
  350. }
  351. if (found == 1) {
  352. LOCK_O;
  353. output.next_sample_rate = decode_newstream(samplerate, output.supported_rates);
  354. IF_DSD( output.next_fmt = PCM; )
  355. output.track_start = outputbuf->writep;
  356. if (output.fade_mode) _checkfade(true);
  357. decode.new_stream = false;
  358. UNLOCK_O;
  359. LOG_INFO("setting track start, samplerate: %u channels: %u", samplerate, channels);
  360. bytes_total = _buf_used(streambuf);
  361. bytes_wrap = min(bytes_total, _buf_cont_read(streambuf));
  362. // come back later if we don' thave enough data
  363. if (bytes_total < WRAPBUF_LEN) {
  364. UNLOCK_S;
  365. LOG_INFO("need more audio data");
  366. return DECODE_RUNNING;
  367. }
  368. } else if (found == -1) {
  369. LOG_WARN("error reading stream header");
  370. UNLOCK_S;
  371. return DECODE_ERROR;
  372. } else {
  373. // not finished header parsing come back next time
  374. UNLOCK_S;
  375. LOG_INFO("header not found yet");
  376. return DECODE_RUNNING;
  377. }
  378. }
  379. // we always have at least WRAPBUF_LEN unless it's the end of a stream
  380. if (bytes_wrap < WRAPBUF_LEN) {
  381. // build a linear buffer if we are crossing the end of streambuf
  382. memcpy(a->wrap_buf, streambuf->readp, bytes_wrap);
  383. memcpy(a->wrap_buf + bytes_wrap, streambuf->buf, min(WRAPBUF_LEN, bytes_total) - bytes_wrap);
  384. sptr = a->wrap_buf;
  385. bytes = bytes_wrap = min(WRAPBUF_LEN, bytes_total);
  386. } else {
  387. sptr = streambuf->readp;
  388. bytes = bytes_wrap;
  389. }
  390. // decode function changes iptr, so can't use streambuf->readp (same for bytes)
  391. res = HAAC(a, Decode, a->hAac, &sptr, &bytes, (short*) a->write_buf);
  392. if (res < 0) {
  393. LOG_WARN("AAC decode error %d", res);
  394. }
  395. HAAC(a, GetLastFrameInfo, a->hAac, &info);
  396. iptr = (ISAMPLE_T *) a->write_buf;
  397. bytes = bytes_wrap - bytes;
  398. endstream = false;
  399. if (a->chunkinfo && a->chunkinfo[a->nextchunk].offset && a->sample++ == a->chunkinfo[a->nextchunk].sample) {
  400. // mp4 end of chunk - skip to next offset
  401. if (a->chunkinfo[a->nextchunk].offset > a->pos) {
  402. u32_t skip = a->chunkinfo[a->nextchunk].offset - a->pos;
  403. if (skip != bytes) {
  404. LOG_DEBUG("skipping to next chunk pos: %u consumed: %u != skip: %u", a->pos, bytes, skip);
  405. }
  406. if (bytes_total >= skip) {
  407. _buf_inc_readp(streambuf, skip);
  408. a->pos += skip;
  409. } else {
  410. a->consume = skip;
  411. }
  412. a->nextchunk++;
  413. } else {
  414. LOG_ERROR("error: need to skip backwards!");
  415. endstream = true;
  416. }
  417. } else if (bytes > 0) {
  418. // adts and mp4 when not at end of chunk
  419. _buf_inc_readp(streambuf, bytes);
  420. a->pos += bytes;
  421. } else {
  422. // error which doesn't advance streambuf - end
  423. endstream = true;
  424. }
  425. UNLOCK_S;
  426. if (endstream) {
  427. LOG_WARN("unable to decode further");
  428. return DECODE_ERROR;
  429. }
  430. if (!info.outputSamps) {
  431. a->empty = true;
  432. return DECODE_RUNNING;
  433. }
  434. frames = info.outputSamps / info.nChans;
  435. if (a->skip) {
  436. u32_t skip;
  437. if (a->empty) {
  438. a->empty = false;
  439. a->skip -= frames;
  440. LOG_DEBUG("gapless: first frame empty, skipped %u frames at start", frames);
  441. }
  442. skip = min(frames, a->skip);
  443. LOG_DEBUG("gapless: skipping %u frames at start", skip);
  444. frames -= skip;
  445. a->skip -= skip;
  446. iptr += skip * info.nChans;
  447. }
  448. if (a->samples) {
  449. if (a->samples < frames) {
  450. LOG_DEBUG("gapless: trimming %u frames from end", frames - a->samples);
  451. frames = (frames_t)a->samples;
  452. }
  453. a->samples -= frames;
  454. }
  455. LOG_SDEBUG("write %u frames", frames);
  456. LOCK_O_direct;
  457. while (frames > 0) {
  458. frames_t f;
  459. frames_t count;
  460. ISAMPLE_T *optr;
  461. IF_DIRECT(
  462. f = _buf_cont_write(outputbuf) / BYTES_PER_FRAME;
  463. optr = (ISAMPLE_T *)outputbuf->writep;
  464. );
  465. IF_PROCESS(
  466. f = process.max_in_frames;
  467. optr = (ISAMPLE_T *)process.inbuf;
  468. );
  469. f = min(f, frames);
  470. count = f;
  471. if (info.nChans == 2) {
  472. #if BYTES_PER_FRAME == 4
  473. memcpy(optr, iptr, count * BYTES_PER_FRAME);
  474. iptr += count * 2;
  475. #else
  476. while (count--) {
  477. *optr++ = *iptr++ << 8;
  478. *optr++ = *iptr++ << 8;
  479. }
  480. #endif
  481. } else if (info.nChans == 1) {
  482. while (count--) {
  483. *optr++ = ALIGN(*iptr);
  484. *optr++ = ALIGN(*iptr++);
  485. }
  486. } else {
  487. LOG_WARN("unsupported number of channels");
  488. }
  489. frames -= f;
  490. IF_DIRECT(
  491. _buf_inc_writep(outputbuf, f * BYTES_PER_FRAME);
  492. );
  493. IF_PROCESS(
  494. process.in_frames = f;
  495. if (frames) LOG_ERROR("unhandled case");
  496. );
  497. }
  498. UNLOCK_O_direct;
  499. return DECODE_RUNNING;
  500. }
  501. static void helixaac_open(u8_t size, u8_t rate, u8_t chan, u8_t endianness) {
  502. LOG_INFO("opening %s stream", size == '2' ? "adts" : "mp4");
  503. a->type = size;
  504. a->pos = a->consume = a->sample = a->nextchunk = 0;
  505. if (a->chunkinfo) {
  506. free(a->chunkinfo);
  507. }
  508. if (a->stsc) {
  509. free(a->stsc);
  510. }
  511. a->chunkinfo = NULL;
  512. a->stsc = NULL;
  513. a->skip = 0;
  514. a->samples = 0;
  515. a->sttssamples = 0;
  516. a->empty = false;
  517. if (a->hAac) {
  518. // always free decoder as flush only works when no parameter has changed
  519. HAAC(a, FreeDecoder, a->hAac);
  520. } else {
  521. a->write_buf = malloc(FRAME_BUF * BYTES_PER_FRAME);
  522. a->wrap_buf = malloc(WRAPBUF_LEN);
  523. }
  524. a->hAac = HAAC(a, InitDecoder);
  525. }
  526. static void helixaac_close(void) {
  527. HAAC(a, FreeDecoder, a->hAac);
  528. a->hAac = NULL;
  529. if (a->chunkinfo) {
  530. free(a->chunkinfo);
  531. a->chunkinfo = NULL;
  532. }
  533. if (a->stsc) {
  534. free(a->stsc);
  535. a->stsc = NULL;
  536. }
  537. free(a->write_buf);
  538. free(a->wrap_buf);
  539. }
  540. static bool load_helixaac() {
  541. #if !LINKALL
  542. void *handle = dlopen(LIBHELIX-AAC, RTLD_NOW);
  543. char *err;
  544. if (!handle) {
  545. LOG_INFO("dlerror: %s", dlerror());
  546. return false;
  547. }
  548. // load symbols here
  549. if ((err = dlerror()) != NULL) {
  550. LOG_INFO("dlerror: %s", err);
  551. return false;
  552. }
  553. LOG_INFO("loaded "LIBHELIX-AAC"");
  554. #endif
  555. return true;
  556. }
  557. struct codec *register_helixaac(void) {
  558. static struct codec ret = {
  559. 'a', // id
  560. "aac", // types
  561. WRAPBUF_LEN, // min read
  562. 20480, // min space
  563. helixaac_open, // open
  564. helixaac_close, // close
  565. helixaac_decode, // decode
  566. };
  567. a = malloc(sizeof(struct helixaac));
  568. if (!a) {
  569. return NULL;
  570. }
  571. a->hAac = NULL;
  572. a->chunkinfo = NULL;
  573. a->stsc = NULL;
  574. if (!load_helixaac()) {
  575. return NULL;
  576. }
  577. LOG_INFO("using helix-aac to decode aac");
  578. return &ret;
  579. }