From patchwork Fri Feb 18 01:42:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Fei W" X-Patchwork-Id: 34371 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp514907nkx; Thu, 17 Feb 2022 17:48:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJz3d7pSTraoHZnai/e6NOTBWc7O1bL6R7rqMXhZnJMV9bJWqSPuQOwdxx4UGcKD3C+04M3K X-Received: by 2002:a50:9f08:0:b0:410:b961:eea4 with SMTP id b8-20020a509f08000000b00410b961eea4mr5765764edf.394.1645148903736; Thu, 17 Feb 2022 17:48:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645148903; cv=none; d=google.com; s=arc-20160816; b=hKW8l5Uizqc/mrTAzLk0C9tr6zxqsJOMHUwflEOYtpqlGRmllSF15h4r7V8USRfqmo NB+gGABIGI+p7tj+EzjKo9ToMN2+kMa0PgP4hmyBKcUdNyarUDUCubOIH6uurb1YxF3C yAnLBEjJBBrHiCeJ3HS80t32e//0+DMucWaYDLuWYiTdqDTvTsUlkWe2xzde+qwzO9xZ 28MTl0sYsgVEn3kb1OL/S0EAFOUZ9sj5avGQqjks9INrPHzlPYEi3v9kEdkGPpzKGZvf MsEUvzZSbS00i3+izjc2upSQxh1yvFI7WlTRatWpjZSATXCMAcZlu0CpBFc/5TBRz+Zj S5QA== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=h9gSgJVUBfBgw1iPbJfQ9Z3MZkO2eqnnJkxE38hffUc=; b=q/4T5KgAIsRPpGYNvrabySXNljUD3hC6ePxZNcos9pXJUbS7DY6moCPQYk25uEhXOM P/RhmvbSIitm8Kab7HStYticXddVBSIRKnmQYdc3/fy4wloPhn9hmruGKnvLX+EkNh5Z V4rLxPDIkAQKHKvCenVDWaPjLPJI92BYej3zGrc58CixRRRN+YporpX+BJfCiXZa28x1 ihaukSFbk9Ql2E9Db13IxWRAaSzlUvdhPtiMIqgE7t7mN4DRwLSfFeJwkdBzASrpwK7Y KCwuCMcLyklpGlCvEYngmxR6pmvOL6g1hLuv1GmcK1xihr4PJVd2tOj6kzXVUmUyQalO OVFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=DhLQw6pE; 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 hp3si3397335ejc.847.2022.02.17.17.48.23; Thu, 17 Feb 2022 17:48:23 -0800 (PST) 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=DhLQw6pE; 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 99FDE68B2F6; Fri, 18 Feb 2022 03:48:20 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BF81068B2F6 for ; Fri, 18 Feb 2022 03:48:13 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645148899; x=1676684899; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=r5zEsWxpHPI0q8COMLYw0h3yEglZJku2zbbBz2Gp0HI=; b=DhLQw6pE547/FaUYuOI28q/csPtPki3WvaLRK+MgX+gbEVAHY5uLeWMj WeAidXJkG8VofvIjVTH0WM3kWM78LMHIB2D/d0d759k/OBmJO3XfjCKVD CwC7Fo1Ykwuy/O5wMDuIRa29Tt7UGZRaYAirmJc2n6JCS2helcRoOvVUT tv+lJXVxqkHaBQ+GwWryB0njeisbaJxPw+rxh86meDWL4Z4MCDlm63Y4h 5vEO64lo9GTR8o0ieiu4YzMrdTm5OUR49Ywfk8b914icRrcmUNZXKuD0G tBT+LQCEh37vC3fyHznOXY/wjCh9Gl8PVOW8sKUcDf5YWs8JxrtHWTQaz g==; X-IronPort-AV: E=McAfee;i="6200,9189,10261"; a="231010239" X-IronPort-AV: E=Sophos;i="5.88,377,1635231600"; d="scan'208";a="231010239" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2022 17:48:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,377,1635231600"; d="scan'208";a="777781284" Received: from t.sh.intel.com ([10.239.159.147]) by fmsmga005.fm.intel.com with ESMTP; 17 Feb 2022 17:48:10 -0800 From: Fei Wang To: ffmpeg-devel@ffmpeg.org Date: Fri, 18 Feb 2022 09:42:58 +0800 Message-Id: <20220218014301.1830754-1-fei.w.wang@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v1 1/4] lavc/vaapi_encode_h265: Add P frame to GPB frame support for hevc_vaapi 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 Wang , Linjie Fu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: BPXUBXkHI/sk From: Linjie Fu Use GPB frames to replace regular P frames if backend driver does not support it. - GPB: Generalized P and B picture. P frames replaced by B frames with forward-predict only, L0 == L1. Normal B frames still have 2 different ref_lists and allow bi-prediction Signed-off-by: Linjie Fu Signed-off-by: Fei Wang --- libavcodec/vaapi_encode.c | 33 +++++++++++++++++++++++++++++++-- libavcodec/vaapi_encode.h | 1 + libavcodec/vaapi_encode_h265.c | 15 +++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c index 3bf379b1a0..95eca7c288 100644 --- a/libavcodec/vaapi_encode.c +++ b/libavcodec/vaapi_encode.c @@ -1845,6 +1845,30 @@ static av_cold int vaapi_encode_init_gop_structure(AVCodecContext *avctx) ref_l1 = attr.value >> 16 & 0xffff; } + ctx->p_to_gpb = 0; + +#if VA_CHECK_VERSION(1, 9, 0) + attr = (VAConfigAttrib) { VAConfigAttribPredictionDirection }; + vas = vaGetConfigAttributes(ctx->hwctx->display, + ctx->va_profile, + ctx->va_entrypoint, + &attr, 1); + if (vas != VA_STATUS_SUCCESS) { + av_log(avctx, AV_LOG_WARNING, "Failed to query prediction direction " + "attribute: %d (%s).\n", vas, vaErrorStr(vas)); + } else if (attr.value == VA_ATTRIB_NOT_SUPPORTED) { + av_log(avctx, AV_LOG_VERBOSE, "Driver does not report whether " + "support GPB, use regular P frames.\n"); + } else { + if (attr.value & VA_PREDICTION_DIRECTION_BI_NOT_EMPTY) { + ctx->p_to_gpb = 1; + av_log(avctx, AV_LOG_VERBOSE, "Use GPB B frames to replace " + "regular P frames.\n"); + } else + av_log(avctx, AV_LOG_VERBOSE, "Use regular P frames.\n"); + } +#endif + if (ctx->codec->flags & FLAG_INTRA_ONLY || avctx->gop_size <= 1) { av_log(avctx, AV_LOG_VERBOSE, "Using intra frames only.\n"); @@ -1861,8 +1885,13 @@ static av_cold int vaapi_encode_init_gop_structure(AVCodecContext *avctx) ctx->p_per_i = INT_MAX; ctx->b_per_p = 0; } else { - av_log(avctx, AV_LOG_VERBOSE, "Using intra, P- and B-frames " - "(supported references: %d / %d).\n", ref_l0, ref_l1); + if (ctx->p_to_gpb) + av_log(avctx, AV_LOG_VERBOSE, "Using intra, GPB-B-frames and " + "B-frames (supported references: %d / %d).\n", + ref_l0, ref_l1); + else + av_log(avctx, AV_LOG_VERBOSE, "Using intra, P- and B-frames " + "(supported references: %d / %d).\n", ref_l0, ref_l1); ctx->gop_size = avctx->gop_size; ctx->p_per_i = INT_MAX; ctx->b_per_p = avctx->max_b_frames; diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h index b41604a883..61c5615eb8 100644 --- a/libavcodec/vaapi_encode.h +++ b/libavcodec/vaapi_encode.h @@ -328,6 +328,7 @@ typedef struct VAAPIEncodeContext { int idr_counter; int gop_counter; int end_of_stream; + int p_to_gpb; // Whether the driver supports ROI at all. int roi_allowed; diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c index e1dc53dfa9..ea45893508 100644 --- a/libavcodec/vaapi_encode_h265.c +++ b/libavcodec/vaapi_encode_h265.c @@ -886,6 +886,7 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice) { + VAAPIEncodeContext *ctx = avctx->priv_data; VAAPIEncodeH265Context *priv = avctx->priv_data; VAAPIEncodeH265Picture *hpic = pic->priv_data; const H265RawSPS *sps = &priv->raw_sps; @@ -908,6 +909,9 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx, sh->slice_type = hpic->slice_type; + if (sh->slice_type == HEVC_SLICE_P && ctx->p_to_gpb) + sh->slice_type = HEVC_SLICE_B; + sh->slice_pic_order_cnt_lsb = hpic->pic_order_cnt & (1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4)) - 1; @@ -1066,6 +1070,9 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx, av_assert0(pic->type == PICTURE_TYPE_P || pic->type == PICTURE_TYPE_B); vslice->ref_pic_list0[0] = vpic->reference_frames[0]; + if (ctx->p_to_gpb && pic->type == PICTURE_TYPE_P) + // Reference for GPB B-frame, L0 == L1 + vslice->ref_pic_list1[0] = vpic->reference_frames[0]; } if (pic->nb_refs >= 2) { // Forward reference for B-frame. @@ -1073,6 +1080,14 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx, vslice->ref_pic_list1[0] = vpic->reference_frames[1]; } + if (pic->type == PICTURE_TYPE_P && ctx->p_to_gpb) { + vslice->slice_type = HEVC_SLICE_B; + for (i = 0; i < FF_ARRAY_ELEMS(vslice->ref_pic_list0); i++) { + vslice->ref_pic_list1[i].picture_id = vslice->ref_pic_list0[i].picture_id; + vslice->ref_pic_list1[i].flags = vslice->ref_pic_list0[i].flags; + } + } + return 0; }