GCC Code Coverage Report
Directory: ../../../ffmpeg/ Exec Total Coverage
File: src/libavcodec/pcm.c Lines: 207 270 76.7 %
Date: 2020-11-28 20:53:16 Branches: 148 182 81.3 %

Line Branch Exec Source
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
1021
static av_cold int pcm_encode_init(AVCodecContext *avctx)
36
{
37
1021
    avctx->frame_size = 0;
38

1021
    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
    case AV_CODEC_ID_PCM_VIDC:
46
        pcm_vidc_tableinit();
47
        break;
48
1013
    default:
49
1013
        break;
50
    }
51
52
1021
    avctx->bits_per_coded_sample = av_get_bits_per_sample(avctx->codec->id);
53
1021
    avctx->block_align           = avctx->channels * avctx->bits_per_coded_sample / 8;
54
1021
    avctx->bit_rate              = avctx->block_align * 8LL * avctx->sample_rate;
55
56
1021
    return 0;
57
}
58
59
/**
60
 * Write PCM samples macro
61
 * @param type   Datatype of native machine format
62
 * @param endian bytestream_put_xxx() suffix
63
 * @param src    Source pointer (variable name)
64
 * @param dst    Destination pointer (variable name)
65
 * @param n      Total number of samples (variable name)
66
 * @param shift  Bitshift (bits)
67
 * @param offset Sample value offset
68
 */
69
#define ENCODE(type, endian, src, dst, n, shift, offset)                \
70
    samples_ ## type = (const type *) src;                              \
