* Id Quake II CIN File Demuxer
* Copyright (c) 2003 The ffmpeg Project
*
- * This library is free software; you can redistribute it and/or
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ * version 2.1 of the License, or (at your option) any later version.
*
- * This library is distributed in the hope that it will be useful,
+ * FFmpeg 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
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
#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 HUFFMAN_TABLE_SIZE (64 * 1024)
#define FRAME_PTS_INC (90000 / 14)
int64_t pts;
- /* keep reference to extradata but never free it */
- void *extradata;
+ AVPaletteControl palctrl;
} IdcinDemuxContext;
static int idcin_probe(AVProbeData *p)
st = av_new_stream(s, 0);
if (!st)
return AVERROR_NOMEM;
+ av_set_pts_info(st, 33, 1, 90000);
idcin->video_stream_index = st->index;
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- st->codec.codec_id = CODEC_ID_IDCIN;
- st->codec.codec_tag = 0; /* no fourcc */
- st->codec.width = width;
- st->codec.height = height;
+ st->codec->codec_type = CODEC_TYPE_VIDEO;
+ st->codec->codec_id = CODEC_ID_IDCIN;
+ st->codec->codec_tag = 0; /* no fourcc */
+ st->codec->width = width;
+ st->codec->height = height;
/* load up the Huffman tables into extradata */
- st->codec.extradata_size = HUFFMAN_TABLE_SIZE;
- st->codec.extradata = av_malloc(HUFFMAN_TABLE_SIZE);
- if (get_buffer(pb, st->codec.extradata, HUFFMAN_TABLE_SIZE) !=
+ st->codec->extradata_size = HUFFMAN_TABLE_SIZE;
+ st->codec->extradata = av_malloc(HUFFMAN_TABLE_SIZE);
+ if (get_buffer(pb, st->codec->extradata, HUFFMAN_TABLE_SIZE) !=
HUFFMAN_TABLE_SIZE)
- return -EIO;
+ return AVERROR_IO;
/* save a reference in order to transport the palette */
- idcin->extradata = st->codec.extradata;
+ st->codec->palctrl = &idcin->palctrl;
/* if sample rate is 0, assume no audio */
if (sample_rate) {
st = av_new_stream(s, 0);
if (!st)
return AVERROR_NOMEM;
+ av_set_pts_info(st, 33, 1, 90000);
idcin->audio_stream_index = st->index;
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- st->codec.codec_tag = 1;
- st->codec.channels = channels;
- st->codec.sample_rate = sample_rate;
- st->codec.bits_per_sample = bytes_per_sample * 8;
- st->codec.bit_rate = sample_rate * bytes_per_sample * 8 * channels;
- st->codec.block_align = bytes_per_sample * channels;
+ st->codec->codec_type = CODEC_TYPE_AUDIO;
+ st->codec->codec_tag = 1;
+ st->codec->channels = channels;
+ st->codec->sample_rate = sample_rate;
+ st->codec->bits_per_sample = bytes_per_sample * 8;
+ st->codec->bit_rate = sample_rate * bytes_per_sample * 8 * channels;
+ st->codec->block_align = bytes_per_sample * channels;
if (bytes_per_sample == 1)
- st->codec.codec_id = CODEC_ID_PCM_U8;
+ st->codec->codec_id = CODEC_ID_PCM_U8;
else
- st->codec.codec_id = CODEC_ID_PCM_S16LE;
+ st->codec->codec_id = CODEC_ID_PCM_S16LE;
if (sample_rate % 14 != 0) {
idcin->audio_chunk_size1 = (sample_rate / 14) *
idcin->next_chunk_is_video = 1;
idcin->pts = 0;
- /* set the pts reference (1 pts = 1/90000) */
- s->pts_num = 1;
- s->pts_den = 90000;
-
return 0;
}
unsigned int chunk_size;
IdcinDemuxContext *idcin = (IdcinDemuxContext *)s->priv_data;
ByteIOContext *pb = &s->pb;
- AVPaletteControl *palette_control = (AVPaletteControl *)idcin->extradata;
int i;
int palette_scale;
+ unsigned char r, g, b;
+ unsigned char palette_buffer[768];
if (url_feof(&s->pb))
- return -EIO;
+ return AVERROR_IO;
if (idcin->next_chunk_is_video) {
command = get_le32(pb);
if (command == 2) {
- return -EIO;
+ return AVERROR_IO;
} else if (command == 1) {
/* trigger a palette change */
- palette_control->palette_changed = 1;
- if (get_buffer(pb, palette_control->palette, 768) != 768)
- return -EIO;
+ idcin->palctrl.palette_changed = 1;
+ if (get_buffer(pb, palette_buffer, 768) != 768)
+ return AVERROR_IO;
/* scale the palette as necessary */
palette_scale = 2;
for (i = 0; i < 768; i++)
- if (palette_control->palette[i] > 63) {
+ if (palette_buffer[i] > 63) {
palette_scale = 0;
break;
}
- if (palette_scale)
- for (i = 0; i < 768; i++)
- palette_control->palette[i] <<= palette_scale;
+ for (i = 0; i < 256; i++) {
+ r = palette_buffer[i * 3 ] << palette_scale;
+ g = palette_buffer[i * 3 + 1] << palette_scale;
+ b = palette_buffer[i * 3 + 2] << palette_scale;
+ idcin->palctrl.palette[i] = (r << 16) | (g << 8) | (b);
+ }
}
chunk_size = get_le32(pb);
/* skip the number of decoded bytes (always equal to width * height) */
url_fseek(pb, 4, SEEK_CUR);
chunk_size -= 4;
- if (av_new_packet(pkt, chunk_size))
- ret = -EIO;
+ ret= av_get_packet(pb, pkt, chunk_size);
+ if (ret != chunk_size)
+ return AVERROR_IO;
pkt->stream_index = idcin->video_stream_index;
pkt->pts = idcin->pts;
- ret = get_buffer(pb, pkt->data, chunk_size);
- if (ret != chunk_size)
- ret = -EIO;
} else {
/* send out the audio chunk */
if (idcin->current_audio_chunk)
chunk_size = idcin->audio_chunk_size2;
else
chunk_size = idcin->audio_chunk_size1;
- if (av_new_packet(pkt, chunk_size))
- return -EIO;
+ ret= av_get_packet(pb, pkt, chunk_size);
+ if (ret != chunk_size)
+ return AVERROR_IO;
pkt->stream_index = idcin->audio_stream_index;
pkt->pts = idcin->pts;
- ret = get_buffer(&s->pb, pkt->data, chunk_size);
- if (ret != chunk_size)
- ret = -EIO;
idcin->current_audio_chunk ^= 1;
idcin->pts += FRAME_PTS_INC;
static int idcin_read_close(AVFormatContext *s)
{
+
return 0;
}
-static AVInputFormat idcin_iformat = {
+AVInputFormat idcin_demuxer = {
"idcin",
"Id CIN format",
sizeof(IdcinDemuxContext),
idcin_read_packet,
idcin_read_close,
};
-
-int idcin_init(void)
-{
- av_register_input_format(&idcin_iformat);
- return 0;
-}