2008-03-30 19:17:01 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008 Jaikrishnan Menon <realityman@gmx.net>
|
2010-02-03 09:57:21 +00:00
|
|
|
* Copyright (c) 2010 Peter Ross <pross@xvid.org>
|
2010-04-27 14:03:47 +00:00
|
|
|
* Copyright (c) 2010 Sebastian Vater <cdgs.basty@googlemail.com>
|
2008-03-30 19:17:01 +00:00
|
|
|
*
|
|
|
|
* 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.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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 FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 14:45:34 +00:00
|
|
|
* @file
|
2008-03-31 17:31:11 +00:00
|
|
|
* IFF file demuxer
|
2008-03-30 19:17:01 +00:00
|
|
|
* by Jaikrishnan Menon
|
|
|
|
* for more information on the .iff file format, visit:
|
|
|
|
* http://wiki.multimedia.cx/index.php?title=IFF
|
|
|
|
*/
|
|
|
|
|
2014-03-10 14:35:59 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
2012-08-10 14:26:39 +00:00
|
|
|
#include "libavutil/avassert.h"
|
2012-04-07 18:05:45 +00:00
|
|
|
#include "libavutil/channel_layout.h"
|
2009-01-11 22:19:48 +00:00
|
|
|
#include "libavutil/intreadwrite.h"
|
2011-05-22 10:46:29 +00:00
|
|
|
#include "libavutil/dict.h"
|
2012-11-13 09:55:07 +00:00
|
|
|
#include "libavcodec/bytestream.h"
|
2008-03-30 19:17:01 +00:00
|
|
|
#include "avformat.h"
|
2011-11-29 18:28:15 +00:00
|
|
|
#include "internal.h"
|
2008-03-30 19:17:01 +00:00
|
|
|
|
|
|
|
#define ID_8SVX MKTAG('8','S','V','X')
|
2012-11-28 15:53:25 +00:00
|
|
|
#define ID_16SV MKTAG('1','6','S','V')
|
2012-11-29 10:45:28 +00:00
|
|
|
#define ID_MAUD MKTAG('M','A','U','D')
|
|
|
|
#define ID_MHDR MKTAG('M','H','D','R')
|
|
|
|
#define ID_MDAT MKTAG('M','D','A','T')
|
2008-03-30 19:17:01 +00:00
|
|
|
#define ID_VHDR MKTAG('V','H','D','R')
|
|
|
|
#define ID_ATAK MKTAG('A','T','A','K')
|
|
|
|
#define ID_RLSE MKTAG('R','L','S','E')
|
|
|
|
#define ID_CHAN MKTAG('C','H','A','N')
|
2010-02-03 09:57:21 +00:00
|
|
|
#define ID_PBM MKTAG('P','B','M',' ')
|
|
|
|
#define ID_ILBM MKTAG('I','L','B','M')
|
|
|
|
#define ID_BMHD MKTAG('B','M','H','D')
|
2012-03-08 22:34:36 +00:00
|
|
|
#define ID_DGBL MKTAG('D','G','B','L')
|
2011-04-20 11:56:56 +00:00
|
|
|
#define ID_CAMG MKTAG('C','A','M','G')
|
2010-02-03 09:57:21 +00:00
|
|
|
#define ID_CMAP MKTAG('C','M','A','P')
|
2011-11-21 19:31:47 +00:00
|
|
|
#define ID_ACBM MKTAG('A','C','B','M')
|
2012-03-08 22:34:36 +00:00
|
|
|
#define ID_DEEP MKTAG('D','E','E','P')
|
2012-11-29 23:42:15 +00:00
|
|
|
#define ID_RGB8 MKTAG('R','G','B','8')
|
|
|
|
#define ID_RGBN MKTAG('R','G','B','N')
|
2008-03-30 19:17:01 +00:00
|
|
|
|
|
|
|
#define ID_FORM MKTAG('F','O','R','M')
|
|
|
|
#define ID_ANNO MKTAG('A','N','N','O')
|
|
|
|
#define ID_AUTH MKTAG('A','U','T','H')
|
|
|
|
#define ID_CHRS MKTAG('C','H','R','S')
|
|
|
|
#define ID_COPYRIGHT MKTAG('(','c',')',' ')
|
|
|
|
#define ID_CSET MKTAG('C','S','E','T')
|
|
|
|
#define ID_FVER MKTAG('F','V','E','R')
|
|
|
|
#define ID_NAME MKTAG('N','A','M','E')
|
|
|
|
#define ID_TEXT MKTAG('T','E','X','T')
|
2011-11-21 19:31:47 +00:00
|
|
|
#define ID_ABIT MKTAG('A','B','I','T')
|
2008-03-30 19:17:01 +00:00
|
|
|
#define ID_BODY MKTAG('B','O','D','Y')
|
2012-03-08 22:34:36 +00:00
|
|
|
#define ID_DBOD MKTAG('D','B','O','D')
|
|
|
|
#define ID_DPEL MKTAG('D','P','E','L')
|
2012-11-18 08:02:03 +00:00
|
|
|
#define ID_DLOC MKTAG('D','L','O','C')
|
2012-11-25 04:12:56 +00:00
|
|
|
#define ID_TVDC MKTAG('T','V','D','C')
|
2008-03-30 19:17:01 +00:00
|
|
|
|
|
|
|
#define LEFT 2
|
|
|
|
#define RIGHT 4
|
|
|
|
#define STEREO 6
|
|
|
|
|
2011-04-20 11:56:56 +00:00
|
|
|
/**
|
|
|
|
* This number of bytes if added at the beginning of each AVPacket
|
|
|
|
* which contain additional information about video properties
|
|
|
|
* which has to be shared between demuxer and decoder.
|
|
|
|
* This number may change between frames, e.g. the demuxer might
|
|
|
|
* set it to smallest possible size of 2 to indicate that there's
|
|
|
|
* no extradata changing in this frame.
|
|
|
|
*/
|
2012-11-25 04:12:56 +00:00
|
|
|
#define IFF_EXTRA_VIDEO_SIZE 41
|
2011-04-20 11:56:56 +00:00
|
|
|
|
2010-04-20 18:40:45 +00:00
|
|
|
typedef enum {
|
|
|
|
COMP_NONE,
|
|
|
|
COMP_FIB,
|
|
|
|
COMP_EXP
|
|
|
|
} svx8_compression_type;
|
|
|
|
|
2008-03-30 19:17:01 +00:00
|
|
|
typedef struct {
|
2013-01-05 20:37:49 +00:00
|
|
|
int64_t body_pos;
|
|
|
|
int64_t body_end;
|
2008-03-30 19:17:01 +00:00
|
|
|
uint32_t body_size;
|
2011-05-10 13:33:36 +00:00
|
|
|
svx8_compression_type svx8_compression;
|
2012-11-29 10:45:28 +00:00
|
|
|
unsigned maud_bits;
|
|
|
|
unsigned maud_compression;
|
2012-11-22 09:42:37 +00:00
|
|
|
unsigned bitmap_compression; ///< delta compression method used
|
2011-04-20 11:56:56 +00:00
|
|
|
unsigned bpp; ///< bits per plane to decode (differs from bits_per_coded_sample if HAM)
|
|
|
|
unsigned ham; ///< 0 if non-HAM or number of hold bits (6 for bpp > 6, 4 otherwise)
|
|
|
|
unsigned flags; ///< 1 for EHB, 0 is no extra half darkening
|
|
|
|
unsigned transparency; ///< transparency color index in palette
|
|
|
|
unsigned masking; ///< masking method used
|
2012-11-25 04:12:56 +00:00
|
|
|
uint8_t tvdc[32]; ///< TVDC lookup table
|
2008-03-30 19:17:01 +00:00
|
|
|
} IffDemuxContext;
|
|
|
|
|
2010-05-05 17:26:59 +00:00
|
|
|
/* Metadata string read */
|
|
|
|
static int get_metadata(AVFormatContext *s,
|
|
|
|
const char *const tag,
|
|
|
|
const unsigned data_size)
|
|
|
|
{
|
|
|
|
uint8_t *buf = ((data_size + 1) == 0) ? NULL : av_malloc(data_size + 1);
|
|
|
|
|
|
|
|
if (!buf)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2013-12-28 23:57:15 +00:00
|
|
|
if (avio_read(s->pb, buf, data_size) != data_size) {
|
2010-05-05 17:26:59 +00:00
|
|
|
av_free(buf);
|
|
|
|
return AVERROR(EIO);
|
|
|
|
}
|
|
|
|
buf[data_size] = 0;
|
2011-05-22 10:46:29 +00:00
|
|
|
av_dict_set(&s->metadata, tag, buf, AV_DICT_DONT_STRDUP_VAL);
|
2010-05-05 17:26:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-30 19:17:01 +00:00
|
|
|
static int iff_probe(AVProbeData *p)
|
|
|
|
{
|
|
|
|
const uint8_t *d = p->buf;
|
|
|
|
|
2012-07-23 21:15:23 +00:00
|
|
|
if ( AV_RL32(d) == ID_FORM &&
|
|
|
|
(AV_RL32(d+8) == ID_8SVX ||
|
2012-11-28 15:53:25 +00:00
|
|
|
AV_RL32(d+8) == ID_16SV ||
|
2012-11-29 10:45:28 +00:00
|
|
|
AV_RL32(d+8) == ID_MAUD ||
|
2012-07-23 21:15:23 +00:00
|
|
|
AV_RL32(d+8) == ID_PBM ||
|
|
|
|
AV_RL32(d+8) == ID_ACBM ||
|
|
|
|
AV_RL32(d+8) == ID_DEEP ||
|
2012-11-29 23:42:15 +00:00
|
|
|
AV_RL32(d+8) == ID_ILBM ||
|
|
|
|
AV_RL32(d+8) == ID_RGB8 ||
|
|
|
|
AV_RL32(d+8) == ID_RGBN) )
|
2008-03-30 19:17:01 +00:00
|
|
|
return AVPROBE_SCORE_MAX;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-08 22:34:36 +00:00
|
|
|
static const uint8_t deep_rgb24[] = {0, 0, 0, 3, 0, 1, 0, 8, 0, 2, 0, 8, 0, 3, 0, 8};
|
|
|
|
static const uint8_t deep_rgba[] = {0, 0, 0, 4, 0, 1, 0, 8, 0, 2, 0, 8, 0, 3, 0, 8};
|
2012-11-18 08:01:41 +00:00
|
|
|
static const uint8_t deep_bgra[] = {0, 0, 0, 4, 0, 3, 0, 8, 0, 2, 0, 8, 0, 1, 0, 8};
|
|
|
|
static const uint8_t deep_argb[] = {0, 0, 0, 4, 0,17, 0, 8, 0, 1, 0, 8, 0, 2, 0, 8};
|
|
|
|
static const uint8_t deep_abgr[] = {0, 0, 0, 4, 0,17, 0, 8, 0, 3, 0, 8, 0, 2, 0, 8};
|
2012-03-08 22:34:36 +00:00
|
|
|
|
2012-01-12 12:20:36 +00:00
|
|
|
static int iff_read_header(AVFormatContext *s)
|
2008-03-30 19:17:01 +00:00
|
|
|
{
|
|
|
|
IffDemuxContext *iff = s->priv_data;
|
2011-02-20 10:04:12 +00:00
|
|
|
AVIOContext *pb = s->pb;
|
2008-03-30 19:17:01 +00:00
|
|
|
AVStream *st;
|
2011-04-20 11:56:56 +00:00
|
|
|
uint8_t *buf;
|
2008-03-30 19:17:01 +00:00
|
|
|
uint32_t chunk_id, data_size;
|
2012-11-29 10:45:28 +00:00
|
|
|
uint32_t screenmode = 0, num, den;
|
2011-04-20 11:56:56 +00:00
|
|
|
unsigned transparency = 0;
|
|
|
|
unsigned masking = 0; // no mask
|
2012-03-08 22:34:36 +00:00
|
|
|
uint8_t fmt[16];
|
|
|
|
int fmt_size;
|
2008-03-30 19:17:01 +00:00
|
|
|
|
2011-06-18 09:43:24 +00:00
|
|
|
st = avformat_new_stream(s, NULL);
|
2008-03-30 19:17:01 +00:00
|
|
|
if (!st)
|
2010-04-27 14:04:11 +00:00
|
|
|
return AVERROR(ENOMEM);
|
2008-03-30 19:17:01 +00:00
|
|
|
|
|
|
|
st->codec->channels = 1;
|
2012-04-07 18:05:45 +00:00
|
|
|
st->codec->channel_layout = AV_CH_LAYOUT_MONO;
|
2011-03-15 08:14:38 +00:00
|
|
|
avio_skip(pb, 8);
|
2010-02-03 09:57:21 +00:00
|
|
|
// codec_tag used by ByteRun1 decoder to distinguish progressive (PBM) and interlaced (ILBM) content
|
2011-02-21 15:43:01 +00:00
|
|
|
st->codec->codec_tag = avio_rl32(pb);
|
2012-11-30 10:44:00 +00:00
|
|
|
iff->bitmap_compression = -1;
|
|
|
|
iff->svx8_compression = -1;
|
|
|
|
iff->maud_bits = -1;
|
|
|
|
iff->maud_compression = -1;
|
2008-03-30 19:17:01 +00:00
|
|
|
|
2010-04-27 14:03:47 +00:00
|
|
|
while(!url_feof(pb)) {
|
|
|
|
uint64_t orig_pos;
|
2010-05-05 17:26:59 +00:00
|
|
|
int res;
|
|
|
|
const char *metadata_tag = NULL;
|
2011-02-21 15:43:01 +00:00
|
|
|
chunk_id = avio_rl32(pb);
|
|
|
|
data_size = avio_rb32(pb);
|
2011-03-03 19:11:45 +00:00
|
|
|
orig_pos = avio_tell(pb);
|
2008-03-30 19:17:01 +00:00
|
|
|
|
|
|
|
switch(chunk_id) {
|
|
|
|
case ID_VHDR:
|
2010-03-30 23:30:55 +00:00
|
|
|
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
|
2010-04-27 14:03:47 +00:00
|
|
|
|
|
|
|
if (data_size < 14)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2011-03-15 08:14:38 +00:00
|
|
|
avio_skip(pb, 12);
|
2011-02-21 15:43:01 +00:00
|
|
|
st->codec->sample_rate = avio_rb16(pb);
|
2010-04-27 14:03:47 +00:00
|
|
|
if (data_size >= 16) {
|
2011-03-15 08:14:38 +00:00
|
|
|
avio_skip(pb, 1);
|
2011-05-10 13:33:36 +00:00
|
|
|
iff->svx8_compression = avio_r8(pb);
|
2010-04-27 14:03:47 +00:00
|
|
|
}
|
2008-03-30 19:17:01 +00:00
|
|
|
break;
|
|
|
|
|
2012-11-29 10:45:28 +00:00
|
|
|
case ID_MHDR:
|
|
|
|
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
|
|
|
|
|
|
|
|
if (data_size < 32)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
avio_skip(pb, 4);
|
|
|
|
iff->maud_bits = avio_rb16(pb);
|
|
|
|
avio_skip(pb, 2);
|
|
|
|
num = avio_rb32(pb);
|
|
|
|
den = avio_rb16(pb);
|
|
|
|
if (!den)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
avio_skip(pb, 2);
|
|
|
|
st->codec->sample_rate = num / den;
|
|
|
|
st->codec->channels = avio_rb16(pb);
|
|
|
|
iff->maud_compression = avio_rb16(pb);
|
|
|
|
if (st->codec->channels == 1)
|
|
|
|
st->codec->channel_layout = AV_CH_LAYOUT_MONO;
|
|
|
|
else if (st->codec->channels == 2)
|
|
|
|
st->codec->channel_layout = AV_CH_LAYOUT_STEREO;
|
|
|
|
break;
|
|
|
|
|
2011-11-21 19:31:47 +00:00
|
|
|
case ID_ABIT:
|
2008-03-30 19:17:01 +00:00
|
|
|
case ID_BODY:
|
2012-03-08 22:34:36 +00:00
|
|
|
case ID_DBOD:
|
2012-11-29 10:45:28 +00:00
|
|
|
case ID_MDAT:
|
2011-03-03 19:11:45 +00:00
|
|
|
iff->body_pos = avio_tell(pb);
|
2013-01-05 20:37:49 +00:00
|
|
|
iff->body_end = iff->body_pos + data_size;
|
2008-03-30 19:17:01 +00:00
|
|
|
iff->body_size = data_size;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_CHAN:
|
2010-04-27 14:03:47 +00:00
|
|
|
if (data_size < 4)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2012-04-07 18:05:45 +00:00
|
|
|
if (avio_rb32(pb) < 6) {
|
|
|
|
st->codec->channels = 1;
|
|
|
|
st->codec->channel_layout = AV_CH_LAYOUT_MONO;
|
|
|
|
} else {
|
|
|
|
st->codec->channels = 2;
|
|
|
|
st->codec->channel_layout = AV_CH_LAYOUT_STEREO;
|
|
|
|
}
|
2008-03-30 19:17:01 +00:00
|
|
|
break;
|
|
|
|
|
2011-04-20 11:56:56 +00:00
|
|
|
case ID_CAMG:
|
|
|
|
if (data_size < 4)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
screenmode = avio_rb32(pb);
|
|
|
|
break;
|
|
|
|
|
2010-02-03 09:57:21 +00:00
|
|
|
case ID_CMAP:
|
2013-03-17 19:22:19 +00:00
|
|
|
if (data_size < 3 || data_size > 768 || data_size % 3) {
|
2014-03-10 14:35:59 +00:00
|
|
|
av_log(s, AV_LOG_ERROR, "Invalid CMAP chunk size %"PRIu32"\n",
|
2013-03-17 19:22:19 +00:00
|
|
|
data_size);
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2011-04-20 11:56:56 +00:00
|
|
|
st->codec->extradata_size = data_size + IFF_EXTRA_VIDEO_SIZE;
|
|
|
|
st->codec->extradata = av_malloc(data_size + IFF_EXTRA_VIDEO_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
|
2010-02-03 09:57:21 +00:00
|
|
|
if (!st->codec->extradata)
|
|
|
|
return AVERROR(ENOMEM);
|
2011-04-20 11:56:56 +00:00
|
|
|
if (avio_read(pb, st->codec->extradata + IFF_EXTRA_VIDEO_SIZE, data_size) < 0)
|
2010-02-03 09:57:21 +00:00
|
|
|
return AVERROR(EIO);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_BMHD:
|
2010-03-30 23:30:55 +00:00
|
|
|
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
|
2010-04-27 14:03:47 +00:00
|
|
|
if (data_size <= 8)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2011-02-21 15:43:01 +00:00
|
|
|
st->codec->width = avio_rb16(pb);
|
|
|
|
st->codec->height = avio_rb16(pb);
|
2011-03-15 08:14:38 +00:00
|
|
|
avio_skip(pb, 4); // x, y offset
|
2011-02-21 15:43:01 +00:00
|
|
|
st->codec->bits_per_coded_sample = avio_r8(pb);
|
2011-04-20 11:56:56 +00:00
|
|
|
if (data_size >= 10)
|
|
|
|
masking = avio_r8(pb);
|
|
|
|
if (data_size >= 11)
|
2011-05-10 13:33:36 +00:00
|
|
|
iff->bitmap_compression = avio_r8(pb);
|
2011-04-20 11:56:56 +00:00
|
|
|
if (data_size >= 14) {
|
|
|
|
avio_skip(pb, 1); // padding
|
|
|
|
transparency = avio_rb16(pb);
|
2010-04-27 14:03:47 +00:00
|
|
|
}
|
|
|
|
if (data_size >= 16) {
|
2011-02-21 15:43:01 +00:00
|
|
|
st->sample_aspect_ratio.num = avio_r8(pb);
|
|
|
|
st->sample_aspect_ratio.den = avio_r8(pb);
|
2010-04-27 14:03:47 +00:00
|
|
|
}
|
2010-02-03 09:57:21 +00:00
|
|
|
break;
|
|
|
|
|
2012-03-08 22:34:36 +00:00
|
|
|
case ID_DPEL:
|
|
|
|
if (data_size < 4 || (data_size & 3))
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
if ((fmt_size = avio_read(pb, fmt, sizeof(fmt))) < 0)
|
|
|
|
return fmt_size;
|
|
|
|
if (fmt_size == sizeof(deep_rgb24) && !memcmp(fmt, deep_rgb24, sizeof(deep_rgb24)))
|
2012-10-08 18:54:00 +00:00
|
|
|
st->codec->pix_fmt = AV_PIX_FMT_RGB24;
|
2012-03-08 22:34:36 +00:00
|
|
|
else if (fmt_size == sizeof(deep_rgba) && !memcmp(fmt, deep_rgba, sizeof(deep_rgba)))
|
2012-10-08 18:54:00 +00:00
|
|
|
st->codec->pix_fmt = AV_PIX_FMT_RGBA;
|
2012-11-18 08:01:41 +00:00
|
|
|
else if (fmt_size == sizeof(deep_bgra) && !memcmp(fmt, deep_bgra, sizeof(deep_bgra)))
|
|
|
|
st->codec->pix_fmt = AV_PIX_FMT_BGRA;
|
|
|
|
else if (fmt_size == sizeof(deep_argb) && !memcmp(fmt, deep_argb, sizeof(deep_argb)))
|
|
|
|
st->codec->pix_fmt = AV_PIX_FMT_ARGB;
|
|
|
|
else if (fmt_size == sizeof(deep_abgr) && !memcmp(fmt, deep_abgr, sizeof(deep_abgr)))
|
|
|
|
st->codec->pix_fmt = AV_PIX_FMT_ABGR;
|
2012-03-08 22:34:36 +00:00
|
|
|
else {
|
2013-03-15 17:13:52 +00:00
|
|
|
avpriv_request_sample(s, "color format %.16s", fmt);
|
2012-03-08 22:34:36 +00:00
|
|
|
return AVERROR_PATCHWELCOME;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_DGBL:
|
|
|
|
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
|
|
|
|
if (data_size < 8)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
st->codec->width = avio_rb16(pb);
|
|
|
|
st->codec->height = avio_rb16(pb);
|
|
|
|
iff->bitmap_compression = avio_rb16(pb);
|
|
|
|
st->sample_aspect_ratio.num = avio_r8(pb);
|
|
|
|
st->sample_aspect_ratio.den = avio_r8(pb);
|
|
|
|
st->codec->bits_per_coded_sample = 24;
|
|
|
|
break;
|
|
|
|
|
2012-11-18 08:02:03 +00:00
|
|
|
case ID_DLOC:
|
|
|
|
if (data_size < 4)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
st->codec->width = avio_rb16(pb);
|
|
|
|
st->codec->height = avio_rb16(pb);
|
|
|
|
break;
|
|
|
|
|
2012-11-25 04:12:56 +00:00
|
|
|
case ID_TVDC:
|
|
|
|
if (data_size < sizeof(iff->tvdc))
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
res = avio_read(pb, iff->tvdc, sizeof(iff->tvdc));
|
|
|
|
if (res < 0)
|
|
|
|
return res;
|
|
|
|
break;
|
|
|
|
|
2010-02-16 09:55:56 +00:00
|
|
|
case ID_ANNO:
|
2011-05-13 21:28:18 +00:00
|
|
|
case ID_TEXT: metadata_tag = "comment"; break;
|
|
|
|
case ID_AUTH: metadata_tag = "artist"; break;
|
|
|
|
case ID_COPYRIGHT: metadata_tag = "copyright"; break;
|
|
|
|
case ID_NAME: metadata_tag = "title"; break;
|
2008-03-30 19:17:01 +00:00
|
|
|
}
|
2010-04-27 14:03:47 +00:00
|
|
|
|
2010-05-05 17:26:59 +00:00
|
|
|
if (metadata_tag) {
|
|
|
|
if ((res = get_metadata(s, metadata_tag, data_size)) < 0) {
|
2012-09-01 10:35:14 +00:00
|
|
|
av_log(s, AV_LOG_ERROR, "cannot allocate metadata tag %s!\n", metadata_tag);
|
2010-05-05 17:26:59 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
2011-03-15 08:14:38 +00:00
|
|
|
avio_skip(pb, data_size - (avio_tell(pb) - orig_pos) + (data_size & 1));
|
2008-03-30 19:17:01 +00:00
|
|
|
}
|
|
|
|
|
2011-02-28 13:57:54 +00:00
|
|
|
avio_seek(pb, iff->body_pos, SEEK_SET);
|
2010-04-27 14:03:47 +00:00
|
|
|
|
2010-02-03 09:57:21 +00:00
|
|
|
switch(st->codec->codec_type) {
|
2010-03-30 23:30:55 +00:00
|
|
|
case AVMEDIA_TYPE_AUDIO:
|
2011-11-29 18:28:15 +00:00
|
|
|
avpriv_set_pts_info(st, 32, 1, st->codec->sample_rate);
|
2008-03-30 19:17:01 +00:00
|
|
|
|
2012-11-28 15:53:25 +00:00
|
|
|
if (st->codec->codec_tag == ID_16SV)
|
|
|
|
st->codec->codec_id = AV_CODEC_ID_PCM_S16BE_PLANAR;
|
2012-11-29 10:45:28 +00:00
|
|
|
else if (st->codec->codec_tag == ID_MAUD) {
|
|
|
|
if (iff->maud_bits == 8 && !iff->maud_compression) {
|
|
|
|
st->codec->codec_id = AV_CODEC_ID_PCM_U8;
|
|
|
|
} else if (iff->maud_bits == 16 && !iff->maud_compression) {
|
|
|
|
st->codec->codec_id = AV_CODEC_ID_PCM_S16BE;
|
|
|
|
} else if (iff->maud_bits == 8 && iff->maud_compression == 2) {
|
|
|
|
st->codec->codec_id = AV_CODEC_ID_PCM_ALAW;
|
|
|
|
} else if (iff->maud_bits == 8 && iff->maud_compression == 3) {
|
|
|
|
st->codec->codec_id = AV_CODEC_ID_PCM_MULAW;
|
|
|
|
} else {
|
2013-03-15 17:13:52 +00:00
|
|
|
avpriv_request_sample(s, "compression %d and bit depth %d", iff->maud_compression, iff->maud_bits);
|
2012-11-29 10:45:28 +00:00
|
|
|
return AVERROR_PATCHWELCOME;
|
|
|
|
}
|
|
|
|
} else {
|
2014-04-13 04:45:10 +00:00
|
|
|
switch (iff->svx8_compression) {
|
|
|
|
case COMP_NONE:
|
|
|
|
st->codec->codec_id = AV_CODEC_ID_PCM_S8_PLANAR;
|
|
|
|
break;
|
|
|
|
case COMP_FIB:
|
|
|
|
st->codec->codec_id = AV_CODEC_ID_8SVX_FIB;
|
|
|
|
break;
|
|
|
|
case COMP_EXP:
|
|
|
|
st->codec->codec_id = AV_CODEC_ID_8SVX_EXP;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
av_log(s, AV_LOG_ERROR,
|
|
|
|
"Unknown SVX8 compression method '%d'\n", iff->svx8_compression);
|
|
|
|
return -1;
|
|
|
|
}
|
2012-11-28 15:53:25 +00:00
|
|
|
}
|
2008-03-30 19:17:01 +00:00
|
|
|
|
2012-11-28 15:53:25 +00:00
|
|
|
st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id);
|
2010-04-20 18:40:45 +00:00
|
|
|
st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * st->codec->bits_per_coded_sample;
|
|
|
|
st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample;
|
|
|
|
break;
|
2010-02-03 09:57:21 +00:00
|
|
|
|
2010-03-30 23:30:55 +00:00
|
|
|
case AVMEDIA_TYPE_VIDEO:
|
2011-04-20 11:56:56 +00:00
|
|
|
iff->bpp = st->codec->bits_per_coded_sample;
|
|
|
|
if ((screenmode & 0x800 /* Hold And Modify */) && iff->bpp <= 8) {
|
|
|
|
iff->ham = iff->bpp > 6 ? 6 : 4;
|
|
|
|
st->codec->bits_per_coded_sample = 24;
|
|
|
|
}
|
|
|
|
iff->flags = (screenmode & 0x80 /* Extra HalfBrite */) && iff->bpp <= 8;
|
|
|
|
iff->masking = masking;
|
|
|
|
iff->transparency = transparency;
|
|
|
|
|
|
|
|
if (!st->codec->extradata) {
|
|
|
|
st->codec->extradata_size = IFF_EXTRA_VIDEO_SIZE;
|
|
|
|
st->codec->extradata = av_malloc(IFF_EXTRA_VIDEO_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
|
|
|
|
if (!st->codec->extradata)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
}
|
2013-03-05 00:35:28 +00:00
|
|
|
av_assert0(st->codec->extradata_size >= IFF_EXTRA_VIDEO_SIZE);
|
2011-04-20 11:56:56 +00:00
|
|
|
buf = st->codec->extradata;
|
|
|
|
bytestream_put_be16(&buf, IFF_EXTRA_VIDEO_SIZE);
|
2011-05-10 13:33:36 +00:00
|
|
|
bytestream_put_byte(&buf, iff->bitmap_compression);
|
2011-04-20 11:56:56 +00:00
|
|
|
bytestream_put_byte(&buf, iff->bpp);
|
|
|
|
bytestream_put_byte(&buf, iff->ham);
|
|
|
|
bytestream_put_byte(&buf, iff->flags);
|
|
|
|
bytestream_put_be16(&buf, iff->transparency);
|
|
|
|
bytestream_put_byte(&buf, iff->masking);
|
2012-11-25 04:12:56 +00:00
|
|
|
bytestream_put_buffer(&buf, iff->tvdc, sizeof(iff->tvdc));
|
2012-11-22 09:42:37 +00:00
|
|
|
st->codec->codec_id = AV_CODEC_ID_IFF_ILBM;
|
2010-02-03 09:57:21 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
2008-03-30 19:17:01 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int iff_read_packet(AVFormatContext *s,
|
|
|
|
AVPacket *pkt)
|
|
|
|
{
|
|
|
|
IffDemuxContext *iff = s->priv_data;
|
2011-02-20 10:04:12 +00:00
|
|
|
AVIOContext *pb = s->pb;
|
2010-02-03 09:57:21 +00:00
|
|
|
AVStream *st = s->streams[0];
|
2008-03-30 19:17:01 +00:00
|
|
|
int ret;
|
2013-01-05 20:37:49 +00:00
|
|
|
int64_t pos = avio_tell(pb);
|
2008-03-30 19:17:01 +00:00
|
|
|
|
2013-01-05 20:37:49 +00:00
|
|
|
if (pos >= iff->body_end)
|
2011-09-07 19:28:07 +00:00
|
|
|
return AVERROR_EOF;
|
2008-05-09 11:25:27 +00:00
|
|
|
|
2011-05-15 11:24:46 +00:00
|
|
|
if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
|
2012-11-29 10:45:28 +00:00
|
|
|
if (st->codec->codec_tag == ID_MAUD) {
|
2013-01-05 20:37:49 +00:00
|
|
|
ret = av_get_packet(pb, pkt, FFMIN(iff->body_end - pos, 1024 * st->codec->block_align));
|
2012-11-29 10:45:28 +00:00
|
|
|
} else {
|
|
|
|
ret = av_get_packet(pb, pkt, iff->body_size);
|
|
|
|
}
|
2010-05-09 20:10:48 +00:00
|
|
|
} else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
|
2011-04-20 11:56:56 +00:00
|
|
|
uint8_t *buf;
|
|
|
|
|
|
|
|
if (av_new_packet(pkt, iff->body_size + 2) < 0) {
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = pkt->data;
|
|
|
|
bytestream_put_be16(&buf, 2);
|
|
|
|
ret = avio_read(pb, buf, iff->body_size);
|
2013-12-15 00:32:48 +00:00
|
|
|
if (ret<0) {
|
|
|
|
av_free_packet(pkt);
|
|
|
|
} else if (ret < iff->body_size)
|
2013-12-15 00:32:48 +00:00
|
|
|
av_shrink_packet(pkt, ret + 2);
|
2011-05-29 19:02:20 +00:00
|
|
|
} else {
|
2012-08-10 14:26:39 +00:00
|
|
|
av_assert0(0);
|
2008-05-09 11:25:27 +00:00
|
|
|
}
|
2008-03-30 19:17:01 +00:00
|
|
|
|
2013-01-05 20:37:49 +00:00
|
|
|
if (pos == iff->body_pos)
|
2010-03-31 12:29:58 +00:00
|
|
|
pkt->flags |= AV_PKT_FLAG_KEY;
|
2012-11-29 10:45:28 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2008-03-30 19:17:01 +00:00
|
|
|
pkt->stream_index = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-01-25 22:03:28 +00:00
|
|
|
AVInputFormat ff_iff_demuxer = {
|
2012-05-19 16:13:17 +00:00
|
|
|
.name = "iff",
|
2012-07-24 01:23:48 +00:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("IFF (Interchange File Format)"),
|
2011-07-16 20:18:12 +00:00
|
|
|
.priv_data_size = sizeof(IffDemuxContext),
|
|
|
|
.read_probe = iff_probe,
|
|
|
|
.read_header = iff_read_header,
|
|
|
|
.read_packet = iff_read_packet,
|
2013-06-20 19:49:02 +00:00
|
|
|
.flags = AVFMT_GENERIC_INDEX | AVFMT_NO_BYTE_SEEK,
|
2008-03-30 19:17:01 +00:00
|
|
|
};
|