ffmpeg/libavformat/aea.c

102 lines
3.1 KiB
C
Raw Normal View History

/*
* 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
*/
#include "libavutil/channel_layout.h"
#include "libavutil/intreadwrite.h"
#include "avformat.h"
#include "pcm.h"
2023-10-01 22:53:16 +00:00
#define AT1_SU_SIZE 212
static int aea_read_probe(const AVProbeData *p)
{
2023-10-01 22:53:16 +00:00
if (p->buf_size <= 2048+AT1_SU_SIZE)
return 0;
/* Magic is '00 08 00 00' in little-endian*/
if (AV_RL32(p->buf)==0x800) {
2023-10-01 22:53:16 +00:00
int ch, block_size, score = 0;
ch = p->buf[264];
if (ch != 1 && ch != 2)
return 0;
2023-10-01 22:53:16 +00:00
block_size = ch * AT1_SU_SIZE;
/* 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
*/
2023-10-01 22:53:16 +00:00
for (int i = 2048 + block_size; i + block_size <= p->buf_size; i += block_size) {
if (AV_RN16(p->buf+i) != AV_RN16(p->buf+i+AT1_SU_SIZE))
return 0;
2023-10-01 22:53:16 +00:00
score++;
}
2023-10-01 22:53:16 +00:00
return FFMIN(AVPROBE_SCORE_MAX / 4 + score, AVPROBE_SCORE_MAX);
}
return 0;
}
static int aea_read_header(AVFormatContext *s)
{
AVStream *st = avformat_new_stream(s, NULL);
int channels;
if (!st)
return AVERROR(ENOMEM);
/* Parse the amount of channels and skip to pos 2048(0x800) */
avio_skip(s->pb, 264);
channels = avio_r8(s->pb);
avio_skip(s->pb, 1783);
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 18:42:52 +00:00
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
st->codecpar->codec_id = AV_CODEC_ID_ATRAC1;
st->codecpar->sample_rate = 44100;
2023-10-01 23:07:52 +00:00
st->codecpar->bit_rate = 146000 * channels;
if (channels != 1 && channels != 2) {
av_log(s, AV_LOG_ERROR, "Channels %d not supported!\n", channels);
return AVERROR_INVALIDDATA;
}
av_channel_layout_default(&st->codecpar->ch_layout, channels);
st->codecpar->block_align = AT1_SU_SIZE * st->codecpar->ch_layout.nb_channels;
return 0;
}
static int aea_read_packet(AVFormatContext *s, AVPacket *pkt)
{
return av_get_packet(s->pb, pkt, s->streams[0]->codecpar->block_align);
}
const AVInputFormat ff_aea_demuxer = {
.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,
.read_seek = ff_pcm_read_seek,
.flags = AVFMT_GENERIC_INDEX,
.extensions = "aea",
};