From patchwork Fri Sep 8 04:39:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Zhao X-Patchwork-Id: 43652 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4e27:b0:149:dfde:5c0a with SMTP id gk39csp248863pzb; Thu, 7 Sep 2023 21:40:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEUijxCP5r872K2ZR4s/cyx9q3zWCf+BAsGgvukOcHEbeOIzhR/VhgR6jw3mMwqYa8wL1Pi X-Received: by 2002:a17:907:1dcb:b0:99d:dd43:d427 with SMTP id og11-20020a1709071dcb00b0099ddd43d427mr900002ejc.10.1694148009607; Thu, 07 Sep 2023 21:40:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694148009; cv=none; d=google.com; s=arc-20160816; b=IRh1TuV/UVErTE361tSaATR8KFVUAGeqvq/fgFwv2vG6bTSnfPHGKqIS2NOzA68W91 rYQDSabe7O+x1br1GWCHH9wg7sJPHN2prcXzaMyTpF35Ue5GKf4ezuym0CNGgVBK5Lgr fWhFZRKiNnMQu5VsSFOCEky4eLJwe7VTl4XBJWZixCGSAV3xxHyog6D/npd2KC/Cgm3z KLkrtBfcYWotcwvN2YvJf5RFNtUoPpmltYULh54g+LNdJx+qQOu9sknCPgKjFZGHa7Ar JF4V28strcaHLjt8qR7OR65EP+M7wSUE44RezUwYLxIqIBTjl9fysJ8oknfAZ8mY5eZs 5U9Q== 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=9Rq6LN8VveSDwPFPsCX8uZTuVNR8cVPalAsjOz17PNk=; fh=paNsSD/gLXCX8XaG2wP2EhSbyn4+hY3DzFJxc2Arm+k=; b=hRBmxDYbMRt7G/sj40ITdNKkude6MzNrRX9gLaN08u7ADHTteZzgVASQFnjmtcm2Mx F2/tybP4Eo/G+eA00d2cLUsEsQxpV6iyVIlzqheesalMrCDttansZdgYP5ghbqGqEAN9 LFIWm91jSF0+6c40o4/Lnvb/7UIi7gL7QjGY91A0pQ1c+kvjhRIbC6hGsCX7PE79I03O 1MuPnXOlOcy9cHi3q6RyaVh+GthjokEf/YAHGNHyElcZ+pUdiesEY9Z0syBvv4x15eAZ 3hq2kf5ONKnwjD+h15FrQwxDoOMJG0tz7oTB55+ulIf7RwYwXwaEvtY3uzT7g8M/GgL6 sLAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=e9m17ChB; 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 gj20-20020a170906e11400b0099ba1cf9543si663372ejb.460.2023.09.07.21.40.08; Thu, 07 Sep 2023 21:40:09 -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=e9m17ChB; 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 DBD7568C7FE; Fri, 8 Sep 2023 07:39:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0393A68C688 for ; Fri, 8 Sep 2023 07:39:48 +0300 (EEST) Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-402c46c49f4so17635975e9.1 for ; Thu, 07 Sep 2023 21:39:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694147987; x=1694752787; 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=M7ObVaB/2XtsYMav6JWohzRgBgoEjPuHrj923NKQ+k0=; b=e9m17ChBNx8dDLrycu3qA+fKaMBQKaaQrN6eMEXpGID0xyKd511mJMo/vJeKmMrS65 XA/k7OmM6ie0K8HXi4xshlt3RT+KKWYMXxM+vPGvRYhUX2pbxbVm8U+5F+IAIRsFJAGZ jxmJXdxyKI253eMeTuzACKL/FiSE50P3SHYDD4v4EoyIadXi5Z/DVmzlGujW4PNTpOt+ aD+f86uci3nFatQGhqZKT5+cEQ8PhzCw05oaPAMLO8jHcCKmOzpExacBOAokVzWuQmrV nTR2poXJiiJ9LL5aQ4s1WOCjoqvxzLAopZNM8JhE2M9JVT4I/ZkbdPoL4ujiFqp7x2ly kWGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694147987; x=1694752787; 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=M7ObVaB/2XtsYMav6JWohzRgBgoEjPuHrj923NKQ+k0=; b=gbAoqG87DsQG4DsPCvsnIQzL+59PR/Z3utiNBBZypxax0exULSChb5ws2NH6Z+09k2 g190HDytdAeT3+YePTJ8siCmZNtznbEFiFt5axcQwaKWmVFdmyDGvPyJLi+p4vflr28R aAMgw5R1gyPAQTRmBIdubCks6DujULkeGK07OS9jVT1Zfkz+z5ZStbRZaHVKS34L/+AU 4SkyUEw6qel1HbIycCwczNPHp+9LbNcWLi7hZ//iIspstNRHB6J+aOEWTcbxXSzpD8gT d9CeclpQLkqFUqq8Y2CmO9p4RuyCSvDiubEa/kcqbCcjnFZRfC/1Fh9daxUiwXr6of4l q4cQ== X-Gm-Message-State: AOJu0YyQ1gGW8lfXM8QCPwX/7ic7DURz/oWBv7/fz5oHUIfN+YoQoqu8 RFihge75DjSZ9jM5n7966Lb390wTS1l3a+NG X-Received: by 2002:a05:600c:204c:b0:401:23fc:1f92 with SMTP id p12-20020a05600c204c00b0040123fc1f92mr1102749wmg.25.1694147987114; Thu, 07 Sep 2023 21:39:47 -0700 (PDT) Received: from localhost.localdomain ([49.51.162.193]) by smtp.gmail.com with ESMTPSA id w3-20020a05600c014300b003fefe70ec9csm4120242wmm.10.2023.09.07.21.39.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 21:39:46 -0700 (PDT) From: Jun Zhao To: ffmpeg-devel@ffmpeg.org Date: Fri, 8 Sep 2023 12:39:43 +0800 Message-Id: <20230908043943.3230926-2-mypopydev@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230908043943.3230926-1-mypopydev@gmail.com> References: <20230908043943.3230926-1-mypopydev@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 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: 0EPbI6tPQB+P Get the encoder supported properties list, it will be used for feature support checks. Signed-off-by: Jun Zhao --- libavcodec/videotoolboxenc.c | 72 ++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 23 deletions(-) diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c index 2e96990741..1d1595329a 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,22 @@ static int vtenc_create_encoder(AVCodecContext *avctx, return AVERROR_EXTERNAL; } +#if defined (MAC_OS_X_VERSION_10_13) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_13) + if (__builtin_available(macOS 10.13, *)) { + 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; + } + } +#endif + // Dump the init encoder { CFStringRef encoderID = NULL; @@ -1662,7 +1707,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 +2475,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 +2732,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 +2755,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; }