From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 655924746B for ; Fri, 8 Sep 2023 04:40:06 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A815368C7F7; Fri, 8 Sep 2023 07:39:54 +0300 (EEST) 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-Google-Smtp-Source: AGHT+IHId8yhVeJLMns6NoriKiqXgroUk6u2QY3iciwjjwk89gaaCubbjFjhK8gzAoRwjtmfauFnUw== 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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; } -- 2.25.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".