changeset 375:f1ff248a793e

* Attempt to fix crash caused by race condition on threaded file decode
author Chris Cannam
date Thu, 07 Feb 2008 12:35:43 +0000
parents 7cc6b7b0d819
children ab24af1271e9
files data/fileio/CodedAudioFileReader.cpp data/fileio/MP3FileReader.cpp
diffstat 2 files changed, 4 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/CodedAudioFileReader.cpp	Wed Feb 06 17:40:53 2008 +0000
+++ b/data/fileio/CodedAudioFileReader.cpp	Thu Feb 07 12:35:43 2008 +0000
@@ -294,7 +294,7 @@
     float max = 1.0;
     size_t count = sz * m_channelCount;
 
-    if (m_resampler) {
+    if (m_resampler && m_fileRate != 0) {
         
         float ratio = float(m_sampleRate) / float(m_fileRate);
 
--- a/data/fileio/MP3FileReader.cpp	Wed Feb 06 17:40:53 2008 +0000
+++ b/data/fileio/MP3FileReader.cpp	Thu Feb 07 12:35:43 2008 +0000
@@ -135,7 +135,7 @@
         m_decodeThread = new DecodeThread(this);
         m_decodeThread->start();
 
-        while (m_channelCount == 0 && !m_done) {
+        while ((m_channelCount == 0 || m_fileRate == 0) && !m_done) {
             usleep(10);
         }
     }
@@ -358,7 +358,8 @@
         double bitrate = m_bitrateNum / m_bitrateDenom;
         double duration = double(m_fileSize * 8) / bitrate;
         double elapsed = double(m_frameCount) / m_sampleRate;
-        double percent = ((elapsed * 100.0) / duration);
+        double percent = 100;
+        if (duration > 0.0) percent = ((elapsed * 100.0) / duration);
         int p = int(percent);
         if (p < 1) p = 1;
         if (p > 99) p = 99;