1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

avformat: add tri-ACE demuxer

This commit is contained in:
Paul B Mahol 2020-09-24 17:55:03 +02:00
parent e0d0565425
commit 069d2b4a50
5 changed files with 118 additions and 1 deletions

View File

@ -31,6 +31,7 @@ version <next>:
- Intel QSV-accelerated AV1 decoding
- Argonaut Games Video decoder
- libwavpack encoder removed
- ACE demuxer
version 4.3:

View File

@ -71,6 +71,7 @@ OBJS-$(CONFIG_AAC_DEMUXER) += aacdec.o apetag.o img2.o rawdec.o
OBJS-$(CONFIG_AAX_DEMUXER) += aaxdec.o
OBJS-$(CONFIG_AC3_DEMUXER) += ac3dec.o rawdec.o
OBJS-$(CONFIG_AC3_MUXER) += rawenc.o
OBJS-$(CONFIG_ACE_DEMUXER) += acedec.o
OBJS-$(CONFIG_ACM_DEMUXER) += acm.o rawdec.o
OBJS-$(CONFIG_ACT_DEMUXER) += act.o
OBJS-$(CONFIG_ADF_DEMUXER) += bintext.o sauce.o

114
libavformat/acedec.c Normal file
View File

@ -0,0 +1,114 @@
/*
* ACE demuxer
* Copyright (c) 2020 Paul B Mahol
*
* 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/intreadwrite.h"
#include "avformat.h"
#include "internal.h"
static int ace_probe(const AVProbeData *p)
{
uint32_t asc;
if (AV_RB32(p->buf) != MKBETAG('A','A','C',' '))
return 0;
if (p->buf_size < 0x44)
return 0;
asc = AV_RB32(p->buf + 0x40);
if (asc < 0x44 || asc > p->buf_size - 4)
return 0;
if (AV_RB32(p->buf + asc) != MKBETAG('A','S','C',' '))
return 0;
return AVPROBE_SCORE_MAX / 2 + 1;
}
static int ace_read_header(AVFormatContext *s)
{
AVIOContext *pb = s->pb;
AVCodecParameters *par;
int ret, codec, rate, nb_channels;
uint32_t asc_pos, size;
AVStream *st;
avio_skip(pb, 0x40);
asc_pos = avio_rb32(pb);
if (asc_pos < 0x44)
return AVERROR_INVALIDDATA;
avio_skip(pb, asc_pos - 0x44);
if (avio_rb32(pb) != MKBETAG('A','S','C',' '))
return AVERROR_INVALIDDATA;
avio_skip(pb, 0xec);
codec = avio_rb32(pb);
nb_channels = avio_rb32(pb);
if (nb_channels <= 0 || nb_channels > 8)
return AVERROR_INVALIDDATA;
size = avio_rb32(pb);
if (size == 0)
return AVERROR_INVALIDDATA;
rate = avio_rb32(pb);
if (rate <= 0)
return AVERROR_INVALIDDATA;
avio_skip(pb, 16);
st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
st->start_time = 0;
par = st->codecpar;
par->codec_type = AVMEDIA_TYPE_AUDIO;
par->channels = nb_channels;
par->sample_rate = rate;
par->block_align = (codec == 4 ? 0x60 : codec == 5 ? 0x98 : 0xC0) * nb_channels;
st->duration = (size / par->block_align) * 1024LL;
par->codec_id = AV_CODEC_ID_ATRAC3;
ret = ff_alloc_extradata(par, 14);
if (ret < 0)
return ret;
AV_WL16(st->codecpar->extradata, 1);
AV_WL16(st->codecpar->extradata+2, 2048 * par->channels);
AV_WL16(st->codecpar->extradata+4, 0);
AV_WL16(st->codecpar->extradata+6, codec == 4 ? 1 : 0);
AV_WL16(st->codecpar->extradata+8, codec == 4 ? 1 : 0);
AV_WL16(st->codecpar->extradata+10, 1);
AV_WL16(st->codecpar->extradata+12, 0);
avpriv_set_pts_info(st, 64, 1, par->sample_rate);
return 0;
}
static int ace_read_packet(AVFormatContext *s, AVPacket *pkt)
{
AVCodecParameters *par = s->streams[0]->codecpar;
return av_get_packet(s->pb, pkt, par->block_align);
}
AVInputFormat ff_ace_demuxer = {
.name = "ace",
.long_name = NULL_IF_CONFIG_SMALL("tri-Ace Audio Container"),
.read_probe = ace_probe,
.read_header = ace_read_header,
.read_packet = ace_read_packet,
.flags = AVFMT_GENERIC_INDEX,
};

View File

@ -34,6 +34,7 @@ extern AVInputFormat ff_aac_demuxer;
extern AVInputFormat ff_aax_demuxer;
extern AVInputFormat ff_ac3_demuxer;
extern AVOutputFormat ff_ac3_muxer;
extern AVInputFormat ff_ace_demuxer;
extern AVInputFormat ff_acm_demuxer;
extern AVInputFormat ff_act_demuxer;
extern AVInputFormat ff_adf_demuxer;

View File

@ -32,7 +32,7 @@
// Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
// Also please add any ticket numbers that you believe might be affected here
#define LIBAVFORMAT_VERSION_MAJOR 58
#define LIBAVFORMAT_VERSION_MINOR 59
#define LIBAVFORMAT_VERSION_MINOR 60
#define LIBAVFORMAT_VERSION_MICRO 100
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \