You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

617 lines
21KB

  1. /*
  2. * Audio Toolbox system codecs
  3. *
  4. * copyright (c) 2016 Rodger Combs
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg 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 GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include <AudioToolbox/AudioToolbox.h>
  23. #include "config.h"
  24. #include "avcodec.h"
  25. #include "ac3_parser.h"
  26. #include "bytestream.h"
  27. #include "internal.h"
  28. #include "mpegaudiodecheader.h"
  29. #include "libavutil/avassert.h"
  30. #include "libavutil/opt.h"
  31. #include "libavutil/log.h"
  32. #if __MAC_OS_X_VERSION_MIN_REQUIRED < 101100
  33. #define kAudioFormatEnhancedAC3 'ec-3'
  34. #endif
  35. typedef struct ATDecodeContext {
  36. AVClass *av_class;
  37. AudioConverterRef converter;
  38. AudioStreamPacketDescription pkt_desc;
  39. AVPacket in_pkt;
  40. AVPacket new_in_pkt;
  41. char *decoded_data;
  42. int channel_map[64];
  43. uint8_t *extradata;
  44. int extradata_size;
  45. int64_t last_pts;
  46. int eof;
  47. } ATDecodeContext;
  48. static UInt32 ffat_get_format_id(enum AVCodecID codec, int profile)
  49. {
  50. switch (codec) {
  51. case AV_CODEC_ID_AAC:
  52. return kAudioFormatMPEG4AAC;
  53. case AV_CODEC_ID_AC3:
  54. return kAudioFormatAC3;
  55. case AV_CODEC_ID_ADPCM_IMA_QT:
  56. return kAudioFormatAppleIMA4;
  57. case AV_CODEC_ID_ALAC:
  58. return kAudioFormatAppleLossless;
  59. case AV_CODEC_ID_AMR_NB:
  60. return kAudioFormatAMR;
  61. case AV_CODEC_ID_EAC3:
  62. return kAudioFormatEnhancedAC3;
  63. case AV_CODEC_ID_GSM_MS:
  64. return kAudioFormatMicrosoftGSM;
  65. case AV_CODEC_ID_ILBC:
  66. return kAudioFormatiLBC;
  67. case AV_CODEC_ID_MP1:
  68. return kAudioFormatMPEGLayer1;
  69. case AV_CODEC_ID_MP2:
  70. return kAudioFormatMPEGLayer2;
  71. case AV_CODEC_ID_MP3:
  72. return kAudioFormatMPEGLayer3;
  73. case AV_CODEC_ID_PCM_ALAW:
  74. return kAudioFormatALaw;
  75. case AV_CODEC_ID_PCM_MULAW:
  76. return kAudioFormatULaw;
  77. case AV_CODEC_ID_QDMC:
  78. return kAudioFormatQDesign;
  79. case AV_CODEC_ID_QDM2:
  80. return kAudioFormatQDesign2;
  81. default:
  82. av_assert0(!"Invalid codec ID!");
  83. return 0;
  84. }
  85. }
  86. static int ffat_get_channel_id(AudioChannelLabel label)
  87. {
  88. if (label == 0)
  89. return -1;
  90. else if (label <= kAudioChannelLabel_LFEScreen)
  91. return label - 1;
  92. else if (label <= kAudioChannelLabel_RightSurround)
  93. return label + 4;
  94. else if (label <= kAudioChannelLabel_CenterSurround)
  95. return label + 1;
  96. else if (label <= kAudioChannelLabel_RightSurroundDirect)
  97. return label + 23;
  98. else if (label <= kAudioChannelLabel_TopBackRight)
  99. return label - 1;
  100. else if (label < kAudioChannelLabel_RearSurroundLeft)
  101. return -1;
  102. else if (label <= kAudioChannelLabel_RearSurroundRight)
  103. return label - 29;
  104. else if (label <= kAudioChannelLabel_RightWide)
  105. return label - 4;
  106. else if (label == kAudioChannelLabel_LFE2)
  107. return ff_ctzll(AV_CH_LOW_FREQUENCY_2);
  108. else if (label == kAudioChannelLabel_Mono)
  109. return ff_ctzll(AV_CH_FRONT_CENTER);
  110. else
  111. return -1;
  112. }
  113. static int ffat_compare_channel_descriptions(const void* a, const void* b)
  114. {
  115. const AudioChannelDescription* da = a;
  116. const AudioChannelDescription* db = b;
  117. return ffat_get_channel_id(da->mChannelLabel) - ffat_get_channel_id(db->mChannelLabel);
  118. }
  119. static AudioChannelLayout *ffat_convert_layout(AudioChannelLayout *layout, UInt32* size)
  120. {
  121. AudioChannelLayoutTag tag = layout->mChannelLayoutTag;
  122. AudioChannelLayout *new_layout;
  123. if (tag == kAudioChannelLayoutTag_UseChannelDescriptions)
  124. return layout;
  125. else if (tag == kAudioChannelLayoutTag_UseChannelBitmap)
  126. AudioFormatGetPropertyInfo(kAudioFormatProperty_ChannelLayoutForBitmap,
  127. sizeof(UInt32), &layout->mChannelBitmap, size);
  128. else
  129. AudioFormatGetPropertyInfo(kAudioFormatProperty_ChannelLayoutForTag,
  130. sizeof(AudioChannelLayoutTag), &tag, size);
  131. new_layout = av_malloc(*size);
  132. if (!new_layout) {
  133. av_free(layout);
  134. return NULL;
  135. }
  136. if (tag == kAudioChannelLayoutTag_UseChannelBitmap)
  137. AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForBitmap,
  138. sizeof(UInt32), &layout->mChannelBitmap, size, new_layout);
  139. else
  140. AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForTag,
  141. sizeof(AudioChannelLayoutTag), &tag, size, new_layout);
  142. new_layout->mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelDescriptions;
  143. av_free(layout);
  144. return new_layout;
  145. }
  146. static int ffat_update_ctx(AVCodecContext *avctx)
  147. {
  148. ATDecodeContext *at = avctx->priv_data;
  149. AudioStreamBasicDescription format;
  150. UInt32 size = sizeof(format);
  151. if (!AudioConverterGetProperty(at->converter,
  152. kAudioConverterCurrentInputStreamDescription,
  153. &size, &format)) {
  154. if (format.mSampleRate)
  155. avctx->sample_rate = format.mSampleRate;
  156. avctx->channels = format.mChannelsPerFrame;
  157. avctx->channel_layout = av_get_default_channel_layout(avctx->channels);
  158. avctx->frame_size = format.mFramesPerPacket;
  159. }
  160. if (!AudioConverterGetProperty(at->converter,
  161. kAudioConverterCurrentOutputStreamDescription,
  162. &size, &format)) {
  163. format.mSampleRate = avctx->sample_rate;
  164. format.mChannelsPerFrame = avctx->channels;
  165. AudioConverterSetProperty(at->converter,
  166. kAudioConverterCurrentOutputStreamDescription,
  167. size, &format);
  168. }
  169. if (!AudioConverterGetPropertyInfo(at->converter, kAudioConverterOutputChannelLayout,
  170. &size, NULL) && size) {
  171. AudioChannelLayout *layout = av_malloc(size);
  172. uint64_t layout_mask = 0;
  173. int i;
  174. if (!layout)
  175. return AVERROR(ENOMEM);
  176. AudioConverterGetProperty(at->converter, kAudioConverterOutputChannelLayout,
  177. &size, layout);
  178. if (!(layout = ffat_convert_layout(layout, &size)))
  179. return AVERROR(ENOMEM);
  180. for (i = 0; i < layout->mNumberChannelDescriptions; i++) {
  181. int id = ffat_get_channel_id(layout->mChannelDescriptions[i].mChannelLabel);
  182. if (id < 0)
  183. goto done;
  184. if (layout_mask & (1 << id))
  185. goto done;
  186. layout_mask |= 1 << id;
  187. layout->mChannelDescriptions[i].mChannelFlags = i; // Abusing flags as index
  188. }
  189. avctx->channel_layout = layout_mask;
  190. qsort(layout->mChannelDescriptions, layout->mNumberChannelDescriptions,
  191. sizeof(AudioChannelDescription), &ffat_compare_channel_descriptions);
  192. for (i = 0; i < layout->mNumberChannelDescriptions; i++)
  193. at->channel_map[i] = layout->mChannelDescriptions[i].mChannelFlags;
  194. done:
  195. av_free(layout);
  196. }
  197. if (!avctx->frame_size)
  198. avctx->frame_size = 2048;
  199. return 0;
  200. }
  201. static void put_descr(PutByteContext *pb, int tag, unsigned int size)
  202. {
  203. int i = 3;
  204. bytestream2_put_byte(pb, tag);
  205. for (; i > 0; i--)
  206. bytestream2_put_byte(pb, (size >> (7 * i)) | 0x80);
  207. bytestream2_put_byte(pb, size & 0x7F);
  208. }
  209. static uint8_t* ffat_get_magic_cookie(AVCodecContext *avctx, UInt32 *cookie_size)
  210. {
  211. ATDecodeContext *at = avctx->priv_data;
  212. if (avctx->codec_id == AV_CODEC_ID_AAC) {
  213. char *extradata;
  214. PutByteContext pb;
  215. *cookie_size = 5 + 3 + 5+13 + 5+at->extradata_size;
  216. if (!(extradata = av_malloc(*cookie_size)))
  217. return NULL;
  218. bytestream2_init_writer(&pb, extradata, *cookie_size);
  219. // ES descriptor
  220. put_descr(&pb, 0x03, 3 + 5+13 + 5+at->extradata_size);
  221. bytestream2_put_be16(&pb, 0);
  222. bytestream2_put_byte(&pb, 0x00); // flags (= no flags)
  223. // DecoderConfig descriptor
  224. put_descr(&pb, 0x04, 13 + 5+at->extradata_size);
  225. // Object type indication
  226. bytestream2_put_byte(&pb, 0x40);
  227. bytestream2_put_byte(&pb, 0x15); // flags (= Audiostream)
  228. bytestream2_put_be24(&pb, 0); // Buffersize DB
  229. bytestream2_put_be32(&pb, 0); // maxbitrate
  230. bytestream2_put_be32(&pb, 0); // avgbitrate
  231. // DecoderSpecific info descriptor
  232. put_descr(&pb, 0x05, at->extradata_size);
  233. bytestream2_put_buffer(&pb, at->extradata, at->extradata_size);
  234. return extradata;
  235. } else {
  236. *cookie_size = at->extradata_size;
  237. return at->extradata;
  238. }
  239. }
  240. static av_cold int ffat_usable_extradata(AVCodecContext *avctx)
  241. {
  242. ATDecodeContext *at = avctx->priv_data;
  243. return at->extradata_size &&
  244. (avctx->codec_id == AV_CODEC_ID_ALAC ||
  245. avctx->codec_id == AV_CODEC_ID_QDM2 ||
  246. avctx->codec_id == AV_CODEC_ID_QDMC ||
  247. avctx->codec_id == AV_CODEC_ID_AAC);
  248. }
  249. static int ffat_set_extradata(AVCodecContext *avctx)
  250. {
  251. ATDecodeContext *at = avctx->priv_data;
  252. if (ffat_usable_extradata(avctx)) {
  253. OSStatus status;
  254. UInt32 cookie_size;
  255. uint8_t *cookie = ffat_get_magic_cookie(avctx, &cookie_size);
  256. if (!cookie)
  257. return AVERROR(ENOMEM);
  258. status = AudioConverterSetProperty(at->converter,
  259. kAudioConverterDecompressionMagicCookie,
  260. cookie_size, cookie);
  261. if (status != 0)
  262. av_log(avctx, AV_LOG_WARNING, "AudioToolbox cookie error: %i\n", (int)status);
  263. if (cookie != at->extradata)
  264. av_free(cookie);
  265. }
  266. return 0;
  267. }
  268. static av_cold int ffat_create_decoder(AVCodecContext *avctx, AVPacket *pkt)
  269. {
  270. ATDecodeContext *at = avctx->priv_data;
  271. OSStatus status;
  272. int i;
  273. enum AVSampleFormat sample_fmt = (avctx->bits_per_raw_sample == 32) ?
  274. AV_SAMPLE_FMT_S32 : AV_SAMPLE_FMT_S16;
  275. AudioStreamBasicDescription in_format = {
  276. .mFormatID = ffat_get_format_id(avctx->codec_id, avctx->profile),
  277. .mBytesPerPacket = (avctx->codec_id == AV_CODEC_ID_ILBC) ? avctx->block_align : 0,
  278. };
  279. AudioStreamBasicDescription out_format = {
  280. .mFormatID = kAudioFormatLinearPCM,
  281. .mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked,
  282. .mFramesPerPacket = 1,
  283. .mBitsPerChannel = av_get_bytes_per_sample(sample_fmt) * 8,
  284. };
  285. avctx->sample_fmt = sample_fmt;
  286. if (ffat_usable_extradata(avctx)) {
  287. UInt32 format_size = sizeof(in_format);
  288. UInt32 cookie_size;
  289. uint8_t *cookie = ffat_get_magic_cookie(avctx, &cookie_size);
  290. if (!cookie)
  291. return AVERROR(ENOMEM);
  292. status = AudioFormatGetProperty(kAudioFormatProperty_FormatInfo,
  293. cookie_size, cookie, &format_size, &in_format);
  294. if (cookie != at->extradata)
  295. av_free(cookie);
  296. if (status != 0) {
  297. av_log(avctx, AV_LOG_ERROR, "AudioToolbox header-parse error: %i\n", (int)status);
  298. return AVERROR_UNKNOWN;
  299. }
  300. #if CONFIG_MP1_AT_DECODER || CONFIG_MP2_AT_DECODER || CONFIG_MP3_AT_DECODER
  301. } else if (pkt && pkt->size >= 4 &&
  302. (avctx->codec_id == AV_CODEC_ID_MP1 ||
  303. avctx->codec_id == AV_CODEC_ID_MP2 ||
  304. avctx->codec_id == AV_CODEC_ID_MP3)) {
  305. enum AVCodecID codec_id;
  306. int bit_rate;
  307. if (ff_mpa_decode_header(AV_RB32(pkt->data), &avctx->sample_rate,
  308. &in_format.mChannelsPerFrame, &avctx->frame_size,
  309. &bit_rate, &codec_id) < 0)
  310. return AVERROR_INVALIDDATA;
  311. avctx->bit_rate = bit_rate;
  312. in_format.mSampleRate = avctx->sample_rate;
  313. #endif
  314. #if CONFIG_AC3_AT_DECODER || CONFIG_EAC3_AT_DECODER
  315. } else if (pkt && pkt->size >= 7 &&
  316. (avctx->codec_id == AV_CODEC_ID_AC3 ||
  317. avctx->codec_id == AV_CODEC_ID_EAC3)) {
  318. AC3HeaderInfo hdr, *phdr = &hdr;
  319. GetBitContext gbc;
  320. init_get_bits(&gbc, pkt->data, pkt->size);
  321. if (avpriv_ac3_parse_header(&gbc, &phdr) < 0)
  322. return AVERROR_INVALIDDATA;
  323. in_format.mSampleRate = hdr.sample_rate;
  324. in_format.mChannelsPerFrame = hdr.channels;
  325. avctx->frame_size = hdr.num_blocks * 256;
  326. avctx->bit_rate = hdr.bit_rate;
  327. #endif
  328. } else {
  329. in_format.mSampleRate = avctx->sample_rate ? avctx->sample_rate : 44100;
  330. in_format.mChannelsPerFrame = avctx->channels ? avctx->channels : 1;
  331. }
  332. avctx->sample_rate = out_format.mSampleRate = in_format.mSampleRate;
  333. avctx->channels = out_format.mChannelsPerFrame = in_format.mChannelsPerFrame;
  334. if (avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_QT)
  335. in_format.mFramesPerPacket = 64;
  336. status = AudioConverterNew(&in_format, &out_format, &at->converter);
  337. if (status != 0) {
  338. av_log(avctx, AV_LOG_ERROR, "AudioToolbox init error: %i\n", (int)status);
  339. return AVERROR_UNKNOWN;
  340. }
  341. if ((status = ffat_set_extradata(avctx)) < 0)
  342. return status;
  343. for (i = 0; i < (sizeof(at->channel_map) / sizeof(at->channel_map[0])); i++)
  344. at->channel_map[i] = i;
  345. ffat_update_ctx(avctx);
  346. if(!(at->decoded_data = av_malloc(av_get_bytes_per_sample(avctx->sample_fmt)
  347. * avctx->frame_size * avctx->channels)))
  348. return AVERROR(ENOMEM);
  349. at->last_pts = AV_NOPTS_VALUE;
  350. return 0;
  351. }
  352. static av_cold int ffat_init_decoder(AVCodecContext *avctx)
  353. {
  354. ATDecodeContext *at = avctx->priv_data;
  355. if (avctx->extradata_size) {
  356. at->extradata = av_mallocz(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
  357. if (!at->extradata)
  358. return AVERROR(ENOMEM);
  359. at->extradata_size = avctx->extradata_size;
  360. memcpy(at->extradata, avctx->extradata, avctx->extradata_size);
  361. }
  362. if ((avctx->channels && avctx->sample_rate) || ffat_usable_extradata(avctx))
  363. return ffat_create_decoder(avctx, NULL);
  364. else
  365. return 0;
  366. }
  367. static OSStatus ffat_decode_callback(AudioConverterRef converter, UInt32 *nb_packets,
  368. AudioBufferList *data,
  369. AudioStreamPacketDescription **packets,
  370. void *inctx)
  371. {
  372. AVCodecContext *avctx = inctx;
  373. ATDecodeContext *at = avctx->priv_data;
  374. if (at->eof) {
  375. *nb_packets = 0;
  376. if (packets) {
  377. *packets = &at->pkt_desc;
  378. at->pkt_desc.mDataByteSize = 0;
  379. }
  380. return 0;
  381. }
  382. av_packet_unref(&at->in_pkt);
  383. av_packet_move_ref(&at->in_pkt, &at->new_in_pkt);
  384. if (!at->in_pkt.data) {
  385. *nb_packets = 0;
  386. return 1;
  387. }
  388. data->mNumberBuffers = 1;
  389. data->mBuffers[0].mNumberChannels = 0;
  390. data->mBuffers[0].mDataByteSize = at->in_pkt.size;
  391. data->mBuffers[0].mData = at->in_pkt.data;
  392. *nb_packets = 1;
  393. if (packets) {
  394. *packets = &at->pkt_desc;
  395. at->pkt_desc.mDataByteSize = at->in_pkt.size;
  396. }
  397. return 0;
  398. }
  399. #define COPY_SAMPLES(type) \
  400. type *in_ptr = (type*)at->decoded_data; \
  401. type *end_ptr = in_ptr + frame->nb_samples * avctx->channels; \
  402. type *out_ptr = (type*)frame->data[0]; \
  403. for (; in_ptr < end_ptr; in_ptr += avctx->channels, out_ptr += avctx->channels) { \
  404. int c; \
  405. for (c = 0; c < avctx->channels; c++) \
  406. out_ptr[c] = in_ptr[at->channel_map[c]]; \
  407. }
  408. static void ffat_copy_samples(AVCodecContext *avctx, AVFrame *frame)
  409. {
  410. ATDecodeContext *at = avctx->priv_data;
  411. if (avctx->sample_fmt == AV_SAMPLE_FMT_S32) {
  412. COPY_SAMPLES(int32_t);
  413. } else {
  414. COPY_SAMPLES(int16_t);
  415. }
  416. }
  417. static int ffat_decode(AVCodecContext *avctx, void *data,
  418. int *got_frame_ptr, AVPacket *avpkt)
  419. {
  420. ATDecodeContext *at = avctx->priv_data;
  421. AVFrame *frame = data;
  422. int pkt_size = avpkt->size;
  423. OSStatus ret;
  424. AudioBufferList out_buffers;
  425. if (avctx->codec_id == AV_CODEC_ID_AAC) {
  426. if (!at->extradata_size) {
  427. uint8_t *side_data;
  428. int side_data_size = 0;
  429. side_data = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA,
  430. &side_data_size);
  431. if (side_data_size) {
  432. at->extradata = av_mallocz(side_data_size + AV_INPUT_BUFFER_PADDING_SIZE);
  433. if (!at->extradata)
  434. return AVERROR(ENOMEM);
  435. at->extradata_size = side_data_size;
  436. memcpy(at->extradata, side_data, side_data_size);
  437. }
  438. }
  439. }
  440. if (!at->converter) {
  441. if ((ret = ffat_create_decoder(avctx, avpkt)) < 0) {
  442. return ret;
  443. }
  444. }
  445. out_buffers = (AudioBufferList){
  446. .mNumberBuffers = 1,
  447. .mBuffers = {
  448. {
  449. .mNumberChannels = avctx->channels,
  450. .mDataByteSize = av_get_bytes_per_sample(avctx->sample_fmt) * avctx->frame_size
  451. * avctx->channels,
  452. }
  453. }
  454. };
  455. av_packet_unref(&at->new_in_pkt);
  456. if (avpkt->size) {
  457. if ((ret = av_packet_ref(&at->new_in_pkt, avpkt)) < 0) {
  458. return ret;
  459. }
  460. } else {
  461. at->eof = 1;
  462. }
  463. frame->sample_rate = avctx->sample_rate;
  464. frame->nb_samples = avctx->frame_size;
  465. out_buffers.mBuffers[0].mData = at->decoded_data;
  466. ret = AudioConverterFillComplexBuffer(at->converter, ffat_decode_callback, avctx,
  467. &frame->nb_samples, &out_buffers, NULL);
  468. if ((!ret || ret == 1) && frame->nb_samples) {
  469. if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
  470. return ret;
  471. ffat_copy_samples(avctx, frame);
  472. *got_frame_ptr = 1;
  473. if (at->last_pts != AV_NOPTS_VALUE) {
  474. frame->pts = at->last_pts;
  475. #if FF_API_PKT_PTS
  476. FF_DISABLE_DEPRECATION_WARNINGS
  477. frame->pkt_pts = at->last_pts;
  478. FF_ENABLE_DEPRECATION_WARNINGS
  479. #endif
  480. at->last_pts = avpkt->pts;
  481. }
  482. } else if (ret && ret != 1) {
  483. av_log(avctx, AV_LOG_WARNING, "Decode error: %i\n", ret);
  484. } else {
  485. at->last_pts = avpkt->pts;
  486. }
  487. return pkt_size;
  488. }
  489. static av_cold void ffat_decode_flush(AVCodecContext *avctx)
  490. {
  491. ATDecodeContext *at = avctx->priv_data;
  492. AudioConverterReset(at->converter);
  493. av_packet_unref(&at->new_in_pkt);
  494. av_packet_unref(&at->in_pkt);
  495. }
  496. static av_cold int ffat_close_decoder(AVCodecContext *avctx)
  497. {
  498. ATDecodeContext *at = avctx->priv_data;
  499. if (at->converter)
  500. AudioConverterDispose(at->converter);
  501. av_packet_unref(&at->new_in_pkt);
  502. av_packet_unref(&at->in_pkt);
  503. av_freep(&at->decoded_data);
  504. av_freep(&at->extradata);
  505. return 0;
  506. }
  507. #define FFAT_DEC_CLASS(NAME) \
  508. static const AVClass ffat_##NAME##_dec_class = { \
  509. .class_name = "at_" #NAME "_dec", \
  510. .version = LIBAVUTIL_VERSION_INT, \
  511. };
  512. #define FFAT_DEC(NAME, ID, bsf_name) \
  513. FFAT_DEC_CLASS(NAME) \
  514. AVCodec ff_##NAME##_at_decoder = { \
  515. .name = #NAME "_at", \
  516. .long_name = NULL_IF_CONFIG_SMALL(#NAME " (AudioToolbox)"), \
  517. .type = AVMEDIA_TYPE_AUDIO, \
  518. .id = ID, \
  519. .priv_data_size = sizeof(ATDecodeContext), \
  520. .init = ffat_init_decoder, \
  521. .close = ffat_close_decoder, \
  522. .decode = ffat_decode, \
  523. .flush = ffat_decode_flush, \
  524. .priv_class = &ffat_##NAME##_dec_class, \
  525. .bsfs = bsf_name, \
  526. .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY, \
  527. .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, \
  528. };
  529. FFAT_DEC(aac, AV_CODEC_ID_AAC, "aac_adtstoasc")
  530. FFAT_DEC(ac3, AV_CODEC_ID_AC3, NULL)
  531. FFAT_DEC(adpcm_ima_qt, AV_CODEC_ID_ADPCM_IMA_QT, NULL)
  532. FFAT_DEC(alac, AV_CODEC_ID_ALAC, NULL)
  533. FFAT_DEC(amr_nb, AV_CODEC_ID_AMR_NB, NULL)
  534. FFAT_DEC(eac3, AV_CODEC_ID_EAC3, NULL)
  535. FFAT_DEC(gsm_ms, AV_CODEC_ID_GSM_MS, NULL)
  536. FFAT_DEC(ilbc, AV_CODEC_ID_ILBC, NULL)
  537. FFAT_DEC(mp1, AV_CODEC_ID_MP1, NULL)
  538. FFAT_DEC(mp2, AV_CODEC_ID_MP2, NULL)
  539. FFAT_DEC(mp3, AV_CODEC_ID_MP3, NULL)
  540. FFAT_DEC(pcm_alaw, AV_CODEC_ID_PCM_ALAW, NULL)
  541. FFAT_DEC(pcm_mulaw, AV_CODEC_ID_PCM_MULAW, NULL)
  542. FFAT_DEC(qdmc, AV_CODEC_ID_QDMC, NULL)
  543. FFAT_DEC(qdm2, AV_CODEC_ID_QDM2, NULL)