From patchwork Mon May 8 18:46:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 3619 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.3.129 with SMTP id 123csp982807vsd; Mon, 8 May 2017 11:47:42 -0700 (PDT) X-Received: by 10.223.128.34 with SMTP id 31mr32751943wrk.108.1494269262099; Mon, 08 May 2017 11:47:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1494269261; cv=none; d=google.com; s=arc-20160816; b=qNJP62Xa7qWS227tsa+cfv+EIMZzpTsfJJj+CINHmW7LlZBsmO2EsCc2ec+shqynti LEHUvSgaFLhrt5JkC78hTHuyTbGY6QK61NFcVXzdHB1u+ZpNyy5H9wazdfB37wwpT0sX OXxAMZYtE3JSQ70dV4Qj4LC06YEINO/j9y4K85S31ER4Goonhu2NtT2VkkAxSPyDTDh1 YGVpxaWGk8gCLfjszVmTcKu8MJH6IjQo9Bp4dSfXrW3IMrF+IG1gX7ZLW9sBtMZcT5ba wiucs8GeidsGHoLPLHZZlFbZ1I+nHy4PiizyzctNwQw3d+XklNbNcydcyAjGlJSDnCQX YNuw== 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:dkim-signature:delivered-to:arc-authentication-results; bh=f7QSt9+80gm43/uPr/jtNYbdhwiMe50TcIldelL0wX4=; b=oxe9nllzwfaU0HWhOTV++3CSPnj1xK3Ki3oGLSz5XC1/5D6H4hQZ0bomngai/gPx6l oo9KzB72cQWM7wZ/BeLTnl9lc7BoBrEK029cVP6cgl3SXZgq9+HyQQCIR7anpzB885BR XbqF9I/e0092rnYfq/C63p5PCuzgPQ7MWPqa6KIcRuk/zDQHQHVO+IxenN3ZHBsVBnQL xIm0eLHBxVn4aBSv5nqgNIWLOx7clKs1D7/LbIknN8hs69u0kESSeudaxECgYpP+71uG PMs3vMfLPmFPG+spzu5L/+l2IizrS83NwKQqSFWbbecZmKjNNcvmNA3M2zUMEtcsViJd 7Cqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.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; dmarc=fail (p=NONE sp=NONE 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 b71si2776988wmg.79.2017.05.08.11.47.41; Mon, 08 May 2017 11:47:41 -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=@gmail.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; dmarc=fail (p=NONE sp=NONE 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 8BB6B688365; Mon, 8 May 2017 21:47:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt0-f193.google.com (mail-qt0-f193.google.com [209.85.216.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CFAA16803A4 for ; Mon, 8 May 2017 21:47:16 +0300 (EEST) Received: by mail-qt0-f193.google.com with SMTP id r58so10749260qtb.2 for ; Mon, 08 May 2017 11:47:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=cfs2TzoPpuKwN8+h2oU7CfTeGw2QhkyyR6QpgR4sVPY=; b=YzajJNxT8raWyu5ADMu9y6SOXzokN+OzjGWo5ZyDB1tOof5xV1rkhAgJW8EreQjs2C MQOmZtNaGa4M2D87W02sOrenBWekuGsvtiSTZ6eM1EZvcvU32nAHujeNDdl7w/zs6itH JU4jlr8gS4/9sVr2gLnPxBlMrL5wYsY3/9/Lc/JraUaV3WgSXdX3X58fgeBUxwp7OUFo t3OwCObTF4JVflwNaxY3ZvDbiCnsssNf3PIdmtU3xje7QTXmTyPSLlao/PEXu9iBfuT3 jNtY6OPAM8BXguuisnix13oQmOqRPeNTIajxar0cvokHktk2ozEh1n8Rqc+JkffTjKu8 JKLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=cfs2TzoPpuKwN8+h2oU7CfTeGw2QhkyyR6QpgR4sVPY=; b=kyWbBPthPOpTJM+hxUkM5j7BPbUhlGjfzbyhUEZocWmf0tMMfOE15xov6vHk+RlkgZ RAyRmGnkERWH6gPjN8fQRw3/X1cUIc4K/oce90Je8Z7HYeEKtkcVvrGwMyG/7Epe/K0y FkDty9lNHyTQYOc9ylWfBc7T09hz7wBhgiQiVQG1eD/A8wdTG73OGDOgg9wqJiImMuwT zw/jLS/r25pk79FPWkkQqAN0qW3S/e1wchd8A45WLl3DgjhHxcqbn1o0UqnzIbstkrWT nmar+5OGzq6/flPHK2NKmvYmitmCX7yabJLAa7sfY5YnC/Kv3X0SdRoPr4IUlYq52BCm zJJQ== X-Gm-Message-State: AN3rC/4d7uKNbElWXIDbuniV4dBdppzBQPYrKPoVsvpbUapTNfNicgmU T1lKh0FS9prE/xdN X-Received: by 10.237.33.69 with SMTP id 63mr45944593qtc.251.1494269241678; Mon, 08 May 2017 11:47:21 -0700 (PDT) Received: from localhost.localdomain ([181.231.116.134]) by smtp.gmail.com with ESMTPSA id t136sm702878qke.40.2017.05.08.11.47.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 May 2017 11:47:21 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 8 May 2017 15:46:23 -0300 Message-Id: <20170508184625.7056-2-jamrial@gmail.com> X-Mailer: git-send-email 2.12.1 In-Reply-To: <20170508184625.7056-1-jamrial@gmail.com> References: <20170508184625.7056-1-jamrial@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/4] h264dec: be more explicit in handling container cropping 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" From: Anton Khirnov The current condition can trigger in cases where it shouldn't, with unexpected results. Make sure that: - container cropping is really based on the original dimensions from the caller - those dimenions are discarded on size change The code is still quite hacky and eventually should be deprecated and removed, with the decision about which cropping is used delegated to the caller. --- This merges commit 4fded0480f20f4d7ca5e776a85574de34dfead14 from libav libavcodec/h264_slice.c | 20 +++++++++++++------- libavcodec/h264dec.c | 3 +++ libavcodec/h264dec.h | 5 +++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index acf6a73f60..a7916e09ce 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -378,6 +378,8 @@ int ff_h264_update_thread_context(AVCodecContext *dst, h->avctx->coded_width = h1->avctx->coded_width; h->avctx->width = h1->avctx->width; h->avctx->height = h1->avctx->height; + h->width_from_caller = h1->width_from_caller; + h->height_from_caller = h1->height_from_caller; h->coded_picture_number = h1->coded_picture_number; h->first_field = h1->first_field; h->picture_structure = h1->picture_structure; @@ -874,13 +876,17 @@ static int init_dimensions(H264Context *h) av_assert0(sps->crop_top + sps->crop_bottom < (unsigned)h->height); /* handle container cropping */ - if (FFALIGN(h->avctx->width, 16) == FFALIGN(width, 16) && - FFALIGN(h->avctx->height, 16) == FFALIGN(height, 16) && - h->avctx->width <= width && - h->avctx->height <= height - ) { - width = h->avctx->width; - height = h->avctx->height; + if (h->width_from_caller > 0 && h->height_from_caller > 0 && + !sps->crop_top && !sps->crop_left && + FFALIGN(h->width_from_caller, 16) == FFALIGN(width, 16) && + FFALIGN(h->height_from_caller, 16) == FFALIGN(height, 16) && + h->width_from_caller <= width && + h->height_from_caller <= height) { + width = h->width_from_caller; + height = h->height_from_caller; + } else { + h->width_from_caller = 0; + h->height_from_caller = 0; } h->avctx->coded_width = h->width; diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index 35ab51f616..a8d07df1e7 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -309,6 +309,9 @@ static int h264_init_context(AVCodecContext *avctx, H264Context *h) h->avctx = avctx; h->cur_chroma_format_idc = -1; + h->width_from_caller = avctx->width; + h->height_from_caller = avctx->height; + h->picture_structure = PICT_FRAME; h->workaround_bugs = avctx->workaround_bugs; h->flags = avctx->flags; diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h index 1c0dfbf7f7..5e03d55558 100644 --- a/libavcodec/h264dec.h +++ b/libavcodec/h264dec.h @@ -534,6 +534,11 @@ typedef struct H264Context { int cur_bit_depth_luma; int16_t slice_row[MAX_SLICES]; ///< to detect when MAX_SLICES is too low + /* original AVCodecContext dimensions, used to handle container + * cropping */ + int width_from_caller; + int height_from_caller; + int enable_er; H264SEIContext sei;