projects
/
ardour.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merged with trunk R1705.
[ardour.git]
/
libs
/
ardour
/
session_butler.cc
diff --git
a/libs/ardour/session_butler.cc
b/libs/ardour/session_butler.cc
index df867c8267b4378110d5df01200bf30a17104480..afb284b0f49a4ab549eee18002894b8929c11e2f 100644
(file)
--- a/
libs/ardour/session_butler.cc
+++ b/
libs/ardour/session_butler.cc
@@
-15,7
+15,6
@@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id$
*/
#include <algorithm>
*/
#include <algorithm>
@@
-26,14
+25,15
@@
#include <fcntl.h>
#include <poll.h>
#include <fcntl.h>
#include <poll.h>
+#include <glibmm/thread.h>
+
#include <pbd/error.h>
#include <pbd/error.h>
-#include <pbd/lockmonitor.h>
#include <pbd/pthread_utils.h>
#include <ardour/configuration.h>
#include <ardour/audioengine.h>
#include <ardour/session.h>
#include <pbd/pthread_utils.h>
#include <ardour/configuration.h>
#include <ardour/audioengine.h>
#include <ardour/session.h>
-#include <ardour/diskstream.h>
+#include <ardour/
audio_
diskstream.h>
#include <ardour/crossfade.h>
#include <ardour/timestamps.h>
#include <ardour/crossfade.h>
#include <ardour/timestamps.h>
@@
-41,7
+41,7
@@
using namespace std;
using namespace ARDOUR;
using namespace std;
using namespace ARDOUR;
-
//using namespace sigc
;
+
using namespace PBD
;
static float _read_data_rate;
static float _write_data_rate;
static float _read_data_rate;
static float _write_data_rate;
@@
-69,12
+69,10
@@
Session::start_butler_thread ()
{
/* size is in Samples, not bytes */
{
/* size is in Samples, not bytes */
- dstream_buffer_size = (uint32_t) floor (Config->get_track_buffer() * (float) frame_rate());
+ dstream_buffer_size = (uint32_t) floor (Config->get_track_buffer
_seconds
() * (float) frame_rate());
Crossfade::set_buffer_size (dstream_buffer_size);
Crossfade::set_buffer_size (dstream_buffer_size);
- pthread_cond_init (&butler_paused, 0);
-
butler_should_run = false;
if (pipe (butler_request_pipe)) {
butler_should_run = false;
if (pipe (butler_request_pipe)) {
@@
-105,16
+103,18
@@
Session::start_butler_thread ()
void
Session::terminate_butler_thread ()
{
void
Session::terminate_butler_thread ()
{
- void* status;
- char c = ButlerRequest::Quit;
- ::write (butler_request_pipe[1], &c, 1);
- pthread_join (butler_thread, &status);
+ if (butler_thread) {
+ void* status;
+ char c = ButlerRequest::Quit;
+ ::write (butler_request_pipe[1], &c, 1);
+ pthread_join (butler_thread, &status);
+ }
}
void
Session::schedule_butler_transport_work ()
{
}
void
Session::schedule_butler_transport_work ()
{
-
atomic
_inc (&butler_should_do_transport_work);
+
g_atomic_int
_inc (&butler_should_do_transport_work);
summon_butler ();
}
summon_butler ();
}
@@
-135,32
+135,29
@@
Session::summon_butler ()
void
Session::stop_butler ()
{
void
Session::stop_butler ()
{
-
LockMonitor lm (butler_request_lock, __LINE__, __FILE__
);
+
Glib::Mutex::Lock lm (butler_request_lock
);
char c = ButlerRequest::Pause;
::write (butler_request_pipe[1], &c, 1);
char c = ButlerRequest::Pause;
::write (butler_request_pipe[1], &c, 1);
-
pthread_cond_wait (&butler_paused, butler_request_lock.mutex()
);
+
butler_paused.wait(butler_request_lock
);
}
void
Session::wait_till_butler_finished ()
{
}
void
Session::wait_till_butler_finished ()
{
-
LockMonitor lm (butler_request_lock, __LINE__, __FILE__
);
+
Glib::Mutex::Lock lm (butler_request_lock
);
char c = ButlerRequest::Wake;
::write (butler_request_pipe[1], &c, 1);
char c = ButlerRequest::Wake;
::write (butler_request_pipe[1], &c, 1);
-
pthread_cond_wait (&butler_paused, butler_request_lock.mutex()
);
+
butler_paused.wait(butler_request_lock
);
}
void *
Session::_butler_thread_work (void* arg)
{
PBD::ThreadCreated (pthread_self(), X_("Butler"));
}
void *
Session::_butler_thread_work (void* arg)
{
PBD::ThreadCreated (pthread_self(), X_("Butler"));
-
return ((Session *) arg)->butler_thread_work ();
return 0;
}
return ((Session *) arg)->butler_thread_work ();
return 0;
}
-#define transport_work_requested() atomic_read(&butler_should_do_transport_work)
-
void *
Session::butler_thread_work ()
{
void *
Session::butler_thread_work ()
{
@@
-170,13
+167,9
@@
Session::butler_thread_work ()
struct timeval begin, end;
struct pollfd pfd[1];
bool disk_work_outstanding = false;
struct timeval begin, end;
struct pollfd pfd[1];
bool disk_work_outstanding = false;
- DiskStreamList::iterator i;
-
- butler_mixdown_buffer = new Sample[DiskStream::disk_io_frames()];
- butler_gain_buffer = new gain_t[DiskStream::disk_io_frames()];
+ DiskstreamList::iterator i;
while (true) {
while (true) {
-
pfd[0].fd = butler_request_pipe[0];
pfd[0].events = POLLIN|POLLERR|POLLHUP;
pfd[0].fd = butler_request_pipe[0];
pfd[0].events = POLLIN|POLLERR|POLLHUP;
@@
-191,27
+184,27
@@
Session::butler_thread_work ()
<< endmsg;
break;
}
<< endmsg;
break;
}
-
+
if (pfd[0].revents & ~POLLIN) {
if (pfd[0].revents & ~POLLIN) {
- error <<
_("Error on butler thread request pipe"
) << endmsg;
+ error <<
string_compose (_("Error on butler thread request pipe: fd=%1 err=%2"), pfd[0].fd, pfd[0].revents
) << endmsg;
break;
}
if (pfd[0].revents & POLLIN) {
break;
}
if (pfd[0].revents & POLLIN) {
-
+
char req;
/* empty the pipe of all current requests */
while (1) {
size_t nread = ::read (butler_request_pipe[0], &req, sizeof (req));
char req;
/* empty the pipe of all current requests */
while (1) {
size_t nread = ::read (butler_request_pipe[0], &req, sizeof (req));
-
if (nread == 1) {
switch ((ButlerRequest::Type) req) {
case ButlerRequest::Wake:
break;
if (nread == 1) {
switch ((ButlerRequest::Type) req) {
case ButlerRequest::Wake:
break;
+
case ButlerRequest::Run:
butler_should_run = true;
break;
case ButlerRequest::Run:
butler_should_run = true;
break;
@@
-239,10
+232,10
@@
Session::butler_thread_work ()
}
}
}
}
}
}
-
-
// for (DiskStreamList::iterator
i = diskstreams.begin(); i != diskstreams.end(); ++i) {
-
//
cerr << "BEFORE " << (*i)->name() << ": pb = " << (*i)->playback_buffer_load() << " cp = " << (*i)->capture_buffer_load() << endl;
-
//
}
+
+
//for (
i = diskstreams.begin(); i != diskstreams.end(); ++i) {
+
//
cerr << "BEFORE " << (*i)->name() << ": pb = " << (*i)->playback_buffer_load() << " cp = " << (*i)->capture_buffer_load() << endl;
+
//
}
if (transport_work_requested()) {
butler_transport_work ();
if (transport_work_requested()) {
butler_transport_work ();
@@
-254,16
+247,18
@@
Session::butler_thread_work ()
gettimeofday (&begin, 0);
gettimeofday (&begin, 0);
- for (i = diskstreams.begin(); !transport_work_requested() && butler_should_run && i != diskstreams.end(); ++i) {
-
- // cerr << "rah fondr " << (*i)->io()->name () << endl;
+ boost::shared_ptr<DiskstreamList> dsl = diskstreams.reader ();
+
+ for (i = dsl->begin(); !transport_work_requested() && butler_should_run && i != dsl->end(); ++i) {
- switch ((*i)->do_refill (butler_mixdown_buffer, butler_gain_buffer)) {
+ boost::shared_ptr<Diskstream> ds = *i;
+
+ switch (ds->do_refill ()) {
case 0:
case 0:
- bytes +=
(*i)
->read_data_count();
+ bytes +=
ds
->read_data_count();
break;
case 1:
break;
case 1:
- bytes +=
(*i)
->read_data_count();
+ bytes +=
ds
->read_data_count();
disk_work_outstanding = true;
break;
disk_work_outstanding = true;
break;
@@
-275,7
+270,7
@@
Session::butler_thread_work ()
}
}
- if (i != d
iskstreams.
end()) {
+ if (i != d
sl->
end()) {
/* we didn't get to all the streams */
disk_work_outstanding = true;
}
/* we didn't get to all the streams */
disk_work_outstanding = true;
}
@@
-296,12
+291,11
@@
Session::butler_thread_work ()
bytes = 0;
compute_io = true;
gettimeofday (&begin, 0);
bytes = 0;
compute_io = true;
gettimeofday (&begin, 0);
-
- for (i = diskstreams.begin(); !transport_work_requested() && butler_should_run && i != diskstreams.end(); ++i) {
-
+
+ for (i = dsl->begin(); !transport_work_requested() && butler_should_run && i != dsl->end(); ++i) {
// cerr << "write behind for " << (*i)->name () << endl;
// cerr << "write behind for " << (*i)->name () << endl;
- switch ((*i)->do_flush ()) {
+ switch ((*i)->do_flush (
Session::ButlerContext
)) {
case 0:
bytes += (*i)->write_data_count();
break;
case 0:
bytes += (*i)->write_data_count();
break;
@@
-327,7
+321,7
@@
Session::butler_thread_work ()
request_stop ();
}
request_stop ();
}
- if (i != d
iskstreams.
end()) {
+ if (i != d
sl->
end()) {
/* we didn't get to all the streams */
disk_work_outstanding = true;
}
/* we didn't get to all the streams */
disk_work_outstanding = true;
}
@@
-351,17
+345,17
@@
Session::butler_thread_work ()
{
{
-
LockMonitor lm (butler_request_lock, __LINE__, __FILE__
);
+
Glib::Mutex::Lock lm (butler_request_lock
);
if (butler_should_run && (disk_work_outstanding || transport_work_requested())) {
if (butler_should_run && (disk_work_outstanding || transport_work_requested())) {
-// for (Disk
StreamList::iterator i = diskstreams.begin(); i != diskstreams.
end(); ++i) {
+// for (Disk
streamList::iterator i = dsl->begin(); i != dsl->
end(); ++i) {
// cerr << "AFTER " << (*i)->name() << ": pb = " << (*i)->playback_buffer_load() << " cp = " << (*i)->capture_buffer_load() << endl;
// }
continue;
}
// cerr << "AFTER " << (*i)->name() << ": pb = " << (*i)->playback_buffer_load() << " cp = " << (*i)->capture_buffer_load() << endl;
// }
continue;
}
-
pthread_cond_signal (&butler_paused
);
+
butler_paused.signal(
);
}
}
}
}
@@
-372,18
+366,17
@@
Session::butler_thread_work ()
void
void
-Session::request_overwrite_buffer (Disk
S
tream* stream)
+Session::request_overwrite_buffer (Disk
s
tream* stream)
{
Event *ev = new Event (Event::Overwrite, Event::Add, Event::Immediate, 0, 0, 0.0);
ev->set_ptr (stream);
queue_event (ev);
}
{
Event *ev = new Event (Event::Overwrite, Event::Add, Event::Immediate, 0, 0, 0.0);
ev->set_ptr (stream);
queue_event (ev);
}
+/** Process thread. */
void
void
-Session::overwrite_some_buffers (Disk
S
tream* ds)
+Session::overwrite_some_buffers (Disk
s
tream* ds)
{
{
- /* executed by the audio thread */
-
if (actively_recording()) {
return;
}
if (actively_recording()) {
return;
}
@@
-394,8
+387,8
@@
Session::overwrite_some_buffers (DiskStream* ds)
} else {
} else {
-
LockMonitor dm (diskstream_lock, __LINE__, __FILE__
);
- for (Disk
StreamList::iterator i = diskstreams.begin(); i != diskstreams.
end(); ++i) {
+
boost::shared_ptr<DiskstreamList> dsl = diskstreams.reader(
);
+ for (Disk
streamList::iterator i = dsl->begin(); i != dsl->
end(); ++i) {
(*i)->set_pending_overwrite (true);
}
}
(*i)->set_pending_overwrite (true);
}
}
@@
-425,36
+418,36
@@
Session::write_data_rate () const
uint32_t
Session::playback_load ()
{
uint32_t
Session::playback_load ()
{
- return (uint32_t)
atomic_read
(&_playback_load);
+ return (uint32_t)
g_atomic_int_get
(&_playback_load);
}
uint32_t
Session::capture_load ()
{
}
uint32_t
Session::capture_load ()
{
- return (uint32_t)
atomic_read
(&_capture_load);
+ return (uint32_t)
g_atomic_int_get
(&_capture_load);
}
uint32_t
Session::playback_load_min ()
{
}
uint32_t
Session::playback_load_min ()
{
- return (uint32_t)
atomic_read
(&_playback_load_min);
+ return (uint32_t)
g_atomic_int_get
(&_playback_load_min);
}
uint32_t
Session::capture_load_min ()
{
}
uint32_t
Session::capture_load_min ()
{
- return (uint32_t)
atomic_read
(&_capture_load_min);
+ return (uint32_t)
g_atomic_int_get
(&_capture_load_min);
}
void
Session::reset_capture_load_min ()
{
}
void
Session::reset_capture_load_min ()
{
-
atomic
_set (&_capture_load_min, 100);
+
g_atomic_int
_set (&_capture_load_min, 100);
}
void
Session::reset_playback_load_min ()
{
}
void
Session::reset_playback_load_min ()
{
-
atomic
_set (&_playback_load_min, 100);
+
g_atomic_int
_set (&_playback_load_min, 100);
}
}