static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,

                            const AVFrame *frame, int *got_packet_ptr)

{

    int n, c, sample_size, v, ret;

    const short *samples;

    unsigned char *dst;

    const uint8_t *samples_uint8_t;

    const int16_t *samples_int16_t;

    const int32_t *samples_int32_t;

    const int64_t *samples_int64_t;

    const uint16_t *samples_uint16_t;

    const uint32_t *samples_uint32_t;



    sample_size = av_get_bits_per_sample(avctx->codec->id) / 8;

    n           = frame->nb_samples * avctx->channels;

    samples     = (const short *)frame->data[0];



    if ((ret = ff_alloc_packet2(avctx, avpkt, n * sample_size)))

        return ret;

    dst = avpkt->data;



    switch (avctx->codec->id) {

    case AV_CODEC_ID_PCM_U32LE:

        ENCODE(uint32_t, le32, samples, dst, n, 0, 0x80000000)

        break;

    case AV_CODEC_ID_PCM_U32BE:

        ENCODE(uint32_t, be32, samples, dst, n, 0, 0x80000000)

        break;

    case AV_CODEC_ID_PCM_S24LE:

        ENCODE(int32_t, le24, samples, dst, n, 8, 0)

        break;

    case AV_CODEC_ID_PCM_S24LE_PLANAR:

        ENCODE_PLANAR(int32_t, le24, dst, n, 8, 0)

        break;

    case AV_CODEC_ID_PCM_S24BE:

        ENCODE(int32_t, be24, samples, dst, n, 8, 0)

        break;

    case AV_CODEC_ID_PCM_U24LE:

        ENCODE(uint32_t, le24, samples, dst, n, 8, 0x800000)

        break;

    case AV_CODEC_ID_PCM_U24BE:

        ENCODE(uint32_t, be24, samples, dst, n, 8, 0x800000)

        break;

    case AV_CODEC_ID_PCM_S24DAUD:

        for (; n > 0; n--) {

            uint32_t tmp = ff_reverse[(*samples >> 8) & 0xff] +

                           (ff_reverse[*samples & 0xff] << 8);

            tmp <<= 4; // sync flags would go here

            bytestream_put_be24(&dst, tmp);

            samples++;

        }

        break;

    case AV_CODEC_ID_PCM_U16LE:

        ENCODE(uint16_t, le16, samples, dst, n, 0, 0x8000)

        break;

    case AV_CODEC_ID_PCM_U16BE:

        ENCODE(uint16_t, be16, samples, dst, n, 0, 0x8000)

        break;

    case AV_CODEC_ID_PCM_S8:

        ENCODE(uint8_t, byte, samples, dst, n, 0, -128)

        break;

    case AV_CODEC_ID_PCM_S8_PLANAR:

        ENCODE_PLANAR(uint8_t, byte, dst, n, 0, -128)

        break;

#if HAVE_BIGENDIAN

    case AV_CODEC_ID_PCM_F64LE:

        ENCODE(int64_t, le64, samples, dst, n, 0, 0)

        break;

    case AV_CODEC_ID_PCM_S32LE:

    case AV_CODEC_ID_PCM_F32LE:

        ENCODE(int32_t, le32, samples, dst, n, 0, 0)

        break;

    case AV_CODEC_ID_PCM_S32LE_PLANAR:

        ENCODE_PLANAR(int32_t, le32, dst, n, 0, 0)

        break;

    case AV_CODEC_ID_PCM_S16LE:

        ENCODE(int16_t, le16, samples, dst, n, 0, 0)

        break;

    case AV_CODEC_ID_PCM_S16LE_PLANAR:

        ENCODE_PLANAR(int16_t, le16, dst, n, 0, 0)

        break;

    case AV_CODEC_ID_PCM_F64BE:

    case AV_CODEC_ID_PCM_F32BE:

    case AV_CODEC_ID_PCM_S32BE:

    case AV_CODEC_ID_PCM_S16BE:

#else

    case AV_CODEC_ID_PCM_F64BE:

        ENCODE(int64_t, be64, samples, dst, n, 0, 0)

        break;

    case AV_CODEC_ID_PCM_F32BE:

    case AV_CODEC_ID_PCM_S32BE:

        ENCODE(int32_t, be32, samples, dst, n, 0, 0)

        break;

    case AV_CODEC_ID_PCM_S16BE:

        ENCODE(int16_t, be16, samples, dst, n, 0, 0)

        break;

    case AV_CODEC_ID_PCM_S16BE_PLANAR:

        ENCODE_PLANAR(int16_t, be16, dst, n, 0, 0)

        break;

    case AV_CODEC_ID_PCM_F64LE:

    case AV_CODEC_ID_PCM_F32LE:

    case AV_CODEC_ID_PCM_S32LE:

    case AV_CODEC_ID_PCM_S16LE:

#endif /* HAVE_BIGENDIAN */

    case AV_CODEC_ID_PCM_U8:

        memcpy(dst, samples, n * sample_size);

        break;

#if HAVE_BIGENDIAN

    case AV_CODEC_ID_PCM_S16BE_PLANAR:

#else

    case AV_CODEC_ID_PCM_S16LE_PLANAR:

    case AV_CODEC_ID_PCM_S32LE_PLANAR:

#endif /* HAVE_BIGENDIAN */

        n /= avctx->channels;

        for (c = 0; c < avctx->channels; c++) {

            const uint8_t *src = frame->extended_data[c];

            bytestream_put_buffer(&dst, src, n * sample_size);

        }

        break;

    case AV_CODEC_ID_PCM_ALAW:

        for (; n > 0; n--) {

            v      = *samples++;

            *dst++ = linear_to_alaw[(v + 32768) >> 2];

        }

        break;

    case AV_CODEC_ID_PCM_MULAW:

        for (; n > 0; n--) {

            v      = *samples++;

            *dst++ = linear_to_ulaw[(v + 32768) >> 2];

        }

        break;

    default:

        return -1;

    }



    *got_packet_ptr = 1;

    return 0;

}

