From patchwork Sat Jul 8 14:12:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 4268 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.1.76 with SMTP id 73csp1426420vsb; Sat, 8 Jul 2017 07:19:20 -0700 (PDT) X-Received: by 10.28.214.133 with SMTP id n127mr2417302wmg.16.1499523560405; Sat, 08 Jul 2017 07:19:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499523560; cv=none; d=google.com; s=arc-20160816; b=MHrQsEEJ4wKMKeWTznEafhvc9vttQ2dgv1Jkjd8Mqf8GVAq6r556L4mVDmrwZW9Nr1 R6Ym1Nhq7YjvdJC7ivBrW/UXF16wjtDZx9+fCxnp67PhCuPSaI7NuJD4FW8v2z9TgH89 A0mdrf09aX0eWlX65k0fMmTOZy+4M60zGvH4HDfA1tkG93TWlqkDWf28uB7flf3xWSYm s5hklJTEg4sXplLPMMCFvXWsj0rISkAV9PKxN+nhsA6HbMVuNDzoH0bZaKOocaHSxOWT kksajD+gm51+AspROlZswBbMVNNJokEAVZ5+MllKllW/QEQwiOAr2Ygl04yKCS+g3qWK xe0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:dkim-signature:delivered-to :arc-authentication-results; bh=0P1e9/ogCcLDDnH8FsjjE4i7HSMrpaKxu7QDPLMtNgE=; b=nSz+zskpnIiKCZlzpsTA7wpb0uU2KWJZ5s+yOU5DrusLxPU5Iygj2RGSGkzw+UDhhQ g3Pd6xGFI3uMZplPfLsJylcQEnY+A3clp7UdS5H2iFIYiIWXKaRM7jgAAwUzAQFmLgsb 74SpaSeFEuunXoqTMkme4tUqKcrJfJUjWBahn0mC8N0Thh0a6gJwOu9ScQWPzvjEKTQO XZYX4wxlgNA4s+i8V/TzpHAc2vZLfXaDZyM3eoKWsLAm+FKF6ZX6rr/4tPcnPYrkGaAw 12JX1pmH/3pu2XuZseKhMBN7aAkk1nfnQdVy3YueYUpO9oiFKzy07cSPed1opDtvDc4/ 6KCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20150623.gappssmtp.com header.b=XST/o4v2; 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 61si4176603wrs.352.2017.07.08.07.19.20; Sat, 08 Jul 2017 07:19:20 -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; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20150623.gappssmtp.com header.b=XST/o4v2; 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 4892C689BCA; Sat, 8 Jul 2017 17:19:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f177.google.com (mail-wr0-f177.google.com [209.85.128.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 02F026899F8 for ; Sat, 8 Jul 2017 17:19:07 +0300 (EEST) Received: by mail-wr0-f177.google.com with SMTP id c11so82190126wrc.3 for ; Sat, 08 Jul 2017 07:19:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=0HfpNw/V5tTvVIg8TCtrsu8DZQCbfB6x2E/aidsAT4I=; b=XST/o4v2gJVMTtuUl86KhM6cVTkCS+izpQGxr0pA9Q9UtUiC0b5PYo9VUIj2XXSfGY xZlgcZNCi2N9Sxz4N2opN1NLAmaDfWfHgEh1/sY15gRCzK7xpbk5F4ipTFIFoPX2o9aN 7YHBhp7kOfL1LD1ItWE33OIZfj9uTW3DZYTXqiuMB0OWX2bS2h+d1YIwKc/60RBsmo9c gKhnTztnZaNHj2EJ2FN0yXAx8UHlbmTuu+D5bJIa4FD2C29/+cc7QvZ7rPj5KmeVZ4HR G7sMopOfckKwgHETlk8IDLM7B00r+4wQ0IlIYPLHUn+UIGCIO30+9zqZAjtbgdxK5liS E34w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=0HfpNw/V5tTvVIg8TCtrsu8DZQCbfB6x2E/aidsAT4I=; b=FAdgLOJWxc0lMBeXCNBppv9BF4ZOLUzCfd8NZwSU+A+LKE77E8cTF67csJe14A5tRQ FDqHTqkTUpfV7sFl+LwS9aNHafv4rDi9S+7/hN++MqlVLjc4yHScTXrShp+mxo2k5Tk3 9pKAY6dOB5E3aE0MQEvR2IUT+fJGHWr82+c4YxjfuKxQNnhMjRd4Hj3doAd1RujadHwA xMf8kGzxUVIH4wCU/dni8reL8q2ikKV5WMMEVFljgQgXydzyXjnJMdMSUSth/DI2Wsuc 2gadt4K3sV9vXMeX2sqZaWx++gw3nCwf2CdZ3jLWFDB9zo6KmMYRNnZGctCw8iUwMsWP iStA== X-Gm-Message-State: AIVw1129ABJtvbX7ttbirCoZEELnJ73PnuvryuHM+JQkG7gAHynTWH1G /PZjCLLcix3p3TjUq08= X-Received: by 10.28.137.199 with SMTP id l190mr2401476wmd.117.1499523168520; Sat, 08 Jul 2017 07:12:48 -0700 (PDT) Received: from [192.168.0.8] (cpc91242-cmbg18-2-0-cust650.5-4.cable.virginm.net. [82.8.130.139]) by smtp.gmail.com with ESMTPSA id c131sm266900wmh.2.2017.07.08.07.12.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Jul 2017 07:12:47 -0700 (PDT) To: FFmpeg development discussions and patches References: <8ef60c68-b260-83a2-8765-87737879e0b3@jkqxz.net> <20170707001406.GL4727@nb4> From: Mark Thompson Message-ID: Date: Sat, 8 Jul 2017 15:12:47 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <20170707001406.GL4727@nb4> Subject: [FFmpeg-devel] [PATCH v2 1/2] pixdesc: Improve scoring for opaque/unknown pixel formats 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" Hardware pixel formats do not tell you anything about their actual contents, but should still score higher than formats with completely unknown properties, which in turn should score higher than invalid formats. Do not return an AVERROR code as a score. Fixes a hang in libavfilter where format negotiation gets stuck in a loop because AV_PIX_FMT_NONE scores more highly than all other possibilities. --- On 07/07/17 01:14, Michael Niedermayer wrote: > On Thu, Jul 06, 2017 at 10:59:24PM +0100, Mark Thompson wrote: >> ... >> + if ((src_desc->flags & AV_PIX_FMT_FLAG_HWACCEL) || >> + (dst_desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) >> + return 0; > > this breaks ffmpegs choose_pixel_fmt() > src_desc being NULL Where does it ever get called with invalid src? I think it would probably be better to fix those cases in the caller. (It would be asking "of the pixel formats A and B, which is a better match for conversion from ", which is nonsensical.) In any case, I've changed the invalid format check to src_desc && dst_desc to make this more robust. >> >> /* compute loss */ >> *lossp = loss = 0; > > shouldnt this be set on a 0 return ? > > i also wonder if src and dst being identical should score different > than if not if either is AV_PIX_FMT_FLAG_HWACCEL Changed to: -1 Matching hardware formats. -2 Non-matching hardware formats. -3 One of the input formats doesn't have enough metadata to return anything useful. -4 One of the input formats is completely invalid. libavutil/pixdesc.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c index 46a7eff06d..1983ce9ef5 100644 --- a/libavutil/pixdesc.c +++ b/libavutil/pixdesc.c @@ -2511,8 +2511,16 @@ static int get_pix_fmt_score(enum AVPixelFormat dst_pix_fmt, int ret, loss, i, nb_components; int score = INT_MAX - 1; - if (dst_pix_fmt >= AV_PIX_FMT_NB || dst_pix_fmt <= AV_PIX_FMT_NONE) - return ~0; + if (!src_desc || !dst_desc) + return -4; + + if ((src_desc->flags & AV_PIX_FMT_FLAG_HWACCEL) || + (dst_desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) { + if (dst_pix_fmt == src_pix_fmt) + return -1; + else + return -2; + } /* compute loss */ *lossp = loss = 0; @@ -2521,9 +2529,9 @@ static int get_pix_fmt_score(enum AVPixelFormat dst_pix_fmt, return INT_MAX; if ((ret = get_pix_fmt_depth(&src_min_depth, &src_max_depth, src_pix_fmt)) < 0) - return ret; + return -3; if ((ret = get_pix_fmt_depth(&dst_min_depth, &dst_max_depth, dst_pix_fmt)) < 0) - return ret; + return -3; src_color = get_color_type(src_desc); dst_color = get_color_type(dst_desc);