diff mbox series

[FFmpeg-devel,3/6] lavf/codec2: Allow versions between 0.8 and 1.X

Message ID d7e885a9dc2a11362eee731cfcc4a57df71ce5d3.camel@haerdin.se
State New
Headers show
Series [FFmpeg-devel,1/6] lavc/codec2utils: Use actual libcodec2 version | expand

Checks

Context Check Description
yinshiyou/configure_loongarch64 warning Failed to apply patch
andriy/configure_x86 warning Failed to apply patch

Commit Message

Tomas Härdin Dec. 28, 2023, 6:44 p.m. UTC
Coordinated with the Freetel-codec2 mailing list

/Tomas
diff mbox series

Patch

From 22fb929a449a955155684645c385e2fbd681b3dd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git@haerdin.se>
Date: Wed, 27 Dec 2023 17:33:18 +0100
Subject: [PATCH 3/6] lavf/codec2: Allow versions between 0.8 and 1.X

---
 libavformat/codec2.c | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/libavformat/codec2.c b/libavformat/codec2.c
index 47fff2a695..162b844897 100644
--- a/libavformat/codec2.c
+++ b/libavformat/codec2.c
@@ -37,8 +37,11 @@ 
 
 //the lowest version we should ever run across is 0.8
 //we may run across later versions as the format evolves
-#define EXPECTED_CODEC2_MAJOR_VERSION 0
-#define EXPECTED_CODEC2_MINOR_VERSION 8
+#define MIN_MAJOR_VERSION 0
+#define MIN_MINOR_VERSION 8
+//accept any minor version with major version 1.X
+//as of writing the latest release is 1.2.0
+#define MAX_MAJOR_VERSION 1
 
 typedef struct {
     const AVClass *class;
@@ -46,17 +49,20 @@  typedef struct {
     int frames_per_packet;
 } Codec2Context;
 
+static int check_version(uint8_t major, uint8_t minor) {
+    //no .c2 files prior to 0.8 or later than 1.X
+    if (major == MIN_MAJOR_VERSION && minor < MIN_MINOR_VERSION)
+        return 1;
+    if (major > MAX_MAJOR_VERSION)
+        return 1;
+    return 0;
+}
+
 static int codec2_probe(const AVProbeData *p)
 {
     //must start wih C0 DE C2
-    if (AV_RB24(p->buf) != CODEC2_MAGIC) {
-        return 0;
-    }
-
-    //no .c2 files prior to 0.8
-    //be strict about major version while we're at it
-    if (p->buf[3] != EXPECTED_CODEC2_MAJOR_VERSION ||
-        p->buf[4] <  EXPECTED_CODEC2_MINOR_VERSION) {
+    if (AV_RB24(p->buf) != CODEC2_MAGIC ||
+        check_version(p->buf[3], p->buf[4])) {
         return 0;
     }
 
@@ -158,7 +164,8 @@  static int codec2_read_header_common(AVFormatContext *s, AVStream *st, int heade
 static int codec2_read_header(AVFormatContext *s)
 {
     AVStream *st = avformat_new_stream(s, NULL);
-    int ret, version;
+    int ret;
+    uint8_t major, minor;
 
     if (!st) {
         return AVERROR(ENOMEM);
@@ -179,9 +186,10 @@  static int codec2_read_header(AVFormatContext *s)
         return ret;
     }
 
-    version = AV_RB16(st->codecpar->extradata);
-    if ((version >> 8) != EXPECTED_CODEC2_MAJOR_VERSION) {
-        avpriv_report_missing_feature(s, "Major version %i", version >> 8);
+    major = st->codecpar->extradata[0];
+    minor = st->codecpar->extradata[1];
+    if (check_version(major, minor)) {
+        avpriv_report_missing_feature(s, "Version %i.%i", major, minor);
         return AVERROR_PATCHWELCOME;
     }
 
-- 
2.39.2