From patchwork Thu Dec 28 18:44:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Tomas_H=C3=A4rdin?= X-Patchwork-Id: 45374 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6623:b0:194:e134:edd4 with SMTP id n35csp4354871pzh; Thu, 28 Dec 2023 10:44:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IEMcycZGqKmtObwrU4DTHjshjFZaHzY2R5vh2Yf0rB8gyK0VRPtcklaqe83AGJngaVUMVa9 X-Received: by 2002:a05:651c:1a06:b0:2cc:ceac:2af6 with SMTP id by6-20020a05651c1a0600b002ccceac2af6mr5920052ljb.5.1703789071595; Thu, 28 Dec 2023 10:44:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703789071; cv=none; d=google.com; s=arc-20160816; b=D2daIOYNWtg6yu4uIqMBfI9zDJsaaHwU2q8YIj8n9LlqyFbEsDcVRt3wLaUvvKj2WT cB/2A2QjIVpwjRrC9RLhwdWey6uSbkaXeMpCmewFAi3gSS2SthHROvf/o9wCLazdf+v+ OPhjtSg+8+/D2mxAP5GYqmja/4FpKSUt1yu8Y0ls0H3cEEaw1xWKLrgwl7WhdgBV5JEq YpJNOGrfrcucxF2pK8cBWvzACuh3omVCyopZPIsHJevzw8GeOyjYbhoOL7BH2mtRBWvf n4QzD/6AVCTeH+UdSWGIX/HztHblMeoqs4ZSp2GGgokIydqsPRWZR8psH7iWTvcGUS2s w2eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:user-agent:references:in-reply-to:date:to:from :message-id:delivered-to; bh=/BKdgP1eyrBk0ENV7JE7qcMmr4aQ9q0jsWIsEVLK8/A=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=M+8e3+sWxUfntKotngoxMS8GSRhV2k5A3CeSDvICWS/+gqs8NXVGUi7do9466BarSn afROdVEekX9rj0NfsnvSC27auXJSJ3xj3SDywzXWcbQOWR3hkHNe4gXdFfOaNbOcVJKg U8MZvJm0g2VJ3o2LO54PTZHycaz4v4jHrz2x8/fEJLNbHtWKb64sw9Vp+QDAK/+rI2ly HysXtx/HB603QK3EjOift6WhrWNSiPLuXQFGO8LddymImBAe7rAtEjbscTvcgI62YvCC lvWOLn267C40QtXUqXnojM7y+atNSnkNf89W8VfzWE+QxE61KVezVBKSiWkV2w06rjA/ uBxQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id g12-20020a056402090c00b005559fc3cb7asi538004edz.3.2023.12.28.10.44.31; Thu, 28 Dec 2023 10:44:31 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EAD2E68CCA8; Thu, 28 Dec 2023 20:44:28 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from glom.nmugroup.com (glom.nmugroup.com [193.183.80.6]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8535668CC3E for ; Thu, 28 Dec 2023 20:44:22 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by glom.nmugroup.com (Postfix) with ESMTP id 2B8B0542843B for ; Thu, 28 Dec 2023 19:44:22 +0100 (CET) Received: from debian.lan (unknown [IPv6:2a00:66c0:a::72c]) (Authenticated sender: git01) by glom.nmugroup.com (Postfix) with ESMTPSA id D636E54252BF for ; Thu, 28 Dec 2023 19:44:21 +0100 (CET) Message-ID: From: Tomas =?iso-8859-1?q?H=E4rdin?= To: FFmpeg development discussions and patches Date: Thu, 28 Dec 2023 19:44:20 +0100 In-Reply-To: References: User-Agent: Evolution 3.46.4-2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/6] lavf/codec2: Allow versions between 0.8 and 1.X X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: nHiMksATckQ5 Coordinated with the Freetel-codec2 mailing list /Tomas From 22fb929a449a955155684645c385e2fbd681b3dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 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