From patchwork Sat Nov 16 00:42:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 16292 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 2BA99446193 for ; Sat, 16 Nov 2019 02:42:51 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0C6E5687FEA; Sat, 16 Nov 2019 02:42:51 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 579C7687FEA for ; Sat, 16 Nov 2019 02:42:44 +0200 (EET) Received: by mail-qt1-f195.google.com with SMTP id p20so12782363qtq.5 for ; Fri, 15 Nov 2019 16:42:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Mj8OD2QhJiutjSWkMnQlA68mzUEQGSEIs4eXzN2mf0A=; b=bW0YiqVtrH9nJmy8h7nT7EuV7OhW+cOc5FHcCfG/AkubcgQwMgcuuVqGc7txozrlED dOAMTpzDkn4aa2kErd6nVa68twXibwMQCvHWDiGmuUlpzlAaTdyQ1h/OeaaokPpNN35J Jm/iah78zDi3ZWShQBk92JIlgvcrTynj2E1GniU0wU4cncu2G72L/x5t7i5LbBOFNh4l 7emKDL5Irywt5qdCQgYa99hWg4yEoV+cllN1uzHeGUbgmzeRSpG0AJNF+yDH/VXtk87R 5rUPeT3zAH0rGHKGPI3KZc0wawhkc2WvfW/DwEzcJBPBlKxWxhhoQfL3/uQQJ+otDVJY dYbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Mj8OD2QhJiutjSWkMnQlA68mzUEQGSEIs4eXzN2mf0A=; b=dYajwmuoSGP1Jy61WIwxQYz57ge5VDt71OgsWC6d0+NkFDp36P4GVVLDMAGoPfj5lw Fo3oXyjMeV8oQxC8bX7ggmlafDwIgUpmaIYHXsJSFQS/AXKaqfp1nxtks0UMuVtrtPpN JFsaozAdvQdnIAvp64IL/KGn8yfNh4qQXHr09UWOZRr/7oyaL4IdXkJLYx9mpg+YyAhb geh0k9kJVMWQRvEZeh0YdzqwgrehidsOtMEUSu7p+opueqXPmfDlE4tBy3cRJptxsZ/7 v7nDiQiWc+TlCbSkr6gnyajyRwMTAnVbSRWZwfeTAfwzWPecP6a2Wkg/gokPmCJ/p8B6 Z4Iw== X-Gm-Message-State: APjAAAWipipvYG7hRiI7dHd5lxULxRQwqKBFO/yKynL6tqbdAIAzlN7B qPBLdpx3qWUJTE4EXCJBjTgnAeqz X-Google-Smtp-Source: APXvYqz2PHyMkaNAamBbkEVObN9RXa9ZC0TVREu5XxdMgzZVjmu3C2Cdxtr7isfwWAqkPV7r6rZwFQ== X-Received: by 2002:ac8:1c03:: with SMTP id a3mr16877046qtk.31.1573864961910; Fri, 15 Nov 2019 16:42:41 -0800 (PST) Received: from localhost.localdomain ([181.23.71.177]) by smtp.gmail.com with ESMTPSA id k26sm5434532qtm.10.2019.11.15.16.42.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 16:42:41 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 15 Nov 2019 21:42:19 -0300 Message-Id: <20191116004219.2465-1-jamrial@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191115183805.1736-2-jamrial@gmail.com> References: <20191115183805.1736-2-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2 v2] avcodec/cbs_av1: keep separate reference frame state for reading and writing X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" In scearios where a Temporal Unit is written right after reading it using the same CBS context (av1_metadata, av1_frame_merge, etc), the reference frame state used by the writer must not be the state that's the result of the reader having already parsed the current frame in question. This fixes writing frames of type Switch. Signed-off-by: James Almer --- This may be needed for other modules as well. I see at least VP9 and h264/hevc keeping some sort of state. Alternatively, we could just require a given CBS context to be used to either read or write, but not both. v2: Simpler version libavcodec/cbs_av1.c | 4 ++++ libavcodec/cbs_av1.h | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c index cca112ecf8..c96e20588b 100644 --- a/libavcodec/cbs_av1.c +++ b/libavcodec/cbs_av1.c @@ -939,6 +939,8 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx, priv->spatial_id = 0; } + priv->ref = (AV1ReferenceFrameState *)&priv->read_ref; + switch (obu->header.obu_type) { case AV1_OBU_SEQUENCE_HEADER: { @@ -1081,6 +1083,8 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx, td = NULL; start_pos = put_bits_count(pbc); + priv->ref = (AV1ReferenceFrameState *)&priv->write_ref; + switch (obu->header.obu_type) { case AV1_OBU_SEQUENCE_HEADER: { diff --git a/libavcodec/cbs_av1.h b/libavcodec/cbs_av1.h index 1fb668ada4..675ed28f60 100644 --- a/libavcodec/cbs_av1.h +++ b/libavcodec/cbs_av1.h @@ -441,7 +441,9 @@ typedef struct CodedBitstreamAV1Context { int tile_cols; int tile_rows; - AV1ReferenceFrameState ref[AV1_NUM_REF_FRAMES]; + AV1ReferenceFrameState *ref; + AV1ReferenceFrameState read_ref[AV1_NUM_REF_FRAMES]; + AV1ReferenceFrameState write_ref[AV1_NUM_REF_FRAMES]; // Write buffer. uint8_t *write_buffer;