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.

634 lines
25KB

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