2009-09-10 20:48:12 +02:00
|
|
|
/*
|
|
|
|
* MD STUDIO audio demuxer
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009 Benjamin Larsson
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2012-11-10 16:00:00 +01:00
|
|
|
#include "libavutil/channel_layout.h"
|
|
|
|
#include "libavutil/intreadwrite.h"
|
2009-09-10 20:48:12 +02:00
|
|
|
#include "avformat.h"
|
2010-08-30 23:17:34 +02:00
|
|
|
#include "pcm.h"
|
2009-09-10 20:48:12 +02:00
|
|
|
|
|
|
|
#define AT1_SU_SIZE 212
|
|
|
|
|
|
|
|
static int aea_read_probe(AVProbeData *p)
|
|
|
|
{
|
|
|
|
if (p->buf_size <= 2048+212)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Magic is '00 08 00 00' in Little Endian*/
|
2009-09-10 21:12:13 +02:00
|
|
|
if (AV_RL32(p->buf)==0x800) {
|
2014-12-23 18:41:53 +01:00
|
|
|
int ch, i;
|
|
|
|
ch = p->buf[264];
|
2009-09-10 20:48:12 +02:00
|
|
|
|
2009-09-13 20:27:53 +02:00
|
|
|
if (ch != 1 && ch != 2)
|
|
|
|
return 0;
|
2009-09-10 20:48:12 +02:00
|
|
|
|
|
|
|
/* Check so that the redundant bsm bytes and info bytes are valid
|
|
|
|
* the block size mode bytes have to be the same
|
|
|
|
* the info bytes have to be the same
|
|
|
|
*/
|
2014-12-23 18:41:53 +01:00
|
|
|
for (i = 2048; i + 211 < p->buf_size; i+= 212) {
|
|
|
|
int bsm_s, bsm_e, inb_s, inb_e;
|
|
|
|
bsm_s = p->buf[0];
|
|
|
|
inb_s = p->buf[1];
|
|
|
|
inb_e = p->buf[210];
|
|
|
|
bsm_e = p->buf[211];
|
|
|
|
|
|
|
|
if (bsm_s != bsm_e || inb_s != inb_e)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return AVPROBE_SCORE_MAX / 4 + 1;
|
2009-09-10 20:48:12 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-12 13:20:36 +01:00
|
|
|
static int aea_read_header(AVFormatContext *s)
|
2009-09-10 20:48:12 +02:00
|
|
|
{
|
2011-06-18 11:43:24 +02:00
|
|
|
AVStream *st = avformat_new_stream(s, NULL);
|
2009-09-10 20:48:12 +02:00
|
|
|
if (!st)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
|
|
|
/* Parse the amount of channels and skip to pos 2048(0x800) */
|
2011-03-15 09:14:38 +01:00
|
|
|
avio_skip(s->pb, 264);
|
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
|
|
|
st->codecpar->channels = avio_r8(s->pb);
|
2011-03-15 09:14:38 +01:00
|
|
|
avio_skip(s->pb, 1783);
|
2009-09-10 20:48:12 +02: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
|
|
|
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
|
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_ATRAC1;
|
|
|
|
st->codecpar->sample_rate = 44100;
|
|
|
|
st->codecpar->bit_rate = 292000;
|
2009-09-10 20:48:12 +02: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 (st->codecpar->channels != 1 && st->codecpar->channels != 2) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "Channels %d not supported!\n", st->codecpar->channels);
|
2015-01-15 13:50:03 +01:00
|
|
|
return AVERROR_INVALIDDATA;
|
2009-09-10 20:48:12 +02: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
|
|
|
st->codecpar->channel_layout = (st->codecpar->channels == 1) ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
|
2009-09-10 20:48:12 +02: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
|
|
|
st->codecpar->block_align = AT1_SU_SIZE * st->codecpar->channels;
|
2009-09-10 20:48:12 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int aea_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|
|
|
{
|
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
|
|
|
int ret = av_get_packet(s->pb, pkt, s->streams[0]->codecpar->block_align);
|
2009-09-10 20:48:12 +02:00
|
|
|
|
|
|
|
pkt->stream_index = 0;
|
|
|
|
if (ret <= 0)
|
|
|
|
return AVERROR(EIO);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-01-25 23:03:28 +01:00
|
|
|
AVInputFormat ff_aea_demuxer = {
|
2011-07-16 22:18:12 +02:00
|
|
|
.name = "aea",
|
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("MD STUDIO audio"),
|
|
|
|
.read_probe = aea_read_probe,
|
|
|
|
.read_header = aea_read_header,
|
|
|
|
.read_packet = aea_read_packet,
|
2012-02-15 10:28:39 +01:00
|
|
|
.read_seek = ff_pcm_read_seek,
|
2012-04-06 16:50:48 +02:00
|
|
|
.flags = AVFMT_GENERIC_INDEX,
|
|
|
|
.extensions = "aea",
|
2009-09-10 20:48:12 +02:00
|
|
|
};
|