]> granicus.if.org Git - handbrake/commitdiff
libhb: re-work OpenCL cleanup a bit.
authorRodeo <tdskywalker@gmail.com>
Tue, 23 Jun 2015 22:35:29 +0000 (22:35 +0000)
committerRodeo <tdskywalker@gmail.com>
Tue, 23 Jun 2015 22:35:29 +0000 (22:35 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7313 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/hb.c
libhb/work.c

index 33fe4200753a426a224e882e1c3ff2907c5a2074..513c27e622a20e848e37640387869365443a841b 100644 (file)
@@ -1635,6 +1635,9 @@ void hb_global_close()
     
     hb_presets_free();
 
+    /* OpenCL library (dynamically loaded) */
+    hb_ocl_close();
+
     /* Find and remove temp folder */
     memset( dirname, 0, 1024 );
     hb_get_temporary_directory( dirname );
index 3d158862b34892b48c9c67894e9d3c28b7ecc5e8..a31333d868a8be97f2f260823f8074446f76f317 100644 (file)
@@ -614,12 +614,23 @@ static void do_job(hb_job_t *job)
 
     job->list_work = hb_list_init();
 
-    /* OpenCL */
+    /*
+     * OpenCL
+     *
+     * Note: we delay hb_ocl_init until here, since they're no point it loading
+     * the library if we aren't going to use it. But we only call hb_ocl_close
+     * in hb_global_close, since un/reloading the library each run is wasteful.
+     */
     if (job->use_opencl && (hb_ocl_init() || hb_init_opencl_run_env(0, NULL, "-I.")))
     {
         hb_log("work: failed to initialize OpenCL environment, using fallback");
+        hb_release_opencl_run_env();
         job->use_opencl = 0;
-        hb_ocl_close();
+    }
+    else
+    {
+        // we're not (re-)using OpenCL here, we can release the environment
+        hb_release_opencl_run_env();
     }
 
     hb_log( "starting job" );
@@ -1730,12 +1741,6 @@ cleanup:
     }
 
     hb_buffer_pool_free();
-          
-    /* OpenCL: must be closed *after* freeing the buffer pool */
-    if (job->use_opencl)
-    {
-        hb_ocl_close();
-    }
     
     hb_job_close( &job );
 }