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.

628 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 "avcodec.h"
  27. #include "bytestream.h"
  28. #include "internal.h"
  29. #include "mathops.h"
  30. #include "pcm_tablegen.h"
  31. static av_cold int pcm_encode_init(AVCodecContext *avctx)
  32. {
  33. avctx->frame_size = 0;
  34. switch (avctx->codec->id) {
  35. case AV_CODEC_ID_PCM_ALAW:
  36. pcm_alaw_tableinit();
  37. break;
  38. case AV_CODEC_ID_PCM_MULAW:
  39. pcm_ulaw_tableinit();
  40. break;
  41. default:
  42. break;
  43. }
  44. avctx->bits_per_coded_sample = av_get_bits_per_sample(avctx->codec->id);
  45. avctx->block_align = avctx->channels * avctx->bits_per_coded_sample / 8;
  46. avctx->bit_rate = avctx->block_align * avctx->sample_rate * 8;
  47. avctx->coded_frame = avcodec_alloc_frame();
  48. if (!avctx->coded_frame)
  49. return AVERROR(ENOMEM);
  50. return 0;
  51. }
  52. static av_cold int pcm_encode_close(AVCodecContext *avctx)
  53. {
  54. av_freep(&avctx->coded_frame);
  55. return 0;
  56. }
  57. /**
  58. * Write PCM samples macro
  59. * @param type Datatype of native machine format
  60. * @param endian bytestream_put_xxx() suffix
  61. * @param src Source pointer (variable name)
  62. * @param dst Destination pointer (variable name)
  63. * @param n Total number of samples (variable name)
  64. * @param shift Bitshift (bits)
  65. * @param offset Sample value offset
  66. */
  67. #define ENCODE(type, endian, src, dst, n, shift, offset) \
  68. samples_ ## type = (const type *) src; \
  69. for (; n > 0; n--) { \
  70. register type v = (*samples_ ## type++ >> shift) + offset; \
  71. bytestream_put_ ## endian(&dst, v); \
  72. }
  73. #define ENCODE_PLANAR(type, endian, dst, n, shift, offset) \
  74. n /= avctx->channels; \
  75. for (c = 0; c < avctx->channels; c++) { \
  76. int i; \
  77. samples_ ## type = (const type *) frame->extended_data[c]; \
  78. for (i = n; i > 0; i--) { \
  79. register type v = (*samples_ ## type++ >> shift) + offset; \
  80. bytestream_put_ ## endian(&dst, v); \
  81. } \
  82. }
  83. static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
  84. const AVFrame *frame, int *got_packet_ptr)
  85. {
  86. int n, c, sample_size, v, ret;
  87. const short *samples;
  88. unsigned char *dst;
  89. const uint8_t *samples_uint8_t;
  90. const int16_t *samples_int16_t;
  91. const int32_t *samples_int32_t;
  92. const int64_t *samples_int64_t;
  93. const uint16_t *samples_uint16_t;
  94. const uint32_t *samples_uint32_t;
  95. sample_size = av_get_bits_per_sample(avctx->codec->id) / 8;
  96. n = frame->nb_samples * avctx->channels;
  97. samples = (const short *)frame->data[0];
  98. if ((ret = ff_alloc_packet2(avctx, avpkt, n * sample_size)) < 0)
  99. return ret;
  100. dst = avpkt->data;
  101. switch (avctx->codec->id) {
  102. case AV_CODEC_ID_PCM_U32LE:
  103. ENCODE(uint32_t, le32, samples, dst, n, 0, 0x80000000)
  104. break;
  105. case AV_CODEC_ID_PCM_U32BE:
  106. ENCODE(uint32_t, be32, samples, dst, n, 0, 0x80000000)
  107. break;
  108. case AV_CODEC_ID_PCM_S24LE:
  109. ENCODE(int32_t, le24, samples, dst, n, 8, 0)
  110. break;
  111. case AV_CODEC_ID_PCM_S24LE_PLANAR:
  112. ENCODE_PLANAR(int32_t, le24, dst, n, 8, 0)
  113. break;
  114. case AV_CODEC_ID_PCM_S24BE:
  115. ENCODE(int32_t, be24, samples, dst, n, 8, 0)
  116. break;
  117. case AV_CODEC_ID_PCM_U24LE:
  118. ENCODE(uint32_t, le24, samples, dst, n, 8, 0x800000)
  119. break;
  120. case AV_CODEC_ID_PCM_U24BE:
  121. ENCODE(uint32_t, be24, samples, dst, n, 8, 0x800000)
  122. break;
  123. case AV_CODEC_ID_PCM_S24DAUD:
  124. for (; n > 0; n--) {
  125. uint32_t tmp = ff_reverse[(*samples >> 8) & 0xff] +
  126. (ff_reverse[*samples & 0xff] << 8);
  127. tmp <<= 4; // sync flags would go here
  128. bytestream_put_be24(&dst, tmp);
  129. samples++;
  130. }
  131. break;
  132. case AV_CODEC_ID_PCM_U16LE:
  133. ENCODE(uint16_t, le16, samples, dst, n, 0, 0x8000)
  134. break;
  135. case AV_CODEC_ID_PCM_U16BE:
  136. ENCODE(uint16_t, be16, samples, dst, n, 0, 0x8000)
  137. break;
  138. case AV_CODEC_ID_PCM_S8:
  139. ENCODE(uint8_t, byte, samples, dst, n, 0, -128)
  140. break;
  141. case AV_CODEC_ID_PCM_S8_PLANAR:
  142. ENCODE_PLANAR(uint8_t, byte, dst, n, 0, -128)
  143. break;
  144. #if HAVE_BIGENDIAN
  145. case AV_CODEC_ID_PCM_F64LE:
  146. ENCODE(int64_t, le64, samples, dst, n, 0, 0)
  147. break;
  148. case AV_CODEC_ID_PCM_S32LE:
  149. case AV_CODEC_ID_PCM_F32LE:
  150. ENCODE(int32_t, le32, samples, dst, n, 0, 0)
  151. break;
  152. case AV_CODEC_ID_PCM_S32LE_PLANAR:
  153. ENCODE_PLANAR(int32_t, le32, dst, n, 0, 0)
  154. break;
  155. case AV_CODEC_ID_PCM_S16LE:
  156. ENCODE(int16_t, le16, samples, dst, n, 0, 0)
  157. break;
  158. case AV_CODEC_ID_PCM_S16LE_PLANAR:
  159. ENCODE_PLANAR(int16_t, le16, dst, n, 0, 0)
  160. break;
  161. case AV_CODEC_ID_PCM_F64BE:
  162. case AV_CODEC_ID_PCM_F32BE:
  163. case AV_CODEC_ID_PCM_S32BE:
  164. case AV_CODEC_ID_PCM_S16BE:
  165. #else
  166. case AV_CODEC_ID_PCM_F64BE:
  167. ENCODE(int64_t, be64, samples, dst, n, 0, 0)
  168. break;
  169. case AV_CODEC_ID_PCM_F32BE:
  170. case AV_CODEC_ID_PCM_S32BE:
  171. ENCODE(int32_t, be32, samples, dst, n, 0, 0)
  172. break;
  173. case AV_CODEC_ID_PCM_S16BE:
  174. ENCODE(int16_t, be16, samples, dst, n, 0, 0)
  175. break;
  176. case AV_CODEC_ID_PCM_S16BE_PLANAR:
  177. ENCODE_PLANAR(int16_t, be16, dst, n, 0, 0)
  178. break;
  179. case AV_CODEC_ID_PCM_F64LE:
  180. case AV_CODEC_ID_PCM_F32LE:
  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. default:
  212. return -1;
  213. }
  214. *got_packet_ptr = 1;
  215. return 0;
  216. }
  217. typedef struct PCMDecode {
  218. short table[256];
  219. } PCMDecode;
  220. static av_cold int pcm_decode_init(AVCodecContext *avctx)
  221. {
  222. PCMDecode *s = avctx->priv_data;
  223. int i;
  224. if (avctx->channels <= 0) {
  225. av_log(avctx, AV_LOG_ERROR, "PCM channels out of bounds\n");
  226. return AVERROR(EINVAL);
  227. }
  228. switch (avctx->codec_id) {
  229. case AV_CODEC_ID_PCM_ALAW:
  230. for (i = 0; i < 256; i++)
  231. s->table[i] = alaw2linear(i);
  232. break;
  233. case AV_CODEC_ID_PCM_MULAW:
  234. for (i = 0; i < 256; i++)
  235. s->table[i] = ulaw2linear(i);
  236. break;
  237. default:
  238. break;
  239. }
  240. avctx->sample_fmt = avctx->codec->sample_fmts[0];
  241. if (avctx->sample_fmt == AV_SAMPLE_FMT_S32)
  242. avctx->bits_per_raw_sample = av_get_bits_per_sample(avctx->codec_id);
  243. return 0;
  244. }
  245. /**
  246. * Read PCM samples macro
  247. * @param size Data size of native machine format
  248. * @param endian bytestream_get_xxx() endian suffix
  249. * @param src Source pointer (variable name)
  250. * @param dst Destination pointer (variable name)
  251. * @param n Total number of samples (variable name)
  252. * @param shift Bitshift (bits)
  253. * @param offset Sample value offset
  254. */
  255. #define DECODE(size, endian, src, dst, n, shift, offset) \
  256. for (; n > 0; n--) { \
  257. uint ## size ## _t v = bytestream_get_ ## endian(&src); \
  258. AV_WN ## size ## A(dst, (v - offset) << shift); \
  259. dst += size / 8; \
  260. }
  261. #define DECODE_PLANAR(size, endian, src, dst, n, shift, offset) \
  262. n /= avctx->channels; \
  263. for (c = 0; c < avctx->channels; c++) { \
  264. int i; \
  265. dst = frame->extended_data[c]; \
  266. for (i = n; i > 0; i--) { \
  267. uint ## size ## _t v = bytestream_get_ ## endian(&src); \
  268. AV_WN ## size ## A(dst, (v - offset) << shift); \
  269. dst += size / 8; \
  270. } \
  271. }
  272. static int pcm_decode_frame(AVCodecContext *avctx, void *data,
  273. int *got_frame_ptr, AVPacket *avpkt)
  274. {
  275. const uint8_t *src = avpkt->data;
  276. int buf_size = avpkt->size;
  277. PCMDecode *s = avctx->priv_data;
  278. AVFrame *frame = data;
  279. int sample_size, c, n, ret, samples_per_block;
  280. uint8_t *samples;
  281. int32_t *dst_int32_t;
  282. sample_size = av_get_bits_per_sample(avctx->codec_id) / 8;
  283. /* av_get_bits_per_sample returns 0 for AV_CODEC_ID_PCM_DVD */
  284. samples_per_block = 1;
  285. if (AV_CODEC_ID_PCM_DVD == avctx->codec_id) {
  286. if (avctx->bits_per_coded_sample != 20 &&
  287. avctx->bits_per_coded_sample != 24) {
  288. av_log(avctx, AV_LOG_ERROR,
  289. "PCM DVD unsupported sample depth %i\n",
  290. avctx->bits_per_coded_sample);
  291. return AVERROR(EINVAL);
  292. }
  293. /* 2 samples are interleaved per block in PCM_DVD */
  294. samples_per_block = 2;
  295. sample_size = avctx->bits_per_coded_sample * 2 / 8;
  296. } else if (avctx->codec_id == AV_CODEC_ID_PCM_LXF) {
  297. /* we process 40-bit blocks per channel for LXF */
  298. samples_per_block = 2;
  299. sample_size = 5;
  300. }
  301. if (sample_size == 0) {
  302. av_log(avctx, AV_LOG_ERROR, "Invalid sample_size\n");
  303. return AVERROR(EINVAL);
  304. }
  305. if (avctx->channels == 0) {
  306. av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
  307. return AVERROR(EINVAL);
  308. }
  309. if (avctx->codec_id != avctx->codec->id) {
  310. av_log(avctx, AV_LOG_ERROR, "codec ids mismatch\n");
  311. return AVERROR(EINVAL);
  312. }
  313. n = avctx->channels * sample_size;
  314. if (n && buf_size % n) {
  315. if (buf_size < n) {
  316. av_log(avctx, AV_LOG_ERROR,
  317. "Invalid PCM packet, data has size %d but at least a size of %d was expected\n",
  318. buf_size, n);
  319. return AVERROR_INVALIDDATA;
  320. } else
  321. buf_size -= buf_size % n;
  322. }
  323. n = buf_size / sample_size;
  324. /* get output buffer */
  325. frame->nb_samples = n * samples_per_block / avctx->channels;
  326. if ((ret = ff_get_buffer(avctx, frame)) < 0) {
  327. av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
  328. return ret;
  329. }
  330. samples = frame->data[0];
  331. switch (avctx->codec_id) {
  332. case AV_CODEC_ID_PCM_U32LE:
  333. DECODE(32, le32, src, samples, n, 0, 0x80000000)
  334. break;
  335. case AV_CODEC_ID_PCM_U32BE:
  336. DECODE(32, be32, src, samples, n, 0, 0x80000000)
  337. break;
  338. case AV_CODEC_ID_PCM_S24LE:
  339. DECODE(32, le24, src, samples, n, 8, 0)
  340. break;
  341. case AV_CODEC_ID_PCM_S24LE_PLANAR:
  342. DECODE_PLANAR(32, le24, src, samples, n, 8, 0);
  343. break;
  344. case AV_CODEC_ID_PCM_S24BE:
  345. DECODE(32, be24, src, samples, n, 8, 0)
  346. break;
  347. case AV_CODEC_ID_PCM_U24LE:
  348. DECODE(32, le24, src, samples, n, 8, 0x800000)
  349. break;
  350. case AV_CODEC_ID_PCM_U24BE:
  351. DECODE(32, be24, src, samples, n, 8, 0x800000)
  352. break;
  353. case AV_CODEC_ID_PCM_S24DAUD:
  354. for (; n > 0; n--) {
  355. uint32_t v = bytestream_get_be24(&src);
  356. v >>= 4; // sync flags are here
  357. AV_WN16A(samples, ff_reverse[(v >> 8) & 0xff] +
  358. (ff_reverse[v & 0xff] << 8));
  359. samples += 2;
  360. }
  361. break;
  362. case AV_CODEC_ID_PCM_U16LE:
  363. DECODE(16, le16, src, samples, n, 0, 0x8000)
  364. break;
  365. case AV_CODEC_ID_PCM_U16BE:
  366. DECODE(16, be16, src, samples, n, 0, 0x8000)
  367. break;
  368. case AV_CODEC_ID_PCM_S8:
  369. for (; n > 0; n--)
  370. *samples++ = *src++ + 128;
  371. break;
  372. case AV_CODEC_ID_PCM_S8_PLANAR:
  373. n /= avctx->channels;
  374. for (c = 0; c < avctx->channels; c++) {
  375. int i;
  376. samples = frame->extended_data[c];
  377. for (i = n; i > 0; i--)
  378. *samples++ = *src++ + 128;
  379. }
  380. break;
  381. #if HAVE_BIGENDIAN
  382. case AV_CODEC_ID_PCM_F64LE:
  383. DECODE(64, le64, src, samples, n, 0, 0)
  384. break;
  385. case AV_CODEC_ID_PCM_S32LE:
  386. case AV_CODEC_ID_PCM_F32LE:
  387. DECODE(32, le32, src, samples, n, 0, 0)
  388. break;
  389. case AV_CODEC_ID_PCM_S32LE_PLANAR:
  390. DECODE_PLANAR(32, le32, src, samples, n, 0, 0);
  391. break;
  392. case AV_CODEC_ID_PCM_S16LE:
  393. DECODE(16, le16, src, samples, n, 0, 0)
  394. break;
  395. case AV_CODEC_ID_PCM_S16LE_PLANAR:
  396. DECODE_PLANAR(16, le16, src, samples, n, 0, 0);
  397. break;
  398. case AV_CODEC_ID_PCM_F64BE:
  399. case AV_CODEC_ID_PCM_F32BE:
  400. case AV_CODEC_ID_PCM_S32BE:
  401. case AV_CODEC_ID_PCM_S16BE:
  402. #else
  403. case AV_CODEC_ID_PCM_F64BE:
  404. DECODE(64, be64, src, samples, n, 0, 0)
  405. break;
  406. case AV_CODEC_ID_PCM_F32BE:
  407. case AV_CODEC_ID_PCM_S32BE:
  408. DECODE(32, be32, src, samples, n, 0, 0)
  409. break;
  410. case AV_CODEC_ID_PCM_S16BE:
  411. DECODE(16, be16, src, samples, n, 0, 0)
  412. break;
  413. case AV_CODEC_ID_PCM_S16BE_PLANAR:
  414. DECODE_PLANAR(16, be16, src, samples, n, 0, 0);
  415. break;
  416. case AV_CODEC_ID_PCM_F64LE:
  417. case AV_CODEC_ID_PCM_F32LE:
  418. case AV_CODEC_ID_PCM_S32LE:
  419. case AV_CODEC_ID_PCM_S16LE:
  420. #endif /* HAVE_BIGENDIAN */
  421. case AV_CODEC_ID_PCM_U8:
  422. memcpy(samples, src, n * sample_size);
  423. break;
  424. #if HAVE_BIGENDIAN
  425. case AV_CODEC_ID_PCM_S16BE_PLANAR:
  426. #else
  427. case AV_CODEC_ID_PCM_S16LE_PLANAR:
  428. case AV_CODEC_ID_PCM_S32LE_PLANAR:
  429. #endif /* HAVE_BIGENDIAN */
  430. n /= avctx->channels;
  431. for (c = 0; c < avctx->channels; c++) {
  432. samples = frame->extended_data[c];
  433. bytestream_get_buffer(&src, samples, n * sample_size);
  434. }
  435. break;
  436. case AV_CODEC_ID_PCM_ZORK:
  437. for (; n > 0; n--) {
  438. int v = *src++;
  439. if (v < 128)
  440. v = 128 - v;
  441. *samples++ = v;
  442. }
  443. break;
  444. case AV_CODEC_ID_PCM_ALAW:
  445. case AV_CODEC_ID_PCM_MULAW:
  446. for (; n > 0; n--) {
  447. AV_WN16A(samples, s->table[*src++]);
  448. samples += 2;
  449. }
  450. break;
  451. case AV_CODEC_ID_PCM_DVD:
  452. {
  453. const uint8_t *src8;
  454. dst_int32_t = (int32_t *)frame->data[0];
  455. n /= avctx->channels;
  456. switch (avctx->bits_per_coded_sample) {
  457. case 20:
  458. while (n--) {
  459. c = avctx->channels;
  460. src8 = src + 4 * c;
  461. while (c--) {
  462. *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8 & 0xf0) << 8);
  463. *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8++ & 0x0f) << 12);
  464. }
  465. src = src8;
  466. }
  467. break;
  468. case 24:
  469. while (n--) {
  470. c = avctx->channels;
  471. src8 = src + 4 * c;
  472. while (c--) {
  473. *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8++) << 8);
  474. *dst_int32_t++ = (bytestream_get_be16(&src) << 16) + ((*src8++) << 8);
  475. }
  476. src = src8;
  477. }
  478. break;
  479. }
  480. break;
  481. }
  482. case AV_CODEC_ID_PCM_LXF:
  483. {
  484. int i;
  485. n /= avctx->channels;
  486. for (c = 0; c < avctx->channels; c++) {
  487. dst_int32_t = (int32_t *)frame->extended_data[c];
  488. for (i = 0; i < n; i++) {
  489. // extract low 20 bits and expand to 32 bits
  490. *dst_int32_t++ = (src[2] << 28) |
  491. (src[1] << 20) |
  492. (src[0] << 12) |
  493. ((src[2] & 0x0F) << 8) |
  494. src[1];
  495. // extract high 20 bits and expand to 32 bits
  496. *dst_int32_t++ = (src[4] << 24) |
  497. (src[3] << 16) |
  498. ((src[2] & 0xF0) << 8) |
  499. (src[4] << 4) |
  500. (src[3] >> 4);
  501. src += 5;
  502. }
  503. }
  504. break;
  505. }
  506. default:
  507. return -1;
  508. }
  509. *got_frame_ptr = 1;
  510. return buf_size;
  511. }
  512. #define PCM_ENCODER_0(id_, sample_fmt_, name_, long_name_)
  513. #define PCM_ENCODER_1(id_, sample_fmt_, name_, long_name_) \
  514. AVCodec ff_ ## name_ ## _encoder = { \
  515. .name = #name_, \
  516. .type = AVMEDIA_TYPE_AUDIO, \
  517. .id = AV_CODEC_ID_ ## id_, \
  518. .init = pcm_encode_init, \
  519. .encode2 = pcm_encode_frame, \
  520. .close = pcm_encode_close, \
  521. .capabilities = CODEC_CAP_VARIABLE_FRAME_SIZE, \
  522. .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
  523. AV_SAMPLE_FMT_NONE }, \
  524. .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
  525. }
  526. #define PCM_ENCODER_2(cf, id, sample_fmt, name, long_name) \
  527. PCM_ENCODER_ ## cf(id, sample_fmt, name, long_name)
  528. #define PCM_ENCODER_3(cf, id, sample_fmt, name, long_name) \
  529. PCM_ENCODER_2(cf, id, sample_fmt, name, long_name)
  530. #define PCM_ENCODER(id, sample_fmt, name, long_name) \
  531. PCM_ENCODER_3(CONFIG_ ## id ## _ENCODER, id, sample_fmt, name, long_name)
  532. #define PCM_DECODER_0(id, sample_fmt, name, long_name)
  533. #define PCM_DECODER_1(id_, sample_fmt_, name_, long_name_) \
  534. AVCodec ff_ ## name_ ## _decoder = { \
  535. .name = #name_, \
  536. .type = AVMEDIA_TYPE_AUDIO, \
  537. .id = AV_CODEC_ID_ ## id_, \
  538. .priv_data_size = sizeof(PCMDecode), \
  539. .init = pcm_decode_init, \
  540. .decode = pcm_decode_frame, \
  541. .capabilities = CODEC_CAP_DR1, \
  542. .sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
  543. AV_SAMPLE_FMT_NONE }, \
  544. .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
  545. }
  546. #define PCM_DECODER_2(cf, id, sample_fmt, name, long_name) \
  547. PCM_DECODER_ ## cf(id, sample_fmt, name, long_name)
  548. #define PCM_DECODER_3(cf, id, sample_fmt, name, long_name) \
  549. PCM_DECODER_2(cf, id, sample_fmt, name, long_name)
  550. #define PCM_DECODER(id, sample_fmt, name, long_name) \
  551. PCM_DECODER_3(CONFIG_ ## id ## _DECODER, id, sample_fmt, name, long_name)
  552. #define PCM_CODEC(id, sample_fmt_, name, long_name_) \
  553. PCM_ENCODER(id, sample_fmt_, name, long_name_); \
  554. PCM_DECODER(id, sample_fmt_, name, long_name_)
  555. /* Note: Do not forget to add new entries to the Makefile as well. */
  556. PCM_CODEC (PCM_ALAW, AV_SAMPLE_FMT_S16, pcm_alaw, "PCM A-law / G.711 A-law");
  557. PCM_DECODER(PCM_DVD, AV_SAMPLE_FMT_S32, pcm_dvd, "PCM signed 20|24-bit big-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");