From patchwork Thu Aug 31 07:21:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Fei W" X-Patchwork-Id: 43405 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:299e:b0:149:dfde:5c0a with SMTP id f30csp76009pzh; Thu, 31 Aug 2023 00:21:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHw+oZOdfl23T2TjU+JKGoBN1l4jZA7YTQL9ps+5HPHlh7ffMymEAH54Ym2cy36QeDsxcj6 X-Received: by 2002:aa7:dd0b:0:b0:528:90d7:a19 with SMTP id i11-20020aa7dd0b000000b0052890d70a19mr3856832edv.11.1693466515646; Thu, 31 Aug 2023 00:21:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693466515; cv=none; d=google.com; s=arc-20160816; b=D1RZ2w0LK32vRH1KQW4Jtt5q8wlXBmhhhx9zxIpdGtgXArPQ+NAs8MPb+NCgCEtAHX JhTHSX7usEWtxTKCEU/5dRQKBVUeBecJ4DpIaLOpZAu5rI47N59X7Jyb+ogpfWtJIxSV 7TQxURiHDjJeH8N3lZJqTARpqkpZsPIsF/3rpKlMSvFGxaAZgxM5rFfLq/5GZDK9/7Vp vbnt0TAcLWCgC+ygHupywZQsPNcjlxFAYQrmYxSHoO8FJxu6c45BX/kE/jxo/WovXf+b qbVHnjH5NoN9pU6XWH2MNI2oAX0xcCQOLi2RsQsWEuIbyf2zyPRC3qfXvBvMQzjC6glE zSDQ== 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:dkim-signature:delivered-to; bh=+lT5DlfGHjlfnDfhGFBUazS0D3sgmTM7cPCIdTPHbAg=; fh=i4ESP4ZRFDcfYfwXKWpOXjc2YhmIGuOsCfZUnwNO0gc=; b=A0BSH/pL6mbmkvt4E3rSsuZpxpnsAGBv2vqjj7RpkSpFQpHOPj31Uc+v6iY0dBFC5D 3dVKlVQe4OyEQTrI2fEnY7aD+yzIXiRt0TEAnaYEpabz1mdszRnKVRv75m0Be5c5ada5 mQ2bSuJtcDOwe2UVg+ox962BDxh44f8/jZnKCzBVuLeTRjHp4RFf0aun7EDzmkyF0aoG 5yGSVp3PC3GvwallZ0dWPBpjlxJpOJqerE8QCrq00Vv5cJe2BmxPkkQGGv7LzluZoX4+ /5ALQgpVYroEUgC90gszjxSuBr0TuAW+2oLDfGw1iEl8r4DW2Kr4c+SMP8tWdx/6OiaW ALOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b="QF0s/mkP"; 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 n25-20020a056402515900b00523d8bee81dsi646704edd.611.2023.08.31.00.21.55; Thu, 31 Aug 2023 00:21:55 -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; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b="QF0s/mkP"; 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 64CF868C717; Thu, 31 Aug 2023 10:21:46 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CC0C868C6B5 for ; Thu, 31 Aug 2023 10:21:39 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1693466505; x=1725002505; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hRdfaATJwXlx/uIsh6+j/tiSsDVwlVaUerWIdP51U2E=; b=QF0s/mkPgcK///mFYAaCY0hkZkOuIXXuIj7MC7evyKJ3083azLhshXxX Pfx5sfa0y3hvlQbt35Ov3pAM7lIvs63aUniL1CzA4jc4Oqua29VtQeWQK 9Wkz0bMnbDj0Nxusad+NCVr1+QYSnSUqb65NqnQgvrg/QW8zx+Qgp0o2O gjZJGulJ+9U4CHMmgZpVako69Tx5F4uvpcY36kUhm0+WYZOtt4RQROABM kFGfKMpPVXzFPBIQS971/+vhwEv9PYKYNg6yXjzwY2QyH7l5QXkiloBUZ XakfJgqFv9k6Ck7iLdZ4uBEx+3cJfjLHKJ+eeRUZEB86rBHJc4+D7FnHA Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10818"; a="355344944" X-IronPort-AV: E=Sophos;i="6.02,216,1688454000"; d="scan'208";a="355344944" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Aug 2023 00:21:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10818"; a="854045388" X-IronPort-AV: E=Sophos;i="6.02,216,1688454000"; d="scan'208";a="854045388" Received: from t-dg2.sh.intel.com ([10.239.159.29]) by fmsmga002.fm.intel.com with ESMTP; 31 Aug 2023 00:21:20 -0700 From: fei.w.wang-at-intel.com@ffmpeg.org To: ffmpeg-devel@ffmpeg.org Date: Thu, 31 Aug 2023 15:21:02 +0800 Message-Id: <20230831072107.1051955-3-fei.w.wang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230831072107.1051955-1-fei.w.wang@intel.com> References: <20230831072107.1051955-1-fei.w.wang@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 3/8] avcodec/cbs_av1: Allow specifying obu size byte length 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: fei.w.wang@intel.com Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: GS+Pf+42zGks From: Fei Wang Signed-off-by: Fei Wang --- libavcodec/cbs_av1.c | 30 +++++++++++++++++++++--------- libavcodec/cbs_av1.h | 1 + 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c index aa92639235..0c08256cc8 100644 --- a/libavcodec/cbs_av1.c +++ b/libavcodec/cbs_av1.c @@ -138,15 +138,19 @@ static int cbs_av1_read_leb128(CodedBitstreamContext *ctx, GetBitContext *gbc, return 0; } +/** Minimum byte length will be used to indicate the len128 of value if byte_len is 0. */ static int cbs_av1_write_leb128(CodedBitstreamContext *ctx, PutBitContext *pbc, - const char *name, uint64_t value) + const char *name, uint64_t value, uint8_t byte_len) { int len, i; uint8_t byte; CBS_TRACE_WRITE_START(); - len = (av_log2(value) + 7) / 7; + if (byte_len) + av_assert0(byte_len >= (av_log2(value) + 7) / 7); + + len = byte_len ? byte_len : (av_log2(value) + 7) / 7; for (i = 0; i < len; i++) { if (put_bits_left(pbc) < 8) @@ -618,7 +622,7 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc) } while (0) #define leb128(name) do { \ - CHECK(cbs_av1_write_leb128(ctx, rw, #name, current->name)); \ + CHECK(cbs_av1_write_leb128(ctx, rw, #name, current->name, 0)); \ } while (0) #define infer(name, value) do { \ @@ -1002,9 +1006,14 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx, if (obu->header.obu_has_size_field) { pbc_tmp = *pbc; - // Add space for the size field to fill later. - put_bits32(pbc, 0); - put_bits32(pbc, 0); + if (obu->obu_size_byte_len) { + for (int i = 0; i < obu->obu_size_byte_len; i++) + put_bits(pbc, 8, 0); + } else { + // Add space for the size field to fill later. + put_bits32(pbc, 0); + put_bits32(pbc, 0); + } } td = NULL; @@ -1124,7 +1133,7 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx, end_pos /= 8; *pbc = pbc_tmp; - err = cbs_av1_write_leb128(ctx, pbc, "obu_size", obu->obu_size); + err = cbs_av1_write_leb128(ctx, pbc, "obu_size", obu->obu_size, obu->obu_size_byte_len); if (err < 0) goto error; @@ -1141,8 +1150,11 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx, } if (obu->obu_size > 0) { - memmove(pbc->buf + data_pos, - pbc->buf + start_pos, header_size); + if (!obu->obu_size_byte_len) { + obu->obu_size_byte_len = start_pos - data_pos; + memmove(pbc->buf + data_pos, + pbc->buf + start_pos, header_size); + } skip_put_bytes(pbc, header_size); if (td) { diff --git a/libavcodec/cbs_av1.h b/libavcodec/cbs_av1.h index 64dfdce9c4..a9e2d2284f 100644 --- a/libavcodec/cbs_av1.h +++ b/libavcodec/cbs_av1.h @@ -401,6 +401,7 @@ typedef struct AV1RawOBU { AV1RawOBUHeader header; size_t obu_size; + uint8_t obu_size_byte_len; union { AV1RawSequenceHeader sequence_header;