From patchwork Tue Feb 16 10:59:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Ser X-Patchwork-Id: 25654 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 12A6444B8FA for ; Tue, 16 Feb 2021 13:00:07 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D0A8E6880FF; Tue, 16 Feb 2021 13:00:06 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 247B5687FA1 for ; Tue, 16 Feb 2021 13:00:01 +0200 (EET) X-Originating-IP: 86.247.11.12 Received: from haruko.lan (lfbn-idf2-1-654-12.w86-247.abo.wanadoo.fr [86.247.11.12]) (Authenticated sender: schroder@emersion.fr) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 723921C000F; Tue, 16 Feb 2021 10:59:59 +0000 (UTC) From: Simon Ser To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Feb 2021 11:59:57 +0100 Message-Id: <20210216105957.538570-1-contact@emersion.fr> X-Mailer: git-send-email 2.30.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] hwcontext_vaapi: introduce AV_HWFRAME_MAP_{SEPARATE, COMBINED}_PLANES 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 Cc: Haihao Xiang , Mark Thompson , Fei Wang Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This allows callers to ask for separate or combined plane formats. Combined formats are desirable in many scenarios, for instance when directly importing the DMA-BUFs into APIs such as GL (as a single EGLImage), KMS or Wayland. This patch was tested with the following Mesa MR: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9015 v2: - Add SEPARATE_PLANES flag - Rename to AV_HWFRAME_COMBINED_PLANES Signed-off-by: Simon Ser Cc: Mark Thompson Cc: Haihao Xiang Cc: Fei Wang --- libavutil/hwcontext.h | 12 ++++++++++++ libavutil/hwcontext_vaapi.c | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h index 04d19d89c2b8..e24cb1470595 100644 --- a/libavutil/hwcontext.h +++ b/libavutil/hwcontext.h @@ -538,6 +538,18 @@ enum { * be much lower than normal memory. */ AV_HWFRAME_MAP_DIRECT = 1 << 3, + /** + * For multi-planar frames, the mapping must break the frame into + * single-plane formats. For instance, an NV12 frame must be split into a + * a 8-bit format for the Y plane and an interleaved 16-bit format for the + * U/V plane with 2x2 subsampling. + */ + AV_HWFRAME_MAP_SEPARATE_PLANES = 1 << 4, + /** + * For multi-planar frames, the mapping must result in a multi-planar + * format. This is the contrary of AV_HWFRAME_MAP_SEPARATE_PLANES. + */ + AV_HWFRAME_MAP_COMBINED_PLANES = 1 << 5, }; /** diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c index 2227d6ed6981..62eb1e2908b3 100644 --- a/libavutil/hwcontext_vaapi.c +++ b/libavutil/hwcontext_vaapi.c @@ -1161,7 +1161,11 @@ static int vaapi_map_to_drm_esh(AVHWFramesContext *hwfc, AVFrame *dst, surface_id = (VASurfaceID)(uintptr_t)src->data[3]; - export_flags = VA_EXPORT_SURFACE_SEPARATE_LAYERS; + export_flags = 0; + if (flags & AV_HWFRAME_MAP_COMBINED_PLANES) + export_flags |= VA_EXPORT_SURFACE_COMPOSED_LAYERS; + else + export_flags |= VA_EXPORT_SURFACE_SEPARATE_LAYERS; if (flags & AV_HWFRAME_MAP_READ) export_flags |= VA_EXPORT_SURFACE_READ_ONLY; if (flags & AV_HWFRAME_MAP_WRITE)