patch proposed by issue 21 revising realtime priority for jack input applied

This commit is contained in:
rafael@riseup.net 2010-07-19 20:42:43 +00:00
parent a6c6389cd7
commit 62a088d81b
4 changed files with 24 additions and 2 deletions

View File

@ -6,6 +6,8 @@
duration = 60 # duration of encoding, in seconds. 0 means forever duration = 60 # duration of encoding, in seconds. 0 means forever
bufferSecs = 5 # size of internal slip buffer, in seconds bufferSecs = 5 # size of internal slip buffer, in seconds
reconnect = yes # reconnect to the server(s) if disconnected reconnect = yes # reconnect to the server(s) if disconnected
realtime = yes # run the encoder with POSIX realtime priority
rtprio = 3 # scheduling priority for the realtime threads
# this section describes the audio input that will be streamed # this section describes the audio input that will be streamed
[input] [input]

View File

@ -62,6 +62,10 @@ streaming, "yes" or "no". (optional parameter, defaults to "yes")
.I realtime .I realtime
Use POSIX realtime scheduling, "yes" or "no". Use POSIX realtime scheduling, "yes" or "no".
(optional parameter, defaults to "yes") (optional parameter, defaults to "yes")
.TP
.I rtprio
Scheduling priority for the realtime threads.
(optional parameter, defaults to 4)
.PP .PP

View File

@ -164,6 +164,13 @@ DarkIce :: init ( const Config & config ) throw ( Exception )
str = cs->get( "realtime" ); str = cs->get( "realtime" );
enableRealTime = str ? (Util::strEq( str, "yes") ? true : false) : true; enableRealTime = str ? (Util::strEq( str, "yes") ? true : false) : true;
// get realtime scheduling priority. If unspecified, set it to 4.
// Why 4? jackd's default priority is 10, jackd client threads run
// at 5, so make the encoder thread use 4. jackd automatically sets
// the process callback priority to the right value, so all we have
// to care about is the encoder priority.
str = cs->get( "rtprio" );
realTimeSchedPriority = (str != NULL) ? Util::strToL( str ) : 4;
// the [input] section // the [input] section
if ( !(cs = config.get( "input")) ) { if ( !(cs = config.get( "input")) ) {
@ -1111,13 +1118,17 @@ DarkIce :: setRealTimeScheduling ( void ) throw ( Exception )
} }
origSchedPriority = param.sched_priority; origSchedPriority = param.sched_priority;
/* set SCHED_FIFO with max - 1 priority */ /* set SCHED_FIFO with max - 1 priority or user configured value */
if ( (high_priority = sched_get_priority_max(SCHED_FIFO)) == -1 ) { if ( (high_priority = sched_get_priority_max(SCHED_FIFO)) == -1 ) {
throw Exception(__FILE__,__LINE__,"sched_get_priority_max",errno); throw Exception(__FILE__,__LINE__,"sched_get_priority_max",errno);
} }
reportEvent( 8, "scheduler high priority", high_priority); reportEvent( 8, "scheduler high priority", high_priority);
if (realTimeSchedPriority > high_priority) {
param.sched_priority = high_priority - 1; param.sched_priority = high_priority - 1;
} else {
param.sched_priority = realTimeSchedPriority;
}
if ( sched_setscheduler( 0, SCHED_FIFO, &param) == -1 ) { if ( sched_setscheduler( 0, SCHED_FIFO, &param) == -1 ) {
reportEvent( 1, reportEvent( 1,

View File

@ -124,6 +124,11 @@ class DarkIce : public virtual Referable, public virtual Reporter
*/ */
int enableRealTime; int enableRealTime;
/**
* Scheduling priority for the realtime threads
*/
int realTimeSchedPriority;
/** /**
* Original scheduling policy * Original scheduling policy
*/ */