From patchwork Tue Apr 11 07:30:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Zhao X-Patchwork-Id: 3363 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.44.195 with SMTP id s186csp1749235vss; Tue, 11 Apr 2017 00:31:15 -0700 (PDT) X-Received: by 10.223.128.194 with SMTP id 60mr41558742wrl.175.1491895875265; Tue, 11 Apr 2017 00:31:15 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id o82si1770735wmo.131.2017.04.11.00.31.12; Tue, 11 Apr 2017 00:31:15 -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=@gmail.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0DE37689948; Tue, 11 Apr 2017 10:31:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f177.google.com (mail-pf0-f177.google.com [209.85.192.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4AC06689213 for ; Tue, 11 Apr 2017 10:30:58 +0300 (EEST) Received: by mail-pf0-f177.google.com with SMTP id o126so44866985pfb.3 for ; Tue, 11 Apr 2017 00:31:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=y4eY0Nwuh0pJhhX8i35nLPhMe5Wanh8MDJFpAAInkto=; b=MekBArSGJ84VAEGjOzFaH6rPLqcCJDjfmzolrm+QgHHgqdfzIeeU052TPJktKkNUlu CftOuA3Drm9VGnbaqLS7316wGyV88RO8VmF4SOaX7t5ThGqbrHwsCrQlMqmvaxsSgbL5 KgbORSbNAbk0hqtU+C6F618CVAr6+EAFmysHdOkHa9bUlHx/TbKSLjVgJMAxhCpAd5xp qgdlV779IXD+Y4uzJWb2YlP7QzTQqE3fOErs1QqZ8P7JPoUrYjIe1LZFzTX8lgiIUmmq q7oqOop2FxJ/dRiDnxhfprWnOFBo4gqMOvj8cfpAG2h1dA55kkyTM52p8JPPVFE2VS70 rhhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=y4eY0Nwuh0pJhhX8i35nLPhMe5Wanh8MDJFpAAInkto=; b=oy2QMkpQapH0r7pbn5wQwjw2/r1s7qYUG/TssUZ+vMb1R2XxkhWCjwP3x7M5YEsjp9 sYBLD/d98EIT23MV0C+3Mk9tmtXzJYmJzTbxDTSXAkotUfMP/WNJugeeV+0HN8p4MINJ Rs8d4EA01oQ4vFPHM+Fdw7uanzrVIp2TB06kH8rMAItzG8R/VknHDM+qpAdnkY4e3Sob mbMjURcJI9wmvF5sCtFZog4c7wPqvay7lAOjhdmn/d7rMMX2d4MS16acsQUGRNVteQaQ B9dJs6sMBR1nh6n/8u7BrGZZK2kLDKx+0mjmGRdEbf+EsqP5p+xY/GZOM+juvBYdKU3H 3FIA== X-Gm-Message-State: AFeK/H39MWp5Apu4yeX18ShIid6O5cGwjHGCnZrNqQ6TGP2ZpzKHgEndEBi6MB9T+widow== X-Received: by 10.99.152.65 with SMTP id l1mr59993347pgo.59.1491895861602; Tue, 11 Apr 2017 00:31:01 -0700 (PDT) Received: from [10.239.204.51] ([192.55.55.41]) by smtp.gmail.com with ESMTPSA id m29sm22237804pfj.32.2017.04.11.00.30.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Apr 2017 00:31:00 -0700 (PDT) To: FFmpeg development discussions and patches , Mark Thompson From: Jun Zhao Message-ID: Date: Tue, 11 Apr 2017 15:30:57 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.0 MIME-Version: 1.0 Content-Language: en-US Content-Disposition: attachment; filename*0="0001-hwcontext_vaapi-use-the-special-UC-copy-for-download.pa"; filename*1="tch" X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: [FFmpeg-devel] [PATCH] hwcontext_vaapi: use the special UC copy for downloading, frames. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From 9bab458006369f427fa2f4c6248ee89329e81067 Mon Sep 17 00:00:00 2001 From: Jun Zhao Date: Tue, 11 Apr 2017 14:37:07 +0800 Subject: [PATCH] hwcontext_vaapi: use the special UC copy for downloading frames. used SSE4 UC function for copying image data from GPU mapped memory, see https://software.intel.com/en-us/articles/copying-accelerated-video-decode-frame-buffers before this change, VA-API HWAccel decoder copy image data from GPU mapped memory used vaCreateImage/vaGetImage/av_frame_copy, now use vaDeriveImage/av_image_copy_uc_from. decoding a 3000 frames 1080p h264 stream in Intel(R) Core(TM) i5-6260U CPU @ 1.80GHz, the CPU usage and decode fps as follow: 1. Software decoder. ./ffmpeg -i ./skyfall2-trailer.mp4 -f null /dev/null CPU: 80%, fps: 334fps 2a. vaCreateImage/vaGetImage/av_frame_copy ./ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -i skyfall2-trailer.mp4 -f null /dev/null CPU: 12%, fps: 147fps 2b. vaDeriveImage/av_image_copy_uc_from ./ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -i skyfall2-trailer.mp4 -f null /dev/null CPU: 23%, fps: 628fps Signed-off-by: Jun Zhao --- libavutil/hwcontext_vaapi.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c index 3b50e95..23899f1 100644 --- a/libavutil/hwcontext_vaapi.c +++ b/libavutil/hwcontext_vaapi.c @@ -40,6 +40,7 @@ #include "mem.h" #include "pixdesc.h" #include "pixfmt.h" +#include "imgutils.h" typedef struct VAAPIDevicePriv { #if HAVE_VAAPI_X11 @@ -720,7 +721,7 @@ static int vaapi_map_frame(AVHWFramesContext *hwfc, // assume for now that the user is not aware of that and would therefore // prefer not to be given direct-mapped memory if they request read access. if (ctx->derive_works && dst->format == hwfc->sw_format && - ((flags & AV_HWFRAME_MAP_DIRECT) || !(flags & AV_HWFRAME_MAP_READ))) { + ((flags & AV_HWFRAME_MAP_DIRECT) || (flags & AV_HWFRAME_MAP_READ))) { vas = vaDeriveImage(hwctx->display, surface_id, &map->image); if (vas != VA_STATUS_SUCCESS) { av_log(hwfc, AV_LOG_ERROR, "Failed to derive image from " @@ -736,7 +737,6 @@ static int vaapi_map_frame(AVHWFramesContext *hwfc, err = AVERROR(EIO); goto fail; } - map->flags |= AV_HWFRAME_MAP_DIRECT; } else { vas = vaCreateImage(hwctx->display, image_format, hwfc->width, hwfc->height, &map->image); @@ -806,7 +806,8 @@ static int vaapi_transfer_data_from(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src) { AVFrame *map; - int err; + int i,err; + ptrdiff_t src_linesize[4], dst_linesize[4]; if (dst->width > hwfc->width || dst->height > hwfc->height) return AVERROR(EINVAL); @@ -823,11 +824,12 @@ static int vaapi_transfer_data_from(AVHWFramesContext *hwfc, map->width = dst->width; map->height = dst->height; - err = av_frame_copy(dst, map); - if (err) - goto fail; - - err = 0; + for (i = 0; i < 4; i++) { + dst_linesize[i] = dst->linesize[i]; + src_linesize[i] = map->linesize[i]; + } + av_image_copy_uc_from(dst->data, dst_linesize, map->data, src_linesize, + hwfc->sw_format, src->width, src->height); fail: av_frame_free(&map); return err;