Commit 10c1d192 authored by Vitor Sessak's avatar Vitor Sessak

Avoid code duplication between mace3_decode_frame() and mace6_decode_frame()

Originally committed as revision 15568 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 0093396c
......@@ -241,8 +241,9 @@ static int mace3_decode_frame(AVCodecContext *avctx,
int16_t *samples = data;
MACEContext *ctx = avctx->priv_data;
int i, j, k, l;
int is_mace3 = (avctx->codec_id == CODEC_ID_MACE3);
if (*data_size < 2 * 3 * buf_size) {
if (*data_size < (3 * buf_size << (2-is_mace3))) {
av_log(avctx, AV_LOG_ERROR, "Output buffer too small!\n");
return -1;
}
......@@ -250,51 +251,28 @@ static int mace3_decode_frame(AVCodecContext *avctx,
for(i = 0; i < avctx->channels; i++) {
int16_t *output = samples + i;
for (j=0; j < buf_size / 2 / avctx->channels; j++)
for (k=0; k < 2; k++) {
uint8_t pkt = buf[i*2 + j*2*avctx->channels + k];
uint8_t val[3] = {pkt & 7, (pkt >> 3) & 3, pkt >> 5};
for (j=0; j < buf_size / (avctx->channels << is_mace3); j++)
for (k=0; k < (1 << is_mace3); k++) {
uint8_t pkt = buf[(i << is_mace3) +
(j*avctx->channels << is_mace3) + k];
uint8_t val[2][3] = {{pkt >> 5, (pkt >> 3) & 3, pkt & 7 },
{pkt & 7 , (pkt >> 3) & 3, pkt >> 5}};
for (l=0; l < 3; l++) {
chomp3(&ctx->chd[i], output, val[l], l, avctx->channels);
output += avctx->channels;
if (is_mace3)
chomp3(&ctx->chd[i], output, val[1][l], l,
avctx->channels);
else
chomp6(&ctx->chd[i], output, val[0][l], l,
avctx->channels);
output += avctx->channels << (1-is_mace3);
}
}
}
*data_size = 2 * 3 * buf_size;
return buf_size;
}
static int mace6_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
const uint8_t *buf, int buf_size)
{
int16_t *samples = data;
MACEContext *ctx = avctx->priv_data;
int i, j, l;
if (*data_size < 2 * 6 * buf_size) {
av_log(avctx, AV_LOG_ERROR, "Output buffer too small!\n");
return -1;
}
for(i = 0; i < avctx->channels; i++) {
int16_t *output = samples + i;
for (j = 0; j < buf_size / avctx->channels; j++) {
uint8_t pkt = buf[i + j*avctx->channels];
uint8_t val[3] = {pkt >> 5, (pkt >> 3) & 3, pkt & 7};
for (l=0; l < 3; l++) {
chomp6(&ctx->chd[i], output, val[l], l, avctx->channels);
output += avctx->channels << 1;
}
}
}
*data_size = 2 * 6 * buf_size;
*data_size = 3 * buf_size << (2-is_mace3);
return buf_size;
}
......@@ -319,7 +297,7 @@ AVCodec mace6_decoder = {
mace_decode_init,
NULL,
NULL,
mace6_decode_frame,
mace3_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("MACE (Macintosh Audio Compression/Expansion) 6:1"),
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment