2006-02-02 16:21:19 +01:00
|
|
|
/*
|
2009-10-15 11:45:16 +02:00
|
|
|
* AIFF/AIFF-C demuxer
|
2006-02-02 16:21:19 +01:00
|
|
|
* Copyright (c) 2006 Patrick Guimond
|
|
|
|
*
|
2006-10-07 17:30:46 +02:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2006-02-02 16:21:19 +01:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 17:30:46 +02:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2006-02-02 16:21:19 +01:00
|
|
|
*
|
2006-10-07 17:30:46 +02:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2006-02-02 16:21:19 +01: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
|
2006-10-07 17:30:46 +02:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-02-02 16:21:19 +01:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2008-05-09 13:56:36 +02:00
|
|
|
|
2012-08-28 03:18:21 +02:00
|
|
|
#include "libavutil/intreadwrite.h"
|
2011-11-27 15:04:16 +01:00
|
|
|
#include "libavutil/mathematics.h"
|
2011-05-22 12:46:29 +02:00
|
|
|
#include "libavutil/dict.h"
|
2006-02-02 16:21:19 +01:00
|
|
|
#include "avformat.h"
|
2011-11-29 19:28:15 +01:00
|
|
|
#include "internal.h"
|
2010-08-30 23:17:34 +02:00
|
|
|
#include "pcm.h"
|
2009-10-15 11:45:16 +02:00
|
|
|
#include "aiff.h"
|
2011-04-28 10:45:32 +02:00
|
|
|
#include "isom.h"
|
2012-06-30 19:05:05 +02:00
|
|
|
#include "id3v2.h"
|
2012-09-30 01:22:18 +02:00
|
|
|
#include "mov_chan.h"
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
#define AIFF 0
|
|
|
|
#define AIFF_C_VERSION1 0xA2805140
|
|
|
|
|
2014-09-22 09:19:33 +02:00
|
|
|
typedef struct AIFFInputContext {
|
2009-10-13 02:19:34 +02:00
|
|
|
int64_t data_end;
|
2012-02-27 04:55:52 +01:00
|
|
|
int block_duration;
|
2009-10-13 02:19:34 +02:00
|
|
|
} AIFFInputContext;
|
|
|
|
|
2012-08-05 11:11:04 +02:00
|
|
|
static enum AVCodecID aiff_codec_get_id(int bps)
|
2006-02-02 16:21:19 +01:00
|
|
|
{
|
|
|
|
if (bps <= 8)
|
2012-08-05 11:11:04 +02:00
|
|
|
return AV_CODEC_ID_PCM_S8;
|
2006-02-02 16:21:19 +01:00
|
|
|
if (bps <= 16)
|
2012-08-05 11:11:04 +02:00
|
|
|
return AV_CODEC_ID_PCM_S16BE;
|
2006-02-02 16:21:19 +01:00
|
|
|
if (bps <= 24)
|
2012-08-05 11:11:04 +02:00
|
|
|
return AV_CODEC_ID_PCM_S24BE;
|
2006-02-02 16:21:19 +01:00
|
|
|
if (bps <= 32)
|
2012-08-05 11:11:04 +02:00
|
|
|
return AV_CODEC_ID_PCM_S32BE;
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
/* bigger than 32 isn't allowed */
|
2012-08-05 11:11:04 +02:00
|
|
|
return AV_CODEC_ID_NONE;
|
2006-02-02 16:21:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* returns the size of the found tag */
|
2011-02-20 11:04:12 +01:00
|
|
|
static int get_tag(AVIOContext *pb, uint32_t * tag)
|
2006-02-02 16:21:19 +01:00
|
|
|
{
|
|
|
|
int size;
|
|
|
|
|
2014-08-07 22:12:41 +02:00
|
|
|
if (avio_feof(pb))
|
2007-07-19 17:23:32 +02:00
|
|
|
return AVERROR(EIO);
|
2006-02-02 16:21:19 +01:00
|
|
|
|
2011-02-21 16:43:01 +01:00
|
|
|
*tag = avio_rl32(pb);
|
|
|
|
size = avio_rb32(pb);
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
if (size < 0)
|
|
|
|
size = 0x7fffffff;
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Metadata string read */
|
2009-02-03 00:43:12 +01:00
|
|
|
static void get_meta(AVFormatContext *s, const char *key, int size)
|
2006-02-02 16:21:19 +01:00
|
|
|
{
|
2009-12-13 21:27:29 +01:00
|
|
|
uint8_t *str = av_malloc(size+1);
|
|
|
|
|
2011-05-06 17:39:31 +02:00
|
|
|
if (str) {
|
|
|
|
int res = avio_read(s->pb, str, size);
|
|
|
|
if (res < 0){
|
|
|
|
av_free(str);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
size += (size&1)-res;
|
|
|
|
str[res] = 0;
|
2012-01-28 04:23:26 +01:00
|
|
|
av_dict_set(&s->metadata, key, str, AV_DICT_DONT_STRDUP_VAL);
|
2011-05-06 17:39:31 +02:00
|
|
|
}else
|
|
|
|
size+= size&1;
|
|
|
|
|
|
|
|
avio_skip(s->pb, size);
|
2006-02-02 16:21:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns the number of sound data frames or negative on error */
|
2015-06-07 23:50:13 +02:00
|
|
|
static int get_aiff_header(AVFormatContext *s, int size,
|
2012-02-27 04:55:52 +01:00
|
|
|
unsigned version)
|
2006-02-02 16:21:19 +01:00
|
|
|
{
|
2012-02-27 04:55:52 +01:00
|
|
|
AVIOContext *pb = s->pb;
|
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 20:42:52 +02:00
|
|
|
AVCodecParameters *par = s->streams[0]->codecpar;
|
2012-02-27 04:55:52 +01:00
|
|
|
AIFFInputContext *aiff = s->priv_data;
|
2011-11-27 15:04:16 +01:00
|
|
|
int exp;
|
|
|
|
uint64_t val;
|
2015-06-07 23:50:13 +02:00
|
|
|
int sample_rate;
|
2006-02-02 16:21:19 +01:00
|
|
|
unsigned int num_frames;
|
|
|
|
|
|
|
|
if (size & 1)
|
|
|
|
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 20:42:52 +02:00
|
|
|
par->codec_type = AVMEDIA_TYPE_AUDIO;
|
|
|
|
par->channels = avio_rb16(pb);
|
2011-02-21 16:43:01 +01:00
|
|
|
num_frames = avio_rb32(pb);
|
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 20:42:52 +02:00
|
|
|
par->bits_per_coded_sample = avio_rb16(pb);
|
2006-02-02 16:21:19 +01:00
|
|
|
|
2015-06-07 23:50:13 +02:00
|
|
|
exp = avio_rb16(pb) - 16383 - 63;
|
2011-11-27 15:04:16 +01:00
|
|
|
val = avio_rb64(pb);
|
2015-06-07 23:50:13 +02:00
|
|
|
if (exp <-63 || exp >63) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "exp %d is out of range\n", exp);
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
if (exp >= 0)
|
|
|
|
sample_rate = val << exp;
|
|
|
|
else
|
|
|
|
sample_rate = (val + (1ULL<<(-exp-1))) >> -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 20:42:52 +02:00
|
|
|
par->sample_rate = sample_rate;
|
2006-02-02 16:21:19 +01:00
|
|
|
size -= 18;
|
|
|
|
|
2012-03-21 19:48:35 +01:00
|
|
|
/* get codec id for AIFF-C */
|
2015-01-09 00:09:04 +01:00
|
|
|
if (size < 4) {
|
|
|
|
version = AIFF;
|
|
|
|
} else if (version == AIFF_C_VERSION1) {
|
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 20:42:52 +02:00
|
|
|
par->codec_tag = avio_rl32(pb);
|
|
|
|
par->codec_id = ff_codec_get_id(ff_codec_aiff_tags, par->codec_tag);
|
2017-03-27 01:31:52 +02:00
|
|
|
if (par->codec_id == AV_CODEC_ID_NONE)
|
|
|
|
avpriv_request_sample(s, "unknown or unsupported codec tag: %s",
|
|
|
|
av_fourcc2str(par->codec_tag));
|
2012-03-21 19:48:35 +01:00
|
|
|
size -= 4;
|
|
|
|
}
|
2006-02-02 16:21:19 +01: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 20:42:52 +02:00
|
|
|
if (version != AIFF_C_VERSION1 || par->codec_id == AV_CODEC_ID_PCM_S16BE) {
|
|
|
|
par->codec_id = aiff_codec_get_id(par->bits_per_coded_sample);
|
|
|
|
par->bits_per_coded_sample = av_get_bits_per_sample(par->codec_id);
|
2012-03-21 19:48:35 +01:00
|
|
|
aiff->block_duration = 1;
|
|
|
|
} 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 20:42:52 +02:00
|
|
|
switch (par->codec_id) {
|
2012-08-05 11:11:04 +02:00
|
|
|
case AV_CODEC_ID_PCM_F32BE:
|
|
|
|
case AV_CODEC_ID_PCM_F64BE:
|
|
|
|
case AV_CODEC_ID_PCM_S16LE:
|
|
|
|
case AV_CODEC_ID_PCM_ALAW:
|
|
|
|
case AV_CODEC_ID_PCM_MULAW:
|
2012-02-27 04:55:52 +01:00
|
|
|
aiff->block_duration = 1;
|
2008-02-25 11:57:22 +01:00
|
|
|
break;
|
2012-08-05 11:11:04 +02:00
|
|
|
case AV_CODEC_ID_ADPCM_IMA_QT:
|
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 20:42:52 +02:00
|
|
|
par->block_align = 34 * par->channels;
|
2008-02-25 11:57:22 +01:00
|
|
|
break;
|
2012-08-05 11:11:04 +02:00
|
|
|
case AV_CODEC_ID_MACE3:
|
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 20:42:52 +02:00
|
|
|
par->block_align = 2 * par->channels;
|
2008-03-05 13:06:57 +01:00
|
|
|
break;
|
2013-10-18 19:53:47 +02:00
|
|
|
case AV_CODEC_ID_ADPCM_G726LE:
|
2016-04-10 21:58:15 +02:00
|
|
|
par->bits_per_coded_sample = 5;
|
2015-10-27 13:24:15 +01:00
|
|
|
case AV_CODEC_ID_ADPCM_IMA_WS:
|
2013-06-09 01:10:36 +02:00
|
|
|
case AV_CODEC_ID_ADPCM_G722:
|
2012-08-05 11:11:04 +02:00
|
|
|
case AV_CODEC_ID_MACE6:
|
2015-10-24 20:41:32 +02:00
|
|
|
case AV_CODEC_ID_SDX2_DPCM:
|
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 20:42:52 +02:00
|
|
|
par->block_align = 1 * par->channels;
|
2008-02-25 13:59:42 +01:00
|
|
|
break;
|
2012-08-05 11:11:04 +02:00
|
|
|
case AV_CODEC_ID_GSM:
|
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 20:42:52 +02:00
|
|
|
par->block_align = 33;
|
2008-09-05 00:35:05 +02:00
|
|
|
break;
|
2008-02-25 11:57:22 +01:00
|
|
|
default:
|
2012-03-21 13:05:34 +01:00
|
|
|
aiff->block_duration = 1;
|
2008-02-25 11:57:22 +01:00
|
|
|
break;
|
2006-02-02 16:21:19 +01: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 20:42:52 +02:00
|
|
|
if (par->block_align > 0)
|
|
|
|
aiff->block_duration = av_get_audio_frame_duration2(par,
|
|
|
|
par->block_align);
|
2006-02-02 16:21:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Block align needs to be computed in all cases, as the definition
|
|
|
|
* is specific to applications -> here we use the WAVE format definition */
|
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 20:42:52 +02:00
|
|
|
if (!par->block_align)
|
2016-04-10 21:58:15 +02:00
|
|
|
par->block_align = (av_get_bits_per_sample(par->codec_id) * par->channels) >> 3;
|
2006-02-02 16:21:19 +01:00
|
|
|
|
2012-03-21 19:30:33 +01:00
|
|
|
if (aiff->block_duration) {
|
2016-12-13 00:38:25 +01:00
|
|
|
par->bit_rate = (int64_t)par->sample_rate * (par->block_align << 3) /
|
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 20:42:52 +02:00
|
|
|
aiff->block_duration;
|
2012-03-21 19:30:33 +01:00
|
|
|
}
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
/* Chunk is over */
|
|
|
|
if (size)
|
2011-03-15 09:14:38 +01:00
|
|
|
avio_skip(pb, size);
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
return num_frames;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int aiff_probe(AVProbeData *p)
|
|
|
|
{
|
|
|
|
/* check file header */
|
|
|
|
if (p->buf[0] == 'F' && p->buf[1] == 'O' &&
|
|
|
|
p->buf[2] == 'R' && p->buf[3] == 'M' &&
|
|
|
|
p->buf[8] == 'A' && p->buf[9] == 'I' &&
|
|
|
|
p->buf[10] == 'F' && (p->buf[11] == 'F' || p->buf[11] == 'C'))
|
|
|
|
return AVPROBE_SCORE_MAX;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* aiff input */
|
2012-01-12 13:20:36 +01:00
|
|
|
static int aiff_read_header(AVFormatContext *s)
|
2006-02-02 16:21:19 +01:00
|
|
|
{
|
2012-10-25 22:45:33 +02:00
|
|
|
int ret, size, filesize;
|
2013-04-03 15:45:46 +02:00
|
|
|
int64_t offset = 0, position;
|
2006-02-02 16:21:19 +01:00
|
|
|
uint32_t tag;
|
|
|
|
unsigned version = AIFF_C_VERSION1;
|
2011-02-20 11:04:12 +01:00
|
|
|
AVIOContext *pb = s->pb;
|
2009-04-17 20:18:29 +02:00
|
|
|
AVStream * st;
|
2009-10-13 02:19:34 +02:00
|
|
|
AIFFInputContext *aiff = s->priv_data;
|
2012-06-30 19:05:05 +02:00
|
|
|
ID3v2ExtraMeta *id3v2_extra_meta = NULL;
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
/* check FORM header */
|
|
|
|
filesize = get_tag(pb, &tag);
|
|
|
|
if (filesize < 0 || tag != MKTAG('F', 'O', 'R', 'M'))
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
/* AIFF data type */
|
2011-02-21 16:43:01 +01:00
|
|
|
tag = avio_rl32(pb);
|
2006-02-02 16:21:19 +01:00
|
|
|
if (tag == MKTAG('A', 'I', 'F', 'F')) /* Got an AIFF file */
|
|
|
|
version = AIFF;
|
|
|
|
else if (tag != MKTAG('A', 'I', 'F', 'C')) /* An AIFF-C file then */
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
filesize -= 4;
|
|
|
|
|
2011-06-18 11:43:24 +02:00
|
|
|
st = avformat_new_stream(s, NULL);
|
2006-02-02 16:21:19 +01:00
|
|
|
if (!st)
|
2007-07-19 17:21:30 +02:00
|
|
|
return AVERROR(ENOMEM);
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
while (filesize > 0) {
|
|
|
|
/* parse different chunks */
|
|
|
|
size = get_tag(pb, &tag);
|
2015-03-19 01:44:14 +01:00
|
|
|
|
2016-04-10 21:58:15 +02:00
|
|
|
if (size == AVERROR_EOF && offset > 0 && st->codecpar->block_align) {
|
2015-03-19 01:44:14 +01:00
|
|
|
av_log(s, AV_LOG_WARNING, "header parser hit EOF\n");
|
|
|
|
goto got_sound;
|
|
|
|
}
|
2006-02-02 16:21:19 +01:00
|
|
|
if (size < 0)
|
|
|
|
return size;
|
|
|
|
|
|
|
|
filesize -= size + 8;
|
|
|
|
|
|
|
|
switch (tag) {
|
2008-02-25 13:23:27 +01:00
|
|
|
case MKTAG('C', 'O', 'M', 'M'): /* Common chunk */
|
|
|
|
/* Then for the complete header info */
|
2012-02-27 04:55:52 +01:00
|
|
|
st->nb_frames = get_aiff_header(s, size, version);
|
2008-02-25 13:23:27 +01:00
|
|
|
if (st->nb_frames < 0)
|
|
|
|
return st->nb_frames;
|
|
|
|
if (offset > 0) // COMM is after SSND
|
|
|
|
goto got_sound;
|
|
|
|
break;
|
2012-06-30 19:05:05 +02:00
|
|
|
case MKTAG('I', 'D', '3', ' '):
|
2013-04-03 15:45:46 +02:00
|
|
|
position = avio_tell(pb);
|
2014-04-18 06:49:40 +02:00
|
|
|
ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta, size);
|
2012-10-25 22:45:33 +02:00
|
|
|
if (id3v2_extra_meta)
|
|
|
|
if ((ret = ff_id3v2_parse_apic(s, &id3v2_extra_meta)) < 0) {
|
|
|
|
ff_id3v2_free_extra_meta(&id3v2_extra_meta);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-06-30 19:05:05 +02:00
|
|
|
ff_id3v2_free_extra_meta(&id3v2_extra_meta);
|
2013-04-03 15:45:46 +02:00
|
|
|
if (position + size > avio_tell(pb))
|
|
|
|
avio_skip(pb, position + size - avio_tell(pb));
|
2012-06-30 19:05:05 +02:00
|
|
|
break;
|
2008-02-25 13:23:27 +01:00
|
|
|
case MKTAG('F', 'V', 'E', 'R'): /* Version chunk */
|
2011-02-21 16:43:01 +01:00
|
|
|
version = avio_rb32(pb);
|
2008-02-25 13:23:27 +01:00
|
|
|
break;
|
|
|
|
case MKTAG('N', 'A', 'M', 'E'): /* Sample name chunk */
|
2009-02-03 00:43:12 +01:00
|
|
|
get_meta(s, "title" , size);
|
2008-02-25 13:23:27 +01:00
|
|
|
break;
|
|
|
|
case MKTAG('A', 'U', 'T', 'H'): /* Author chunk */
|
2009-02-03 00:43:12 +01:00
|
|
|
get_meta(s, "author" , size);
|
2008-02-25 13:23:27 +01:00
|
|
|
break;
|
|
|
|
case MKTAG('(', 'c', ')', ' '): /* Copyright chunk */
|
2009-02-03 00:43:12 +01:00
|
|
|
get_meta(s, "copyright", size);
|
2008-02-25 13:23:27 +01:00
|
|
|
break;
|
|
|
|
case MKTAG('A', 'N', 'N', 'O'): /* Annotation chunk */
|
2009-02-03 00:43:12 +01:00
|
|
|
get_meta(s, "comment" , size);
|
2008-02-25 13:23:27 +01:00
|
|
|
break;
|
|
|
|
case MKTAG('S', 'S', 'N', 'D'): /* Sampled sound chunk */
|
2011-03-03 20:11:45 +01:00
|
|
|
aiff->data_end = avio_tell(pb) + size;
|
2011-02-21 16:43:01 +01:00
|
|
|
offset = avio_rb32(pb); /* Offset of sound data */
|
|
|
|
avio_rb32(pb); /* BlockSize... don't care */
|
2011-03-03 20:11:45 +01:00
|
|
|
offset += avio_tell(pb); /* Compute absolute data offset */
|
2017-03-21 21:02:30 +01:00
|
|
|
if (st->codecpar->block_align && !(pb->seekable & AVIO_SEEKABLE_NORMAL)) /* Assume COMM already parsed */
|
2008-02-25 13:23:27 +01:00
|
|
|
goto got_sound;
|
2016-09-27 16:26:37 +02:00
|
|
|
if (!(pb->seekable & AVIO_SEEKABLE_NORMAL)) {
|
2008-02-25 13:23:27 +01:00
|
|
|
av_log(s, AV_LOG_ERROR, "file is not seekable\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2011-03-15 09:14:38 +01:00
|
|
|
avio_skip(pb, size - 8);
|
2008-02-25 13:23:27 +01:00
|
|
|
break;
|
2008-02-25 13:29:34 +01:00
|
|
|
case MKTAG('w', 'a', 'v', 'e'):
|
2008-02-25 13:38:37 +01:00
|
|
|
if ((uint64_t)size > (1<<30))
|
|
|
|
return -1;
|
2016-04-14 18:21:08 +02:00
|
|
|
if (ff_get_extradata(s, st->codecpar, pb, size) < 0)
|
2008-02-25 13:29:34 +01:00
|
|
|
return AVERROR(ENOMEM);
|
2016-07-03 04:37:48 +02:00
|
|
|
if ( (st->codecpar->codec_id == AV_CODEC_ID_QDMC || st->codecpar->codec_id == AV_CODEC_ID_QDM2)
|
|
|
|
&& size>=12*4 && !st->codecpar->block_align) {
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->block_align = AV_RB32(st->codecpar->extradata+11*4);
|
|
|
|
aiff->block_duration = AV_RB32(st->codecpar->extradata+9*4);
|
|
|
|
} else if (st->codecpar->codec_id == AV_CODEC_ID_QCELP) {
|
2013-04-23 15:16:50 +02:00
|
|
|
char rate = 0;
|
|
|
|
if (size >= 25)
|
2016-04-10 21:58:15 +02:00
|
|
|
rate = st->codecpar->extradata[24];
|
2013-04-23 15:16:50 +02:00
|
|
|
switch (rate) {
|
|
|
|
case 'H': // RATE_HALF
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->block_align = 17;
|
2013-04-23 15:16:50 +02:00
|
|
|
break;
|
|
|
|
case 'F': // RATE_FULL
|
|
|
|
default:
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->block_align = 35;
|
2013-04-23 15:16:50 +02:00
|
|
|
}
|
|
|
|
aiff->block_duration = 160;
|
2016-12-13 00:38:25 +01:00
|
|
|
st->codecpar->bit_rate = (int64_t)st->codecpar->sample_rate * (st->codecpar->block_align << 3) /
|
2016-04-10 21:58:15 +02:00
|
|
|
aiff->block_duration;
|
2013-01-01 17:57:01 +01:00
|
|
|
}
|
2008-02-25 13:29:34 +01:00
|
|
|
break;
|
2011-04-23 10:31:03 +02:00
|
|
|
case MKTAG('C','H','A','N'):
|
2012-09-07 13:37:19 +02:00
|
|
|
if(ff_mov_read_chan(s, pb, st, size) < 0)
|
2011-04-23 10:31:03 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
break;
|
2015-03-19 01:39:47 +01:00
|
|
|
case 0:
|
2016-04-10 21:58:15 +02:00
|
|
|
if (offset > 0 && st->codecpar->block_align) // COMM && SSND
|
2015-03-19 01:39:47 +01:00
|
|
|
goto got_sound;
|
2008-02-25 13:23:27 +01:00
|
|
|
default: /* Jump */
|
2011-03-15 09:14:38 +01:00
|
|
|
avio_skip(pb, size);
|
2006-02-02 16:21:19 +01:00
|
|
|
}
|
2016-08-08 21:06:03 +02:00
|
|
|
|
|
|
|
/* Skip required padding byte for odd-sized chunks. */
|
|
|
|
if (size & 1) {
|
|
|
|
filesize--;
|
|
|
|
avio_skip(pb, 1);
|
|
|
|
}
|
2006-02-02 16:21:19 +01:00
|
|
|
}
|
|
|
|
|
2012-02-18 00:51:27 +01:00
|
|
|
got_sound:
|
2016-10-11 09:49:35 +02:00
|
|
|
if (!st->codecpar->block_align && st->codecpar->codec_id == AV_CODEC_ID_QCELP) {
|
|
|
|
av_log(s, AV_LOG_WARNING, "qcelp without wave chunk, assuming full rate\n");
|
|
|
|
st->codecpar->block_align = 35;
|
|
|
|
} else if (!st->codecpar->block_align) {
|
2012-02-18 00:51:27 +01:00
|
|
|
av_log(s, AV_LOG_ERROR, "could not find COMM tag or invalid block_align value\n");
|
2008-05-16 00:47:40 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
/* Now positioned, get the sound data start and end */
|
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 20:42:52 +02:00
|
|
|
avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
|
2006-02-02 16:21:19 +01:00
|
|
|
st->start_time = 0;
|
2012-02-27 04:55:52 +01:00
|
|
|
st->duration = st->nb_frames * aiff->block_duration;
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
/* Position the stream at the first block */
|
2011-02-28 14:57:54 +01:00
|
|
|
avio_seek(pb, offset, SEEK_SET);
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_SIZE 4096
|
|
|
|
|
|
|
|
static int aiff_read_packet(AVFormatContext *s,
|
|
|
|
AVPacket *pkt)
|
|
|
|
{
|
2006-05-15 14:38:33 +02:00
|
|
|
AVStream *st = s->streams[0];
|
2009-10-13 02:19:34 +02:00
|
|
|
AIFFInputContext *aiff = s->priv_data;
|
|
|
|
int64_t max_size;
|
2009-11-30 23:01:21 +01:00
|
|
|
int res, size;
|
2006-02-02 16:21:19 +01:00
|
|
|
|
2009-10-13 02:19:34 +02:00
|
|
|
/* calculate size of remaining data */
|
2011-03-03 20:11:45 +01:00
|
|
|
max_size = aiff->data_end - avio_tell(s->pb);
|
2009-10-13 02:19:34 +02:00
|
|
|
if (max_size <= 0)
|
|
|
|
return AVERROR_EOF;
|
|
|
|
|
2016-10-20 20:08:15 +02:00
|
|
|
if (!st->codecpar->block_align) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "block_align not set\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
2006-02-02 16:21:19 +01:00
|
|
|
/* Now for that packet */
|
2016-04-10 21:58:15 +02:00
|
|
|
switch (st->codecpar->codec_id) {
|
2014-06-03 00:54:46 +02:00
|
|
|
case AV_CODEC_ID_ADPCM_IMA_QT:
|
|
|
|
case AV_CODEC_ID_GSM:
|
|
|
|
case AV_CODEC_ID_QDM2:
|
|
|
|
case AV_CODEC_ID_QCELP:
|
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 20:42:52 +02:00
|
|
|
size = st->codecpar->block_align;
|
2014-06-03 00:54:46 +02:00
|
|
|
break;
|
|
|
|
default:
|
2016-10-16 22:29:13 +02:00
|
|
|
size = st->codecpar->block_align ? (MAX_SIZE / st->codecpar->block_align) * st->codecpar->block_align : MAX_SIZE;
|
2014-06-03 00:54:46 +02:00
|
|
|
}
|
2009-11-30 23:01:21 +01:00
|
|
|
size = FFMIN(max_size, size);
|
|
|
|
res = av_get_packet(s->pb, pkt, size);
|
2006-02-02 16:21:19 +01:00
|
|
|
if (res < 0)
|
|
|
|
return res;
|
|
|
|
|
2016-04-10 21:58:15 +02:00
|
|
|
if (size >= st->codecpar->block_align)
|
2012-04-30 22:58:27 +02:00
|
|
|
pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
|
2006-02-02 16:21:19 +01:00
|
|
|
/* Only one stream in an AIFF file */
|
|
|
|
pkt->stream_index = 0;
|
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 20:42:52 +02:00
|
|
|
pkt->duration = (res / st->codecpar->block_align) * aiff->block_duration;
|
2006-02-02 16:21:19 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-25 23:03:28 +01:00
|
|
|
AVInputFormat ff_aiff_demuxer = {
|
2011-07-16 22:18:12 +02:00
|
|
|
.name = "aiff",
|
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("Audio IFF"),
|
|
|
|
.priv_data_size = sizeof(AIFFInputContext),
|
|
|
|
.read_probe = aiff_probe,
|
|
|
|
.read_header = aiff_read_header,
|
|
|
|
.read_packet = aiff_read_packet,
|
2012-02-15 10:28:39 +01:00
|
|
|
.read_seek = ff_pcm_read_seek,
|
2012-04-06 16:50:48 +02:00
|
|
|
.codec_tag = (const AVCodecTag* const []){ ff_codec_aiff_tags, 0 },
|
2006-02-02 16:21:19 +01:00
|
|
|
};
|