likely fix for crash-by-assert just after a MIDI diskstream overwrite (e.g. just...
authorPaul Davis <paul@linuxaudiosystems.com>
Mon, 6 Feb 2012 14:58:03 +0000 (14:58 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Mon, 6 Feb 2012 14:58:03 +0000 (14:58 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@11455 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/midi_diskstream.cc

index 79ef361e1fbadf62ad55467c50db86e77c8d094d..e62ec6837e6dc8e3c57e2371a42b43624edfbf3f 100644 (file)
@@ -455,14 +455,23 @@ MidiDiskstream::commit (framecnt_t playback_distance)
        uint32_t frames_read = g_atomic_int_get(&_frames_read_from_ringbuffer);
        uint32_t frames_written = g_atomic_int_get(&_frames_written_to_ringbuffer);
 
-       cerr << name() << " MDS written: " << frames_written << " - read: " << frames_read <<
-               " = " << frames_written - frames_read
-            << " + " << playback_distance << " < " << midi_readahead << " = " << need_butler << ")" << endl;
-               
-       assert (frames_read <= frames_written);
-
-       if ((frames_written - frames_read) + playback_distance < midi_readahead) {
-               need_butler = true;
+       /*
+         cerr << name() << " MDS written: " << frames_written << " - read: " << frames_read <<
+         " = " << frames_written - frames_read
+         << " + " << playback_distance << " < " << midi_readahead << " = " << need_butler << ")" << endl;
+       */
+
+       /* frames_read will generally be less than frames_written, but
+        * immediately after an overwrite, we can end up having read some data
+        * before we've written any. we don't need to trip an assert() on this,
+        * but we do need to check so that the decision on whether or not we
+        * need the butler is done correctly.
+        */
+       
+       if (frames_read <= frames_written) {
+               if ((frames_written - frames_read) + playback_distance < midi_readahead) {
+                       need_butler = true;
+               }
        }
 
 
@@ -487,8 +496,6 @@ MidiDiskstream::overwrite_existing_buffers ()
        g_atomic_int_set (&_frames_read_from_ringbuffer, 0);
        g_atomic_int_set (&_frames_written_to_ringbuffer, 0);
 
-       cerr << name() << " FWTRB reset to zero for overwrite\n";
-
        read (overwrite_frame, disk_io_chunk_frames, false);
        file_frame = overwrite_frame; // it was adjusted by ::read()
        overwrite_queued = false;
@@ -508,8 +515,6 @@ MidiDiskstream::seek (framepos_t frame, bool complete_refill)
        g_atomic_int_set(&_frames_read_from_ringbuffer, 0);
        g_atomic_int_set(&_frames_written_to_ringbuffer, 0);
 
-       cerr << name() << " FWTRB reset to zero for seek\n";
-
        playback_sample = frame;
        file_frame = frame;
 
@@ -606,7 +611,6 @@ MidiDiskstream::read (framepos_t& start, framecnt_t dur, bool reversed)
                }
 
                g_atomic_int_add (&_frames_written_to_ringbuffer, this_read);
-               cerr << "FWTRB added " << this_read << " now " << g_atomic_int_get (&_frames_written_to_ringbuffer) << endl;
 
                if (reversed) {
 
@@ -1297,7 +1301,6 @@ MidiDiskstream::get_playback (MidiBuffer& dst, framecnt_t nframes)
 #endif
 
        g_atomic_int_add (&_frames_read_from_ringbuffer, nframes);
-       cerr << name() << " FRFB advanced by " << nframes << " to " << g_atomic_int_get (&_frames_read_from_ringbuffer) << endl;
 }
 
 bool