Fix delay on closing portaudio DataSource. If portaudio binary is missing this prevents loading neomedia service, its now fixed.

cusax-fix
Damian Minkov 16 years ago
parent 24a6c03903
commit 6cbb790186

@ -1,9 +1,9 @@
1. portaudio
- Linux
$./configure --enable-static --disable-shared --with-jack=no & make
$./configure --enable-static --disable-shared --with-jack=no && make
- Linux amd64
./configure --enable-static --disable-shared --with-pic --with-jack=no & make
./configure --enable-static --disable-shared --with-pic --with-jack=no && make
- Mac OS X
$./configure --enable-static --disable-shared && make

@ -222,12 +222,38 @@ else if (audioCaptureDevices.length < 1)
+ " capture devices: " + audioCaptureDevices);
String audioDevName = config.getString(PROP_AUDIO_DEVICE);
boolean errorStartingPA = false;
try
{
// as here is the first entry when starting up
// we will create the instance of portaudio manager
// and if there are exceptions like missing binary
// will be back to javasound
// this will create portaudio instance
PortAudioManager.getInstance().isEnabledEchoCancel();
}
catch (Throwable e)
{
errorStartingPA = true;
}
if(audioDevName == null)
{
// the default behaviour if nothing set is to use javasound
// this will also choose the capture device
setAudioSystem(AUDIO_SYSTEM_PORTAUDIO, null, false);
if(!errorStartingPA)
{
setAudioSystem(AUDIO_SYSTEM_PORTAUDIO, null, false);
}
else
{
setAudioPlaybackDevice(null, false);
setAudioNotifyDevice(null, false);
setAudioCaptureDevice(null, false);
setAudioSystem(AUDIO_SYSTEM_JAVASOUND, null, false);
}
}
else
{
@ -241,11 +267,11 @@ else if (audioCaptureDevices.length < 1)
}
}
if(getAudioSystem() == null)
if(getAudioSystem() == null || errorStartingPA)
{
logger.warn("Computer sound config changed or " +
"there is a problem since last config was saved, " +
"will back to default javasound");
"will back to javasound");
setAudioPlaybackDevice(null, false);
setAudioNotifyDevice(null, false);
setAudioCaptureDevice(null, false);
@ -257,39 +283,42 @@ else if (audioCaptureDevices.length < 1)
+ " as an audio capture device.");
// now extract other sound related configs
try
if(!errorStartingPA)
{
boolean echoCancelEnabled =
config.getBoolean(PROP_AUDIO_ECHOCANCEL_ENABLED,
PortAudioManager.getInstance().isEnabledEchoCancel());
if(echoCancelEnabled)
try
{
int echoCancelTail =
config.getInt(PROP_AUDIO_ECHOCANCEL_TAIL,
PortAudioManager.getInstance().getFilterLength());
PortAudioManager.getInstance().setEchoCancel(
echoCancelEnabled,
PortAudioManager.getInstance().getFrameSize(),
echoCancelTail);
}
boolean echoCancelEnabled =
config.getBoolean(PROP_AUDIO_ECHOCANCEL_ENABLED,
PortAudioManager.getInstance().isEnabledEchoCancel());
if(echoCancelEnabled)
{
int echoCancelTail =
config.getInt(PROP_AUDIO_ECHOCANCEL_TAIL,
PortAudioManager.getInstance().getFilterLength());
PortAudioManager.getInstance().setEchoCancel(
echoCancelEnabled,
PortAudioManager.getInstance().getFrameSize(),
echoCancelTail);
}
boolean denoiseEnabled =
config.getBoolean(PROP_AUDIO_DENOISE_ENABLED,
PortAudioManager.getInstance().isEnabledDeNoise());
PortAudioManager.getInstance().setDeNoise(denoiseEnabled);
// suggested latency is saved in configuration as
// milliseconds but PortAudioManager use it as seconds
int audioLatency = config.getInt(PROP_AUDIO_LATENCY,
(int)(PortAudioManager.getSuggestedLatency()*1000));
if(audioLatency !=
(int)PortAudioManager.getSuggestedLatency()*1000)
PortAudioManager.setSuggestedLatency(
(double)audioLatency/1000d);
}
catch (Exception e)
{
logger.error("Error parsing audio config", e);
boolean denoiseEnabled =
config.getBoolean(PROP_AUDIO_DENOISE_ENABLED,
PortAudioManager.getInstance().isEnabledDeNoise());
PortAudioManager.getInstance().setDeNoise(denoiseEnabled);
// suggested latency is saved in configuration as
// milliseconds but PortAudioManager use it as seconds
int audioLatency = config.getInt(PROP_AUDIO_LATENCY,
(int)(PortAudioManager.getSuggestedLatency()*1000));
if(audioLatency !=
(int)PortAudioManager.getSuggestedLatency()*1000)
PortAudioManager.setSuggestedLatency(
(double)audioLatency/1000d);
}
catch (Exception e)
{
logger.error("Error parsing audio config", e);
}
}
}

@ -14,7 +14,14 @@ public final class PortAudio
{
static
{
System.loadLibrary("jportaudio");
try
{
System.loadLibrary("jportaudio");
}
catch (Throwable e)
{
System.out.println("Missing portaudio binary");
}
}
/**

@ -78,6 +78,7 @@ public synchronized void stop()
{
if(started)
{
parentStream.setStopping(true);
parentStream.stop(this);
started = false;
}

@ -58,6 +58,15 @@ public class MasterPortAudioStream
*/
private Object connectedToStreamSync = new Object();
/**
* Other using MasterPortAudioStream may inform us that will stop us.
* This is unprotected field which will stop any further reading,
* as read is synchronized sometimes there maybe some delay
* before we are stopped, as reading is too aggressive stopping thread may
* even wait more than 20 seconds.
*/
private boolean stopping = false;
/**
* The <tt>InputPortAudioStream</tt>s which read audio from this
* <tt>MasterPortAudioStream</tt>s.
@ -169,6 +178,7 @@ synchronized void stop(InputPortAudioStream slave)
PortAudio.Pa_CloseStream(stream);
stream = 0;
started = false;
stopping = false;
PortAudioManager.getInstance().stoppedInputPortAudioStream(this);
}
}
@ -197,24 +207,30 @@ public long getStream()
* @return the bytes that a read from underlying stream.
* @throws PortAudioException if an error occurs while reading.
*/
public synchronized byte[] read()
public byte[] read()
throws PortAudioException
{
if(!started)
if(stopping)
return new byte[0];
byte[] bytebuff = new byte[PortAudioManager.NUM_SAMPLES*frameSize];
synchronized(connectedToStreamSync)
synchronized(this)
{
PortAudio.Pa_ReadStream(
stream, bytebuff, PortAudioManager.NUM_SAMPLES);
}
if(!started)
return new byte[0];
byte[] bytebuff = new byte[PortAudioManager.NUM_SAMPLES*frameSize];
for(InputPortAudioStream slave : slaves)
slave.setBuffer(bytebuff);
synchronized(connectedToStreamSync)
{
PortAudio.Pa_ReadStream(
stream, bytebuff, PortAudioManager.NUM_SAMPLES);
}
return bytebuff;
for(InputPortAudioStream slave : slaves)
slave.setBuffer(bytebuff);
return bytebuff;
}
}
/**
@ -244,4 +260,13 @@ public void setParams(OutputPortAudioStream out,
deNoiseEnabled,
echoCancelEnabled, frameSize, filterLength);
}
/**
* Inform that we will be stopping this stream.
* @param stopping the stopping to set
*/
public void setStopping(boolean stopping)
{
this.stopping = stopping;
}
}

Loading…
Cancel
Save