LCOV - code coverage report
Current view: top level - libavcodec - pcm.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 211 265 79.6 %
Date: 2017-12-18 20:14:19 Functions: 5 5 100.0 %

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

Generated by: LCOV version 1.13