Commit 3ef8be2b authored by Mike Melanson's avatar Mike Melanson

initial commit for Id RoQ and Interplay MVE multimedia subsystems

Originally committed as revision 2195 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 149f7c02
......@@ -17,7 +17,8 @@ OBJS= common.o utils.o mem.o allcodecs.o \
mpeg12.o mpegaudiodec.o pcm.o simple_idct.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
vp3.o asv1.o 4xm.o cabac.o ffv1.o ra144.o ra288.o vcr1.o cljr.o \
roqvideo.o dpcm.o interplayvideo.o
ifeq ($(AMR_NB),yes)
ifeq ($(AMR_NB_FIXED),yes)
......
......@@ -121,11 +121,15 @@ void avcodec_register_all(void)
register_avcodec(&cljr_decoder);
register_avcodec(&fourxm_decoder);
register_avcodec(&mdec_decoder);
register_avcodec(&roq_decoder);
register_avcodec(&interplay_video_decoder);
#ifdef CONFIG_AC3
register_avcodec(&ac3_decoder);
#endif
register_avcodec(&ra_144_decoder);
register_avcodec(&ra_288_decoder);
register_avcodec(&roq_dpcm_decoder);
register_avcodec(&interplay_dpcm_decoder);
#endif /* CONFIG_DECODERS */
#ifdef AMR_NB
......
......@@ -66,6 +66,8 @@ enum CodecID {
CODEC_ID_VCR1,
CODEC_ID_CLJR,
CODEC_ID_MDEC,
CODEC_ID_ROQ,
CODEC_ID_INTERPLAY_VIDEO,
/* various pcm "codecs" */
CODEC_ID_PCM_S16LE,
......@@ -88,6 +90,10 @@ enum CodecID {
/* RealAudio codecs*/
CODEC_ID_RA_144,
CODEC_ID_RA_288,
/* various DPCM codecs */
CODEC_ID_ROQ_DPCM,
CODEC_ID_INTERPLAY_DPCM,
};
enum CodecType {
......@@ -1347,8 +1353,12 @@ extern AVCodec cljr_decoder;
extern AVCodec ffv1_decoder;
extern AVCodec fourxm_decoder;
extern AVCodec mdec_decoder;
extern AVCodec roq_decoder;
extern AVCodec interplay_video_decoder;
extern AVCodec ra_144_decoder;
extern AVCodec ra_288_decoder;
extern AVCodec roq_dpcm_decoder;
extern AVCodec interplay_dpcm_decoder;
/* pcm codecs */
#define PCM_CODEC(id, name) \
......
/*
* Assorted DPCM codecs
* 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: dpcm.c
* Assorted DPCM (differential pulse code modulation) audio codecs
* by Mike Melanson (melanson@pcisys.net)
* for more information on the specific data formats, visit:
* http://www.pcisys.net/~melanson/codecs/simpleaudio.html
*/
#include "avcodec.h"
typedef struct DPCMContext {
int channels;
short roq_square_array[256];
int last_delta[2];
} DPCMContext;
#define SATURATE_S16(x) if (x < -32768) x = -32768; \
else if (x > 32767) x = 32767;
#define SE_16BIT(x) if (x & 0x8000) x -= 0x10000;
#define LE_16(x) ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0])
#define LE_32(x) ((((uint8_t*)(x))[3] << 24) | \
(((uint8_t*)(x))[2] << 16) | \
(((uint8_t*)(x))[1] << 8) | \
((uint8_t*)(x))[0])
static int interplay_delta_table[] = {
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 47, 51, 56, 61,
66, 72, 79, 86, 94, 102, 112, 122,
133, 145, 158, 173, 189, 206, 225, 245,
267, 292, 318, 348, 379, 414, 452, 493,
538, 587, 640, 699, 763, 832, 908, 991,
1081, 1180, 1288, 1405, 1534, 1673, 1826, 1993,
2175, 2373, 2590, 2826, 3084, 3365, 3672, 4008,
4373, 4772, 5208, 5683, 6202, 6767, 7385, 8059,
8794, 9597, 10472, 11428, 12471, 13609, 14851, 16206,
17685, 19298, 21060, 22981, 25078, 27367, 29864, 32589,
-29973, -26728, -23186, -19322, -15105, -10503, -5481, -1,
1, 1, 5481, 10503, 15105, 19322, 23186, 26728,
29973, -32589, -29864, -27367, -25078, -22981, -21060, -19298,
-17685, -16206, -14851, -13609, -12471, -11428, -10472, -9597,
-8794, -8059, -7385, -6767, -6202, -5683, -5208, -4772,
-4373, -4008, -3672, -3365, -3084, -2826, -2590, -2373,
-2175, -1993, -1826, -1673, -1534, -1405, -1288, -1180,
-1081, -991, -908, -832, -763, -699, -640, -587,
-538, -493, -452, -414, -379, -348, -318, -292,
-267, -245, -225, -206, -189, -173, -158, -145,
-133, -122, -112, -102, -94, -86, -79, -72,
-66, -61, -56, -51, -47, -43, -42, -41,
-40, -39, -38, -37, -36, -35, -34, -33,
-32, -31, -30, -29, -28, -27, -26, -25,
-24, -23, -22, -21, -20, -19, -18, -17,
-16, -15, -14, -13, -12, -11, -10, -9,
-8, -7, -6, -5, -4, -3, -2, -1
};
static int dpcm_decode_init(AVCodecContext *avctx)
{
DPCMContext *s = avctx->priv_data;
int i;
short square;
s->channels = avctx->channels;
switch(avctx->codec->id) {
case CODEC_ID_ROQ_DPCM:
/* initialize square table */
for (i = 0; i < 128; i++) {
square = i * i;
s->roq_square_array[i] = square;
s->roq_square_array[i + 128] = -square;
}
break;
default:
break;
}
return 0;
}
static int dpcm_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
uint8_t *buf, int buf_size)
{
DPCMContext *s = avctx->priv_data;
int in, out = 0;
int i;
int predictor[2];
int channel_number = 0;
short *output_samples = data;
int sequence_number;
switch(avctx->codec->id) {
case CODEC_ID_ROQ_DPCM:
if (s->channels == 1)
predictor[0] = LE_16(&buf[6]);
else {
predictor[0] = buf[7] << 8;
predictor[1] = buf[6] << 8;
}
SE_16BIT(predictor[0]);
SE_16BIT(predictor[1]);
/* decode the samples */
for (in = 8, out = 0; in < buf_size; in++, out++) {
predictor[channel_number] += s->roq_square_array[buf[in]];
SATURATE_S16(predictor[channel_number]);
output_samples[out] = predictor[channel_number];
/* toggle channel */
channel_number ^= s->channels - 1;
}
break;
case CODEC_ID_INTERPLAY_DPCM:
in = 0;
sequence_number = LE_16(&buf[in]);
in += 6; /* skip over the stream mask and stream length */
if (sequence_number == 1) {
predictor[0] = LE_16(&buf[in]);
in += 2;
SE_16BIT(predictor[0])
if (s->channels == 2) {
predictor[1] = LE_16(&buf[in]);
SE_16BIT(predictor[1])
in += 2;
}
} else {
for (i = 0; i < s->channels; i++)
predictor[i] = s->last_delta[i];
}
while (in < buf_size) {
predictor[channel_number] += interplay_delta_table[buf[in++]];
SATURATE_S16(predictor[channel_number]);
output_samples[out++] = predictor[channel_number];
/* toggle channel */
channel_number ^= s->channels - 1;
}
/* save predictors for next round */
for (i = 0; i < s->channels; i++)
s->last_delta[i] = predictor[i];
break;
}
*data_size = out * sizeof(short);
return buf_size;
}
AVCodec roq_dpcm_decoder = {
"roq_dpcm",
CODEC_TYPE_AUDIO,
CODEC_ID_ROQ_DPCM,
sizeof(DPCMContext),
dpcm_decode_init,
NULL,
NULL,
dpcm_decode_frame,
};
AVCodec interplay_dpcm_decoder = {
"interplay_dpcm",
CODEC_TYPE_AUDIO,
CODEC_ID_INTERPLAY_DPCM,
sizeof(DPCMContext),
dpcm_decode_init,
NULL,
NULL,
dpcm_decode_frame,
};
/*
* Interplay MVE 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 roqvideo.c
* Interplay MVE Video Decoder by Mike Melanson
* For more information about the Interplay MVE format, visit:
* http://www.pcisys.net/~melanson/codecs/
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "common.h"
#include "avcodec.h"
#include "dsputil.h"
typedef struct IpvideoContext {
AVCodecContext *avctx;
DSPContext dsp;
AVFrame last_frame;
AVFrame current_frame;
int first_frame;
int receiving_decoding_map;
unsigned char *decoding_map;
int decoding_map_size;
unsigned char *buf;
int size;
} IpvideoContext;
static int ipvideo_decode_init(AVCodecContext *avctx)
{
IpvideoContext *s = avctx->priv_data;
s->avctx = avctx;
avctx->pix_fmt = PIX_FMT_YUV444P;
avctx->has_b_frames = 0;
dsputil_init(&s->dsp, avctx);
s->first_frame = 1;
s->receiving_decoding_map = 1; /* decoding map will be received first */
/* decoding map contains 4 bits of information per 8x8 block */
s->decoding_map_size = avctx->width * avctx->height / (8 * 8 * 2);
s->decoding_map = av_malloc(s->decoding_map_size);
return 0;
}
static int ipvideo_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
uint8_t *buf, int buf_size)
{
IpvideoContext *s = avctx->priv_data;
if (s->receiving_decoding_map) {
/* receiving the decoding map on this iteration */
s->receiving_decoding_map = 0;
if (buf_size != s->decoding_map_size)
printf (" Interplay video: buf_size != decoding_map_size (%d != %d)\n",
buf_size, s->decoding_map_size);
else
memcpy(s->decoding_map, buf, buf_size);
*data_size = 0;
*(AVFrame*)data = s->last_frame;
} else {
/* receiving the compressed video data on this iteration */
s->receiving_decoding_map = 1;
s->buf = buf;
s->size = buf_size;
if (avctx->get_buffer(avctx, &s->current_frame)) {
printf (" Interplay Video: get_buffer() failed\n");
return -1;
}
// ipvideo_decode_frame(s);
memset(s->current_frame.data[0], 0x80, s->current_frame.linesize[0] * avctx->height);
memset(s->current_frame.data[1], 0x80, s->current_frame.linesize[1] * avctx->height / 4);
memset(s->current_frame.data[2], 0x80, s->current_frame.linesize[2] * avctx->height / 4);
/* release the last frame if it is allocated */
if (s->first_frame)
s->first_frame = 0;
else
avctx->release_buffer(avctx, &s->last_frame);
/* shuffle frames */
s->last_frame = s->current_frame;
*data_size = sizeof(AVFrame);
*(AVFrame*)data = s->current_frame;
}
/* always report that the buffer was completely consumed */
return buf_size;
}
static int ipvideo_decode_end(AVCodecContext *avctx)
{
IpvideoContext *s = avctx->priv_data;
/* release the last frame */
avctx->release_buffer(avctx, &s->last_frame);
av_free(s->decoding_map);
return 0;
}
AVCodec interplay_video_decoder = {
"interplayvideo",
CODEC_TYPE_VIDEO,
CODEC_ID_INTERPLAY_VIDEO,
sizeof(IpvideoContext),
ipvideo_decode_init,
NULL,
ipvideo_decode_end,
ipvideo_decode_frame,
CODEC_CAP_DR1,
};
This diff is collapsed.
......@@ -14,7 +14,7 @@ PPOBJS=
# mux and demuxes
OBJS+=mpeg.o mpegts.o mpegtsenc.o ffm.o crc.o img.o raw.o rm.o \
avienc.o avidec.o wav.o swf.o au.o gif.o mov.o mpjpeg.o dvcore.o dv.o \
yuv4mpeg.o 4xm.o flvenc.o flvdec.o movenc.o psxstr.o
yuv4mpeg.o 4xm.o flvenc.o flvdec.o movenc.o psxstr.o idroq.o ipmovie.o
ifeq ($(CONFIG_RISKY),yes)
OBJS+= asf.o
......
......@@ -52,6 +52,8 @@ void av_register_all(void)
flvenc_init();
flvdec_init();
str_init();
roq_init();
ipmovie_init();
#ifdef AMR_NB
amr_init();
......
......@@ -383,6 +383,12 @@ int fourxm_init(void);
/* psxstr.c */
int str_init(void);
/* idroq.c */
int roq_init(void);
/* ipmovie.c */
int ipmovie_init(void);
#include "rtp.h"
#include "rtsp.h"
......
/*
* Id RoQ (.roq) File Demuxer
* 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 idroq.c
* Id RoQ format file demuxer
* by Mike Melanson (melanson@pcisys.net)
* for more information on the .roq file format, visit:
* http://www.csse.monash.edu.au/~timf/
*/
#include "avformat.h"
#define LE_16(x) ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0])
#define LE_32(x) ((((uint8_t*)(x))[3] << 24) | \
(((uint8_t*)(x))[2] << 16) | \
(((uint8_t*)(x))[1] << 8) | \
((uint8_t*)(x))[0])
#define RoQ_MAGIC_NUMBER 0x1084
#define RoQ_CHUNK_PREAMBLE_SIZE 8
#define RoQ_AUDIO_SAMPLE_RATE 22050
#define RoQ_CHUNKS_TO_SCAN 30
#define RoQ_INFO 0x1001
#define RoQ_QUAD_CODEBOOK 0x1002
#define RoQ_QUAD_VQ 0x1011
#define RoQ_SOUND_MONO 0x1020
#define RoQ_SOUND_STEREO 0x1021
typedef struct RoqDemuxContext {
int width;
int height;
int audio_channels;
int framerate;
int frame_pts_inc;
int video_stream_index;
int audio_stream_index;
int64_t video_pts;
unsigned int audio_frame_count;
} RoqDemuxContext;
static int roq_probe(AVProbeData *p)
{
if ((LE_16(&p->buf[0]) != RoQ_MAGIC_NUMBER) ||
(LE_32(&p->buf[2]) != 0xFFFFFFFF))
return 0;
return AVPROBE_SCORE_MAX;
}
static int roq_read_header(AVFormatContext *s,
AVFormatParameters *ap)
{
RoqDemuxContext *roq = s->priv_data;
ByteIOContext *pb = &s->pb;
AVStream *st;
unsigned char preamble[RoQ_CHUNK_PREAMBLE_SIZE];
int i;
unsigned int chunk_size;
unsigned int chunk_type;
/* get the main header */
if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) !=
RoQ_CHUNK_PREAMBLE_SIZE)
return AVERROR_IO;
roq->framerate = LE_16(&preamble[6]);
roq->frame_pts_inc = 90000 / roq->framerate;
/* set the pts reference (1 pts = 1/90000) */
s->pts_num = 1;
s->pts_den = 90000;
/* init private context parameters */
roq->width = roq->height = roq->audio_channels = roq->video_pts =
roq->audio_frame_count = 0;
/* scan the first n chunks searching for A/V parameters */
for (i = 0; i < RoQ_CHUNKS_TO_SCAN; i++) {
if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) !=
RoQ_CHUNK_PREAMBLE_SIZE)
return AVERROR_IO;
chunk_type = LE_16(&preamble[0]);
chunk_size = LE_32(&preamble[2]);
switch (chunk_type) {
case RoQ_INFO:
/* fetch the width and height; reuse the preamble bytes */
if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) !=
RoQ_CHUNK_PREAMBLE_SIZE)
return AVERROR_IO;
roq->width = LE_16(&preamble[0]);
roq->height = LE_16(&preamble[2]);
break;
case RoQ_QUAD_CODEBOOK:
case RoQ_QUAD_VQ:
/* ignore during this scan */
url_fseek(pb, chunk_size, SEEK_CUR);
break;
case RoQ_SOUND_MONO:
roq->audio_channels = 1;
url_fseek(pb, chunk_size, SEEK_CUR);
break;
case RoQ_SOUND_STEREO:
roq->audio_channels = 2;
url_fseek(pb, chunk_size, SEEK_CUR);
break;
default:
printf (" unknown RoQ chunk type (%04X)\n", LE_16(&preamble[0]));
return AVERROR_INVALIDDATA;
break;
}
/* if all necessary parameters have been gathered, exit early */
if ((roq->width && roq->height) && roq->audio_channels)
break;
}
/* seek back to the first chunk */
url_fseek(pb, RoQ_CHUNK_PREAMBLE_SIZE, SEEK_SET);
/* initialize the decoders */
st = av_new_stream(s, 0);
if (!st)
return AVERROR_NOMEM;
roq->video_stream_index = st->index;
st->codec.codec_type = CODEC_TYPE_VIDEO;
st->codec.codec_id = CODEC_ID_ROQ;
st->codec.codec_tag = 0; /* no fourcc */
st->codec.width = roq->width;
st->codec.height = roq->height;
if (roq->audio_channels) {
st = av_new_stream(s, 0);
if (!st)
return AVERROR_NOMEM;
roq->audio_stream_index = st->index;
st->codec.codec_type = CODEC_TYPE_AUDIO;
st->codec.codec_id = CODEC_ID_ROQ_DPCM;
st->codec.codec_tag = 0; /* no tag */
st->codec.channels = roq->audio_channels;
st->codec.sample_rate = RoQ_AUDIO_SAMPLE_RATE;
st->codec.bits_per_sample = 16;
st->codec.bit_rate = st->codec.channels * st->codec.sample_rate *
st->codec.bits_per_sample;
st->codec.block_align = st->codec.channels * st->codec.bits_per_sample;
}
printf (" video is %d x %d, audio is %d channels\n",
roq->width, roq->height, roq->audio_channels);
return 0;
}
static int roq_read_packet(AVFormatContext *s,
AVPacket *pkt)
{
RoqDemuxContext *roq = s->priv_data;
ByteIOContext *pb = &s->pb;
int ret = 0;
unsigned int chunk_size;
unsigned int chunk_type;
unsigned int codebook_size;
unsigned char preamble[RoQ_CHUNK_PREAMBLE_SIZE];
int packet_read = 0;
offset_t codebook_offset;
while (!packet_read) {
if (url_feof(&s->pb))
return -EIO;
/* get the next chunk preamble */
if ((ret = get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE)) !=
RoQ_CHUNK_PREAMBLE_SIZE)
return -EIO;
chunk_type = LE_16(&preamble[0]);
chunk_size = LE_32(&preamble[2]);
switch (chunk_type) {
case RoQ_INFO:
/* don't care about this chunk anymore */
url_fseek(pb, RoQ_CHUNK_PREAMBLE_SIZE, SEEK_CUR);
break;
case RoQ_QUAD_CODEBOOK:
/* packet needs to contain both this codebook and next VQ chunk */
codebook_offset = url_ftell(pb) - RoQ_CHUNK_PREAMBLE_SIZE;
codebook_size = chunk_size;
url_fseek(pb, codebook_size, SEEK_CUR);
if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) !=
RoQ_CHUNK_PREAMBLE_SIZE)
return -EIO;
chunk_size = LE_32(&preamble[2]) + RoQ_CHUNK_PREAMBLE_SIZE * 2 +
codebook_size;
/* rewind */
url_fseek(pb, codebook_offset, SEEK_SET);
/* load up the packet */
if (av_new_packet(pkt, chunk_size))
return -EIO;
pkt->stream_index = roq->video_stream_index;
pkt->pts = roq->video_pts;
ret = get_buffer(pb, pkt->data, chunk_size);
if (ret != chunk_size)
ret = -EIO;
roq->video_pts += roq->frame_pts_inc;
packet_read = 1;
break;
case RoQ_SOUND_MONO:
case RoQ_SOUND_STEREO:
case RoQ_QUAD_VQ:
/* load up the packet */
if (av_new_packet(pkt, chunk_size + RoQ_CHUNK_PREAMBLE_SIZE))
return -EIO;
/* copy over preamble */
memcpy(pkt->data, preamble, RoQ_CHUNK_PREAMBLE_SIZE);
if (chunk_type == RoQ_QUAD_VQ) {
pkt->stream_index = roq->video_stream_index;
pkt->pts = roq->video_pts;
roq->video_pts += roq->frame_pts_inc;
} else {
pkt->stream_index = roq->audio_stream_index;
pkt->pts = roq->audio_frame_count;
pkt->pts *= 90000;
pkt->pts /= RoQ_AUDIO_SAMPLE_RATE;
roq->audio_frame_count += (chunk_size / roq->audio_channels);
}
ret = get_buffer(pb, pkt->data, chunk_size);
if (ret != chunk_size)
ret = -EIO;
packet_read = 1;
break;
default:
printf (" unknown RoQ chunk (%04X)\n", chunk_type);
return AVERROR_INVALIDDATA;
break;
}
}
return ret;
}
static int roq_read_close(AVFormatContext *s)
{
// RoqDemuxContext *roq = (RoqDemuxContext *)s->priv_data;
return 0;
}
static AVInputFormat roq_iformat = {
"RoQ",
"Id RoQ format",
sizeof(RoqDemuxContext),
roq_probe,
roq_read_header,
roq_read_packet,
roq_read_close,
};
int roq_init(void)
{