X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fbutler.cc;h=62f3a525ea82582c8dc866a627d0ef715a0de2e3;hb=f269e39115934c8e48dbc66e495d8cfdba1e70f0;hp=f8f8c83eba55179e8c8087b0953a880717a6a13d;hpb=46c83693284ece4a732d26e62113ea4ac584d539;p=ardour.git diff --git a/libs/ardour/butler.cc b/libs/ardour/butler.cc index f8f8c83eba..62f3a525ea 100644 --- a/libs/ardour/butler.cc +++ b/libs/ardour/butler.cc @@ -106,12 +106,12 @@ Butler::start_thread() { // set up capture and playback buffering Diskstream::set_buffering_parameters (Config->get_buffering_preset()); - + /* size is in Samples, not bytes */ const float rate = (float)_session.frame_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: AudioEngine needs to tell us the MIDI buffer size * (i.e. how many MIDI bytes we might see in a cycle) @@ -129,11 +129,11 @@ Butler::start_thread() //pthread_detach (thread); have_thread = true; - + // we are ready to request buffer adjustments _session.adjust_capture_buffering (); _session.adjust_playback_buffering (); - + return 0; } @@ -198,7 +198,7 @@ Butler::thread_work () } } - + restart: DEBUG_TRACE (DEBUG::Butler, "at restart for disk work\n"); disk_work_outstanding = false; @@ -215,6 +215,7 @@ Butler::thread_work () boost::shared_ptr tr = boost::dynamic_pointer_cast (_session.the_auditioner()); DEBUG_TRACE (DEBUG::Butler, "seek the auditioner\n"); tr->seek(audition_seek); + tr->do_refill (); _session.the_auditioner()->seek_response(audition_seek); } @@ -243,7 +244,7 @@ Butler::thread_work () case 0: DEBUG_TRACE (DEBUG::Butler, string_compose ("\ttrack refill done %1\n", tr->name())); break; - + case 1: DEBUG_TRACE (DEBUG::Butler, string_compose ("\ttrack refill unfinished %1\n", tr->name())); disk_work_outstanding = true; @@ -267,44 +268,7 @@ Butler::thread_work () goto restart; } - 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 - */ - - gint64 before, after; - int ret; - - DEBUG_TRACE (DEBUG::Butler, string_compose ("butler flushes track %1 capture load %2\n", tr->name(), tr->capture_buffer_load())); - before = g_get_monotonic_time (); - ret = tr->do_flush (ButlerContext); - after = g_get_monotonic_time (); - switch (ret) { - case 0: - DEBUG_TRACE (DEBUG::Butler, string_compose ("\tflush complete for %1, %2 usecs\n", tr->name(), after - before)); - break; - - case 1: - DEBUG_TRACE (DEBUG::Butler, string_compose ("\tflush not finished for %1, %2 usecs\n", tr->name(), after - before)); - disk_work_outstanding = true; - break; - - default: - err++; - error << string_compose(_("Butler write-behind failure on dstream %1"), (*i)->name()) << endmsg; - std::cerr << string_compose(_("Butler write-behind failure on dstream %1"), (*i)->name()) << std::endl; - /* don't break - try to flush all streams in case they - are split across disks. - */ - } - } + disk_work_outstanding = flush_tracks_to_disk_normal (rl, err); if (err && _session.actively_recording()) { /* stop the transport and try to catch as much possible @@ -314,12 +278,6 @@ Butler::thread_work () _session.request_stop (); } - if (i != rl->begin() && i != rl->end()) { - /* we didn't get to all the streams */ - DEBUG_TRACE (DEBUG::Butler, "not all tracks processed, will need to go back for more\n"); - disk_work_outstanding = true; - } - if (!err && transport_work_requested()) { DEBUG_TRACE (DEBUG::Butler, "transport work requested during flush, back to restart\n"); goto restart; @@ -329,7 +287,6 @@ Butler::thread_work () _session.refresh_disk_space (); } - { Glib::Threads::Mutex::Lock lm (request_lock); @@ -350,6 +307,100 @@ Butler::thread_work () return (0); } +bool +Butler::flush_tracks_to_disk_normal (boost::shared_ptr rl, uint32_t& errors) +{ + bool disk_work_outstanding = false; + + for (RouteList::iterator 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 + */ + + int ret; + + DEBUG_TRACE (DEBUG::Butler, string_compose ("butler flushes track %1 capture load %2\n", tr->name(), tr->capture_buffer_load())); + ret = tr->do_flush (ButlerContext, false); + switch (ret) { + case 0: + DEBUG_TRACE (DEBUG::Butler, string_compose ("\tflush complete for %1\n", tr->name())); + break; + + case 1: + DEBUG_TRACE (DEBUG::Butler, string_compose ("\tflush not finished for %1\n", tr->name())); + disk_work_outstanding = true; + break; + + default: + errors++; + error << string_compose(_("Butler write-behind failure on dstream %1"), (*i)->name()) << endmsg; + std::cerr << string_compose(_("Butler write-behind failure on dstream %1"), (*i)->name()) << std::endl; + /* don't break - try to flush all streams in case they + are split across disks. + */ + } + } + + return disk_work_outstanding; +} + +bool +Butler::flush_tracks_to_disk_after_locate (boost::shared_ptr rl, uint32_t& errors) +{ + bool disk_work_outstanding = false; + + /* almost the same as the "normal" version except that we do not test + * for transport_work_requested() and we force flushes. + */ + + for (RouteList::iterator i = rl->begin(); 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 + */ + + int ret; + + DEBUG_TRACE (DEBUG::Butler, string_compose ("butler flushes track %1 capture load %2\n", tr->name(), tr->capture_buffer_load())); + ret = tr->do_flush (ButlerContext, true); + switch (ret) { + case 0: + DEBUG_TRACE (DEBUG::Butler, string_compose ("\tflush complete for %1\n", tr->name())); + break; + + case 1: + DEBUG_TRACE (DEBUG::Butler, string_compose ("\tflush not finished for %1\n", tr->name())); + disk_work_outstanding = true; + break; + + default: + errors++; + error << string_compose(_("Butler write-behind failure on dstream %1"), (*i)->name()) << endmsg; + std::cerr << string_compose(_("Butler write-behind failure on dstream %1"), (*i)->name()) << std::endl; + /* don't break - try to flush all streams in case they + are split across disks. + */ + } + } + + return disk_work_outstanding; +} + void Butler::schedule_transport_work () {