[FFmpeg-cvslog] r15568 - trunk/libavcodec/mace.c
vitor
subversion
Sun Oct 5 22:06:41 CEST 2008
Author: vitor
Date: Sun Oct 5 22:06:40 2008
New Revision: 15568
Log:
Avoid code duplication between mace3_decode_frame() and mace6_decode_frame()
Modified:
trunk/libavcodec/mace.c
Modified: trunk/libavcodec/mace.c
==============================================================================
--- trunk/libavcodec/mace.c (original)
+++ trunk/libavcodec/mace.c Sun Oct 5 22:06:40 2008
@@ -241,8 +241,9 @@ static int mace3_decode_frame(AVCodecCon
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(AVCodecCon
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 (l=0; l < 3; l++) {
- chomp3(&ctx->chd[i], output, val[l], l, avctx->channels);
- output += avctx->channels;
- }
- }
- }
-
- *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 (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];
- for(i = 0; i < avctx->channels; i++) {
- int16_t *output = samples + i;
+ uint8_t val[2][3] = {{pkt >> 5, (pkt >> 3) & 3, pkt & 7 },
+ {pkt & 7 , (pkt >> 3) & 3, pkt >> 5}};
- 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++) {
+ 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);
- for (l=0; l < 3; l++) {
- chomp6(&ctx->chd[i], output, val[l], l, avctx->channels);
- output += avctx->channels << 1;
+ output += avctx->channels << (1-is_mace3);
+ }
}
- }
}
- *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"),
};
More information about the ffmpeg-cvslog
mailing list