*/
#include "avcodec.h"
+#include "internal.h"
+#include "libavutil/common.h"
/** decoder context */
typedef struct EightSvxContext {
- AVFrame frame;
uint8_t fib_acc[2];
const int8_t *table;
* @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,
- uint8_t *state, const int8_t *table, int channels)
+ uint8_t *state, const int8_t *table)
{
uint8_t val = *state;
while (src_size--) {
uint8_t d = *src++;
val = av_clip_uint8(val + table[d & 0xF]);
- *dst = val;
- dst += channels;
+ *dst++ = val;
val = av_clip_uint8(val + table[d >> 4]);
- *dst = val;
- dst += channels;
+ *dst++ = val;
}
*state = val;
}
-static void raw_decode(uint8_t *dst, const int8_t *src, int src_size,
- int channels)
+static void raw_decode(uint8_t *dst, const int8_t *src, int src_size)
{
- while (src_size--) {
- *dst = *src++ + 128;
- dst += channels;
- }
+ while (src_size--)
+ *dst++ = *src++ + 128;
}
/** decode a frame */
int *got_frame_ptr, AVPacket *avpkt)
{
EightSvxContext *esc = avctx->priv_data;
+ AVFrame *frame = data;
int buf_size;
- uint8_t *out_data;
- int ret;
- int is_compr = (avctx->codec_id != CODEC_ID_PCM_S8_PLANAR);
+ int ch, ret;
+ int is_compr = (avctx->codec_id != AV_CODEC_ID_PCM_S8_PLANAR);
/* for the first packet, copy data to buffer */
if (avpkt->data) {
}
/* get output buffer */
- esc->frame.nb_samples = buf_size * (is_compr + 1);
- if ((ret = avctx->get_buffer(avctx, &esc->frame)) < 0) {
+ frame->nb_samples = buf_size * (is_compr + 1);
+ if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret;
}
- out_data = esc->frame.data[0];
-
- if (is_compr) {
- delta_decode(out_data, &esc->data[0][esc->data_idx], buf_size,
- &esc->fib_acc[0], esc->table, avctx->channels);
- if (avctx->channels == 2) {
- delta_decode(&out_data[1], &esc->data[1][esc->data_idx], buf_size,
- &esc->fib_acc[1], esc->table, avctx->channels);
- }
- } 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);
+
+ for (ch = 0; ch < avctx->channels; ch++) {
+ if (is_compr) {
+ delta_decode(frame->data[ch], &esc->data[ch][esc->data_idx],
+ buf_size, &esc->fib_acc[ch], esc->table);
+ } else {
+ raw_decode(frame->data[ch], &esc->data[ch][esc->data_idx],
+ buf_size);
}
}
+
esc->data_idx += buf_size;
- *got_frame_ptr = 1;
- *(AVFrame *)data = esc->frame;
+ *got_frame_ptr = 1;
return avpkt->size;
}
}
switch(avctx->codec->id) {
- case CODEC_ID_8SVX_FIB:
+ case AV_CODEC_ID_8SVX_FIB:
esc->table = fibonacci;
break;
- case CODEC_ID_8SVX_EXP:
+ case AV_CODEC_ID_8SVX_EXP:
esc->table = exponential;
break;
- case CODEC_ID_PCM_S8_PLANAR:
+ case AV_CODEC_ID_PCM_S8_PLANAR:
break;
default:
return -1;
}
- avctx->sample_fmt = AV_SAMPLE_FMT_U8;
-
- avcodec_get_frame_defaults(&esc->frame);
- avctx->coded_frame = &esc->frame;
+ avctx->sample_fmt = AV_SAMPLE_FMT_U8P;
return 0;
}
AVCodec ff_eightsvx_fib_decoder = {
.name = "8svx_fib",
+ .long_name = NULL_IF_CONFIG_SMALL("8SVX fibonacci"),
.type = AVMEDIA_TYPE_AUDIO,
- .id = CODEC_ID_8SVX_FIB,
+ .id = AV_CODEC_ID_8SVX_FIB,
.priv_data_size = sizeof (EightSvxContext),
.init = eightsvx_decode_init,
.close = eightsvx_decode_close,
.decode = eightsvx_decode_frame,
.capabilities = CODEC_CAP_DELAY | CODEC_CAP_DR1,
- .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 = {
.name = "8svx_exp",
+ .long_name = NULL_IF_CONFIG_SMALL("8SVX exponential"),
.type = AVMEDIA_TYPE_AUDIO,
- .id = CODEC_ID_8SVX_EXP,
+ .id = AV_CODEC_ID_8SVX_EXP,
.priv_data_size = sizeof (EightSvxContext),
.init = eightsvx_decode_init,
.close = eightsvx_decode_close,
.decode = eightsvx_decode_frame,
.capabilities = CODEC_CAP_DELAY | CODEC_CAP_DR1,
- .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 = {
.name = "pcm_s8_planar",
+ .long_name = NULL_IF_CONFIG_SMALL("PCM signed 8-bit planar"),
.type = AVMEDIA_TYPE_AUDIO,
- .id = CODEC_ID_PCM_S8_PLANAR,
+ .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_DELAY | 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 },
};