# HG changeset patch # User Chris Cannam # Date 1190996106 0 # Node ID 21a76c9ed5c3a29456916b706640bd76de6022fb # Parent a65a01870d8c00b52f059dc182be6337a4d28e29 * Merge transform directory from sv-match-alignment branch (the previous comment included notes for this stuff, but I missed it in the actual merge) * Fix crash when a transform fails to create an output model and the thread that created the transform then deletes its input model thinking it's no longer needed, even though the transform run thread is still using it -- fix is to wait() on the transform before returning the null output model diff -r a65a01870d8c -r 21a76c9ed5c3 transform/FeatureExtractionPluginTransform.cpp --- a/transform/FeatureExtractionPluginTransform.cpp Fri Sep 28 14:32:45 2007 +0000 +++ b/transform/FeatureExtractionPluginTransform.cpp Fri Sep 28 16:15:06 2007 +0000 @@ -220,6 +220,7 @@ FeatureExtractionPluginTransform::~FeatureExtractionPluginTransform() { + std::cerr << "FeatureExtractionPluginTransform::~FeatureExtractionPluginTransform()" << std::endl; delete m_plugin; delete m_descriptor; } @@ -241,6 +242,8 @@ DenseTimeValueModel *input = getInput(); if (!input) return; + if (!m_output) return; + while (!input->isReady()) { /* if (dynamic_cast(input)) { @@ -253,8 +256,6 @@ sleep(1); } - if (!m_output) return; - size_t sampleRate = m_input->getSampleRate(); size_t channelCount = input->getChannelCount(); @@ -297,16 +298,35 @@ long startFrame = m_input->getStartFrame(); long endFrame = m_input->getEndFrame(); - long blockFrame = startFrame; + + long contextStart = m_context.startFrame; + long contextDuration = m_context.duration; + + if (contextStart == 0 || contextStart < startFrame) { + contextStart = startFrame; + } + + if (contextDuration == 0) { + contextDuration = endFrame - contextStart; + } + if (contextStart + contextDuration > endFrame) { + contextDuration = endFrame - contextStart; + } + + long blockFrame = contextStart; long prevCompletion = 0; + setCompletion(0); + while (!m_abandoned) { if (frequencyDomain) { - if (blockFrame - int(m_context.blockSize)/2 > endFrame) break; + if (blockFrame - int(m_context.blockSize)/2 > + contextStart + contextDuration) break; } else { - if (blockFrame >= endFrame) break; + if (blockFrame >= + contextStart + contextDuration) break; } // std::cerr << "FeatureExtractionPluginTransform::run: blockFrame " @@ -314,8 +334,8 @@ // << m_context.blockSize << std::endl; long completion = - (((blockFrame - startFrame) / m_context.stepSize) * 99) / - ( (endFrame - startFrame) / m_context.stepSize); + (((blockFrame - contextStart) / m_context.stepSize) * 99) / + (contextDuration / m_context.stepSize); // channelCount is either m_input->channelCount or 1 @@ -341,7 +361,7 @@ addFeature(blockFrame, feature); } - if (blockFrame == startFrame || completion > prevCompletion) { + if (blockFrame == contextStart || completion > prevCompletion) { setCompletion(completion); prevCompletion = completion; } @@ -500,8 +520,8 @@ binCount = m_descriptor->binCount; } -// std::cerr << "FeatureExtractionPluginTransform::setCompletion(" -// << completion << ")" << std::endl; + std::cerr << "FeatureExtractionPluginTransform::setCompletion(" + << completion << ")" << std::endl; if (binCount == 0) { diff -r a65a01870d8c -r 21a76c9ed5c3 transform/PluginTransform.cpp --- a/transform/PluginTransform.cpp Fri Sep 28 14:32:45 2007 +0000 +++ b/transform/PluginTransform.cpp Fri Sep 28 16:15:06 2007 +0000 @@ -30,7 +30,10 @@ domain(Vamp::Plugin::TimeDomain), stepSize(_bs ? _bs : 1024), blockSize(_bs ? _bs : 1024), - windowType(HanningWindow) + windowType(HanningWindow), + startFrame(0), + duration(0), + sampleRate(0) { } @@ -40,7 +43,10 @@ domain(Vamp::Plugin::FrequencyDomain), stepSize(_ss ? _ss : (_bs ? _bs / 2 : 512)), blockSize(_bs ? _bs : 1024), - windowType(_wt) + windowType(_wt), + startFrame(0), + duration(0), + sampleRate(0) { } @@ -50,7 +56,10 @@ domain(Vamp::Plugin::TimeDomain), stepSize(0), blockSize(0), - windowType(HanningWindow) + windowType(HanningWindow), + startFrame(0), + duration(0), + sampleRate(0) { makeConsistentWithPlugin(_plugin); } @@ -62,7 +71,10 @@ c.domain == domain && c.stepSize == stepSize && c.blockSize == blockSize && - c.windowType == windowType); + c.windowType == windowType && + c.startFrame == startFrame && + c.duration == duration && + c.sampleRate == sampleRate); } void diff -r a65a01870d8c -r 21a76c9ed5c3 transform/PluginTransform.h --- a/transform/PluginTransform.h Fri Sep 28 14:32:45 2007 +0000 +++ b/transform/PluginTransform.h Fri Sep 28 16:15:06 2007 +0000 @@ -48,6 +48,9 @@ size_t stepSize; size_t blockSize; WindowType windowType; + size_t startFrame; + size_t duration; // 0 -> whole thing + float sampleRate; // 0 -> model's rate }; protected: diff -r a65a01870d8c -r 21a76c9ed5c3 transform/TransformFactory.cpp --- a/transform/TransformFactory.cpp Fri Sep 28 14:32:45 2007 +0000 +++ b/transform/TransformFactory.cpp Fri Sep 28 16:15:06 2007 +0000 @@ -292,6 +292,8 @@ units, configurable); } + + delete plugin; } } @@ -553,6 +555,8 @@ if (FeatureExtractionPluginFactory::instanceFor(id)) { + std::cerr << "getConfigurationForTransform: instantiating Vamp plugin" << std::endl; + Vamp::Plugin *vp = FeatureExtractionPluginFactory::instanceFor(id)->instantiatePlugin (id, inputModel->getSampleRate()); @@ -709,8 +713,10 @@ FeatureExtractionPluginFactory::instanceFor(id)->instantiatePlugin (id, inputModel ? inputModel->getSampleRate() : 48000); - if (vp) context = PluginTransform::ExecutionContext(-1, vp); - + if (vp) { + context = PluginTransform::ExecutionContext(-1, vp); + delete vp; + } } return context; @@ -779,6 +785,8 @@ } else if (trn != "") { model->setObjectName(trn); } + } else { + t->wait(); } return model;