From patchwork Fri Sep 8 02:55:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Zhao X-Patchwork-Id: 43650 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4e27:b0:149:dfde:5c0a with SMTP id gk39csp215273pzb; Thu, 7 Sep 2023 19:56:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHZOKwyaNPV/mBkLe8Nnw12UCtqxgMrY4ANOZ7xpn/DPdlMumQoBuYwk25N7ysc8lMlK8aH X-Received: by 2002:a17:906:32c3:b0:9a5:a701:2b90 with SMTP id k3-20020a17090632c300b009a5a7012b90mr780855ejk.40.1694141778269; Thu, 07 Sep 2023 19:56:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694141778; cv=none; d=google.com; s=arc-20160816; b=vhHYzb3eMXzTinOMgtJ97sCbuG/Ej/rZPRnZIbspG5YOQw/A7RRZf1yHSHrxvQGxso zpMAk3Ej7uUhGcAfeEQsJTmeMgJm4fPrLFxKJbf2Kq7IK1q1IjJyIMsKTQEjsFSJEwZ1 ipoABRejCyiwz6l+JKUfr7ONFni2CMnnBD6998K75/g4IaznvHBaYPME+oglWA2k69Uz X/xp664r30U0vinMkq3r02FH8gSWaTFSqApP1hq5aZ3BgUsz04mLM3xY/NoM8s4Fhoz0 i4HQZuQ41bvC4dKtlBawsiRdACvlt8c6fKVL/LtqYQJtBxaKhlHtPPiiYwyLyoz3X/ZY 8LIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=5i00sGTzqPENzpvCGtquE3Y0f4uBPGdsuV3x8Z+3E0U=; fh=paNsSD/gLXCX8XaG2wP2EhSbyn4+hY3DzFJxc2Arm+k=; b=aaCbcWYsQ9AJ8v7WqQquwg8c+hRildA7sSj7UtlLgquYKXw0t9tkSMHVRi8rpnR5vC AnvLOZFycTKc2O3+734G3PQkgrVMnnf+QSadB4kPdcsed01B1UKIUBsOI1WT72qxTCxe kie5ExAK7F6obG3Kfnzu/kZiBZtBvpE8bXiF12JWrqLBMy2UZ9fB4RXBLBd9tZmhYGO4 m/4a9Vd2RXzQRagOnXcdGmm9Ufo39rNiJZ9OpwtYc0J93i0maplVyk4RPbE2hBazPUY1 pAhb3sqSEiCyYmqYbi1AtAu3VYFOG3F09KqyL6SFu6+0CKQOobSJ4gSgPCq70UsgpiOZ kQXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=mDYbUnsL; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id j9-20020a170906410900b00992bf8cc68csi475585ejk.973.2023.09.07.19.56.17; Thu, 07 Sep 2023 19:56:18 -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=@gmail.com header.s=20221208 header.b=mDYbUnsL; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9BC3D68C88D; Fri, 8 Sep 2023 05:56:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 08AC368C709 for ; Fri, 8 Sep 2023 05:55:56 +0300 (EEST) Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-401da71b85eso17127585e9.1 for ; Thu, 07 Sep 2023 19:55:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694141755; x=1694746555; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wwEXW6eKAcKfI8XRv40gti6vF3oLuWdLFDjdfEkWBqE=; b=mDYbUnsLZwpcQfMq8gvmXSBpCMKf/1dx9OCAX6YumCxL1SiR6YBAF0WfP8i/DIYom4 K8GPfQx6EiBZiWD66CwykFb5mWveToIKN6CFSvGHUKUc/F+yzlogS6t1FDP43u4IlW7B JqNgiBtNJqgqvMJSGc+QctbUEfxMRWoZB5I3F5Cwq/CcZOSdWeQRqULNdkYkVRBAiVaI UzKpsMQ/FXvlCKmpZ+W7BD+dHorrF7mOc2YEguaXSUgKXSRBpa/QBJxl9Zqw5kXaSkMZ PbY3iRYEmwj5Nn46lsCQbL3S4DvN8+SO+20IJp9eU0B1r+I2EP0JJRDR+z+z5rfFm4Tw hxbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694141755; x=1694746555; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wwEXW6eKAcKfI8XRv40gti6vF3oLuWdLFDjdfEkWBqE=; b=sJgcv8gAeAOB5rhF6pGGXuaj64VjkUMF++pG/H1P1OQUa64+8aHgbv4TWK8NDYU6B7 vKhI16583T3Es56OpxB/vAFh3BDRGpb7eqxQJwpTlsdeQ59YN/HS8HUoWeUx3+0sPuds 9PZZvIXGKEukCavHxNkuSjwKvV5cFFW/McKuEuLvNpxf2fiz9kzQ1c2YTnlnJlm5+cXu 6UqRO/eiyL5YydYWbPOIgjzGivu9obThwFTTUfpytgBaLlYfBJoh53MWSfoZ1BM153SP 0T6sKWDznq/2bdc56OEPsv5Ui171lJuSSKfLyC3HgJq7p9oEVMl/ptJiPUBfrVrExHT1 umtw== X-Gm-Message-State: AOJu0YwlH16sCXS4RKJEz+89SaiN1zm7SANbShXDzm0TcKWZ9f66GjjI mmPLfBUnVxaid33G8OTjI1Ks/aR8cUODtUjx X-Received: by 2002:a05:600c:2a50:b0:402:bda9:74d1 with SMTP id x16-20020a05600c2a5000b00402bda974d1mr971439wme.8.1694141754785; Thu, 07 Sep 2023 19:55:54 -0700 (PDT) Received: from localhost.localdomain ([49.51.162.193]) by smtp.gmail.com with ESMTPSA id e11-20020adffc4b000000b0031f65cdd271sm803831wrs.100.2023.09.07.19.55.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 19:55:54 -0700 (PDT) From: Jun Zhao To: ffmpeg-devel@ffmpeg.org Date: Fri, 8 Sep 2023 10:55:46 +0800 Message-Id: <20230908025546.3205524-2-mypopydev@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230908025546.3205524-1-mypopydev@gmail.com> References: <20230908025546.3205524-1-mypopydev@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 2/2] lavc/videotoolboxenc: Get the encoder supported properties 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 Cc: Jun Zhao , Jun Zhao Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: dAFpgFK5th72 Get the encoder supported properties list, it will be used for feature support checks. Signed-off-by: Jun Zhao --- libavcodec/videotoolboxenc.c | 70 ++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c index 2e96990741..832147b6cd 100644 --- a/libavcodec/videotoolboxenc.c +++ b/libavcodec/videotoolboxenc.c @@ -232,6 +232,7 @@ typedef struct VTEncContext { AVClass *class; enum AVCodecID codec_id; VTCompressionSessionRef session; + CFDictionaryRef supported_props; CFStringRef ycbcr_matrix; CFStringRef color_primaries; CFStringRef transfer_function; @@ -321,6 +322,34 @@ static void clear_frame_queue(VTEncContext *vtctx) set_async_error(vtctx, 0); } +static void vtenc_reset(VTEncContext *vtctx) +{ + if (vtctx->session) { + CFRelease(vtctx->session); + vtctx->session = NULL; + } + + if (vtctx->supported_props) { + CFRelease(vtctx->supported_props); + vtctx->supported_props = NULL; + } + + if (vtctx->color_primaries) { + CFRelease(vtctx->color_primaries); + vtctx->color_primaries = NULL; + } + + if (vtctx->transfer_function) { + CFRelease(vtctx->transfer_function); + vtctx->transfer_function = NULL; + } + + if (vtctx->ycbcr_matrix) { + CFRelease(vtctx->ycbcr_matrix); + vtctx->ycbcr_matrix = NULL; + } +} + static int vtenc_q_pop(VTEncContext *vtctx, bool wait, CMSampleBufferRef *buf, ExtraSEI **sei) { BufNode *info; @@ -1110,6 +1139,20 @@ static int vtenc_create_encoder(AVCodecContext *avctx, return AVERROR_EXTERNAL; } + if (__builtin_available(macOS 10.13, iOS 11, tvOS 11, *)) { + status = VTCopySupportedPropertyDictionaryForEncoder(avctx->width, + avctx->height, + codec_type, + enc_info, + NULL, + &vtctx->supported_props); + + if (status != noErr) { + av_log(avctx, AV_LOG_ERROR,"Error retrieving the supported property dictionary err=%"PRId64"\n", (int64_t)status); + return AVERROR_EXTERNAL; + } + } + // Dump the init encoder { CFStringRef encoderID = NULL; @@ -1662,7 +1705,6 @@ static av_cold int vtenc_init(AVCodecContext *avctx) // It can happen when user set avctx->profile directly. if (vtctx->profile == AV_PROFILE_UNKNOWN) vtctx->profile = avctx->profile; - vtctx->session = NULL; status = vtenc_configure_encoder(avctx); if (status) return status; @@ -2431,8 +2473,8 @@ static int create_cv_pixel_buffer(AVCodecContext *avctx, vtstatus = VTCompressionSessionPrepareToEncodeFrames(vtctx->session); if (vtstatus == kVTInvalidSessionErr) { - CFRelease(vtctx->session); - vtctx->session = NULL; + vtenc_reset(vtctx); + status = vtenc_configure_encoder(avctx); if (status == 0) pix_buf_pool = VTCompressionSessionGetPixelBufferPool(vtctx->session); @@ -2688,10 +2730,7 @@ static int vtenc_populate_extradata(AVCodecContext *avctx, pe_cleanup: CVPixelBufferRelease(pix_buf); - if(vtctx->session) - CFRelease(vtctx->session); - - vtctx->session = NULL; + vtenc_reset(vtctx); vtctx->frame_ct_out = 0; av_assert0(status != 0 || (avctx->extradata && avctx->extradata_size > 0)); @@ -2714,23 +2753,8 @@ static av_cold int vtenc_close(AVCodecContext *avctx) clear_frame_queue(vtctx); pthread_cond_destroy(&vtctx->cv_sample_sent); pthread_mutex_destroy(&vtctx->lock); - CFRelease(vtctx->session); - vtctx->session = NULL; - - if (vtctx->color_primaries) { - CFRelease(vtctx->color_primaries); - vtctx->color_primaries = NULL; - } - if (vtctx->transfer_function) { - CFRelease(vtctx->transfer_function); - vtctx->transfer_function = NULL; - } - - if (vtctx->ycbcr_matrix) { - CFRelease(vtctx->ycbcr_matrix); - vtctx->ycbcr_matrix = NULL; - } + vtenc_reset(vtctx); return 0; }