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 CBF3646356 for ; Mon, 13 Nov 2023 14:41:44 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DDB5B68CCE4; Mon, 13 Nov 2023 16:41:41 +0200 (EET) Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 799D068CC41 for ; Mon, 13 Nov 2023 16:41:35 +0200 (EET) Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-9d0b4dfd60dso684862966b.1 for ; Mon, 13 Nov 2023 06:41:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699886494; x=1700491294; 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=V/6ZC4095v69QvQIgz7IrCFOm8mLXrKO4dQIrt9ZcVE=; b=cGq0FT4PV762weEdLkuXQUqF08ACCRgXgxt9ckrFP/Cq6pY8lMJV7gOn9E2CtvJ3A3 3u/LTHX0dLuZVwKwAcv75GWeKIgFj8s+3VKicNp7NBGdqrcV1APzk0I0ipw/L6Uh/g+9 LLE3ZzHSh1mF9VwU/xIG6KpCTl2c90n5b/ndxDBOHxVqrANh9MA47SIqjbNGaCOAMgNg JpRY+V4zcm6rBmNsSMvl0IP3e12AJFQIVhQ7xkroJ9BHORKPd0LNA1P5KigyBU8utROz kTSUWbbs8hrQ4BwK4jI3tOrV9ccKe0ql26j9O8LoUVEBvTaWZsAJ8C1w9O8gL83VFopH T8zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699886494; x=1700491294; 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=V/6ZC4095v69QvQIgz7IrCFOm8mLXrKO4dQIrt9ZcVE=; b=uXPVvnRb+zWasQx6gPr5RX+vELHTnmS55TYH1iyFy8LJBX7jaXoj7B76/LIHgBBqiY GsHV5+yzZVvqJtIhcyVOv9YQ6lhmduWBxsoF6WG954mvoLUKF5PlmITfHhN31uAG2QiC h52SwAslAuv30HPzlQQ+lbYGfn+aD+zMgM2lRQ6RPhY90+vNRJc2GSlMEskqAaT2j2XU 2Z7kPQ+h8twYdrtR9tntEwzPrnXRg09N+a3wjgq8D7W0O0bIx2rcp40Ts9C/hnFT7YI0 stNA1Bkm/Yz+h1lg+X7DFitpRJM3WKQg58reY5PHPla27LQHM37QSYbitT/a69BpwxTH 4dZg== X-Gm-Message-State: AOJu0YzD3feutl/gzYC50FIOoEXDa2MDs9dtkw+z4371Wl2E1d78374t s2oqSTpLSEwAj/RRNBiRsFW4qDPsJ94= X-Google-Smtp-Source: AGHT+IHUs1QQ77jlug+4DdijmSDqEdn8QQNO3Xqw/LiieO/K3klzGG4bM9SqJYM6w5B1IUd43GdRWQ== X-Received: by 2002:a17:906:1395:b0:9be:ab38:a362 with SMTP id f21-20020a170906139500b009beab38a362mr4888586ejc.46.1699886494134; Mon, 13 Nov 2023 06:41:34 -0800 (PST) Received: from MSDN-EVPAVLOV.amd.com (178-223-50-56.dynamic.isp.telekom.rs. [178.223.50.56]) by smtp.gmail.com with ESMTPSA id a26-20020a17090640da00b009e651700b92sm4110985ejk.124.2023.11.13.06.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 06:41:33 -0800 (PST) From: Evgeny Pavlov To: ffmpeg-devel@ffmpeg.org Date: Mon, 13 Nov 2023 15:37:02 +0100 Message-ID: <20231113143722.1959-1-lucenticus@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231016091402.7972-1-lucenticus@gmail.com> References: <20231016091402.7972-1-lucenticus@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] avcodec/amfenc: increase precision of Sleep() on Windows 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: Evgeny Pavlov 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: This commit increase precision of Sleep() function on Windows. This fix reduces the sleep time on Windows to improve AMF encoding performance on low resolution input videos. Fix for issue #10622 v2: use timeBeginPeriod/timeEndPeriod for increasing precision of Sleep() Signed-off-by: Evgeny Pavlov --- libavcodec/amfenc.c | 31 +++++++++++++++++++++++++++++++ libavcodec/amfenc.h | 3 +++ 2 files changed, 34 insertions(+) diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c index 061859f85c..55e24856e8 100644 --- a/libavcodec/amfenc.c +++ b/libavcodec/amfenc.c @@ -42,7 +42,12 @@ #endif #ifdef _WIN32 +#include #include "compat/w32dlfcn.h" + +typedef MMRESULT (*timeapi_fun)(UINT uPeriod); +#define WINMM_DLL "winmm.dll" + #else #include #endif @@ -113,6 +118,9 @@ static int amf_load_library(AVCodecContext *avctx) AMFInit_Fn init_fun; AMFQueryVersion_Fn version_fun; AMF_RESULT res; +#ifdef _WIN32 + timeapi_fun time_begin_fun; +#endif ctx->delayed_frame = av_frame_alloc(); if (!ctx->delayed_frame) { @@ -145,6 +153,16 @@ static int amf_load_library(AVCodecContext *avctx) AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetTrace() failed with error %d\n", res); res = ctx->factory->pVtbl->GetDebug(ctx->factory, &ctx->debug); AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetDebug() failed with error %d\n", res); + +#ifdef _WIN32 + // Increase precision of Sleep() function on Windows platform + ctx->winmm_lib = dlopen(WINMM_DLL, RTLD_NOW | RTLD_LOCAL); + AMF_RETURN_IF_FALSE(ctx, ctx->winmm_lib != NULL, 0, "DLL %s failed to open\n", WINMM_DLL); + time_begin_fun = (timeapi_fun)dlsym(ctx->winmm_lib, "timeBeginPeriod"); + AMF_RETURN_IF_FALSE(ctx, time_begin_fun != NULL, 0, "DLL %s failed to find function %s\n", WINMM_DLL, "timeBeginPeriod"); + time_begin_fun(1); +#endif //_WIN32 + return 0; } @@ -375,6 +393,9 @@ static int amf_init_encoder(AVCodecContext *avctx) int av_cold ff_amf_encode_close(AVCodecContext *avctx) { AmfContext *ctx = avctx->priv_data; +#ifdef _WIN32 + timeapi_fun time_end_fun; +#endif //_WIN32 if (ctx->delayed_surface) { ctx->delayed_surface->pVtbl->Release(ctx->delayed_surface); @@ -410,6 +431,16 @@ int av_cold ff_amf_encode_close(AVCodecContext *avctx) av_frame_free(&ctx->delayed_frame); av_fifo_freep2(&ctx->timestamp_list); +#ifdef _WIN32 + if (ctx->winmm_lib) { + time_end_fun = (timeapi_fun)dlsym(ctx->winmm_lib, "timeEndPeriod"); + AMF_RETURN_IF_FALSE(ctx, time_end_fun != NULL, 0, "DLL %s failed to find function %s\n", WINMM_DLL, "timeEndPeriod"); + time_end_fun(1); + dlclose(ctx->winmm_lib); + ctx->winmm_lib = NULL; + } +#endif //_WIN32 + return 0; } diff --git a/libavcodec/amfenc.h b/libavcodec/amfenc.h index 2dbd378ef8..35bcf1dfe3 100644 --- a/libavcodec/amfenc.h +++ b/libavcodec/amfenc.h @@ -50,6 +50,9 @@ typedef struct AmfContext { AVClass *avclass; // access to AMF runtime amf_handle library; ///< handle to DLL library +#ifdef _WIN32 + amf_handle winmm_lib; ///< handle to winmm DLL library +#endif //_WIN32 AMFFactory *factory; ///< pointer to AMF factory AMFDebug *debug; ///< pointer to AMF debug interface AMFTrace *trace; ///< pointer to AMF trace interface -- 2.42.0 _______________________________________________ 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".