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 2A70445EFC for ; Thu, 18 May 2023 06:55:56 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CF94C68C140; Thu, 18 May 2023 09:55:50 +0300 (EEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2C26D68C005 for ; Thu, 18 May 2023 09:55:43 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684392949; x=1715928949; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eRlDdQe2CBVBJ9SdgeU2iNghSd2OhXHcH+HCUL5e4cg=; b=ED/+SmS4NAio3jp9pGWVwmxe9nbkAyhF+gPrdElPTjc+jc82luY4kM4n YpLBZIfziI3tunoIA5VyySKwm190I5iDivyAaQ8di3CMZskEmHHP1k8Us EP5fKrelbjXoHviZTBrJ6E53MvBBz4a/hTIi0V79JdcKzWHVjFQL9I0hQ +UvLVQnwGoZZp/c/A4hs5MmwHYU7gM+xk6GFFHdprmCpjOWbrVEX5uAH0 F33sTtikiF5s0dGybJj2xA+bCTrrG26uQlUPVYxz+GfMpj/5c8s29h9oo B+MPYXRbMzyWvPmay6fY2VO4r8NOoYiWAqXfLZnl1CG2lbuqvO8M+v61r w==; X-IronPort-AV: E=McAfee;i="6600,9927,10713"; a="380193454" X-IronPort-AV: E=Sophos;i="5.99,284,1677571200"; d="scan'208";a="380193454" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2023 23:55:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10713"; a="846359902" X-IronPort-AV: E=Sophos;i="5.99,284,1677571200"; d="scan'208";a="846359902" Received: from xhh-tgl64.sh.intel.com ([10.238.2.19]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2023 23:55:13 -0700 From: "Xiang, Haihao" To: ffmpeg-devel@ffmpeg.org Date: Thu, 18 May 2023 14:54:38 +0800 Message-Id: <20230518065438.144156-3-haihao.xiang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230518065438.144156-1-haihao.xiang@intel.com> References: <20230518065438.144156-1-haihao.xiang@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] lavc/qsvenc: make sure continuous allocation 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: Haihao Xiang 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: Haihao Xiang Intel MediaSDK and oneVPL expect continuous allocation for data[i], however there are mandatory padding bytes between data[i] and data[i+1]. when calling av_frame_get_buffer. This patch removes all extra padding bytes. Signed-off-by: Haihao Xiang --- libavcodec/qsvenc.c | 58 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index b6813b3023..4ae9a92490 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -1882,6 +1882,62 @@ static int qsvenc_fill_padding_area(AVFrame *frame, int new_w, int new_h) return 0; } +/* frame width / height have been aligned with the alignment */ +static int qsvenc_get_continuous_buffer(AVFrame *frame) +{ + int total_size; + + switch (frame->format) { + case AV_PIX_FMT_NV12: + frame->linesize[0] = frame->width; + frame->linesize[1] = frame->linesize[0]; + total_size = frame->linesize[0] * frame->height + frame->linesize[1] * frame->height / 2; + break; + + case AV_PIX_FMT_P010: + case AV_PIX_FMT_P012: + frame->linesize[0] = 2 * frame->width; + frame->linesize[1] = frame->linesize[0]; + total_size = frame->linesize[0] * frame->height + frame->linesize[1] * frame->height / 2; + break; + + case AV_PIX_FMT_YUYV422: + frame->linesize[0] = 2 * frame->width; + frame->linesize[1] = 0; + total_size = frame->linesize[0] * frame->height; + break; + + case AV_PIX_FMT_Y210: + case AV_PIX_FMT_VUYX: + case AV_PIX_FMT_XV30: + case AV_PIX_FMT_BGRA: + case AV_PIX_FMT_X2RGB10: + frame->linesize[0] = 4 * frame->width; + frame->linesize[1] = 0; + total_size = frame->linesize[0] * frame->height; + break; + + default: + // This should never be reached + av_assert0(0); + return AVERROR(EINVAL); + } + + frame->buf[0] = av_buffer_alloc(total_size); + if (!frame->buf[0]) + return AVERROR(ENOMEM); + + frame->data[0] = frame->buf[0]->data; + frame->extended_data = frame->data; + + if (frame->format == AV_PIX_FMT_NV12 || + frame->format == AV_PIX_FMT_P010 || + frame->format == AV_PIX_FMT_P012) + frame->data[1] = frame->data[0] + frame->linesize[0] * frame->height; + + return 0; +} + static int submit_frame(QSVEncContext *q, const AVFrame *frame, QSVFrame **new_frame) { @@ -1919,7 +1975,7 @@ static int submit_frame(QSVEncContext *q, const AVFrame *frame, qf->frame->format = frame->format; if (!qf->frame->data[0]) { - ret = av_frame_get_buffer(qf->frame, q->width_align); + ret = qsvenc_get_continuous_buffer(qf->frame); if (ret < 0) return ret; } -- 2.34.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".