X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fbutler.cc;h=72f2a0971d0cce97d35799c3eb1c73fd6320fe76;hb=ed72df29b79f9e2dc7482f07c39010b4523c4a8e;hp=8b88197073c10f9d50889dfb5f9f9c6d58364eed;hpb=8783fc35f27b8583755d53d70efbf6cece27ca29;p=ardour.git diff --git a/libs/ardour/butler.cc b/libs/ardour/butler.cc index 8b88197073..72f2a0971d 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" @@ -41,12 +43,15 @@ namespace ARDOUR { Butler::Butler(Session& s) : SessionHandleRef (s) , thread(0) - , audio_dstream_buffer_size(0) + , audio_dstream_capture_buffer_size(0) + , audio_dstream_playback_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); + + Config->ParameterChanged.connect_same_thread (*this, boost::bind (&Butler::config_changed, this, _1)); } Butler::~Butler() @@ -54,13 +59,27 @@ Butler::~Butler() terminate_thread (); } +void +Butler::config_changed (std::string p) +{ + if (p == "playback-buffer-seconds") { + /* size is in Samples, not bytes */ + audio_dstream_playback_buffer_size = (uint32_t) floor (Config->get_audio_playback_buffer_seconds() * _session.frame_rate()); + _session.adjust_playback_buffering (); + } else if (p == "capture-buffer-seconds") { + audio_dstream_capture_buffer_size = (uint32_t) floor (Config->get_audio_capture_buffer_seconds() * _session.frame_rate()); + _session.adjust_capture_buffering (); + } +} + int Butler::start_thread() { const float rate = (float)_session.frame_rate(); /* size is in Samples, not bytes */ - audio_dstream_buffer_size = (uint32_t) floor (Config->get_audio_track_buffer_seconds() * rate); + audio_dstream_capture_buffer_size = (uint32_t) floor (Config->get_audio_capture_buffer_seconds() * rate); + audio_dstream_playback_buffer_size = (uint32_t) floor (Config->get_audio_playback_buffer_seconds() * rate); /* size is in bytes * XXX: Jack needs to tell us the MIDI buffer size @@ -68,9 +87,9 @@ Butler::start_thread() */ midi_dstream_buffer_size = (uint32_t) floor (Config->get_midi_track_buffer_seconds() * rate); - MidiDiskstream::set_readahead_frames ((nframes_t)(Config->get_midi_readahead() * rate)); + MidiDiskstream::set_readahead_frames ((framecnt_t) (Config->get_midi_readahead() * rate)); - Crossfade::set_buffer_size (audio_dstream_buffer_size); + Crossfade::set_buffer_size (audio_dstream_playback_buffer_size); should_run = false; @@ -108,7 +127,7 @@ Butler::terminate_thread () if (thread) { void* status; const char c = Request::Quit; - ::write (request_pipe[1], &c, 1); + (void) ::write (request_pipe[1], &c, 1); pthread_join (thread, &status); } } @@ -131,7 +150,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]; @@ -197,40 +216,49 @@ Butler::thread_work () } } - if (transport_work_requested()) { - _session.butler_transport_work (); - } - disk_work_outstanding = false; bytes = 0; compute_io = true; +restart: + disk_work_outstanding = false; + + if (transport_work_requested()) { + _session.butler_transport_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; @@ -242,13 +270,13 @@ Butler::thread_work () } - if (i != dsl->begin() && 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; } if (!err && transport_work_requested()) { - continue; + goto restart; } if (compute_io) { @@ -264,18 +292,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; @@ -296,13 +329,13 @@ Butler::thread_work () _session.request_stop (); } - if (i != dsl->begin() && i != dsl->end()) { + if (i != rl->begin() && i != rl->end()) { /* we didn't get to all the streams */ disk_work_outstanding = true; } if (!err && transport_work_requested()) { - continue; + goto restart; } if (compute_io) { @@ -328,7 +361,7 @@ Butler::thread_work () // cerr << "AFTER " << (*i)->name() << ": pb = " << (*i)->playback_buffer_load() << " cp = " << (*i)->capture_buffer_load() << endl; // } - continue; + goto restart; } paused.signal(); @@ -353,7 +386,7 @@ void Butler::summon () { char c = Request::Run; - ::write (request_pipe[1], &c, 1); + (void) ::write (request_pipe[1], &c, 1); } void @@ -361,7 +394,7 @@ Butler::stop () { Glib::Mutex::Lock lm (request_lock); char c = Request::Pause; - ::write (request_pipe[1], &c, 1); + (void) ::write (request_pipe[1], &c, 1); paused.wait(request_lock); } @@ -370,7 +403,7 @@ Butler::wait_until_finished () { Glib::Mutex::Lock lm (request_lock); char c = Request::Wake; - ::write (request_pipe[1], &c, 1); + (void) ::write (request_pipe[1], &c, 1); paused.wait(request_lock); } @@ -428,5 +461,12 @@ Butler::empty_pool_trash () } } +void +Butler::drop_references () +{ + SessionEvent::pool->set_trash (0); +} + + } // namespace ARDOUR