71
    for (; n > 0; n--) {                                                \
72
        register type v = (*samples_ ## type++ >> shift) + offset;      \
73
        bytestream_put_ ## endian(&dst, v);                             \
74
    }
75
76
#define ENCODE_PLANAR(type, endian, dst, n, shift, offset)              \
77
    n /= avctx->channels;                                               \
78
    for (c = 0; c < avctx->channels; c++) {                             \
79
        int i;                                                          \
80
        samples_ ## type = (const type *) frame->extended_data[c];      \
81
        for (i = n; i > 0; i--) {                                       \
82
            register type v = (*samples_ ## type++ >> shift) + offset;  \
83
            bytestream_put_ ## endian(&dst, v);                         \
84
        }                                                               \
85
    }
86
87
238695
static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
88
                            const AVFrame *frame, int *got_packet_ptr)
89
{
90
    int n, c, sample_size, v, ret;
91
    const short *samples;
92
    unsigned char *dst;
93
    const uint8_t *samples_uint8_t;
94
    const int16_t *samples_int16_t;
95
    const int32_t *samples_int32_t;
96
    const int64_t *samples_int64_t;
97
    const uint16_t *samples_uint16_t;
98
    const uint32_t *samples_uint32_t;
99
100
238695
    sample_size = av_get_bits_per_sample(avctx->codec->id) / 8;
101
238695
    n           = frame->nb_samples * avctx->channels;
102
238695
    samples     = (const short *)frame->data[0];
103
104
238695
    if ((ret = ff_alloc_packet2(avctx, avpkt, n * sample_size, n * sample_size)) < 0)
105
        return ret;
106
238695
    dst = avpkt->data;
107
108





238695
    switch (avctx->codec->id) {
109
259
    case AV_CODEC_ID_PCM_U32LE:
110
529459
        ENCODE(uint32_t, le32, samples, dst, n, 0, 0x80000000)
111
259
        break;
112
259
    case AV_CODEC_ID_PCM_U32BE:
113
529459
        ENCODE(uint32_t, be32, samples, dst, n, 0, 0x80000000)
114
259
        break;
115
5847
    case AV_CODEC_ID_PCM_S24LE:
116
39354433
        ENCODE(int32_t, le24, samples, dst, n, 8, 0)
117
5847
        break;
118
259
    case AV_CODEC_ID_PCM_S24LE_PLANAR:
119

529977
        ENCODE_PLANAR(int32_t, le24, dst, n, 8, 0)
120
259
        break;
121
259
    case AV_CODEC_ID_PCM_S24BE:
122
529459
        ENCODE(int32_t, be24, samples, dst, n, 8, 0)
123
259
        break;
124
259
    case AV_CODEC_ID_PCM_U24LE:
125
529459
        ENCODE(uint32_t, le24, samples, dst, n, 8, 0x800000)
126
259
        break;
127
259
    case AV_CODEC_ID_PCM_U24BE:
128
529459
        ENCODE(uint32_t, be24, samples, dst, n, 8, 0x800000)
129
259
        break;
130
20
    case AV_CODEC_ID_PCM_S24DAUD:
131
40940
        for (; n > 0; n--) {
132
40920
            uint32_t tmp = ff_reverse[(*samples >> 8) & 0xff] +
133
40920
                           (ff_reverse[*samples & 0xff] << 8);
134
40920
            tmp <<= 4; // sync flags would go here
135
40920
            bytestream_put_be24(&dst, tmp);
136
40920
            samples++;
137
        }
138
20
        break;
139
259
    case AV_CODEC_ID_PCM_U16LE:
140
529459
        ENCODE(uint16_t, le16, samples, dst, n, 0, 0x8000)
141
259
        break;
142
259
    case AV_CODEC_ID_PCM_U16BE:
143
529459
        ENCODE(uint16_t, be16, samples, dst, n, 0, 0x8000)
144
259
        break;
145
366
    case AV_CODEC_ID_PCM_S8:
146
7726634
        ENCODE(uint8_t, byte, samples, dst, n, 0, -128)
147
366
        break;
148
259
    case AV_CODEC_ID_PCM_S8_PLANAR:
149

529977
        ENCODE_PLANAR(uint8_t, byte, dst, n, 0, -128)
150
259
        break;
151
#if HAVE_BIGENDIAN
152
    case AV_CODEC_ID_PCM_S64LE:
153
    case AV_CODEC_ID_PCM_F64LE:
154
        ENCODE(int64_t, le64, samples, dst, n, 0, 0)
155
        break;
156
    case AV_CODEC_ID_PCM_S32LE:
157
    case AV_CODEC_ID_PCM_F32LE:
158
        ENCODE(int32_t, le32, samples, dst, n, 0, 0)
159
        break;
160
    case AV_CODEC_ID_PCM_S32LE_PLANAR:
161
        ENCODE_PLANAR(int32_t, le32, dst, n, 0, 0)
162
        break;
163
    case AV_CODEC_ID_PCM_S16LE:
164
        ENCODE(int16_t, le16, samples, dst, n, 0, 0)
165
        break;
166
    case AV_CODEC_ID_PCM_S16LE_PLANAR:
167
        ENCODE_PLANAR(int16_t, le16, dst, n, 0, 0)
168
        break;
169
    case AV_CODEC_ID_PCM_F64BE:
170
    case AV_CODEC_ID_PCM_F32BE:
171
    case AV_CODEC_ID_PCM_S64BE:
172
    case AV_CODEC_ID_PCM_S32BE:
173
    case AV_CODEC_ID_PCM_S16BE:
174
#else
175
259
    case AV_CODEC_ID_PCM_S64BE:
176
    case AV_CODEC_ID_PCM_F64BE:
177
529459
        ENCODE(int64_t, be64, samples, dst, n, 0, 0)
178
259
        break;
179
518
    case AV_CODEC_ID_PCM_F32BE:
180
    case AV_CODEC_ID_PCM_S32BE:
181
1058918
        ENCODE(int32_t, be32, samples, dst, n, 0, 0)
182
518
        break;
183
391
    case AV_CODEC_ID_PCM_S16BE:
184
661891
        ENCODE(int16_t, be16, samples, dst, n, 0, 0)
185
391
        break;
186
303
    case AV_CODEC_ID_PCM_S16BE_PLANAR:
187

618309
        ENCODE_PLANAR(int16_t, be16, dst, n, 0, 0)
188
303
        break;
189
227360
    case AV_CODEC_ID_PCM_F64LE:
190
    case AV_CODEC_ID_PCM_F32LE:
191
    case AV_CODEC_ID_PCM_S64LE:
192
    case AV_CODEC_ID_PCM_S32LE:
193
    case AV_CODEC_ID_PCM_S16LE:
194
#endif /* HAVE_BIGENDIAN */
195
    case AV_CODEC_ID_PCM_U8:
196
227360
        memcpy(dst, samples, n * sample_size);
197
227360
        break;
198
#if HAVE_BIGENDIAN
199
    case AV_CODEC_ID_PCM_S16BE_PLANAR:
200
#else
201
518
    case AV_CODEC_ID_PCM_S16LE_PLANAR:
202
    case AV_CODEC_ID_PCM_S32LE_PLANAR:
203
#endif /* HAVE_BIGENDIAN */
204
518
        n /= avctx->channels;
205
1554
        for (c = 0; c < avctx->channels; c++) {
206
1036
            const uint8_t *src = frame->extended_data[c];
207
1036
            bytestream_put_buffer(&dst, src, n * sample_size);
208
        }
209
518
        break;
210
479
    case AV_CODEC_ID_PCM_ALAW:
211
750179
        for (; n > 0; n--) {
212
749700
            v      = *samples++;
213
749700
            *dst++ = linear_to_alaw[(v + 32768) >> 2];
214
        }
215
479
        break;
216
303
    case AV_CODEC_ID_PCM_MULAW:
217
573603
        for (; n > 0; n--) {
218
573300
            v      = *samples++;
219
573300
            *dst++ = linear_to_ulaw[(v + 32768) >> 2];
220
        }
221
303
        break;
222
    case AV_CODEC_ID_PCM_VIDC:
223
        for (; n > 0; n--) {
224
            v      = *samples++;
225
            *dst++ = linear_to_vidc[(v + 32768) >> 2];
226
        }
227
        break;
228
    default:
229
        return -1;
230
    }
231
232
238695
    *got_packet_ptr = 1;
233
238695
    return 0;
234
}
235
236
typedef struct PCMDecode {
237
    short   table[256];
238
    void (*vector_fmul_scalar)(float *dst, const float *src, float mul,
239
                               int len);
240
    float   scale;
241
} PCMDecode;
242
243
1460
static av_cold int pcm_decode_init(AVCodecContext *avctx)
244
{
245
1460
    PCMDecode *s = avctx->priv_data;
246
    AVFloatDSPContext *fdsp;
247
    int i;
248
249
1460
    if (avctx->channels <= 0) {
250
        av_log(avctx, AV_LOG_ERROR, "PCM channels out of bounds\n");
251
        return AVERROR(EINVAL);
252
    }
253
254

1460
    switch (avctx->codec_id) {
255
24
    case AV_CODEC_ID_PCM_ALAW:
256
6168
        for (i = 0; i < 256; i++)
257
6144
            s->table[i] = alaw2linear(i);
258
24
        break;
259
14
    case AV_CODEC_ID_PCM_MULAW:
260
3598
        for (i = 0; i < 256; i++)
261
3584
            s->table[i] = ulaw2linear(i);
262
14
        break;
263
    case AV_CODEC_ID_PCM_VIDC:
264
        for (i = 0; i < 256; i++)
265
            s->table[i] = vidc2linear(i);
266
        break;
267
    case AV_CODEC_ID_PCM_F16LE:
268
    case AV_CODEC_ID_PCM_F24LE:
269
        if (avctx->bits_per_coded_sample < 1 || avctx->bits_per_coded_sample > 24)
270
            return AVERROR_INVALIDDATA;
271
272
        s->scale = 1. / (1 << (avctx->bits_per_coded_sample - 1));
273
        fdsp = avpriv_float_dsp_alloc(0);
274
        if (!fdsp)
275
            return AVERROR(ENOMEM);
276
        s->vector_fmul_scalar = fdsp->vector_fmul_scalar;
277
        av_free(fdsp);
278
        break;
279
1422
    default:
280
1422
        break;
281
    }
282
283
1460
    avctx->sample_fmt = avctx->codec->sample_fmts[0];
284
285
1460
    if (avctx->sample_fmt == AV_SAMPLE_FMT_S32)
286
47
        avctx->bits_per_raw_sample = av_get_bits_per_sample(avctx->codec_id);
287
288
1460
    return 0;
289
}
290
291
/**
292
 * Read PCM samples macro
293
 * @param size   Data size of native machine format
294
 * @param endian bytestream_get_xxx() endian suffix
295
 * @param src    Source pointer (variable name)
296
 * @param dst    Destination pointer (variable name)
297
 * @param n      Total number of samples (variable name)
298
 * @param shift  Bitshift (bits)
299
 * @param offset Sample value offset
300
 */
301
#define DECODE(size, endian, src, dst, n, shift, offset)                       \
302
    for (; n > 0; n--) {                                                       \
303
        uint ## size ## _t v = bytestream_get_ ## endian(&src);                \
304
        AV_WN ## size ## A(dst, (uint ## size ## _t)(v - offset) << shift);    \
305
        dst += size / 8;                                                       \
306
    }
307
308
#define DECODE_PLANAR(size, endian, src, dst, n, shift, offset)                \
309
    n /= avctx->channels;                                                      \
310
    for (c = 0; c < avctx->channels; c++) {                                    \
311
        int i;                                                                 \
312
        dst = frame->extended_data[c];                                         \
313
        for (i = n; i > 0; i--) {                                              \
314
            uint ## size ## _t v = bytestream_get_ ## endian(&src);            \
315
            AV_WN ## size ## A(dst, (uint ## size ##_t)(v - offset) << shift); \
316
            dst += size / 8;                                                   \
317
        }                                                                      \
318
    }
319
320
77436
static int pcm_decode_frame(AVCodecContext *avctx, void *data,
321
                            int *got_frame_ptr, AVPacket *avpkt)
322
{
323
77436
    const uint8_t *src = avpkt->data;
324
77436
    int buf_size       = avpkt->size;
325
77436
    PCMDecode *s       = avctx->priv_data;
326
77436
    AVFrame *frame     = data;
327
    int sample_size, c, n, ret, samples_per_block;
328
    uint8_t *samples;
329
    int32_t *dst_int32_t;
330
331
77436
    sample_size = av_get_bits_per_sample(avctx->codec_id) / 8;
332
333
    /* av_get_bits_per_sample returns 0 for AV_CODEC_ID_PCM_DVD */
334
77436
    samples_per_block = 1;
335
77436
    if (avctx->codec_id == AV_CODEC_ID_PCM_LXF) {
336
        /* we process 40-bit blocks per channel for LXF */
337
        samples_per_block = 2;
338
        sample_size       = 5;
339
    }
340
341
77436
    if (sample_size == 0) {
342
        av_log(avctx, AV_LOG_ERROR, "Invalid sample_size\n");
343
        return AVERROR(EINVAL);
344
    }
345
346
77436
    if (avctx->channels == 0) {
347
        av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
348
        return AVERROR(EINVAL);
349
    }
350
351
77436
    if (avctx->codec_id != avctx->codec->id) {
352
        av_log(avctx, AV_LOG_ERROR, "codec ids mismatch\n");
353
        return AVERROR(EINVAL);
354
    }
355
356
77436
    n = avctx->channels * sample_size;
357
358

77436
    if (n && buf_size % n) {
359
        if (buf_size < n) {
360
            av_log(avctx, AV_LOG_ERROR,
361
                   "Invalid PCM packet, data has size %d but at least a size of %d was expected\n",
362
                   buf_size, n);
363
            return AVERROR_INVALIDDATA;
364
        } else
365
            buf_size -= buf_size % n;
366
    }
367
368
77436
    n = buf_size / sample_size;
369
370
    /* get output buffer */
371
77436
    frame->nb_samples = n * samples_per_block / avctx->channels;
372
77436
    if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
373
        return ret;
374
77436
    samples = frame->data[0];
375
376





77436
    switch (avctx->codec_id) {
377
259
    case AV_CODEC_ID_PCM_U32LE:
378
529459
        DECODE(32, le32, src, samples, n, 0, 0x80000000)
379
259
        break;
380
259
    case AV_CODEC_ID_PCM_U32BE:
381
529459
        DECODE(32, be32, src, samples, n, 0, 0x80000000)
382
259
        break;
383
14475
    case AV_CODEC_ID_PCM_S24LE:
384
19756559
        DECODE(32, le24, src, samples, n, 8, 0)
385
14475
        break;
386
259
    case AV_CODEC_ID_PCM_S24LE_PLANAR:
387

529977
        DECODE_PLANAR(32, le24, src, samples, n, 8, 0);
388
259
        break;
389
259
    case AV_CODEC_ID_PCM_S24BE:
390
529459
        DECODE(32, be24, src, samples, n, 8, 0)
391
259
        break;
392
259
    case AV_CODEC_ID_PCM_U24LE:
393
529459
        DECODE(32, le24, src, samples, n, 8, 0x800000)
394
259
        break;
395
259
    case AV_CODEC_ID_PCM_U24BE:
396
529459
        DECODE(32, be24, src, samples, n, 8, 0x800000)
397
259
        break;
398
20
    case AV_CODEC_ID_PCM_S24DAUD:
399
40940
        for (; n > 0; n--) {
400
40920
            uint32_t v = bytestream_get_be24(&src);
401
40920
            v >>= 4; // sync flags are here
402
40920
            AV_WN16A(samples, ff_reverse[(v >> 8) & 0xff] +
403
                             (ff_reverse[v        & 0xff] << 8));
404
40920
            samples += 2;
405
        }
406
20
        break;
407
259
    case AV_CODEC_ID_PCM_U16LE:
408
529459
        DECODE(16, le16, src, samples, n, 0, 0x8000)
409
259
        break;
410
259
    case AV_CODEC_ID_PCM_U16BE:
411
529459
        DECODE(16, be16, src, samples, n, 0, 0x8000)
412
259
        break;
413
259
    case AV_CODEC_ID_PCM_S8:
414
529459
        for (; n > 0; n--)
415
529200
            *samples++ = *src++ + 128;
416
259
        break;
417
259
    case AV_CODEC_ID_PCM_S8_PLANAR:
418
259
        n /= avctx->channels;
419
777
        for (c = 0; c < avctx->channels; c++) {
420
            int i;
421
518
            samples = frame->extended_data[c];
422
529718
            for (i = n; i > 0; i--)
423
529200
                *samples++ = *src++ + 128;
424
        }
425
259
        break;
426
#if HAVE_BIGENDIAN
427
    case AV_CODEC_ID_PCM_S64LE:
428
    case AV_CODEC_ID_PCM_F64LE:
429
        DECODE(64, le64, src, samples, n, 0, 0)
430
        break;
431
    case AV_CODEC_ID_PCM_S32LE:
432
    case AV_CODEC_ID_PCM_F32LE:
433
    case AV_CODEC_ID_PCM_F24LE:
434
    case AV_CODEC_ID_PCM_F16LE:
435
        DECODE(32, le32, src, samples, n, 0, 0)
436
        break;
437
    case AV_CODEC_ID_PCM_S32LE_PLANAR:
438
        DECODE_PLANAR(32, le32, src, samples, n, 0, 0);
439
        break;
440
    case AV_CODEC_ID_PCM_S16LE:
441
        DECODE(16, le16, src, samples, n, 0, 0)
442
        break;
443
    case AV_CODEC_ID_PCM_S16LE_PLANAR:
444
        DECODE_PLANAR(16, le16, src, samples, n, 0, 0);
445
        break;
446
    case AV_CODEC_ID_PCM_F64BE:
447
    case AV_CODEC_ID_PCM_F32BE:
448
    case AV_CODEC_ID_PCM_S64BE:
449
    case AV_CODEC_ID_PCM_S32BE:
450
    case AV_CODEC_ID_PCM_S16BE:
451
#else
452
259
    case AV_CODEC_ID_PCM_S64BE:
453
    case AV_CODEC_ID_PCM_F64BE:
454
529459
        DECODE(64, be64, src, samples, n, 0, 0)
455
259
        break;
456
518
    case AV_CODEC_ID_PCM_F32BE:
457
    case AV_CODEC_ID_PCM_S32BE:
458
1058918
        DECODE(32, be32, src, samples, n, 0, 0)
459
518
        break;
460
1028
    case AV_CODEC_ID_PCM_S16BE:
461
1888842
        DECODE(16, be16, src, samples, n, 0, 0)
462
1028
        break;
463
303
    case AV_CODEC_ID_PCM_S16BE_PLANAR:
464

618309
        DECODE_PLANAR(16, be16, src, samples, n, 0, 0);
465
303
        break;
466
54735
    case AV_CODEC_ID_PCM_F64LE:
467
    case AV_CODEC_ID_PCM_F32LE:
468
    case AV_CODEC_ID_PCM_F24LE:
469
    case AV_CODEC_ID_PCM_F16LE:
470
    case AV_CODEC_ID_PCM_S64LE:
471
    case AV_CODEC_ID_PCM_S32LE:
472
    case AV_CODEC_ID_PCM_S16LE:
473
#endif /* HAVE_BIGENDIAN */
474
    case AV_CODEC_ID_PCM_U8:
475
54735
        memcpy(samples, src, n * sample_size);
476
54735
        break;
477
#if HAVE_BIGENDIAN
478
    case AV_CODEC_ID_PCM_S16BE_PLANAR:
479
#else
480
660
    case AV_CODEC_ID_PCM_S16LE_PLANAR:
481
    case AV_CODEC_ID_PCM_S32LE_PLANAR:
482
#endif /* HAVE_BIGENDIAN */
483
660
        n /= avctx->channels;
484
1980
        for (c = 0; c < avctx->channels; c++) {
485
1320
            samples = frame->extended_data[c];
486
1320
            bytestream_get_buffer(&src, samples, n * sample_size);
487
        }
488
660
        break;
489
2848
    case AV_CODEC_ID_PCM_ALAW:
490
    case AV_CODEC_ID_PCM_MULAW:
491
    case AV_CODEC_ID_PCM_VIDC:
492
4972036
        for (; n > 0; n--) {
493
4969188
            AV_WN16A(samples, s->table[*src++]);
494
4969188
            samples += 2;
495
        }
496
2848
        break;
497
    case AV_CODEC_ID_PCM_LXF:
498
    {
499
        int i;
500
        n /= avctx->channels;
501
        for (c = 0; c < avctx->channels; c++) {
502
            dst_int32_t = (int32_t *)frame->extended_data[c];
503
            for (i = 0; i < n; i++) {
504
                // extract low 20 bits and expand to 32 bits
505
                *dst_int32_t++ =  ((uint32_t)src[2]<<28) |
506
                                  (src[1]         << 20) |
507
                                  (src[0]         << 12) |
508
                                 ((src[2] & 0x0F) <<  8) |
509
                                   src[1];
510
                // extract high 20 bits and expand to 32 bits
511
                *dst_int32_t++ =  ((uint32_t)src[4]<<24) |
512
                                  (src[3]         << 16) |
513
                                 ((src[2] & 0xF0) <<  8) |
514
                                  (src[4]         <<  4) |
515
                                  (src[3]         >>  4);
516
                src += 5;
517
            }
518
        }
519
        break;
520
    }
521
    default:
522
        return -1;
523
    }
524
525
77436
    if (avctx->codec_id == AV_CODEC_ID_PCM_F16LE ||
526
77436
        avctx->codec_id == AV_CODEC_ID_PCM_F24LE) {
527
        s->vector_fmul_scalar((float *)frame->extended_data[0],
528
                              (const float *)frame->extended_data[0],
529
                              s->scale, FFALIGN(frame->nb_samples * avctx->channels, 4));
530
        emms_c();
531
    }
532
533
77436
    *got_frame_ptr = 1;
534
535
77436
    return buf_size;
536
}
537
538
#define PCM_ENCODER_0(id_, sample_fmt_, name_, long_name_)
539
#define PCM_ENCODER_1(id_, sample_fmt_, name_, long_name_)                  \
540
AVCodec ff_ ## name_ ## _encoder = {                                        \
541
    .name         = #name_,                                                 \
542
    .long_name    = NULL_IF_CONFIG_SMALL(long_name_),                       \
543
    .type         = AVMEDIA_TYPE_AUDIO,                                     \
544
    .id           = AV_CODEC_ID_ ## id_,                                    \
545
    .init         = pcm_encode_init,                                        \
546
    .encode2      = pcm_encode_frame,                                       \
547
    .capabilities = AV_CODEC_CAP_VARIABLE_FRAME_SIZE,                       \
548
    .sample_fmts  = (const enum AVSampleFormat[]){ sample_fmt_,             \
549
                                                   AV_SAMPLE_FMT_NONE },    \
550
}
551
552
#define PCM_ENCODER_2(cf, id, sample_fmt, name, long_name)                  \
553
    PCM_ENCODER_ ## cf(id, sample_fmt, name, long_name)
