From patchwork Mon Sep 20 18:43:32 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: 30385 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp1712507iob; Mon, 20 Sep 2021 11:43:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypCDSJ+uOSsGM32mAFhHkq433M0Cl0dvgQ5d1EkdxkUNbhn0pGamypkAUEFkcPMrDTl8ak X-Received: by 2002:a50:e085:: with SMTP id f5mr15800611edl.9.1632163438189; Mon, 20 Sep 2021 11:43:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632163438; cv=none; d=google.com; s=arc-20160816; b=YorJ2svpzYPIDHIGsvzstGhbGyGeWxgHjQK8JalJ9F/CLtPejuP0ffWYYJ1ex+6G7h YwoHgjbqPPCH/zzY8S9xewMWFr86UpPc8933FzTPkiN69zKxFZUI6Wpf+TL08vv6JJpG +OAFdi3+w8HiEuLwqtotB5DA/ETuL/MjAEwQ05Bpzr7qb5ESBZtupfYaQo6+VnBtU/1G dxci18sgAdzwWLq2w53UNhq08NfkfYoPtYFUR24wgk22dWKEhmQPmLzPx6wiIGU/UuHD q5Qjwhe6hz5K48ULCzpU8v/twruBExkc4tnh83z2msn7c+ddznnkVV/nyCkasJm9gsfe r+5w== 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=y58mYfuBPQuSto+bZvM7DMJUUaJJZ5wSqTgPQWrsAw0=; b=oSoZiH6rlibopD0CTYE3PWBp8/V7PazHVUHhLj9paBdOBVbI0GabmqvOlNMEFrfCsA rYU2qm4mwrgawzHnc1VSTgALvv6WvCFsmQCT+lS3rC4XC1vP8ON61j3Lo2NWccZnEgFo mBxkPGZifzgK0wStN46w9pryO8s0AfjpGGOLlPpF1e9rmW6xOdR27KRO7QwIyNRTsQdQ UFCkU1zQ04uJUTVisgm8+8+zzIvsMmMMFUbSPHE7Cy4GUGamUuD2rcYGDVGn7AR39CiD jLNx/hCQorG3SJZAschOU4+SHW9lmpOm+rjdCqnfP9zse0UmBjvFkvrjom3dwnLf+WrT f5Dg== 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 f20si15816210edj.364.2021.09.20.11.43.57; Mon, 20 Sep 2021 11:43:58 -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 DA5CF68AF21; Mon, 20 Sep 2021 21:43:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 98C9668ADF2 for ; Mon, 20 Sep 2021 21:43:38 +0300 (EEST) Received: by mail-lf1-f52.google.com with SMTP id b20so12968376lfv.3 for ; Mon, 20 Sep 2021 11:43:38 -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=NOZUoD1aL+rfK7Cw6thweNBKNvx/VksYSjItIkkt/JE=; b=YGPGay6enf0qenShdRtcKdpXOSnqjoxpylMLEpGlwVfOQpw8qxJkWiQ34k2Ckc0cm7 6S1v3qXliDHMVTMgn64Rx+dEXKI1iL3ODTErZy2BuFSVVbBs2bipg4u2padTqqvSKa8X 3zyRkSdfz8snBlv0v46UIDURUdUr1I+YcrQbksn/rSYmGAPwCfTDigRuvcHtlc3Y67/8 al/gxeubqgkP1Lbbdq551HYWCAxRVfgdPM1Vtfo1eT+cHgGPKEfXu3EG7WP2ifKHo/wL o5hk9tNW+fPdZZenQBr7s0HvK/3xJSFqp3fNLO31Bu+/lIpGocwqN1+ffXb1K13ow2XE oJDA== X-Gm-Message-State: AOAM532shG6XQHEoT/7quCugVDmWEh9m5PHBfSpITNu6zXxFtbftL5ot O+hcXLDvfwT2x8Ayk/J5IwHyumf7Mj3C3Q== X-Received: by 2002:a05:651c:503:: with SMTP id o3mr24549989ljp.528.1632163417904; Mon, 20 Sep 2021 11:43:37 -0700 (PDT) Received: from romu.localdomain (87-92-247-137.rev.dnainternet.fi. [87.92.247.137]) by smtp.gmail.com with ESMTPSA id x9sm1276066lfn.303.2021.09.20.11.43.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 11:43:37 -0700 (PDT) From: =?utf-8?b?UGVra2EgVsOkw6Ruw6RuZW4=?= To: ffmpeg-devel@ffmpeg.org Date: Mon, 20 Sep 2021 21:43:32 +0300 Message-Id: <20210920184332.11434-2-pekka.vaananen@iki.fi> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210920184332.11434-1-pekka.vaananen@iki.fi> References: <20210920184332.11434-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: CKTkuc94N1A5 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 | 49 ++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/libavformat/westwood_vqa.c b/libavformat/westwood_vqa.c index 77df007c11..587626ea67 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. * @@ -40,6 +41,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 +62,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 +124,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,11 +178,21 @@ 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; + 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); - if (ret<0) + ret = av_get_packet(pb, pkt, chunk_size); + + if (ret < 0) return AVERROR(EIO); switch (chunk_type) { @@ -235,6 +251,31 @@ static int wsvqa_read_packet(AVFormatContext *s, } break; case VQFR_TAG: + /* if a new codebook is available inside an earlier a VQFL chunk then + * prepend it to 'pkt' */ + if (wsvqa->vqfl_chunk_size > 0) { + int64_t current_pos = pkt->pos; + int current_size = pkt->size; + + 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_get_packet(pb, pkt, wsvqa->vqfl_chunk_size) < 0) + return AVERROR(EIO); + + if (avio_seek(pb, current_pos, SEEK_SET) < 0) + return AVERROR(EIO); + + ret = av_append_packet(pb, pkt, current_size); + + wsvqa->vqfl_chunk_pos = 0; + wsvqa->vqfl_chunk_size = 0; + } + pkt->stream_index = wsvqa->video_stream_index; pkt->duration = 1; break;