From: OvchinnikovDmitrii Date: Sat, 21 Jul 2018 17:08:34 +0000 (+0300) Subject: Amf enc availability check (#1489) X-Git-Tag: 1.2.0~226 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5c242c2b7713480943afb0ee4c004aefd8b74a36;p=handbrake Amf enc availability check (#1489) * AMF encoder availability check. #1408 --- diff --git a/libhb/vce_common.c b/libhb/vce_common.c index 98b76d8c5..9965df339 100644 --- a/libhb/vce_common.c +++ b/libhb/vce_common.c @@ -8,15 +8,97 @@ */ #ifdef USE_VCE +#include "AMF/core/Factory.h" +#include "AMF/components/VideoDecoderUVD.h" +#include "hb.h" + +AMF_RESULT check_component_available(const wchar_t *componentID) +{ + amf_handle library = NULL; + AMFInit_Fn init_fun; + AMFFactory *factory = NULL; + AMFContext *context = NULL; + AMFComponent *encoder = NULL; + AMFCaps *encoderCaps = NULL; + AMF_RESULT result = AMF_FAIL; + + library = hb_dlopen(AMF_DLL_NAMEA); + if(!library) + { + result = AMF_FAIL; + goto clean; + } + + init_fun = (AMFInit_Fn)(hb_dlsym(library, AMF_INIT_FUNCTION_NAME)); + if(!init_fun) + { + result = AMF_FAIL; + goto clean; + } + + result = init_fun(AMF_FULL_VERSION, &factory); + if(result != AMF_OK) + { + goto clean; + } + + result = factory->pVtbl->CreateContext(factory, &context); + if(result != AMF_OK) + { + goto clean; + } + + result = context->pVtbl->InitDX11(context, NULL, AMF_DX11_1); + if (result != AMF_OK) { + result = context->pVtbl->InitDX9(context, NULL); + if (result != AMF_OK) { + goto clean; + } + } + + result = factory->pVtbl->CreateComponent(factory, context, componentID, &encoder); + if(result != AMF_OK) + { + goto clean; + } + + result = encoder->pVtbl->GetCaps(encoder, &encoderCaps); + +clean: + if (encoderCaps) + { + encoderCaps->pVtbl->Clear(encoderCaps); + encoderCaps->pVtbl->Release(encoderCaps); + encoderCaps = NULL; + } + if (encoder) + { + encoder->pVtbl->Terminate(encoder); + encoder->pVtbl->Release(encoder); + encoder = NULL; + } + if (context) + { + context->pVtbl->Terminate(context); + context->pVtbl->Release(context); + context = NULL; + } + if(library) + { + hb_dlclose(library); + } + + return result; +} int hb_vce_h264_available() { - return 1; + return (check_component_available(AMFVideoDecoderUVD_H264_AVC) == AMF_OK) ? 1 : 0; } int hb_vce_h265_available() { - return 1; + return (check_component_available(AMFVideoDecoderHW_H265_HEVC) == AMF_OK) ? 1 : 0; } #else