554
#define PCM_ENCODER_3(cf, id, sample_fmt, name, long_name)                  \
555
    PCM_ENCODER_2(cf, id, sample_fmt, name, long_name)
556
#define PCM_ENCODER(id, sample_fmt, name, long_name)                        \
557
    PCM_ENCODER_3(CONFIG_ ## id ## _ENCODER, id, sample_fmt, name, long_name)
558
559
#define PCM_DECODER_0(id, sample_fmt, name, long_name)
560
#define PCM_DECODER_1(id_, sample_fmt_, name_, long_name_)                  \
561
AVCodec ff_ ## name_ ## _decoder = {                                        \
562
    .name           = #name_,                                               \
563
    .long_name      = NULL_IF_CONFIG_SMALL(long_name_),                     \
564
    .type           = AVMEDIA_TYPE_AUDIO,                                   \
565
    .id             = AV_CODEC_ID_ ## id_,                                  \
566
    .priv_data_size = sizeof(PCMDecode),                                    \
567
    .init           = pcm_decode_init,                                      \
568
    .decode         = pcm_decode_frame,                                     \
569
    .capabilities   = AV_CODEC_CAP_DR1,                                     \
570
    .sample_fmts    = (const enum AVSampleFormat[]){ sample_fmt_,           \
571
                                                     AV_SAMPLE_FMT_NONE },  \
572
}
573
574
#define PCM_DECODER_2(cf, id, sample_fmt, name, long_name)                  \
575
    PCM_DECODER_ ## cf(id, sample_fmt, name, long_name)
