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