changeset 544:65d955c4d671

* throw (but do not yet catch!) exception when running out of disc space in coded audio file * simpler (faster?) cache-to-cache move operation in spectrogram, and some other minor fixes
author Chris Cannam
date Wed, 04 Feb 2009 12:13:16 +0000
parents 7a66b94ef1c0
children c603d9439b37
files base/Exceptions.cpp base/Exceptions.h data/fileio/CodedAudioFileReader.cpp data/fileio/CodedAudioFileReader.h
diffstat 4 files changed, 28 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/base/Exceptions.cpp	Wed Feb 04 10:53:38 2009 +0000
+++ b/base/Exceptions.cpp	Wed Feb 04 12:13:16 2009 +0000
@@ -100,11 +100,25 @@
               << ", only have " << available << std::endl;
 }
 
+InsufficientDiscSpace::InsufficientDiscSpace(QString directory) throw() :
+    m_directory(directory),
+    m_required(0),
+    m_available(0)
+{
+    std::cerr << "ERROR: Not enough disc space available in "
+              << directory.toStdString() << std::endl;
+}
+
 const char *
 InsufficientDiscSpace::what() const throw()
 {
-    return QString("Not enough space available in \"%1\": need %2, have %3")
-        .arg(m_directory).arg(m_required).arg(m_available).toLocal8Bit().data();
+    if (m_required > 0) {
+        return QString("Not enough space available in \"%1\": need %2, have %3")
+            .arg(m_directory).arg(m_required).arg(m_available).toLocal8Bit().data();
+    } else {
+        return QString("Not enough space available in \"%1\"")
+            .arg(m_directory).toLocal8Bit().data();
+    }
 }
 
 AllocationFailed::AllocationFailed(QString purpose) throw() :
--- a/base/Exceptions.h	Wed Feb 04 10:53:38 2009 +0000
+++ b/base/Exceptions.h	Wed Feb 04 12:13:16 2009 +0000
@@ -81,9 +81,11 @@
 public:
     InsufficientDiscSpace(QString directory,
                           size_t required, size_t available) throw();
+    InsufficientDiscSpace(QString directory) throw();
     virtual ~InsufficientDiscSpace() throw() { }
     virtual const char *what() const throw();
 
+    QString getDirectory() const { return m_directory; }
     size_t getRequired() const { return m_required; }
     size_t getAvailable() const { return m_available; }
 
--- a/data/fileio/CodedAudioFileReader.cpp	Wed Feb 04 10:53:38 2009 +0000
+++ b/data/fileio/CodedAudioFileReader.cpp	Wed Feb 04 12:13:16 2009 +0000
@@ -269,7 +269,6 @@
     }
 
     if (m_cacheWriteBufferIndex > 0) {
-        //!!! check for return value! out of disk space, etc!
         pushBuffer(m_cacheWriteBuffer,
                    m_cacheWriteBufferIndex / m_channelCount,
                    true);
@@ -328,8 +327,11 @@
     switch (m_cacheMode) {
 
     case CacheInTemporaryFile:
-        //!!! check for return value! out of disk space, etc!
-        sf_writef_float(m_cacheFileWritePtr, buffer, sz);
+        if (sf_writef_float(m_cacheFileWritePtr, buffer, sz) < sz) {
+            sf_close(m_cacheFileWritePtr);
+            m_cacheFileWritePtr = 0;
+            throw InsufficientDiscSpace(TempDirectory::getInstance()->getPath());
+        }
         break;
 
     case CacheInMemory:
--- a/data/fileio/CodedAudioFileReader.h	Wed Feb 04 10:53:38 2009 +0000
+++ b/data/fileio/CodedAudioFileReader.h	Wed Feb 04 12:13:16 2009 +0000
@@ -50,10 +50,15 @@
     CodedAudioFileReader(CacheMode cacheMode, size_t targetRate);
 
     void initialiseDecodeCache(); // samplerate, channels must have been set
+
+    // may throw InsufficientDiscSpace:
     void addSamplesToDecodeCache(float **samples, size_t nframes);
     void addSamplesToDecodeCache(float *samplesInterleaved, size_t nframes);
     void addSamplesToDecodeCache(const SampleBlock &interleaved);
+
+    // may throw InsufficientDiscSpace:
     void finishDecodeCache();
+
     bool isDecodeCacheInitialised() const { return m_initialised; }
 
     void startSerialised(QString id);