From patchwork Sat Feb 11 13:17:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wm4 X-Patchwork-Id: 2506 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp107568vsb; Sat, 11 Feb 2017 05:18:04 -0800 (PST) X-Received: by 10.28.144.66 with SMTP id s63mr32057831wmd.134.1486819084563; Sat, 11 Feb 2017 05:18:04 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id z22si6069985wrc.201.2017.02.11.05.18.04; Sat, 11 Feb 2017 05:18:04 -0800 (PST) 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=@googlemail.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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C8316689DA6; Sat, 11 Feb 2017 15:17:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8CD57689DA1 for ; Sat, 11 Feb 2017 15:17:44 +0200 (EET) Received: by mail-wm0-f66.google.com with SMTP id r18so10915681wmd.3 for ; Sat, 11 Feb 2017 05:17:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yerBTJayJ31KnSSPhfELxymtP+7GGxMNslcFbJYkCzo=; b=qOFBw9I+1uGskVOEOL7w5XW+vPp8Rq1rqXn9g7T/5qrDHhLuvDngtInPF3SC0yLJqe Ntbm6GHK6gBK8JrM7Cl/UEqC14l1DWVKa5zN2uk3mQpo96cnggNMBQPuo7uMpfWiO4fb uDkOSSSyBtG+wl49/f2jc7B8wK+4mIOZenRFE7nykLKu35EhCHMXT3uuf5BSSECFGY9g NYJSuqZb6ltbfYimRXJvGHDmYLo8HTnT9ibEwY4yBUWYlZ/itYuQ/+JnP1U2vPsQjn83 k9Q6+wmUA+cqS10HfaJIR2W9EVckRWLmYxXY4L/+mQBFvwZ38M5Paei/G26Hu+eVNh8A z7qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yerBTJayJ31KnSSPhfELxymtP+7GGxMNslcFbJYkCzo=; b=Hl9tAEDm9Ouzbnb3BtD6Rm1QusHLhOiHAmcDYmE97ESo8oIjRuLt3qstT3mvupUPq/ m2GyZlUzooq7wA5WC3E4YXQW9geeomHf8lZz2BYtPlDJkJDruoV+iGv0K+NHox7snAnH Y3HMfBMeB5hFzVHsDwMK219R7XmaNvekPPNwUP7V72O0yvwBadEUFdc8sETUd/1r0GdT kxArqVNx+POqmXvcHJMo0IZScEF5hzSiYwCJj5r3nc6YawI/swZ9qHg1u3AMAvKROCcv pYFvPjbtN7g4ZJSXs/RN980Pdn7PCVhYkETmEAXQAC0E/d70wGQgnDFgZrobflPNFqOY GYOw== X-Gm-Message-State: AMke39mEP8oo0OzadCCBBmPX0nFgz9uxFjfwHlQ3mh8PYLApfjHIuMdAP5G+c9MDOUzhrQ== X-Received: by 10.28.216.14 with SMTP id p14mr29144719wmg.56.1486819068509; Sat, 11 Feb 2017 05:17:48 -0800 (PST) Received: from localhost.localdomain ([79.240.12.67]) by smtp.googlemail.com with ESMTPSA id o143sm5207404wmd.3.2017.02.11.05.17.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 11 Feb 2017 05:17:47 -0800 (PST) From: wm4 To: ffmpeg-devel@ffmpeg.org Date: Sat, 11 Feb 2017 14:17:36 +0100 Message-Id: <20170211131737.18139-2-nfxjfg@googlemail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170211131737.18139-1-nfxjfg@googlemail.com> References: <20170211131737.18139-1-nfxjfg@googlemail.com> Subject: [FFmpeg-devel] [PATCH 1/2] AVFrame: add an opaque_ref field 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: wm4 , Anton Khirnov MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This is an extended version of the AVFrame.opaque field, which can be used to attach arbitrary user information to an AVFrame. The usefulness of the opaque field is rather limited, because it can store only up to 32 bits of information (or 64 bit on 64 bit systems). It's not possible to set this field to a memory allocation, because there is no way to deallocate it correctly. The opaque_ref field circumvents this by letting the user set an AVBuffer, which makes the user data refcounted. Signed-off-by: Anton Khirnov Merges Libav commit 04f3bd349651. --- doc/APIchanges | 3 +++ libavutil/frame.c | 9 +++++++++ libavutil/frame.h | 11 +++++++++++ libavutil/version.h | 2 +- 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/doc/APIchanges b/doc/APIchanges index 8bca71ef36..81e49c22b9 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,9 @@ libavutil: 2015-08-28 API changes, most recent first: +2017-02-11 - xxxxxxx - lavu 55.47.100 - frame.h + Add AVFrame.opaque_ref. + 2017-01-31 - xxxxxxx - lavu 55.46.100 / 55.20.0 - cpu.h Add AV_CPU_FLAG_SSSE3SLOW. diff --git a/libavutil/frame.c b/libavutil/frame.c index a08e0c539d..2913982e91 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -379,6 +379,13 @@ FF_DISABLE_DEPRECATION_WARNINGS FF_ENABLE_DEPRECATION_WARNINGS #endif + av_buffer_unref(&dst->opaque_ref); + if (src->opaque_ref) { + dst->opaque_ref = av_buffer_ref(src->opaque_ref); + if (!dst->opaque_ref) + return AVERROR(ENOMEM); + } + return 0; } @@ -513,6 +520,8 @@ void av_frame_unref(AVFrame *frame) av_buffer_unref(&frame->hw_frames_ctx); + av_buffer_unref(&frame->opaque_ref); + get_frame_defaults(frame); } diff --git a/libavutil/frame.h b/libavutil/frame.h index b4500923af..3023559beb 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -538,6 +538,17 @@ typedef struct AVFrame { * AVHWFramesContext describing the frame. */ AVBufferRef *hw_frames_ctx; + + /** + * AVBufferRef for free use by the API user. Libav will never check the + * contents of the buffer ref. Libav calls av_buffer_unref() on it when + * the frame is unreferenced. av_frame_copy_props() calls create a new + * reference with av_buffer_ref() for the target frame's opaque_ref field. + * + * This is unrelated to the opaque field, although it serves a similar + * purpose. + */ + AVBufferRef *opaque_ref; } AVFrame; /** diff --git a/libavutil/version.h b/libavutil/version.h index 8866064aac..a8b00bfc64 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 55 -#define LIBAVUTIL_VERSION_MINOR 46 +#define LIBAVUTIL_VERSION_MINOR 47 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \