From patchwork Mon Jun 12 22:40:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 3953 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.22.4 with SMTP id 4csp78379vsw; Mon, 12 Jun 2017 15:44:13 -0700 (PDT) X-Received: by 10.223.163.198 with SMTP id m6mr755908wrb.58.1497307453163; Mon, 12 Jun 2017 15:44:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497307453; cv=none; d=google.com; s=arc-20160816; b=mMXiGYYOTlXCoL00oQUXrQ97UGNiH+bz+tp6efNW2hybl2T/ToyWahkLVHSrQnire4 uTDajMMgzWVRYuK+/2k8OF68Yw5OpCua3Zpj7mPRdcjYKp4Ga7T2Ud0+M6HKPAmcA89I +O7WCcneRRep5liPdgG0PDFzRRZf2N/lJ/+luBy2/QrbIu8621usJv5tDivVdrqYGV+/ O7G+nKxGtGKMABveQ6WL7o8teZPVr6Qt2iaetSpU4Jk/xmEqlSi8cfalNKMsFj+2NlW/ E5/W5aQfe81bUJ3AiCYk9S1nRXL/TOYzgauKu+L8fkyOVnbGMOEr8AH54VlZNWmNURbe y+jg== 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=A04iCV0YAm0mSaZsMmQXMC/DIwufiJ5MiYfQHeiyfz4=; b=MtsOHqKUJIjZtMSfNnVaqrlzygyqy3PNq8ezaOFXHmTeheCRaXDigAke69/PHe7oiC /O8b2HwSZrRgYMQUmhmDanKJw18DXyiZYBt9ofuY+akxTRcYpA2VEFbYD+GUnGCYXBev 8nHPDXNnVIyVf3eYvY2L7AojSNKp+KshuKHq0+2JJt+MIl5m8VcBOIeFgzCbexsMq/G5 9qUaDYQOn0JjMdXw63EzXoZbqj9dGxmsCaThMks0YxJxfTgeL77IEPYnlkjBtzEGpD4p dt/yahEfTLIuu65aFhLf7OLy6lkyW+eZxl4hmhorNRIp0m0NemekPuEiKOtHcJgmq9Il 8zkQ== 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 d24si10407581wrc.116.2017.06.12.15.44.12; Mon, 12 Jun 2017 15:44:13 -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 0932368A0C3; Tue, 13 Jun 2017 01:41:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f170.google.com (mail-wr0-f170.google.com [209.85.128.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 948E268A08E for ; Tue, 13 Jun 2017 01:41:15 +0300 (EEST) Received: by mail-wr0-f170.google.com with SMTP id v104so113618151wrb.0 for ; Mon, 12 Jun 2017 15:41:17 -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=mRv48nWjQanyxIP3aQ8OuUDgSca4xtH7p86BTpHAIZo=; b=be+pDGdzwBRng8SJ1EJoe3PyctRllWPNmy+C4lgYw4avwblRsDDjM80KoNLlsZ9oYR 6B7QNk9yj/i9eFJVBMPQwQxCJ4baJh1TlYx5s25ek6hNMNpS1kD8G3IKdl6kB7EGjcRJ FA2EDzOm+jfITi8hGTKRG4/VowWB6Urq+iF160ucrEzsupcjk/W6hu4n7x7sgSSLkjoI Nh+cQeBqL+uNgRsg6HqX/qmZLdIPVA9cc27U76P3Owv5hNoIq/mLyvTJW0y0D546Ghmy 2Z1flWhyCl8n7S+ZYZVI17g3gWt2itLWSg1plKJbwdlfFW423bK14Qu2V4dawznjlr+e bxDg== 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=mRv48nWjQanyxIP3aQ8OuUDgSca4xtH7p86BTpHAIZo=; b=gW595XoBZOrpM889uar3VOCDICFccpdyjJ3itZBA1NixWJZtdz4d5DVfV8Z50KCsX6 Nb/KR2IrN42SMfuNtbiduuHjsr7/ahKEgWhQ7Kl0Wzsf7NRmgMsb5lqezB9HlsuQ4ybD rvJWUcHnkRFno0Qp/1Il/ZNYsYKDUSAHKRonXttdXzonhIR8FgBxBMufZVB7nL1PLD/V uBJkm7MFiVOQISXgJF51PfAZ/w067j8nJ9hwqXTBNkNBGAL0Ta0VwGV5A9dC+rLf5Sk5 eFkvdP7hrZGjPKgCyEgaS7mI0+9IpIgjgIbhGcqQR/qwp26o9O2W0UyO5HU8PSFufCaB v17A== X-Gm-Message-State: AKS2vOw43598TAw/ELIEZBjN1CIyCNxF18ekmsPsAfRr+zP4eBwSbWg2 coTDVIT0G/MRqos165E= X-Received: by 10.223.179.86 with SMTP id k22mr706387wrd.5.1497307276968; Mon, 12 Jun 2017 15:41:16 -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.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Jun 2017 15:41:16 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 12 Jun 2017 23:40:38 +0100 Message-Id: <20170612224041.6750-22-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 21/24] hwcontext: Improve allocation in derived contexts 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" Use the flags argument of av_hwframe_ctx_create_derived() to pass the mapping flags which will be used on allocation. Also, set the format and hardware context on the allocated frame automatically - the user should not be required to do this themselves. (cherry picked from commit c5714b51aad41fef56dddac1d542e7fc6b984627) --- doc/APIchanges | 4 ++++ libavutil/hwcontext.c | 14 +++++++++++++- libavutil/hwcontext.h | 4 +++- libavutil/hwcontext_internal.h | 5 +++++ libavutil/version.h | 2 +- 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 12c4877b9b..19776f830e 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,10 @@ libavutil: 2015-08-28 API changes, most recent first: +2017-06-xx - xxxxxxx - lavu 55.66.100 - hwcontext.h + av_hwframe_ctx_create_derived() now takes some AV_HWFRAME_MAP_* combination + as its flags argument (which was previously unused). + 2017-06-xx - xxxxxxx - lavc 57.99.100 - avcodec.h Add AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH. diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c index ba7ffd1951..4726986902 100644 --- a/libavutil/hwcontext.c +++ b/libavutil/hwcontext.c @@ -458,6 +458,11 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags) // and map the frame immediately. AVFrame *src_frame; + frame->format = ctx->format; + frame->hw_frames_ctx = av_buffer_ref(hwframe_ref); + if (!frame->hw_frames_ctx) + return AVERROR(ENOMEM); + src_frame = av_frame_alloc(); if (!src_frame) return AVERROR(ENOMEM); @@ -467,7 +472,8 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags) if (ret < 0) return ret; - ret = av_hwframe_map(frame, src_frame, 0); + ret = av_hwframe_map(frame, src_frame, + ctx->internal->source_allocation_map_flags); if (ret) { av_log(ctx, AV_LOG_ERROR, "Failed to map frame into derived " "frame context: %d.\n", ret); @@ -819,6 +825,12 @@ int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx, goto fail; } + dst->internal->source_allocation_map_flags = + flags & (AV_HWFRAME_MAP_READ | + AV_HWFRAME_MAP_WRITE | + AV_HWFRAME_MAP_OVERWRITE | + AV_HWFRAME_MAP_DIRECT); + ret = AVERROR(ENOSYS); if (src->internal->hw_type->frames_derive_from) ret = src->internal->hw_type->frames_derive_from(dst, src, flags); diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h index 37e8831f6b..edf12cc631 100644 --- a/libavutil/hwcontext.h +++ b/libavutil/hwcontext.h @@ -566,7 +566,9 @@ int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags); * AVHWFramesContext on. * @param source_frame_ctx A reference to an existing AVHWFramesContext * which will be mapped to the derived context. - * @param flags Currently unused; should be set to zero. + * @param flags Some combination of AV_HWFRAME_MAP_* flags, defining the + * mapping parameters to apply to frames which are allocated + * in the derived device. * @return Zero on success, negative AVERROR code on failure. */ int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx, diff --git a/libavutil/hwcontext_internal.h b/libavutil/hwcontext_internal.h index 0a0c4e86ce..68f78c0a1f 100644 --- a/libavutil/hwcontext_internal.h +++ b/libavutil/hwcontext_internal.h @@ -121,6 +121,11 @@ struct AVHWFramesInternal { * context it was derived from. */ AVBufferRef *source_frames; + /** + * Flags to apply to the mapping from the source to the derived + * frame context when trying to allocate in the derived context. + */ + int source_allocation_map_flags; }; typedef struct HWMapDescriptor { diff --git a/libavutil/version.h b/libavutil/version.h index 322b683cf4..308d16f95b 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -80,7 +80,7 @@ #define LIBAVUTIL_VERSION_MAJOR 55 -#define LIBAVUTIL_VERSION_MINOR 65 +#define LIBAVUTIL_VERSION_MINOR 66 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \