From patchwork Sat Jul 9 06:45:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Lhomme X-Patchwork-Id: 36719 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:6da0:b0:8b:e47:9dbf with SMTP id wl32csp55098pzb; Fri, 8 Jul 2022 23:45:42 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sAQNJRHdHa4dJSGMFjnH2XM/oRpKKlp5E/0OaHH/jdZvtji7BWBQ86AOdNBH07eUNP+2Zm X-Received: by 2002:a17:907:7e85:b0:726:9fc5:cc2d with SMTP id qb5-20020a1709077e8500b007269fc5cc2dmr7183034ejc.376.1657349141895; Fri, 08 Jul 2022 23:45:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657349141; cv=none; d=google.com; s=arc-20160816; b=AjqfrT/T9uRgjw0+UJUU3oKp5TRSSLwIGGs+KBdJL3Ec6SlO9m0Uewii9iLe4/Mp3n XXtNj9LSgO1S4MRroHwuDKiizl7B/j5jUb3qwbETAAoYJ4CasI3bJKgNTlJKcnHUDIvJ Oi9zYUsHATJwy7cYt3fIkA7BvTv9Uu0gxIIXxOe8wv13JjRlX0lS2ylHeLIaaySZZzZj VlnyJogjo0SgsS1BpYncUjTCs4abBGsjeMld7SYADG03OAH3b+1oLYKa1bwi25QNrRLG NNMVDMbz3HEuxwrS/8uf6WSOwIrV+yiY/HDayUTkISHV9Rl2lBuQD/WWNBK0dpBtAQ7n 5q+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:from :content-language:to:mime-version:date:message-id:delivered-to; bh=L1gcfZxAFQ3SbutVs7XSs5LiH40sLKQUQILP0JqiHrw=; b=lEiT2lPyYujWhTmb2CfjXfcX7eI9Lr7oGF+QSeVJrmTAhb0Z19aLrAuQHC1m6IyHZd ZA7ozdsgkisC92si1OjU9fdOlgH0thxecDuH9fZHFvxwMMOS3yPjZukHIzJDGhk0DCoD QtYrqwB0+RATn6RYHmir3pVMZRrnWEd+hSRE8fOlSL2keGrsHWgclJOwmU23CbRLbkLj 6zjhamFGtnZVCdliLxOwgoVDpS+3PuBCszczOE0DT1DDgepRUZP51xujIqNcB0syNSAr 7yLtV3hYloeydMhE7okSpbQ7Jttrs96Q1cIcnbwVb2Dz1GWwRKDk497PD/HaelLwa/7J hEMA== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t4-20020a056402240400b0043765427d74si1173480eda.347.2022.07.08.23.45.41; Fri, 08 Jul 2022 23:45: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; 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 43BF168BA3C; Sat, 9 Jul 2022 09:45:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C229468B7ED for ; Sat, 9 Jul 2022 09:45:32 +0300 (EEST) Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4Lg0yf1Nptz9sRp for ; Sat, 9 Jul 2022 08:45:30 +0200 (CEST) Message-ID: <6301fb24-1d5d-b069-a773-0defdc2086df@ycbcr.xyz> Date: Sat, 9 Jul 2022 08:45:31 +0200 MIME-Version: 1.0 To: FFmpeg development discussions and patches Content-Language: en-US From: Steve Lhomme X-Rspamd-Queue-Id: 4Lg0yf1Nptz9sRp Subject: [FFmpeg-devel] [PATCH] avcodec/pthread_frame: update the main avctx from the current, ThreadContext X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: It7+xeDOar5h Patch attached in the email. In some cases, the submit packet can result in configurations changes of the hardware decoders. The previous HW context is then freed and a new one created. That context is supposed to move up to the main context and the other threads. It appears that when more than 2 frame threads are involved, the new context doesn't move in the right place (or rather at the right time). And it can create a crash when reusing the old HW context. This patch fixes the issue I could reproduce in VLC with DXVA decoding. I have no idea if this is correct or the side effects induced by this. It seems the right thing to do. Keeping the previous call exhibits the issue. It seems odd the other existing thread context are not updated with the current hwaccel_priv_data. But maybe they are updated later from the "main" thread context, in which case this patch seems solid. From e8abeeff92f5d7b3b553acdb7595d40153cbec1e Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Fri, 8 Jul 2022 11:49:27 +0200 Subject: [PATCH] avcodec/pthread_frame: update the main avctx from the current ThreadContext After a submit_decoder() the hwaccel_priv_data may have changed in that avctx. Doing it after the "next available frame" loop will likely point to the hwaccel_priv_data from another PerThreadContext which had the old value which might have been freed, if the submit_decoder() resulting in a format change. --- libavcodec/pthread_frame.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index 8faea75a49..eff09c3510 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -529,6 +529,8 @@ int ff_thread_decode_frame(AVCodecContext *avctx, if (err) goto finish; + update_context_from_thread(avctx, p->avctx, 1); + /* * If we're still receiving the initial packets, don't return a frame. */ @@ -578,8 +580,6 @@ int ff_thread_decode_frame(AVCodecContext *avctx, if (finished >= avctx->thread_count) finished = 0; } while (!avpkt->size && !*got_picture_ptr && err >= 0 && finished != fctx->next_finished); - update_context_from_thread(avctx, p->avctx, 1); - if (fctx->next_decoding >= avctx->thread_count) fctx->next_decoding = 0; fctx->next_finished = finished;