From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id D5C3D49560 for ; Thu, 14 Mar 2024 08:16:44 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E02EE68D171; Thu, 14 Mar 2024 10:16:14 +0200 (EET) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ACCD668D15D for ; Thu, 14 Mar 2024 10:16:07 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1710404173; x=1741940173; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=O613hJdn/ON3U4POGH1jx85L+wvutN4kyB3kZlGq/9o=; b=BqkDmD4zIsX76/cIA3dPIW04RcGuFRIB1uJoUY8Z4cnccwwL/BDamDbB tYFEpk2y8FIf3mVYzIyIcFfZ8UQFxbDTuZ599frV+ZxFzTkeMgNuPpFj2 yPIJsI9FmOlQxLj0l4ZXee8HE6PjB80s1p0nEJIjrY3f04GBKBmj+Zw9a cDOmXVqNOLl7Txjd2buy0n0o2QEUZw+mUC749udsdD7H5ekppk3ozVQ2K +0Pjn5Pw7W1F8PHaZSkDV5ywiizAVF4YHBeuELfjBRtWCcdT9F4sHsZR4 28YsBwpSNEDnqyBID2DisuIKORYvL43H3rq7OiXsjoWid3q2EY0p2YU8V g==; X-IronPort-AV: E=McAfee;i="6600,9927,11012"; a="9029373" X-IronPort-AV: E=Sophos;i="6.07,124,1708416000"; d="scan'208";a="9029373" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Mar 2024 01:16:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,124,1708416000"; d="scan'208";a="12095262" Received: from desktop-qn7n0nf.sh.intel.com (HELO localhost.localdomain) ([10.239.160.66]) by fmviesa007.fm.intel.com with ESMTP; 14 Mar 2024 01:16:03 -0700 From: tong1.wu-at-intel.com@ffmpeg.org To: ffmpeg-devel@ffmpeg.org Date: Thu, 14 Mar 2024 16:14:47 +0800 Message-ID: <20240314081456.379-4-tong1.wu@intel.com> X-Mailer: git-send-email 2.41.0.windows.1 In-Reply-To: <20240314081456.379-1-tong1.wu@intel.com> References: <20240314081456.379-1-tong1.wu@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 04/12] avcodec/vaapi_encode: extract a init function to base layer 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: Tong Wu Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Tong Wu Move the base_ctx parameter initialization to base layer. Signed-off-by: Tong Wu --- libavcodec/hw_base_encode.c | 33 +++++++++++++++++++++++++++++++++ libavcodec/hw_base_encode.h | 2 ++ libavcodec/vaapi_encode.c | 36 ++++-------------------------------- 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/libavcodec/hw_base_encode.c b/libavcodec/hw_base_encode.c index dcba902f44..71ead512c0 100644 --- a/libavcodec/hw_base_encode.c +++ b/libavcodec/hw_base_encode.c @@ -597,3 +597,36 @@ end: return 0; } + +int ff_hw_base_encode_init(AVCodecContext *avctx) +{ + HWBaseEncodeContext *ctx = avctx->priv_data; + + ctx->frame = av_frame_alloc(); + if (!ctx->frame) + return AVERROR(ENOMEM); + + if (!avctx->hw_frames_ctx) { + av_log(avctx, AV_LOG_ERROR, "A hardware frames reference is " + "required to associate the encoding device.\n"); + return AVERROR(EINVAL); + } + + ctx->input_frames_ref = av_buffer_ref(avctx->hw_frames_ctx); + if (!ctx->input_frames_ref) + return AVERROR(ENOMEM); + + ctx->input_frames = (AVHWFramesContext *)ctx->input_frames_ref->data; + + ctx->device_ref = av_buffer_ref(ctx->input_frames->device_ref); + if (!ctx->device_ref) + return AVERROR(ENOMEM); + + ctx->device = (AVHWDeviceContext *)ctx->device_ref->data; + + ctx->tail_pkt = av_packet_alloc(); + if (!ctx->tail_pkt) + return AVERROR(ENOMEM); + + return 0; +} diff --git a/libavcodec/hw_base_encode.h b/libavcodec/hw_base_encode.h index c9df95f952..c9c8fb43c9 100644 --- a/libavcodec/hw_base_encode.h +++ b/libavcodec/hw_base_encode.h @@ -226,6 +226,8 @@ typedef struct HWBaseEncodeContext { int ff_hw_base_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt); +int ff_hw_base_encode_init(AVCodecContext *avctx); + #define HW_BASE_ENCODE_COMMON_OPTIONS \ { "idr_interval", \ "Distance (in I-frames) between key frames", \ diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c index c6742c4301..887543734b 100644 --- a/libavcodec/vaapi_encode.c +++ b/libavcodec/vaapi_encode.c @@ -2208,45 +2208,17 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx) VAStatus vas; int err; + err = ff_hw_base_encode_init(avctx); + if (err < 0) + goto fail; + ctx->va_config = VA_INVALID_ID; ctx->va_context = VA_INVALID_ID; base_ctx->op = &vaapi_op; - /* If you add something that can fail above this av_frame_alloc(), - * modify ff_vaapi_encode_close() accordingly. */ - base_ctx->frame = av_frame_alloc(); - if (!base_ctx->frame) { - return AVERROR(ENOMEM); - } - - if (!avctx->hw_frames_ctx) { - av_log(avctx, AV_LOG_ERROR, "A hardware frames reference is " - "required to associate the encoding device.\n"); - return AVERROR(EINVAL); - } - - base_ctx->input_frames_ref = av_buffer_ref(avctx->hw_frames_ctx); - if (!base_ctx->input_frames_ref) { - err = AVERROR(ENOMEM); - goto fail; - } - base_ctx->input_frames = (AVHWFramesContext*)base_ctx->input_frames_ref->data; - - base_ctx->device_ref = av_buffer_ref(base_ctx->input_frames->device_ref); - if (!base_ctx->device_ref) { - err = AVERROR(ENOMEM); - goto fail; - } - base_ctx->device = (AVHWDeviceContext*)base_ctx->device_ref->data; ctx->hwctx = base_ctx->device->hwctx; - base_ctx->tail_pkt = av_packet_alloc(); - if (!base_ctx->tail_pkt) { - err = AVERROR(ENOMEM); - goto fail; - } - err = vaapi_encode_profile_entrypoint(avctx); if (err < 0) goto fail; -- 2.41.0.windows.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".