comparison transform/FeatureExtractionModelTransformer.cpp @ 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 a99641535e02
children 7fb7b59c35ee
comparison
equal deleted inserted replaced
1367:1b888a85983b 1368:d163b04c3ec4
83 // first check that they are actually similar as promised) 83 // first check that they are actually similar as promised)
84 84
85 for (int j = 1; j < (int)m_transforms.size(); ++j) { 85 for (int j = 1; j < (int)m_transforms.size(); ++j) {
86 if (!areTransformsSimilar(m_transforms[0], m_transforms[j])) { 86 if (!areTransformsSimilar(m_transforms[0], m_transforms[j])) {
87 m_message = tr("Transforms supplied to a single FeatureExtractionModelTransformer instance must be similar in every respect except plugin output"); 87 m_message = tr("Transforms supplied to a single FeatureExtractionModelTransformer instance must be similar in every respect except plugin output");
88 SVCERR << m_message << endl;
88 return false; 89 return false;
89 } 90 }
90 } 91 }
91 92
92 Transform primaryTransform = m_transforms[0]; 93 Transform primaryTransform = m_transforms[0];
96 FeatureExtractionPluginFactory *factory = 97 FeatureExtractionPluginFactory *factory =
97 FeatureExtractionPluginFactory::instance(); 98 FeatureExtractionPluginFactory::instance();
98 99
99 if (!factory) { 100 if (!factory) {
100 m_message = tr("No factory available for feature extraction plugin id \"%1\" (unknown plugin type, or internal error?)").arg(pluginId); 101 m_message = tr("No factory available for feature extraction plugin id \"%1\" (unknown plugin type, or internal error?)").arg(pluginId);
102 SVCERR << m_message << endl;
101 return false; 103 return false;
102 } 104 }
103 105
104 DenseTimeValueModel *input = getConformingInput(); 106 DenseTimeValueModel *input = getConformingInput();
105 if (!input) { 107 if (!input) {
106 m_message = tr("Input model for feature extraction plugin \"%1\" is of wrong type (internal error?)").arg(pluginId); 108 m_message = tr("Input model for feature extraction plugin \"%1\" is of wrong type (internal error?)").arg(pluginId);
109 SVCERR << m_message << endl;
107 return false; 110 return false;
108 } 111 }
109 112
110 SVDEBUG << "FeatureExtractionModelTransformer: Instantiating plugin for transform in thread " 113 SVDEBUG << "FeatureExtractionModelTransformer: Instantiating plugin for transform in thread "
111 << QThread::currentThreadId() << endl; 114 << QThread::currentThreadId() << endl;
112 115
113 m_plugin = factory->instantiatePlugin(pluginId, input->getSampleRate()); 116 m_plugin = factory->instantiatePlugin(pluginId, input->getSampleRate());
114 if (!m_plugin) { 117 if (!m_plugin) {
115 m_message = tr("Failed to instantiate plugin \"%1\"").arg(pluginId); 118 m_message = tr("Failed to instantiate plugin \"%1\"").arg(pluginId);
119 SVCERR << m_message << endl;
116 return false; 120 return false;
117 } 121 }
118 122
119 TransformFactory::getInstance()->makeContextConsistentWithPlugin 123 TransformFactory::getInstance()->makeContextConsistentWithPlugin
120 (primaryTransform, m_plugin); 124 (primaryTransform, m_plugin);
121 125
122 TransformFactory::getInstance()->setPluginParameters 126 TransformFactory::getInstance()->setPluginParameters
123 (primaryTransform, m_plugin); 127 (primaryTransform, m_plugin);
124 128
125 int channelCount = input->getChannelCount(); 129 int channelCount = input->getChannelCount();
126 if ((int)m_plugin->getMaxChannelCount() < channelCount) { 130 if ((int)m_plugin->getMaxChannelCount() < channelCount) {
127 channelCount = 1; 131 channelCount = 1;
128 } 132 }
129 if ((int)m_plugin->getMinChannelCount() > channelCount) { 133 if ((int)m_plugin->getMinChannelCount() > channelCount) {
130 m_message = tr("Cannot provide enough channels to feature extraction plugin \"%1\" (plugin min is %2, max %3; input model has %4)") 134 m_message = tr("Cannot provide enough channels to feature extraction plugin \"%1\" (plugin min is %2, max %3; input model has %4)")
131 .arg(pluginId) 135 .arg(pluginId)
132 .arg(m_plugin->getMinChannelCount()) 136 .arg(m_plugin->getMinChannelCount())
133 .arg(m_plugin->getMaxChannelCount()) 137 .arg(m_plugin->getMaxChannelCount())
134 .arg(input->getChannelCount()); 138 .arg(input->getChannelCount());
139 SVCERR << m_message << endl;
135 return false; 140 return false;
136 } 141 }
137 142
138 SVDEBUG << "Initialising feature extraction plugin with channels = " 143 SVDEBUG << "Initialising feature extraction plugin with channels = "
139 << channelCount << ", step = " << primaryTransform.getStepSize() 144 << channelCount << ", step = " << primaryTransform.getStepSize()
140 << ", block = " << primaryTransform.getBlockSize() << endl; 145 << ", block = " << primaryTransform.getBlockSize() << endl;
141 146
142 if (!m_plugin->initialise(channelCount, 147 if (!m_plugin->initialise(channelCount,
164 primaryTransform.getBlockSize())) { 169 primaryTransform.getBlockSize())) {
165 170
166 SVDEBUG << "Initialisation failed again" << endl; 171 SVDEBUG << "Initialisation failed again" << endl;
167 172
168 m_message = tr("Failed to initialise feature extraction plugin \"%1\"").arg(pluginId); 173 m_message = tr("Failed to initialise feature extraction plugin \"%1\"").arg(pluginId);
174 SVCERR << m_message << endl;
169 return false; 175 return false;
170 176
171 } else { 177 } else {
172 178
173 SVDEBUG << "Initialisation succeeded this time" << endl; 179 SVDEBUG << "Initialisation succeeded this time" << endl;
176 .arg(pluginId) 182 .arg(pluginId)
177 .arg(pstep) 183 .arg(pstep)
178 .arg(pblock) 184 .arg(pblock)
179 .arg(primaryTransform.getStepSize()) 185 .arg(primaryTransform.getStepSize())
180 .arg(primaryTransform.getBlockSize()); 186 .arg(primaryTransform.getBlockSize());
187 SVCERR << m_message << endl;
181 } 188 }
182 189
183 } else { 190 } else {
184 191
185 SVDEBUG << "Initialisation failed" << endl; 192 SVDEBUG << "Initialisation failed" << endl;
186 193
187 m_message = tr("Failed to initialise feature extraction plugin \"%1\"").arg(pluginId); 194 m_message = tr("Failed to initialise feature extraction plugin \"%1\"").arg(pluginId);
195 SVCERR << m_message << endl;
188 return false; 196 return false;
189 } 197 }
190 } else { 198 } else {
191 SVDEBUG << "Initialisation succeeded" << endl; 199 SVDEBUG << "Initialisation succeeded" << endl;
192 } 200 }
201 if (m_message != "") { 209 if (m_message != "") {
202 m_message = QString("%1; %2").arg(vm).arg(m_message); 210 m_message = QString("%1; %2").arg(vm).arg(m_message);
203 } else { 211 } else {
204 m_message = vm; 212 m_message = vm;
205 } 213 }
214 SVCERR << m_message << endl;
206 } 215 }
207 } 216 }
208 217
209 Vamp::Plugin::OutputList outputs = m_plugin->getOutputDescriptors(); 218 Vamp::Plugin::OutputList outputs = m_plugin->getOutputDescriptors();
210 219
211 if (outputs.empty()) { 220 if (outputs.empty()) {
212 m_message = tr("Plugin \"%1\" has no outputs").arg(pluginId); 221 m_message = tr("Plugin \"%1\" has no outputs").arg(pluginId);
222 SVCERR << m_message << endl;
213 return false; 223 return false;
214 } 224 }
215 225
216 for (int j = 0; j < (int)m_transforms.size(); ++j) { 226 for (int j = 0; j < (int)m_transforms.size(); ++j) {
217 227
228 238
229 if ((int)m_descriptors.size() <= j) { 239 if ((int)m_descriptors.size() <= j) {
230 m_message = tr("Plugin \"%1\" has no output named \"%2\"") 240 m_message = tr("Plugin \"%1\" has no output named \"%2\"")
231 .arg(pluginId) 241 .arg(pluginId)
232 .arg(m_transforms[j].getOutput()); 242 .arg(m_transforms[j].getOutput());
243 SVCERR << m_message << endl;
233 return false; 244 return false;
234 } 245 }
235 } 246 }
236 247
237 for (int j = 0; j < (int)m_transforms.size(); ++j) { 248 for (int j = 0; j < (int)m_transforms.size(); ++j) {
520 531
521 void 532 void
522 FeatureExtractionModelTransformer::awaitOutputModels() 533 FeatureExtractionModelTransformer::awaitOutputModels()
523 { 534 {
524 m_outputMutex.lock(); 535 m_outputMutex.lock();
525 while (!m_haveOutputs) { 536 while (!m_haveOutputs && !m_abandoned) {
526 m_outputsCondition.wait(&m_outputMutex); 537 m_outputsCondition.wait(&m_outputMutex, 500);
527 } 538 }
528 m_outputMutex.unlock(); 539 m_outputMutex.unlock();
529 } 540 }
530 541
531 FeatureExtractionModelTransformer::~FeatureExtractionModelTransformer() 542 FeatureExtractionModelTransformer::~FeatureExtractionModelTransformer()
611 } 622 }
612 623
613 void 624 void
614 FeatureExtractionModelTransformer::run() 625 FeatureExtractionModelTransformer::run()
615 { 626 {
616 initialise(); 627 if (initialise()) {
628 abandon();
629 return;
630 }
617 631
618 DenseTimeValueModel *input = getConformingInput(); 632 DenseTimeValueModel *input = getConformingInput();
619 if (!input) return; 633 if (!input) {
620 634 abandon();
621 if (m_outputs.empty()) return; 635 return;
636 }
637
638 if (m_outputs.empty()) {
639 abandon();
640 return;
641 }
622 642
623 Transform primaryTransform = m_transforms[0]; 643 Transform primaryTransform = m_transforms[0];
624 644
625 while (!input->isReady() && !m_abandoned) { 645 while (!input->isReady() && !m_abandoned) {
626 cerr << "FeatureExtractionModelTransformer::run: Waiting for input model to be ready..." << endl; 646 cerr << "FeatureExtractionModelTransformer::run: Waiting for input model to be ready..." << endl;