From patchwork Thu Mar 1 13:47:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rostislav Pehlivanov X-Patchwork-Id: 7774 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.181.170 with SMTP id m39csp5054850jaj; Thu, 1 Mar 2018 05:48:00 -0800 (PST) X-Google-Smtp-Source: AG47ELtQ/BPQBupXiBDwGS8eZs8iSDHX+bVE47pQavG8z45HIt9yVMOna3/i5m1MsF0h5DwWIjs2 X-Received: by 10.28.52.9 with SMTP id b9mr1988665wma.134.1519912080240; Thu, 01 Mar 2018 05:48:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519912080; cv=none; d=google.com; s=arc-20160816; b=WDEs1uunOt9YFndUwJ8itIntp0LrW04bH1l/qMaGuE2brAlIgXvK2jJN6HWpk2OUQi jPLCuIt72UHrJxK6rPmq83daC6t0OPXB99NyWPWKcCPxUd2dzo6QXFiTsNk1oPhvvrVU eBqYd4KphWOz8lvDxVKBGhc2p1JTijX8d/Hu8ZFoUtXrxjkid3spkcPbu3b8lQ7C0ygf yNhwx78b65AKIvs6qX1BU9wYNCeshpEJnzdxXNec9+MS/TEmHySxkyvvlaSInbrdKaIh kC/5cuc/C7m/TAgNL5m/8DcPs/VU1V4nK5QmYppxoSgUp7aXIxIGWflP4SuuxoI3yP25 VGOA== 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=CNZ1ciA2tkwqqqh5inSbRn0epq0wQMGyRG542NMYO+0=; b=zWpyj9tcvizodZC5xmDO4NHiN4sny/H8BjQrmFHR43AAkk9unLV3JKwylLROqsk585 KdkB3s5hJD8BRzWy/tsVbOnOTxbvHrd9mkKWqZJLRmDl11RLs2xcTpPvMe/uqbQj3ZYI NO07GsP5qF/s1rzWTGGNJtsWkmb4vWnaC2aKIqwvdvIegQhejX/9Dcg6cuYFj26aJaLy uzVSu8y002IOGIocAF0ilX26MmcL+4LtTuupDMK+3uYw4PK0l0rQ0vAqNhj7nHDM0Dz+ Xw9Z34dBfWkTjDlnm4MjMlETVNd5Rh1YvZ8ymDjKJs5GvIeq0Uac3M0lQmRhP8eogtxH vLZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=W62lIAGM; 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 p91si3048673wrb.163.2018.03.01.05.47.59; Thu, 01 Mar 2018 05:48:00 -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=W62lIAGM; 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 6ABD968A3FE; Thu, 1 Mar 2018 15:47:52 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1D70A689C5E for ; Thu, 1 Mar 2018 15:47:46 +0200 (EET) Received: by mail-wr0-f195.google.com with SMTP id u49so6227375wrc.10 for ; Thu, 01 Mar 2018 05:47:51 -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=tSEr7F0NaBJmq7Bfwz9K2+ziegKTrsZ4RChtwtLnGsQ=; b=W62lIAGMDRmE62kYV6dTaMriMfW2jTISz8mLMJPDQ1w3DERR8QpxRYFhWNqlrHY/xo o7W6EVyjeHBWG8+jC5/Oz5GdPX5muaLAIo8SGPFR1vOXitd+0ExBmhjvnckSqNyqxhMp 73ZGS937ANUaTidVrBMeQixw8enTekhEG9cI7dfJcMSetFsGs25QQ8cNhEq7V9GUJoHi 0SOwB01Pvh1hGNrmoyP4UNDswgmRZverMoxHxXlTPHWl3Tkn8JeM5wECbnd4AdiCDCLA Umi6g6Vd4MdQ3fKCRdnC/IguyPPWKC+khcwIqTC3ByWCE0XZfRLJM3APe70+dutR654l cjyQ== 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=tSEr7F0NaBJmq7Bfwz9K2+ziegKTrsZ4RChtwtLnGsQ=; b=eZxNtuXwr2jEn65brhZpUNn5YKyRDrF37FSIwTP1syMfuBYg2M8zY4uv6iPW46Yiga ZkM4GXYlRjPozA3cpX1UR4eCWweC5SuzQA55x/3RgPnt4L5zv5ZijGAlNlItkwMypM+6 qWaspQOfOb1M4CDdjUQwgeQc5uYhqBveXDSbmNZPrG3xvweb0c9GkOzIshULUqwX9eIa Kunu4QotWbaFu/cMKVZWQigyEyGJ4O7goYXziIZ7/LwCX7vGbGbFm36cSsnzCVoyVsn8 bvxDq7PNSWwn/NBy5RRxPM0+TcYOhGXuKnJc5prdtzkqYo2I+Mf9vGzP3KYrKigNWOU6 4Xsw== X-Gm-Message-State: APf1xPC41cUW1cegGVJIVJ9JS82lB7Ak97l/ycMwvbvUQz6o5MFJynEG 7BY4OtaYV8HhKPc8cSsaO0bDeai+ X-Received: by 10.223.163.222 with SMTP id m30mr1976586wrb.30.1519912070790; Thu, 01 Mar 2018 05:47:50 -0800 (PST) Received: from moonbase.pars.ee ([2a00:23c4:7c88:af00:6dc9:fcdb:ae53:674a]) by smtp.gmail.com with ESMTPSA id 78sm5760638wmm.22.2018.03.01.05.47.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Mar 2018 05:47:49 -0800 (PST) From: Rostislav Pehlivanov To: ffmpeg-devel@ffmpeg.org Date: Thu, 1 Mar 2018 13:47:48 +0000 Message-Id: <20180301134748.14346-1-atomnuker@gmail.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180301134615.12adccb6@debian> References: <20180301134615.12adccb6@debian> 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 --- 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 | 42 +++++++++++++++++++++++------------------- libavutil/frame.h | 16 ++++++++++++++++ 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index 662a7e5ab5..12a26fb150 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,15 @@ AVFrameSideData *av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, int size) { + AVBufferRef *buf = av_buffer_alloc(size); + if (!buf) + return NULL; - return frame_new_side_data(frame, type, av_buffer_alloc(size)); + AVFrameSideData *ret = av_frame_new_side_data_from_buf(frame, type, buf); + av_buffer_unref(&buf); + if (!ref) + 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.