From patchwork Tue Sep 24 07:09:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51792 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:ad12:0:b0:48e:c0f8:d0de with SMTP id w18csp202673vqy; Tue, 24 Sep 2024 01:29:19 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX5QMzV35lE1taOrgLpZE/ZYFXLM4k1QYBeIV3kF4fUsl060/7RBuz7ubRwNPbvjreSRIa89se7Dvh5hmIE/R8/@gmail.com X-Google-Smtp-Source: AGHT+IHl5kposp0aIX2fR/b3VhOKKqZPqycdi/vYdJxutHZz2CTGP7XF6sAU592VDKk1C8FLraMP X-Received: by 2002:a05:6512:3f01:b0:52c:dfa2:5ac1 with SMTP id 2adb3069b0e04-536ac2e51c8mr7724621e87.24.1727166559045; Tue, 24 Sep 2024 01:29:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727166559; cv=none; d=google.com; s=arc-20240605; b=SpMv3D6JrVQZTp5XXtNkYwy+EN25bjItyrYNgctrC4EVYpI2/6wY0QZYnChlalpkaG RzohSphL1Cqj/ySXOz8oUxM1/hIzV4Ax8XPgkjS8z4weC/LX0iQIl3SBg0w1iJ5+PlQ9 LW851jJEFvzVi6NImG5aCxp/6li9gFHDO4LMYanj/z9+egcMNtDYcU3Gcuxu+nR3X3DQ x1T3cMvnPTvOFCGaPN9Mga5v/T7a7LCYv0f+cPItS8t4ECwxVVo8lWwsJOuAoyNfcRcS EBSMVsABvNqET/crUWE6K8ddMgTZFX/CV0Drp8+ASVIISkkudNXE5TYzTJFJB9eczp2R YcuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=IRAxkc8R5NTC6D100r42txFUAihaH5FGV4UO/AO0DrY=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=j8Pz+s9S9a3k3Ni4pJFzLnSK5MbRjmUVlutjbwHs3ZZPDLnOrOtSAt0NELRjYcUNbh JwSC56FaAKhHIOKt9XyEJeByUYx37OPZe/2qP/6HQtmoTG5x6C/FvgMDaz5fItAOj7Gh VEFf4i7nx7SoFfLXmU6DQDDHLsVejFELctilXNtw90hwPCQb9qnelLLZy0Ay9VSd5K0U 2Ks4+tGqnI2eDr+3T1IPKgCg4eiFObbBpZ7xtqZCNVcc6Tn5yXHlufhp7GlX1wIp/dJF wb73B9a974iAH6s9VBj0LQ47KPwnTx4Sy2OtHC3G3ZQMieMJmqCT7ogWaQrvQJh9ZKR6 yZNA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=DxmlGIBk; 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 2adb3069b0e04-537a865097bsi338784e87.595.2024.09.24.01.29.18; Tue, 24 Sep 2024 01:29:19 -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=@khirnov.net header.s=mail header.b=DxmlGIBk; 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 AAC9468DBA3; Tue, 24 Sep 2024 10:10:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 19E4D68DAB2 for ; Tue, 24 Sep 2024 10:10:23 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=DxmlGIBk; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id D3FA94E09 for ; Tue, 24 Sep 2024 09:10:18 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id NtzXW-lKQVkH for ; Tue, 24 Sep 2024 09:10:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1727161816; bh=l8vqaEZdb/RfECfb0OINQHt3gK3fgWbOspkGLhhTgbI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=DxmlGIBkxHjEuhPhhF/q8Mmj/uG/Ow3IzKIjt+SSgutrdaIPGSHBd83n2Q1cUqjgj K/GaCbwiydH6+MCQFEXlpP59lwEKmcJTWNsu0hIDH/y7EyDjsfRjFpqv0ZD4BBaPkI QkP9XozAxCT1cgNM6oxY1aKlWlYFk8idznDYpmYRDLOmlAKRe04VdlhOqDMGmZ+HPf tse9Xp3pJ0iNSfdmP1M6AhwJC/HcJCsVFxTeDzQd0Movx6EMfMfTgSDi3ijJvUdQUf TsRTY3HqBRGgKjLmeg26WunriDd3aMIkeTfMQ/I72G1r3oEHQv6gm6sQK8+hABXcjW 5P2swCnvBGrKA== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 92EF14E14 for ; Tue, 24 Sep 2024 09:10:16 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id EE9533A0998 for ; Tue, 24 Sep 2024 09:10:09 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 24 Sep 2024 09:09:44 +0200 Message-ID: <20240924071000.11428-3-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240924071000.11428-1-anton@khirnov.net> References: <20240924071000.11428-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/13] fftools/ffmpeg_enc: stop using OutputStream in hw_device_setup_for_encode() 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: Ks4eg449GCMz The only variable accessed from it is AVCodecContext, which we can pass directly. Also, this function currently logs into the AVCodecContext, which is wrong. Log to Encoder instead. --- fftools/ffmpeg_enc.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 2e1c7f27c1..c11ec218d7 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -110,34 +110,35 @@ int enc_alloc(Encoder **penc, const AVCodec *codec, return 0; } -static int hw_device_setup_for_encode(OutputStream *ost, AVBufferRef *frames_ref) +static int hw_device_setup_for_encode(Encoder *e, AVCodecContext *enc_ctx, + AVBufferRef *frames_ref) { const AVCodecHWConfig *config; HWDevice *dev = NULL; if (frames_ref && ((AVHWFramesContext*)frames_ref->data)->format == - ost->enc_ctx->pix_fmt) { + enc_ctx->pix_fmt) { // Matching format, will try to use hw_frames_ctx. } else { frames_ref = NULL; } for (int i = 0;; i++) { - config = avcodec_get_hw_config(ost->enc_ctx->codec, i); + config = avcodec_get_hw_config(enc_ctx->codec, i); if (!config) break; if (frames_ref && config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX && (config->pix_fmt == AV_PIX_FMT_NONE || - config->pix_fmt == ost->enc_ctx->pix_fmt)) { - av_log(ost->enc_ctx, AV_LOG_VERBOSE, "Using input " + config->pix_fmt == enc_ctx->pix_fmt)) { + av_log(e, AV_LOG_VERBOSE, "Using input " "frames context (format %s) with %s encoder.\n", - av_get_pix_fmt_name(ost->enc_ctx->pix_fmt), - ost->enc_ctx->codec->name); - ost->enc_ctx->hw_frames_ctx = av_buffer_ref(frames_ref); - if (!ost->enc_ctx->hw_frames_ctx) + av_get_pix_fmt_name(enc_ctx->pix_fmt), + enc_ctx->codec->name); + enc_ctx->hw_frames_ctx = av_buffer_ref(frames_ref); + if (!enc_ctx->hw_frames_ctx) return AVERROR(ENOMEM); return 0; } @@ -148,11 +149,11 @@ static int hw_device_setup_for_encode(OutputStream *ost, AVBufferRef *frames_ref } if (dev) { - av_log(ost->enc_ctx, AV_LOG_VERBOSE, "Using device %s " + av_log(e, AV_LOG_VERBOSE, "Using device %s " "(type %s) with %s encoder.\n", dev->name, - av_hwdevice_get_type_name(dev->type), ost->enc_ctx->codec->name); - ost->enc_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref); - if (!ost->enc_ctx->hw_device_ctx) + av_hwdevice_get_type_name(dev->type), enc_ctx->codec->name); + enc_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref); + if (!enc_ctx->hw_device_ctx) return AVERROR(ENOMEM); } else { // No device required, or no device available. @@ -335,7 +336,7 @@ int enc_open(void *opaque, const AVFrame *frame) enc_ctx->flags |= AV_CODEC_FLAG_FRAME_DURATION; - ret = hw_device_setup_for_encode(ost, frame ? frame->hw_frames_ctx : NULL); + ret = hw_device_setup_for_encode(e, enc_ctx, frame ? frame->hw_frames_ctx : NULL); if (ret < 0) { av_log(e, AV_LOG_ERROR, "Encoding hardware device setup failed: %s\n", av_err2str(ret));