From 62a088d81bcb5b07e23d18ea51fdcc6743955fa7 Mon Sep 17 00:00:00 2001 From: "rafael@riseup.net" Date: Mon, 19 Jul 2010 20:42:43 +0000 Subject: [PATCH] patch proposed by issue 21 revising realtime priority for jack input applied --- darkice/trunk/darkice.cfg | 2 ++ darkice/trunk/man/darkice.cfg.5 | 4 ++++ darkice/trunk/src/DarkIce.cpp | 15 +++++++++++++-- darkice/trunk/src/DarkIce.h | 5 +++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/darkice/trunk/darkice.cfg b/darkice/trunk/darkice.cfg index 0c7f935..4ccf1c6 100644 --- a/darkice/trunk/darkice.cfg +++ b/darkice/trunk/darkice.cfg @@ -6,6 +6,8 @@ duration = 60 # duration of encoding, in seconds. 0 means forever bufferSecs = 5 # size of internal slip buffer, in seconds 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 [input] diff --git a/darkice/trunk/man/darkice.cfg.5 b/darkice/trunk/man/darkice.cfg.5 index 37ffba9..18396c6 100644 --- a/darkice/trunk/man/darkice.cfg.5 +++ b/darkice/trunk/man/darkice.cfg.5 @@ -62,6 +62,10 @@ streaming, "yes" or "no". (optional parameter, defaults to "yes") .I realtime Use POSIX realtime scheduling, "yes" or "no". (optional parameter, defaults to "yes") +.TP +.I rtprio +Scheduling priority for the realtime threads. +(optional parameter, defaults to 4) .PP diff --git a/darkice/trunk/src/DarkIce.cpp b/darkice/trunk/src/DarkIce.cpp index 4267100..09eb5cb 100644 --- a/darkice/trunk/src/DarkIce.cpp +++ b/darkice/trunk/src/DarkIce.cpp @@ -164,6 +164,13 @@ DarkIce :: init ( const Config & config ) throw ( Exception ) str = cs->get( "realtime" ); 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 if ( !(cs = config.get( "input")) ) { @@ -1111,13 +1118,17 @@ DarkIce :: setRealTimeScheduling ( void ) throw ( Exception ) } 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 ) { throw Exception(__FILE__,__LINE__,"sched_get_priority_max",errno); } reportEvent( 8, "scheduler high priority", high_priority); - param.sched_priority = high_priority - 1; + if (realTimeSchedPriority > high_priority) { + param.sched_priority = high_priority - 1; + } else { + param.sched_priority = realTimeSchedPriority; + } if ( sched_setscheduler( 0, SCHED_FIFO, ¶m) == -1 ) { reportEvent( 1, diff --git a/darkice/trunk/src/DarkIce.h b/darkice/trunk/src/DarkIce.h index f8f1f21..4f9ee96 100644 --- a/darkice/trunk/src/DarkIce.h +++ b/darkice/trunk/src/DarkIce.h @@ -124,6 +124,11 @@ class DarkIce : public virtual Referable, public virtual Reporter */ int enableRealTime; + /** + * Scheduling priority for the realtime threads + */ + int realTimeSchedPriority; + /** * Original scheduling policy */