X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fsurfaces%2Ftranzport%2Finit.cc;h=56501b2c2cbb8d38e0c878670057bb0f2258595f;hb=e9013c0f99a3f16097800276241e8363fda33e8f;hp=910d37a5de3c54535b4c10518f3592471197adf8;hpb=4a3d7877f6b03fac7755f997b945583ba5732d13;p=ardour.git diff --git a/libs/surfaces/tranzport/init.cc b/libs/surfaces/tranzport/init.cc index 910d37a5de..56501b2c2c 100644 --- a/libs/surfaces/tranzport/init.cc +++ b/libs/surfaces/tranzport/init.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006 Paul Davis + * Copyright (C) 2006 Paul Davis * Copyright (C) 2007 Michael Taht * * This program is free software; you can redistribute it and/or modify @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * + * */ #include @@ -26,7 +26,7 @@ using namespace std; using namespace sigc; using namespace PBD; -#include "i18n.h" +#include "pbd/i18n.h" #include @@ -41,35 +41,31 @@ TranzportControlProtocol::~TranzportControlProtocol () set_active (false); } -int TranzportControlProtocol::rtpriority_set(int priority) +int TranzportControlProtocol::rtpriority_set(int priority) { - struct sched_param rtparam; - int err; char *a = (char*) alloca(4096*2); a[0] = 'a'; a[4096] = 'b'; - memset (&rtparam, 0, sizeof (rtparam)); - rtparam.sched_priority = priority; /* XXX should be relative to audio (JACK) thread */ - // Note - try SCHED_RR with a low limit + // Note - try SCHED_RR with a low limit // - we don't care if we can't write everything this ms // and it will help if we lose the device - if ((err = pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam)) != 0) { - PBD::info << string_compose (_("%1: thread not running with realtime scheduling (%2)"), name(), strerror (errno)) << endmsg; + if (set_thread_priority (SCHED_FIFO, priority)) { + PBD::info << string_compose (_("%1: thread not running with realtime scheduling."), name(), strerror (errno)) << endmsg; return 1; - } + } return 0; } // Running with realtime privs is bad when you have problems -int TranzportControlProtocol::rtpriority_unset(int priority) +int TranzportControlProtocol::rtpriority_unset(int priority) { struct sched_param rtparam; int err; memset (&rtparam, 0, sizeof (rtparam)); - rtparam.sched_priority = priority; + rtparam.sched_priority = priority; if ((err = pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam)) != 0) { PBD::info << string_compose (_("%1: can't stop realtime scheduling (%2)"), name(), strerror (errno)) << endmsg; return 1; - } + } PBD::info << string_compose (_("%1: realtime scheduling stopped (%2)"), name(), strerror (errno)) << endmsg; return 0; } @@ -86,18 +82,8 @@ TranzportControlProtocol::set_active (bool yn) return -1; } - if (pthread_create_and_store (X_("tranzport monitor"), &thread, 0, _monitor_work, this) == 0) { + if (pthread_create_and_store (X_("tranzport monitor"), &thread, _monitor_work, this) == 0) { _active = true; -#if TRANZPORT_THREADS - if (pthread_create_and_store (X_("tranzport read"), &thread_read, 0, _read_work, this) == 0) { - _active_read = true; - if (pthread_create_and_store (X_("tranzport write"), &thread_write, 0, _write_work, this) == 0) { - _active_write = true; - if (pthread_create_and_store (X_("tranzport process"), &thread_process, 0, _process_work, this) == 0) { - _active_process = true; - if (pthread_create_and_store (X_("tranzport timer"), &thread_timer, 0, _process_timer, this) == 0) { - _active_process = true; -#endif } else { return -1; } @@ -112,19 +98,14 @@ TranzportControlProtocol::set_active (bool yn) // thread FIXME - wait til all writes are done for(int x = 0; (x < 20/MAX_TRANZPORT_INFLIGHT) && flush(); x++) { usleep(100); } } -#if TRANZPORT_THREADS - pthread_cancel_one (_thread_timer); - pthread_cancel_one (_thread_process); - pthread_cancel_one (_thread_read); - pthread_cancel_one (_thread_write); -#endif + pthread_cancel_one (thread); cerr << "Tranzport Thread dead\n"; close (); _active = false; cerr << "End tranzport shutdown\n"; - } + } } return 0; @@ -142,7 +123,7 @@ TranzportControlProtocol::TranzportControlProtocol (Session& s) _device_status = STATUS_OFFLINE; udev = 0; current_track_id = 0; - last_where = max_frames; + last_where = max_samples; wheel_mode = WheelTimeline; wheel_shift_mode = WheelShiftGain; wheel_increment = WheelIncrScreen; @@ -206,13 +187,13 @@ TranzportControlProtocol::monitor_work () /* bInterval for this beastie is 10ms */ if (_device_status == STATUS_OFFLINE) { - first_time = true; offline++; + first_time = true; offline++; #if TRANZPORT_DEBUG > 3 - if(offline == 1) { + if(offline == 1) { cerr << "Transport has gone offline\n"; } #endif - } else { + } else { offline = 0; // hate writing this } unsigned int s = (last_write_error == 0) | ((last_read_error == 0) << 1); @@ -223,7 +204,7 @@ TranzportControlProtocol::monitor_work () case 3: val = read(buf,DEFAULT_USB_TIMEOUT*2); break; // Hoo, boy, we're in trouble default: break; // not reached } - + #if DEBUG_TRANZPORT_BITS > 9 if(_device_status != STATUS_OFFLINE && _device_status != STATUS_ONLINE && _device_status != STATUS_OK) { printf("The device has more status bits than off or online: %d\n",_device_status); @@ -233,8 +214,8 @@ TranzportControlProtocol::monitor_work () #if DEBUG_TRANZPORT_BITS > 99 if (val != 8) { printf("val = %d errno = %d\n",val,errno); - buf[0] = buf[1] = buf[2] = buf[3] = - buf[4] = buf[5] = buf[6] = buf[7] = + buf[0] = buf[1] = buf[2] = buf[3] = + buf[4] = buf[5] = buf[6] = buf[7] = buf[8] = 0; } #endif @@ -261,44 +242,44 @@ TranzportControlProtocol::monitor_work () #if DEBUG_TRANZPORT_BITS > 10 // Perhaps an online message indicates something - if(_device_status != buf[1]) { - printf("WTF- val: %d, device status != buf! %d != %d \n",val,_device_status,buf[1]); _device_status = buf[1]; + if(_device_status != buf[1]) { + printf("WTF- val: %d, device status != buf! %d != %d \n",val,_device_status,buf[1]); _device_status = buf[1]; } #endif - + } - + #if DEBUG_TRANZPORT_BITS > 10 if(val == 8) { if(_device_status == STATUS_ONLINE) { - printf("ONLINE : %02x %02x %02x %02x %02x %02x %02x %02x\n", - buf[0],buf[1],buf[2], buf[3], buf[4], buf[5],buf[6],buf[7]); + printf("ONLINE : %02x %02x %02x %02x %02x %02x %02x %02x\n", + buf[0],buf[1],buf[2], buf[3], buf[4], buf[5],buf[6],buf[7]); } if(_device_status == STATUS_OFFLINE) { - printf("OFFLINE : %02x %02x %02x %02x %02x %02x %02x %02x\n", - buf[0],buf[1],buf[2], buf[3], buf[4], buf[5],buf[6],buf[7]); + printf("OFFLINE : %02x %02x %02x %02x %02x %02x %02x %02x\n", + buf[0],buf[1],buf[2], buf[3], buf[4], buf[5],buf[6],buf[7]); } - + if(_device_status == STATUS_OK) { - printf("OK : %02x %02x %02x %02x %02x %02x %02x %02x\n", - buf[0],buf[1],buf[2], buf[3], buf[4], buf[5],buf[6],buf[7]); + printf("OK : %02x %02x %02x %02x %02x %02x %02x %02x\n", + buf[0],buf[1],buf[2], buf[3], buf[4], buf[5],buf[6],buf[7]); } - + } - + #endif - + /* update whatever needs updating */ - if(last_write_error == 0 && (_device_status == STATUS_ONLINE || _device_status == STATUS_OK)) { + if(last_write_error == 0 && (_device_status == STATUS_ONLINE || _device_status == STATUS_OK)) { update_state (); - + /* still struggling with a good means of exerting flow control without having to create threads */ // pending = flush(); - + if(pending == 0) { - pending = flush(); + pending = flush(); } else { if(inflight > 0) { pending = --inflight; // we just did a whole bunch of writes so wait @@ -308,7 +289,7 @@ TranzportControlProtocol::monitor_work () } } // pending = 0; - } + } return (void*) 0; }