diff options
author | Paul B Mahol <onemda@gmail.com> | 2012-11-19 09:19:30 +0000 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2012-11-20 17:29:00 +0000 |
commit | dd59f0125df0339dafb5ac63be9b3c416babb0b2 (patch) | |
tree | 4821c4c8300ef47a1d69331b45087e5196314a10 /libavcodec/pcm.c | |
parent | f17f759544bcde5bd49ddc681bccde313ff3e030 (diff) | |
download | ffmpeg-dd59f0125df0339dafb5ac63be9b3c416babb0b2.tar.gz |
add some planar PCM encoders
Signed-off-by: Paul B Mahol <onemda@gmail.com>
Diffstat (limited to 'libavcodec/pcm.c')
-rw-r--r-- | libavcodec/pcm.c | 50 |
1 files changed, 44 insertions, 6 deletions
diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c index 489e79e302..5ed603ee3f 100644 --- a/libavcodec/pcm.c +++ b/libavcodec/pcm.c @@ -79,10 +79,21 @@ static av_cold int pcm_encode_close(AVCodecContext *avctx) bytestream_put_ ## endian(&dst, v); \ } +#define ENCODE_PLANAR(type, endian, dst, n, shift, offset) \ + n /= avctx->channels; \ + for (c = 0; c < avctx->channels; c++) { \ + int i; \ + samples_ ## type = (const type *) frame->extended_data[c]; \ + for (i = n; i > 0; i--) { \ + register type v = (*samples_ ## type++ >> shift) + offset; \ + bytestream_put_ ## endian(&dst, v); \ + } \ + } + static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr) { - int n, sample_size, v, ret; + int n, c, sample_size, v, ret; const short *samples; unsigned char *dst; const uint8_t *samples_uint8_t; @@ -110,6 +121,9 @@ static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, 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; @@ -137,6 +151,9 @@ static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, 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) @@ -145,9 +162,15 @@ static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, 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: @@ -163,6 +186,9 @@ static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, 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: @@ -171,6 +197,18 @@ static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, 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++; @@ -565,18 +603,18 @@ PCM_CODEC (PCM_F64LE, AV_SAMPLE_FMT_DBL, pcm_f64le, "PCM 64-bit f PCM_DECODER(PCM_LXF, AV_SAMPLE_FMT_S32P,pcm_lxf, "PCM signed 20-bit little-endian planar"); PCM_CODEC (PCM_MULAW, AV_SAMPLE_FMT_S16, pcm_mulaw, "PCM mu-law / G.711 mu-law"); PCM_CODEC (PCM_S8, AV_SAMPLE_FMT_U8, pcm_s8, "PCM signed 8-bit"); -PCM_DECODER(PCM_S8_PLANAR, AV_SAMPLE_FMT_U8P, pcm_s8_planar, "PCM signed 8-bit planar"); +PCM_CODEC (PCM_S8_PLANAR, AV_SAMPLE_FMT_U8P, pcm_s8_planar, "PCM signed 8-bit planar"); PCM_CODEC (PCM_S16BE, AV_SAMPLE_FMT_S16, pcm_s16be, "PCM signed 16-bit big-endian"); -PCM_DECODER(PCM_S16BE_PLANAR, AV_SAMPLE_FMT_S16P,pcm_s16be_planar, "PCM signed 16-bit big-endian planar"); +PCM_CODEC (PCM_S16BE_PLANAR, AV_SAMPLE_FMT_S16P,pcm_s16be_planar, "PCM signed 16-bit big-endian planar"); PCM_CODEC (PCM_S16LE, AV_SAMPLE_FMT_S16, pcm_s16le, "PCM signed 16-bit little-endian"); -PCM_DECODER(PCM_S16LE_PLANAR, AV_SAMPLE_FMT_S16P,pcm_s16le_planar, "PCM signed 16-bit little-endian planar"); +PCM_CODEC (PCM_S16LE_PLANAR, AV_SAMPLE_FMT_S16P,pcm_s16le_planar, "PCM signed 16-bit little-endian planar"); PCM_CODEC (PCM_S24BE, AV_SAMPLE_FMT_S32, pcm_s24be, "PCM signed 24-bit big-endian"); PCM_CODEC (PCM_S24DAUD, AV_SAMPLE_FMT_S16, pcm_s24daud, "PCM D-Cinema audio signed 24-bit"); PCM_CODEC (PCM_S24LE, AV_SAMPLE_FMT_S32, pcm_s24le, "PCM signed 24-bit little-endian"); -PCM_DECODER(PCM_S24LE_PLANAR, AV_SAMPLE_FMT_S32P,pcm_s24le_planar, "PCM signed 24-bit little-endian planar"); +PCM_CODEC (PCM_S24LE_PLANAR, AV_SAMPLE_FMT_S32P,pcm_s24le_planar, "PCM signed 24-bit little-endian planar"); PCM_CODEC (PCM_S32BE, AV_SAMPLE_FMT_S32, pcm_s32be, "PCM signed 32-bit big-endian"); PCM_CODEC (PCM_S32LE, AV_SAMPLE_FMT_S32, pcm_s32le, "PCM signed 32-bit little-endian"); -PCM_DECODER(PCM_S32LE_PLANAR, AV_SAMPLE_FMT_S32P,pcm_s32le_planar, "PCM signed 32-bit little-endian planar"); +PCM_CODEC (PCM_S32LE_PLANAR, AV_SAMPLE_FMT_S32P,pcm_s32le_planar, "PCM signed 32-bit little-endian planar"); PCM_CODEC (PCM_U8, AV_SAMPLE_FMT_U8, pcm_u8, "PCM unsigned 8-bit"); PCM_CODEC (PCM_U16BE, AV_SAMPLE_FMT_S16, pcm_u16be, "PCM unsigned 16-bit big-endian"); PCM_CODEC (PCM_U16LE, AV_SAMPLE_FMT_S16, pcm_u16le, "PCM unsigned 16-bit little-endian"); |