]> granicus.if.org Git - handbrake/commitdiff
libhb: Add a hb_global_init_no_hardware that disables all the hardware encoder/decode...
authorsr55 <sr55.hb@outlook.com>
Sat, 9 Feb 2019 18:12:44 +0000 (18:12 +0000)
committersr55 <sr55.hb@outlook.com>
Mon, 11 Feb 2019 16:16:05 +0000 (16:16 +0000)
libhb/common.c
libhb/common.h
libhb/hb.c
libhb/hb.h
libhb/nvenc_common.c
libhb/qsv_common.c
libhb/vce_common.c

index 525bf3ae4d857aac1724005eb346e2d3b8acd947..d1a78f6ee2bb9800a4f7f227ea36c41782c06051 100644 (file)
@@ -270,44 +270,52 @@ hb_encoder_internal_t hb_video_encoders[]  =
     { { "Theora",              "theora",     "Theora (libtheora)",      HB_VCODEC_THEORA,                            HB_MUX_MASK_MKV, }, NULL, 1, HB_GID_VCODEC_THEORA, },
 };
 int hb_video_encoders_count = sizeof(hb_video_encoders) / sizeof(hb_video_encoders[0]);
-static int hb_video_encoder_is_enabled(int encoder)
+static int hb_video_encoder_is_enabled(int encoder, int disable_hardware)
 {
-#ifdef USE_QSV
-    if (encoder & HB_VCODEC_QSV_MASK)
+    // Hardware Encoders
+    if (!disable_hardware)
     {
-        return hb_qsv_video_encoder_is_enabled(encoder);
-    }
+#ifdef USE_QSV
+        if (encoder & HB_VCODEC_QSV_MASK)
+        {
+            return hb_qsv_video_encoder_is_enabled(encoder);
+        }
 #endif
-    switch (encoder)
-    {
-        // the following encoders are always enabled
-        case HB_VCODEC_THEORA:
-        case HB_VCODEC_FFMPEG_MPEG4:
-        case HB_VCODEC_FFMPEG_MPEG2:
-        case HB_VCODEC_FFMPEG_VP8:
-        case HB_VCODEC_FFMPEG_VP9:
-            return 1;
 
+        switch (encoder){
 #ifdef USE_VCE
-        case HB_VCODEC_FFMPEG_VCE_H264:
-                       return hb_vce_h264_available();
-        case HB_VCODEC_FFMPEG_VCE_H265:
-            return hb_vce_h265_available();
+            case HB_VCODEC_FFMPEG_VCE_H264:
+               return hb_vce_h264_available();
+            case HB_VCODEC_FFMPEG_VCE_H265:
+                return hb_vce_h265_available();
 #endif
 
 #ifdef USE_NVENC
-        case HB_VCODEC_FFMPEG_NVENC_H264:
-            return hb_nvenc_h264_available();
-        case HB_VCODEC_FFMPEG_NVENC_H265:
-            return hb_nvenc_h265_available();
+            case HB_VCODEC_FFMPEG_NVENC_H264:
+                return hb_nvenc_h264_available();
+            case HB_VCODEC_FFMPEG_NVENC_H265:
+                return hb_nvenc_h265_available();
 #endif
 
 #ifdef __APPLE__
-        case HB_VCODEC_FFMPEG_VT_H264:
-            return hb_vt_h264_is_available();
-        case HB_VCODEC_FFMPEG_VT_H265:
-            return hb_vt_h265_is_available();
+            case HB_VCODEC_FFMPEG_VT_H264:
+                return hb_vt_h264_is_available();
+            case HB_VCODEC_FFMPEG_VT_H265:
+                return hb_vt_h265_is_available();
 #endif
+        }
+    }
+
+    // Software Encoders
+    switch (encoder)
+    {
+        // the following encoders are always enabled
+        case HB_VCODEC_THEORA:
+        case HB_VCODEC_FFMPEG_MPEG4:
+        case HB_VCODEC_FFMPEG_MPEG2:
+        case HB_VCODEC_FFMPEG_VP8:
+        case HB_VCODEC_FFMPEG_VP9:
+            return 1;
 
 #ifdef USE_X265
         case HB_VCODEC_X265_8BIT:
@@ -458,7 +466,7 @@ static int hb_container_is_enabled(int format)
     }
 }
 
