diff transform/ModelTransformerFactory.cpp @ 1832:7c92c644db20

Merge from branch audio-source-refactor. Various changes to memory management for plugins, ring buffers etc, for safer code further up the stack
author Chris Cannam
date Fri, 03 Apr 2020 12:12:02 +0100
parents 5f8fbbde08ff
children
line wrap: on
line diff
--- a/transform/ModelTransformerFactory.cpp	Fri Mar 27 10:06:03 2020 +0000
+++ b/transform/ModelTransformerFactory.cpp	Fri Apr 03 12:12:02 2020 +0100
@@ -40,6 +40,8 @@
 using std::vector;
 using std::set;
 using std::map;
+using std::shared_ptr;
+using std::make_shared;
 
 ModelTransformerFactory *
 ModelTransformerFactory::m_instance = new ModelTransformerFactory;
@@ -110,7 +112,7 @@
 
     SVDEBUG << "ModelTransformer: last configuration for identifier " << transform.getIdentifier() << ": " << configurationXml << endl;
 
-    Vamp::PluginBase *plugin = nullptr;
+    shared_ptr<Vamp::PluginBase> plugin;
 
     if (RealTimePluginFactory::instanceFor(id)) {
 
@@ -127,20 +129,16 @@
             channels = source->getTargetChannelCount();
         }
 
-        RealTimePluginInstance *rtp = factory->instantiatePlugin
+        plugin = factory->instantiatePlugin
             (id, 0, 0, sampleRate, blockSize, channels);
 
-        plugin = rtp;
-
     } else {
 
         SVDEBUG << "ModelTransformerFactory::getConfigurationForTransform: instantiating Vamp plugin" << endl;
 
-        Vamp::Plugin *vp =
+        plugin =
             FeatureExtractionPluginFactory::instance()->instantiatePlugin
             (id, float(defaultSampleRate));
-
-        plugin = vp;
     }
 
     if (plugin) {
@@ -172,10 +170,6 @@
             makeContextConsistentWithPlugin(transform, plugin);
 
         configurationXml = PluginXml(plugin).toXmlString();
-
-        SVDEBUG << "ModelTransformerFactory::getConfigurationForTransform: got configuration, deleting plugin" << endl;
-        
-        delete plugin;
     }
 
     if (ok) {