From 5a660d91c2f34c4e464212bf3694cdb7bca80f1a 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 4/7] lavf/codec2: Allow versions between 0.8 and 1.X
---
libavformat/codec2.c | 36 ++++++++++++++++++++++--------------
1 file changed, 22 insertions(+), 14 deletions(-)
@@ -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