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.

633 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. AVFloatDSPContext *fdsp;
  226. float scale;
  227. } PCMDecode;
  228. static av_cold int pcm_decode_init(AVCodecContext *avctx)
  229. {
  230. PCMDecode *s = avctx->priv_data;
  231. int i;
  232. if (avctx->channels <= 0) {
  233. av_log(avctx, AV_LOG_ERROR, "PCM channels out of bounds\n");
  234. return AVERROR(EINVAL);
  235. }
  236. switch (avctx->codec_id) {
  237. case AV_CODEC_ID_PCM_ALAW:
  238. for (i = 0; i < 256; i++)
  239. s->table[i] = alaw2linear(i);
  240. break;
  241. case AV_CODEC_ID_PCM_MULAW:
  242. for (i = 0; i < 256; i++)
  243. s->table[i] = ulaw2linear(i);
  244. break;
  245. case AV_CODEC_ID_PCM_VIDC:
  246. for (i = 0; i < 256; i++)
  247. s->table[i] = vidc2linear(i);
  248. break;
  249. case AV_CODEC_ID_PCM_F16LE:
  250. case AV_CODEC_ID_PCM_F24LE:
  251. if (avctx->bits_per_coded_sample < 1 || avctx->bits_per_coded_sample > 24)
  252. return AVERROR_INVALIDDATA;
  253. s->scale = 1. / (1 << (avctx->bits_per_coded_sample - 1));
  254. s->fdsp = avpriv_float_dsp_alloc(0);
  255. if (!s->fdsp)
  256. return AVERROR(ENOMEM);
  257. break;
  258. default:
  259. break;
  260. }
  261. avctx->sample_fmt = avctx->codec->sample_fmts[0];
  262. if (avctx->sample_fmt == AV_SAMPLE_FMT_S32)
  263. avctx->bits_per_raw_sample = av_get_bits_per_sample(avctx->codec_id);
  264. return 0;
  265. }
  266. static av_cold int pcm_decode_close(AVCodecContext *avctx)
  267. {
  268. PCMDecode *s = avctx->priv_data;
  269. av_freep(&s->fdsp);
  270. return 0;
  271. }
  272. /**
  273. * Read PCM samples macro
  274. * @param size Data size of native machine format
  275. * @param endian bytestream_get_xxx() endian suffix
  276. * @param src Source pointer (variable name)
  277. * @param dst Destination pointer (variable name)
  278. * @param n Total number of samples (variable name)
  279. * @param shift Bitshift (bits)
  280. * @param offset Sample value offset
  281. */
  282. #define DECODE(size, endian, src, dst, n, shift, offset) \
  283. for (; n > 0; n--) { \
  284. uint ## size ## _t v = bytestream_get_ ## endian(&src); \
  285. AV_WN ## size ## A(dst, (uint ## size ## _t)(v - offset) << shift); \
  286. dst += size / 8; \
  287. }
  288. #define DECODE_PLANAR(size, endian, src, dst, n, shift, offset) \
  289. n /= avctx->channels; \
  290. for (c = 0; c < avctx->channels; c++) { \
  291. int i; \
  292. dst = frame->extended_data[c]; \
  293. for (i = n; i > 0; i--) { \
  294. uint ## size ## _t v = bytestream_get_ ## endian(&src); \
  295. AV_WN ## size ## A(dst, (uint ## size ##_t)(v - offset) << shift); \
  296. dst += size / 8; \
  297. } \
  298. }
  299. static int pcm_decode_frame(AVCodecContext *avctx, void *data,
  300. int *got_frame_ptr, AVPacket *avpkt)
  301. {
  302. const uint8_t *src = avpkt->data;
  303. int buf_size = avpkt->size;
  304. PCMDecode *s = avctx->priv_data;
  305. AVFrame *frame = data;
  306. int sample_size, c, n, ret, samples_per_block;
  307. uint8_t *samples;
  308. int32_t *dst_int32_t;
  309. sample_size = av_get_bits_per_sample(avctx->codec_id) / 8;
  310. /* av_get_bits_per_sample returns 0 for AV_CODEC_ID_PCM_DVD */
  311. samples_per_block = 1;
  312. if (avctx->codec_id == AV_CODEC_ID_PCM_LXF) {
  313. /* we process 40-bit blocks per channel for LXF */
  314. samples_per_block = 2;
  315. sample_size = 5;
  316. }
  317. if (sample_size == 0) {
  318. av_log(avctx, AV_LOG_ERROR, "Invalid sample_size\n");
  319. return AVERROR(EINVAL);
  320. }
  321. if (avctx->channels == 0) {
  322. av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
  323. return AVERROR(EINVAL);
  324. }
  325. if (avctx->codec_id != avctx->codec->id) {
  326. av_log(avctx, AV_LOG_ERROR, "codec ids mismatch\n");
  327. return AVERROR(EINVAL);
  328. }
  329. n = avctx->channels * sample_size;
  330. if (n && buf_size % n) {
  331. if (buf_size < n) {
  332. av_log(avctx, AV_LOG_ERROR,
  333. "Invalid PCM packet, data has size %d but at least a size of %d was expected\n",
  334. buf_size, n);
  335. return AVERROR_INVALIDDATA;
  336. } else
  337. buf_size -= buf_size % n;
  338. }
  339. n = buf_size / sample_size;
  340. /* get output buffer */
  341. frame->nb_samples = n * samples_per_block / avctx->channels;
  342. if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
  343. return ret;
  344. samples = frame->data[0];
  345. switch (avctx->codec_id) {
  346. case AV_CODEC_ID_PCM_U32LE:
  347. DECODE(32, le32, src, samples, n, 0, 0x80000000)
  348. break;
  349. case AV_CODEC_ID_PCM_U32BE:
  350. DECODE(32, be32, src, samples, n, 0, 0x80000000)
  351. break;
  352. case AV_CODEC_ID_PCM_S24LE:
  353. DECODE(32, le24, src, samples, n, 8, 0)
  354. break;
  355. case AV_CODEC_ID_PCM_S24LE_PLANAR:
  356. DECODE_PLANAR(32, le24, src, samples, n, 8, 0);
  357. break;
  358. case AV_CODEC_ID_PCM_S24BE:
  359. DECODE(32, be24, src, samples, n, 8, 0)
  360. break;
  361. case AV_CODEC_ID_PCM_U24LE:
  362. DECODE(32, le24, src, samples, n, 8, 0x800000)
  363. break;
  364. case AV_CODEC_ID_PCM_U24BE:
  365. DECODE(32, be24, src, samples, n, 8, 0x800000)
  366. break;
  367. case AV_CODEC_ID_PCM_S24DAUD:
  368. for (; n > 0; n--) {
  369. uint32_t v = bytestream_get_be24(&src);
  370. v >>= 4; // sync flags are here
  371. AV_WN16A(samples, ff_reverse[(v >> 8) & 0xff] +
  372. (ff_reverse[v & 0xff] << 8));
  373. samples += 2;
  374. }
  375. break;
  376. case AV_CODEC_ID_PCM_U16LE:
  377. DECODE(16, le16, src, samples, n, 0, 0x8000)
  378. break;
  379. case AV_CODEC_ID_PCM_U16BE:
  380. DECODE(16, be16, src, samples, n, 0, 0x8000)
  381. break;
  382. case AV_CODEC_ID_PCM_S8:
  383. for (; n > 0; n--)
  384. *samples++ = *src++ + 128;
  385. break;
  386. case AV_CODEC_ID_PCM_S8_PLANAR:
  387. n /= avctx->channels;
  388. for (c = 0; c < avctx->channels; c++) {
  389. int i;
  390. samples = frame->extended_data[c];
  391. for (i = n; i > 0; i--)
  392. *samples++ = *src++ + 128;
  393. }
  394. break;
  395. #if HAVE_BIGENDIAN
  396. case AV_CODEC_ID_PCM_S64LE:
  397. case AV_CODEC_ID_PCM_F64LE:
  398. DECODE(64, le64, src, samples, n, 0, 0)
  399. break;
  400. case AV_CODEC_ID_PCM_S32LE:
  401. case AV_CODEC_ID_PCM_F32LE:
  402. case AV_CODEC_ID_PCM_F24LE:
  403. case AV_CODEC_ID_PCM_F16LE:
  404. DECODE(32, le32, src, samples, n, 0, 0)
  405. break;
  406. case AV_CODEC_ID_PCM_S32LE_PLANAR:
  407. DECODE_PLANAR(32, le32, src, samples, n, 0, 0);
  408. break;
  409. case AV_CODEC_ID_PCM_S16LE:
  410. DECODE(16, le16, src, samples, n, 0, 0)
  411. break;
  412. case AV_CODEC_ID_PCM_S16LE_PLANAR:
  413. DECODE_PLANAR(16, le16, src, samples, n, 0, 0);
  414. break;
  415. case AV_CODEC_ID_PCM_F64BE:
  416. case AV_CODEC_ID_PCM_F32BE:
  417. case AV_CODEC_ID_PCM_S64BE:
  418. case AV_CODEC_ID_PCM_S32BE:
  419. case AV_CODEC_ID_PCM_S16BE:
  420. #else
  421. case AV_CODEC_ID_PCM_S64BE:
  422. case AV_CODEC_ID_PCM_F64BE:
  423. DECODE(64, be64, src, samples, n, 0, 0)
  424. break;
  425. case AV_CODEC_ID_PCM_F32BE:
  426. case AV_CODEC_ID_PCM_S32BE:
  427. DECODE(32, be32, src, samples, n, 0, 0)
  428. break;
  429. case AV_CODEC_ID_PCM_S16BE:
  430. DECODE(16, be16, src, samples, n, 0, 0)
  431. break;
  432. case AV_CODEC_ID_PCM_S16BE_PLANAR:
  433. DECODE_PLANAR(16, be16, src, samples, n, 0, 0);
  434. break;
  435. case AV_CODEC_ID_PCM_F64LE:
  436. case AV_CODEC_ID_PCM_F32LE:
  437. case AV_CODEC_ID_PCM_F24LE:
  438. case AV_CODEC_ID_PCM_F16LE:
  439. case AV_CODEC_ID_PCM_S64LE:
  440. case AV_CODEC_ID_PCM_S32LE:
  441. case AV_CODEC_ID_PCM_S16LE:
  442. #endif /* HAVE_BIGENDIAN */
  443. case AV_CODEC_ID_PCM_U8:
  444. memcpy(samples, src, n * sample_size);
  445. break;
  446. #if HAVE_BIGENDIAN
  447. case AV_CODEC_ID_PCM_S16BE_PLANAR:
  448. #else
  449. case AV_CODEC_ID_PCM_S16LE_PLANAR:
  450. case AV_CODEC_ID_PCM_S32LE_PLANAR:
  451. #endif /* HAVE_BIGENDIAN */
  452. n /= avctx->channels;
  453. for (c = 0; c < avctx->channels; c++) {
  454. samples = frame->extended_data[c];
  455. bytestream_get_buffer(&src, samples, n * sample_size);
  456. }
  457. break;
  458. case AV_CODEC_ID_PCM_ZORK:
  459. for (; n > 0; n--) {
  460. int v = *src++;
  461. if (v < 128)
  462. v = 128 - v;
  463. *samples++ = v;
  464. }
  465. break;
  466. case AV_CODEC_ID_PCM_ALAW:
  467. case AV_CODEC_ID_PCM_MULAW:
  468. case AV_CODEC_ID_PCM_VIDC:
  469. for (; n > 0; n--) {
  470. AV_WN16A(samples, s->table[*src++]);
  471. samples += 2;
  472. }
  473. break;
  474. case AV_CODEC_ID_PCM_LXF:
  475. {
  476. int i;
  477. n /= avctx->channels;
  478. for (c = 0; c < avctx->channels; c++) {
  479. dst_int32_t = (int32_t *)frame->extended_data[c];
  480. for (i = 0; i < n; i++) {
  481. // extract low 20 bits and expand to 32 bits
  482. *dst_int32_t++ = ((uint32_t)src[2]<<28) |
  483. (src[1] << 20) |
  484. (src[0] << 12) |
  485. ((src[2] & 0x0F) << 8) |
  486. src[1];
  487. // extract high 20 bits and expand to 32 bits
  488. *dst_int32_t++ = ((uint32_t)src[4]<<24) |
  489. (src[3] << 16) |
  490. ((src[2] & 0xF0) << 8) |
  491. (src[4] << 4) |
  492. (src[3] >> 4);
  493. src += 5;
  494. }
  495. }
  496. break;
  497. }
  498. default:
  499. return -1;
  500. }
  501. if (avctx->codec_id == AV_CODEC_ID_PCM_F16LE ||
  502. avctx->codec_id == AV_CODEC_ID_PCM_F24LE) {
  503. s->fdsp->vector_fmul_scalar((float *)frame->extended_data[0],
  504. (const float *)frame->extended_data[0],
  505. s->scale, FFALIGN(frame->nb_samples * avctx->channels, 4));
  506. emms_c();
  507. }
  508. *got_frame_ptr = 1;
  509. return buf_size;
  510. }
  511. #define PCM_ENCODER_0(id_, sample_fmt_, name_, long_name_)
  512. #define PCM_ENCODER_1(id_, sample_fmt_, name_, long_name_) \
  513. AVCodec ff_ ## name_ ## _encoder = { \
  514. .name = #name_, \
  515. .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
  516. .type = AVMEDIA_TYPE_AUDIO, \
  517. .id = AV_CODEC_ID_ ## id_, \
  518. .init = pcm_encode_init, \
  519. .encode2 = pcm_encode_frame, \
  520. .capabilities = AV_CODEC_CAP_VARIABLE_FRAME_SIZE, \
  521. .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
  522. AV_SAMPLE_FMT_NONE }, \
  523. }
  524. #define PCM_ENCODER_2(cf, id, sample_fmt, name, long_name) \
  525. PCM_ENCODER_ ## cf(id, sample_fmt, name, long_name)
  526. #define PCM_ENCODER_3(cf, id, sample_fmt, name, long_name) \
  527. PCM_ENCODER_2(cf, id, sample_fmt, name, long_name)
  528. #define PCM_ENCODER(id, sample_fmt, name, long_name) \
  529. PCM_ENCODER_3(CONFIG_ ## id ## _ENCODER, id, sample_fmt, name, long_name)
  530. #define PCM_DECODER_0(id, sample_fmt, name, long_name)
  531. #define PCM_DECODER_1(id_, sample_fmt_, name_, long_name_) \
  532. AVCodec ff_ ## name_ ## _decoder = { \
  533. .name = #name_, \
  534. .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
  535. .type = AVMEDIA_TYPE_AUDIO, \
  536. .id = AV_CODEC_ID_ ## id_, \
  537. .priv_data_size = sizeof(PCMDecode), \
  538. .init = pcm_decode_init, \
  539. .close = pcm_decode_close, \
  540. .decode = pcm_decode_frame, \
  541. .capabilities = AV_CODEC_CAP_DR1, \
  542. .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
  543. AV_SAMPLE_FMT_NONE }, \
  544. }
  545. #define PCM_DECODER_2(cf, id, sample_fmt, name, long_name) \
  546. PCM_DECODER_ ## cf(id, sample_fmt, name, long_name)
  547. #define PCM_DECODER_3(cf, id, sample_fmt, name, long_name) \
  548. PCM_DECODER_2(cf, id, sample_fmt, name, long_name)
  549. #define PCM_DECODER(id, sample_fmt, name, long_name) \
  550. PCM_DECODER_3(CONFIG_ ## id ## _DECODER, id, sample_fmt, name, long_name)
  551. #define PCM_CODEC(id, sample_fmt_, name, long_name_) \
  552. PCM_ENCODER(id, sample_fmt_, name, long_name_); \
  553. PCM_DECODER(id, sample_fmt_, name, long_name_)
  554. /* Note: Do not forget to add new entries to the Makefile as well. */
  555. PCM_CODEC (PCM_ALAW, AV_SAMPLE_FMT_S16, pcm_alaw, "PCM A-law / G.711 A-law");
  556. PCM_DECODER(PCM_F16LE, AV_SAMPLE_FMT_FLT, pcm_f16le, "PCM 16.8 floating point little-endian");
  557. PCM_DECODER(PCM_F24LE, AV_SAMPLE_FMT_FLT, pcm_f24le, "PCM 24.0 floating point little-endian");
  558. PCM_CODEC (PCM_F32BE, AV_SAMPLE_FMT_FLT, pcm_f32be, "PCM 32-bit floating point big-endian");
  559. PCM_CODEC (PCM_F32LE, AV_SAMPLE_FMT_FLT, pcm_f32le, "PCM 32-bit floating point little-endian");
  560. PCM_CODEC (PCM_F64BE, AV_SAMPLE_FMT_DBL, pcm_f64be, "PCM 64-bit floating point big-endian");
  561. PCM_CODEC (PCM_F64LE, AV_SAMPLE_FMT_DBL, pcm_f64le, "PCM 64-bit floating point little-endian");
  562. PCM_DECODER(PCM_LXF, AV_SAMPLE_FMT_S32P,pcm_lxf, "PCM signed 20-bit little-endian planar");
  563. PCM_CODEC (PCM_MULAW, AV_SAMPLE_FMT_S16, pcm_mulaw, "PCM mu-law / G.711 mu-law");
  564. PCM_CODEC (PCM_S8, AV_SAMPLE_FMT_U8, pcm_s8, "PCM signed 8-bit");
  565. PCM_CODEC (PCM_S8_PLANAR, AV_SAMPLE_FMT_U8P, pcm_s8_planar, "PCM signed 8-bit planar");
  566. PCM_CODEC (PCM_S16BE, AV_SAMPLE_FMT_S16, pcm_s16be, "PCM signed 16-bit big-endian");
  567. PCM_CODEC (PCM_S16BE_PLANAR, AV_SAMPLE_FMT_S16P,pcm_s16be_planar, "PCM signed 16-bit big-endian planar");
  568. PCM_CODEC (PCM_S16LE, AV_SAMPLE_FMT_S16, pcm_s16le, "PCM signed 16-bit little-endian");
  569. PCM_CODEC (PCM_S16LE_PLANAR, AV_SAMPLE_FMT_S16P,pcm_s16le_planar, "PCM signed 16-bit little-endian planar");
  570. PCM_CODEC (PCM_S24BE, AV_SAMPLE_FMT_S32, pcm_s24be, "PCM signed 24-bit big-endian");
  571. PCM_CODEC (PCM_S24DAUD, AV_SAMPLE_FMT_S16, pcm_s24daud, "PCM D-Cinema audio signed 24-bit");
  572. PCM_CODEC (PCM_S24LE, AV_SAMPLE_FMT_S32, pcm_s24le, "PCM signed 24-bit little-endian");
  573. PCM_CODEC (PCM_S24LE_PLANAR, AV_SAMPLE_FMT_S32P,pcm_s24le_planar, "PCM signed 24-bit little-endian planar");
  574. PCM_CODEC (PCM_S32BE, AV_SAMPLE_FMT_S32, pcm_s32be, "PCM signed 32-bit big-endian");
  575. PCM_CODEC (PCM_S32LE, AV_SAMPLE_FMT_S32, pcm_s32le, "PCM signed 32-bit little-endian");
  576. PCM_CODEC (PCM_S32LE_PLANAR, AV_SAMPLE_FMT_S32P,pcm_s32le_planar, "PCM signed 32-bit little-endian planar");
  577. PCM_CODEC (PCM_U8, AV_SAMPLE_FMT_U8, pcm_u8, "PCM unsigned 8-bit");
  578. PCM_CODEC (PCM_U16BE, AV_SAMPLE_FMT_S16, pcm_u16be, "PCM unsigned 16-bit big-endian");
  579. PCM_CODEC (PCM_U16LE, AV_SAMPLE_FMT_S16, pcm_u16le, "PCM unsigned 16-bit little-endian");
  580. PCM_CODEC (PCM_U24BE, AV_SAMPLE_FMT_S32, pcm_u24be, "PCM unsigned 24-bit big-endian");
  581. PCM_CODEC (PCM_U24LE, AV_SAMPLE_FMT_S32, pcm_u24le, "PCM unsigned 24-bit little-endian");
  582. PCM_CODEC (PCM_U32BE, AV_SAMPLE_FMT_S32, pcm_u32be, "PCM unsigned 32-bit big-endian");
  583. PCM_CODEC (PCM_U32LE, AV_SAMPLE_FMT_S32, pcm_u32le, "PCM unsigned 32-bit little-endian");
  584. PCM_DECODER(PCM_ZORK, AV_SAMPLE_FMT_U8, pcm_zork, "PCM Zork");
  585. PCM_CODEC (PCM_S64BE, AV_SAMPLE_FMT_S64, pcm_s64be, "PCM signed 64-bit big-endian");
  586. PCM_CODEC (PCM_S64LE, AV_SAMPLE_FMT_S64, pcm_s64le, "PCM signed 64-bit little-endian");
  587. PCM_CODEC (PCM_VIDC, AV_SAMPLE_FMT_S16, pcm_vidc, "PCM Archimedes VIDC");