changeset 31:8b20521fc40f

* Commit old fix (which I hope was correct!) to avoid leaking fds on exceptions * Remove dependency on audioio library
author Chris Cannam
date Fri, 12 Mar 2010 12:08:21 +0000
parents 1141bc562301
children 7dbf20549eea
files runner/FeatureExtractionManager.cpp runner/FeatureExtractionManager.h runner/runner.pro sonic-annotator.pro
diffstat 4 files changed, 44 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/runner/FeatureExtractionManager.cpp	Fri Oct 09 09:13:21 2009 +0000
+++ b/runner/FeatureExtractionManager.cpp	Fri Mar 12 12:08:21 2010 +0000
@@ -383,6 +383,8 @@
 {
     if (m_plugins.empty()) return;
 
+    testOutputFiles(audioSource);
+
     ProgressPrinter retrievalProgress("Retrieving audio data...");
 
     FileSource source(audioSource, &retrievalProgress);
@@ -429,6 +431,7 @@
 
     // reject file if it has too few channels, plugin will handle if it has too many
     if ((int)channels < m_channels) {
+        delete reader;
         throw FileOperationFailed
             (audioSource,
              QString("read sufficient channels (found %1, require %2)")
@@ -440,6 +443,24 @@
     for (int c = 0; c < m_channels; ++c) {
         data[c] = new float[m_blockSize];
     }
+    
+    struct LifespanMgr { // unintrusive hack introduced to ensure
+                         // destruction on exceptions
+        AudioFileReader *m_r;
+        int m_c;
+        float **m_d;
+        LifespanMgr(AudioFileReader *r, int c, float **d) :
+            m_r(r), m_c(c), m_d(d) { }
+        ~LifespanMgr() { destroy(); }
+        void destroy() {
+            if (!m_r) return;
+            delete m_r;
+            for (int i = 0; i < m_c; ++i) delete[] m_d[i];
+            delete[] m_d;
+            m_r = 0;
+        }
+    };
+    LifespanMgr lifemgr(reader, m_channels, data);
 
     size_t frameCount = reader->getFrameCount();
     
@@ -593,7 +614,7 @@
 
 //    std::cerr << "FeatureExtractionManager: deleting audio file reader" << std::endl;
 
-    delete reader;
+    lifemgr.destroy(); // deletes reader, data
     
     for (PluginMap::iterator pi = m_plugins.begin();
          pi != m_plugins.end(); ++pi) { 
@@ -722,6 +743,23 @@
     }
 }
 
+void FeatureExtractionManager::testOutputFiles(QString audioSource)
+{
+    for (PluginMap::iterator pi = m_plugins.begin();
+         pi != m_plugins.end(); ++pi) {
+
+        for (TransformWriterMap::iterator ti = pi->second.begin();
+             ti != pi->second.end(); ++ti) {
+        
+            vector<FeatureWriter *> &writers = ti->second;
+
+            for (int i = 0; i < (int)writers.size(); ++i) {
+                writers[i]->testOutputFile(audioSource, ti->first.getIdentifier());
+            }
+        }
+    }
+}
+
 void FeatureExtractionManager::finish()
 {
     for (PluginMap::iterator pi = m_plugins.begin();
--- a/runner/FeatureExtractionManager.h	Fri Oct 09 09:13:21 2009 +0000
+++ b/runner/FeatureExtractionManager.h	Fri Mar 12 12:08:21 2010 +0000
@@ -97,6 +97,8 @@
                        const Vamp::Plugin::FeatureSet &,
                        Transform::SummaryType summaryType =
                        Transform::NoSummary);
+
+    void testOutputFiles(QString audioSource);
     void finish();
 
     int m_blockSize;
--- a/runner/runner.pro	Fri Oct 09 09:13:21 2009 +0000
+++ b/runner/runner.pro	Fri Mar 12 12:08:21 2010 +0000
@@ -28,17 +28,15 @@
 
 DEPENDPATH += . .. i18n main
 INCLUDEPATH += . .. main
-LIBPATH = ../audioio ../data ../plugin ../rdf ../transform ../base ../system $$LIBPATH
+LIBPATH = ../data ../plugin ../rdf ../transform ../base ../system $$LIBPATH
 
 QMAKE_CXXFLAGS_RELEASE += -fmessage-length=80 -fdiagnostics-show-location=every-line
 
 contains(DEFINES, BUILD_STATIC):LIBS -= -ljack
 
-#LIBS = -lsvaudioio -lsvdata -lsvtransform -lsvplugin -lsvrdf -lsvbase -lsvsystem  $$LIBS
 LIBS = -lsvdata -lsvtransform -lsvplugin -lsvrdf -lsvdata -lsvbase -lsvsystem  $$LIBS
 
-PRE_TARGETDEPS += ../audioio/libsvaudioio.a \
-                  ../data/libsvdata.a \
+PRE_TARGETDEPS += ../data/libsvdata.a \
                   ../transform/libsvtransform.a \
                   ../plugin/libsvplugin.a \
                   ../rdf/libsvrdf.a \
--- a/sonic-annotator.pro	Fri Oct 09 09:13:21 2009 +0000
+++ b/sonic-annotator.pro	Fri Mar 12 12:08:21 2010 +0000
@@ -1,6 +1,6 @@
 
 TEMPLATE = subdirs
 
-SUBDIRS = audioio base data plugin rdf system transform runner
+SUBDIRS = base data plugin rdf system transform runner