13
0

Disk I/O: only allocate midi-buffer if needed

This fixes a memory-leak (_midi_buf was allocated in DiskIOProc
but only delete in DiskReader). Also skip midi-refill early on
This commit is contained in:
Robin Gareus 2018-11-29 02:05:26 +01:00
parent dfbda9e0f6
commit 6fc2804414
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
3 changed files with 24 additions and 9 deletions

View File

@ -55,7 +55,7 @@ DiskIOProcessor::DiskIOProcessor (Session& s, string const & str, Flag f)
, playback_sample (0)
, _need_butler (false)
, channels (new ChannelList)
, _midi_buf (new MidiRingBuffer<samplepos_t> (s.butler()->midi_diskstream_buffer_size()))
, _midi_buf (0)
, _samples_written_to_ringbuffer (0)
, _samples_read_from_ringbuffer (0)
{
@ -76,6 +76,7 @@ DiskIOProcessor::~DiskIOProcessor ()
}
channels.flush ();
delete _midi_buf;
}

View File

@ -71,7 +71,6 @@ DiskReader::~DiskReader ()
_playlists[n]->release ();
}
}
delete _midi_buf;
}
void
@ -408,7 +407,7 @@ DiskReader::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp
/* MIDI data handling */
midi:
if (/*!_session.declick_out_pending() && */ bufs.count().n_midi()) {
if (/*!_session.declick_out_pending() && */ bufs.count().n_midi() && _midi_buf) {
MidiBuffer* dst;
if (_no_disk_output) {
@ -642,7 +641,9 @@ DiskReader::seek (samplepos_t sample, bool complete_refill)
reset_tracker ();
}
_midi_buf->reset();
if (_midi_buf) {
_midi_buf->reset();
}
g_atomic_int_set(&_samples_read_from_ringbuffer, 0);
g_atomic_int_set(&_samples_written_to_ringbuffer, 0);
@ -1209,7 +1210,9 @@ DiskReader::move_processor_automation (boost::weak_ptr<Processor> p, list< Evora
void
DiskReader::reset_tracker ()
{
_midi_buf->reset_tracker ();
if (_midi_buf) {
_midi_buf->reset_tracker ();
}
boost::shared_ptr<MidiPlaylist> mp (midi_playlist());
@ -1221,7 +1224,9 @@ DiskReader::reset_tracker ()
void
DiskReader::resolve_tracker (Evoral::EventSink<samplepos_t>& buffer, samplepos_t time)
{
_midi_buf->resolve_tracker(buffer, time);
if (_midi_buf) {
_midi_buf->resolve_tracker(buffer, time);
}
boost::shared_ptr<MidiPlaylist> mp (midi_playlist());
@ -1239,6 +1244,8 @@ DiskReader::get_midi_playback (MidiBuffer& dst, samplepos_t start_sample, sample
MidiBuffer* target;
samplepos_t nframes = end_sample - start_sample;
assert (_midi_buf);
if ((ms & MonitoringInput) == 0) {
/* Route::process_output_buffers() clears the buffer as-needed */
target = &dst;
@ -1378,6 +1385,8 @@ DiskReader::midi_read (samplepos_t& start, samplecnt_t dur, bool reversed)
samplepos_t effective_start = start;
Evoral::Range<samplepos_t>* loop_range (0);
assert(_midi_buf);
DEBUG_TRACE (DEBUG::MidiDiskstreamIO, string_compose ("MDS::midi_read @ %1 cnt %2\n", start, dur));
boost::shared_ptr<MidiTrack> mt = boost::dynamic_pointer_cast<MidiTrack>(_route);
@ -1463,7 +1472,7 @@ DiskReader::midi_read (samplepos_t& start, samplecnt_t dur, bool reversed)
int
DiskReader::refill_midi ()
{
if (!_playlists[DataType::MIDI]) {
if (!_playlists[DataType::MIDI] || !_midi_buf) {
return 0;
}

View File

@ -517,6 +517,8 @@ DiskWriter::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp
boost::shared_ptr<MidiTrack> mt = boost::dynamic_pointer_cast<MidiTrack>(_route);
MidiChannelFilter* filter = mt ? &mt->capture_filter() : 0;
assert (buf.size() == 0 || _midi_buf);
for (MidiBuffer::iterator i = buf.begin(); i != buf.end(); ++i) {
Evoral::Event<MidiBuffer::TimeType> ev (*i, false);
if (ev.time() + rec_offset > rec_nframes) {
@ -571,6 +573,7 @@ DiskWriter::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp
_midi_buf->write (event_time, ev.event_type(), ev.size(), ev.buffer());
}
}
g_atomic_int_add (const_cast<gint*>(&_samples_pending_write), nframes);
if (buf.size() != 0) {
@ -815,7 +818,9 @@ DiskWriter::seek (samplepos_t sample, bool complete_refill)
(*chan)->wbuf->reset ();
}
_midi_buf->reset ();
if (_midi_buf) {
_midi_buf->reset ();
}
g_atomic_int_set(&_samples_read_from_ringbuffer, 0);
g_atomic_int_set(&_samples_written_to_ringbuffer, 0);
@ -953,7 +958,7 @@ DiskWriter::do_flush (RunContext ctxt, bool force_flush)
/* MIDI*/
if (_midi_write_source) {
if (_midi_write_source && _midi_buf) {
const samplecnt_t total = g_atomic_int_get(const_cast<gint*> (&_samples_pending_write));