X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fbutler.cc;h=9847d55e40a5455c2e691c191dac9816ddc4ac85;hb=0cd3bd4f194439a047f8ab6b7baaf38d118a1d85;hp=addf6ddf27f0e8b1333ab70c91d610aaf92f4a4f;hpb=8ae20c0c4d1353afe2a42f17eb14270882a89174;p=ardour.git diff --git a/libs/ardour/butler.cc b/libs/ardour/butler.cc index addf6ddf27..9847d55e40 100644 --- a/libs/ardour/butler.cc +++ b/libs/ardour/butler.cc @@ -28,6 +28,8 @@ #include "ardour/io.h" #include "ardour/midi_diskstream.h" #include "ardour/session.h" +#include "ardour/track.h" +#include "ardour/auditioner.h" #include "i18n.h" @@ -43,8 +45,10 @@ Butler::Butler(Session& s) , thread(0) , audio_dstream_buffer_size(0) , midi_dstream_buffer_size(0) + , pool_trash(16) { g_atomic_int_set(&should_do_transport_work, 0); + SessionEvent::pool->set_trash (&pool_trash); } Butler::~Butler() @@ -129,7 +133,7 @@ Butler::thread_work () struct pollfd pfd[1]; bool disk_work_outstanding = false; - Session::DiskstreamList::iterator i; + RouteList::iterator i; while (true) { pfd[0].fd = request_pipe[0]; @@ -205,30 +209,36 @@ Butler::thread_work () begin = get_microseconds(); - boost::shared_ptr dsl = _session.diskstream_list().reader (); + boost::shared_ptr rl = _session.get_routes(); + + RouteList rl_with_auditioner = *rl; + rl_with_auditioner.push_back (_session.the_auditioner()); // for (i = dsl->begin(); i != dsl->end(); ++i) { // cerr << "BEFORE " << (*i)->name() << ": pb = " << (*i)->playback_buffer_load() << " cp = " << (*i)->capture_buffer_load() << endl; // } - for (i = dsl->begin(); !transport_work_requested() && should_run && i != dsl->end(); ++i) { + for (i = rl_with_auditioner.begin(); !transport_work_requested() && should_run && i != rl_with_auditioner.end(); ++i) { - boost::shared_ptr ds = *i; + boost::shared_ptr tr = boost::dynamic_pointer_cast (*i); + if (!tr) { + continue; + } /* don't read inactive tracks */ - boost::shared_ptr io = ds->io(); + boost::shared_ptr io = tr->input (); if (io && !io->active()) { continue; } - switch (ds->do_refill ()) { + switch (tr->do_refill ()) { case 0: - bytes += ds->read_data_count(); + bytes += tr->read_data_count(); break; case 1: - bytes += ds->read_data_count(); + bytes += tr->read_data_count(); disk_work_outstanding = true; break; @@ -240,7 +250,7 @@ Butler::thread_work () } - if (i != dsl->end()) { + if (i != rl_with_auditioner.begin() && i != rl_with_auditioner.end()) { /* we didn't get to all the streams */ disk_work_outstanding = true; } @@ -262,18 +272,23 @@ Butler::thread_work () compute_io = true; begin = get_microseconds(); - for (i = dsl->begin(); !transport_work_requested() && should_run && i != dsl->end(); ++i) { + for (i = rl->begin(); !transport_work_requested() && should_run && i != rl->end(); ++i) { // cerr << "write behind for " << (*i)->name () << endl; + boost::shared_ptr tr = boost::dynamic_pointer_cast (*i); + if (!tr) { + continue; + } + /* note that we still try to flush diskstreams attached to inactive routes */ - switch ((*i)->do_flush (ButlerContext)) { + switch (tr->do_flush (ButlerContext)) { case 0: - bytes += (*i)->write_data_count(); + bytes += tr->write_data_count(); break; case 1: - bytes += (*i)->write_data_count(); + bytes += tr->write_data_count(); disk_work_outstanding = true; break; @@ -294,7 +309,7 @@ Butler::thread_work () _session.request_stop (); } - if (i != dsl->end()) { + if (i != rl->begin() && i != rl->end()) { /* we didn't get to all the streams */ disk_work_outstanding = true; } @@ -331,6 +346,8 @@ Butler::thread_work () paused.signal(); } + + empty_pool_trash (); } pthread_exit_pbd (0); @@ -394,4 +411,42 @@ Butler::write_data_rate () const return _write_data_rate > 10485.7600000f ? 0.0f : _write_data_rate; } +void +Butler::empty_pool_trash () +{ + /* look in the trash, deleting empty pools until we come to one that is not empty */ + + RingBuffer::rw_vector vec; + pool_trash.get_read_vector (&vec); + + guint deleted = 0; + + for (int i = 0; i < 2; ++i) { + for (guint j = 0; j < vec.len[i]; ++j) { + if (vec.buf[i][j]->empty()) { + delete vec.buf[i][j]; + ++deleted; + } else { + /* found a non-empty pool, so stop deleting */ + if (deleted) { + pool_trash.increment_read_idx (deleted); + } + return; + } + } + } + + if (deleted) { + pool_trash.increment_read_idx (deleted); + } +} + +void +Butler::drop_references () +{ + SessionEvent::pool->set_trash (0); +} + + } // namespace ARDOUR +