From patchwork Mon Jun 12 22:40:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 3936 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.22.4 with SMTP id 4csp77738vsw; Mon, 12 Jun 2017 15:41:41 -0700 (PDT) X-Received: by 10.28.232.133 with SMTP id f5mr9034208wmi.113.1497307301551; Mon, 12 Jun 2017 15:41:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497307301; cv=none; d=google.com; s=arc-20160816; b=g8u6GFm4g4s0/r37wmGJttwANq9/VKUCAZ2lb/FgFqr0nkhd+4ukN2h+HVfOgvnLIu cPygvRSa6TkV+l9iWTCo+gGEIp6z7fSEwhJUzK5z1EUrHsPBYlXq4WzqhpQmjn7TFiP0 jKMdNccucuXKJ+0FMLkN5+3tBJtE4pmYTwj8TNlZLZJwv7qbcZGlgrBEtLSDgqGsW5ui V2y9VvjR6pYRORJ1rpXzudpgVkPh+NdkMbQxwt5cF1++mDrovh6A4Q+iTALwtQgu3j0e fDUo4I6lhprtNpZGaLsQs0sWbmgu2+uhu8eiyQ1hhar1ZW0HO6EaQUI5AiXn9GyxhCkI JohA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=1PebVT1HbJS/XPd49EIO8D564N61smoMz1cjdl/sUfU=; b=AudXA0ICAW3OEFE6SRD75BMxi1WRkAifHZz+csbx3b/+cf3nJlMiNxyrPgsjme5+Gj zZF6Ob4Ax8+PksY5/QyDB/4KAKk8aE9lv45eeGZil18rYO/Mtnzbve8FHyqVHsaCOKBs YY98fuCMzyPA+gv7Wi1NABvGSZbBCJv1XcAvExfy9fmuI54HZreHxC+2gxmIl+FZ2yYb wn7VAK6Cj6jqI9GWpxMB7PXI5LZG8cmH3MHd066z6GfYQECVrjPBQ/RervtmgjoEpKd5 M7u8y+e0Xrid1iuCyxJAwVrkSTIl5L7697FNMVTRlKKm8ZBZQdjIVTWoMk0EL9CkLoHd b0/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20150623.gappssmtp.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y39si10432629wrd.81.2017.06.12.15.41.41; Mon, 12 Jun 2017 15:41:41 -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=@jkqxz-net.20150623.gappssmtp.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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 36612689FFF; Tue, 13 Jun 2017 01:41:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f174.google.com (mail-wr0-f174.google.com [209.85.128.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D64DD68091A for ; Tue, 13 Jun 2017 01:40:59 +0300 (EEST) Received: by mail-wr0-f174.google.com with SMTP id g76so113425591wrd.1 for ; Mon, 12 Jun 2017 15:41:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=AMxrJtexwjfY9XOfzpc+DpW9mAID8J8qtqxO0Pbs6Bs=; b=ZI7rUeqK6crh2yds8lyw5x6jTe3De6ruV+avec2TMrODeh5CTsULEyFKm1f5b6zPUQ /Fnmrgvyi8996oa3Or0wynG6x5OGqWZMVouvSaBFxboMrL7Fz5iFMgDH20scisxzOCef 47z2jvvKlthdR7Y1lPhNn9pgZk1faJ4aCWZFoWonMtrdamkOVOcYLll1C4sKRgc5OiEv yhFuTQGc6mf6meVkwJP6KHfrtPVwlII0mf6sAc7K3iXW25aP3q4Kf+/NexhRFIevYnfl KUKQHG6Qz69yU1aY1XY5y2nBbMC5npACODpLJRgWeURsMPzAbz+7Wmb5cWLXAOtJV23/ v8sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=AMxrJtexwjfY9XOfzpc+DpW9mAID8J8qtqxO0Pbs6Bs=; b=Y1VHFoPMSvXj6N1XJQnGmn6gjegQKPoDBwlczH1N+SyFrzcvM4Xn4va5gTxCOYSAuf Q03oaXdmw9V9FGbCfATuyfpseTMKVki67u5kdm6a3q1smBtJQnLXNX3QiS0ZKIMV/l9T sTeQ1NU4t0+yeBSZ067dIvuITWqHh1mlMswG4yaUOhVC+voxjwxs2hC5/krYSacmAOXn OmPYQ4N9/ubLJWe83GVjur3C5TJr8l0V3RmQi1WYsHsFExi9DNpChMpyMfEmbbijgrhW mfZ/3g1UZ98aS7dEdCgQK5THQyYXWAdUJ/CsH3B9Dx1UKLy96qKOVYcEBnXjgP1Z9eso Lg+A== X-Gm-Message-State: AKS2vOyvzCitdffeDRtADdzgR6lTK4mz3KD1x7Qy6AXUrK7pRBZrrrxM jqETZAnHF2eSdvRo7M0= X-Received: by 10.223.178.143 with SMTP id g15mr491893wrd.144.1497307261374; Mon, 12 Jun 2017 15:41:01 -0700 (PDT) Received: from rywe.jkqxz.net (cpc91242-cmbg18-2-0-cust650.5-4.cable.virginm.net. [82.8.130.139]) by smtp.gmail.com with ESMTPSA id m191sm13098233wmg.30.2017.06.12.15.41.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Jun 2017 15:41:00 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 12 Jun 2017 23:40:20 +0100 Message-Id: <20170612224041.6750-4-sw@jkqxz.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170612224041.6750-1-sw@jkqxz.net> References: <20170612224041.6750-1-sw@jkqxz.net> Subject: [FFmpeg-devel] [PATCH 03/24] hwcontext: Add device derivation 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Creates a new device context from another of a different type which refers to the same underlying hardware. (cherry picked from commit b266ad56fe0e4ce5bb70118ba2e2b1dabfaf76ce) --- doc/APIchanges | 3 ++ libavutil/hwcontext.c | 65 ++++++++++++++++++++++++++++++++++++++++++ libavutil/hwcontext.h | 26 +++++++++++++++++ libavutil/hwcontext_internal.h | 8 ++++++ libavutil/version.h | 2 +- 5 files changed, 103 insertions(+), 1 deletion(-) diff --git a/doc/APIchanges b/doc/APIchanges index 67a6142401..a6889f3930 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,9 @@ libavutil: 2015-08-28 API changes, most recent first: +2017-06-xx - xxxxxxx - lavu 55.64.100 - hwcontext.h + Add av_hwdevice_ctx_create_derived(). + 2017-05-15 - xxxxxxxxxx - lavc 57.96.100 - avcodec.h VideoToolbox hardware-accelerated decoding now supports the new hwaccel API, which can create the decoder context and allocate hardware frames automatically. diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c index 8d50a32b84..86d290d322 100644 --- a/libavutil/hwcontext.c +++ b/libavutil/hwcontext.c @@ -68,6 +68,8 @@ static void hwdevice_ctx_free(void *opaque, uint8_t *data) if (ctx->free) ctx->free(ctx); + av_buffer_unref(&ctx->internal->source_device); + av_freep(&ctx->hwctx); av_freep(&ctx->internal->priv); av_freep(&ctx->internal); @@ -538,6 +540,69 @@ fail: return ret; } +int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ref_ptr, + enum AVHWDeviceType type, + AVBufferRef *src_ref, int flags) +{ + AVBufferRef *dst_ref = NULL, *tmp_ref; + AVHWDeviceContext *dst_ctx, *tmp_ctx; + int ret = 0; + + tmp_ref = src_ref; + while (tmp_ref) { + tmp_ctx = (AVHWDeviceContext*)tmp_ref->data; + if (tmp_ctx->type == type) { + dst_ref = av_buffer_ref(tmp_ref); + if (!dst_ref) { + ret = AVERROR(ENOMEM); + goto fail; + } + goto done; + } + tmp_ref = tmp_ctx->internal->source_device; + } + + dst_ref = av_hwdevice_ctx_alloc(type); + if (!dst_ref) { + ret = AVERROR(ENOMEM); + goto fail; + } + dst_ctx = (AVHWDeviceContext*)dst_ref->data; + + tmp_ref = src_ref; + while (tmp_ref) { + tmp_ctx = (AVHWDeviceContext*)tmp_ref->data; + if (dst_ctx->internal->hw_type->device_derive) { + ret = dst_ctx->internal->hw_type->device_derive(dst_ctx, + tmp_ctx, + flags); + if (ret == 0) { + dst_ctx->internal->source_device = av_buffer_ref(src_ref); + if (!dst_ctx->internal->source_device) { + ret = AVERROR(ENOMEM); + goto fail; + } + goto done; + } + if (ret != AVERROR(ENOSYS)) + goto fail; + } + tmp_ref = tmp_ctx->internal->source_device; + } + + ret = AVERROR(ENOSYS); + goto fail; + +done: + *dst_ref_ptr = dst_ref; + return 0; + +fail: + av_buffer_unref(&dst_ref); + *dst_ref_ptr = NULL; + return ret; +} + static void ff_hwframe_unmap(void *opaque, uint8_t *data) { HWMapDescriptor *hwmap = (HWMapDescriptor*)data; diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h index cfc6ad0e28..782dbf22e1 100644 --- a/libavutil/hwcontext.h +++ b/libavutil/hwcontext.h @@ -271,6 +271,32 @@ int av_hwdevice_ctx_create(AVBufferRef **device_ctx, enum AVHWDeviceType type, const char *device, AVDictionary *opts, int flags); /** + * Create a new device of the specified type from an existing device. + * + * If the source device is a device of the target type or was originally + * derived from such a device (possibly through one or more intermediate + * devices of other types), then this will return a reference to the + * existing device of the same type as is requested. + * + * Otherwise, it will attempt to derive a new device from the given source + * device. If direct derivation to the new type is not implemented, it will + * attempt the same derivation from each ancestor of the source device in + * turn looking for an implemented derivation method. + * + * @param dst_ctx On success, a reference to the newly-created + * AVHWDeviceContext. + * @param type The type of the new device to create. + * @param src_ctx A reference to an existing AVHWDeviceContext which will be + * used to create the new device. + * @param flags Currently unused; should be set to zero. + * @return Zero on success, a negative AVERROR code on failure. + */ +int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ctx, + enum AVHWDeviceType type, + AVBufferRef *src_ctx, int flags); + + +/** * Allocate an AVHWFramesContext tied to a given device context. * * @param device_ctx a reference to a AVHWDeviceContext. This function will make diff --git a/libavutil/hwcontext_internal.h b/libavutil/hwcontext_internal.h index cf05323e15..6451c0e2c5 100644 --- a/libavutil/hwcontext_internal.h +++ b/libavutil/hwcontext_internal.h @@ -66,6 +66,8 @@ typedef struct HWContextType { int (*device_create)(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags); + int (*device_derive)(AVHWDeviceContext *dst_ctx, + AVHWDeviceContext *src_ctx, int flags); int (*device_init)(AVHWDeviceContext *ctx); void (*device_uninit)(AVHWDeviceContext *ctx); @@ -95,6 +97,12 @@ typedef struct HWContextType { struct AVHWDeviceInternal { const HWContextType *hw_type; void *priv; + + /** + * For a derived device, a reference to the original device + * context it was derived from. + */ + AVBufferRef *source_device; }; struct AVHWFramesInternal { diff --git a/libavutil/version.h b/libavutil/version.h index fb61dcc666..dd8d2407da 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -80,7 +80,7 @@ #define LIBAVUTIL_VERSION_MAJOR 55 -#define LIBAVUTIL_VERSION_MINOR 63 +#define LIBAVUTIL_VERSION_MINOR 64 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \