From patchwork Thu Mar 1 13:55:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rostislav Pehlivanov X-Patchwork-Id: 7775 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.181.170 with SMTP id m39csp5062143jaj; Thu, 1 Mar 2018 05:55:26 -0800 (PST) X-Google-Smtp-Source: AG47ELsVmJ7sZ1WC8ziOU4m+6Kzc1fmLo0YaJKwnusxZ8Io0pVUwfLpND0AKveYkClEfaOuIbF/C X-Received: by 10.28.12.14 with SMTP id 14mr1826477wmm.107.1519912525993; Thu, 01 Mar 2018 05:55:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519912525; cv=none; d=google.com; s=arc-20160816; b=WbBWSmZWZT93sNYoGnvQjA+RPZaXEK8O4R0ocZkbxJnBmHU/DSBQy3Bmoa3vzcZ0oY KkXXFSIR9P639dvpzsUye9b7i7QZUYyge1z9U8hQa75U/UCCN/jVgRzNfyGsW3zg19vp KUI0/zIlZVFzJqCIv5w1C5osvMIiOorioLVWGDhmZHp0S5TKCLc41oG0Mk6ZkuW8/mXZ TQjrVmxryljDu7NFM5e5E4fI2CvDZQn0awtOQZUoDQd96et4sbFQBYWqPlJdzmEl/hSW +NfiCq/58xkEIcznLKoyx3iVNTcWHGxpdraIBeyKdd6Gyb21njeAMTMvX4JR1JIwE3CZ 1BFQ== 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:cc: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=Y/ZxzbHAeE7ML+qhpFxA1NOxCKJBvIOnaLupC41WAmg=; b=RX4hC7lItzI6PbocZq5yQBDzHouHmj2K245x6ojEpPKbRZzns4/NS38ByrJ3Zs37GG x3ZFkPeiDAX4vtiszIJj2Q1C7F7fdedJ1HM/bW/9Ndod8Syxn57OKrK6DAZ5HK5SWf33 TW8v/N4fqSJn7Uyoi9T9I1MFIg6ye69SgtlBznlVTzaaQd5zmjGox1hHODa8o/mcQwS1 W7PZcwtg/bMbq54CE6h9j69vK/uFQqzWghmMglNmF45H9BTlcaPjqtB+b9Tkz2/btyHQ nPvJkqzVPg7W+YL4yMTLHDpkSaDeDTX+5m6WMNGnyHOEX9UDHVXbzG/A7p/JCzzfDoa8 cNDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=tZmpWevt; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id p17si2842669wrp.6.2018.03.01.05.55.25; Thu, 01 Mar 2018 05:55:25 -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=@gmail.com header.s=20161025 header.b=tZmpWevt; 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=QUARANTINE 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 C616068A3FE; Thu, 1 Mar 2018 15:55:18 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f194.google.com (mail-wr0-f194.google.com [209.85.128.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BEEB0689D83 for ; Thu, 1 Mar 2018 15:55:12 +0200 (EET) Received: by mail-wr0-f194.google.com with SMTP id m5so6308670wrg.1 for ; Thu, 01 Mar 2018 05:55:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MqhnJAf5hgtuj4V09VF9Ffwiji2cXgtuOTd+9Rhb1HM=; b=tZmpWevtI9YPKHqMUp45maFeM/g+B+tF4mdumUKk/50DHtSDEFYzbKynH9+7KoLmKF kUu4subUbAhHqpKlNSWD1cbPhJxLgX3tbEQUdSWNm5UKwAYSqcJjScryerPLRX8diUlY uz7NbkfJiW96IoBCcE0CxHD9a14inNhJQV80lg/G0At/xM//V+MVjNPR5rDgNT3OBPrN SZe207PeCFDyPxOYHMFWNdzFmytZV8PQOhns7BPlSMNr4kDMl/8mq4+jlY93oJQrhuj2 mbMl1Vm325js3BBblf2HcDSqIVLT7bGtUwwTzalC0NgMUgw01kEh58TIddWn3dkSuHxS Vrfg== 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=MqhnJAf5hgtuj4V09VF9Ffwiji2cXgtuOTd+9Rhb1HM=; b=IvSM9YU0Fy8BI6SUxbGpkuOqtTkkr9qycH6jgFKhL1EcLR0gMddU07/im3OktllC3/ xPNGgED/6OhLyAj7yURlRhgn7ovEyBeVVqPJSZq3jHzYFQ/V91g5YDjQHEw9wbY82F8Z jKxrTJBdrafCqQO785HwTXEi6oooKljtNN5nyMb91vGXNVbdPChHbzFwFKKa2eXQEICn qBEmMpGecHsPhLTxgh9kytXysf+uqXvVIdJJSPnGe8X5WlcxfXrz06CPFiOTSylYuhUV LPUqPfJp+oh8ZHMembZsLgRRWhaf5wuteVItc83Ywv6uY/XSCaVbrL9HnJSBEnlaoZ2H sBYg== X-Gm-Message-State: APf1xPB/0opGKifTiLIOEQxyt/3p1/Y7DMtFkTaUoXqtMgBxbXZ+0+Cn 1pPvqlEcaqoU/GrxI0WyGVVBT0qK X-Received: by 10.223.142.5 with SMTP id n5mr2015698wrb.28.1519912517473; Thu, 01 Mar 2018 05:55:17 -0800 (PST) Received: from moonbase.pars.ee ([2a00:23c4:7c88:af00:28e9:f50d:c7d9:1df0]) by smtp.gmail.com with ESMTPSA id 4sm3633812wmz.31.2018.03.01.05.55.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Mar 2018 05:55:15 -0800 (PST) From: Rostislav Pehlivanov To: ffmpeg-devel@ffmpeg.org Date: Thu, 1 Mar 2018 13:55:12 +0000 Message-Id: <20180301135512.24265-1-atomnuker@gmail.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180301134748.14346-1-atomnuker@gmail.com> References: <20180301134748.14346-1-atomnuker@gmail.com> Subject: [FFmpeg-devel] [PATCH] frame: add an av_frame_new_side_data_from_buf function 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: Rostislav Pehlivanov MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Rostislav Pehlivanov --- Sending again, forgot to amend. Updated with description of that the function will do. Originally the function made a reference from the bufferref but someone said that it shouldn't. I don't think that this is very useful so I've changed it back so that it refs the buffer (and leaves it up to API users to unref it if they no longer need it). The function will still do nothing in case it fails and returns NULL. Also, the previous version still had the old function forward declared, fixed that by removing it. libavutil/frame.c | 43 ++++++++++++++++++++++++------------------- libavutil/frame.h | 16 ++++++++++++++++ 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index 662a7e5ab5..869b7866c8 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -26,11 +26,6 @@ #include "mem.h" #include "samplefmt.h" - -static AVFrameSideData *frame_new_side_data(AVFrame *frame, - enum AVFrameSideDataType type, - AVBufferRef *buf); - #if FF_API_FRAME_GET_SET MAKE_ACCESSORS(AVFrame, frame, int64_t, best_effort_timestamp) MAKE_ACCESSORS(AVFrame, frame, int64_t, pkt_duration) @@ -356,7 +351,7 @@ FF_ENABLE_DEPRECATION_WARNINGS } memcpy(sd_dst->data, sd_src->data, sd_src->size); } else { - sd_dst = frame_new_side_data(dst, sd_src->type, av_buffer_ref(sd_src->buf)); + sd_dst = av_frame_new_side_data_from_buf(dst, sd_src->type, sd_src->buf); if (!sd_dst) { wipe_side_data(dst); return AVERROR(ENOMEM); @@ -642,29 +637,30 @@ AVBufferRef *av_frame_get_plane_buffer(AVFrame *frame, int plane) return NULL; } -static AVFrameSideData *frame_new_side_data(AVFrame *frame, - enum AVFrameSideDataType type, - AVBufferRef *buf) +AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame, + enum AVFrameSideDataType type, + AVBufferRef *buf) { - AVFrameSideData *ret, **tmp; + AVFrameSideData *ret, **tmp = NULL; + AVBufferRef *ref = av_buffer_ref(buf); - if (!buf) - return NULL; + if (!buf || !ref) + goto fail; if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1) goto fail; + ret = av_mallocz(sizeof(*ret)); + if (!ret) + goto fail; + tmp = av_realloc(frame->side_data, (frame->nb_side_data + 1) * sizeof(*frame->side_data)); if (!tmp) goto fail; frame->side_data = tmp; - ret = av_mallocz(sizeof(*ret)); - if (!ret) - goto fail; - - ret->buf = buf; + ret->buf = ref; ret->data = ret->buf->data; ret->size = buf->size; ret->type = type; @@ -673,7 +669,8 @@ static AVFrameSideData *frame_new_side_data(AVFrame *frame, return ret; fail: - av_buffer_unref(&buf); + av_buffer_unref(&ref); + av_free(tmp); return NULL; } @@ -681,8 +678,16 @@ AVFrameSideData *av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, int size) { + AVFrameSideData *ret; + AVBufferRef *buf = av_buffer_alloc(size); + if (!buf) + return NULL; - return frame_new_side_data(frame, type, av_buffer_alloc(size)); + ret = av_frame_new_side_data_from_buf(frame, type, buf); + av_buffer_unref(&buf); + if (!ret) + return NULL; + return ret; } AVFrameSideData *av_frame_get_side_data(const AVFrame *frame, diff --git a/libavutil/frame.h b/libavutil/frame.h index d54bd9a354..504ddce073 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -800,6 +800,22 @@ AVFrameSideData *av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, int size); +/** + * Add a new side data to a frame from an existing AVBufferRef + * + * A new reference of the buffer will be created and used. + * On error, nothing will be changed and the function will return NULL. + * + * @param frame a frame to which the side data should be added + * @param type type of the added side data + * @param buf the AVBufferRef to add as side data + * + * @return newly added side data on success, NULL on error + */ +AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame, + enum AVFrameSideDataType type, + AVBufferRef *buf); + /** * @return a pointer to the side data of a given type on success, NULL if there * is no side data with such type in this frame.