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 45B9644369 for ; Mon, 10 Oct 2022 08:08:27 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 832DA68BCB4; Mon, 10 Oct 2022 11:08:24 +0300 (EEST) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5B08668B968 for ; Mon, 10 Oct 2022 11:08:18 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665389303; x=1696925303; h=from:to:cc:subject:date:message-id; bh=TjPZmxrBVCniNk9PSuqy8iZr/3EE3n3htJQvryYuPCk=; b=dPYq76g2l8i2wc44O/vIpYlqWVYrbV6Y0CbPGyFn8GxvNXC3lyYlu3+P dtJMmVk6vBRRpsgG44IJl9E+/mUQDwKW9Vuc5I2rKILwHJ6p6PHx6fP1m 7eVjT2la/WMOMLoQUo8lIRk9qDDHAtqrwjisfskrURDi0vQWR6vGKZkXq FXsueMXeVl3p+5oWGEjZ1dKC4YXJ+7Saf4l1uN6YDG9p2D4TSKELfy6B7 V2x/urmg0FcgcWBf2Pw1mZMZs+/9JY7tWM5Tz7n/XDSd3ChsawFGTTZyg I+n+ygUldp9+WDYW35Hg3AlIOjPE+D0F9xng+5ogMgPlS7yuKfyU3XYWf A==; X-IronPort-AV: E=McAfee;i="6500,9779,10495"; a="284548740" X-IronPort-AV: E=Sophos;i="5.95,173,1661842800"; d="scan'208";a="284548740" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Oct 2022 01:08:04 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10495"; a="625887347" X-IronPort-AV: E=Sophos;i="5.95,173,1661842800"; d="scan'208";a="625887347" Received: from xhh-dg164.sh.intel.com ([10.238.5.169]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Oct 2022 01:08:03 -0700 From: "Xiang, Haihao" To: ffmpeg-devel@ffmpeg.org Date: Mon, 10 Oct 2022 16:05:45 +0800 Message-Id: <20221010080545.1550-1-haihao.xiang@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] lavc/qsvenc: fill the padding area 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 MIME-Version: 1.0 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 qsvenc makes a copy when the input in system memory is not padded as the SDK requires, however the padding area is not filled with right data Signed-off-by: Haihao Xiang --- libavcodec/qsvenc.c | 69 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index dc5479d0f3..15e6936a65 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -1514,6 +1514,64 @@ static int get_free_frame(QSVEncContext *q, QSVFrame **f) return 0; } +static int qsvenc_fill_padding_area(AVFrame *frame, int new_w, int new_h) +{ + const AVPixFmtDescriptor *desc; + int max_step[4], filled[4] = { 0 }; + + desc = av_pix_fmt_desc_get(frame->format); + av_assert0(desc); + av_image_fill_max_pixsteps(max_step, NULL, desc); + + for (int i = 0; i < desc->nb_components; i++) { + const AVComponentDescriptor *comp = &desc->comp[i]; + int sheight, dheight, plane = comp->plane; + ptrdiff_t swidth = av_image_get_linesize(frame->format, + frame->width, + plane); + ptrdiff_t dwidth = av_image_get_linesize(frame->format, + new_w, + plane); + + if (swidth < 0 || dwidth < 0) { + av_log(NULL, AV_LOG_ERROR, "av_image_get_linesize failed\n"); + return AVERROR(EINVAL); + } + + if (filled[plane]) + continue; + + sheight = frame->height; + dheight = new_h; + + if (plane) { + sheight = AV_CEIL_RSHIFT(frame->height, desc->log2_chroma_h); + dheight = AV_CEIL_RSHIFT(new_h, desc->log2_chroma_h); + } + + // Fill right padding + if (new_w > frame->width) { + for (int j = 0; j < sheight; j++) { + void *line_ptr = frame->data[plane] + j * frame->linesize[plane] + swidth; + + av_memcpy_backptr(line_ptr, + max_step[plane], + new_w - frame->width); + } + } + + // Fill bottom padding + for (int j = sheight; j < dheight; j++) + memcpy(frame->data[plane] + j * frame->linesize[plane], + frame->data[plane] + (sheight - 1) * frame->linesize[plane], + dwidth); + + filled[plane] = 1; + } + + return 0; +} + static int submit_frame(QSVEncContext *q, const AVFrame *frame, QSVFrame **new_frame) { @@ -1543,8 +1601,9 @@ static int submit_frame(QSVEncContext *q, const AVFrame *frame, /* and to make allocation continious for data[0]/data[1] */ if ((frame->height & 31 || frame->linesize[0] & (q->width_align - 1)) || (frame->data[1] - frame->data[0] != frame->linesize[0] * FFALIGN(qf->frame->height, q->height_align))) { - qf->frame->height = FFALIGN(frame->height, q->height_align); - qf->frame->width = FFALIGN(frame->width, q->width_align); + int tmp_w, tmp_h; + qf->frame->height = tmp_h = FFALIGN(frame->height, q->height_align); + qf->frame->width = tmp_w = FFALIGN(frame->width, q->width_align); qf->frame->format = frame->format; @@ -1562,6 +1621,12 @@ static int submit_frame(QSVEncContext *q, const AVFrame *frame, av_frame_unref(qf->frame); return ret; } + + ret = qsvenc_fill_padding_area(qf->frame, tmp_w, tmp_h); + if (ret < 0) { + av_frame_unref(qf->frame); + return ret; + } } else { av_frame_unref(qf->frame); ret = av_frame_ref(qf->frame, frame); -- 2.17.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".