# HG changeset patch # User Chris Cannam # Date 1233749596 0 # Node ID 65d955c4d67146c340586d4ffb992678bfbb4f71 # Parent 7a66b94ef1c0036df56446907f0ddc6592fa416a * 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 diff -r 7a66b94ef1c0 -r 65d955c4d671 base/Exceptions.cpp --- 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() : diff -r 7a66b94ef1c0 -r 65d955c4d671 base/Exceptions.h --- 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; } diff -r 7a66b94ef1c0 -r 65d955c4d671 data/fileio/CodedAudioFileReader.cpp --- 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: diff -r 7a66b94ef1c0 -r 65d955c4d671 data/fileio/CodedAudioFileReader.h --- 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);