Re: [FFmpeg-devel] [PATCH v2 4/4] avformat: add Argonaut Games BRP demuxer

2020-09-14 Thread Paul B Mahol
On Wed, Sep 09, 2020 at 12:05:03AM +, Zane van Iperen wrote:
> Used in FMVs for FX Fighter and Croc. Supports BVID and BASF streams,
> requests samples for anything else.
> 
> Due to the way BASF streams are contained in the file, only one is
> supported. I have yet to see a BRP file with multiple.
> 
> Signed-off-by: Zane van Iperen 
> ---
>  Changelog|   1 +
>  libavformat/Makefile |   1 +
>  libavformat/allformats.c |   1 +
>  libavformat/argo_brp.c   | 449 +++
>  libavformat/version.h|   2 +-
>  5 files changed, 453 insertions(+), 1 deletion(-)
>  create mode 100644 libavformat/argo_brp.c
> 
> diff --git a/Changelog b/Changelog
> index ff9ff2fcb8..2ccecfbcc9 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -21,6 +21,7 @@ version :
>  - MOFLEX demuxer
>  - MODS demuxer
>  - PhotoCD decoder
> +- Argonaut Games BRP demuxer
>  
>  
>  version 4.3:
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index 2368bc15ac..062f3bd9c2 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -104,6 +104,7 @@ OBJS-$(CONFIG_APTX_HD_MUXER) += rawenc.o
>  OBJS-$(CONFIG_AQTITLE_DEMUXER)   += aqtitledec.o subtitles.o
>  OBJS-$(CONFIG_ARGO_ASF_DEMUXER)  += argo_asf.o
>  OBJS-$(CONFIG_ARGO_ASF_MUXER)+= argo_asf.o
> +OBJS-$(CONFIG_ARGO_BRP_DEMUXER)  += argo_brp.o argo_asf.o
>  OBJS-$(CONFIG_ASF_DEMUXER)   += asfdec_f.o asf.o asfcrypt.o \
>  avlanguage.o
>  OBJS-$(CONFIG_ASF_O_DEMUXER) += asfdec_o.o asf.o asfcrypt.o \
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 3438a14141..8e7556e529 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -65,6 +65,7 @@ extern AVOutputFormat ff_aptx_hd_muxer;
>  extern AVInputFormat  ff_aqtitle_demuxer;
>  extern AVInputFormat  ff_argo_asf_demuxer;
>  extern AVOutputFormat ff_argo_asf_muxer;
> +extern AVInputFormat  ff_argo_brp_demuxer;
>  extern AVInputFormat  ff_asf_demuxer;
>  extern AVOutputFormat ff_asf_muxer;
>  extern AVInputFormat  ff_asf_o_demuxer;
> diff --git a/libavformat/argo_brp.c b/libavformat/argo_brp.c
> new file mode 100644
> index 00..122f616ecc
> --- /dev/null
> +++ b/libavformat/argo_brp.c
> @@ -0,0 +1,449 @@
> +/*
> + * Argonaut Games BRP Demuxer
> + *
> + * Copyright (C) 2020 Zane van Iperen (z...@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"
> +#include "argo_asf.h"
> +
> +#define BRP_TAG MKTAG('B', 'R', 'P', 'P')
> +#define BRP_FILE_HEADER_SIZE12
> +#define BRP_BLOCK_HEADER_SIZE   12
> +#define BRP_STREAM_HEADER_SIZE  20
> +#define BRP_MAX_STREAMS 32 /* Soft cap, but even this is overkill. */
> +#define BVID_HEADER_SIZE16
> +#define BRP_MIN_BUFFER_SIZE FFMAX(FFMAX3(BRP_FILE_HEADER_SIZE,\
> + BRP_BLOCK_HEADER_SIZE,   \
> + BRP_STREAM_HEADER_SIZE), \
> +  BVID_HEADER_SIZE)
> +
> +#define BRP_CODEC_ID_BVID   MKTAG('B', 'V', 'I', 'D')
> +#define BRP_CODEC_ID_BASF   MKTAG('B', 'A', 'S', 'F')
> +
> +typedef struct ArgoBRPFileHeader {
> +uint32_t magic;
> +uint32_t num_streams;
> +uint32_t byte_rate;
> +} ArgoBRPFileHeader;
> +
> +typedef struct ArgoBRPBlockHeader {
> +int32_t  stream_id;
> +uint32_t start_ms;
> +uint32_t size;
> +} ArgoBRPBlockHeader;
> +
> +typedef struct ArgoBVIDHeader {
> +uint32_t num_frames;
> +uint32_t width;
> +uint32_t height;
> +uint32_t depth;
> +} ArgoBVIDHeader;
> +
> +typedef struct ArgoBRPStreamHeader {
> +uint32_t codec_id;
> +uint32_t id;
> +uint32_t duration_ms;
> +uint32_t byte_rate;
> +uint32_t extradata_size;
> +union
> +{
> +/* If codec_id == BRP_CODEC_ID_BVID */
> +ArgoBVIDHeaderbvid;
> +/* If codec_id == BRP_CODEC_ID_BASF */
> +ArgoASFFileHeader basf;
> +} 

[FFmpeg-devel] [PATCH v2 4/4] avformat: add Argonaut Games BRP demuxer

2020-09-08 Thread Zane van Iperen
Used in FMVs for FX Fighter and Croc. Supports BVID and BASF streams,
requests samples for anything else.

Due to the way BASF streams are contained in the file, only one is
supported. I have yet to see a BRP file with multiple.

Signed-off-by: Zane van Iperen 
---
 Changelog|   1 +
 libavformat/Makefile |   1 +
 libavformat/allformats.c |   1 +
 libavformat/argo_brp.c   | 449 +++
 libavformat/version.h|   2 +-
 5 files changed, 453 insertions(+), 1 deletion(-)
 create mode 100644 libavformat/argo_brp.c

diff --git a/Changelog b/Changelog
index ff9ff2fcb8..2ccecfbcc9 100644
--- a/Changelog
+++ b/Changelog
@@ -21,6 +21,7 @@ version :
 - MOFLEX demuxer
 - MODS demuxer
 - PhotoCD decoder
+- Argonaut Games BRP demuxer
 
 
 version 4.3:
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 2368bc15ac..062f3bd9c2 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -104,6 +104,7 @@ OBJS-$(CONFIG_APTX_HD_MUXER) += rawenc.o
 OBJS-$(CONFIG_AQTITLE_DEMUXER)   += aqtitledec.o subtitles.o
 OBJS-$(CONFIG_ARGO_ASF_DEMUXER)  += argo_asf.o
 OBJS-$(CONFIG_ARGO_ASF_MUXER)+= argo_asf.o
+OBJS-$(CONFIG_ARGO_BRP_DEMUXER)  += argo_brp.o argo_asf.o
 OBJS-$(CONFIG_ASF_DEMUXER)   += asfdec_f.o asf.o asfcrypt.o \
 avlanguage.o
 OBJS-$(CONFIG_ASF_O_DEMUXER) += asfdec_o.o asf.o asfcrypt.o \
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 3438a14141..8e7556e529 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -65,6 +65,7 @@ extern AVOutputFormat ff_aptx_hd_muxer;
 extern AVInputFormat  ff_aqtitle_demuxer;
 extern AVInputFormat  ff_argo_asf_demuxer;
 extern AVOutputFormat ff_argo_asf_muxer;
+extern AVInputFormat  ff_argo_brp_demuxer;
 extern AVInputFormat  ff_asf_demuxer;
 extern AVOutputFormat ff_asf_muxer;
 extern AVInputFormat  ff_asf_o_demuxer;
diff --git a/libavformat/argo_brp.c b/libavformat/argo_brp.c
new file mode 100644
index 00..122f616ecc
--- /dev/null
+++ b/libavformat/argo_brp.c
@@ -0,0 +1,449 @@
+/*
+ * Argonaut Games BRP Demuxer
+ *
+ * Copyright (C) 2020 Zane van Iperen (z...@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"
+#include "argo_asf.h"
+
+#define BRP_TAG MKTAG('B', 'R', 'P', 'P')
+#define BRP_FILE_HEADER_SIZE12
+#define BRP_BLOCK_HEADER_SIZE   12
+#define BRP_STREAM_HEADER_SIZE  20
+#define BRP_MAX_STREAMS 32 /* Soft cap, but even this is overkill. */
+#define BVID_HEADER_SIZE16
+#define BRP_MIN_BUFFER_SIZE FFMAX(FFMAX3(BRP_FILE_HEADER_SIZE,\
+ BRP_BLOCK_HEADER_SIZE,   \
+ BRP_STREAM_HEADER_SIZE), \
+  BVID_HEADER_SIZE)
+
+#define BRP_CODEC_ID_BVID   MKTAG('B', 'V', 'I', 'D')
+#define BRP_CODEC_ID_BASF   MKTAG('B', 'A', 'S', 'F')
+
+typedef struct ArgoBRPFileHeader {
+uint32_t magic;
+uint32_t num_streams;
+uint32_t byte_rate;
+} ArgoBRPFileHeader;
+
+typedef struct ArgoBRPBlockHeader {
+int32_t  stream_id;
+uint32_t start_ms;
+uint32_t size;
+} ArgoBRPBlockHeader;
+
+typedef struct ArgoBVIDHeader {
+uint32_t num_frames;
+uint32_t width;
+uint32_t height;
+uint32_t depth;
+} ArgoBVIDHeader;
+
+typedef struct ArgoBRPStreamHeader {
+uint32_t codec_id;
+uint32_t id;
+uint32_t duration_ms;
+uint32_t byte_rate;
+uint32_t extradata_size;
+union
+{
+/* If codec_id == BRP_CODEC_ID_BVID */
+ArgoBVIDHeaderbvid;
+/* If codec_id == BRP_CODEC_ID_BASF */
+ArgoASFFileHeader basf;
+} extradata;
+} ArgoBRPStreamHeader;
+
+typedef struct ArgoBRPDemuxContext {
+ArgoBRPFileHeader   fhdr;
+ArgoBRPStreamHeader *streams;
+/* To know how much of a BASF to give. */
+int64_t lastpts;
+int hit_eof;
+
+/* BASF-specific fields. */
+struct {
+int index;