[FFmpeg-devel] [PATCH v10 2/2] avformat: add demuxer for Pro Pinball Series' Soundbanks
Michael Niedermayer
michael at niedermayer.cc
Sat Apr 25 14:15:25 EEST 2020
On Sat, Apr 18, 2020 at 12:20:49AM +0000, Zane van Iperen wrote:
> Signed-off-by: Zane van Iperen <zane at zanevaniperen.com>
> ---
> Changelog | 1 +
> libavformat/Makefile | 1 +
> libavformat/allformats.c | 1 +
> libavformat/pp_bnk.c | 293 +++++++++++++++++++++++++++++++++++++++
> libavformat/version.h | 2 +-
> 5 files changed, 297 insertions(+), 1 deletion(-)
> create mode 100644 libavformat/pp_bnk.c
>
> diff --git a/Changelog b/Changelog
> index 1d219a56e0..592beca626 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -60,6 +60,7 @@ version <next>:
> - Expanded styling support for 3GPP Timed Text Subtitles (movtext)
> - WebP parser
> - Cunning Developments ADPCM decoder
> +- Pro Pinball Series Soundbank demuxer
>
>
> version 4.2:
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index d4bed3c113..b744eb69b2 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -428,6 +428,7 @@ OBJS-$(CONFIG_PCM_VIDC_DEMUXER) += pcmdec.o pcm.o
> OBJS-$(CONFIG_PCM_VIDC_MUXER) += pcmenc.o rawenc.o
> OBJS-$(CONFIG_PJS_DEMUXER) += pjsdec.o subtitles.o
> OBJS-$(CONFIG_PMP_DEMUXER) += pmpdec.o
> +OBJS-$(CONFIG_PP_BNK_DEMUXER) += pp_bnk.o
> OBJS-$(CONFIG_PVA_DEMUXER) += pva.o
> OBJS-$(CONFIG_PVF_DEMUXER) += pvfdec.o pcm.o
> OBJS-$(CONFIG_QCP_DEMUXER) += qcp.o
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 39d2c352f5..3919c9e4c1 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -341,6 +341,7 @@ extern AVInputFormat ff_pcm_u8_demuxer;
> extern AVOutputFormat ff_pcm_u8_muxer;
> extern AVInputFormat ff_pjs_demuxer;
> extern AVInputFormat ff_pmp_demuxer;
> +extern AVInputFormat ff_pp_bnk_demuxer;
> extern AVOutputFormat ff_psp_muxer;
> extern AVInputFormat ff_pva_demuxer;
> extern AVInputFormat ff_pvf_demuxer;
> diff --git a/libavformat/pp_bnk.c b/libavformat/pp_bnk.c
> new file mode 100644
> index 0000000000..f67f04b699
> --- /dev/null
> +++ b/libavformat/pp_bnk.c
> @@ -0,0 +1,293 @@
> +/*
> + * Pro Pinball Series Soundbank (44c, 22c, 11c, 5c) demuxer.
> + *
> + * Copyright (C) 2020 Zane van Iperen (zane at zanevaniperen.com)
> + *
> + * 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 "avformat.h"
> +#include "internal.h"
> +#include "libavutil/intreadwrite.h"
> +#include "libavutil/avassert.h"
> +#include "libavutil/internal.h"
> +
> +#define PP_BNK_MAX_READ_SIZE 4096
> +#define PP_BNK_FILE_HEADER_SIZE 20
> +#define PP_BNK_TRACK_SIZE 20
> +
> +typedef struct PPBnkHeader {
> + uint32_t bank_id; /*< Bank ID, useless for our purposes. */
> + uint32_t sample_rate; /*< Sample rate of the contained tracks. */
> + uint32_t always1; /*< Unknown, always seems to be 1. */
> + uint32_t track_count; /*< Number of tracks in the file. */
> + uint32_t flags; /*< Flags. */
> +} PPBnkHeader;
> +
> +typedef struct PPBnkTrack {
> + uint32_t id; /*< Track ID. Usually track[i].id == track[i-1].id + 1, but not always */
> + uint32_t size; /*< Size of the data in bytes. */
> + uint32_t sample_rate; /*< Sample rate. */
> + uint32_t always1_1; /*< Unknown, always seems to be 1. */
> + uint32_t always1_2; /*< Unknown, always seems to be 1. */
> +} PPBnkTrack;
> +
> +typedef struct PPBnkCtxTrack {
> + int64_t data_offset;
> + uint32_t data_size;
> +} PPBnkCtxTrack;
> +
> +typedef struct PPBnkCtx {
> + int track_count;
> + PPBnkCtxTrack *tracks;
> + uint32_t current_track;
> + uint32_t bytes_read;
> +} PPBnkCtx;
> +
> +enum {
> + PP_BNK_FLAG_PERSIST = (1 << 0), /*< This is a large file, keep in memory. */
> + PP_BNK_FLAG_MUSIC = (1 << 1), /*< This is music. */
> + PP_BNK_FLAG_MASK = (PP_BNK_FLAG_PERSIST | PP_BNK_FLAG_MUSIC)
> +};
> +
> +static void pp_bnk_parse_header(PPBnkHeader *hdr, const uint8_t *buf)
> +{
> + hdr->bank_id = AV_RL32(buf + 0);
> + hdr->sample_rate = AV_RL32(buf + 4);
> + hdr->always1 = AV_RL32(buf + 8);
> + hdr->track_count = AV_RL32(buf + 12);
> + hdr->flags = AV_RL32(buf + 16);
> +}
> +
> +static void pp_bnk_parse_track(PPBnkTrack *trk, const uint8_t *buf)
> +{
> + trk->id = AV_RL32(buf + 0);
> + trk->size = AV_RL32(buf + 4);
> + trk->sample_rate = AV_RL32(buf + 8);
> + trk->always1_1 = AV_RL32(buf + 12);
> + trk->always1_2 = AV_RL32(buf + 16);
> +}
> +
> +static int pp_bnk_probe(const AVProbeData *p)
> +{
> + uint32_t sample_rate = AV_RL32(p->buf + 4);
> + uint32_t track_count = AV_RL32(p->buf + 12);
> + uint32_t flags = AV_RL32(p->buf + 16);
> +
> + if (track_count == 0 || sample_rate == 0)
> + return 0;
the header code checks these also for INT_MAX
> +
> + /* Sometimes we have the first track header, so check that too. */
> + if (p->buf_size >= 32 && AV_RL32(p->buf + 28) != sample_rate)
> + return 0;
are files with 32 or less bytes valid ?
If not its probably better to not recognize such small pieces
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
He who knows, does not speak. He who speaks, does not know. -- Lao Tsu
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20200425/fa42c00c/attachment.sig>
More information about the ffmpeg-devel
mailing list