diff mbox series

[FFmpeg-devel,v7,2/3] libavformat: Add DFPWM raw format

Message ID 08b63a0d-bb01-cabf-62d4-ddb561b5c1ce@gmail.com
State Accepted
Commit 70fef2371c0bde5dea22889e8eeda03d3cddc5aa
Headers show
Series [FFmpeg-devel,v7,1/3] libavcodec: Added DFPWM1a codec | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished

Commit Message

Jack Bruienne March 8, 2022, 3:29 a.m. UTC
This patch builds on my previous DFPWM codec patch, adding a raw
audio format to be able to read/write the raw files that are most commonly
used (as no other container format supports it yet).

The muxers are mostly copied from the PCM demuxer and the raw muxers, as
DFPWM is typically stored as raw data.

Please see the previous patch for more information on DFPWM.

Changes since v4:
Fixed descriptions of formats.

Changes since v2/v3:
Removed unused MIME parsing code, and added channels option.

Signed-off-by: Jack Bruienne <jackbruienne@gmail.com>
---
  Changelog                 |  2 +-
  MAINTAINERS               |  1 +
  doc/general_contents.texi |  1 +
  libavformat/Makefile      |  2 +
  libavformat/allformats.c  |  2 +
  libavformat/dfpwmdec.c    | 82 +++++++++++++++++++++++++++++++++++++++
  libavformat/rawenc.c      | 13 +++++++
  libavformat/version.h     |  4 +-
  8 files changed, 104 insertions(+), 3 deletions(-)
  create mode 100644 libavformat/dfpwmdec.c

Comments

