From patchwork Wed Oct 21 00:11:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23126 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 7691C44AC78 for ; Wed, 21 Oct 2020 03:17:22 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4D4AF68B757; Wed, 21 Oct 2020 03:17:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f196.google.com (mail-qk1-f196.google.com [209.85.222.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F1BD368B6D7 for ; Wed, 21 Oct 2020 03:17:15 +0300 (EEST) Received: by mail-qk1-f196.google.com with SMTP id 140so707613qko.2 for ; Tue, 20 Oct 2020 17:17:15 -0700 (PDT) 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=/YmHddH4OYyMsnR70fgX9uglpiJhlWhNBGQCR58jRY0=; b=G6BaX+1P4Ih8RfdD8YDv/2K9bhA7LexKyyBg2gGTdyB1pmwKOhNeBUKBBMKuvkcqgq d9xpj5dNwer2387z454XTUBcMzIQl/wI3zBaTFShk3SW2IbfSn/t08LgxA2tG47+01Mj Wq8DO6hwxF5kFNtafZmWR87cr16aMWM/+2Ve0USlgMnwWSRsuIBC/9vpurXBcLb72YfD lO5h3AFs7eZ46HqtYn0zP0dHbXMixCHOmAm/H0492ttjbr9hOT9gGatgnHnIXqrPzSaE 2Q4+r2tW3zFVDsRqMgFteUO/KXGaVbN6Tlf0fGoae99Z0KEQB0XtY7F1YPBUZecC0vuE rJjw== 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=/YmHddH4OYyMsnR70fgX9uglpiJhlWhNBGQCR58jRY0=; b=quDeujD3OMwa44vcfYRHqLTtYZrUY6rBXkG9pYikyqkfsMSO04FRtR3VDxphVUJqg4 cTuEpCzhQ8M360t/zkwfFsdvI1rCJPJRlmsGx6nrPEpDxcGT+C8Xf21nhLu12Mr6wxjC GAYeMg/C68tdSNgSn+kyJffLtcepIJFeevZMGmQVP6Etpxnc1uWfonbh4h/csMbm/eyQ 4fFnzg25qUu677KhbNhM24nEZaAcjKREzjQ1H33IkxvgfAq/I60PLb6L5NJpjNl29YrX xppErQE/msNJD6lOhnuC6HmUfeyrrBj8vuCJqzGVPOg6gZ6kD6YzDm7CVilPbKCSqDQk JMbw== X-Gm-Message-State: AOAM530sz0gBfdfAWguEHNRBgoFGL+FUrEjenzeKp6UCgOOdLC2LXH7H mhDThpAihAj9+kGm3dTEFjIWPtYZMdo= X-Google-Smtp-Source: ABdhPJxqM4zBP5/eTCkSAYjagJo00B5xBkWAt+I6VQrVfpSD2PTOWWwfzWWzhUrH9P+Q1fQZhRc/qg== X-Received: by 2002:a05:620a:809:: with SMTP id s9mr820974qks.57.1603239105507; Tue, 20 Oct 2020 17:11:45 -0700 (PDT) Received: from localhost.localdomain ([181.23.86.134]) by smtp.gmail.com with ESMTPSA id p21sm205528qtf.5.2020.10.20.17.11.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Oct 2020 17:11:44 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 20 Oct 2020 21:11:25 -0300 Message-Id: <20201021001126.14044-2-jamrial@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201021001126.14044-1-jamrial@gmail.com> References: <20201021001126.14044-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] avcodec/cbs_av1: infer segmentation parameters from reference frames 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" Partially implements of setup_past_independence() and load_previous(). These ensures they are always set, even if the values were not coded in the input bitstream and will not be coded in the output bitstream. Signed-off-by: James Almer --- libavcodec/cbs_av1.h | 2 ++ libavcodec/cbs_av1_syntax_template.c | 43 +++++++++++++++++++++------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/libavcodec/cbs_av1.h b/libavcodec/cbs_av1.h index 97aeee9795..a2d78e736f 100644 --- a/libavcodec/cbs_av1.h +++ b/libavcodec/cbs_av1.h @@ -416,6 +416,8 @@ typedef struct AV1ReferenceFrameState { int8_t loop_filter_ref_deltas[AV1_TOTAL_REFS_PER_FRAME]; int8_t loop_filter_mode_deltas[2]; + uint8_t feature_enabled[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX]; + int16_t feature_value[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX]; } AV1ReferenceFrameState; typedef struct CodedBitstreamAV1Context { diff --git a/libavcodec/cbs_av1_syntax_template.c b/libavcodec/cbs_av1_syntax_template.c index 4edf4fd47c..2df5619279 100644 --- a/libavcodec/cbs_av1_syntax_template.c +++ b/libavcodec/cbs_av1_syntax_template.c @@ -743,8 +743,11 @@ static int FUNC(quantization_params)(CodedBitstreamContext *ctx, RWContext *rw, static int FUNC(segmentation_params)(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current) { + CodedBitstreamAV1Context *priv = ctx->priv_data; static const uint8_t bits[AV1_SEG_LVL_MAX] = { 8, 6, 6, 6, 6, 3, 0, 0 }; static const uint8_t sign[AV1_SEG_LVL_MAX] = { 1, 1, 1, 1, 1, 0, 0, 0 }; + static const uint8_t default_feature_enabled[AV1_SEG_LVL_MAX] = { 0 }; + static const int16_t default_feature_value[AV1_SEG_LVL_MAX] = { 0 }; int i, j, err; flag(segmentation_enabled); @@ -763,22 +766,38 @@ static int FUNC(segmentation_params)(CodedBitstreamContext *ctx, RWContext *rw, flag(segmentation_update_data); } - if (current->segmentation_update_data) { for (i = 0; i < AV1_MAX_SEGMENTS; i++) { - for (j = 0; j < AV1_SEG_LVL_MAX; j++) { - flags(feature_enabled[i][j], 2, i, j); + const uint8_t *feature_enabled; + const int16_t *feature_value; + + if (current->primary_ref_frame == AV1_PRIMARY_REF_NONE) { + feature_enabled = default_feature_enabled; + feature_value = default_feature_value; + } else { + feature_enabled = + priv->ref[current->ref_frame_idx[current->primary_ref_frame]].feature_enabled[i]; + feature_value = + priv->ref[current->ref_frame_idx[current->primary_ref_frame]].feature_value[i]; + } - if (current->feature_enabled[i][j] && bits[j] > 0) { - if (sign[j]) - sus(1 + bits[j], feature_value[i][j], 2, i, j); - else - fbs(bits[j], feature_value[i][j], 2, i, j); + for (j = 0; j < AV1_SEG_LVL_MAX; j++) { + if (current->segmentation_update_data) { + flags(feature_enabled[i][j], 2, i, j); + + if (current->feature_enabled[i][j] && bits[j] > 0) { + if (sign[j]) + sus(1 + bits[j], feature_value[i][j], 2, i, j); + else + fbs(bits[j], feature_value[i][j], 2, i, j); + } else { + infer(feature_value[i][j], 0); + } } else { - infer(feature_value[i][j], 0); + infer(feature_enabled[i][j], feature_enabled[j]); + infer(feature_value[i][j], feature_value[j]); } } } - } } else { for (i = 0; i < AV1_MAX_SEGMENTS; i++) { for (j = 0; j < AV1_SEG_LVL_MAX; j++) { @@ -1645,6 +1664,10 @@ update_refs: sizeof(current->loop_filter_ref_deltas)); memcpy(priv->ref[i].loop_filter_mode_deltas, current->loop_filter_mode_deltas, sizeof(current->loop_filter_mode_deltas)); + memcpy(priv->ref[i].feature_enabled, current->feature_enabled, + sizeof(current->feature_enabled)); + memcpy(priv->ref[i].feature_value, current->feature_value, + sizeof(current->feature_value)); } }