From patchwork Wed Oct 21 00:11:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23127 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 21DF044AC78 for ; Wed, 21 Oct 2020 03:17:51 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0BC7968B796; Wed, 21 Oct 2020 03:17:51 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 77B6F68B787 for ; Wed, 21 Oct 2020 03:17:44 +0300 (EEST) Received: by mail-qt1-f169.google.com with SMTP id j62so707781qtd.0 for ; Tue, 20 Oct 2020 17:17:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=y8GoEOfuVm1llsOWfHYYNbT5ma+4jVIlp12enmkappY=; b=j9lxWnGzBicj02YMDPioP64xJ/kQYW3ITzB+9T0SBhj/W3BwBc9oxTFrDcUNrNQDax NGWInOjhULCYc57qrPAiQmbEfEmMlKmfyj9EVFqsj1zdxLyIzFr39Yz4LAuEyuSHlhPf R+RZYbjNVACNMC9htN5xsRkXtA+8SQPPk6pCT1wSRLesI9z4zAfvqH5wIztAGxPwLHTE IGsDfSTWEI8irmFq55MNc9uV+68jBll8YUetXDioU3iMLuOWpox416DG8gaN2hyqwfvj 3i8c4kxX3oqWYSESmBzemwO2W55Qz2qCp/UR5sdwa2ytyQySG5d7yYV4RTFrqyWV13jo HxNA== 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:mime-version :content-transfer-encoding; bh=y8GoEOfuVm1llsOWfHYYNbT5ma+4jVIlp12enmkappY=; b=lMejft9KEBSBa2kbR6GNDd93HETZIjtIBCFbXSuhMYS8lNNQXpJ1QCTQXG9G3DOiY3 ZVfX0SBY6UrIEXwSDwi33ZoSMIRgCTs/wGM+1avQsyMJbJUzQhiLSQa0t75mVCLUv3wi 6T+Bm81+D14Y8PEp2JZFRl5imzeJPxtkh4e9DV8AlVej+EdVOR1/Q8+DAvzAQy4ujiEG MMePQOqHX8VUzfhFvi7h/qi3DLuz/BP42IskXTG5gMLNCwtyPYKql3Wj48+u/AzzH3in HPTMXMMSLvDZfCxFxfO5nrfQPfIpRcGqDZR6aA3DqE/mvlyvTFyolkTkjtxUnxf36BqJ liJQ== X-Gm-Message-State: AOAM531bXvl7JRCsfdZBFNdrZJ3X537G4bw7i0u0YzWJD90tZLh99h0p /r+X7+e5FaYNbBDYWaI+OskAEOOvFf0= X-Google-Smtp-Source: ABdhPJz8nsje8jzV9wphrD4TDA6wAAxIystFfPxKLt5nxBhF+HA2eWpmxqvLmXZ0RUXRtL7YpdBuSA== X-Received: by 2002:ae9:c211:: with SMTP id j17mr851473qkg.458.1603239103840; Tue, 20 Oct 2020 17:11:43 -0700 (PDT) Received: from localhost.localdomain ([181.23.86.134]) by smtp.gmail.com with ESMTPSA id p21sm205528qtf.5.2020.10.20.17.11.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Oct 2020 17:11:43 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 20 Oct 2020 21:11:24 -0300 Message-Id: <20201021001126.14044-1-jamrial@gmail.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] avcodec/cbs_av1: infer loop filter delta 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 | 3 +++ libavcodec/cbs_av1_syntax_template.c | 40 +++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/libavcodec/cbs_av1.h b/libavcodec/cbs_av1.h index 7a0c08c596..97aeee9795 100644 --- a/libavcodec/cbs_av1.h +++ b/libavcodec/cbs_av1.h @@ -413,6 +413,9 @@ typedef struct AV1ReferenceFrameState { int subsampling_y; // RefSubsamplingY int bit_depth; // RefBitDepth int order_hint; // RefOrderHint + + int8_t loop_filter_ref_deltas[AV1_TOTAL_REFS_PER_FRAME]; + int8_t loop_filter_mode_deltas[2]; } AV1ReferenceFrameState; typedef struct CodedBitstreamAV1Context { diff --git a/libavcodec/cbs_av1_syntax_template.c b/libavcodec/cbs_av1_syntax_template.c index bcaa334134..4edf4fd47c 100644 --- a/libavcodec/cbs_av1_syntax_template.c +++ b/libavcodec/cbs_av1_syntax_template.c @@ -837,6 +837,9 @@ static int FUNC(loop_filter_params)(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current) { CodedBitstreamAV1Context *priv = ctx->priv_data; + static const int8_t default_loop_filter_ref_deltas[AV1_TOTAL_REFS_PER_FRAME] = + { 1, 0, 0, 0, -1, 0, -1, -1 }; + static const int8_t default_loop_filter_mode_deltas[2] = { 0 }; int i, err; if (priv->coded_lossless || current->allow_intrabc) { @@ -870,19 +873,44 @@ static int FUNC(loop_filter_params)(CodedBitstreamContext *ctx, RWContext *rw, flag(loop_filter_delta_enabled); if (current->loop_filter_delta_enabled) { + const int8_t *loop_filter_ref_deltas, *loop_filter_mode_deltas; + + if (current->primary_ref_frame == AV1_PRIMARY_REF_NONE) { + loop_filter_ref_deltas = default_loop_filter_ref_deltas; + loop_filter_mode_deltas = default_loop_filter_mode_deltas; + } else { + loop_filter_ref_deltas = + priv->ref[current->ref_frame_idx[current->primary_ref_frame]].loop_filter_ref_deltas; + loop_filter_mode_deltas = + priv->ref[current->ref_frame_idx[current->primary_ref_frame]].loop_filter_mode_deltas; + } + flag(loop_filter_delta_update); - if (current->loop_filter_delta_update) { for (i = 0; i < AV1_TOTAL_REFS_PER_FRAME; i++) { - flags(update_ref_delta[i], 1, i); + if (current->loop_filter_delta_update) + flags(update_ref_delta[i], 1, i); + else + infer(update_ref_delta[i], 0); if (current->update_ref_delta[i]) sus(1 + 6, loop_filter_ref_deltas[i], 1, i); + else + infer(loop_filter_ref_deltas[i], loop_filter_ref_deltas[i]); } for (i = 0; i < 2; i++) { - flags(update_mode_delta[i], 1, i); + if (current->loop_filter_delta_update) + flags(update_mode_delta[i], 1, i); + else + infer(update_mode_delta[i], 0); if (current->update_mode_delta[i]) sus(1 + 6, loop_filter_mode_deltas[i], 1, i); + else + infer(loop_filter_mode_deltas[i], loop_filter_mode_deltas[i]); } - } + } else { + for (i = 0; i < AV1_TOTAL_REFS_PER_FRAME; i++) + infer(loop_filter_ref_deltas[i], default_loop_filter_ref_deltas[i]); + for (i = 0; i < 2; i++) + infer(loop_filter_mode_deltas[i], default_loop_filter_mode_deltas[i]); } return 0; @@ -1613,6 +1641,10 @@ update_refs: .bit_depth = priv->bit_depth, .order_hint = priv->order_hint, }; + memcpy(priv->ref[i].loop_filter_ref_deltas, current->loop_filter_ref_deltas, + 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)); } }