summaryrefslogtreecommitdiff
path: root/libavcodec/mace.c
diff options
context:
space:
mode:
authorVitor Sessak <vitor1001@gmail.com>2008-10-05 20:06:40 +0000
committerVitor Sessak <vitor1001@gmail.com>2008-10-05 20:06:40 +0000
commit10c1d19212c2e74c9eae915defee4948f9a6be02 (patch)
tree3efe0ce1a932571e2a3efd24519fc5ff8c9e9bac /libavcodec/mace.c
parent0093396cff8ffa2d7e20621abf7b62f8018dd1f1 (diff)
Avoid code duplication between mace3_decode_frame() and mace6_decode_frame()
Originally committed as revision 15568 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/mace.c')
-rw-r--r--libavcodec/mace.c60
1 files changed, 19 insertions, 41 deletions
diff --git a/libavcodec/mace.c b/libavcodec/mace.c
index 423575374c..94646106c3 100644
--- a/libavcodec/mace.c
+++ b/libavcodec/mace.c
@@ -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"),
};