Mercurial > libavcodec.hg
changeset 8001:038bb3b45b34 libavcodec
Avoid code duplication between mace3_decode_frame() and mace6_decode_frame()
author | vitor |
---|---|
date | Sun, 05 Oct 2008 20:06:40 +0000 |
parents | 5ef823d919d5 |
children | f94fb6a31d5c |
files | mace.c |
diffstat | 1 files changed, 19 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/mace.c Sun Oct 05 16:33:43 2008 +0000 +++ b/mace.c Sun Oct 05 20:06:40 2008 +0000 @@ -241,8 +241,9 @@ 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 @@ 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 @@ mace_decode_init, NULL, NULL, - mace6_decode_frame, + mace3_decode_frame, .long_name = NULL_IF_CONFIG_SMALL("MACE (Macintosh Audio Compression/Expansion) 6:1"), };