From patchwork Mon Sep 2 14:28:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Darnley X-Patchwork-Id: 14847 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 116A1448974 for ; Mon, 2 Sep 2019 17:37:43 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E5145680BCF; Mon, 2 Sep 2019 17:37:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 29C32680233 for ; Mon, 2 Sep 2019 17:37:37 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id t9so14862427wmi.5 for ; Mon, 02 Sep 2019 07:37:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=obe-tv.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nvAEf3T5lQFQdBUVEZ5mOTFWHo9oendTqIvHeNwnvvs=; b=ymm0euUXWqMrc0ExgyBKYaRdvJCRNie2lexjjoJBD9WaA+EY1YJNjTm33+DbEzuV2P 4gIf0nrs2THgZ/od7FeUg0zQeuSfjEB+zu2J5cwgVsxQrTwdEIAsHPvBNnG37RrROQNK AMkPwkENW6ss5tvjN3Mq8V/GOm23mzSl5jgn5VtCx2liYtlqwRUKvtudYJkUcMhX4lbc 0q3F/rbTDT0oLvZEE8eOt5lGMSLLmTPQ9bB859/YhDBp0vptv4lRxJT5al/qrSnOckEL WJCOM765wbGRfZuv7K0pEErK9vZ49YW0qYhbzEry00JrIqqC0cmjqMr/vknyFiFTq5Je 40TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nvAEf3T5lQFQdBUVEZ5mOTFWHo9oendTqIvHeNwnvvs=; b=Whxkl73FDC7GoXK3Sqio8mwiWuJVL1/QeP7uE9Zw/Nmr9iWTa7yK7tfXQTvYJ2Rm5g vwGv4BMxlL9ufS9/7BJEFLjDlZpxxa9NBsUjkS/7EGdWeQUBpMIrFA8vtFWIdMBvzxHI PXIa10HtGTe6bIFxyUSozxCqP4ugcbo+w5gbxPzFgRKf0323PD9HqCZGOzHOglWT4G4X pC5YRMMOJqc2W5LtJOTpoPdCvwkGj59dmO7JH4NEs2Ga1O9NYQiNYpyJVuBreU+BZ0Vl Uj9SmtrCf4kXQEM33EKifAznPEEHC+Q4LaTjor1esPp87lYrR6ZOxZsI//9ZERufq5dr 7OVg== X-Gm-Message-State: APjAAAW1Vq4b1EmwKXbp0LpsFUSL8Ews4yLzK/g4oP3d9RUbqGYs/LWf QB13TMPOkEe/XDKgNtdalO/fqVK64G2Iog== X-Google-Smtp-Source: APXvYqw2gk9mA9VsTO9ab7UwxUAdSxl7DbdAZ2FDrlOHAq4xbrnBUYquDQc2xYrLhGXEsrMlet3gsQ== X-Received: by 2002:a1c:c706:: with SMTP id x6mr37062544wmf.104.1567434551597; Mon, 02 Sep 2019 07:29:11 -0700 (PDT) Received: from Ramuh.systemlords.lan (ptr-7sz70r2zkpm35z8cnil.18120a2.ip6.access.telenet.be. [2a02:1811:41e:dc00:d926:c42d:226a:860d]) by smtp.gmail.com with ESMTPSA id q26sm2337828wmf.45.2019.09.02.07.29.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2019 07:29:10 -0700 (PDT) From: James Darnley To: ffmpeg-devel@ffmpeg.org Date: Mon, 2 Sep 2019 16:28:53 +0200 Message-Id: <20190902142853.31171-3-jdarnley@obe.tv> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190902142853.31171-1-jdarnley@obe.tv> References: <20190902142853.31171-1-jdarnley@obe.tv> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/h264: fix draw_horiz_band with slice threads 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 Cc: Kieran Kunhya Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Kieran Kunhya --- libavcodec/h264_slice.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 5ceee107a0..fe2aa01ceb 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -2527,18 +2527,33 @@ static void predict_field_decoding_flag(const H264Context *h, H264SliceContext * /** * Draw edges and report progress for the last MB row. */ -static void decode_finish_row(const H264Context *h, H264SliceContext *sl) +static void decode_finish_row(const H264Context *h, H264SliceContext *sl, int slice_end) { int top = 16 * (sl->mb_y >> FIELD_PICTURE(h)); int pic_height = 16 * h->mb_height >> FIELD_PICTURE(h); int height = 16 << FRAME_MBAFF(h); int deblock_border = (16 + 4) << FRAME_MBAFF(h); - if (sl->deblocking_filter) { + /* Slice-threaded draw_horiz_band not useful in this situation */ + if (sl->deblocking_filter == 1) { if ((top + height) >= pic_height) height += deblock_border; top -= deblock_border; } + else if (sl->deblocking_filter == 2) { + int first_mb_y = sl->first_mb_addr / h->mb_width; + + /* Draw the whole slice if it's possible: + * - If the beginning of the slice is at the start of a row + * - If we are at the end of the slice + * Previous slice is guaranteed not be included. */ + if (!(sl->first_mb_addr % h->mb_width)) { + if (slice_end) { + top = 16 * (first_mb_y >> FIELD_PICTURE(h)); + height = (16 << FRAME_MBAFF(h)) * ((sl->mb_y+1) - first_mb_y); + } + } + } if (top >= pic_height || (top + height) < 0) return; @@ -2549,7 +2564,8 @@ static void decode_finish_row(const H264Context *h, H264SliceContext *sl) top = 0; } - ff_h264_draw_horiz_band(h, sl, top, height); + if (slice_end) + ff_h264_draw_horiz_band(h, sl, top, height); if (h->droppable || sl->h264->slice_ctx[0].er.error_occurred) return; @@ -2622,7 +2638,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg) for (;;) { // START_TIMER - int ret, eos; + int ret, eos, slice_end; if (sl->mb_x + sl->mb_y * h->mb_width >= sl->next_slice_idx) { av_log(h->avctx, AV_LOG_ERROR, "Slice overlaps with next at %d\n", sl->next_slice_idx); @@ -2669,10 +2685,11 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg) return AVERROR_INVALIDDATA; } + slice_end = eos || sl->mb_y >= h->mb_height; if (++sl->mb_x >= h->mb_width) { loop_filter(h, sl, lf_x_start, sl->mb_x); sl->mb_x = lf_x_start = 0; - decode_finish_row(h, sl); + decode_finish_row(h, sl, slice_end); ++sl->mb_y; if (FIELD_OR_MBAFF_PICTURE(h)) { ++sl->mb_y; @@ -2729,7 +2746,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg) if (++sl->mb_x >= h->mb_width) { loop_filter(h, sl, lf_x_start, sl->mb_x); sl->mb_x = lf_x_start = 0; - decode_finish_row(h, sl); + decode_finish_row(h, sl, 0); ++sl->mb_y; if (FIELD_OR_MBAFF_PICTURE(h)) { ++sl->mb_y;