Commit 2fdf638b authored by Mike Melanson's avatar Mike Melanson

New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &

Video-1, Apple RPZA, Cinepak, Westwood IMA ADPCM

Originally committed as revision 2324 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent f2f6134b
......@@ -16,4 +16,6 @@ Michael Niedermayer
Franois Revol
Dieter Shirley
Juan J. Sierralta
Ewald Snel
Roberto Togni
Lionel Ulmer
version <next>:
- Microsoft RLE video decoder
- Microsoft Video-1 decoder
- Apple Video (RPZA) decoder
- Cinepak decoder
- Sega FILM (CPK) file demuxer
- Westwood multimedia support (VQA/AUD file demuxer, audio decoder)
version 0.4.8:
- MPEG2 video encoding (Michael)
......
......@@ -628,6 +628,10 @@ library:
@tab format used in various Interplay computer games
@item WC3 Movie @tab @tab X
@tab multimedia format used in Origin's Wing Commander III computer game
@item Sega FILM/CPK @tab @tab X
@tab used in many Sega Saturn console games
@item Westwood Studios VQA/AUD @tab @tab X
@tab Multimedia formats used in Westwood Studios games
@end multitable
@code{X} means that the encoding (resp. decoding) is supported.
......@@ -682,6 +686,10 @@ following image formats are supported:
@item Id RoQ @tab @tab X @tab used in Quake III, Jedi Knight 2, other computer games
@item Xan/WC3 @tab @tab X @tab used in Wing Commander III .MVE files
@item Interplay Video @tab @tab X @tab used in Interplay .MVE files
@item Apple Video @tab @tab X @tab fourcc: rpza
@item Cinepak @tab @tab X
@item Microsoft RLE @tab @tab X
@item Microsoft Video-1 @tab @tab X
@end multitable
@code{X} means that the encoding (resp. decoding) is supported.
......@@ -710,6 +718,8 @@ solutions.
@tab used in some Sega Saturn console games
@item Duck DK4 IMA ADPCM @tab @tab X
@tab used in some Sega Saturn console games
@item Westwood Studios IMA ADPCM @tab @tab X
@tab used in Westwood Studios games likes Command and Conquer
@item RA144 @tab @tab X
@tab Real 14400 bit/s codec
@item RA288 @tab @tab X
......
......@@ -17,7 +17,8 @@ OBJS= common.o utils.o mem.o allcodecs.o \
ratecontrol.o adpcm.o eval.o dv.o error_resilience.o \
fft.o mdct.o mace.o huffyuv.o cyuv.o opts.o raw.o h264.o golomb.o \
vp3.o asv1.o 4xm.o cabac.o ffv1.o ra144.o ra288.o vcr1.o cljr.o \
roqvideo.o dpcm.o interplayvideo.o xan.o
roqvideo.o dpcm.o interplayvideo.o xan.o rpza.o cinepak.o msrle.o \
msvideo1.o
ifeq ($(AMR_NB),yes)
ifeq ($(AMR_NB_FIXED),yes)
......
......@@ -22,7 +22,7 @@
* @file adpcm.c
* ADPCM codecs.
* First version by Francois Revol revol@free.fr
* Fringe ADPCM codecs (e.g., DK3 and DK4)
* Fringe ADPCM codecs (e.g., DK3, DK4, Westwood)
* by Mike Melanson (melanson@pcisys.net)
*
* Features and limitations:
......@@ -658,6 +658,25 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
*samples++ = c->status[0].predictor - c->status[1].predictor;
}
break;
case CODEC_ID_ADPCM_IMA_WS:
/* no per-block initialization; just start decoding the data */
while (src < buf + buf_size) {
if (st) {
*samples++ = adpcm_ima_expand_nibble(&c->status[0],
(src[0] >> 4) & 0x0F);
*samples++ = adpcm_ima_expand_nibble(&c->status[1],
src[0] & 0x0F);
} else {
*samples++ = adpcm_ima_expand_nibble(&c->status[0],
(src[0] >> 4) & 0x0F);
*samples++ = adpcm_ima_expand_nibble(&c->status[0],
src[0] & 0x0F);
}
src++;
}
break;
default:
*data_size = 0;
return -1;
......@@ -692,6 +711,7 @@ ADPCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
ADPCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
ADPCM_CODEC(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3);
ADPCM_CODEC(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4);
ADPCM_CODEC(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws);
ADPCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms);
ADPCM_CODEC(CODEC_ID_ADPCM_4XM, adpcm_4xm);
......
......@@ -123,6 +123,10 @@ void avcodec_register_all(void)
register_avcodec(&roq_decoder);
register_avcodec(&interplay_video_decoder);
register_avcodec(&xan_wc3_decoder);
register_avcodec(&rpza_decoder);
register_avcodec(&cinepak_decoder);
register_avcodec(&msrle_decoder);
register_avcodec(&msvideo1_decoder);
#ifdef CONFIG_AC3
register_avcodec(&ac3_decoder);
#endif
......@@ -163,6 +167,7 @@ PCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
PCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
PCM_CODEC(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3);
PCM_CODEC(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4);
PCM_CODEC(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws);
PCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms);
PCM_CODEC(CODEC_ID_ADPCM_4XM, adpcm_4xm);
......
......@@ -74,6 +74,11 @@ enum CodecID {
CODEC_ID_INTERPLAY_VIDEO,
CODEC_ID_XAN_WC3,
CODEC_ID_XAN_WC4,
CODEC_ID_RPZA,
CODEC_ID_CINEPAK,
CODEC_ID_WS_VQA,
CODEC_ID_MSRLE,
CODEC_ID_MSVIDEO1,
/* various pcm "codecs" */
CODEC_ID_PCM_S16LE,
......@@ -90,6 +95,7 @@ enum CodecID {
CODEC_ID_ADPCM_IMA_WAV,
CODEC_ID_ADPCM_IMA_DK3,
CODEC_ID_ADPCM_IMA_DK4,
CODEC_ID_ADPCM_IMA_WS,
CODEC_ID_ADPCM_MS,
CODEC_ID_ADPCM_4XM,
......@@ -1419,6 +1425,10 @@ extern AVCodec mdec_decoder;
extern AVCodec roq_decoder;
extern AVCodec interplay_video_decoder;
extern AVCodec xan_wc3_decoder;
extern AVCodec rpza_decoder;
extern AVCodec cinepak_decoder;
extern AVCodec msrle_decoder;
extern AVCodec msvideo1_decoder;
extern AVCodec ra_144_decoder;
extern AVCodec ra_288_decoder;
extern AVCodec roq_dpcm_decoder;
......@@ -1445,6 +1455,7 @@ PCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
PCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
PCM_CODEC(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3);
PCM_CODEC(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4);
PCM_CODEC(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws);
PCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms);
PCM_CODEC(CODEC_ID_ADPCM_4XM, adpcm_4xm);
......
/*
* Cinepak Video Decoder
* Copyright (C) 2003 the ffmpeg project
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/**
* @file cinepak.c
* Cinepak video decoder
* by Ewald Snel <ewald@rambo.its.tudelft.nl>
* For more information on the Cinepak algorithm, visit:
* http://www.csse.monash.edu.au/~timf/
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "common.h"
#include "avcodec.h"
#include "dsputil.h"
#define PALETTE_COUNT 256
#define BE_16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1])
#define BE_32(x) ((((uint8_t*)(x))[0] << 24) | \
(((uint8_t*)(x))[1] << 16) | \
(((uint8_t*)(x))[2] << 8) | \
((uint8_t*)(x))[3])
typedef struct {
uint8_t y0, y1, y2, y3;
uint8_t u, v;
} cvid_codebook_t;
#define MAX_STRIPS 32
typedef struct {
uint16_t id;
uint16_t x1, y1;
uint16_t x2, y2;
cvid_codebook_t v4_codebook[256];
cvid_codebook_t v1_codebook[256];
} cvid_strip_t;
typedef struct CinepakContext {
AVCodecContext *avctx;
DSPContext dsp;
AVFrame frame;
AVFrame prev_frame;
unsigned char *data;
int size;
unsigned char palette[PALETTE_COUNT * 4];
int palette_video;
cvid_strip_t strips[MAX_STRIPS];
} CinepakContext;
static void cinepak_decode_codebook (cvid_codebook_t *codebook,
int chunk_id, int size, uint8_t *data)
{
uint8_t *eod = (data + size);
uint32_t flag, mask;
int i, n;
/* check if this chunk contains 4- or 6-element vectors */
n = (chunk_id & 0x0400) ? 4 : 6;
flag = 0;
mask = 0;
for (i=0; i < 256; i++) {
if ((chunk_id & 0x0100) && !(mask >>= 1)) {
if ((data + 4) > eod)
break;
flag = BE_32 (data);
data += 4;
mask = 0x80000000;
}
if (!(chunk_id & 0x0100) || (flag & mask)) {
if ((data + n) > eod)
break;
if (n == 6) {
codebook[i].y0 = *data++;
codebook[i].y1 = *data++;
codebook[i].y2 = *data++;
codebook[i].y3 = *data++;
codebook[i].u = 128 + *data++;
codebook[i].v = 128 + *data++;
} else {
/* this codebook type indicates either greyscale or
* palettized video; if palettized, U & V components will
* not be used so it is safe to set them to 128 for the
* benefit of greyscale rendering in YUV420P */
codebook[i].y0 = *data++;
codebook[i].y1 = *data++;
codebook[i].y2 = *data++;
codebook[i].y3 = *data++;
codebook[i].u = 128;
codebook[i].v = 128;
}
}
}
}
static int cinepak_decode_vectors (CinepakContext *s, cvid_strip_t *strip,
int chunk_id, int size, uint8_t *data)
{
uint8_t *eod = (data + size);
uint32_t flag, mask;
cvid_codebook_t *codebook;
unsigned int i, j, x, y;
uint32_t iy[4];
uint32_t iu[2];
uint32_t iv[2];
flag = 0;
mask = 0;
for (y=strip->y1; y < strip->y2; y+=4) {
iy[0] = strip->x1 + (y * s->frame.linesize[0]);
iy[1] = iy[0] + s->frame.linesize[0];
iy[2] = iy[1] + s->frame.linesize[0];
iy[3] = iy[2] + s->frame.linesize[0];
iu[0] = (strip->x1/2) + ((y/2) * s->frame.linesize[1]);
iu[1] = iu[0] + s->frame.linesize[1];
iv[0] = (strip->x1/2) + ((y/2) * s->frame.linesize[2]);
iv[1] = iv[0] + s->frame.linesize[2];
for (x=strip->x1; x < strip->x2; x+=4) {
if ((chunk_id & 0x0100) && !(mask >>= 1)) {
if ((data + 4) > eod)
return -1;
flag = BE_32 (data);
data += 4;
mask = 0x80000000;
}
if (!(chunk_id & 0x0100) || (flag & mask)) {
if (!(chunk_id & 0x0200) && !(mask >>= 1)) {
if ((data + 4) > eod)
return -1;
flag = BE_32 (data);
data += 4;
mask = 0x80000000;
}
if ((chunk_id & 0x0200) || (~flag & mask)) {
if (data >= eod)
return -1;
codebook = &strip->v1_codebook[*data++];
s->frame.data[0][iy[0] + 0] = codebook->y0;
s->frame.data[0][iy[0] + 1] = codebook->y0;
s->frame.data[0][iy[1] + 0] = codebook->y0;
s->frame.data[0][iy[1] + 1] = codebook->y0;
if (!s->palette_video) {
s->frame.data[1][iu[0]] = codebook->u;
s->frame.data[2][iv[0]] = codebook->v;
}
s->frame.data[0][iy[0] + 2] = codebook->y0;
s->frame.data[0][iy[0] + 3] = codebook->y0;
s->frame.data[0][iy[1] + 2] = codebook->y0;
s->frame.data[0][iy[1] + 3] = codebook->y0;
if (!s->palette_video) {
s->frame.data[1][iu[0] + 1] = codebook->u;
s->frame.data[2][iv[0] + 1] = codebook->v;
}
s->frame.data[0][iy[2] + 0] = codebook->y0;
s->frame.data[0][iy[2] + 1] = codebook->y0;
s->frame.data[0][iy[3] + 0] = codebook->y0;
s->frame.data[0][iy[3] + 1] = codebook->y0;
if (!s->palette_video) {
s->frame.data[1][iu[1]] = codebook->u;
s->frame.data[2][iv[1]] = codebook->v;
}
s->frame.data[0][iy[2] + 2] = codebook->y0;
s->frame.data[0][iy[2] + 3] = codebook->y0;
s->frame.data[0][iy[3] + 2] = codebook->y0;
s->frame.data[0][iy[3] + 3] = codebook->y0;
if (!s->palette_video) {
s->frame.data[1][iu[1] + 1] = codebook->u;
s->frame.data[2][iv[1] + 1] = codebook->v;
}
} else if (flag & mask) {
if ((data + 4) > eod)
return -1;
codebook = &strip->v4_codebook[*data++];
s->frame.data[0][iy[0] + 0] = codebook->y0;
s->frame.data[0][iy[0] + 1] = codebook->y1;
s->frame.data[0][iy[1] + 0] = codebook->y2;
s->frame.data[0][iy[1] + 1] = codebook->y3;
if (!s->palette_video) {
s->frame.data[1][iu[0]] = codebook->u;
s->frame.data[2][iv[0]] = codebook->v;
}
codebook = &strip->v4_codebook[*data++];
s->frame.data[0][iy[0] + 2] = codebook->y0;
s->frame.data[0][iy[0] + 3] = codebook->y1;
s->frame.data[0][iy[1] + 2] = codebook->y2;
s->frame.data[0][iy[1] + 3] = codebook->y3;
if (!s->palette_video) {
s->frame.data[1][iu[0] + 1] = codebook->u;
s->frame.data[2][iv[0] + 1] = codebook->v;
}
codebook = &strip->v4_codebook[*data++];
s->frame.data[0][iy[2] + 0] = codebook->y0;
s->frame.data[0][iy[2] + 1] = codebook->y1;
s->frame.data[0][iy[3] + 0] = codebook->y2;
s->frame.data[0][iy[3] + 1] = codebook->y3;
if (!s->palette_video) {
s->frame.data[1][iu[1]] = codebook->u;
s->frame.data[2][iv[1]] = codebook->v;
}
codebook = &strip->v4_codebook[*data++];
s->frame.data[0][iy[2] + 2] = codebook->y0;
s->frame.data[0][iy[2] + 3] = codebook->y1;
s->frame.data[0][iy[3] + 2] = codebook->y2;
s->frame.data[0][iy[3] + 3] = codebook->y3;
if (!s->palette_video) {
s->frame.data[1][iu[1] + 1] = codebook->u;
s->frame.data[2][iv[1] + 1] = codebook->v;
}
}
} else {
/* copy from the previous frame */
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
s->frame.data[0][iy[i] + j] =
s->prev_frame.data[0][iy[i] + j];
}
}
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
s->frame.data[1][iu[i] + j] =
s->prev_frame.data[1][iu[i] + j];
s->frame.data[2][iv[i] + j] =
s->prev_frame.data[2][iv[i] + j];
}
}
}
iy[0] += 4; iy[1] += 4;
iy[2] += 4; iy[3] += 4;
iu[0] += 2; iu[1] += 2;
iv[0] += 2; iv[1] += 2;
}
}
return 0;
}
static int cinepak_decode_strip (CinepakContext *s,
cvid_strip_t *strip, uint8_t *data, int size)
{
uint8_t *eod = (data + size);
int chunk_id, chunk_size;
/* coordinate sanity checks */
if (strip->x1 >= s->avctx->width || strip->x2 > s->avctx->width ||
strip->y1 >= s->avctx->height || strip->y2 > s->avctx->height ||
strip->x1 >= strip->x2 || strip->y1 >= strip->y2)
return -1;
while ((data + 4) <= eod) {
chunk_id = BE_16 (&data[0]);
chunk_size = BE_16 (&data[2]) - 4;
data += 4;
chunk_size = ((data + chunk_size) > eod) ? (eod - data) : chunk_size;
switch (chunk_id) {
case 0x2000:
case 0x2100:
case 0x2400:
case 0x2500:
cinepak_decode_codebook (strip->v4_codebook, chunk_id,
chunk_size, data);
break;
case 0x2200:
case 0x2300:
case 0x2600:
case 0x2700:
cinepak_decode_codebook (strip->v1_codebook, chunk_id,
chunk_size, data);
break;
case 0x3000:
case 0x3100:
case 0x3200:
return cinepak_decode_vectors (s, strip, chunk_id,
chunk_size, data);
}
data += chunk_size;
}
return -1;
}
static int cinepak_decode (CinepakContext *s)
{
uint8_t *eod = (s->data + s->size);
int i, result, strip_size, frame_flags, num_strips;
int y0 = 0;
if (s->size < 10)
return -1;
frame_flags = s->data[0];
num_strips = BE_16 (&s->data[8]);
s->data += 10;
if (num_strips > MAX_STRIPS)
num_strips = MAX_STRIPS;
for (i=0; i < num_strips; i++) {
if ((s->data + 12) > eod)
return -1;
s->strips[i].id = BE_16 (s->data);
s->strips[i].y1 = y0;
s->strips[i].x1 = 0;
s->strips[i].y2 = y0 + BE_16 (&s->data[8]);
s->strips[i].x2 = s->avctx->width;
strip_size = BE_16 (&s->data[2]) - 12;
s->data += 12;
strip_size = ((s->data + strip_size) > eod) ? (eod - s->data) : strip_size;
if ((i > 0) && !(frame_flags & 0x01)) {
memcpy (s->strips[i].v4_codebook, s->strips[i-1].v4_codebook,
sizeof(s->strips[i].v4_codebook));
memcpy (s->strips[i].v1_codebook, s->strips[i-1].v1_codebook,
sizeof(s->strips[i].v1_codebook));
}
result = cinepak_decode_strip (s, &s->strips[i], s->data, strip_size);
if (result != 0)
return result;
s->data += strip_size;
y0 = s->strips[i].y2;
}
return 0;
}
static int cinepak_decode_init(AVCodecContext *avctx)
{
CinepakContext *s = (CinepakContext *)avctx->priv_data;
/*
int i;
unsigned char r, g, b;
unsigned char *raw_palette;
unsigned int *palette32;
*/
s->avctx = avctx;
// check for paletted data
s->palette_video = 0;
avctx->pix_fmt = PIX_FMT_YUV420P;
avctx->has_b_frames = 0;
dsputil_init(&s->dsp, avctx);
s->frame.data[0] = s->prev_frame.data[0] = NULL;
return 0;
}
static int cinepak_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
uint8_t *buf, int buf_size)
{
CinepakContext *s = (CinepakContext *)avctx->priv_data;
s->data = buf;
s->size = buf_size;
if (avctx->get_buffer(avctx, &s->frame)) {
printf (" Cinepak: get_buffer() failed\n");
return -1;
}
cinepak_decode(s);
if (s->prev_frame.data[0])
avctx->release_buffer(avctx, &s->prev_frame);
/* shuffle frames */
s->prev_frame = s->frame;
*data_size = sizeof(AVFrame);
*(AVFrame*)data = s->frame;
/* report that the buffer was completely consumed */
return buf_size;
}
static int cinepak_decode_end(AVCodecContext *avctx)
{
CinepakContext *s = (CinepakContext *)avctx->priv_data;
if (s->prev_frame.data[0])
avctx->release_buffer(avctx, &s->prev_frame);