From patchwork Wed Sep 22 12:42:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UGVra2EgVsOkw6Ruw6RuZW4=?= X-Patchwork-Id: 30455 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp478960iob; Wed, 22 Sep 2021 05:42:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyx2fuq6mQb5ElmceXq0w5YtGibN8RJ6zOgG1REkis0fk0p2I7m53VYauLwYirY8f7KPgKF X-Received: by 2002:a17:906:5acb:: with SMTP id x11mr39907687ejs.514.1632314566820; Wed, 22 Sep 2021 05:42:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632314566; cv=none; d=google.com; s=arc-20160816; b=fh2lW4wmQFk5PcGjnJ6U+XM+c5iwEf6avSxO4aryQWj/S2e9ZCwWwNrhHQi5ZJUSsL FrT19YNvaqEdraoktc7F3kPRfwmrNl70aFef8plhMYIjiIkvmJsLdm4sxgRuJbXLPFs2 vOQ13uIzJarqBW+9iucyD+vXj0O+pUfQ8tLKDbdpoOgsXb40212Sn6wYifX5PcjpLCzV 7vIAO7o35Wltpg7XyZUPavGLkWIIb3qb83Et8h1RsNjabpM1J8Yw2jAp7GL/R2dNZ+/3 ahd7zNF3rgIMS8esHTbIjCwqlCk9Yl2dmD7j20Hn6gmA0I0x/QX/b0LEFaTzbVODK7Jb idpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=q6KdxV+jWXQsDMyW2FVkBkLgN0ZPguvrfhMOatAmrus=; b=M+bNftfVlv6KDRIlm/z2LSmcTNpxjZ38GHCPqcW2374b4ECVbX3iDYkcBjIljcCmdI ChfsZxQAVix7RS0JrEXF39z3AveD5jkQFPaowUe+ChOYEa/35EcV30jLCRQ6jA0rzv6q Uz7cCKFCDRpfeQwwdizOHg70sqb3eHCRhh4KWsLKo8Ku2OObbO3qC/Iehh/DXT6emc6P WgcKbUJiYI965g00FcOqrRi/hxQyEPSeSKIb2xtUd1QutZiAOTrijOmRfWjfSkWDJ0tI fEpNCwDZ/ysJP9LkcQ5hPIPwp6W5rBfMARaCtvnQwLjAofLx8yTtgXQNp5Oxyf/DryLr sxPA== 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 be21si2559561edb.44.2021.09.22.05.42.46; Wed, 22 Sep 2021 05:42:46 -0700 (PDT) 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 716D968AEA5; Wed, 22 Sep 2021 15:42:36 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 25B2368AE72 for ; Wed, 22 Sep 2021 15:42:28 +0300 (EEST) Received: by mail-lf1-f41.google.com with SMTP id g41so11496774lfv.1 for ; Wed, 22 Sep 2021 05:42:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VKSISdNr1p1SZL6HaFPLgwg6fI+qRUPqH61FovRPe/4=; b=VpDfcuApq/AOrh1POEEqnx0QFXJcKze1dqGX008D8i1KUONPVGjBfPFUhGkMG4NByU YweQv9itLdJJ1NmtiQi/NDowbYu8l/BdHFTaYFsj+lhq9khxMqvZDzqtqo9WdUz0l0oA 77xq5YNYRcj8ESe9/96nofJsXUinSyLfVVqPwN+8eDVDXRryzIoFpm4B/JxJbXSBK8CT 8lRQNZubU1/ejcM1iztBPhFk61xByLh5ANasWhSr9wdnWgzcs3gxVPA4GKBzrkqIm56E +H0C9QMqoXGSpY4R+aqgZMN4eohTfEN4Y5fCfa+x/8+cD1tgZmbUzbAW+dJQp/EXZNEc SJEA== X-Gm-Message-State: AOAM531ltcBSGvZNrKE8LmGtVbTbuo3bKhzCD1sRYxDsE3qDnrIFvSC0 arGHOxelr9ZcsQhktZDjVk4wQEMf9oYTyJe2 X-Received: by 2002:a05:651c:1503:: with SMTP id e3mr32656555ljf.182.1632314547508; Wed, 22 Sep 2021 05:42:27 -0700 (PDT) Received: from romu.localdomain (87-92-247-137.rev.dnainternet.fi. [87.92.247.137]) by smtp.gmail.com with ESMTPSA id c5sm240936ljd.94.2021.09.22.05.42.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Sep 2021 05:42:27 -0700 (PDT) From: =?utf-8?b?UGVra2EgVsOkw6Ruw6RuZW4=?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 22 Sep 2021 15:42:23 +0300 Message-Id: <20210922124223.7244-2-pekka.vaananen@iki.fi> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210922124223.7244-1-pekka.vaananen@iki.fi> References: <3CAM7PR03MB6660D08F14DBF637352910EE8FA19%40AM7PR03MB6660.eurprd03.prod.outlook.com> <20210922124223.7244-1-pekka.vaananen@iki.fi> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/westwood_vqa: Store VQFL codebook chunks 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 Cc: =?utf-8?b?UGVra2EgVsOkw6Ruw6RuZW4=?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: UrAYXvsDCKJ1 High color 15-bit VQA3 video streams contain high level chunks with only codebook updates that shouldn't be considered new frames. Now the demuxer stores a reference to such VQFL chunks and returns them later along with a VQFR chunk with full frame data. --- libavformat/westwood_vqa.c | 48 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/libavformat/westwood_vqa.c b/libavformat/westwood_vqa.c index 77df007c11..bc4f53d4e3 100644 --- a/libavformat/westwood_vqa.c +++ b/libavformat/westwood_vqa.c @@ -1,6 +1,7 @@ /* * Westwood Studios VQA Format Demuxer - * Copyright (c) 2003 The FFmpeg project + * Copyright (c) 2003 Mike Melanson + * Copyright (c) 2021 Pekka Väänänen * * This file is part of FFmpeg. * @@ -30,6 +31,7 @@ #include "libavutil/intreadwrite.h" #include "avformat.h" +#include "avio_internal.h" #include "internal.h" #define FORM_TAG MKBETAG('F', 'O', 'R', 'M') @@ -40,6 +42,7 @@ #define SND1_TAG MKBETAG('S', 'N', 'D', '1') #define SND2_TAG MKBETAG('S', 'N', 'D', '2') #define VQFR_TAG MKBETAG('V', 'Q', 'F', 'R') +#define VQFL_TAG MKBETAG('V', 'Q', 'F', 'L') /* don't know what these tags are for, but acknowledge their existence */ #define CINF_TAG MKBETAG('C', 'I', 'N', 'F') @@ -60,6 +63,8 @@ typedef struct WsVqaDemuxContext { int sample_rate; int audio_stream_index; int video_stream_index; + int64_t vqfl_chunk_pos; + int vqfl_chunk_size; } WsVqaDemuxContext; static int wsvqa_probe(const AVProbeData *p) @@ -120,6 +125,8 @@ static int wsvqa_read_header(AVFormatContext *s) wsvqa->channels = header[26]; wsvqa->bps = header[27]; wsvqa->audio_stream_index = -1; + wsvqa->vqfl_chunk_pos = 0; + wsvqa->vqfl_chunk_size = 0; s->ctx_flags |= AVFMTCTX_NOHEADER; @@ -172,7 +179,22 @@ static int wsvqa_read_packet(AVFormatContext *s, skip_byte = chunk_size & 0x01; - if ((chunk_type == SND0_TAG) || (chunk_type == SND1_TAG) || + if (chunk_type == VQFL_TAG) { + /* Each VQFL chunk carries only a codebook update inside which must be applied + * before the next VQFR is rendered. That's why we stash the VQFL offset here + * so it can be combined with the next VQFR packet. This way each packet + * includes a whole frame as expected. */ + wsvqa->vqfl_chunk_pos = avio_tell(pb); + wsvqa->vqfl_chunk_size = (int)(chunk_size); + if (wsvqa->vqfl_chunk_size < 0 || wsvqa->vqfl_chunk_size > 3 * (1 << 20)) + return AVERROR_INVALIDDATA; + /* We need a big seekback buffer because there can be SNxx, VIEW and ZBUF + * chunks (<512 KiB total) in the stream before we read VQFR (<256 KiB) and + * seek back here. */ + ffio_ensure_seekback(pb, wsvqa->vqfl_chunk_size + (512 + 256) * 1024); + avio_skip(pb, chunk_size + skip_byte); + continue; + } else if ((chunk_type == SND0_TAG) || (chunk_type == SND1_TAG) || (chunk_type == SND2_TAG) || (chunk_type == VQFR_TAG)) { ret= av_get_packet(pb, pkt, chunk_size); @@ -235,6 +257,28 @@ static int wsvqa_read_packet(AVFormatContext *s, } break; case VQFR_TAG: + /* if a new codebook is available inside an earlier a VQFL chunk then + * append it to 'pkt' */ + if (wsvqa->vqfl_chunk_size > 0) { + int64_t current_pos = pkt->pos; + + if (avio_seek(pb, wsvqa->vqfl_chunk_pos, SEEK_SET) < 0) + return AVERROR(EIO); + + /* the decoder expects chunks to be 16-bit aligned */ + if (wsvqa->vqfl_chunk_size % 2 == 1) + wsvqa->vqfl_chunk_size++; + + if (av_append_packet(pb, pkt, wsvqa->vqfl_chunk_size) < 0) + return AVERROR(EIO); + + if (avio_seek(pb, current_pos, SEEK_SET) < 0) + return AVERROR(EIO); + + wsvqa->vqfl_chunk_pos = 0; + wsvqa->vqfl_chunk_size = 0; + } + pkt->stream_index = wsvqa->video_stream_index; pkt->duration = 1; break;