-void hb_common_global_init()
+void hb_common_global_init(int disable_hardware)
 {
     static int common_init_done = 0;
     if (common_init_done)
@@ -568,7 +576,7 @@ void hb_common_global_init()
         {
             // we still need to check
             hb_video_encoders[i].enabled =
-                hb_video_encoder_is_enabled(hb_video_encoders[i].item.codec);
+                hb_video_encoder_is_enabled(hb_video_encoders[i].item.codec, disable_hardware);
         }
         if (hb_video_encoders[i].enabled)
         {
@@ -590,7 +598,7 @@ void hb_common_global_init()
         if (!hb_video_encoders[i].enabled)
         {
             if ((hb_video_encoders[i].item.codec & HB_VCODEC_MASK) &&
-                (hb_video_encoder_is_enabled(hb_video_encoders[i].item.codec)))
+                (hb_video_encoder_is_enabled(hb_video_encoders[i].item.codec, disable_hardware)))
             {
                 // we have a specific fallback and it's enabled
                 continue;
index cfdaced173810860aac738dd191f2ac5e61356d8..e4fa881b9da54b72f0be7eba7931cf6bb3867126 100644 (file)
@@ -331,7 +331,7 @@ struct hb_subtitle_config_s
  *
  */
 
-void hb_common_global_init(void);
+void hb_common_global_init(int);
 
 int              hb_video_framerate_get_from_name(const char *name);
 const char*      hb_video_framerate_get_name(int framerate);
index 3be050a9a727ccbb6827d1e32e0f090c5329d167..ca08baa88682a4014a37241ebad6da62ff755365 100644 (file)
@@ -68,6 +68,7 @@ struct hb_handle_s
 
 hb_work_object_t * hb_objects = NULL;
 int hb_instance_counter = 0;
+int disable_hardware = 0;
 
 static void thread_func( void * );
 
@@ -411,8 +412,11 @@ void hb_scan( hb_handle_t * h, const char * path, int title_index,
     hb_log(" - logical processor count: %d", hb_get_cpu_count());
 
 #ifdef USE_QSV
-    /* Print QSV info here so that it's in all scan and encode logs */
-    hb_qsv_info_print();
+    if (!is_hardware_disabled())
+    {
+        /* Print QSV info here so that it's in all scan and encode logs */
+        hb_qsv_info_print();
+    }
 #endif
 
     hb_log( "hb_scan: path=%s, title_index=%d", path, title_index );
@@ -1635,6 +1639,12 @@ void hb_close( hb_handle_t ** _h )
     *_h = NULL;
 }
 
+int hb_global_init_no_hardware()
+{
+    disable_hardware = 1;
+    hb_global_init();
+}
+
 int hb_global_init()
 {
     int result = 0;
@@ -1647,13 +1657,16 @@ int hb_global_init()
     }
 
 #ifdef USE_QSV
-    result = hb_qsv_info_init();
-    if (result < 0)
+    if (!disable_hardware) 
     {
-        hb_error("hb_qsv_info_init failed!");
-        return -1;
+        result = hb_qsv_info_init();
+        if (result < 0)
+        {
+            hb_error("hb_qsv_info_init failed!");
+            return -1;
+        }
+        hb_param_configure_qsv();
     }
-    hb_param_configure_qsv();
 #endif
 
     /* libavcodec */
@@ -1689,11 +1702,14 @@ int hb_global_init()
     hb_register(&hb_encx265);
 #endif
 #ifdef USE_QSV
-    hb_register(&hb_encqsv);
+    if (!disable_hardware) 
+    {
+        hb_register(&hb_encqsv);
+    }
 #endif
 
     hb_x264_global_init();
-    hb_common_global_init();
+    hb_common_global_init(disable_hardware);
 
     /*
      * Initialise buffer pool
@@ -1907,3 +1923,7 @@ hb_interjob_t * hb_interjob_get( hb_handle_t * h )
 {
     return h->interjob;
 }
+
+int is_hardware_disabled(void){
+    return disable_hardware;
+}
index aa9a039a6a0c403a3b2db52ecc6f6c077d35f3d6..c003c2a9c2433608c5d62957f480dbf910de4da8 100644 (file)
@@ -134,6 +134,7 @@ void          hb_close( hb_handle_t ** );
 /* hb_global_init()
    Performs process initialization. */
 int           hb_global_init(void);
+int           hb_global_init_no_hardware();
 /* hb_global_close()
    Performs final cleanup for the process. */
 void          hb_global_close(void);
@@ -142,6 +143,8 @@ void          hb_global_close(void);
    Return the unique instance id of an libhb instance created by hb_init. */
 int hb_get_instance_id( hb_handle_t * h );
 
+int is_hardware_disabled(void);
+
 #ifdef __cplusplus
 }
 #endif
index c3c7508e06dd496608b875a2830f1c1afc87b819..f1b7f42804d9a09e67e0d78b01309d9a0be4fc96 100644 (file)
@@ -8,6 +8,7 @@
  */
 
 #include "hbffmpeg.h"
+#include "hb.h"
 
 #ifdef USE_NVENC
 #include <ffnvcodec/nvEncodeAPI.h>
@@ -36,6 +37,11 @@ int hb_nvenc_h265_available()
 
 int hb_check_nvenc_available() 
 {
+    if (is_hardware_disabled())
+    {
+        return 0;
+    } 
+    
     #ifdef USE_NVENC
         uint32_t nvenc_ver;
         void *context;
index 64c99ba0a65f7dfe8b3aafcb5607f37e17b92788..7376be4b9c04854da28839d5034399c79f595689 100644 (file)
@@ -147,6 +147,11 @@ static int qsv_implementation_is_hardware(mfxIMPL implementation)
 
 int hb_qsv_available()
 {
+    if (is_hardware_disabled())
+    {
+        return 0;
+    } 
+    
     return ((hb_qsv_video_encoder_is_enabled(HB_VCODEC_QSV_H264) ? HB_VCODEC_QSV_H264 : 0) |
             (hb_qsv_video_encoder_is_enabled(HB_VCODEC_QSV_H265) ? HB_VCODEC_QSV_H265 : 0) |
             (hb_qsv_video_encoder_is_enabled(HB_VCODEC_QSV_H265_10BIT) ? HB_VCODEC_QSV_H265_10BIT : 0));
index e5293705b2f3e675ad6f43adcc06c795ff701589..ab545eab00262178411262f28ded372e60cc5202 100644 (file)
@@ -98,11 +98,21 @@ clean:
 
 int hb_vce_h264_available()
 {
+    if (is_hardware_disabled())
+    {
+        return 0;
+    } 
+    
     return (check_component_available(AMFVideoEncoderVCE_AVC) == AMF_OK) ? 1 : 0;
 }
 
 int hb_vce_h265_available()
 {
+    if (is_hardware_disabled())
+    {
+        return 0;
+    } 
+    
     return (check_component_available(AMFVideoEncoder_HEVC) == AMF_OK) ? 1 : 0;
 }