From patchwork Tue May 9 13:19:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 3628 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.3.129 with SMTP id 123csp1331694vsd; Tue, 9 May 2017 06:20:29 -0700 (PDT) X-Received: by 10.223.176.194 with SMTP id j2mr42267539wra.81.1494336029459; Tue, 09 May 2017 06:20:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1494336029; cv=none; d=google.com; s=arc-20160816; b=uDJE/s8stLV/JAxcI63HLGHaMxodc3H7vi2eQYyIDajTDc3V8SQMHDVW0a5aYbZSyZ XvdcdOxQ5xhUdZAxDd/rpGT8mqgps5rl7WlaKvdslwe2d0Go6s0QYPblZykSjJVziDEn HsXpbL5XTBoVXRI78cvbGIfeu5BFJfGYLmErJUJEoCIeJaT4DnpxSuOjjOTujzHdg880 pP9ff2zy3qBKeQYXU/21UZnQtxzxxc+8uhPY96Ara9Vs0iUfuFWm909bf7qVIZ4/B2uo syWyV7zRm1WU4N9eEGxCZKVDcOS6t4BqqpxPYOZvigRVkk7I6m6z9DESEjM6vH/tFXei nEvA== 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:delivered-to:arc-authentication-results; bh=GGXMRwk2y3c2QJTtf3r3y6533hqzc/p9PKu0AVjWoGs=; b=LnZ90jNwLy8dgc8xwhPSDjsTlztmbz4ctNWRMm6T39cLm2yk48yWev2p/Nxf7pjtQu h4vp2/V2y1j6/gkv3uJLZwcCsGiLLb3+V1LGR8hOW8eb048/cMj2H27WDj40kVN44dtc NkMjbv7Tuw870Gc664+0rWvr6H/YSUyDe3rutSekkVf3iqLK76xdsRcABUIwou44RRWK t2Q//H7YJd7iux1h2pMBmZy/ttS6D5dpyMPcJGh6C1SXBEAP6+OYPfIHab100IOCR494 5uwI/UBBbuFPR0giefii/fI0D2Xrly7fG1OqFShq0fgMPkA+AWVQGKKsbaBJa2BDtuYA rjFA== ARC-Authentication-Results: i=1; mx.google.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 v65si921593wme.165.2017.05.09.06.20.29; Tue, 09 May 2017 06:20:29 -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; 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 A7A816883B7; Tue, 9 May 2017 16:20:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef2.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 937BD688249 for ; Tue, 9 May 2017 16:19:57 +0300 (EEST) Received: from phare.normalesup.org (archicubes.ens.fr [129.199.129.80]) by nef2.ens.fr (8.13.6/1.01.28121999) with ESMTP id v49DK3AT066834 for ; Tue, 9 May 2017 15:20:03 +0200 (CEST) Received: by phare.normalesup.org (Postfix, from userid 1001) id 98F29E00F9; Tue, 9 May 2017 15:20:03 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Tue, 9 May 2017 15:19:44 +0200 Message-Id: <20170509131944.27166-3-george@nsup.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170509131944.27166-1-george@nsup.org> References: <20170509131944.27166-1-george@nsup.org> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef2.ens.fr [129.199.96.32]); Tue, 09 May 2017 15:20:03 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 3/3] lavfi: add a framework to fix alignment problems. 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" A lot of filters require aligned frame data, but do not document it. It can result in crashes with perfectly valid uses of the API. For now, the default alignment is not set. Signed-off-by: Nicolas George --- libavfilter/avfilter.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ libavfilter/avfilter.h | 9 +++++++++ 2 files changed, 59 insertions(+) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 08b86b010d..2918687e81 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -1515,15 +1515,60 @@ static void consume_update(AVFilterLink *link, const AVFrame *frame) link->frame_count_out++; } +static int frame_realign(AVFilterLink *link, AVFrame *frame) +{ + AVFrame *tmp; + int ret; + + if (!frame || av_frame_check_align(frame, link->alignment)) + return 0; + + switch (link->type) { + case AVMEDIA_TYPE_VIDEO: + tmp = ff_get_video_buffer(link, link->w, link->h); + break; + case AVMEDIA_TYPE_AUDIO: + tmp = ff_get_audio_buffer(link, frame->nb_samples); + break; + default: + av_assert0(!"reached"); + } + if (!tmp) + return AVERROR(ENOMEM); + + if (ret < 0) + goto fail; + ret = av_frame_copy(tmp, frame); + if (ret < 0) + return ret; + ret = av_frame_copy_props(tmp, frame); + if (ret < 0) + return ret; + av_frame_unref(frame); + av_frame_move_ref(frame, tmp); + av_frame_free(&tmp); + return 0; + +fail: + av_frame_free(&tmp); + return ret; +} + int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe) { AVFrame *frame; + int ret; *rframe = NULL; if (!ff_inlink_check_available_frame(link)) return 0; frame = ff_framequeue_take(&link->fifo); consume_update(link, frame); + ret = frame_realign(link, frame); + if (ret < 0) { + av_frame_free(&frame); + return ret; + } *rframe = frame; return 1; } @@ -1544,6 +1589,11 @@ int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, if (ret < 0) return ret; consume_update(link, frame); + ret = frame_realign(link, frame); + if (ret < 0) { + av_frame_free(&frame); + return ret; + } *rframe = frame; return 1; } diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 60662c19ac..db9c02b8c0 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -569,6 +569,15 @@ struct AVFilterLink { */ AVBufferRef *hw_frames_ctx; + /** + * Minimum alignment of frame data required by the destination filter. + * All frame data pointers must have the alignment lower bits cleared, + * i.e. be a multiple of 1<