2008-03-30 22:17:01 +03:00
|
|
|
/*
|
2008-03-31 20:31:11 +03:00
|
|
|
* IFF (.iff) file demuxer
|
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
|
|
|
*
|
2011-03-18 19:35:10 +02:00
|
|
|
* This file is part of Libav.
|
2008-03-30 22:17:01 +03:00
|
|
|
*
|
2011-03-18 19:35:10 +02:00
|
|
|
* Libav is free software; you can redistribute it and/or
|
2008-03-30 22:17:01 +03:00
|
|
|
* 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.
|
|
|
|
*
|
2011-03-18 19:35:10 +02:00
|
|
|
* Libav is distributed in the hope that it will be useful,
|
2008-03-30 22:17:01 +03:00
|
|
|
* 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
|
2011-03-18 19:35:10 +02:00
|
|
|
* License along with Libav; if not, write to the Free Software
|
2008-03-30 22:17:01 +03:00
|
|
|
* 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-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"
|
2008-03-30 22:17:01 +03:00
|
|
|
#include "avformat.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')
|
|
|
|
#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')
|
|
|
|
#define ID_CMAP MKTAG('C','M','A','P')
|
2008-03-30 22:17:01 +03: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')
|
|
|
|
#define ID_BODY MKTAG('B','O','D','Y')
|
2010-02-16 11:55:56 +02:00
|
|
|
#define ID_ANNO MKTAG('A','N','N','O')
|
2008-03-30 22:17:01 +03:00
|
|
|
|
|
|
|
#define LEFT 2
|
|
|
|
#define RIGHT 4
|
|
|
|
#define STEREO 6
|
|
|
|
|
2010-04-20 21:40:45 +03:00
|
|
|
typedef enum {
|
|
|
|
COMP_NONE,
|
|
|
|
COMP_FIB,
|
|
|
|
COMP_EXP
|
|
|
|
} svx8_compression_type;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
BITMAP_RAW,
|
|
|
|
BITMAP_BYTERUN1
|
|
|
|
} bitmap_compression_type;
|
2008-03-30 22:17:01 +03:00
|
|
|
|
2014-09-22 10:19:33 +03:00
|
|
|
typedef struct IffDemuxContext {
|
2010-04-27 17:03:47 +03:00
|
|
|
uint64_t body_pos;
|
2008-03-30 22:17:01 +03:00
|
|
|
uint32_t body_size;
|
|
|
|
uint32_t sent_bytes;
|
|
|
|
} IffDemuxContext;
|
|
|
|
|
2008-05-09 14:25:27 +03:00
|
|
|
|
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);
|
|
|
|
|
2011-02-21 17:43:01 +02:00
|
|
|
if (avio_read(s->pb, buf, data_size) < 0) {
|
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;
|
|
|
|
}
|
|
|
|
|
2008-03-30 22:17:01 +03:00
|
|
|
static int iff_probe(AVProbeData *p)
|
|
|
|
{
|
|
|
|
const uint8_t *d = p->buf;
|
|
|
|
|
|
|
|
if ( AV_RL32(d) == ID_FORM &&
|
2010-02-03 11:57:21 +02:00
|
|
|
(AV_RL32(d+8) == ID_8SVX || AV_RL32(d+8) == ID_PBM || AV_RL32(d+8) == ID_ILBM) )
|
2008-03-30 22:17:01 +03:00
|
|
|
return AVPROBE_SCORE_MAX;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
uint32_t chunk_id, data_size;
|
2010-02-03 11:57:21 +02:00
|
|
|
int compression = -1;
|
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;
|
2011-03-15 10:14:38 +02:00
|
|
|
avio_skip(pb, 8);
|
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);
|
2008-03-30 22:17:01 +03:00
|
|
|
|
2011-03-07 22:50:25 +02:00
|
|
|
while(!pb->eof_reached) {
|
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;
|
2011-02-21 17:43:01 +02:00
|
|
|
chunk_id = avio_rl32(pb);
|
|
|
|
data_size = 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-02-21 17:43:01 +02:00
|
|
|
compression = avio_r8(pb);
|
2010-04-27 17:03:47 +03:00
|
|
|
}
|
2008-03-30 22:17:01 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_BODY:
|
2011-03-03 21:11:45 +02:00
|
|
|
iff->body_pos = avio_tell(pb);
|
2008-03-30 22:17:01 +03:00
|
|
|
iff->body_size = data_size;
|
|
|
|
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;
|
|
|
|
|
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-03-10 17:35:59 +03:00
|
|
|
av_log(s, AV_LOG_ERROR, "Invalid CMAP chunk size %"PRIu32"\n",
|
2013-03-17 22:22:19 +03:00
|
|
|
data_size);
|
|
|
|
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->extradata_size = data_size;
|
|
|
|
st->codecpar->extradata = av_malloc(data_size);
|
|
|
|
if (!st->codecpar->extradata)
|
2010-02-03 11:57:21 +02:00
|
|
|
return AVERROR(ENOMEM);
|
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 (avio_read(pb, st->codecpar->extradata, 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);
|
2010-04-27 17:03:47 +03:00
|
|
|
if (data_size >= 11) {
|
2011-03-15 10:14:38 +02:00
|
|
|
avio_skip(pb, 1); // masking
|
2011-02-21 17:43:01 +02:00
|
|
|
compression = avio_r8(pb);
|
2010-04-27 17:03:47 +03:00
|
|
|
}
|
|
|
|
if (data_size >= 16) {
|
2016-04-27 19:45:23 +02:00
|
|
|
avio_skip(pb, 3); // padding, transparent
|
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;
|
|
|
|
|
2010-02-16 11:55:56 +02:00
|
|
|
case ID_ANNO:
|
2010-05-05 20:26:59 +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";
|
2010-02-16 11:55:56 +02:00
|
|
|
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) {
|
2010-07-15 14:43:09 +03:00
|
|
|
av_log(s, AV_LOG_ERROR, "cannot allocate metadata tag %s!", 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
|
|
|
}
|
|
|
|
|
2011-02-28 15:57:54 +02:00
|
|
|
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
|
|
|
|
2010-04-20 21:40:45 +03:00
|
|
|
switch(compression) {
|
|
|
|
case COMP_NONE:
|
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_id = AV_CODEC_ID_PCM_S8_PLANAR;
|
2010-04-20 21:40:45 +03:00
|
|
|
break;
|
|
|
|
case COMP_FIB:
|
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_id = AV_CODEC_ID_8SVX_FIB;
|
2010-04-20 21:40:45 +03:00
|
|
|
break;
|
|
|
|
case COMP_EXP:
|
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_id = AV_CODEC_ID_8SVX_EXP;
|
2010-04-20 21:40:45 +03:00
|
|
|
break;
|
|
|
|
default:
|
2010-07-15 14:43:09 +03:00
|
|
|
av_log(s, AV_LOG_ERROR, "unknown compression method\n");
|
2010-04-20 21:40:45 +03:00
|
|
|
return -1;
|
|
|
|
}
|
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->bits_per_coded_sample = 8;
|
|
|
|
st->codecpar->bit_rate = st->codecpar->channels * st->codecpar->sample_rate * st->codecpar->bits_per_coded_sample;
|
|
|
|
st->codecpar->block_align = st->codecpar->channels * st->codecpar->bits_per_coded_sample;
|
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:
|
2010-02-03 11:57:21 +02:00
|
|
|
switch (compression) {
|
|
|
|
case BITMAP_RAW:
|
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_id = AV_CODEC_ID_IFF_ILBM;
|
2010-02-03 11:57:21 +02:00
|
|
|
break;
|
|
|
|
case BITMAP_BYTERUN1:
|
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_id = AV_CODEC_ID_IFF_BYTERUN1;
|
2010-02-03 11:57:21 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
av_log(s, AV_LOG_ERROR, "unknown compression method\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
2008-03-30 22:17:01 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2008-03-30 22:17:01 +03:00
|
|
|
int ret;
|
|
|
|
|
2010-02-03 11:57:21 +02:00
|
|
|
if(iff->sent_bytes >= iff->body_size)
|
2011-09-07 22:28:07 +03:00
|
|
|
return AVERROR_EOF;
|
2008-05-09 14:25:27 +03:00
|
|
|
|
2011-09-07 22:28:07 +03:00
|
|
|
ret = av_get_packet(pb, pkt, iff->body_size);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2008-03-30 22:17:01 +03:00
|
|
|
|
|
|
|
if(iff->sent_bytes == 0)
|
2010-03-31 15:29:58 +03:00
|
|
|
pkt->flags |= AV_PKT_FLAG_KEY;
|
2011-09-07 22:28:07 +03:00
|
|
|
iff->sent_bytes = iff->body_size;
|
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,
|
2008-03-30 22:17:01 +03:00
|
|
|
};
|