Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH v2 1/6] doc/general_contents.texi: Add missing ADPCM IMA APC entry
@ 2023-12-30 21:12 Tomas Härdin
  2023-12-30 21:13 ` [FFmpeg-devel] [PATCH v2 2/6] lavf/apc: Read duration from file Tomas Härdin
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Tomas Härdin @ 2023-12-30 21:12 UTC (permalink / raw)
  To: ffmpeg-devel

[-- Attachment #1: Type: text/plain, Size: 59 bytes --]

Addressed some comments and reordered some patches

/Tomas

[-- Attachment #2: 0001-doc-general_contents.texi-Add-missing-ADPCM-IMA-APC-.patch --]
[-- Type: text/x-patch, Size: 945 bytes --]

From 90954f54d82bd0ceda0400ceb0e92e1affecf3db Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git@haerdin.se>
Date: Tue, 26 Dec 2023 15:03:51 +0100
Subject: [PATCH 1/6] doc/general_contents.texi: Add missing ADPCM IMA APC
 entry

---
 doc/general_contents.texi | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index 8b48fed060..ec7516dce8 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -1188,6 +1188,8 @@ following image formats are supported:
 @item ADPCM IMA Acorn Replay @tab     @tab  X
 @item ADPCM IMA AMV          @tab  X  @tab  X
     @tab Used in AMV files
+@item ADPCM IMA APC          @tab     @tab  X
+    @tab Codec used in games by Cryo Interactive
 @item ADPCM IMA Cunning Developments  @tab     @tab  X
 @item ADPCM IMA Electronic Arts EACS  @tab     @tab  X
 @item ADPCM IMA Electronic Arts SEAD  @tab     @tab  X
-- 
2.39.2


[-- Attachment #3: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [FFmpeg-devel] [PATCH v2 2/6] lavf/apc: Read duration from file
  2023-12-30 21:12 [FFmpeg-devel] [PATCH v2 1/6] doc/general_contents.texi: Add missing ADPCM IMA APC entry Tomas Härdin
@ 2023-12-30 21:13 ` Tomas Härdin
  2023-12-30 21:13 ` [FFmpeg-devel] [PATCH v2 3/6] Un-mark IMA APC as intra-only, only mark first packet as keyframe Tomas Härdin
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Tomas Härdin @ 2023-12-30 21:13 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

[-- Attachment #1: Type: text/plain, Size: 1 bytes --]



[-- Attachment #2: 0002-lavf-apc-Read-duration-from-file.patch --]
[-- Type: text/x-patch, Size: 1134 bytes --]

From 2ef5c89c3e3173b26690bad0279fd484a30a6268 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git@haerdin.se>
Date: Tue, 26 Dec 2023 14:31:59 +0100
Subject: [PATCH 2/6] lavf/apc: Read duration from file

---
 libavformat/apc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavformat/apc.c b/libavformat/apc.c
index b8b18c966c..7765c53088 100644
--- a/libavformat/apc.c
+++ b/libavformat/apc.c
@@ -24,6 +24,7 @@
 #include "libavutil/channel_layout.h"
 #include "avformat.h"
 #include "demux.h"
+#include "internal.h"
 
 static int apc_probe(const AVProbeData *p)
 {
@@ -51,8 +52,9 @@ static int apc_read_header(AVFormatContext *s)
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_APC;
 
-    avio_rl32(pb); /* number of samples */
+    st->duration = avio_rl32(pb); /* number of samples */
     st->codecpar->sample_rate = avio_rl32(pb);
+    avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
 
     /* initial predictor values for adpcm decoder */
     if ((ret = ff_get_extradata(s, st->codecpar, pb, 2 * 4)) < 0)
-- 
2.39.2


[-- Attachment #3: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [FFmpeg-devel] [PATCH v2 3/6] Un-mark IMA APC as intra-only, only mark first packet as keyframe
  2023-12-30 21:12 [FFmpeg-devel] [PATCH v2 1/6] doc/general_contents.texi: Add missing ADPCM IMA APC entry Tomas Härdin
  2023-12-30 21:13 ` [FFmpeg-devel] [PATCH v2 2/6] lavf/apc: Read duration from file Tomas Härdin
