From da8242e2d6f85d95239082efd0e5e2345e685a2c Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Sun, 18 Nov 2012 18:50:57 +0000 Subject: [PATCH] 8svx: move pcm_s8_planar decoder to pcm.c Removes limitation of max 2 channels for pcm_s8_planar decoder by moving it to more natural place. AV_CODEC_ID_8SVX_RAW is not used by anything anymore and is going to be removed. Signed-off-by: Paul B Mahol --- libavcodec/8svx.c | 45 +++++++-------------------------------------- libavcodec/Makefile | 2 +- libavcodec/pcm.c | 10 ++++++++++ libavcodec/utils.c | 1 + 4 files changed, 19 insertions(+), 39 deletions(-) diff --git a/libavcodec/8svx.c b/libavcodec/8svx.c index 698ddd0f14..618ae872cc 100644 --- a/libavcodec/8svx.c +++ b/libavcodec/8svx.c @@ -82,12 +82,6 @@ static void delta_decode(uint8_t *dst, const uint8_t *src, int src_size, *state = val; } -static void raw_decode(uint8_t *dst, const int8_t *src, int src_size) -{ - while (src_size--) - *dst++ = *src++ + 128; -} - /** decode a frame */ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) @@ -95,8 +89,7 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, EightSvxContext *esc = avctx->priv_data; int buf_size; int ch, ret; - int is_compr = (avctx->codec_id != AV_CODEC_ID_PCM_S8_PLANAR); - int hdr_size = is_compr ? 2 : 0; + int hdr_size = 2; /* decode and interleave the first packet */ if (!esc->data[0] && avpkt) { @@ -110,11 +103,9 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, return AVERROR(EINVAL); } - if (is_compr) { - esc->fib_acc[0] = avpkt->data[1] + 128; - if (avctx->channels == 2) - esc->fib_acc[1] = avpkt->data[2+chan_size+1] + 128; - } + esc->fib_acc[0] = avpkt->data[1] + 128; + if (avctx->channels == 2) + esc->fib_acc[1] = avpkt->data[2+chan_size+1] + 128; esc->data_idx = 0; esc->data_size = chan_size; @@ -143,20 +134,15 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, } /* get output buffer */ - esc->frame.nb_samples = buf_size * (is_compr + 1); + esc->frame.nb_samples = buf_size * 2; if ((ret = avctx->get_buffer(avctx, &esc->frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } for (ch = 0; ch < avctx->channels; ch++) { - if (is_compr) { - delta_decode(esc->frame.data[ch], &esc->data[ch][esc->data_idx], - buf_size, &esc->fib_acc[ch], esc->table); - } else { - raw_decode(esc->frame.data[ch], &esc->data[ch][esc->data_idx], - buf_size); - } + delta_decode(esc->frame.data[ch], &esc->data[ch][esc->data_idx], + buf_size, &esc->fib_acc[ch], esc->table); } esc->data_idx += buf_size; @@ -179,8 +165,6 @@ static av_cold int eightsvx_decode_init(AVCodecContext *avctx) switch (avctx->codec->id) { case AV_CODEC_ID_8SVX_FIB: esc->table = fibonacci; break; case AV_CODEC_ID_8SVX_EXP: esc->table = exponential; break; - case AV_CODEC_ID_PCM_S8_PLANAR: - case AV_CODEC_ID_8SVX_RAW: esc->table = NULL; break; default: av_log(avctx, AV_LOG_ERROR, "Invalid codec id %d.\n", avctx->codec->id); return AVERROR_INVALIDDATA; @@ -235,18 +219,3 @@ AVCodec ff_eightsvx_exp_decoder = { AV_SAMPLE_FMT_NONE }, }; #endif -#if CONFIG_PCM_S8_PLANAR_DECODER -AVCodec ff_pcm_s8_planar_decoder = { - .name = "pcm_s8_planar", - .type = AVMEDIA_TYPE_AUDIO, - .id = AV_CODEC_ID_PCM_S8_PLANAR, - .priv_data_size = sizeof(EightSvxContext), - .init = eightsvx_decode_init, - .close = eightsvx_decode_close, - .decode = eightsvx_decode_frame, - .capabilities = CODEC_CAP_DR1, - .long_name = NULL_IF_CONFIG_SMALL("PCM signed 8-bit planar"), - .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_U8P, - AV_SAMPLE_FMT_NONE }, -}; -#endif diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 7b3462e3c2..5945332ef1 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -521,7 +521,7 @@ OBJS-$(CONFIG_PCM_MULAW_DECODER) += pcm.o OBJS-$(CONFIG_PCM_MULAW_ENCODER) += pcm.o OBJS-$(CONFIG_PCM_S8_DECODER) += pcm.o OBJS-$(CONFIG_PCM_S8_ENCODER) += pcm.o -OBJS-$(CONFIG_PCM_S8_PLANAR_DECODER) += 8svx.o +OBJS-$(CONFIG_PCM_S8_PLANAR_DECODER) += pcm.o OBJS-$(CONFIG_PCM_S16BE_DECODER) += pcm.o OBJS-$(CONFIG_PCM_S16BE_ENCODER) += pcm.o OBJS-$(CONFIG_PCM_S16BE_PLANAR_DECODER) += pcm.o diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c index d91113d781..36385f7e99 100644 --- a/libavcodec/pcm.c +++ b/libavcodec/pcm.c @@ -376,6 +376,15 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data, for (; n > 0; n--) *samples++ = *src++ + 128; break; + case AV_CODEC_ID_PCM_S8_PLANAR: + n /= avctx->channels; + for (c = 0; c < avctx->channels; c++) { + int i; + samples = s->frame.extended_data[c]; + for (i = n; i > 0; i--) + *samples++ = *src++ + 128; + } + break; #if HAVE_BIGENDIAN case AV_CODEC_ID_PCM_F64LE: DECODE(64, le64, src, samples, n, 0, 0) @@ -548,6 +557,7 @@ 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_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_S16LE, AV_SAMPLE_FMT_S16, pcm_s16le, "PCM signed 16-bit little-endian"); diff --git a/libavcodec/utils.c b/libavcodec/utils.c index a4df3f3548..b117271b40 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -2307,6 +2307,7 @@ int av_get_exact_bits_per_sample(enum AVCodecID codec_id) case AV_CODEC_ID_PCM_ALAW: case AV_CODEC_ID_PCM_MULAW: case AV_CODEC_ID_PCM_S8: + case AV_CODEC_ID_PCM_S8_PLANAR: case AV_CODEC_ID_PCM_U8: case AV_CODEC_ID_PCM_ZORK: return 8;