From patchwork Tue Mar 9 02:36:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26276 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 1E162449D24 for ; Tue, 9 Mar 2021 04:38:58 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EC132689A8B; Tue, 9 Mar 2021 04:38:57 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 01A9C688316 for ; Tue, 9 Mar 2021 04:38:50 +0200 (EET) Received: by mail-qv1-f50.google.com with SMTP id d9so5730381qvo.3 for ; Mon, 08 Mar 2021 18:38:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=yZoi1fMZMpD6fD6UOV84Z9zqOPMrYfNA7lSIvwZOMK4=; b=mJmfYFygIQdiaSNhWj5ouA/5epk+TDccNz+ZLn2cm6r7QrIx04pfPXT6q66vRueHO3 tq8P+4euZdko7uNCRUc41iCBrQ/CJ8/ifHTax/pXj050jw7CoBfINbdRi+8jUahTdbzZ Tgp8Y7Xksfpga6Fkj93DIlMnPsNU0rP+Uu5Z0LR2HIdzfWLsEGwt4N2biDlObQtjCoxL pw5NeileyT7IVbLMM8BUlKrS3c1w3beSu4e78rkXCrKxDfrqYLhCNkJsCAXhdu6uGaeh RIhM+xuzpNxNXONFWjQgGWMALk80jaS7vAnjUkJLMjoO8yD3S1pUZ0t1lTKjXsqNyLH3 35zg== 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:mime-version :content-transfer-encoding; bh=yZoi1fMZMpD6fD6UOV84Z9zqOPMrYfNA7lSIvwZOMK4=; b=dkqPH8HhxVmh2lEOgJNeGJR3oJkVFvox0HekdQhZQ7DuAFW3oi31HXSBkwr5rPAUHl v4dGuNinb5XddwOq9frcquw2d5pfjMyIpBt/GTZBcTlS9t2M/cYxB3/5gYPjjo8lEqN9 2ISQblXtvIA8cU7Bqxw+cIN708WsgMmIYkAxzjoCs1cVY6CQmRNLT04NCzKMsz18Vr64 BUv+zkj+1vOB11ZsRbtj8q7KZYL/ka71PhSzMQcsgB96SJqxDk37kuB2Ws1ofWWDpGgD SpYN/SzAXnospuCl8VGXedF4YZ4A4cvAywGTyYwiMDAJkjG3UG0PPodRdaBus2ydsF8w TRDQ== X-Gm-Message-State: AOAM531s0U0eczCrsWx+y2USafKhyqhABkDDziS8jTjtY3ApS8ZAOTgR sLctJmZyizVz/8uXME+9c/H9O/F3lxbRjA== X-Google-Smtp-Source: ABdhPJyiF9LrD9Nf2pdsfST38SKMKFi00I+I2/p+/EfiDZn+8xY9Hy05I4/siHwXaW+SsmgX2uuyvA== X-Received: by 2002:a05:6214:2464:: with SMTP id im4mr1830957qvb.61.1615257529255; Mon, 08 Mar 2021 18:38:49 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id c125sm9424874qke.117.2021.03.08.18.38.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 18:38:48 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 8 Mar 2021 23:36:00 -0300 Message-Id: <20210309023600.16661-1-jamrial@gmail.com> X-Mailer: git-send-email 2.30.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/h264_slice: don't copy frame data during error concealment 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" In addition to the fact that av_image_copy() cannot handle hardware pixel formats, h->short_ref[0]->f may not even be writable at this point. Based on a patch by Hendrik Leppkes. Signed-off-by: James Almer --- This is an alternative to "avcodec/h264_slice: properly handle missing reference frames with hwaccel", given that I noticed that the target frame is not writable for example when running fate-h264-missing-frame. To keep the current behavior of copying the frame data instead of making a reference, I also tried to do ff_thread_release_buffer() -> ff_thread_get_buffer() -> av_frame_copy(), which worked with software decoding, but when using the d3d11va hwaccel the av_frame_copy() call would fail. There is a warning above this code that makes it sound like making references is not ideal, but considering h->short_ref[0] is not writable here it feels like it could be an outdated comment that someone forgot to remove. libavcodec/h264_slice.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index fa7a639053..a2f4ffa6d6 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -1599,13 +1599,11 @@ static int h264_field_start(H264Context *h, const H264SliceContext *sl, ff_thread_await_progress(&prev->tf, INT_MAX, 0); if (prev->field_picture) ff_thread_await_progress(&prev->tf, INT_MAX, 1); - av_image_copy(h->short_ref[0]->f->data, - h->short_ref[0]->f->linesize, - (const uint8_t **)prev->f->data, - prev->f->linesize, - prev->f->format, - prev->f->width, - prev->f->height); + ff_thread_release_buffer(h->avctx, &h->short_ref[0]->tf); + h->short_ref[0]->tf.f = h->short_ref[0]->f; + ret = ff_thread_ref_frame(&h->short_ref[0]->tf, &prev->tf); + if (ret < 0) + return ret; h->short_ref[0]->poc = prev->poc + 2U; } else if (!h->frame_recovered && !h->avctx->hwaccel) ff_color_frame(h->short_ref[0]->f, c);