@ 2023-12-30 21:13 ` Tomas Härdin
  2023-12-30 21:13 ` [FFmpeg-devel] [PATCH v2 4/6] lavf: Add CRYO APC muxer Tomas Härdin
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Tomas Härdin @ 2023-12-30 21:13 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

[-- Attachment #1: Type: text/plain, Size: 1 bytes --]



[-- Attachment #2: 0003-Un-mark-IMA-APC-as-intra-only-only-mark-first-packet.patch --]
[-- Type: text/x-patch, Size: 1652 bytes --]

From f652daf2e9bad345c0e98ab058a5e07c3d45d13e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git@haerdin.se>
Date: Tue, 26 Dec 2023 16:30:35 +0100
Subject: [PATCH 3/6] Un-mark IMA APC as intra-only, only mark first packet as
 keyframe

Packets must be decoded in order.
There is no way to seek and get a bitexact decode.
---
 libavcodec/codec_desc.c | 2 +-
 libavformat/apc.c       | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 033344304c..45ef4c5091 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -2431,7 +2431,7 @@ static const AVCodecDescriptor codec_descriptors[] = {
         .type      = AVMEDIA_TYPE_AUDIO,
         .name      = "adpcm_ima_apc",
         .long_name = NULL_IF_CONFIG_SMALL("ADPCM IMA CRYO APC"),
-        .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
+        .props     = AV_CODEC_PROP_LOSSY,
     },
     {
         .id        = AV_CODEC_ID_ADPCM_VIMA,
diff --git a/libavformat/apc.c b/libavformat/apc.c
index 7765c53088..d1891954a8 100644
--- a/libavformat/apc.c
+++ b/libavformat/apc.c
@@ -75,8 +75,13 @@ static int apc_read_header(AVFormatContext *s)
 
 static int apc_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
+    int first = avio_tell(s->pb) == 32;
     if (av_get_packet(s->pb, pkt, MAX_READ_SIZE) <= 0)
         return AVERROR(EIO);
+    // each IMA APC packet depends on the one before for bitexact decode
+    // extradata is used to initialize the decoder
+    if (first)
+        pkt->flags |= AV_PKT_FLAG_KEY;
     pkt->stream_index = 0;
     return 0;
 }
-- 
2.39.2


[-- Attachment #3: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [FFmpeg-devel] [PATCH v2 4/6] lavf: Add CRYO APC muxer
  2023-12-30 21:12 [FFmpeg-devel] [PATCH v2 1/6] doc/general_contents.texi: Add missing ADPCM IMA APC entry Tomas Härdin
  2023-12-30 21:13 ` [FFmpeg-devel] [PATCH v2 2/6] lavf/apc: Read duration from file Tomas Härdin
  2023-12-30 21:13 ` [FFmpeg-devel] [PATCH v2 3/6] Un-mark IMA APC as intra-only, only mark first packet as keyframe Tomas Härdin
@ 2023-12-30 21:13 ` Tomas Härdin
  2023-12-30 21:14 ` [FFmpeg-devel] [PATCH v2 5/6] lavc: Add ADPCM IMA CRYO APC encoder Tomas Härdin
  2023-12-30 21:14 ` [FFmpeg-devel] [PATCH v2 6/6] Add myself as APC maintainer Tomas Härdin
  4 siblings, 0 replies; 6+ messages in thread
From: Tomas Härdin @ 2023-12-30 21:13 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

[-- Attachment #1: Type: text/plain, Size: 1 bytes --]



[-- Attachment #2: 0004-lavf-Add-CRYO-APC-muxer.patch --]
[-- Type: text/x-patch, Size: 7288 bytes --]

From 1fab30dea9528478ccbe78dc68a3933acb8115b8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git@haerdin.se>
Date: Tue, 26 Dec 2023 14:32:10 +0100
Subject: [PATCH 4/6] lavf: Add CRYO APC muxer

---
 Changelog                 |   1 +
 doc/general_contents.texi |   2 +-
 libavformat/Makefile      |   1 +
 libavformat/allformats.c  |   1 +
 libavformat/apcenc.c      | 129 ++++++++++++++++++++++++++++++++++++++
 libavformat/version.h     |   2 +-
 6 files changed, 134 insertions(+), 2 deletions(-)
 create mode 100644 libavformat/apcenc.c

diff --git a/Changelog b/Changelog
index a638c03250..31c9e25be6 100644
--- a/Changelog
+++ b/Changelog
@@ -13,6 +13,7 @@ version <next>:
 - IAMF raw demuxer and muxer
 - D3D12VA hardware accelerated H264, HEVC, VP9, AV1, MPEG-2 and VC1 decoding
 - tiltandshift filter
+- CRYO APC muxer
 
 version 6.1:
 - libaribcaption decoder
diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index ec7516dce8..df31edd060 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -464,7 +464,7 @@ library:
 @item CRC testing format        @tab X @tab
 @item Creative Voice            @tab X @tab X
     @tab Created for the Sound Blaster Pro.
-@item CRYO APC                  @tab   @tab X
+@item CRYO APC                  @tab X @tab X
     @tab Audio format used in some games by CRYO Interactive Entertainment.
 @item D-Cinema audio            @tab X @tab X
 @item Deluxe Paint Animation    @tab   @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 581e378d95..f605f4ae69 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -105,6 +105,7 @@ OBJS-$(CONFIG_AMV_MUXER)                 += amvenc.o
 OBJS-$(CONFIG_ANM_DEMUXER)               += anm.o
 OBJS-$(CONFIG_APAC_DEMUXER)              += apac.o rawdec.o
 OBJS-$(CONFIG_APC_DEMUXER)               += apc.o
+OBJS-$(CONFIG_APC_MUXER)                 += apcenc.o
 OBJS-$(CONFIG_APE_DEMUXER)               += ape.o apetag.o img2.o
 OBJS-$(CONFIG_APM_DEMUXER)               += apm.o
 OBJS-$(CONFIG_APM_MUXER)                 += apm.o rawenc.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index ce6be5f04d..18a33d7448 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -60,6 +60,7 @@ extern const FFOutputFormat ff_amv_muxer;
 extern const AVInputFormat  ff_anm_demuxer;
 extern const AVInputFormat  ff_apac_demuxer;
 extern const AVInputFormat  ff_apc_demuxer;
+extern const FFOutputFormat ff_apc_muxer;
 extern const AVInputFormat  ff_ape_demuxer;
 extern const AVInputFormat  ff_apm_demuxer;
 extern const FFOutputFormat ff_apm_muxer;
diff --git a/libavformat/apcenc.c b/libavformat/apcenc.c
new file mode 100644
index 0000000000..7c7f3a1f26
--- /dev/null
+++ b/libavformat/apcenc.c
@@ -0,0 +1,129 @@
+/*
+ * CRYO APC audio format muxer
+ * Copyright (c) 2023 Tomas Härdin <git@haerdin.se>
+ *
+ * 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 "avio_internal.h"
+#include "internal.h"
+#include "mux.h"
+
+#define APC_HEADER_SIZE (8*4)
+
+static int apc_write_header(AVFormatContext *s)
+{
+    AVCodecParameters *par;
+    AVStream *st;
+
+    if (s->nb_streams != 1) {
+        av_log(s, AV_LOG_ERROR, "Must have exactly one stream\n");
+        return AVERROR(EINVAL);
+    }
+
+    st = s->streams[0];
+    par = st->codecpar;
+
+    if (par->ch_layout.nb_channels <= 0 || par->ch_layout.nb_channels > 2) {
+        av_log(s, AV_LOG_ERROR, "Must be mono or stereo\n");
+        return AVERROR(EINVAL);
+    }
+
+    avpriv_set_pts_info(st, 64, 1, par->sample_rate);
+    // delay writing the actual header until we get extradata from the encoder
+    return 0;
+}
+
+static int apc_write_header_delayed(AVFormatContext *s, AVPacket *pkt)
+{
+    AVIOContext *pb = s->pb;
+    AVCodecParameters *par = s->streams[0]->codecpar;
+    size_t new_extradata_size = 0, extradata_size;
+    const uint8_t *new_extradata = av_packet_get_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, &new_extradata_size), *extradata;
+
+    // prefer updated extradata from the encoder
+    if (new_extradata) {
+        extradata_size = new_extradata_size;
+        extradata = new_extradata;
+    } else {
+        extradata_size = par->extradata_size;
+        extradata = par->extradata;
+    }
+
+    if (extradata_size != 8) {
+        av_log(s, AV_LOG_ERROR, "Must have exactly 8 bytes of extradata, got %zu\n", extradata_size);
+        return AVERROR(EINVAL);
+    }
+
+    ffio_wfourcc(pb, "CRYO");
+    ffio_wfourcc(pb, "_APC");
+    ffio_wfourcc(pb, "1.20");
+    avio_wl32(pb, 0); // number or samples. updated in apc_write_trailer()
+    avio_wl32(pb, par->sample_rate);
+    avio_write(pb, extradata, extradata_size);
+    avio_wl32(pb, par->ch_layout.nb_channels - 1);
+
+    return 0;
+}
+
+static int apc_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+    if (avio_tell(s->pb) == 0) {
+        // first packet - write header
+        int ret;
+        if ((ret = apc_write_header_delayed(s, pkt)) < 0)
+            return ret;
+    }
+
+    avio_write(s->pb, pkt->data, pkt->size);
+    return 0;
+}
+
+static int apc_write_trailer(AVFormatContext *s)
+{
+    int64_t file_size = avio_tell(s->pb);
+
+    if (file_size < APC_HEADER_SIZE) {
+        av_log(s, AV_LOG_ERROR, "Got no packets\n");
+        return AVERROR(EINVAL);
+    }
+
+    // write length, if we're able to seek back
+    if (avio_seek(s->pb, 12, SEEK_SET) >= 0) {
+        int64_t data_size = file_size -= APC_HEADER_SIZE;
+        int channels = s->streams[0]->codecpar->ch_layout.nb_channels;
+
+        if (data_size / channels > UINT32_MAX / 2) {
+            av_log(s, AV_LOG_ERROR, "File too large\n");
+            return AVERROR(EINVAL);
+        }
+
+        avio_wl32(s->pb, data_size * 2 / channels);
+    }
+    return 0;
+}
+
+const FFOutputFormat ff_apc_muxer = {
+    .p.name         = "apc",
+    .p.long_name    = NULL_IF_CONFIG_SMALL("CRYO APC"),
+    .p.extensions   = "apc",
+    .p.audio_codec  = AV_CODEC_ID_ADPCM_IMA_APC,
+    .write_header   = apc_write_header,
+    .write_packet   = apc_write_packet,
+    .write_trailer  = apc_write_trailer,
+};
+
diff --git a/libavformat/version.h b/libavformat/version.h
index de9cc8e31d..683184d5da 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -31,7 +31,7 @@
 
 #include "version_major.h"
 
-#define LIBAVFORMAT_VERSION_MINOR  20
+#define LIBAVFORMAT_VERSION_MINOR  21
 #define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
-- 
2.39.2


[-- Attachment #3: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [FFmpeg-devel] [PATCH v2 5/6] lavc: Add ADPCM IMA CRYO APC encoder
  2023-12-30 21:12 [FFmpeg-devel] [PATCH v2 1/6] doc/general_contents.texi: Add missing ADPCM IMA APC entry Tomas Härdin
                   ` (2 preceding siblings ...)
  2023-12-30 21:13 ` [FFmpeg-devel] [PATCH v2 4/6] lavf: Add CRYO APC muxer Tomas Härdin
@ 2023-12-30 21:14 ` Tomas Härdin
  2023-12-30 21:14 ` [FFmpeg-devel] [PATCH v2 6/6] Add myself as APC maintainer Tomas Härdin
  4 siblings, 0 replies; 6+ messages in thread
From: Tomas Härdin @ 2023-12-30 21:14 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

[-- Attachment #1: Type: text/plain, Size: 1 bytes --]



[-- Attachment #2: 0005-lavc-Add-ADPCM-IMA-CRYO-APC-encoder.patch --]
[-- Type: text/x-patch, Size: 7067 bytes --]

From 701eec2a7e742fa0fcc375a6c3784ac012100d0a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git@haerdin.se>
Date: Tue, 26 Dec 2023 14:32:20 +0100
Subject: [PATCH 5/6] lavc: Add ADPCM IMA CRYO APC encoder

No trellis quantization yet
---
 Changelog                      |  1 +
 doc/general_contents.texi      |  2 +-
 libavcodec/adpcmenc.c          | 33 +++++++++++++++++++++++++++++++++
 libavcodec/allcodecs.c         |  1 +
 libavcodec/version.h           |  2 +-
 tests/fate/acodec.mak          |  2 ++
 tests/ref/acodec/adpcm-ima_apc |  4 ++++
 7 files changed, 43 insertions(+), 2 deletions(-)
 create mode 100644 tests/ref/acodec/adpcm-ima_apc

diff --git a/Changelog b/Changelog
index 31c9e25be6..586ccd1a9c 100644
--- a/Changelog
+++ b/Changelog
@@ -14,6 +14,7 @@ version <next>:
 - D3D12VA hardware accelerated H264, HEVC, VP9, AV1, MPEG-2 and VC1 decoding
 - tiltandshift filter
 - CRYO APC muxer
+- ADPCM IMA APC encoder
 
 version 6.1:
 - libaribcaption decoder
diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index df31edd060..9f450dc794 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -1188,7 +1188,7 @@ following image formats are supported:
 @item ADPCM IMA Acorn Replay @tab     @tab  X
 @item ADPCM IMA AMV          @tab  X  @tab  X
     @tab Used in AMV files
-@item ADPCM IMA APC          @tab     @tab  X
+@item ADPCM IMA APC          @tab  X  @tab  X
     @tab Codec used in games by Cryo Interactive
 @item ADPCM IMA Cunning Developments  @tab     @tab  X
 @item ADPCM IMA Electronic Arts EACS  @tab     @tab  X
diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c
index 7f18fc2daf..7abd71541d 100644
--- a/libavcodec/adpcmenc.c
+++ b/libavcodec/adpcmenc.c
@@ -74,6 +74,7 @@ typedef struct ADPCMEncodeContext {
     TrellisNode *node_buf;
     TrellisNode **nodep_buf;
     uint8_t *trellis_hash;
+    int extradata_updated;
 } ADPCMEncodeContext;
 
 #define FREEZE_INTERVAL 128
@@ -157,6 +158,15 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx)
             bytestream_put_le16(&extradata, ff_adpcm_AdaptCoeff2[i] * 4);
         }
         ) /* End of CASE */
+    CASE(ADPCM_IMA_APC,
+        if (avctx->trellis) {
+            av_log(avctx, AV_LOG_ERROR, "trellis encoding not implemented for CRYO APC\n");
+            return AVERROR_PATCHWELCOME;
+        }
+        //extradata will be output in adpcm_encode_frame()
+        avctx->frame_size  = s->block_size * 2 / channels;
+        avctx->block_align = s->block_size;
+        ) /* End of CASE */
     CASE(ADPCM_YAMAHA,
         avctx->frame_size  = s->block_size * 2 / channels;
         avctx->block_align = s->block_size;
@@ -622,6 +632,28 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     dst = avpkt->data;
 
     switch(avctx->codec->id) {
+    CASE(ADPCM_IMA_APC,
+        //initialize predictors using initial samples
+        if (!c->extradata_updated) {
+            uint8_t *side_data = av_packet_new_side_data(
+                avpkt, AV_PKT_DATA_NEW_EXTRADATA, 8);
+
+            if (!side_data) {
+                return AVERROR(ENOMEM);
+            }
+
+            for (int ch = 0; ch < channels; ch++) {
+                c->status[ch].prev_sample = samples[ch];
+                bytestream_put_le32(&side_data, c->status[ch].prev_sample);
+            }
+            c->extradata_updated = 1;
+        }
+        for (int i = 0; i < frame->nb_samples*channels/2; i++) {
+            uint8_t l = adpcm_ima_compress_sample(&c->status[0],  samples[2*i+0]);
+            uint8_t r = adpcm_ima_compress_sample(&c->status[st], samples[2*i+1]);
+            *dst++ = (l<<4) | r;
+        }
+        ) /* End of CASE */
     CASE(ADPCM_IMA_WAV,
         int blocks = (frame->nb_samples - 1) / 8;
 
@@ -1027,6 +1059,7 @@ ADPCM_ENCODER(ADPCM_IMA_QT,  adpcm_ima_qt,  sample_fmts_p, 0,
 ADPCM_ENCODER(ADPCM_IMA_SSI, adpcm_ima_ssi, sample_fmts,   AV_CODEC_CAP_SMALL_LAST_FRAME, "ADPCM IMA Simon & Schuster Interactive")
 ADPCM_ENCODER(ADPCM_IMA_WAV, adpcm_ima_wav, sample_fmts_p, 0,                             "ADPCM IMA WAV")
 ADPCM_ENCODER(ADPCM_IMA_WS,  adpcm_ima_ws,  sample_fmts,   AV_CODEC_CAP_SMALL_LAST_FRAME, "ADPCM IMA Westwood")
+ADPCM_ENCODER(ADPCM_IMA_APC, adpcm_ima_apc, sample_fmts,   0,                             "ADPCM IMA CRYO APC")
 ADPCM_ENCODER(ADPCM_MS,      adpcm_ms,      sample_fmts,   0,                             "ADPCM Microsoft")
 ADPCM_ENCODER(ADPCM_SWF,     adpcm_swf,     sample_fmts,   0,                             "ADPCM Shockwave Flash")
 ADPCM_ENCODER(ADPCM_YAMAHA,  adpcm_yamaha,  sample_fmts,   0,                             "ADPCM Yamaha")
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index b0f004e15c..34662a88f3 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -669,6 +669,7 @@ extern const FFCodec ff_adpcm_ima_amv_encoder;
 extern const FFCodec ff_adpcm_ima_alp_decoder;
 extern const FFCodec ff_adpcm_ima_alp_encoder;
 extern const FFCodec ff_adpcm_ima_apc_decoder;
+extern const FFCodec ff_adpcm_ima_apc_encoder;
 extern const FFCodec ff_adpcm_ima_apm_decoder;
 extern const FFCodec ff_adpcm_ima_apm_encoder;
 extern const FFCodec ff_adpcm_ima_cunning_decoder;
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 34b059a8a9..376388c5bb 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #include "version_major.h"
 
-#define LIBAVCODEC_VERSION_MINOR  36
+#define LIBAVCODEC_VERSION_MINOR  37
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
diff --git a/tests/fate/acodec.mak b/tests/fate/acodec.mak
index 7b09e3bd63..e7e3ae5ab8 100644
--- a/tests/fate/acodec.mak
+++ b/tests/fate/acodec.mak
@@ -48,6 +48,7 @@ fate-acodec-pcm-f%be: FMT = au
 
 FATE_ACODEC_ADPCM_RESAMPLE-$(call ENCDEC, ADPCM_ADX,  ADX)      += adx
 FATE_ACODEC_ADPCM_RESAMPLE-$(call ENCDEC, ADPCM_ARGO, ARGO_ASF) += argo
+FATE_ACODEC_ADPCM-$(call ENCDEC, ADPCM_IMA_APC, APC)      += ima_apc
 FATE_ACODEC_ADPCM-$(call ENCDEC, ADPCM_IMA_APM, APM)      += ima_apm
 FATE_ACODEC_ADPCM-$(call ENCDEC, ADPCM_IMA_ALP, ALP)      += ima_alp
 FATE_ACODEC_ADPCM_RESAMPLE-$(call ENCDEC, ADPCM_IMA_QT,  AIFF)  += ima_qt
@@ -69,6 +70,7 @@ fate-acodec-adpcm-%: CODEC = adpcm_$(@:fate-acodec-adpcm-%=%)
 
 fate-acodec-adpcm-adx:     FMT = adx
 fate-acodec-adpcm-argo:    FMT = argo_asf
+fate-acodec-adpcm-ima_apc: FMT = apc
 fate-acodec-adpcm-ima_apm: FMT = apm
 fate-acodec-adpcm-ima_qt:  FMT = aiff
 fate-acodec-adpcm-ima_ssi: FMT = kvag
diff --git a/tests/ref/acodec/adpcm-ima_apc b/tests/ref/acodec/adpcm-ima_apc
new file mode 100644
index 0000000000..f168734c78
--- /dev/null
+++ b/tests/ref/acodec/adpcm-ima_apc
@@ -0,0 +1,4 @@
+45aca515c679bb0c315df766432d5630 *tests/data/fate/acodec-adpcm-ima_apc.apc
+265248 tests/data/fate/acodec-adpcm-ima_apc.apc
+03fc41cf61b7a160359147cd6363562a *tests/data/fate/acodec-adpcm-ima_apc.out.wav
+stddev:  904.04 PSNR: 37.21 MAXDIFF:34026 bytes:  1058400/  1060864
-- 
2.39.2


[-- Attachment #3: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [FFmpeg-devel] [PATCH v2 6/6] Add myself as APC maintainer
  2023-12-30 21:12 [FFmpeg-devel] [PATCH v2 1/6] doc/general_contents.texi: Add missing ADPCM IMA APC entry Tomas Härdin
                   ` (3 preceding siblings ...)
  2023-12-30 21:14 ` [FFmpeg-devel] [PATCH v2 5/6] lavc: Add ADPCM IMA CRYO APC encoder Tomas Härdin
@ 2023-12-30 21:14 ` Tomas Härdin
  4 siblings, 0 replies; 6+ messages in thread
From: Tomas Härdin @ 2023-12-30 21:14 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

[-- Attachment #1: Type: text/plain, Size: 1 bytes --]



[-- Attachment #2: 0006-Add-myself-as-APC-maintainer.patch --]
[-- Type: text/x-patch, Size: 845 bytes --]

From 65f4215a519e457d6a3d6c943d14ebd739083eed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git@haerdin.se>
Date: Tue, 26 Dec 2023 16:45:33 +0100
Subject: [PATCH 6/6] Add myself as APC maintainer

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 9c4683db19..fa98e043c5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -391,6 +391,7 @@ Muxers/Demuxers:
   aiffenc.c                             Baptiste Coudurier, Matthieu Bouron
   alp.c                                 Zane van Iperen
   amvenc.c                              Zane van Iperen
+  apc*                                  Tomas Härdin
   apm.c                                 Zane van Iperen
   apngdec.c                             Benoit Fouet
   argo_asf.c                            Zane van Iperen
-- 
2.39.2


[-- Attachment #3: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-12-30 21:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-30 21:12 [FFmpeg-devel] [PATCH v2 1/6] doc/general_contents.texi: Add missing ADPCM IMA APC entry Tomas Härdin
2023-12-30 21:13 ` [FFmpeg-devel] [PATCH v2 2/6] lavf/apc: Read duration from file Tomas Härdin
2023-12-30 21:13 ` [FFmpeg-devel] [PATCH v2 3/6] Un-mark IMA APC as intra-only, only mark first packet as keyframe Tomas Härdin
2023-12-30 21:13 ` [FFmpeg-devel] [PATCH v2 4/6] lavf: Add CRYO APC muxer Tomas Härdin
2023-12-30 21:14 ` [FFmpeg-devel] [PATCH v2 5/6] lavc: Add ADPCM IMA CRYO APC encoder Tomas Härdin
2023-12-30 21:14 ` [FFmpeg-devel] [PATCH v2 6/6] Add myself as APC maintainer Tomas Härdin

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git