From patchwork Fri May 29 17:20:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 19972 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 4B22E44AF0B for ; Fri, 29 May 2020 20:21:06 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2223268AD22; Fri, 29 May 2020 20:21:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f196.google.com (mail-qk1-f196.google.com [209.85.222.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 060D268A953 for ; Fri, 29 May 2020 20:21:00 +0300 (EEST) Received: by mail-qk1-f196.google.com with SMTP id v79so2866718qkb.10 for ; Fri, 29 May 2020 10:20:59 -0700 (PDT) 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=aLPliVzLEe/axfnMo8zgkz6mkAfQtzhyS/CZSdQzCqQ=; b=btVXEAg7ZQOCP5WaVk8jLwoReS0pbpH99D2naXGJeL1ZeBNSZyCnWJ/YR/8sbD65n3 WPcA6MvZA7INW/0FEsOrLAo275RvTjsyLU1LUIQrl9BT2Tt9hUVV5M7FGLFeSuvv4hIg s/6FpYX4UyK8AkeMmy3hEkk5A08KcKtZMUyZfrFoMEfY8TZ1dq8kgNdHhOMpA8xkCNul zx/fCRJ0RFjA9hpaIkQNex1lEpJADGHMl/KBrQvu/HjCSzTqzLZlGeiyUMYe8/7eyyso YVyRRkpHoH0XbwHhqwfU9Q0xndvJXiUbWn9TGhnuHARA96dvWGi9NdsIhKdgZyYl0+uc ACRA== 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=aLPliVzLEe/axfnMo8zgkz6mkAfQtzhyS/CZSdQzCqQ=; b=UtwkDVKR07Q13NQqTuUJfoX0m0mvcTQpA8GXkXgCuZURvToqckmOCy7ATJX2zCkvdk UNs0ZM3aSn8sdP4fixnsAjDrSld7G1uT1NRqmKJstIBDK61hpnJkkLJ+SLQ3qHMu8bA+ cnQMKlPc5Gdv2jNWg8YskLjf2Eb87Wxu9dmkDDYw94adA0Ue5LIqWT4rwbIHOb9uQtX3 nmw9CI89uhOdNSseVxa3/kKk1q0LZs2Ck501+BzaxaLQsXXBdkCqXNGD3pg/tIn2xXNq u+H0vys3nSTsUkSaxzGPDop/kgDjU0km9485TRY6a7hkZDhPGXKz13g9YqSwm6TuiM6E JXDQ== X-Gm-Message-State: AOAM533UcFd/ZS+JgrJr2g9kckCNq7ezNYOi5JMSXxaFwLUe8MxIYgrb HCyT1++wYBwXQf/V/zXxV7eXRUvT X-Google-Smtp-Source: ABdhPJym88hWG/QkPLj6G7rNRy0+efRcg1TlO/r5QsmB8BsR100LqSb3noT4I6NV1K45vl5AJapUwA== X-Received: by 2002:a37:b185:: with SMTP id a127mr8710465qkf.87.1590772857907; Fri, 29 May 2020 10:20:57 -0700 (PDT) Received: from localhost.localdomain ([181.23.76.18]) by smtp.gmail.com with ESMTPSA id j5sm500652qtc.72.2020.05.29.10.20.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 10:20:56 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 29 May 2020 14:20:37 -0300 Message-Id: <20200529172037.4595-1-jamrial@gmail.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/snow: ensure current_picture is writable before modifying its data 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" current_picture was not writable here because a reference existed in at least avctx->coded_frame, and potentially elsewhere if the caller created new ones from it. Signed-off-by: James Almer --- For that matter, there are two filters that depend on whatever s->mpvencdsp.draw_edges is doing on this buffer, accessing it through avctx->coded_frame after passing their input to this encoder. This is very hacky and the main blocker to remove coded_frame in the next bump, so it must be changed. If mpvencdsp.draw_edges needs to be accessed from lavfi, then it could be shared, or its code duplicated. But the current snow usage from lavfi is crazy and beyond the scope of coded_frame, which was meant to export quality stats and not work as some sort of interface to access lavc image processing features. libavcodec/snowenc.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c index 3f2a75a670..3543574ec5 100644 --- a/libavcodec/snowenc.c +++ b/libavcodec/snowenc.c @@ -1624,10 +1624,20 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, s->lambda = 0; }//else keep previous frame's qlog until after motion estimation +#if FF_API_CODED_FRAME +FF_DISABLE_DEPRECATION_WARNINGS + av_frame_unref(avctx->coded_frame); +FF_ENABLE_DEPRECATION_WARNINGS +#endif + if (s->current_picture->data[0]) { int w = s->avctx->width; int h = s->avctx->height; + ret = av_frame_make_writable(s->current_picture); + if (ret < 0) + return ret; + s->mpvencdsp.draw_edges(s->current_picture->data[0], s->current_picture->linesize[0], w , h , EDGE_WIDTH , EDGE_WIDTH , EDGE_TOP | EDGE_BOTTOM); @@ -1645,7 +1655,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, ff_snow_frame_start(s); #if FF_API_CODED_FRAME FF_DISABLE_DEPRECATION_WARNINGS - av_frame_unref(avctx->coded_frame); ret = av_frame_ref(avctx->coded_frame, s->current_picture); FF_ENABLE_DEPRECATION_WARNINGS #endif