Move portaudio specific settings from DeviceConfiguration to PortAudioAuto, and leave stopping only to portaudio slave streams.

cusax-fix
Damian Minkov 16 years ago
parent 629efbb21e
commit de4f2d14bb

@ -112,26 +112,26 @@ public class DeviceConfiguration
/**
* Property used to store is echo cancel enabled or disabled.
*/
private static final String PROP_AUDIO_ECHOCANCEL_ENABLED =
static final String PROP_AUDIO_ECHOCANCEL_ENABLED =
"net.java.sip.communicator.impl.neomedia.echocancel";
/**
* Property used to store the echo cancel tail used for cancelation.
*/
private static final String PROP_AUDIO_ECHOCANCEL_TAIL =
static final String PROP_AUDIO_ECHOCANCEL_TAIL =
"net.java.sip.communicator.impl.neomedia.echocancel.tail";
/**
* Property used to store is denoise enabled or disabled.
*/
private static final String PROP_AUDIO_DENOISE_ENABLED =
static final String PROP_AUDIO_DENOISE_ENABLED =
"net.java.sip.communicator.impl.neomedia.denoise";
/**
* Property used to store the latency option we use for current OS.
* Must be in milliseconds.
*/
private static final String PROP_AUDIO_LATENCY =
static final String PROP_AUDIO_LATENCY =
"net.java.sip.communicator.impl.neomedia.latency";
/**
@ -222,28 +222,12 @@ 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
if(!errorStartingPA)
if(PortAudioAuto.isSupported())
{
setAudioSystem(AUDIO_SYSTEM_PORTAUDIO, null, false);
}
@ -267,7 +251,7 @@ else if (audioCaptureDevices.length < 1)
}
}
if(getAudioSystem() == null || errorStartingPA)
if(getAudioSystem() == null || !PortAudioAuto.isSupported())
{
logger.warn("Computer sound config changed or " +
"there is a problem since last config was saved, " +
@ -281,45 +265,6 @@ else if (audioCaptureDevices.length < 1)
if (audioCaptureDevice != null)
logger.info("Found " + audioCaptureDevice.getName()
+ " as an audio capture device.");
// now extract other sound related configs
if(!errorStartingPA)
{
try
{
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);
}
}
}
if (config.getBoolean(PROP_VIDEO_DEVICE_IS_DISABLED, false))

@ -10,9 +10,11 @@
import javax.media.*;
import net.java.sip.communicator.impl.neomedia.*;
import net.java.sip.communicator.impl.neomedia.portaudio.*;
import net.java.sip.communicator.impl.neomedia.jmfext.media.protocol.portaudio.*;
import net.java.sip.communicator.util.*;
import net.java.sip.communicator.service.configuration.*;
import com.sun.media.util.*;
@ -24,6 +26,12 @@
*/
public class PortAudioAuto
{
/**
* The <tt>Logger</tt> used by the <tt>PortAudioAuto</tt> class and its
* instances for logging output.
*/
private static final Logger logger = Logger.getLogger(PortAudioAuto.class);
/**
* An array of the devices that can be used for playback.
*/
@ -39,6 +47,11 @@ public class PortAudioAuto
*/
public static CaptureDeviceInfo defaultCaptureDevice = null;
/**
* Is portaudio supported on current platform.
*/
private static boolean supported = false;
/**
* Initializes a new <tt>PortAudioAuto</tt> instance which creates PortAudio
* capture devices by enumerating all host devices with input channels.
@ -55,7 +68,7 @@ public class PortAudioAuto
PortAudioManager.getInstance();
// enable jmf logging, so we can track codec chains and formats
if(Logger.getLogger(PortAudioAuto.class).isDebugEnabled())
if(logger.isDebugEnabled())
Registry.set("allowLogging", true);
int deviceCount = PortAudio.Pa_GetDeviceCount();
@ -105,5 +118,60 @@ public class PortAudioAuto
// now add it as available audio system to DeviceConfiguration
DeviceConfiguration.addAudioSystem(
DeviceConfiguration.AUDIO_SYSTEM_PORTAUDIO);
// now extract other sound related configs
try
{
ConfigurationService config
= NeomediaActivator.getConfigurationService();
boolean echoCancelEnabled =
config.getBoolean(
DeviceConfiguration.PROP_AUDIO_ECHOCANCEL_ENABLED,
PortAudioManager.getInstance().isEnabledEchoCancel());
if(echoCancelEnabled)
{
int echoCancelTail =
config.getInt(
DeviceConfiguration.PROP_AUDIO_ECHOCANCEL_TAIL,
PortAudioManager.getInstance().getFilterLength());
PortAudioManager.getInstance().setEchoCancel(
echoCancelEnabled,
PortAudioManager.getInstance().getFrameSize(),
echoCancelTail);
}
boolean denoiseEnabled =
config.getBoolean(
DeviceConfiguration.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(
DeviceConfiguration.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);
}
supported = true;
}
/**
* Whether portaudio is supported.
* @return the supported
*/
public static boolean isSupported()
{
return supported;
}
}

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

@ -15,10 +15,24 @@
*/
public class InputPortAudioStream
{
/**
* Our parent stream, the actual source of data.
*/
private final MasterPortAudioStream parentStream;
/**
* Is this stream started.
*/
private boolean started = false;
/**
* 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 buffer to return.
*/
@ -42,6 +56,9 @@ public InputPortAudioStream(MasterPortAudioStream st)
public byte[] read()
throws PortAudioException
{
if(stopping || !started)
return new byte[0];
synchronized(parentStream)
{
byte[] res = buffer;
@ -78,9 +95,10 @@ public synchronized void stop()
{
if(started)
{
parentStream.setStopping(true);
stopping = true;
parentStream.stop(this);
started = false;
stopping = false;
}
}

@ -58,15 +58,6 @@ 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.
@ -178,7 +169,6 @@ synchronized void stop(InputPortAudioStream slave)
PortAudio.Pa_CloseStream(stream);
stream = 0;
started = false;
stopping = false;
PortAudioManager.getInstance().stoppedInputPortAudioStream(this);
}
}
@ -207,30 +197,24 @@ public long getStream()
* @return the bytes that a read from underlying stream.
* @throws PortAudioException if an error occurs while reading.
*/
public byte[] read()
public synchronized byte[] read()
throws PortAudioException
{
if(stopping)
if(!started)
return new byte[0];
synchronized(this)
{
if(!started)
return new byte[0];
byte[] bytebuff = new byte[PortAudioManager.NUM_SAMPLES*frameSize];
byte[] bytebuff = new byte[PortAudioManager.NUM_SAMPLES*frameSize];
synchronized(connectedToStreamSync)
{
PortAudio.Pa_ReadStream(
stream, bytebuff, PortAudioManager.NUM_SAMPLES);
}
synchronized(connectedToStreamSync)
{
PortAudio.Pa_ReadStream(
stream, bytebuff, PortAudioManager.NUM_SAMPLES);
}
for(InputPortAudioStream slave : slaves)
slave.setBuffer(bytebuff);
for(InputPortAudioStream slave : slaves)
slave.setBuffer(bytebuff);
return bytebuff;
}
return bytebuff;
}
/**
@ -260,13 +244,4 @@ 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