b2f58786e2dc — Chris Cannam 11 months ago
Return to marking zero-duration (i.e. probably-being-written) wav streams as seekable, just of unknown-or-zero duration
2 files changed, 14 insertions(+), 14 deletions(-)

M bqaudiostream/AudioReadStream.h
M src/SimpleWavFileReadStream.cpp
M bqaudiostream/AudioReadStream.h +12 -5
@@ 83,13 83,20 @@ public:
     bool isSeekable() const;
 
     /**
-     * Return an estimate of the number of frames in the stream (at
-     * its native sample rate) or zero if the stream can't provide
+     * Return an estimate of the number of frames in the stream, at
+     * its native sample rate, or zero if the stream can't provide
      * that information.
      *
-     * For seekable streams (see isSeekable()) this is guaranteed to
-     * return a true frame count. For other streams it may be
-     * approximate, hence the name.
+     * There is no way to distinguish between a stream that can't
+     * provide this estimate and a stream of truly zero
+     * duration. Although unsatisfactory, this is at least consistent
+     * with the treatment of WAV files of zero data size, which are
+     * usually understood as files that are still being written and
+     * may have a true duration that is so far unknown.
+     *
+     * For seekable streams (see isSeekable()), any non-zero return
+     * value is guaranteed to be a true frame count. For other streams
+     * it may be approximate, hence the name.
      */
     size_t getEstimatedFrameCount() const;
 

          
M src/SimpleWavFileReadStream.cpp +2 -9
@@ 92,6 92,8 @@ SimpleWavFileReadStream::SimpleWavFileRe
         throw FileNotFound(m_path);
     }
 
+    m_seekable = true;
+
     readHeader();
 }
 

          
@@ 173,15 175,6 @@ SimpleWavFileReadStream::readHeader()
         m_estimatedFrameCount = 0;
     }
 
-    // Mark as seekable only if we have a known duration. This is
-    // largely to honour the guarantee in getEstimatedFrameCount that
-    // the returned value will be a true value if the stream is
-    // seekable. But it's also a bit iffy with files that are still
-    // being written, to have seek success depend on whether the
-    // target frame has been written yet. (Nonetheless we do support
-    // that case in the actual seek implementation)
-    m_seekable = (m_estimatedFrameCount > 0);
-
     m_dataReadOffset = 0;
     m_dataReadStart = m_file->tellg();
 }