added option to turn off automatic reconnect feature

This commit is contained in:
darkeye 2005-04-11 19:27:43 +00:00
parent 028f6d98fd
commit 426a126181
6 changed files with 63 additions and 19 deletions

View File

@ -8,6 +8,7 @@ DarkIce next release
including support for MacOS X.
Thanks to Nicholas J. Humfrey <njh@ecs.soton.ac.uk>
o various improvements by Joel Ebel <jbebel@ncsu.edu>
o added option to turn off automatic reconnect feature
15-02-2004: DarkIce 0.14 released

View File

@ -5,6 +5,7 @@
[general]
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
# this section describes the audio input that will be streamed
[input]

View File

@ -50,6 +50,10 @@ Time for DarkIce to run, in seconds. If 0, run forever.
Data read from the sound card is buffered before sent to
the encoder. Each buffer will be able to hold this
many seconds of samples.
.TP
.I reconnect
Try to reconnect to the server(s) if the connection is broken during
streaming, "yes" or "no". (optional parameter, defaults to "yes")
.PP
.B [input]

View File

@ -129,6 +129,7 @@ DarkIce :: init ( const Config & config ) throw ( Exception )
unsigned int sampleRate;
unsigned int bitsPerSample;
unsigned int channel;
bool reconnect;
const char * device;
// the [general] section
@ -139,6 +140,8 @@ DarkIce :: init ( const Config & config ) throw ( Exception )
duration = Util::strToL( str);
str = cs->getForSure( "bufferSecs", " missing in section [general]");
bufferSecs = Util::strToL( str);
str = cs->get( "reconnect");
reconnect = str ? (Util::strEq( str, "yes") ? true : false) : true;
// the [input] section
@ -146,19 +149,19 @@ DarkIce :: init ( const Config & config ) throw ( Exception )
throw Exception( __FILE__, __LINE__, "no section [general] in config");
}
str = cs->getForSure( "sampleRate", " missing in section [input]");
str = cs->getForSure( "sampleRate", " missing in section [input]");
sampleRate = Util::strToL( str);
str = cs->getForSure( "bitsPerSample", " missing in section [input]");
str = cs->getForSure( "bitsPerSample", " missing in section [input]");
bitsPerSample = Util::strToL( str);
str = cs->getForSure( "channel", " missing in section [input]");
channel = Util::strToL( str);
device = cs->getForSure( "device", " missing in section [input]");
str = cs->getForSure( "channel", " missing in section [input]");
channel = Util::strToL( str);
device = cs->getForSure( "device", " missing in section [input]");
dsp = AudioSource::createDspSource( device,
sampleRate,
bitsPerSample,
channel );
encConnector = new MultiThreadedConnector( dsp.get());
encConnector = new MultiThreadedConnector( dsp.get(), reconnect );
noAudioOuts = 0;
configIceCast( config, bufferSecs);
@ -1008,6 +1011,9 @@ DarkIce :: run ( void ) throw ( Exception )
$Source$
$Log$
Revision 1.43 2005/04/11 19:27:43 darkeye
added option to turn off automatic reconnect feature
Revision 1.42 2005/04/04 08:36:17 darkeye
commited changes to enable Jack support
thanks to Nicholas J. Humfrey, njh@ecs.soton.ac.uk

View File

@ -64,8 +64,10 @@ static const char fileid[] = "$Id$";
* Initialize the object
*----------------------------------------------------------------------------*/
void
MultiThreadedConnector :: init ( void ) throw ( Exception )
MultiThreadedConnector :: init ( bool reconnect ) throw ( Exception )
{
this->reconnect = reconnect;
pthread_mutex_init( &mutexProduce, 0);
pthread_cond_init( &condProduce, 0);
threads = 0;
@ -96,6 +98,7 @@ MultiThreadedConnector :: MultiThreadedConnector (
throw ( Exception )
: Connector( connector)
{
reconnect = connector.reconnect;
mutexProduce = connector.mutexProduce;
condProduce = connector.condProduce;
@ -119,6 +122,7 @@ MultiThreadedConnector :: operator= ( const MultiThreadedConnector & connector )
if ( this != &connector ) {
Connector::operator=( connector);
reconnect = connector.reconnect;
mutexProduce = connector.mutexProduce;
condProduce = connector.condProduce;
@ -310,13 +314,18 @@ MultiThreadedConnector :: sinkThread( int ixSink )
pthread_mutex_unlock( &mutexProduce);
if ( !threadData->accepting ) {
// if we're not accepting, try to reopen the sink
try {
sink->close();
sink->open();
threadData->accepting = sink->isOpen();
} catch ( Exception & e ) {
// don't care, just try and try again
if ( reconnect ) {
// if we're not accepting, try to reopen the sink
try {
sink->close();
sink->open();
threadData->accepting = sink->isOpen();
} catch ( Exception & e ) {
// don't care, just try and try again
}
} else {
// if !reconnect, just stop the connector
running = false;
}
}
}
@ -366,6 +375,9 @@ MultiThreadedConnector :: ThreadData :: threadFunction( void * param )
$Source$
$Log$
Revision 1.5 2005/04/11 19:27:43 darkeye
added option to turn off automatic reconnect feature
Revision 1.4 2004/01/07 13:18:17 darkeye
commited patch sent by John Hay, fixing FreeBSD problems

View File

@ -156,6 +156,12 @@ class MultiThreadedConnector : public virtual Connector
*/
bool running;
/**
* Flag to show if the connector should try to reconnect if
* the connection is dropped on the other side.
*/
bool reconnect;
/**
* The buffer of information presented to each thread.
*/
@ -169,10 +175,13 @@ class MultiThreadedConnector : public virtual Connector
/**
* Initialize the object.
*
* @param reconnect flag to indicate if the connector should
* try to reconnect if the connection was
* dropped by the other end
* @exception Exception
*/
void
init ( void ) throw ( Exception );
init ( bool reconnect ) throw ( Exception );
/**
* De-initialize the object.
@ -202,14 +211,18 @@ class MultiThreadedConnector : public virtual Connector
* Constructor based on a Source.
*
* @param source the source to connect to the sinks.
* @param reconnect flag to indicate if the connector should
* try to reconnect if the connection was
* dropped by the other end
* @exception Exception
*/
inline
MultiThreadedConnector ( Source * source )
MultiThreadedConnector ( Source * source,
bool reconnect )
throw ( Exception )
: Connector( source )
{
init();
init(reconnect);
}
/**
@ -217,15 +230,19 @@ class MultiThreadedConnector : public virtual Connector
*
* @param source the source to connect to the sinks.
* @param sink a sink to connect to the source.
* @param reconnect flag to indicate if the connector should
* try to reconnect if the connection was
* dropped by the other end
* @exception Exception
*/
inline
MultiThreadedConnector ( Source * source,
Sink * sink )
Sink * sink,
bool reconnect )
throw ( Exception )
: Connector( source, sink)
{
init();
init(reconnect);
}
/**
@ -330,6 +347,9 @@ class MultiThreadedConnector : public virtual Connector
$Source$
$Log$
Revision 1.5 2005/04/11 19:27:43 darkeye
added option to turn off automatic reconnect feature
Revision 1.4 2004/02/23 19:12:52 darkeye
ported to NetBSD