8svx: use planar sample format

This commit is contained in:
Justin Ruggles 2012-08-27 12:01:16 -04:00
parent fd41cb4370
commit cf8c93ada4

View File

@ -58,30 +58,25 @@ static const int8_t exponential[16] = { -128, -64, -32, -16, -8, -4, -2, -1,
* @param[in,out] state starting value. it is saved for use in the next call. * @param[in,out] state starting value. it is saved for use in the next call.
*/ */
static void delta_decode(uint8_t *dst, const uint8_t *src, int src_size, static void delta_decode(uint8_t *dst, const uint8_t *src, int src_size,
uint8_t *state, const int8_t *table, int channels) uint8_t *state, const int8_t *table)
{ {
uint8_t val = *state; uint8_t val = *state;
while (src_size--) { while (src_size--) {
uint8_t d = *src++; uint8_t d = *src++;
val = av_clip_uint8(val + table[d & 0xF]); val = av_clip_uint8(val + table[d & 0xF]);
*dst = val; *dst++ = val;
dst += channels;
val = av_clip_uint8(val + table[d >> 4]); val = av_clip_uint8(val + table[d >> 4]);
*dst = val; *dst++ = val;
dst += channels;
} }
*state = val; *state = val;
} }
static void raw_decode(uint8_t *dst, const int8_t *src, int src_size, static void raw_decode(uint8_t *dst, const int8_t *src, int src_size)
int channels)
{ {
while (src_size--) { while (src_size--)
*dst = *src++ + 128; *dst++ = *src++ + 128;
dst += channels;
}
} }
/** decode a frame */ /** decode a frame */
@ -90,8 +85,7 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
{ {
EightSvxContext *esc = avctx->priv_data; EightSvxContext *esc = avctx->priv_data;
int buf_size; int buf_size;
uint8_t *out_data; int ch, ret;
int ret;
int is_compr = (avctx->codec_id != AV_CODEC_ID_PCM_S8_PLANAR); int is_compr = (avctx->codec_id != AV_CODEC_ID_PCM_S8_PLANAR);
/* for the first packet, copy data to buffer */ /* for the first packet, copy data to buffer */
@ -146,22 +140,17 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret; return ret;
} }
out_data = esc->frame.data[0];
if (is_compr) { for (ch = 0; ch < avctx->channels; ch++) {
delta_decode(out_data, &esc->data[0][esc->data_idx], buf_size, if (is_compr) {
&esc->fib_acc[0], esc->table, avctx->channels); delta_decode(esc->frame.data[ch], &esc->data[ch][esc->data_idx],
if (avctx->channels == 2) { buf_size, &esc->fib_acc[ch], esc->table);
delta_decode(&out_data[1], &esc->data[1][esc->data_idx], buf_size, } else {
&esc->fib_acc[1], esc->table, avctx->channels); raw_decode(esc->frame.data[ch], &esc->data[ch][esc->data_idx],
} buf_size);
} else {
int ch;
for (ch = 0; ch < avctx->channels; ch++) {
raw_decode((int8_t *)&out_data[ch], &esc->data[ch][esc->data_idx],
buf_size, avctx->channels);
} }
} }
esc->data_idx += buf_size; esc->data_idx += buf_size;
*got_frame_ptr = 1; *got_frame_ptr = 1;
@ -192,7 +181,7 @@ static av_cold int eightsvx_decode_init(AVCodecContext *avctx)
default: default:
return -1; return -1;
} }
avctx->sample_fmt = AV_SAMPLE_FMT_U8; avctx->sample_fmt = AV_SAMPLE_FMT_U8P;
avcodec_get_frame_defaults(&esc->frame); avcodec_get_frame_defaults(&esc->frame);
avctx->coded_frame = &esc->frame; avctx->coded_frame = &esc->frame;
@ -220,6 +209,8 @@ AVCodec ff_eightsvx_fib_decoder = {
.decode = eightsvx_decode_frame, .decode = eightsvx_decode_frame,
.capabilities = CODEC_CAP_DELAY | CODEC_CAP_DR1, .capabilities = CODEC_CAP_DELAY | CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("8SVX fibonacci"), .long_name = NULL_IF_CONFIG_SMALL("8SVX fibonacci"),
.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_U8P,
AV_SAMPLE_FMT_NONE },
}; };
AVCodec ff_eightsvx_exp_decoder = { AVCodec ff_eightsvx_exp_decoder = {
@ -232,6 +223,8 @@ AVCodec ff_eightsvx_exp_decoder = {
.decode = eightsvx_decode_frame, .decode = eightsvx_decode_frame,
.capabilities = CODEC_CAP_DELAY | CODEC_CAP_DR1, .capabilities = CODEC_CAP_DELAY | CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("8SVX exponential"), .long_name = NULL_IF_CONFIG_SMALL("8SVX exponential"),
.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_U8P,
AV_SAMPLE_FMT_NONE },
}; };
AVCodec ff_pcm_s8_planar_decoder = { AVCodec ff_pcm_s8_planar_decoder = {
@ -244,4 +237,6 @@ AVCodec ff_pcm_s8_planar_decoder = {
.decode = eightsvx_decode_frame, .decode = eightsvx_decode_frame,
.capabilities = CODEC_CAP_DELAY | CODEC_CAP_DR1, .capabilities = CODEC_CAP_DELAY | CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("PCM signed 8-bit planar"), .long_name = NULL_IF_CONFIG_SMALL("PCM signed 8-bit planar"),
.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_U8P,
AV_SAMPLE_FMT_NONE },
}; };