changeset 1368:d163b04c3ec4

Set abandoned flag when bailing out of run() because init failed at the start; then check that flag in awaitOutputModels() so as not to get stuck on a wait condition
author Chris Cannam
date Wed, 18 Jan 2017 14:21:39 +0000
parents 1b888a85983b
children 7fb7b59c35ee
files transform/FeatureExtractionModelTransformer.cpp
diffstat 1 files changed, 28 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/transform/FeatureExtractionModelTransformer.cpp	Wed Jan 18 14:20:05 2017 +0000
+++ b/transform/FeatureExtractionModelTransformer.cpp	Wed Jan 18 14:21:39 2017 +0000
@@ -85,6 +85,7 @@
     for (int j = 1; j < (int)m_transforms.size(); ++j) {
         if (!areTransformsSimilar(m_transforms[0], m_transforms[j])) {
             m_message = tr("Transforms supplied to a single FeatureExtractionModelTransformer instance must be similar in every respect except plugin output");
+            SVCERR << m_message << endl;
             return false;
         }
     }
@@ -98,12 +99,14 @@
 
     if (!factory) {
         m_message = tr("No factory available for feature extraction plugin id \"%1\" (unknown plugin type, or internal error?)").arg(pluginId);
+        SVCERR << m_message << endl;
 	return false;
     }
 
     DenseTimeValueModel *input = getConformingInput();
     if (!input) {
         m_message = tr("Input model for feature extraction plugin \"%1\" is of wrong type (internal error?)").arg(pluginId);
+        SVCERR << m_message << endl;
         return false;
     }
 
@@ -113,15 +116,16 @@
     m_plugin = factory->instantiatePlugin(pluginId, input->getSampleRate());
     if (!m_plugin) {
         m_message = tr("Failed to instantiate plugin \"%1\"").arg(pluginId);
+        SVCERR << m_message << endl;
 	return false;
     }
 
     TransformFactory::getInstance()->makeContextConsistentWithPlugin
         (primaryTransform, m_plugin);
-
+    
     TransformFactory::getInstance()->setPluginParameters
         (primaryTransform, m_plugin);
-
+    
     int channelCount = input->getChannelCount();
     if ((int)m_plugin->getMaxChannelCount() < channelCount) {
 	channelCount = 1;
@@ -132,9 +136,10 @@
             .arg(m_plugin->getMinChannelCount())
             .arg(m_plugin->getMaxChannelCount())
             .arg(input->getChannelCount());
+        SVCERR << m_message << endl;
 	return false;
     }
-
+    
     SVDEBUG << "Initialising feature extraction plugin with channels = "
             << channelCount << ", step = " << primaryTransform.getStepSize()
             << ", block = " << primaryTransform.getBlockSize() << endl;
@@ -166,6 +171,7 @@
                 SVDEBUG << "Initialisation failed again" << endl;
                 
                 m_message = tr("Failed to initialise feature extraction plugin \"%1\"").arg(pluginId);
+                SVCERR << m_message << endl;
                 return false;
 
             } else {
@@ -178,6 +184,7 @@
                     .arg(pblock)
                     .arg(primaryTransform.getStepSize())
                     .arg(primaryTransform.getBlockSize());
+                SVCERR << m_message << endl;
             }
 
         } else {
@@ -185,6 +192,7 @@
             SVDEBUG << "Initialisation failed" << endl;
                 
             m_message = tr("Failed to initialise feature extraction plugin \"%1\"").arg(pluginId);
+            SVCERR << m_message << endl;
             return false;
         }
     } else {
@@ -203,6 +211,7 @@
             } else {
                 m_message = vm;
             }
+            SVCERR << m_message << endl;
         }
     }
 
@@ -210,6 +219,7 @@
 
     if (outputs.empty()) {
         m_message = tr("Plugin \"%1\" has no outputs").arg(pluginId);
+        SVCERR << m_message << endl;
 	return false;
     }
 
@@ -230,6 +240,7 @@
             m_message = tr("Plugin \"%1\" has no output named \"%2\"")
                 .arg(pluginId)
                 .arg(m_transforms[j].getOutput());
+            SVCERR << m_message << endl;
             return false;
         }
     }
@@ -522,8 +533,8 @@
 FeatureExtractionModelTransformer::awaitOutputModels()
 {
     m_outputMutex.lock();
-    while (!m_haveOutputs) {
-        m_outputsCondition.wait(&m_outputMutex);
+    while (!m_haveOutputs && !m_abandoned) {
+        m_outputsCondition.wait(&m_outputMutex, 500);
     }
     m_outputMutex.unlock();
 }
@@ -613,12 +624,21 @@
 void
 FeatureExtractionModelTransformer::run()
 {
-    initialise();
+    if (initialise()) {
+        abandon();
+        return;
+    }
     
     DenseTimeValueModel *input = getConformingInput();
-    if (!input) return;
+    if (!input) {
+        abandon();
+        return;
+    }
 
-    if (m_outputs.empty()) return;
+    if (m_outputs.empty()) {
+        abandon();
+        return;
+    }
 
     Transform primaryTransform = m_transforms[0];