static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,

                            const AVFrame *frame, int *got_packet_ptr)

{

    int n, c, sample_size, v, ret;

    const short *samples;

    unsigned char *dst;

    const uint8_t *samples_uint8_t;

    const int16_t *samples_int16_t;

    const int32_t *samples_int32_t;

    const int64_t *samples_int64_t;

    const uint16_t *samples_uint16_t;

    const uint32_t *samples_uint32_t;



    sample_size = av_get_bits_per_sample(avctx->codec->id) / 8;

    n           = frame->nb_samples * avctx->channels;

    samples     = (const short *)frame->data[0];



    if ((ret = ff_alloc_packet2(avctx, avpkt, n * sample_size)))

        return ret;

    dst = avpkt->data;



    switch (avctx->codec->id) {

    case AV_CODEC_ID_PCM_U32LE:

        ENCODE(uint32_t, le32, samples, dst, n, 0, 0x80000000)

        break;

    case AV_CODEC_ID_PCM_U32BE:

        ENCODE(uint32_t, be32, samples, dst, n, 0, 0x80000000)

        break;

    case AV_CODEC_ID_PCM_S24LE:

        ENCODE(int32_t, le24, samples, dst, n, 8, 0)

        break;

    case AV_CODEC_ID_PCM_S24LE_PLANAR:

        ENCODE_PLANAR(int32_t, le24, dst, n, 8, 0)

        break;

    case AV_CODEC_ID_PCM_S24BE:

        ENCODE(int32_t, be24, samples, dst, n, 8, 0)

        break;

    case AV_CODEC_ID_PCM_U24LE:

        ENCODE(uint32_t, le24, samples, dst, n, 8, 0x800000)

        break;

    case AV_CODEC_ID_PCM_U24BE:

        ENCODE(uint32_t, be24, samples, dst, n, 8, 0x800000)

        break;

    case AV_CODEC_ID_PCM_S24DAUD:

        for (; n > 0; n--) {

            uint32_t tmp = ff_reverse[(*samples >> 8) & 0xff] +

                           (ff_reverse[*samples & 0xff] << 8);

            tmp <<= 4; 

            bytestream_put_be24(&dst, tmp);

            samples++;

        }

        break;

    case AV_CODEC_ID_PCM_U16LE:

        ENCODE(uint16_t, le16, samples, dst, n, 0, 0x8000)

        break;

    case AV_CODEC_ID_PCM_U16BE:

        ENCODE(uint16_t, be16, samples, dst, n, 0, 0x8000)

        break;

    case AV_CODEC_ID_PCM_S8:

        ENCODE(uint8_t, byte, samples, dst, n, 0, -128)

        break;

    case AV_CODEC_ID_PCM_S8_PLANAR:

        ENCODE_PLANAR(uint8_t, byte, dst, n, 0, -128)

        break;

#if HAVE_BIGENDIAN

    case AV_CODEC_ID_PCM_F64LE:

        ENCODE(int64_t, le64, samples, dst, n, 0, 0)

        break;

    case AV_CODEC_ID_PCM_S32LE:

    case AV_CODEC_ID_PCM_F32LE:

        ENCODE(int32_t, le32, samples, dst, n, 0, 0)

        break;

    case AV_CODEC_ID_PCM_S32LE_PLANAR:

        ENCODE_PLANAR(int32_t, le32, dst, n, 0, 0)

        break;

    case AV_CODEC_ID_PCM_S16LE:

        ENCODE(int16_t, le16, samples, dst, n, 0, 0)

        break;

    case AV_CODEC_ID_PCM_S16LE_PLANAR:

        ENCODE_PLANAR(int16_t, le16, dst, n, 0, 0)

        break;

    case AV_CODEC_ID_PCM_F64BE:

    case AV_CODEC_ID_PCM_F32BE:

    case AV_CODEC_ID_PCM_S32BE:

    case AV_CODEC_ID_PCM_S16BE:

#else

    case AV_CODEC_ID_PCM_F64BE:

        ENCODE(int64_t, be64, samples, dst, n, 0, 0)

        break;

    case AV_CODEC_ID_PCM_F32BE:

    case AV_CODEC_ID_PCM_S32BE:

        ENCODE(int32_t, be32, samples, dst, n, 0, 0)

        break;

    case AV_CODEC_ID_PCM_S16BE:

        ENCODE(int16_t, be16, samples, dst, n, 0, 0)

        break;

    case AV_CODEC_ID_PCM_S16BE_PLANAR:

        ENCODE_PLANAR(int16_t, be16, dst, n, 0, 0)

        break;

    case AV_CODEC_ID_PCM_F64LE:

    case AV_CODEC_ID_PCM_F32LE:

    case AV_CODEC_ID_PCM_S32LE:

    case AV_CODEC_ID_PCM_S16LE:

#endif 

    case AV_CODEC_ID_PCM_U8:

        memcpy(dst, samples, n * sample_size);

        break;

#if HAVE_BIGENDIAN

    case AV_CODEC_ID_PCM_S16BE_PLANAR:

#else

    case AV_CODEC_ID_PCM_S16LE_PLANAR:

    case AV_CODEC_ID_PCM_S32LE_PLANAR:

#endif 

        n /= avctx->channels;

        for (c = 0; c < avctx->channels; c++) {

            const uint8_t *src = frame->extended_data[c];

            bytestream_put_buffer(&dst, src, n * sample_size);

        }

        break;

    case AV_CODEC_ID_PCM_ALAW:

        for (; n > 0; n--) {

            v      = *samples++;

            *dst++ = linear_to_alaw[(v + 32768) >> 2];

        }

        break;

    case AV_CODEC_ID_PCM_MULAW:

        for (; n > 0; n--) {

            v      = *samples++;

            *dst++ = linear_to_ulaw[(v + 32768) >> 2];

        }

        break;

    default:

        return -1;

    }



    *got_packet_ptr = 1;

    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1,

                            const AVFrame *VAR_2, int *VAR_3)

