From patchwork Thu May 18 08:11:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 3696 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.10.2 with SMTP id 2csp553395vsk; Thu, 18 May 2017 01:11:37 -0700 (PDT) X-Received: by 10.28.164.130 with SMTP id n124mr1168915wme.107.1495095097554; Thu, 18 May 2017 01:11:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495095097; cv=none; d=google.com; s=arc-20160816; b=E6cBZXji8dAyrR+H6sZ54Gz0geOCFCG52UyY5cynyMn781FHmCyXfPo6hXjxgpu7uy jar+N4iF5I2eH9MAbqX6tTKk1W0BEXwe+e75p7xgnFlP5K2NRjojZB3U0f1liOgGTI7+ Xkf+3tlMQntfTmznVsJb4YJZ5SMY6o8rDI/txKYPZ/LUpvqlCO8jlQkCVSjuTpbMTj7j FH0njE3ShMLjeCdQ+UcCMnFIBmDCw0CNtT8m1weYcezupWY0r8L5vz0XdaX2xXMRVvr0 Sr4P1buvGWf4W6ysN5ndL46w0nbPxaDKrxPbqixv1k2aNsf0n9hIR4xQX4GJ28evsm67 SVBw== 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:message-id:date:to:from:delivered-to :arc-authentication-results; bh=II3nN3dzj1g7euA62oiYzaXPnPeGaNSPMqqyS6KWZOA=; b=uXRCFHqG4RcPCj22ch2YHzmzw874vQ+jFvgbXzrEOJaCbtBTGp0l8alEgwcLkpNaiR a2PE+EDVT+ZDwPfZJvfCQKcZHk7C7d/md2QOYxlZG4QaxHf+PWOndo5yxzyyCvA88R/Q tBZO/iTadC7utLZRKygX1cSV3wWz17rEaEVwqaYCG6Z1+Zhb7CkL+JiA+YCJSC7j0RPG Z68Ou05RgcHaMYyst2Bz/dwTsklYBnzIS1oUu5+YHN52Ty2cHwrVlww7CKvv/a74immB 7Kz5XOgPmNqqpJ6JJLKpvcszGhFr/1/BwoaTJ/IpfIGgynvy3AraMrrqb2n9PZRK+MDD bTyw== 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 f124si19910000wmg.140.2017.05.18.01.11.37; Thu, 18 May 2017 01:11:37 -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 114806897A4; Thu, 18 May 2017 11:11:25 +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 B4A1D687EC0 for ; Thu, 18 May 2017 11:11:17 +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 v4I8BGl3016220 for ; Thu, 18 May 2017 10:11:17 +0200 (CEST) Received: by phare.normalesup.org (Postfix, from userid 1001) id E9832E0087; Thu, 18 May 2017 10:11:16 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Thu, 18 May 2017 10:11:12 +0200 Message-Id: <20170518081114.21425-1-george@nsup.org> X-Mailer: git-send-email 2.11.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef2.ens.fr [129.199.96.32]); Thu, 18 May 2017 10:11:17 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 1/3] lavu/frame: add av_frame_check_align(). 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" Signed-off-by: Nicolas George --- doc/APIchanges | 3 +++ libavutil/frame.c | 17 +++++++++++++++++ libavutil/frame.h | 8 ++++++++ 3 files changed, 28 insertions(+) With the linesize check and without the 1<<. diff --git a/doc/APIchanges b/doc/APIchanges index 67a6142401..6d3b573c2d 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,9 @@ libavutil: 2015-08-28 API changes, most recent first: +2017-05-18 - xxxxxxxxxx - lavu 55.63.100 - frame.h + Add av_frame_check_align(). + 2017-05-15 - xxxxxxxxxx - lavc 57.96.100 - avcodec.h VideoToolbox hardware-accelerated decoding now supports the new hwaccel API, which can create the decoder context and allocate hardware frames automatically. diff --git a/libavutil/frame.c b/libavutil/frame.c index 24d5d5f184..aed3cd04ec 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -781,3 +781,20 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type) } return NULL; } + +int av_frame_check_align(const AVFrame *frame, unsigned align) +{ + unsigned mask = align - 1; + unsigned i; + + for (i = 0; i < AV_NUM_DATA_POINTERS; i++) + if (((intptr_t)frame->data[i] & mask) || + (frame->linesize[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 26261d7e40..1cbf7c7a5a 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -772,6 +772,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 alignment. + * @return >0 if aligned, 0 if not + */ +int av_frame_check_align(const AVFrame *frame, unsigned align); + +/** * @} */