comparison transform/FeatureExtractionModelTransformer.cpp @ 1372:54366398e636

Handle exceptions raised during plugin processing (as opposed to on init/configure, which were already handled)
author Chris Cannam
date Tue, 31 Jan 2017 11:13:20 +0000
parents 7fb7b59c35ee
children 7a38b2cbb6c1
comparison
equal deleted inserted replaced
1371:fad8f533ca13 1372:54366398e636
260 void 260 void
261 FeatureExtractionModelTransformer::deinitialise() 261 FeatureExtractionModelTransformer::deinitialise()
262 { 262 {
263 SVDEBUG << "FeatureExtractionModelTransformer: deleting plugin for transform in thread " 263 SVDEBUG << "FeatureExtractionModelTransformer: deleting plugin for transform in thread "
264 << QThread::currentThreadId() << endl; 264 << QThread::currentThreadId() << endl;
265 265
266 delete m_plugin; 266 try {
267 delete m_plugin;
268 } catch (const std::exception &e) {
269 // A destructor shouldn't throw an exception. But at one point
270 // (now fixed) our plugin stub destructor could have
271 // accidentally done so, so just in case:
272 SVCERR << "FeatureExtractionModelTransformer: caught exception while deleting plugin: " << e.what() << endl;
273 m_message = e.what();
274 }
275 m_plugin = 0;
276
267 for (int j = 0; j < (int)m_descriptors.size(); ++j) { 277 for (int j = 0; j < (int)m_descriptors.size(); ++j) {
268 delete m_descriptors[j]; 278 delete m_descriptors[j];
269 } 279 }
270 } 280 }
271 281
728 imaginaries = new float[blockSize/2 + 1]; 738 imaginaries = new float[blockSize/2 + 1];
729 } 739 }
730 740
731 QString error = ""; 741 QString error = "";
732 742
733 while (!m_abandoned) { 743 try {
734 744 while (!m_abandoned) {
735 if (frequencyDomain) { 745
736 if (blockFrame - int(blockSize)/2 > 746 if (frequencyDomain) {
737 contextStart + contextDuration) break; 747 if (blockFrame - int(blockSize)/2 >
738 } else { 748 contextStart + contextDuration) break;
739 if (blockFrame >= 749 } else {
740 contextStart + contextDuration) break; 750 if (blockFrame >=
741 } 751 contextStart + contextDuration) break;
752 }
742 753
743 // SVDEBUG << "FeatureExtractionModelTransformer::run: blockFrame " 754 // SVDEBUG << "FeatureExtractionModelTransformer::run: blockFrame "
744 // << blockFrame << ", endFrame " << endFrame << ", blockSize " 755 // << blockFrame << ", endFrame " << endFrame << ", blockSize "
745 // << blockSize << endl; 756 // << blockSize << endl;
746 757
747 int completion = int 758 int completion = int
748 ((((blockFrame - contextStart) / stepSize) * 99) / 759 ((((blockFrame - contextStart) / stepSize) * 99) /
749 (contextDuration / stepSize + 1)); 760 (contextDuration / stepSize + 1));
750 761
751 // channelCount is either m_input.getModel()->channelCount or 1 762 // channelCount is either m_input.getModel()->channelCount or 1
752 763
753 if (frequencyDomain) { 764 if (frequencyDomain) {
754 for (int ch = 0; ch < channelCount; ++ch) { 765 for (int ch = 0; ch < channelCount; ++ch) {
755 int column = int((blockFrame - startFrame) / stepSize); 766 int column = int((blockFrame - startFrame) / stepSize);
756 if (fftModels[ch]->getValuesAt(column, reals, imaginaries)) { 767 if (fftModels[ch]->getValuesAt(column, reals, imaginaries)) {
757 for (int i = 0; i <= blockSize/2; ++i) { 768 for (int i = 0; i <= blockSize/2; ++i) {
758 buffers[ch][i*2] = reals[i]; 769 buffers[ch][i*2] = reals[i];
759 buffers[ch][i*2+1] = imaginaries[i]; 770 buffers[ch][i*2+1] = imaginaries[i];
771 }
772 } else {
773 for (int i = 0; i <= blockSize/2; ++i) {
774 buffers[ch][i*2] = 0.f;
775 buffers[ch][i*2+1] = 0.f;
776 }
777 }
778 error = fftModels[ch]->getError();
779 if (error != "") {
780 SVCERR << "FeatureExtractionModelTransformer::run: Abandoning, error is " << error << endl;
781 m_abandoned = true;
782 m_message = error;
783 break;
760 } 784 }
761 } else {
762 for (int i = 0; i <= blockSize/2; ++i) {
763 buffers[ch][i*2] = 0.f;
764 buffers[ch][i*2+1] = 0.f;
765 }
766 }
767 error = fftModels[ch]->getError();
768 if (error != "") {
769 SVDEBUG << "FeatureExtractionModelTransformer::run: Abandoning, error is " << error << endl;
770 m_abandoned = true;
771 m_message = error;
772 break;
773 } 785 }
774 } 786 } else {
775 } else { 787 getFrames(channelCount, blockFrame, blockSize, buffers);
776 getFrames(channelCount, blockFrame, blockSize, buffers); 788 }
777 } 789
778 790 if (m_abandoned) break;
779 if (m_abandoned) break; 791
780 792 Vamp::Plugin::FeatureSet features = m_plugin->process
781 Vamp::Plugin::FeatureSet features = m_plugin->process 793 (buffers, RealTime::frame2RealTime(blockFrame, sampleRate).toVampRealTime());
782 (buffers, RealTime::frame2RealTime(blockFrame, sampleRate).toVampRealTime()); 794
783 795 if (m_abandoned) break;
784 if (m_abandoned) break; 796
785
786 for (int j = 0; j < (int)m_outputNos.size(); ++j) {
787 for (int fi = 0; fi < (int)features[m_outputNos[j]].size(); ++fi) {
788 Vamp::Plugin::Feature feature = features[m_outputNos[j]][fi];
789 addFeature(j, blockFrame, feature);
790 }
791 }
792
793 if (blockFrame == contextStart || completion > prevCompletion) {
794 for (int j = 0; j < (int)m_outputNos.size(); ++j) { 797 for (int j = 0; j < (int)m_outputNos.size(); ++j) {
795 setCompletion(j, completion); 798 for (int fi = 0; fi < (int)features[m_outputNos[j]].size(); ++fi) {
796 } 799 Vamp::Plugin::Feature feature = features[m_outputNos[j]][fi];
797 prevCompletion = completion; 800 addFeature(j, blockFrame, feature);
798 } 801 }
799 802 }
800 blockFrame += stepSize; 803
801 } 804 if (blockFrame == contextStart || completion > prevCompletion) {
802 805 for (int j = 0; j < (int)m_outputNos.size(); ++j) {
803 if (!m_abandoned) { 806 setCompletion(j, completion);
804 Vamp::Plugin::FeatureSet features = m_plugin->getRemainingFeatures(); 807 }
805 808 prevCompletion = completion;
806 for (int j = 0; j < (int)m_outputNos.size(); ++j) { 809 }
807 for (int fi = 0; fi < (int)features[m_outputNos[j]].size(); ++fi) { 810
808 Vamp::Plugin::Feature feature = features[m_outputNos[j]][fi]; 811 blockFrame += stepSize;
809 addFeature(j, blockFrame, feature); 812
810 } 813 }
811 } 814
815 if (!m_abandoned) {
816 Vamp::Plugin::FeatureSet features = m_plugin->getRemainingFeatures();
817
818 for (int j = 0; j < (int)m_outputNos.size(); ++j) {
819 for (int fi = 0; fi < (int)features[m_outputNos[j]].size(); ++fi) {
820 Vamp::Plugin::Feature feature = features[m_outputNos[j]][fi];
821 addFeature(j, blockFrame, feature);
822 }
823 }
824 }
825 } catch (const std::exception &e) {
826 SVCERR << "FeatureExtractionModelTransformer::run: Exception caught: "
827 << e.what() << endl;
828 m_abandoned = true;
829 m_message = e.what();
812 } 830 }
813 831
814 for (int j = 0; j < (int)m_outputNos.size(); ++j) { 832 for (int j = 0; j < (int)m_outputNos.size(); ++j) {
815 setCompletion(j, 100); 833 setCompletion(j, 100);
816 } 834 }