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.

618 lines
24KB

  1. /*
  2. * PCM codecs
  3. * Copyright (c) 2001 Fabrice Bellard
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * PCM codecs
  24. */
  25. #include "libavutil/attributes.h"
  26. #include "libavutil/float_dsp.h"
  27. #include "avcodec.h"
  28. #include "bytestream.h"
  29. #include "internal.h"
  30. #include "mathops.h"
  31. #include "pcm_tablegen.h"
  32. static av_cold int pcm_encode_init(AVCodecContext *avctx)
  33. {
  34. avctx->frame_size = 0;
  35. switch (avctx->codec->id) {
  36. case AV_CODEC_ID_PCM_ALAW:
  37. pcm_alaw_tableinit();
  38. break;
  39. case AV_CODEC_ID_PCM_MULAW:
  40. pcm_ulaw_tableinit();
  41. break;
  42. case AV_CODEC_ID_PCM_VIDC:
  43. pcm_vidc_tableinit();
  44. break;
  45. default:
  46. break;
  47. }
  48. avctx->bits_per_coded_sample = av_get_bits_per_sample(avctx->codec->id);
  49. avctx->block_align = avctx->channels * avctx->bits_per_coded_sample / 8;
  50. avctx->bit_rate = avctx->block_align * 8LL * avctx->sample_rate;
  51. return 0;
  52. }
  53. /**
  54. * Write PCM samples macro
  55. * @param type Datatype of native machine format
  56. * @param endian bytestream_put_xxx() suffix
  57. * @param src Source pointer (variable name)
  58. * @param dst Destination pointer (variable name)
  59. * @param n Total number of samples (variable name)
  60. * @param shift Bitshift (bits)
  61. * @param offset Sample value offset
  62. */
  63. #define ENCODE(type, endian, src, dst, n, shift, offset) \
  64. samples_ ## type = (const type *) src; \
  65. for (; n > 0; n--) { \
  66. register type v = (*samples_ ## type++ >> shift) + offset; \
  67. bytestream_put_ ## endian(&dst, v); \
  68. }
  69. #define ENCODE_PLANAR(type, endian, dst, n, shift, offset) \
  70. n /= avctx->channels; \
  71. for (c = 0; c < avctx->channels; c++) { \
  72. int i; \
  73. samples_ ## type = (const type *) frame->extended_data[c]; \
  74. for (i = n; i > 0; i--) { \
  75. register type v = (*samples_ ## type++ >> shift) + offset; \
  76. bytestream_put_ ## endian(&dst, v); \
  77. } \
  78. }
  79. static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
  80. const AVFrame *frame, int *got_packet_ptr)
  81. {
  82. int n, c, sample_size, v, ret;
  83. const short *samples;
  84. unsigned char *dst;
  85. const uint8_t *samples_uint8_t;
  86. const int16_t *samples_int16_t;
  87. const int32_t *samples_int32_t;
  88. const int64_t *samples_int64_t;
  89. const uint16_t *samples_uint16_t;
  90. const uint32_t *samples_uint32_t;
  91. sample_size = av_get_bits_per_sample(avctx->codec->id) / 8;
  92. n = frame->nb_samples * avctx->channels;
  93. samples = (const short *)frame->data[0];
  94. if ((ret = ff_alloc_packet2(avctx, avpkt, n * sample_size, n * sample_size)) < 0)
  95. return ret;
  96. dst = avpkt->data;
  97. switch (avctx->codec->id) {
  98. case AV_CODEC_ID_PCM_U32LE:
  99. ENCODE(uint32_t, le32, samples, dst, n, 0, 0x80000000)
  100. break;
  101. case AV_CODEC_ID_PCM_U32BE:
  102. ENCODE(uint32_t, be32, samples, dst, n, 0, 0x80000000)
  103. break;
  104. case AV_CODEC_ID_PCM_S24LE:
  105. ENCODE(int32_t, le24, samples, dst, n, 8, 0)
  106. break;
  107. case AV_CODEC_ID_PCM_S24LE_PLANAR:
  108. ENCODE_PLANAR(int32_t, le24, dst, n, 8, 0)
  109. break;
  110. case AV_CODEC_ID_PCM_S24BE:
  111. ENCODE(int32_t, be24, samples, dst, n, 8, 0)
  112. break;
  113. case AV_CODEC_ID_PCM_U24LE:
  114. ENCODE(uint32_t, le24, samples, dst, n, 8, 0x800000)
  115. break;
  116. case AV_CODEC_ID_PCM_U24BE:
  117. ENCODE(uint32_t, be24, samples, dst, n, 8, 0x800000)
  118. break;
  119. case AV_CODEC_ID_PCM_S24DAUD:
  120. for (; n > 0; n--) {
  121. uint32_t tmp = ff_reverse[(*samples >> 8) & 0xff] +
  122. (ff_reverse[*samples & 0xff] << 8);
  123. tmp <<= 4; // sync flags would go here
  124. bytestream_put_be24(&dst, tmp);
  125. samples++;
  126. }
  127. break;
  128. case AV_CODEC_ID_PCM_U16LE:
  129. ENCODE(uint16_t, le16, samples, dst, n, 0, 0x8000)
  130. break;
  131. case AV_CODEC_ID_PCM_U16BE:
  132. ENCODE(uint16_t, be16, samples, dst, n, 0, 0x8000)
  133. break;
  134. case AV_CODEC_ID_PCM_S8:
  135. ENCODE(uint8_t, byte, samples, dst, n, 0, -128)
  136. break;
  137. case AV_CODEC_ID_PCM_S8_PLANAR:
  138. ENCODE_PLANAR(uint8_t, byte, dst, n, 0, -128)
  139. break;
  140. #if HAVE_BIGENDIAN
  141. case AV_CODEC_ID_PCM_S64LE:
  142. case AV_CODEC_ID_PCM_F64LE:
  143. ENCODE(int64_t, le64, samples, dst, n, 0, 0)
  144. break;
  145. case AV_CODEC_ID_PCM_S32LE:
  146. case AV_CODEC_ID_PCM_F32LE:
  147. ENCODE(int32_t, le32, samples, dst, n, 0, 0)
  148. break;
  149. case AV_CODEC_ID_PCM_S32LE_PLANAR:
  150. ENCODE_PLANAR(int32_t, le32, dst, n, 0, 0)
  151. break;
  152. case AV_CODEC_ID_PCM_S16LE:
  153. ENCODE(int16_t, le16, samples, dst, n, 0, 0)
  154. break;
  155. case AV_CODEC_ID_PCM_S16LE_PLANAR:
  156. ENCODE_PLANAR(int16_t, le16, dst, n, 0, 0)
  157. break;
  158. case AV_CODEC_ID_PCM_F64BE:
  159. case AV_CODEC_ID_PCM_F32BE:
  160. case AV_CODEC_ID_PCM_S64BE:
  161. case AV_CODEC_ID_PCM_S32BE:
  162. case AV_CODEC_ID_PCM_S16BE:
  163. #else
  164. case AV_CODEC_ID_PCM_S64BE:
  165. case AV_CODEC_ID_PCM_F64BE:
  166. ENCODE(int64_t, be64, samples, dst, n, 0, 0)
  167. break;
  168. case AV_CODEC_ID_PCM_F32BE:
  169. case AV_CODEC_ID_PCM_S32BE:
  170. ENCODE(int32_t, be32, samples, dst, n, 0, 0)
  171. break;
  172. case AV_CODEC_ID_PCM_S16BE:
  173. ENCODE(int16_t, be16, samples, dst, n, 0, 0)
  174. break;
  175. case AV_CODEC_ID_PCM_S16BE_PLANAR:
  176. ENCODE_PLANAR(int16_t, be16, dst, n, 0, 0)
  177. break;
  178. case AV_CODEC_ID_PCM_F64LE:
  179. case AV_CODEC_ID_PCM_F32LE:
  180. case AV_CODEC_ID_PCM_S64LE:
  181. case AV_CODEC_ID_PCM_S32LE:
  182. case AV_CODEC_ID_PCM_S16LE:
  183. #endif /* HAVE_BIGENDIAN */
  184. case AV_CODEC_ID_PCM_U8:
  185. memcpy(dst, samples, n * sample_size);
  186. break;
  187. #if HAVE_BIGENDIAN
  188. case AV_CODEC_ID_PCM_S16BE_PLANAR:
  189. #else
  190. case AV_CODEC_ID_PCM_S16LE_PLANAR:
  191. case AV_CODEC_ID_PCM_S32LE_PLANAR:
  192. #endif /* HAVE_BIGENDIAN */
  193. n /= avctx->channels;
  194. for (c = 0; c < avctx->channels; c++) {
  195. const uint8_t *src = frame->extended_data[c];
  196. bytestream_put_buffer(&dst, src, n * sample_size);
  197. }
  198. break;
  199. case AV_CODEC_ID_PCM_ALAW:
  200. for (; n > 0; n--) {
  201. v = *samples++;
  202. *dst++ = linear_to_alaw[(v + 32768) >> 2];
  203. }
  204. break;
  205. case AV_CODEC_ID_PCM_MULAW:
  206. for (; n > 0; n--) {
  207. v = *samples++;
  208. *dst++ = linear_to_ulaw[(v + 32768) >> 2];
  209. }
  210. break;
  211. case AV_CODEC_ID_PCM_VIDC:
  212. for (; n > 0; n--) {
  213. v = *samples++;
  214. *dst++ = linear_to_vidc[(v + 32768) >> 2];
  215. }
  216. break;
  217. default:
  218. return -1;
  219. }
  220. *got_packet_ptr = 1;
  221. return 0;
  222. }
  223. typedef struct PCMDecode {
  224. short table[256];
  225. void (*vector_fmul_scalar)(float *dst, const float *src, float mul,
  226. int len);
  227. float scale;
  228. } PCMDecode;
  229. static av_cold int pcm_decode_init(AVCodecContext *avctx)
  230. {
  231. PCMDecode *s = avctx->priv_data;
  232. AVFloatDSPContext *fdsp;
  233. int i;
  234. if (avctx->channels <= 0) {
  235. av_log(avctx, AV_LOG_ERROR, "PCM channels out of bounds\n");
  236. return AVERROR(EINVAL);
  237. }
  238. switch (avctx->codec_id) {
  239. case AV_CODEC_ID_PCM_ALAW:
  240. for (i = 0; i < 256; i++)
  241. s->table[i] = alaw2linear(i);
  242. break;
  243. case AV_CODEC_ID_PCM_MULAW:
  244. for (i = 0; i < 256; i++)
  245. s->table[i] = ulaw2linear(i);
  246. break;
  247. case AV_CODEC_ID_PCM_VIDC:
  248. for (i = 0; i < 256; i++)
  249. s->table[i] = vidc2linear(i);
  250. break;
  251. case AV_CODEC_ID_PCM_F16LE:
  252. case AV_CODEC_ID_PCM_F24LE:
  253. if (avctx->bits_per_coded_sample < 1 || avctx->bits_per_coded_sample > 24)
  254. return AVERROR_INVALIDDATA;
  255. s->scale = 1. / (1 << (avctx->bits_per_coded_sample - 1));
  256. fdsp = avpriv_float_dsp_alloc(0);
  257. if (!fdsp)
  258. return AVERROR(ENOMEM);
  259. s->vector_fmul_scalar = fdsp->vector_fmul_scalar;
  260. av_free(fdsp);
  261. break;
  262. default:
  263. break;
  264. }
  265. avctx->sample_fmt = avctx->codec->sample_fmts[0];
  266. if (avctx->sample_fmt == AV_SAMPLE_FMT_S32)
  267. avctx->bits_per_raw_sample = av_get_bits_per_sample(avctx->codec_id);
  268. return 0;
  269. }
  270. /**
  271. * Read PCM samples macro
  272. * @param size Data size of native machine format
  273. * @param endian bytestream_get_xxx() endian suffix
  274. * @param src Source pointer (variable name)
  275. * @param dst Destination pointer (variable name)
  276. * @param n Total number of samples (variable name)
  277. * @param shift Bitshift (bits)
  278. * @param offset Sample value offset
  279. */
  280. #define DECODE(size, endian, src, dst, n, shift, offset) \
  281. for (; n > 0; n--) { \
  282. uint ## size ## _t v = bytestream_get_ ## endian(&src); \
  283. AV_WN ## size ## A(dst, (uint ## size ## _t)(v - offset) << shift); \
  284. dst += size / 8; \
  285. }
  286. #define DECODE_PLANAR(size, endian, src, dst, n, shift, offset) \
  287. n /= avctx->channels; \
  288. for (c = 0; c < avctx->channels; c++) { \
  289. int i; \
  290. dst = frame->extended_data[c]; \
  291. for (i = n; i > 0; i--) { \
  292. uint ## size ## _t v = bytestream_get_ ## endian(&src); \
  293. AV_WN ## size ## A(dst, (uint ## size ##_t)(v - offset) << shift); \
  294. dst += size / 8; \
  295. } \
  296. }
  297. static int pcm_decode_frame(AVCodecContext *avctx, void *data,
  298. int *got_frame_ptr, AVPacket *avpkt)
  299. {
  300. const uint8_t *src = avpkt->data;
  301. int buf_size = avpkt->size;
  302. PCMDecode *s = avctx->priv_data;
  303. AVFrame *frame = data;
  304. int sample_size, c, n, ret, samples_per_block;
  305. uint8_t *samples;
  306. int32_t *dst_int32_t;
  307. sample_size = av_get_bits_per_sample(avctx->codec_id) / 8;
  308. /* av_get_bits_per_sample returns 0 for AV_CODEC_ID_PCM_DVD */
  309. samples_per_block = 1;
  310. if (avctx->codec_id == AV_CODEC_ID_PCM_LXF) {
  311. /* we process 40-bit blocks per channel for LXF */
  312. samples_per_block = 2;
  313. sample_size = 5;
  314. }
  315. if (sample_size == 0) {
  316. av_log(avctx, AV_LOG_ERROR, "Invalid sample_size\n");
  317. return AVERROR(EINVAL);
  318. }
  319. if (avctx->channels == 0) {
  320. av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
  321. return AVERROR(EINVAL);
  322. }
  323. if (avctx->codec_id != avctx->codec->id) {
  324. av_log(avctx, AV_LOG_ERROR, "codec ids mismatch\n");
  325. return AVERROR(EINVAL);
  326. }
  327. n = avctx->channels * sample_size;
  328. if (n && buf_size % n) {
  329. if (buf_size < n) {
  330. av_log(avctx, AV_LOG_ERROR,
  331. "Invalid PCM packet, data has size %d but at least a size of %d was expected\n",
  332. buf_size, n);
  333. return AVERROR_INVALIDDATA;
  334. } else
  335. buf_size -= buf_size % n;
  336. }
  337. n = buf_size / sample_size;
  338. /* get output buffer */
  339. frame->nb_samples = n * samples_per_block / avctx->channels;
  340. if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
  341. return ret;
  342. samples = frame->data[0];
  343. switch (avctx->codec_id) {
  344. case AV_CODEC_ID_PCM_U32LE:
  345. DECODE(32, le32, src, samples, n, 0, 0x80000000)
  346. break;
  347. case AV_CODEC_ID_PCM_U32BE:
  348. DECODE(32, be32, src, samples, n, 0, 0x80000000)
  349. break;
  350. case AV_CODEC_ID_PCM_S24LE:
  351. DECODE(32, le24, src, samples, n, 8, 0)
  352. break;
  353. case AV_CODEC_ID_PCM_S24LE_PLANAR:
  354. DECODE_PLANAR(32, le24, src, samples, n, 8, 0);
  355. break;
  356. case AV_CODEC_ID_PCM_S24BE:
  357. DECODE(32, be24, src, samples, n, 8, 0)
  358. break;
  359. case AV_CODEC_ID_PCM_U24LE:
  360. DECODE(32, le24, src, samples, n, 8, 0x800000)
  361. break;
  362. case AV_CODEC_ID_PCM_U24BE:
  363. DECODE(32, be24, src, samples, n, 8, 0x800000)
  364. break;
  365. case AV_CODEC_ID_PCM_S24DAUD:
  366. for (; n > 0; n--) {
  367. uint32_t v = bytestream_get_be24(&src);
  368. v >>= 4; // sync flags are here
  369. AV_WN16A(samples, ff_reverse[(v >> 8) & 0xff] +
  370. (ff_reverse[v & 0xff] << 8));
  371. samples += 2;
  372. }
  373. break;
  374. case AV_CODEC_ID_PCM_U16LE:
  375. DECODE(16, le16, src, samples, n, 0, 0x8000)
  376. break;
  377. case AV_CODEC_ID_PCM_U16BE:
  378. DECODE(16, be16, src, samples, n, 0, 0x8000)
  379. break;
  380. case AV_CODEC_ID_PCM_S8:
  381. for (; n > 0; n--)
  382. *samples++ = *src++ + 128;
  383. break;
  384. case AV_CODEC_ID_PCM_S8_PLANAR:
  385. n /= avctx->channels;
  386. for (c = 0; c < avctx->channels; c++) {
  387. int i;
  388. samples = frame->extended_data[c];
  389. for (i = n; i > 0; i--)
  390. *samples++ = *src++ + 128;
  391. }
  392. break;
  393. #if HAVE_BIGENDIAN
  394. case AV_CODEC_ID_PCM_S64LE:
  395. case AV_CODEC_ID_PCM_F64LE:
  396. DECODE(64, le64, src, samples, n, 0, 0)
  397. break;
  398. case AV_CODEC_ID_PCM_S32LE:
  399. case AV_CODEC_ID_PCM_F32LE:
  400. case AV_CODEC_ID_PCM_F24LE:
  401. case AV_CODEC_ID_PCM_F16LE:
  402. DECODE(32, le32, src, samples, n, 0, 0)
  403. break;
  404. case AV_CODEC_ID_PCM_S32LE_PLANAR:
  405. DECODE_PLANAR(32, le32, src, samples, n, 0, 0);
  406. break;
  407. case AV_CODEC_ID_PCM_S16LE:
  408. DECODE(16, le16, src, samples, n, 0, 0)
  409. break;
  410. case AV_CODEC_ID_PCM_S16LE_PLANAR:
  411. DECODE_PLANAR(16, le16, src, samples, n, 0, 0);
  412. break;
  413. case AV_CODEC_ID_PCM_F64BE:
  414. case AV_CODEC_ID_PCM_F32BE:
  415. case AV_CODEC_ID_PCM_S64BE:
  416. case AV_CODEC_ID_PCM_S32BE:
  417. case AV_CODEC_ID_PCM_S16BE:
  418. #else
  419. case AV_CODEC_ID_PCM_S64BE:
  420. case AV_CODEC_ID_PCM_F64BE:
  421. DECODE(64, be64, src, samples, n, 0, 0)
  422. break;
  423. case AV_CODEC_ID_PCM_F32BE:
  424. case AV_CODEC_ID_PCM_S32BE:
  425. DECODE(32, be32, src, samples, n, 0, 0)
  426. break;
  427. case AV_CODEC_ID_PCM_S16BE:
  428. DECODE(16, be16, src, samples, n, 0, 0)
  429. break;
  430. case AV_CODEC_ID_PCM_S16BE_PLANAR:
  431. DECODE_PLANAR(16, be16, src, samples, n, 0, 0);
  432. break;
  433. case AV_CODEC_ID_PCM_F64LE:
  434. case AV_CODEC_ID_PCM_F32LE:
  435. case AV_CODEC_ID_PCM_F24LE:
  436. case AV_CODEC_ID_PCM_F16LE:
  437. case AV_CODEC_ID_PCM_S64LE:
  438. case AV_CODEC_ID_PCM_S32LE:
  439. case AV_CODEC_ID_PCM_S16LE:
  440. #endif /* HAVE_BIGENDIAN */
  441. case AV_CODEC_ID_PCM_U8:
  442. memcpy(samples, src, n * sample_size);
  443. break;
  444. #if HAVE_BIGENDIAN
  445. case AV_CODEC_ID_PCM_S16BE_PLANAR:
  446. #else
  447. case AV_CODEC_ID_PCM_S16LE_PLANAR:
  448. case AV_CODEC_ID_PCM_S32LE_PLANAR:
  449. #endif /* HAVE_BIGENDIAN */
  450. n /= avctx->channels;
  451. for (c = 0; c < avctx->channels; c++) {
  452. samples = frame->extended_data[c];
  453. bytestream_get_buffer(&src, samples, n * sample_size);
  454. }
  455. break;
  456. case AV_CODEC_ID_PCM_ALAW:
  457. case AV_CODEC_ID_PCM_MULAW:
  458. case AV_CODEC_ID_PCM_VIDC:
  459. for (; n > 0; n--) {
  460. AV_WN16A(samples, s->table[*src++]);
  461. samples += 2;
  462. }
  463. break;
  464. case AV_CODEC_ID_PCM_LXF:
  465. {
  466. int i;
  467. n /= avctx->channels;
  468. for (c = 0; c < avctx->channels; c++) {
  469. dst_int32_t = (int32_t *)frame->extended_data[c];
  470. for (i = 0; i < n; i++) {
  471. // extract low 20 bits and expand to 32 bits
  472. *dst_int32_t++ = ((uint32_t)src[2]<<28) |
  473. (src[1] << 20) |
  474. (src[0] << 12) |
  475. ((src[2] & 0x0F) << 8) |
  476. src[1];
  477. // extract high 20 bits and expand to 32 bits
  478. *dst_int32_t++ = ((uint32_t)src[4]<<24) |
  479. (src[3] << 16) |
  480. ((src[2] & 0xF0) << 8) |
  481. (src[4] << 4) |
  482. (src[3] >> 4);
  483. src += 5;
  484. }
  485. }
  486. break;
  487. }
  488. default:
  489. return -1;
  490. }
  491. if (avctx->codec_id == AV_CODEC_ID_PCM_F16LE ||
  492. avctx->codec_id == AV_CODEC_ID_PCM_F24LE) {
  493. s->vector_fmul_scalar((float *)frame->extended_data[0],
  494. (const float *)frame->extended_data[0],
  495. s->scale, FFALIGN(frame->nb_samples * avctx->channels, 4));
  496. emms_c();
  497. }
  498. *got_frame_ptr = 1;
  499. return buf_size;
  500. }
  501. #define PCM_ENCODER_0(id_, sample_fmt_, name_, long_name_)
  502. #define PCM_ENCODER_1(id_, sample_fmt_, name_, long_name_) \
  503. AVCodec ff_ ## name_ ## _encoder = { \
  504. .name = #name_, \
  505. .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
  506. .type = AVMEDIA_TYPE_AUDIO, \
  507. .id = AV_CODEC_ID_ ## id_, \
  508. .init = pcm_encode_init, \
  509. .encode2 = pcm_encode_frame, \
  510. .capabilities = AV_CODEC_CAP_VARIABLE_FRAME_SIZE, \
  511. .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
  512. AV_SAMPLE_FMT_NONE }, \
  513. }
  514. #define PCM_ENCODER_2(cf, id, sample_fmt, name, long_name) \
  515. PCM_ENCODER_ ## cf(id, sample_fmt, name, long_name)
  516. #define PCM_ENCODER_3(cf, id, sample_fmt, name, long_name) \
  517. PCM_ENCODER_2(cf, id, sample_fmt, name, long_name)
  518. #define PCM_ENCODER(id, sample_fmt, name, long_name) \
  519. PCM_ENCODER_3(CONFIG_ ## id ## _ENCODER, id, sample_fmt, name, long_name)
  520. #define PCM_DECODER_0(id, sample_fmt, name, long_name)
  521. #define PCM_DECODER_1(id_, sample_fmt_, name_, long_name_) \
  522. AVCodec ff_ ## name_ ## _decoder = { \
  523. .name = #name_, \
  524. .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
  525. .type = AVMEDIA_TYPE_AUDIO, \
  526. .id = AV_CODEC_ID_ ## id_, \
  527. .priv_data_size = sizeof(PCMDecode), \
  528. .init = pcm_decode_init, \
  529. .decode = pcm_decode_frame, \
  530. .capabilities = AV_CODEC_CAP_DR1, \
  531. .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
  532. AV_SAMPLE_FMT_NONE }, \
  533. }
  534. #define PCM_DECODER_2(cf, id, sample_fmt, name, long_name) \
  535. PCM_DECODER_ ## cf(id, sample_fmt, name, long_name)
  536. #define PCM_DECODER_3(cf, id, sample_fmt, name, long_name) \
  537. PCM_DECODER_2(cf, id, sample_fmt, name, long_name)
  538. #define PCM_DECODER(id, sample_fmt, name, long_name) \
  539. PCM_DECODER_3(CONFIG_ ## id ## _DECODER, id, sample_fmt, name, long_name)
  540. #define PCM_CODEC(id, sample_fmt_, name, long_name_) \
  541. PCM_ENCODER(id, sample_fmt_, name, long_name_); \
  542. PCM_DECODER(id, sample_fmt_, name, long_name_)
  543. /* Note: Do not forget to add new entries to the Makefile as well. */
  544. PCM_CODEC (PCM_ALAW, AV_SAMPLE_FMT_S16, pcm_alaw, "PCM A-law / G.711 A-law");
  545. PCM_DECODER(PCM_F16LE, AV_SAMPLE_FMT_FLT, pcm_f16le, "PCM 16.8 floating point little-endian");
  546. PCM_DECODER(PCM_F24LE, AV_SAMPLE_FMT_FLT, pcm_f24le, "PCM 24.0 floating point little-endian");
  547. PCM_CODEC (PCM_F32BE, AV_SAMPLE_FMT_FLT, pcm_f32be, "PCM 32-bit floating point big-endian");
  548. PCM_CODEC (PCM_F32LE, AV_SAMPLE_FMT_FLT, pcm_f32le, "PCM 32-bit floating point little-endian");
  549. PCM_CODEC (PCM_F64BE, AV_SAMPLE_FMT_DBL, pcm_f64be, "PCM 64-bit floating point big-endian");
  550. PCM_CODEC (PCM_F64LE, AV_SAMPLE_FMT_DBL, pcm_f64le, "PCM 64-bit floating point little-endian");
  551. PCM_DECODER(PCM_LXF, AV_SAMPLE_FMT_S32P,pcm_lxf, "PCM signed 20-bit little-endian planar");
  552. PCM_CODEC (PCM_MULAW, AV_SAMPLE_FMT_S16, pcm_mulaw, "PCM mu-law / G.711 mu-law");
  553. PCM_CODEC (PCM_S8, AV_SAMPLE_FMT_U8, pcm_s8, "PCM signed 8-bit");
  554. PCM_CODEC (PCM_S8_PLANAR, AV_SAMPLE_FMT_U8P, pcm_s8_planar, "PCM signed 8-bit planar");
  555. PCM_CODEC (PCM_S16BE, AV_SAMPLE_FMT_S16, pcm_s16be, "PCM signed 16-bit big-endian");
  556. PCM_CODEC (PCM_S16BE_PLANAR, AV_SAMPLE_FMT_S16P,pcm_s16be_planar, "PCM signed 16-bit big-endian planar");
  557. PCM_CODEC (PCM_S16LE, AV_SAMPLE_FMT_S16, pcm_s16le, "PCM signed 16-bit little-endian");
  558. PCM_CODEC (PCM_S16LE_PLANAR, AV_SAMPLE_FMT_S16P,pcm_s16le_planar, "PCM signed 16-bit little-endian planar");
  559. PCM_CODEC (PCM_S24BE, AV_SAMPLE_FMT_S32, pcm_s24be, "PCM signed 24-bit big-endian");
  560. PCM_CODEC (PCM_S24DAUD, AV_SAMPLE_FMT_S16, pcm_s24daud, "PCM D-Cinema audio signed 24-bit");
  561. PCM_CODEC (PCM_S24LE, AV_SAMPLE_FMT_S32, pcm_s24le, "PCM signed 24-bit little-endian");
  562. PCM_CODEC (PCM_S24LE_PLANAR, AV_SAMPLE_FMT_S32P,pcm_s24le_planar, "PCM signed 24-bit little-endian planar");
  563. PCM_CODEC (PCM_S32BE, AV_SAMPLE_FMT_S32, pcm_s32be, "PCM signed 32-bit big-endian");
  564. PCM_CODEC (PCM_S32LE, AV_SAMPLE_FMT_S32, pcm_s32le, "PCM signed 32-bit little-endian");
  565. PCM_CODEC (PCM_S32LE_PLANAR, AV_SAMPLE_FMT_S32P,pcm_s32le_planar, "PCM signed 32-bit little-endian planar");
  566. PCM_CODEC (PCM_U8, AV_SAMPLE_FMT_U8, pcm_u8, "PCM unsigned 8-bit");
  567. PCM_CODEC (PCM_U16BE, AV_SAMPLE_FMT_S16, pcm_u16be, "PCM unsigned 16-bit big-endian");
  568. PCM_CODEC (PCM_U16LE, AV_SAMPLE_FMT_S16, pcm_u16le, "PCM unsigned 16-bit little-endian");
  569. PCM_CODEC (PCM_U24BE, AV_SAMPLE_FMT_S32, pcm_u24be, "PCM unsigned 24-bit big-endian");
  570. PCM_CODEC (PCM_U24LE, AV_SAMPLE_FMT_S32, pcm_u24le, "PCM unsigned 24-bit little-endian");
  571. PCM_CODEC (PCM_U32BE, AV_SAMPLE_FMT_S32, pcm_u32be, "PCM unsigned 32-bit big-endian");
  572. PCM_CODEC (PCM_U32LE, AV_SAMPLE_FMT_S32, pcm_u32le, "PCM unsigned 32-bit little-endian");
  573. PCM_CODEC (PCM_S64BE, AV_SAMPLE_FMT_S64, pcm_s64be, "PCM signed 64-bit big-endian");
  574. PCM_CODEC (PCM_S64LE, AV_SAMPLE_FMT_S64, pcm_s64le, "PCM signed 64-bit little-endian");
  575. PCM_CODEC (PCM_VIDC, AV_SAMPLE_FMT_S16, pcm_vidc, "PCM Archimedes VIDC");