{

    int VAR_4, VAR_5, VAR_6, VAR_7, VAR_8;

    const short *VAR_9;

    unsigned char *VAR_10;

    const uint8_t *VAR_11;

    const int16_t *VAR_12;

    const int32_t *VAR_13;

    const int64_t *VAR_14;

    const uint16_t *VAR_15;

    const uint32_t *VAR_16;



    VAR_6 = av_get_bits_per_sample(VAR_0->codec->id) / 8;

    VAR_4           = VAR_2->nb_samples * VAR_0->channels;

    VAR_9     = (const short *)VAR_2->data[0];



    if ((VAR_8 = ff_alloc_packet2(VAR_0, VAR_1, VAR_4 * VAR_6)))

        return VAR_8;

    VAR_10 = VAR_1->data;



    switch (VAR_0->codec->id) {

    case AV_CODEC_ID_PCM_U32LE:

        ENCODE(uint32_t, le32, VAR_9, VAR_10, VAR_4, 0, 0x80000000)

        break;

    case AV_CODEC_ID_PCM_U32BE:

        ENCODE(uint32_t, be32, VAR_9, VAR_10, VAR_4, 0, 0x80000000)

        break;

    case AV_CODEC_ID_PCM_S24LE:

        ENCODE(int32_t, le24, VAR_9, VAR_10, VAR_4, 8, 0)

        break;

    case AV_CODEC_ID_PCM_S24LE_PLANAR:

        ENCODE_PLANAR(int32_t, le24, VAR_10, VAR_4, 8, 0)

        break;

    case AV_CODEC_ID_PCM_S24BE:

        ENCODE(int32_t, be24, VAR_9, VAR_10, VAR_4, 8, 0)

        break;

    case AV_CODEC_ID_PCM_U24LE:

        ENCODE(uint32_t, le24, VAR_9, VAR_10, VAR_4, 8, 0x800000)

        break;

    case AV_CODEC_ID_PCM_U24BE:

        ENCODE(uint32_t, be24, VAR_9, VAR_10, VAR_4, 8, 0x800000)

        break;

    case AV_CODEC_ID_PCM_S24DAUD:

        for (; VAR_4 > 0; VAR_4--) {

            uint32_t tmp = ff_reverse[(*VAR_9 >> 8) & 0xff] +

                           (ff_reverse[*VAR_9 & 0xff] << 8);

            tmp <<= 4; 

            bytestream_put_be24(&VAR_10, tmp);

            VAR_9++;

        }

        break;

    case AV_CODEC_ID_PCM_U16LE:

        ENCODE(uint16_t, le16, VAR_9, VAR_10, VAR_4, 0, 0x8000)

        break;

    case AV_CODEC_ID_PCM_U16BE:

        ENCODE(uint16_t, be16, VAR_9, VAR_10, VAR_4, 0, 0x8000)

        break;

    case AV_CODEC_ID_PCM_S8:

        ENCODE(uint8_t, byte, VAR_9, VAR_10, VAR_4, 0, -128)

        break;

    case AV_CODEC_ID_PCM_S8_PLANAR:

        ENCODE_PLANAR(uint8_t, byte, VAR_10, VAR_4, 0, -128)

        break;

#if HAVE_BIGENDIAN

    case AV_CODEC_ID_PCM_F64LE:

        ENCODE(int64_t, le64, VAR_9, VAR_10, VAR_4, 0, 0)

        break;

    case AV_CODEC_ID_PCM_S32LE:

    case AV_CODEC_ID_PCM_F32LE:

        ENCODE(int32_t, le32, VAR_9, VAR_10, VAR_4, 0, 0)

        break;

    case AV_CODEC_ID_PCM_S32LE_PLANAR:

        ENCODE_PLANAR(int32_t, le32, VAR_10, VAR_4, 0, 0)

        break;

    case AV_CODEC_ID_PCM_S16LE:

        ENCODE(int16_t, le16, VAR_9, VAR_10, VAR_4, 0, 0)

        break;

    case AV_CODEC_ID_PCM_S16LE_PLANAR:

        ENCODE_PLANAR(int16_t, le16, VAR_10, VAR_4, 0, 0)

        break;

    case AV_CODEC_ID_PCM_F64BE:

    case AV_CODEC_ID_PCM_F32BE:

    case AV_CODEC_ID_PCM_S32BE:

    case AV_CODEC_ID_PCM_S16BE:

#else

    case AV_CODEC_ID_PCM_F64BE:

        ENCODE(int64_t, be64, VAR_9, VAR_10, VAR_4, 0, 0)

        break;

    case AV_CODEC_ID_PCM_F32BE:

    case AV_CODEC_ID_PCM_S32BE:

        ENCODE(int32_t, be32, VAR_9, VAR_10, VAR_4, 0, 0)

        break;

    case AV_CODEC_ID_PCM_S16BE:

        ENCODE(int16_t, be16, VAR_9, VAR_10, VAR_4, 0, 0)

        break;

    case AV_CODEC_ID_PCM_S16BE_PLANAR:

        ENCODE_PLANAR(int16_t, be16, VAR_10, VAR_4, 0, 0)

        break;

    case AV_CODEC_ID_PCM_F64LE:

    case AV_CODEC_ID_PCM_F32LE:

    case AV_CODEC_ID_PCM_S32LE:

    case AV_CODEC_ID_PCM_S16LE:

#endif 

    case AV_CODEC_ID_PCM_U8:

        memcpy(VAR_10, VAR_9, VAR_4 * VAR_6);

        break;

#if HAVE_BIGENDIAN

    case AV_CODEC_ID_PCM_S16BE_PLANAR:

#else

    case AV_CODEC_ID_PCM_S16LE_PLANAR:

    case AV_CODEC_ID_PCM_S32LE_PLANAR:

#endif 

        VAR_4 /= VAR_0->channels;

        for (VAR_5 = 0; VAR_5 < VAR_0->channels; VAR_5++) {

            const uint8_t *src = VAR_2->extended_data[VAR_5];

            bytestream_put_buffer(&VAR_10, src, VAR_4 * VAR_6);

        }

        break;

    case AV_CODEC_ID_PCM_ALAW:

        for (; VAR_4 > 0; VAR_4--) {

            VAR_7      = *VAR_9++;

            *VAR_10++ = linear_to_alaw[(VAR_7 + 32768) >> 2];

        }

        break;

    case AV_CODEC_ID_PCM_MULAW:

        for (; VAR_4 > 0; VAR_4--) {

            VAR_7      = *VAR_9++;

            *VAR_10++ = linear_to_ulaw[(VAR_7 + 32768) >> 2];

        }

        break;

    default:

        return -1;

    }



    *VAR_3 = 1;

    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1,
const AVFrame *VAR_2, int *VAR_3)
{ int VAR_4, VAR_5, VAR_6, VAR_7, VAR_8; const short *VAR_9; unsigned char *VAR_10; const uint8_t *VAR_11; const int16_t *VAR_12; const int32_t *VAR_13; const int64_t *VAR_14; const uint16_t *VAR_15; const uint32_t *VAR_16; VAR_6 = av_get_bits_per_sample(VAR_0->codec->id) / 8; VAR_4           = VAR_2->nb_samples * VAR_0->channels; VAR_9     = (const short *)VAR_2->data[0]; if ((VAR_8 = ff_alloc_packet2(VAR_0, VAR_1, VAR_4 * VAR_6)))
return VAR_8; VAR_10 = VAR_1->data; switch (VAR_0->codec->id) { case AV_CODEC_ID_PCM_U32LE:
ENCODE(uint32_t, le32, VAR_9, VAR_10, VAR_4, 0, 0x80000000)
break; case AV_CODEC_ID_PCM_U32BE:
ENCODE(uint32_t, be32, VAR_9, VAR_10, VAR_4, 0, 0x80000000)
break; case AV_CODEC_ID_PCM_S24LE:
ENCODE(int32_t, le24, VAR_9, VAR_10, VAR_4, 8, 0)
break; case AV_CODEC_ID_PCM_S24LE_PLANAR:
ENCODE_PLANAR(int32_t, le24, VAR_10, VAR_4, 8, 0)
break; case AV_CODEC_ID_PCM_S24BE:
ENCODE(int32_t, be24, VAR_9, VAR_10, VAR_4, 8, 0)
break; case AV_CODEC_ID_PCM_U24LE:
ENCODE(uint32_t, le24, VAR_9, VAR_10, VAR_4, 8, 0x800000)
break; case AV_CODEC_ID_PCM_U24BE:
ENCODE(uint32_t, be24, VAR_9, VAR_10, VAR_4, 8, 0x800000)
break; case AV_CODEC_ID_PCM_S24DAUD:
for (; VAR_4 > 0; VAR_4--) { uint32_t tmp = ff_reverse[(*VAR_9 >> 8) & 0xff] +
(ff_reverse[*VAR_9 & 0xff] << 8); tmp <<= 4; bytestream_put_be24(&VAR_10, tmp); VAR_9++; } break; case AV_CODEC_ID_PCM_U16LE:
ENCODE(uint16_t, le16, VAR_9, VAR_10, VAR_4, 0, 0x8000)
break; case AV_CODEC_ID_PCM_U16BE:
ENCODE(uint16_t, be16, VAR_9, VAR_10, VAR_4, 0, 0x8000)
break; case AV_CODEC_ID_PCM_S8:
ENCODE(uint8_t, byte, VAR_9, VAR_10, VAR_4, 0, -128)
break; case AV_CODEC_ID_PCM_S8_PLANAR:
ENCODE_PLANAR(uint8_t, byte, VAR_10, VAR_4, 0, -128)
break; #if HAVE_BIGENDIAN
case AV_CODEC_ID_PCM_F64LE:
ENCODE(int64_t, le64, VAR_9, VAR_10, VAR_4, 0, 0)
break; case AV_CODEC_ID_PCM_S32LE:
case AV_CODEC_ID_PCM_F32LE:
ENCODE(int32_t, le32, VAR_9, VAR_10, VAR_4, 0, 0)
break; case AV_CODEC_ID_PCM_S32LE_PLANAR:
ENCODE_PLANAR(int32_t, le32, VAR_10, VAR_4, 0, 0)
break; case AV_CODEC_ID_PCM_S16LE:
ENCODE(int16_t, le16, VAR_9, VAR_10, VAR_4, 0, 0)
break; case AV_CODEC_ID_PCM_S16LE_PLANAR:
ENCODE_PLANAR(int16_t, le16, VAR_10, VAR_4, 0, 0)
break; case AV_CODEC_ID_PCM_F64BE:
case AV_CODEC_ID_PCM_F32BE:
case AV_CODEC_ID_PCM_S32BE:
case AV_CODEC_ID_PCM_S16BE:
#else
case AV_CODEC_ID_PCM_F64BE:
ENCODE(int64_t, be64, VAR_9, VAR_10, VAR_4, 0, 0)
break; case AV_CODEC_ID_PCM_F32BE:
case AV_CODEC_ID_PCM_S32BE:
ENCODE(int32_t, be32, VAR_9, VAR_10, VAR_4, 0, 0)
break; case AV_CODEC_ID_PCM_S16BE:
ENCODE(int16_t, be16, VAR_9, VAR_10, VAR_4, 0, 0)
break; case AV_CODEC_ID_PCM_S16BE_PLANAR:
ENCODE_PLANAR(int16_t, be16, VAR_10, VAR_4, 0, 0)
break; case AV_CODEC_ID_PCM_F64LE:
case AV_CODEC_ID_PCM_F32LE:
case AV_CODEC_ID_PCM_S32LE:
case AV_CODEC_ID_PCM_S16LE:
#endif
case AV_CODEC_ID_PCM_U8:
memcpy(VAR_10, VAR_9, VAR_4 * VAR_6); break; #if HAVE_BIGENDIAN
case AV_CODEC_ID_PCM_S16BE_PLANAR:
#else
case AV_CODEC_ID_PCM_S16LE_PLANAR:
case AV_CODEC_ID_PCM_S32LE_PLANAR:
#endif
VAR_4 /= VAR_0->channels; for (VAR_5 = 0; VAR_5 < VAR_0->channels; VAR_5++) { const uint8_t *src = VAR_2->extended_data[VAR_5]; bytestream_put_buffer(&VAR_10, src, VAR_4 * VAR_6); } break; case AV_CODEC_ID_PCM_ALAW:
for (; VAR_4 > 0; VAR_4--) { VAR_7      = *VAR_9++; *VAR_10++ = linear_to_alaw[(VAR_7 + 32768) >> 2]; } break; case AV_CODEC_ID_PCM_MULAW:
for (; VAR_4 > 0; VAR_4--) { VAR_7      = *VAR_9++; *VAR_10++ = linear_to_ulaw[(VAR_7 + 32768) >> 2]; } break; default:
return -1; } *VAR_3 = 1; return 0; }