2008-03-30 22:17:01 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008 Jaikrishnan Menon <realityman@gmx.net>
|
2010-02-03 11:57:21 +02:00
|
|
|
* Copyright (c) 2010 Peter Ross <pross@xvid.org>
|
2010-04-27 17:03:47 +03:00
|
|
|
* Copyright (c) 2010 Sebastian Vater <cdgs.basty@googlemail.com>
|
2008-03-30 22:17:01 +03: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 17:45:34 +03:00
|
|
|
* @file
|
2008-03-31 20:31:11 +03:00
|
|
|
* IFF file demuxer
|
2008-03-30 22:17:01 +03:00
|
|
|
* by Jaikrishnan Menon
|
|
|
|
* for more information on the .iff file format, visit:
|
|
|
|
* http://wiki.multimedia.cx/index.php?title=IFF
|
|
|
|
*/
|
|
|
|
|
2014-03-10 17:35:59 +03:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
2012-08-10 17:26:39 +03:00
|
|
|
#include "libavutil/avassert.h"
|
2012-04-07 21:05:45 +03:00
|
|
|
#include "libavutil/channel_layout.h"
|
2009-01-12 00:19:48 +02:00
|
|
|
#include "libavutil/intreadwrite.h"
|
2011-05-22 13:46:29 +03:00
|
|
|
#include "libavutil/dict.h"
|
2012-11-13 12:55:07 +03:00
|
|
|
#include "libavcodec/bytestream.h"
|
2008-03-30 22:17:01 +03:00
|
|
|
#include "avformat.h"
|
2014-04-18 09:00:15 +03:00
|
|
|
#include "id3v2.h"
|
2011-11-29 21:28:15 +03:00
|
|
|
#include "internal.h"
|
2008-03-30 22:17:01 +03:00
|
|
|
|
|
|
|
#define ID_8SVX MKTAG('8','S','V','X')
|
2012-11-28 18:53:25 +03:00
|
|
|
#define ID_16SV MKTAG('1','6','S','V')
|
2012-11-29 13:45:28 +03: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 22:17:01 +03: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 11:57:21 +02: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-09 01:34:36 +03:00
|
|
|
#define ID_DGBL MKTAG('D','G','B','L')
|
2011-04-20 14:56:56 +03:00
|
|
|
#define ID_CAMG MKTAG('C','A','M','G')
|
2010-02-03 11:57:21 +02:00
|
|
|
#define ID_CMAP MKTAG('C','M','A','P')
|
2011-11-21 22:31:47 +03:00
|
|
|
#define ID_ACBM MKTAG('A','C','B','M')
|
2012-03-09 01:34:36 +03:00
|
|
|
#define ID_DEEP MKTAG('D','E','E','P')
|
2012-11-30 02:42:15 +03:00
|
|
|
#define ID_RGB8 MKTAG('R','G','B','8')
|
|
|
|
#define ID_RGBN MKTAG('R','G','B','N')
|
2014-04-18 09:00:15 +03:00
|
|
|
#define ID_DSD MKTAG('D','S','D',' ')
|
2016-05-05 21:21:27 +02:00
|
|
|
#define ID_DST MKTAG('D','S','T',' ')
|
|
|
|
#define ID_DSTC MKTAG('D','S','T','C')
|
|
|
|
#define ID_DSTF MKTAG('D','S','T','F')
|
|
|
|
#define ID_FRTE MKTAG('F','R','T','E')
|
2014-08-18 16:36:05 +03:00
|
|
|
#define ID_ANIM MKTAG('A','N','I','M')
|
2016-05-10 23:48:50 +02:00
|
|
|
#define ID_ANHD MKTAG('A','N','H','D')
|
|
|
|
#define ID_DLTA MKTAG('D','L','T','A')
|
2016-05-19 12:42:41 +02:00
|
|
|
#define ID_DPAN MKTAG('D','P','A','N')
|
2008-03-30 22:17:01 +03:00
|
|
|
|
|
|
|
#define ID_FORM MKTAG('F','O','R','M')
|
2014-04-18 09:00:15 +03:00
|
|
|
#define ID_FRM8 MKTAG('F','R','M','8')
|
2008-03-30 22:17:01 +03:00
|
|
|
#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 22:31:47 +03:00
|
|
|
#define ID_ABIT MKTAG('A','B','I','T')
|
2008-03-30 22:17:01 +03:00
|
|
|
#define ID_BODY MKTAG('B','O','D','Y')
|
2012-03-09 01:34:36 +03:00
|
|
|
#define ID_DBOD MKTAG('D','B','O','D')
|
|
|
|
#define ID_DPEL MKTAG('D','P','E','L')
|
2012-11-18 11:02:03 +03:00
|
|
|
#define ID_DLOC MKTAG('D','L','O','C')
|
2012-11-25 07:12:56 +03:00
|
|
|
#define ID_TVDC MKTAG('T','V','D','C')
|
2008-03-30 22:17:01 +03:00
|
|
|
|
|
|
|
#define LEFT 2
|
|
|
|
#define RIGHT 4
|
|
|
|
#define STEREO 6
|
|
|
|
|
2011-04-20 14:56:56 +03: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 07:12:56 +03:00
|
|
|
#define IFF_EXTRA_VIDEO_SIZE 41
|
2011-04-20 14:56:56 +03:00
|
|
|
|
2010-04-20 21:40:45 +03:00
|
|
|
typedef enum {
|
|
|
|
COMP_NONE,
|
|
|
|
COMP_FIB,
|
|
|
|
COMP_EXP
|
|
|
|
} svx8_compression_type;
|
|
|
|
|
2014-09-22 10:19:33 +03:00
|
|
|
typedef struct IffDemuxContext {
|
2014-04-18 09:00:15 +03:00
|
|
|
int is_64bit; ///< chunk size is 64-bit
|
2013-01-05 23:37:49 +03:00
|
|
|
int64_t body_pos;
|
|
|
|
int64_t body_end;
|
2008-03-30 22:17:01 +03:00
|
|
|
uint32_t body_size;
|
2011-05-10 16:33:36 +03:00
|
|
|
svx8_compression_type svx8_compression;
|
2012-11-29 13:45:28 +03:00
|
|
|
unsigned maud_bits;
|
|
|
|
unsigned maud_compression;
|
2012-11-22 12:42:37 +03:00
|
|
|
unsigned bitmap_compression; ///< delta compression method used
|
2011-04-20 14:56:56 +03: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 07:12:56 +03:00
|
|
|
uint8_t tvdc[32]; ///< TVDC lookup table
|
2016-05-10 23:48:50 +02:00
|
|
|
int64_t pts;
|
2008-03-30 22:17:01 +03:00
|
|
|
} IffDemuxContext;
|
|
|
|
|
2010-05-05 20:26:59 +03: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-29 02:57:15 +03:00
|
|
|
if (avio_read(s->pb, buf, data_size) != data_size) {
|
2010-05-05 20:26:59 +03:00
|
|
|
av_free(buf);
|
|
|
|
return AVERROR(EIO);
|
|
|
|
}
|
|
|
|
buf[data_size] = 0;
|
2011-05-22 13:46:29 +03:00
|
|
|
av_dict_set(&s->metadata, tag, buf, AV_DICT_DONT_STRDUP_VAL);
|
2010-05-05 20:26:59 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-21 02:18:37 +02:00
|
|
|
static int iff_probe(const AVProbeData *p)
|
2008-03-30 22:17:01 +03:00
|
|
|
{
|
|
|
|
const uint8_t *d = p->buf;
|
|
|
|
|
2014-04-18 09:00:15 +03:00
|
|
|
if ( (AV_RL32(d) == ID_FORM &&
|
2012-07-24 00:15:23 +03:00
|
|
|
(AV_RL32(d+8) == ID_8SVX ||
|
2012-11-28 18:53:25 +03:00
|
|
|
AV_RL32(d+8) == ID_16SV ||
|
2012-11-29 13:45:28 +03:00
|
|
|
AV_RL32(d+8) == ID_MAUD ||
|
2012-07-24 00:15:23 +03:00
|
|
|
AV_RL32(d+8) == ID_PBM ||
|
|
|
|
AV_RL32(d+8) == ID_ACBM ||
|
|
|
|
AV_RL32(d+8) == ID_DEEP ||
|
2012-11-30 02:42:15 +03:00
|
|
|
AV_RL32(d+8) == ID_ILBM ||
|
|
|
|
AV_RL32(d+8) == ID_RGB8 ||
|
2014-08-18 16:36:05 +03:00
|
|
|
AV_RL32(d+8) == ID_ANIM ||
|
2014-04-18 09:00:15 +03:00
|
|
|
AV_RL32(d+8) == ID_RGBN)) ||
|
|
|
|
(AV_RL32(d) == ID_FRM8 && AV_RL32(d+12) == ID_DSD))
|
2008-03-30 22:17:01 +03:00
|
|
|
return AVPROBE_SCORE_MAX;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-04-18 09:00:15 +03:00
|
|
|
static const AVCodecTag dsd_codec_tags[] = {
|
|
|
|
{ AV_CODEC_ID_DSD_MSBF, ID_DSD },
|
2016-05-05 21:21:27 +02:00
|
|
|
{ AV_CODEC_ID_DST, ID_DST },
|
2014-04-18 09:00:15 +03:00
|
|
|
{ AV_CODEC_ID_NONE, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define DSD_SLFT MKTAG('S','L','F','T')
|
|
|
|
#define DSD_SRGT MKTAG('S','R','G','T')
|
|
|
|
#define DSD_MLFT MKTAG('M','L','F','T')
|
|
|
|
#define DSD_MRGT MKTAG('M','R','G','T')
|
|
|
|
#define DSD_C MKTAG('C',' ',' ',' ')
|
|
|
|
#define DSD_LS MKTAG('L','S',' ',' ')
|
|
|
|
#define DSD_RS MKTAG('R','S',' ',' ')
|
|
|
|
#define DSD_LFE MKTAG('L','F','E',' ')
|
|
|
|
|
|
|
|
static const uint32_t dsd_stereo[] = { DSD_SLFT, DSD_SRGT };
|
|
|
|
static const uint32_t dsd_5point0[] = { DSD_MLFT, DSD_MRGT, DSD_C, DSD_LS, DSD_RS };
|
|
|
|
static const uint32_t dsd_5point1[] = { DSD_MLFT, DSD_MRGT, DSD_C, DSD_LFE, DSD_LS, DSD_RS };
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint64_t layout;
|
|
|
|
const uint32_t * dsd_layout;
|
|
|
|
} DSDLayoutDesc;
|
|
|
|
|
|
|
|
static const DSDLayoutDesc dsd_channel_layout[] = {
|
|
|
|
{ AV_CH_LAYOUT_STEREO, dsd_stereo },
|
|
|
|
{ AV_CH_LAYOUT_5POINT0, dsd_5point0 },
|
|
|
|
{ AV_CH_LAYOUT_5POINT1, dsd_5point1 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const uint64_t dsd_loudspeaker_config[] = {
|
|
|
|
AV_CH_LAYOUT_STEREO,
|
|
|
|
0, 0,
|
|
|
|
AV_CH_LAYOUT_5POINT0, AV_CH_LAYOUT_5POINT1,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * dsd_source_comment[] = {
|
|
|
|
"dsd_source_comment",
|
|
|
|
"analogue_source_comment",
|
|
|
|
"pcm_source_comment",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * dsd_history_comment[] = {
|
|
|
|
"general_remark",
|
|
|
|
"operator_name",
|
|
|
|
"creating_machine",
|
|
|
|
"timezone",
|
|
|
|
"file_revision"
|
|
|
|
};
|
|
|
|
|
|
|
|
static int parse_dsd_diin(AVFormatContext *s, AVStream *st, uint64_t eof)
|
|
|
|
{
|
|
|
|
AVIOContext *pb = s->pb;
|
|
|
|
|
2016-04-30 18:06:53 +02:00
|
|
|
while (avio_tell(pb) + 12 <= eof && !avio_feof(pb)) {
|
2014-04-18 09:00:15 +03:00
|
|
|
uint32_t tag = avio_rl32(pb);
|
|
|
|
uint64_t size = avio_rb64(pb);
|
|
|
|
uint64_t orig_pos = avio_tell(pb);
|
|
|
|
const char * metadata_tag = NULL;
|
|
|
|
|
|
|
|
switch(tag) {
|
|
|
|
case MKTAG('D','I','A','R'): metadata_tag = "artist"; break;
|
|
|
|
case MKTAG('D','I','T','I'): metadata_tag = "title"; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (metadata_tag && size > 4) {
|
|
|
|
unsigned int tag_size = avio_rb32(pb);
|
|
|
|
int ret = get_metadata(s, metadata_tag, FFMIN(tag_size, size - 4));
|
|
|
|
if (ret < 0) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "cannot allocate metadata tag %s!\n", metadata_tag);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
avio_skip(pb, size - (avio_tell(pb) - orig_pos) + (size & 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_dsd_prop(AVFormatContext *s, AVStream *st, uint64_t eof)
|
|
|
|
{
|
|
|
|
AVIOContext *pb = s->pb;
|
|
|
|
char abss[24];
|
|
|
|
int hour, min, sec, i, ret, config;
|
|
|
|
int dsd_layout[6];
|
|
|
|
ID3v2ExtraMeta *id3v2_extra_meta;
|
|
|
|
|
2016-04-30 18:06:53 +02:00
|
|
|
while (avio_tell(pb) + 12 <= eof && !avio_feof(pb)) {
|
2014-04-18 09:00:15 +03:00
|
|
|
uint32_t tag = avio_rl32(pb);
|
|
|
|
uint64_t size = avio_rb64(pb);
|
|
|
|
uint64_t orig_pos = avio_tell(pb);
|
|
|
|
|
|
|
|
switch(tag) {
|
|
|
|
case MKTAG('A','B','S','S'):
|
|
|
|
if (size < 8)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
hour = avio_rb16(pb);
|
|
|
|
min = avio_r8(pb);
|
|
|
|
sec = avio_r8(pb);
|
|
|
|
snprintf(abss, sizeof(abss), "%02dh:%02dm:%02ds:%d", hour, min, sec, avio_rb32(pb));
|
|
|
|
av_dict_set(&st->metadata, "absolute_start_time", abss, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MKTAG('C','H','N','L'):
|
|
|
|
if (size < 2)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->channels = avio_rb16(pb);
|
|
|
|
if (size < 2 + st->codecpar->channels * 4)
|
2014-04-18 09:00:15 +03:00
|
|
|
return AVERROR_INVALIDDATA;
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->channel_layout = 0;
|
|
|
|
if (st->codecpar->channels > FF_ARRAY_ELEMS(dsd_layout)) {
|
2014-04-18 09:00:15 +03:00
|
|
|
avpriv_request_sample(s, "channel layout");
|
|
|
|
break;
|
|
|
|
}
|
2016-04-10 21:58:15 +02:00
|
|
|
for (i = 0; i < st->codecpar->channels; i++)
|
2014-04-18 09:00:15 +03:00
|
|
|
dsd_layout[i] = avio_rl32(pb);
|
|
|
|
for (i = 0; i < FF_ARRAY_ELEMS(dsd_channel_layout); i++) {
|
|
|
|
const DSDLayoutDesc * d = &dsd_channel_layout[i];
|
2016-04-10 21:58:15 +02:00
|
|
|
if (av_get_channel_layout_nb_channels(d->layout) == st->codecpar->channels &&
|
|
|
|
!memcmp(d->dsd_layout, dsd_layout, st->codecpar->channels * sizeof(uint32_t))) {
|
|
|
|
st->codecpar->channel_layout = d->layout;
|
2014-04-18 09:00:15 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MKTAG('C','M','P','R'):
|
|
|
|
if (size < 4)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2016-05-05 21:21:27 +02:00
|
|
|
st->codecpar->codec_tag = tag = avio_rl32(pb);
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->codec_id = ff_codec_get_id(dsd_codec_tags, tag);
|
|
|
|
if (!st->codecpar->codec_id) {
|
2017-03-27 09:45:35 +02:00
|
|
|
av_log(s, AV_LOG_ERROR, "'%s' compression is not supported\n",
|
|
|
|
av_fourcc2str(tag));
|
2014-09-26 08:44:46 +03:00
|
|
|
return AVERROR_PATCHWELCOME;
|
|
|
|
}
|
2014-04-18 09:00:15 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MKTAG('F','S',' ',' '):
|
|
|
|
if (size < 4)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->sample_rate = avio_rb32(pb) / 8;
|
2014-04-18 09:00:15 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MKTAG('I','D','3',' '):
|
|
|
|
id3v2_extra_meta = NULL;
|
|
|
|
ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta, size);
|
|
|
|
if (id3v2_extra_meta) {
|
2017-10-05 03:34:19 +02:00
|
|
|
if ((ret = ff_id3v2_parse_apic(s, &id3v2_extra_meta)) < 0 ||
|
|
|
|
(ret = ff_id3v2_parse_chapters(s, &id3v2_extra_meta)) < 0) {
|
2014-04-18 09:00:15 +03:00
|
|
|
ff_id3v2_free_extra_meta(&id3v2_extra_meta);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ff_id3v2_free_extra_meta(&id3v2_extra_meta);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size < avio_tell(pb) - orig_pos) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "id3 exceeds chunk size\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MKTAG('L','S','C','O'):
|
|
|
|
if (size < 2)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
config = avio_rb16(pb);
|
|
|
|
if (config != 0xFFFF) {
|
|
|
|
if (config < FF_ARRAY_ELEMS(dsd_loudspeaker_config))
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->channel_layout = dsd_loudspeaker_config[config];
|
|
|
|
if (!st->codecpar->channel_layout)
|
2014-04-18 09:00:15 +03:00
|
|
|
avpriv_request_sample(s, "loudspeaker configuration %d", config);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
avio_skip(pb, size - (avio_tell(pb) - orig_pos) + (size & 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-05 21:21:27 +02:00
|
|
|
static int read_dst_frame(AVFormatContext *s, AVPacket *pkt)
|
|
|
|
{
|
|
|
|
IffDemuxContext *iff = s->priv_data;
|
|
|
|
AVIOContext *pb = s->pb;
|
|
|
|
uint32_t chunk_id;
|
|
|
|
uint64_t chunk_pos, data_pos, data_size;
|
|
|
|
int ret = AVERROR_EOF;
|
|
|
|
|
|
|
|
while (!avio_feof(pb)) {
|
|
|
|
chunk_pos = avio_tell(pb);
|
|
|
|
if (chunk_pos >= iff->body_end)
|
|
|
|
return AVERROR_EOF;
|
|
|
|
|
|
|
|
chunk_id = avio_rl32(pb);
|
|
|
|
data_size = iff->is_64bit ? avio_rb64(pb) : avio_rb32(pb);
|
|
|
|
data_pos = avio_tell(pb);
|
|
|
|
|
|
|
|
if (data_size < 1)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
switch (chunk_id) {
|
|
|
|
case ID_DSTF:
|
|
|
|
if (!pkt) {
|
|
|
|
iff->body_pos = avio_tell(pb) - (iff->is_64bit ? 12 : 8);
|
|
|
|
iff->body_size = iff->body_end - iff->body_pos;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ret = av_get_packet(pb, pkt, data_size);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
if (data_size & 1)
|
|
|
|
avio_skip(pb, 1);
|
|
|
|
pkt->flags |= AV_PKT_FLAG_KEY;
|
|
|
|
pkt->stream_index = 0;
|
|
|
|
pkt->duration = 588 * s->streams[0]->codecpar->sample_rate / 44100;
|
|
|
|
pkt->pos = chunk_pos;
|
|
|
|
|
|
|
|
chunk_pos = avio_tell(pb);
|
|
|
|
if (chunk_pos >= iff->body_end)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
avio_seek(pb, chunk_pos, SEEK_SET);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case ID_FRTE:
|
|
|
|
if (data_size < 4)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
s->streams[0]->duration = avio_rb32(pb) * 588LL * s->streams[0]->codecpar->sample_rate / 44100;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
avio_skip(pb, data_size - (avio_tell(pb) - data_pos) + (data_size & 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-03-09 01:34:36 +03: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 11:01:41 +03: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-09 01:34:36 +03:00
|
|
|
|
2012-01-12 15:20:36 +03:00
|
|
|
static int iff_read_header(AVFormatContext *s)
|
2008-03-30 22:17:01 +03:00
|
|
|
{
|
|
|
|
IffDemuxContext *iff = s->priv_data;
|
2011-02-20 12:04:12 +02:00
|
|
|
AVIOContext *pb = s->pb;
|
2008-03-30 22:17:01 +03:00
|
|
|
AVStream *st;
|
2011-04-20 14:56:56 +03:00
|
|
|
uint8_t *buf;
|
2014-04-18 09:00:15 +03:00
|
|
|
uint32_t chunk_id;
|
|
|
|
uint64_t data_size;
|
2012-11-29 13:45:28 +03:00
|
|
|
uint32_t screenmode = 0, num, den;
|
2011-04-20 14:56:56 +03:00
|
|
|
unsigned transparency = 0;
|
|
|
|
unsigned masking = 0; // no mask
|
2012-03-09 01:34:36 +03:00
|
|
|
uint8_t fmt[16];
|
|
|
|
int fmt_size;
|
2008-03-30 22:17:01 +03:00
|
|
|
|
2011-06-18 12:43:24 +03:00
|
|
|
st = avformat_new_stream(s, NULL);
|
2008-03-30 22:17:01 +03:00
|
|
|
if (!st)
|
2010-04-27 17:04:11 +03:00
|
|
|
return AVERROR(ENOMEM);
|
2008-03-30 22:17:01 +03:00
|
|
|
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 21:42:52 +03:00
|
|
|
st->codecpar->channels = 1;
|
|
|
|
st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
|
2014-04-18 09:00:15 +03:00
|
|
|
iff->is_64bit = avio_rl32(pb) == ID_FRM8;
|
|
|
|
avio_skip(pb, iff->is_64bit ? 8 : 4);
|
2010-02-03 11:57:21 +02:00
|
|
|
// codec_tag used by ByteRun1 decoder to distinguish progressive (PBM) and interlaced (ILBM) content
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 21:42:52 +03:00
|
|
|
st->codecpar->codec_tag = avio_rl32(pb);
|
2016-04-10 21:58:15 +02:00
|
|
|
if (st->codecpar->codec_tag == ID_ANIM) {
|
2016-05-10 23:48:50 +02:00
|
|
|
avio_skip(pb, 12);
|
2014-08-18 16:36:05 +03:00
|
|
|
}
|
2012-11-30 13:44:00 +03:00
|
|
|
iff->bitmap_compression = -1;
|
|
|
|
iff->svx8_compression = -1;
|
|
|
|
iff->maud_bits = -1;
|
|
|
|
iff->maud_compression = -1;
|
2008-03-30 22:17:01 +03:00
|
|
|
|
2014-08-07 23:12:41 +03:00
|
|
|
while(!avio_feof(pb)) {
|
2010-04-27 17:03:47 +03:00
|
|
|
uint64_t orig_pos;
|
2010-05-05 20:26:59 +03:00
|
|
|
int res;
|
|
|
|
const char *metadata_tag = NULL;
|
2014-04-18 09:00:15 +03:00
|
|
|
int version, nb_comments, i;
|
2011-02-21 17:43:01 +02:00
|
|
|
chunk_id = avio_rl32(pb);
|
2014-04-18 09:00:15 +03:00
|
|
|
data_size = iff->is_64bit ? avio_rb64(pb) : avio_rb32(pb);
|
2011-03-03 21:11:45 +02:00
|
|
|
orig_pos = avio_tell(pb);
|
2008-03-30 22:17:01 +03:00
|
|
|
|
|
|
|
switch(chunk_id) {
|
|
|
|
case ID_VHDR:
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 21:42:52 +03:00
|
|
|
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
|
2010-04-27 17:03:47 +03:00
|
|
|
|
|
|
|
if (data_size < 14)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2011-03-15 10:14:38 +02:00
|
|
|
avio_skip(pb, 12);
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 21:42:52 +03:00
|
|
|
st->codecpar->sample_rate = avio_rb16(pb);
|
2010-04-27 17:03:47 +03:00
|
|
|
if (data_size >= 16) {
|
2011-03-15 10:14:38 +02:00
|
|
|
avio_skip(pb, 1);
|
2011-05-10 16:33:36 +03:00
|
|
|
iff->svx8_compression = avio_r8(pb);
|
2010-04-27 17:03:47 +03:00
|
|
|
}
|
2008-03-30 22:17:01 +03:00
|
|
|
break;
|
|
|
|
|
2012-11-29 13:45:28 +03:00
|
|
|
case ID_MHDR:
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
|
2012-11-29 13:45:28 +03:00
|
|
|
|
|
|
|
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);
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->sample_rate = num / den;
|
|
|
|
st->codecpar->channels = avio_rb16(pb);
|
2012-11-29 13:45:28 +03:00
|
|
|
iff->maud_compression = avio_rb16(pb);
|
2016-04-10 21:58:15 +02:00
|
|
|
if (st->codecpar->channels == 1)
|
|
|
|
st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
|
|
|
|
else if (st->codecpar->channels == 2)
|
|
|
|
st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
|
2012-11-29 13:45:28 +03:00
|
|
|
break;
|
|
|
|
|
2011-11-21 22:31:47 +03:00
|
|
|
case ID_ABIT:
|
2008-03-30 22:17:01 +03:00
|
|
|
case ID_BODY:
|
2012-03-09 01:34:36 +03:00
|
|
|
case ID_DBOD:
|
2014-04-18 09:00:15 +03:00
|
|
|
case ID_DSD:
|
2016-05-05 21:21:27 +02:00
|
|
|
case ID_DST:
|
2012-11-29 13:45:28 +03:00
|
|
|
case ID_MDAT:
|
2011-03-03 21:11:45 +02:00
|
|
|
iff->body_pos = avio_tell(pb);
|
2013-01-05 23:37:49 +03:00
|
|
|
iff->body_end = iff->body_pos + data_size;
|
2008-03-30 22:17:01 +03:00
|
|
|
iff->body_size = data_size;
|
2016-05-05 21:21:27 +02:00
|
|
|
if (chunk_id == ID_DST) {
|
|
|
|
int ret = read_dst_frame(s, NULL);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
2008-03-30 22:17:01 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_CHAN:
|
2010-04-27 17:03:47 +03:00
|
|
|
if (data_size < 4)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2012-04-07 21:05:45 +03:00
|
|
|
if (avio_rb32(pb) < 6) {
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 21:42:52 +03:00
|
|
|
st->codecpar->channels = 1;
|
|
|
|
st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
|
2012-04-07 21:05:45 +03:00
|
|
|
} else {
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 21:42:52 +03:00
|
|
|
st->codecpar->channels = 2;
|
|
|
|
st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
|
2012-04-07 21:05:45 +03:00
|
|
|
}
|
2008-03-30 22:17:01 +03:00
|
|
|
break;
|
|
|
|
|
2011-04-20 14:56:56 +03:00
|
|
|
case ID_CAMG:
|
|
|
|
if (data_size < 4)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
screenmode = avio_rb32(pb);
|
|
|
|
break;
|
|
|
|
|
2010-02-03 11:57:21 +02:00
|
|
|
case ID_CMAP:
|
2013-03-17 22:22:19 +03:00
|
|
|
if (data_size < 3 || data_size > 768 || data_size % 3) {
|
2014-04-18 09:00:15 +03:00
|
|
|
av_log(s, AV_LOG_ERROR, "Invalid CMAP chunk size %"PRIu64"\n",
|
2013-03-17 22:22:19 +03:00
|
|
|
data_size);
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->extradata_size = data_size + IFF_EXTRA_VIDEO_SIZE;
|
|
|
|
st->codecpar->extradata = av_malloc(data_size + IFF_EXTRA_VIDEO_SIZE + AV_INPUT_BUFFER_PADDING_SIZE);
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 21:42:52 +03:00
|
|
|
if (!st->codecpar->extradata)
|
2010-02-03 11:57:21 +02:00
|
|
|
return AVERROR(ENOMEM);
|
2016-04-10 21:58:15 +02:00
|
|
|
if (avio_read(pb, st->codecpar->extradata + IFF_EXTRA_VIDEO_SIZE, data_size) < 0)
|
2010-02-03 11:57:21 +02:00
|
|
|
return AVERROR(EIO);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_BMHD:
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 21:42:52 +03:00
|
|
|
st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
|
2010-04-27 17:03:47 +03:00
|
|
|
if (data_size <= 8)
|
|
|
|
return AVERROR_INVALIDDATA;
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 21:42:52 +03:00
|
|
|
st->codecpar->width = avio_rb16(pb);
|
|
|
|
st->codecpar->height = avio_rb16(pb);
|
2011-03-15 10:14:38 +02:00
|
|
|
avio_skip(pb, 4); // x, y offset
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 21:42:52 +03:00
|
|
|
st->codecpar->bits_per_coded_sample = avio_r8(pb);
|
2011-04-20 14:56:56 +03:00
|
|
|
if (data_size >= 10)
|
|
|
|
masking = avio_r8(pb);
|
|
|
|
if (data_size >= 11)
|
2011-05-10 16:33:36 +03:00
|
|
|
iff->bitmap_compression = avio_r8(pb);
|
2011-04-20 14:56:56 +03:00
|
|
|
if (data_size >= 14) {
|
|
|
|
avio_skip(pb, 1); // padding
|
|
|
|
transparency = avio_rb16(pb);
|
2010-04-27 17:03:47 +03:00
|
|
|
}
|
|
|
|
if (data_size >= 16) {
|
2011-02-21 17:43:01 +02:00
|
|
|
st->sample_aspect_ratio.num = avio_r8(pb);
|
|
|
|
st->sample_aspect_ratio.den = avio_r8(pb);
|
2010-04-27 17:03:47 +03:00
|
|
|
}
|
2010-02-03 11:57:21 +02:00
|
|
|
break;
|
|
|
|
|
2016-05-10 23:48:50 +02:00
|
|
|
case ID_ANHD:
|
|
|
|
break;
|
|
|
|
|
2016-05-19 12:42:41 +02:00
|
|
|
case ID_DPAN:
|
|
|
|
avio_skip(pb, 2);
|
|
|
|
st->duration = avio_rb16(pb);
|
|
|
|
break;
|
|
|
|
|
2012-03-09 01:34:36 +03: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)))
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->format = AV_PIX_FMT_RGB24;
|
2012-03-09 01:34:36 +03:00
|
|
|
else if (fmt_size == sizeof(deep_rgba) && !memcmp(fmt, deep_rgba, sizeof(deep_rgba)))
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->format = AV_PIX_FMT_RGBA;
|
2012-11-18 11:01:41 +03:00
|
|
|
else if (fmt_size == sizeof(deep_bgra) && !memcmp(fmt, deep_bgra, sizeof(deep_bgra)))
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->format = AV_PIX_FMT_BGRA;
|
2012-11-18 11:01:41 +03:00
|
|
|
else if (fmt_size == sizeof(deep_argb) && !memcmp(fmt, deep_argb, sizeof(deep_argb)))
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->format = AV_PIX_FMT_ARGB;
|
2012-11-18 11:01:41 +03:00
|
|
|
else if (fmt_size == sizeof(deep_abgr) && !memcmp(fmt, deep_abgr, sizeof(deep_abgr)))
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->format = AV_PIX_FMT_ABGR;
|
2012-03-09 01:34:36 +03:00
|
|
|
else {
|
2013-03-15 20:13:52 +03:00
|
|
|
avpriv_request_sample(s, "color format %.16s", fmt);
|
2012-03-09 01:34:36 +03:00
|
|
|
return AVERROR_PATCHWELCOME;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_DGBL:
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
|
2012-03-09 01:34:36 +03:00
|
|
|
if (data_size < 8)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->width = avio_rb16(pb);
|
|
|
|
st->codecpar->height = avio_rb16(pb);
|
2012-03-09 01:34:36 +03:00
|
|
|
iff->bitmap_compression = avio_rb16(pb);
|
|
|
|
st->sample_aspect_ratio.num = avio_r8(pb);
|
|
|
|
st->sample_aspect_ratio.den = avio_r8(pb);
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->bits_per_coded_sample = 24;
|
2012-03-09 01:34:36 +03:00
|
|
|
break;
|
|
|
|
|
2012-11-18 11:02:03 +03:00
|
|
|
case ID_DLOC:
|
|
|
|
if (data_size < 4)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->width = avio_rb16(pb);
|
|
|
|
st->codecpar->height = avio_rb16(pb);
|
2012-11-18 11:02:03 +03:00
|
|
|
break;
|
|
|
|
|
2012-11-25 07:12:56 +03: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 11:55:56 +02:00
|
|
|
case ID_ANNO:
|
2011-05-14 00:28:18 +03: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;
|
2014-04-18 09:00:15 +03:00
|
|
|
|
|
|
|
/* DSD tags */
|
|
|
|
|
|
|
|
case MKTAG('F','V','E','R'):
|
|
|
|
if (data_size < 4)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
version = avio_rb32(pb);
|
|
|
|
av_log(s, AV_LOG_DEBUG, "DSIFF v%d.%d.%d.%d\n",version >> 24, (version >> 16) & 0xFF, (version >> 8) & 0xFF, version & 0xFF);
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
|
2014-04-18 09:00:15 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MKTAG('D','I','I','N'):
|
|
|
|
res = parse_dsd_diin(s, st, orig_pos + data_size);
|
|
|
|
if (res < 0)
|
|
|
|
return res;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MKTAG('P','R','O','P'):
|
|
|
|
if (data_size < 4)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
if (avio_rl32(pb) != MKTAG('S','N','D',' ')) {
|
|
|
|
avpriv_request_sample(s, "unknown property type");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
res = parse_dsd_prop(s, st, orig_pos + data_size);
|
|
|
|
if (res < 0)
|
|
|
|
return res;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MKTAG('C','O','M','T'):
|
|
|
|
if (data_size < 2)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
nb_comments = avio_rb16(pb);
|
|
|
|
for (i = 0; i < nb_comments; i++) {
|
|
|
|
int year, mon, day, hour, min, type, ref;
|
|
|
|
char tmp[24];
|
|
|
|
const char *tag;
|
|
|
|
int metadata_size;
|
|
|
|
|
|
|
|
year = avio_rb16(pb);
|
|
|
|
mon = avio_r8(pb);
|
|
|
|
day = avio_r8(pb);
|
|
|
|
hour = avio_r8(pb);
|
|
|
|
min = avio_r8(pb);
|
|
|
|
snprintf(tmp, sizeof(tmp), "%04d-%02d-%02d %02d:%02d", year, mon, day, hour, min);
|
|
|
|
av_dict_set(&st->metadata, "comment_time", tmp, 0);
|
|
|
|
|
|
|
|
type = avio_rb16(pb);
|
|
|
|
ref = avio_rb16(pb);
|
|
|
|
switch (type) {
|
|
|
|
case 1:
|
|
|
|
if (!i)
|
|
|
|
tag = "channel_comment";
|
|
|
|
else {
|
|
|
|
snprintf(tmp, sizeof(tmp), "channel%d_comment", ref);
|
|
|
|
tag = tmp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
2014-08-05 19:16:46 +03:00
|
|
|
tag = ref < FF_ARRAY_ELEMS(dsd_source_comment) ? dsd_source_comment[ref] : "source_comment";
|
2014-04-18 09:00:15 +03:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
tag = ref < FF_ARRAY_ELEMS(dsd_history_comment) ? dsd_history_comment[ref] : "file_history";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
tag = "comment";
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata_size = avio_rb32(pb);
|
|
|
|
if ((res = get_metadata(s, tag, metadata_size)) < 0) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "cannot allocate metadata tag %s!\n", tag);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (metadata_size & 1)
|
|
|
|
avio_skip(pb, 1);
|
|
|
|
}
|
|
|
|
break;
|
2008-03-30 22:17:01 +03:00
|
|
|
}
|
2010-04-27 17:03:47 +03:00
|
|
|
|
2010-05-05 20:26:59 +03:00
|
|
|
if (metadata_tag) {
|
|
|
|
if ((res = get_metadata(s, metadata_tag, data_size)) < 0) {
|
2012-09-01 13:35:14 +03:00
|
|
|
av_log(s, AV_LOG_ERROR, "cannot allocate metadata tag %s!\n", metadata_tag);
|
2010-05-05 20:26:59 +03:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
2011-03-15 10:14:38 +02:00
|
|
|
avio_skip(pb, data_size - (avio_tell(pb) - orig_pos) + (data_size & 1));
|
2008-03-30 22:17:01 +03:00
|
|
|
}
|
|
|
|
|
2016-05-10 23:48:50 +02:00
|
|
|
if (st->codecpar->codec_tag == ID_ANIM)
|
|
|
|
avio_seek(pb, 12, SEEK_SET);
|
|
|
|
else
|
|
|
|
avio_seek(pb, iff->body_pos, SEEK_SET);
|
2010-04-27 17:03:47 +03:00
|
|
|
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 21:42:52 +03:00
|
|
|
switch(st->codecpar->codec_type) {
|
2010-03-31 02:30:55 +03:00
|
|
|
case AVMEDIA_TYPE_AUDIO:
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 21:42:52 +03:00
|
|
|
avpriv_set_pts_info(st, 32, 1, st->codecpar->sample_rate);
|
2008-03-30 22:17:01 +03:00
|
|
|
|
2016-04-10 21:58:15 +02:00
|
|
|
if (st->codecpar->codec_tag == ID_16SV)
|
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_PCM_S16BE_PLANAR;
|
|
|
|
else if (st->codecpar->codec_tag == ID_MAUD) {
|
2012-11-29 13:45:28 +03:00
|
|
|
if (iff->maud_bits == 8 && !iff->maud_compression) {
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_PCM_U8;
|
2012-11-29 13:45:28 +03:00
|
|
|
} else if (iff->maud_bits == 16 && !iff->maud_compression) {
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_PCM_S16BE;
|
2012-11-29 13:45:28 +03:00
|
|
|
} else if (iff->maud_bits == 8 && iff->maud_compression == 2) {
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_PCM_ALAW;
|
2012-11-29 13:45:28 +03:00
|
|
|
} else if (iff->maud_bits == 8 && iff->maud_compression == 3) {
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_PCM_MULAW;
|
2012-11-29 13:45:28 +03:00
|
|
|
} else {
|
2013-03-15 20:13:52 +03:00
|
|
|
avpriv_request_sample(s, "compression %d and bit depth %d", iff->maud_compression, iff->maud_bits);
|
2012-11-29 13:45:28 +03:00
|
|
|
return AVERROR_PATCHWELCOME;
|
|
|
|
}
|
2016-05-05 21:21:27 +02:00
|
|
|
} else if (st->codecpar->codec_tag != ID_DSD &&
|
|
|
|
st->codecpar->codec_tag != ID_DST) {
|
2014-04-13 07:45:10 +03:00
|
|
|
switch (iff->svx8_compression) {
|
|
|
|
case COMP_NONE:
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_PCM_S8_PLANAR;
|
2014-04-13 07:45:10 +03:00
|
|
|
break;
|
|
|
|
case COMP_FIB:
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_8SVX_FIB;
|
2014-04-13 07:45:10 +03:00
|
|
|
break;
|
|
|
|
case COMP_EXP:
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_8SVX_EXP;
|
2014-04-13 07:45:10 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
av_log(s, AV_LOG_ERROR,
|
|
|
|
"Unknown SVX8 compression method '%d'\n", iff->svx8_compression);
|
|
|
|
return -1;
|
|
|
|
}
|
2012-11-28 18:53:25 +03:00
|
|
|
}
|
2008-03-30 22:17:01 +03:00
|
|
|
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->bits_per_coded_sample = av_get_bits_per_sample(st->codecpar->codec_id);
|
2016-12-13 01:38:25 +02:00
|
|
|
st->codecpar->bit_rate = (int64_t)st->codecpar->channels * st->codecpar->sample_rate * st->codecpar->bits_per_coded_sample;
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 21:42:52 +03:00
|
|
|
st->codecpar->block_align = st->codecpar->channels * st->codecpar->bits_per_coded_sample;
|
2016-05-05 21:21:27 +02:00
|
|
|
if (st->codecpar->codec_tag == ID_DSD && st->codecpar->block_align <= 0)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2010-04-20 21:40:45 +03:00
|
|
|
break;
|
2010-02-03 11:57:21 +02:00
|
|
|
|
2010-03-31 02:30:55 +03:00
|
|
|
case AVMEDIA_TYPE_VIDEO:
|
2016-04-10 21:58:15 +02:00
|
|
|
iff->bpp = st->codecpar->bits_per_coded_sample;
|
2016-05-10 23:48:50 +02:00
|
|
|
if (st->codecpar->codec_tag == ID_ANIM)
|
|
|
|
avpriv_set_pts_info(st, 32, 1, 60);
|
2011-04-20 14:56:56 +03:00
|
|
|
if ((screenmode & 0x800 /* Hold And Modify */) && iff->bpp <= 8) {
|
|
|
|
iff->ham = iff->bpp > 6 ? 6 : 4;
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->bits_per_coded_sample = 24;
|
2011-04-20 14:56:56 +03:00
|
|
|
}
|
|
|
|
iff->flags = (screenmode & 0x80 /* Extra HalfBrite */) && iff->bpp <= 8;
|
|
|
|
iff->masking = masking;
|
|
|
|
iff->transparency = transparency;
|
|
|
|
|
2016-04-10 21:58:15 +02:00
|
|
|
if (!st->codecpar->extradata) {
|
|
|
|
st->codecpar->extradata_size = IFF_EXTRA_VIDEO_SIZE;
|
|
|
|
st->codecpar->extradata = av_malloc(IFF_EXTRA_VIDEO_SIZE + AV_INPUT_BUFFER_PADDING_SIZE);
|
|
|
|
if (!st->codecpar->extradata)
|
2011-04-20 14:56:56 +03:00
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
}
|
2016-04-10 21:58:15 +02:00
|
|
|
av_assert0(st->codecpar->extradata_size >= IFF_EXTRA_VIDEO_SIZE);
|
|
|
|
buf = st->codecpar->extradata;
|
2011-04-20 14:56:56 +03:00
|
|
|
bytestream_put_be16(&buf, IFF_EXTRA_VIDEO_SIZE);
|
2011-05-10 16:33:36 +03:00
|
|
|
bytestream_put_byte(&buf, iff->bitmap_compression);
|
2011-04-20 14:56:56 +03: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 07:12:56 +03:00
|
|
|
bytestream_put_buffer(&buf, iff->tvdc, sizeof(iff->tvdc));
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_IFF_ILBM;
|
2010-02-03 11:57:21 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
2008-03-30 22:17:01 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-10 23:48:50 +02:00
|
|
|
static unsigned get_anim_duration(uint8_t *buf, int size)
|
|
|
|
{
|
|
|
|
GetByteContext gb;
|
|
|
|
|
|
|
|
bytestream2_init(&gb, buf, size);
|
|
|
|
bytestream2_skip(&gb, 4);
|
|
|
|
while (bytestream2_get_bytes_left(&gb) > 8) {
|
|
|
|
unsigned chunk = bytestream2_get_le32(&gb);
|
|
|
|
unsigned size = bytestream2_get_be32(&gb);
|
|
|
|
|
|
|
|
if (chunk == ID_ANHD) {
|
|
|
|
if (size < 40)
|
|
|
|
break;
|
|
|
|
bytestream2_skip(&gb, 14);
|
|
|
|
return bytestream2_get_be32(&gb);
|
|
|
|
} else {
|
|
|
|
bytestream2_skip(&gb, size + size & 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
|
2008-03-30 22:17:01 +03:00
|
|
|
static int iff_read_packet(AVFormatContext *s,
|
|
|
|
AVPacket *pkt)
|
|
|
|
{
|
|
|
|
IffDemuxContext *iff = s->priv_data;
|
2011-02-20 12:04:12 +02:00
|
|
|
AVIOContext *pb = s->pb;
|
2010-02-03 11:57:21 +02:00
|
|
|
AVStream *st = s->streams[0];
|
2008-03-30 22:17:01 +03:00
|
|
|
int ret;
|
2013-01-05 23:37:49 +03:00
|
|
|
int64_t pos = avio_tell(pb);
|
2008-03-30 22:17:01 +03:00
|
|
|
|
2016-05-05 21:21:27 +02:00
|
|
|
if (avio_feof(pb))
|
|
|
|
return AVERROR_EOF;
|
|
|
|
if (st->codecpar->codec_tag != ID_ANIM && pos >= iff->body_end)
|
2011-09-07 22:28:07 +03:00
|
|
|
return AVERROR_EOF;
|
2008-05-09 14:25:27 +03:00
|
|
|
|
2016-04-10 21:58:15 +02:00
|
|
|
if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
|
|
|
|
if (st->codecpar->codec_tag == ID_DSD || st->codecpar->codec_tag == ID_MAUD) {
|
|
|
|
ret = av_get_packet(pb, pkt, FFMIN(iff->body_end - pos, 1024 * st->codecpar->block_align));
|
2016-05-05 21:21:27 +02:00
|
|
|
} else if (st->codecpar->codec_tag == ID_DST) {
|
|
|
|
return read_dst_frame(s, pkt);
|
2012-11-29 13:45:28 +03:00
|
|
|
} else {
|
2015-09-25 21:21:24 +02:00
|
|
|
if (iff->body_size > INT_MAX)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2012-11-29 13:45:28 +03:00
|
|
|
ret = av_get_packet(pb, pkt, iff->body_size);
|
|
|
|
}
|
2016-05-10 23:48:50 +02:00
|
|
|
} else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
|
|
|
|
st->codecpar->codec_tag == ID_ANIM) {
|
|
|
|
uint64_t data_size, orig_pos;
|
2016-05-16 22:39:03 +02:00
|
|
|
uint32_t chunk_id, chunk_id2;
|
2011-04-20 14:56:56 +03:00
|
|
|
|
2016-05-10 23:48:50 +02:00
|
|
|
while (!avio_feof(pb)) {
|
|
|
|
if (avio_feof(pb))
|
|
|
|
return AVERROR_EOF;
|
|
|
|
|
2016-05-16 22:39:03 +02:00
|
|
|
orig_pos = avio_tell(pb);
|
2016-05-10 23:48:50 +02:00
|
|
|
chunk_id = avio_rl32(pb);
|
|
|
|
data_size = avio_rb32(pb);
|
2016-05-16 22:39:03 +02:00
|
|
|
chunk_id2 = avio_rl32(pb);
|
2011-04-20 14:56:56 +03:00
|
|
|
|
2016-05-16 22:39:03 +02:00
|
|
|
if (chunk_id == ID_FORM &&
|
|
|
|
chunk_id2 == ID_ILBM) {
|
|
|
|
avio_skip(pb, -4);
|
2016-05-10 23:48:50 +02:00
|
|
|
break;
|
2016-05-16 22:39:03 +02:00
|
|
|
} else if (chunk_id == ID_FORM &&
|
|
|
|
chunk_id2 == ID_ANIM) {
|
|
|
|
continue;
|
|
|
|
} else {
|
2016-05-10 23:48:50 +02:00
|
|
|
avio_skip(pb, data_size);
|
2016-05-16 22:39:03 +02:00
|
|
|
}
|
2016-05-10 23:48:50 +02:00
|
|
|
}
|
|
|
|
ret = av_get_packet(pb, pkt, data_size);
|
|
|
|
pkt->pos = orig_pos;
|
|
|
|
pkt->duration = get_anim_duration(pkt->data, pkt->size);
|
|
|
|
if (pos == 12)
|
|
|
|
pkt->flags |= AV_PKT_FLAG_KEY;
|
|
|
|
} else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
|
|
|
|
st->codecpar->codec_tag != ID_ANIM) {
|
|
|
|
ret = av_get_packet(pb, pkt, iff->body_size);
|
|
|
|
pkt->pos = pos;
|
|
|
|
if (pos == iff->body_pos)
|
|
|
|
pkt->flags |= AV_PKT_FLAG_KEY;
|
2011-05-29 22:02:20 +03:00
|
|
|
} else {
|
2012-08-10 17:26:39 +03:00
|
|
|
av_assert0(0);
|
2008-05-09 14:25:27 +03:00
|
|
|
}
|
2008-03-30 22:17:01 +03:00
|
|
|
|
2012-11-29 13:45:28 +03:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2008-03-30 22:17:01 +03:00
|
|
|
pkt->stream_index = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-01-26 00:03:28 +02:00
|
|
|
AVInputFormat ff_iff_demuxer = {
|
2012-05-19 19:13:17 +03:00
|
|
|
.name = "iff",
|
2012-07-24 04:23:48 +03:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("IFF (Interchange File Format)"),
|
2011-07-16 23:18:12 +03:00
|
|
|
.priv_data_size = sizeof(IffDemuxContext),
|
|
|
|
.read_probe = iff_probe,
|
|
|
|
.read_header = iff_read_header,
|
|
|
|
.read_packet = iff_read_packet,
|
2013-06-20 22:49:02 +03:00
|
|
|
.flags = AVFMT_GENERIC_INDEX | AVFMT_NO_BYTE_SEEK,
|
2008-03-30 22:17:01 +03:00
|
|
|
};
|