*/
/**
- * @file mace.c
+ * @file
* MACE decoder.
*/
{
if (avctx->channels > 2)
return -1;
- avctx->sample_fmt = SAMPLE_FMT_S16;
+ avctx->sample_fmt = AV_SAMPLE_FMT_S16;
return 0;
}
-static int mace3_decode_frame(AVCodecContext *avctx,
+static int mace_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
- const uint8_t *buf, int buf_size)
+ AVPacket *avpkt)
{
+ const uint8_t *buf = avpkt->data;
+ int buf_size = avpkt->size;
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;
}
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;
}
-AVCodec mace3_decoder = {
+AVCodec ff_mace3_decoder = {
"mace3",
- CODEC_TYPE_AUDIO,
+ AVMEDIA_TYPE_AUDIO,
CODEC_ID_MACE3,
sizeof(MACEContext),
mace_decode_init,
NULL,
NULL,
- mace3_decode_frame,
+ mace_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("MACE (Macintosh Audio Compression/Expansion) 3:1"),
};
-AVCodec mace6_decoder = {
+AVCodec ff_mace6_decoder = {
"mace6",
- CODEC_TYPE_AUDIO,
+ AVMEDIA_TYPE_AUDIO,
CODEC_ID_MACE6,
sizeof(MACEContext),
mace_decode_init,
NULL,
NULL,
- mace6_decode_frame,
+ mace_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("MACE (Macintosh Audio Compression/Expansion) 6:1"),
};