Tomas Härdin March 14, 2022, 9:47 a.m. UTC | #1
+static const AVOption dfpwm_options[] = {
+    { "sample_rate", "", offsetof(DFPWMAudioDemuxerContext,
sample_rate), AV_OPT_TYPE_INT, {.i64 = 48000}, 0, INT_MAX,
AV_OPT_FLAG_DECODING_PARAM },
+    { "channels",    "", offsetof(DFPWMAudioDemuxerContext, channels),
AV_OPT_TYPE_INT, {.i64 = 1}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+    { NULL },
+};

I think you can set the input sample rate and channel count via the
FFmpeg CLI's -ar and -ac options and have them be carried in and out of
here

/Tomas
Paul B Mahol March 14, 2022, 9:56 a.m. UTC | #2
On Mon, Mar 14, 2022 at 10:47 AM Tomas Härdin <tjoppen@acc.umu.se> wrote:

> +static const AVOption dfpwm_options[] = {
> +    { "sample_rate", "", offsetof(DFPWMAudioDemuxerContext,
> sample_rate), AV_OPT_TYPE_INT, {.i64 = 48000}, 0, INT_MAX,
> AV_OPT_FLAG_DECODING_PARAM },
> +    { "channels",    "", offsetof(DFPWMAudioDemuxerContext, channels),
> AV_OPT_TYPE_INT, {.i64 = 1}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
> +    { NULL },
> +};
>
> I think you can set the input sample rate and channel count via the
> FFmpeg CLI's -ar and -ac options and have them be carried in and out of
> here
>

I highly doubt that.


>
> /Tomas
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
Tomas Härdin March 14, 2022, 10:24 a.m. UTC | #3
mån 2022-03-14 klockan 10:56 +0100 skrev Paul B Mahol:
> On Mon, Mar 14, 2022 at 10:47 AM Tomas Härdin <tjoppen@acc.umu.se>
> wrote:
> 
> > +static const AVOption dfpwm_options[] = {
> > +    { "sample_rate", "", offsetof(DFPWMAudioDemuxerContext,
> > sample_rate), AV_OPT_TYPE_INT, {.i64 = 48000}, 0, INT_MAX,
> > AV_OPT_FLAG_DECODING_PARAM },
> > +    { "channels",    "", offsetof(DFPWMAudioDemuxerContext,
> > channels),
> > AV_OPT_TYPE_INT, {.i64 = 1}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM
> > },
> > +    { NULL },
> > +};
> > 
> > I think you can set the input sample rate and channel count via the
> > FFmpeg CLI's -ar and -ac options and have them be carried in and
> > out of
> > here
> > 
> 
> I highly doubt that.

You can for other raw formats:

  ffplay -f s16le -ar 8k -ac 1 /dev/urandom

/Tomas
diff mbox series

Patch

diff --git a/Changelog b/Changelog
index f3249fe..ac614f8 100644
--- a/Changelog
+++ b/Changelog
@@ -5,7 +5,7 @@  version 5.1:
 - dialogue enhance audio filter
 - dropped obsolete XvMC hwaccel
 - pcm-bluray encoder
-- DFPWM audio encoder/decoder
+- DFPWM audio encoder/decoder and raw muxer/demuxer
 
 
 version 5.0:
diff --git a/MAINTAINERS b/MAINTAINERS
index 57b6f33..931cf4b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -416,6 +416,7 @@  Muxers/Demuxers:
   dashdec.c                             Steven Liu
   dashenc.c                             Karthick Jeyapal
   daud.c                                Reimar Doeffinger
+  dfpwmdec.c                            Jack Bruienne
   dss.c                                 Oleksij Rempel
   dtsdec.c                              foo86
   dtshddec.c                            Paul B Mahol
diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index 14aeaed..fcd9da1 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -578,6 +578,7 @@  library:
 @item raw aptX                  @tab X @tab X
 @item raw aptX HD               @tab X @tab X
 @item raw Chinese AVS video     @tab X @tab X
+@item raw DFPWM                 @tab X @tab X
 @item raw Dirac                 @tab X @tab X
 @item raw DNxHD                 @tab X @tab X
 @item raw DTS                   @tab X @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 16d019d..322c8e7 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -166,6 +166,8 @@  OBJS-$(CONFIG_DAUD_MUXER)                += daudenc.o
 OBJS-$(CONFIG_DCSTR_DEMUXER)             += dcstr.o
 OBJS-$(CONFIG_DERF_DEMUXER)              += derf.o pcm.o
 OBJS-$(CONFIG_DFA_DEMUXER)               += dfa.o
+OBJS-$(CONFIG_DFPWM_DEMUXER)             += dfpwmdec.o pcm.o
+OBJS-$(CONFIG_DFPWM_MUXER)               += rawenc.o
 OBJS-$(CONFIG_DHAV_DEMUXER)              += dhav.o
 OBJS-$(CONFIG_DIRAC_DEMUXER)             += diracdec.o rawdec.o
 OBJS-$(CONFIG_DIRAC_MUXER)               += rawenc.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index d066a77..587ad59 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -124,6 +124,8 @@  extern const AVOutputFormat ff_daud_muxer;
 extern const AVInputFormat  ff_dcstr_demuxer;
 extern const AVInputFormat  ff_derf_demuxer;
 extern const AVInputFormat  ff_dfa_demuxer;
+extern const AVInputFormat  ff_dfpwm_demuxer;
+extern const AVOutputFormat ff_dfpwm_muxer;
 extern const AVInputFormat  ff_dhav_demuxer;
 extern const AVInputFormat  ff_dirac_demuxer;
 extern const AVOutputFormat ff_dirac_muxer;
diff --git a/libavformat/dfpwmdec.c b/libavformat/dfpwmdec.c
new file mode 100644
index 0000000..85d9b61
--- /dev/null
+++ b/libavformat/dfpwmdec.c
@@ -0,0 +1,82 @@ 
+/*
+ * RAW PCM demuxers
+ * Copyright (c) 2002 Fabrice Bellard
+ * Copyright (c) 2022 Jack Bruienne
+ *
+ * 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/avstring.h"
+#include "avformat.h"
+#include "internal.h"
+#include "pcm.h"
+#include "libavutil/log.h"
+#include "libavutil/opt.h"
+#include "libavutil/avassert.h"
+
+typedef struct DFPWMAudioDemuxerContext {
+    AVClass *class;
+    int sample_rate;
+    int channels;
+} DFPWMAudioDemuxerContext;
+
+static int dfpwm_read_header(AVFormatContext *s)
+{
+    DFPWMAudioDemuxerContext *s1 = s->priv_data;
+    AVCodecParameters *par;
+    AVStream *st;
+
+    st = avformat_new_stream(s, NULL);
+    if (!st)
+        return AVERROR(ENOMEM);
+    par = st->codecpar;
+
+    par->codec_type  = AVMEDIA_TYPE_AUDIO;
+    par->codec_id    = s->iformat->raw_codec_id;
+    par->sample_rate = s1->sample_rate;
+    par->channels    = s1->channels;
+    par->bits_per_coded_sample = 1;
+    par->block_align = 1;
+
+    avpriv_set_pts_info(st, 64, 1, par->sample_rate);
+    return 0;
+}
+
+static const AVOption dfpwm_options[] = {
+    { "sample_rate", "", offsetof(DFPWMAudioDemuxerContext, sample_rate), AV_OPT_TYPE_INT, {.i64 = 48000}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+    { "channels",    "", offsetof(DFPWMAudioDemuxerContext, channels),    AV_OPT_TYPE_INT, {.i64 = 1}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+    { NULL },
+};
+static const AVClass dfpwm_demuxer_class = {
+    .class_name = "dfpwm demuxer",
+    .item_name  = av_default_item_name,
+    .option     = dfpwm_options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
+const AVInputFormat ff_dfpwm_demuxer = {
+    .name           = "dfpwm",
+    .long_name      = NULL_IF_CONFIG_SMALL("raw DFPWM1a"),
+    .priv_data_size = sizeof(DFPWMAudioDemuxerContext),
+    .read_header    = dfpwm_read_header,
+    .read_packet    = ff_pcm_read_packet,
+    .read_seek      = ff_pcm_read_seek,
+    .flags          = AVFMT_GENERIC_INDEX,
+    .extensions     = "dfpwm",
+    .raw_codec_id   = AV_CODEC_ID_DFPWM,
+    .priv_class     = &dfpwm_demuxer_class,
+};
\ No newline at end of file
diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c
index 4bbae77..f8c267c 100644
--- a/libavformat/rawenc.c
+++ b/libavformat/rawenc.c
@@ -192,6 +192,19 @@  const AVOutputFormat ff_data_muxer = {
 };
 #endif
 
+#if CONFIG_DFPWM_MUXER
+const AVOutputFormat ff_dfpwm_muxer = {
+    .name              = "dfpwm",
+    .long_name         = NULL_IF_CONFIG_SMALL("raw DFPWM1a"),
+    .extensions        = "dfpwm",
+    .audio_codec       = AV_CODEC_ID_DFPWM,
+    .video_codec       = AV_CODEC_ID_NONE,
+    .init              = force_one_stream,
+    .write_packet      = ff_raw_write_packet,
+    .flags             = AVFMT_NOTIMESTAMPS,
+};
+#endif
+
 #if CONFIG_DIRAC_MUXER
 const AVOutputFormat ff_dirac_muxer = {
     .name              = "dirac",
diff --git a/libavformat/version.h b/libavformat/version.h
index 05688e3..0f89af4 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,8 +32,8 @@ 
 // 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  59
-#define LIBAVFORMAT_VERSION_MINOR  17
-#define LIBAVFORMAT_VERSION_MICRO 103
+#define LIBAVFORMAT_VERSION_MINOR  18
+#define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                LIBAVFORMAT_VERSION_MINOR, \