]> granicus.if.org Git - handbrake/commitdiff
Amf enc availability check (#1489)
authorOvchinnikovDmitrii <ovchinnikov.dmitrii@gmail.com>
Sat, 21 Jul 2018 17:08:34 +0000 (20:08 +0300)
committerScott <628593+sr55@users.noreply.github.com>
Sat, 21 Jul 2018 17:08:34 +0000 (18:08 +0100)
* AMF encoder availability check. #1408

libhb/vce_common.c

index 98b76d8c5f6bc7a94c5f0a0ba83ec430e9192e65..9965df339f8e7b7c3d73f2ce2edeefc600b4949d 100644 (file)
@@ -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