576
#define PCM_DECODER_3(cf, id, sample_fmt, name, long_name)                  \
577
    PCM_DECODER_2(cf, id, sample_fmt, name, long_name)
578
#define PCM_DECODER(id, sample_fmt, name, long_name)                        \
579
    PCM_DECODER_3(CONFIG_ ## id ## _DECODER, id, sample_fmt, name, long_name)
580
581
#define PCM_CODEC(id, sample_fmt_, name, long_name_)                    \
582
    PCM_ENCODER(id, sample_fmt_, name, long_name_);                     \
583
    PCM_DECODER(id, sample_fmt_, name, long_name_)
584
585
/* Note: Do not forget to add new entries to the Makefile as well. */
586
PCM_CODEC  (PCM_ALAW,         AV_SAMPLE_FMT_S16, pcm_alaw,         "PCM A-law / G.711 A-law");
587
PCM_DECODER(PCM_F16LE,        AV_SAMPLE_FMT_FLT, pcm_f16le,        "PCM 16.8 floating point little-endian");
588
PCM_DECODER(PCM_F24LE,        AV_SAMPLE_FMT_FLT, pcm_f24le,        "PCM 24.0 floating point little-endian");
589
PCM_CODEC  (PCM_F32BE,        AV_SAMPLE_FMT_FLT, pcm_f32be,        "PCM 32-bit floating point big-endian");
590
PCM_CODEC  (PCM_F32LE,        AV_SAMPLE_FMT_FLT, pcm_f32le,        "PCM 32-bit floating point little-endian");
591
PCM_CODEC  (PCM_F64BE,        AV_SAMPLE_FMT_DBL, pcm_f64be,        "PCM 64-bit floating point big-endian");
592
PCM_CODEC  (PCM_F64LE,        AV_SAMPLE_FMT_DBL, pcm_f64le,        "PCM 64-bit floating point little-endian");
593
PCM_DECODER(PCM_LXF,          AV_SAMPLE_FMT_S32P,pcm_lxf,          "PCM signed 20-bit little-endian planar");
594
PCM_CODEC  (PCM_MULAW,        AV_SAMPLE_FMT_S16, pcm_mulaw,        "PCM mu-law / G.711 mu-law");
595
PCM_CODEC  (PCM_S8,           AV_SAMPLE_FMT_U8,  pcm_s8,           "PCM signed 8-bit");
596
PCM_CODEC  (PCM_S8_PLANAR,    AV_SAMPLE_FMT_U8P, pcm_s8_planar,    "PCM signed 8-bit planar");
597
PCM_CODEC  (PCM_S16BE,        AV_SAMPLE_FMT_S16, pcm_s16be,        "PCM signed 16-bit big-endian");
598
PCM_CODEC  (PCM_S16BE_PLANAR, AV_SAMPLE_FMT_S16P,pcm_s16be_planar, "PCM signed 16-bit big-endian planar");
599
PCM_CODEC  (PCM_S16LE,        AV_SAMPLE_FMT_S16, pcm_s16le,        "PCM signed 16-bit little-endian");
600
PCM_CODEC  (PCM_S16LE_PLANAR, AV_SAMPLE_FMT_S16P,pcm_s16le_planar, "PCM signed 16-bit little-endian planar");
601
PCM_CODEC  (PCM_S24BE,        AV_SAMPLE_FMT_S32, pcm_s24be,        "PCM signed 24-bit big-endian");
602
PCM_CODEC  (PCM_S24DAUD,      AV_SAMPLE_FMT_S16, pcm_s24daud,      "PCM D-Cinema audio signed 24-bit");
603
PCM_CODEC  (PCM_S24LE,        AV_SAMPLE_FMT_S32, pcm_s24le,        "PCM signed 24-bit little-endian");
604
PCM_CODEC  (PCM_S24LE_PLANAR, AV_SAMPLE_FMT_S32P,pcm_s24le_planar, "PCM signed 24-bit little-endian planar");
605
PCM_CODEC  (PCM_S32BE,        AV_SAMPLE_FMT_S32, pcm_s32be,        "PCM signed 32-bit big-endian");
606
PCM_CODEC  (PCM_S32LE,        AV_SAMPLE_FMT_S32, pcm_s32le,        "PCM signed 32-bit little-endian");
607
PCM_CODEC  (PCM_S32LE_PLANAR, AV_SAMPLE_FMT_S32P,pcm_s32le_planar, "PCM signed 32-bit little-endian planar");
608
PCM_CODEC  (PCM_U8,           AV_SAMPLE_FMT_U8,  pcm_u8,           "PCM unsigned 8-bit");
609
PCM_CODEC  (PCM_U16BE,        AV_SAMPLE_FMT_S16, pcm_u16be,        "PCM unsigned 16-bit big-endian");
610
PCM_CODEC  (PCM_U16LE,        AV_SAMPLE_FMT_S16, pcm_u16le,        "PCM unsigned 16-bit little-endian");
611
PCM_CODEC  (PCM_U24BE,        AV_SAMPLE_FMT_S32, pcm_u24be,        "PCM unsigned 24-bit big-endian");
612
PCM_CODEC  (PCM_U24LE,        AV_SAMPLE_FMT_S32, pcm_u24le,        "PCM unsigned 24-bit little-endian");
613
PCM_CODEC  (PCM_U32BE,        AV_SAMPLE_FMT_S32, pcm_u32be,        "PCM unsigned 32-bit big-endian");
614
PCM_CODEC  (PCM_U32LE,        AV_SAMPLE_FMT_S32, pcm_u32le,        "PCM unsigned 32-bit little-endian");
615
PCM_CODEC  (PCM_S64BE,        AV_SAMPLE_FMT_S64, pcm_s64be,        "PCM signed 64-bit big-endian");
616
PCM_CODEC  (PCM_S64LE,        AV_SAMPLE_FMT_S64, pcm_s64le,        "PCM signed 64-bit little-endian");
617
PCM_CODEC  (PCM_VIDC,         AV_SAMPLE_FMT_S16, pcm_vidc,         "PCM Archimedes VIDC");