From patchwork Sun May 7 14:41:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 3598 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.3.129 with SMTP id 123csp473981vsd; Sun, 7 May 2017 07:41:21 -0700 (PDT) X-Received: by 10.223.136.227 with SMTP id g32mr37957016wrg.58.1494168081861; Sun, 07 May 2017 07:41:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1494168081; cv=none; d=google.com; s=arc-20160816; b=fMd5G1eXIUGi4FkbjZAOCLyASCod3q3SF7itKb4FqEDP99sfRBPDE1rSBawJhtcNfh E3A4TQlCHpsiso+x2xAzT52/7oTDyZsfNf70Jj/pQ7ALSPHQEyN60CNsWLW/zPv4JlIy 3HWENTW+G5QcMu7uPk3uvV+/A0yK8+BECeyWWAprxoljXGIPHfNoHmV+Df/CmAc6ikJi OPxKfSpFCIKZcBpmoOVAHPKalP3N2TdgGgHRxpnX+lPusEoyThOm6+1uvs5nzGqmwnSB Xo3LDXdabBnvemYPUvGhWM7bu25BnLOycqYLHL3sjzSOKgs2dNejYC8ib04SjzKL5u+8 pzcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:user-agent :in-reply-to:mime-version:references:message-id:to:from:date :delivered-to:arc-authentication-results; bh=1e07k3sG4uCGwAUwlchh4CMLcaTpeEV/aMWGg4vH0Mc=; b=f9FAZCZEdTmGthtP9kjso99bpv/T7WfxcpZ82K2RO1VMyZxJdYQlh2U3nLyHLS4QQf N9O1CRYDOq7y2ZWPYiWmPP/ey2iODvAM+iBnMgsICuj4S8e92r3JgqIF3M7aSa4q1Co7 ozV87qkW+qEu7Ypwhy188iHO30rY3n6lJTnsFFA8kdToE1T8No1Mh2A0QqK+XFh7KyEW eUBm6MhLhFEABkSdIKaZs1Y78UlnyFRoaG9sBMAIroKJS2hsrJ6Lq6MbxXMNM7P/MmXb NiiF+YDGBGPlE2m6u3d3j6im7vLJ4sUvfD1j3N8U1j5dJwqzdiCNmnRfPk1lDUZJdCVK UuGQ== 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 p18si12542850wrc.79.2017.05.07.07.41.21; Sun, 07 May 2017 07:41:21 -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 3E442687ECA; Sun, 7 May 2017 17:41:13 +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 9FBFF6818DB for ; Sun, 7 May 2017 17:41:06 +0300 (EEST) Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef2.ens.fr (8.13.6/1.01.28121999) with ESMTP id v47EfBBP055004 for ; Sun, 7 May 2017 16:41:12 +0200 (CEST) Received: by phare.normalesup.org (Postfix, from userid 1001) id DD724E00D0; Sun, 7 May 2017 16:41:11 +0200 (CEST) Date: Sun, 7 May 2017 16:41:11 +0200 From: Nicolas George To: FFmpeg development discussions and patches Message-ID: <20170507144111.GA1085904@phare.normalesup.org> References: <20170506092006.22397-1-george@nsup.org> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef2.ens.fr [129.199.96.32]); Sun, 07 May 2017 16:41:12 +0200 (CEST) Subject: Re: [FFmpeg-devel] [PATCH 1/3] lavu/frame: add av_frame_realign(). 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" L'octidi 18 floréal, an CCXXV, Marton Balint a écrit : > I suggest to return 1 if an actual alignment (with deep copy) happened. Actually, as Muhammad just pointed and as I noticed a few minutes ago, we can not use the same function from lavfi and lavc, due to the get_buffer issue. I propose the attached patch to factor the alignment check (notice it is slightly more complex than in Muhammad's patch, because it takes care of all cases and not just the mp3lame crash). The realignment functions will look like: int ff_frame_realign(AVFrame *frame, unsigned align) { if (ff_frame_check_align(frame, align)) return 0; specific_get_buffer(frame); } If we were not so much in a rush, I would propose a solution to avoid the copy-paste, but it can wait for later. Regards, From 3dacd6fa2aa86b31b73edda83f995b841e1d57b5 Mon Sep 17 00:00:00 2001 From: Nicolas George Date: Sat, 6 May 2017 10:56:33 +0200 Subject: [PATCH 1/3] lavu/frame: add av_frame_check_align(). TODO APIchanges and minor bump. Signed-off-by: Nicolas George --- libavutil/frame.c | 18 ++++++++++++++++++ libavutil/frame.h | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/libavutil/frame.c b/libavutil/frame.c index dd12c5549c..cb6e334833 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -777,3 +777,21 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type) } return NULL; } + +int av_frame_check_align(AVFrame *frame, unsigned align) +{ + unsigned mask = (1 << align) - 1; + unsigned i; + int ret; + + av_assert1(align < 16); + for (i = 0; i < AV_NUM_DATA_POINTERS; i++) + if (((intptr_t)frame->data[i] & mask)) + return 0; + if (!frame->extended_data || frame->extended_data == frame->data) + return 1; + for (i = AV_NUM_DATA_POINTERS; i < frame->channels; i++) + if (((intptr_t)frame->extended_data[i] & mask)) + return 0; + return 1; +} diff --git a/libavutil/frame.h b/libavutil/frame.h index 4d8c1bed4f..f6ff807404 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -746,6 +746,14 @@ void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type); const char *av_frame_side_data_name(enum AVFrameSideDataType type); /** + * Check if the data pointers of a frame are aligned enough. + * Test if all frame data pointers have the alignment lower bits cleared, + * i.e. are a multiple of 1<0 if aligned, 0 if not + */ +int av_frame_check_align(AVFrame *frame, unsigned align); + +/** * @} */ -- 2.11.0