diff --git a/src/org/jitsi/impl/neomedia/device/AudioSystem.java b/src/org/jitsi/impl/neomedia/device/AudioSystem.java index a89462004c698cc7d724afa08b90eb82e96221ca..320c6f70e4a28d556476004ba374eec517993e37 100644 --- a/src/org/jitsi/impl/neomedia/device/AudioSystem.java +++ b/src/org/jitsi/impl/neomedia/device/AudioSystem.java @@ -15,6 +15,7 @@ import javax.sound.sampled.*; import org.jitsi.impl.neomedia.jmfext.media.renderer.audio.*; +import org.jitsi.service.configuration.*; import org.jitsi.service.libjitsi.*; import org.jitsi.service.neomedia.*; import org.jitsi.service.resources.*; @@ -94,6 +95,20 @@ public enum DataFlow */ private static Logger logger = Logger.getLogger(AudioSystem.class); + /** + * The (base) name of the <tt>ConfigurationService</tt> property which + * indicates whether noise suppression is to be performed for the captured + * audio. + */ + protected static final String PNAME_DENOISE = "denoise"; + + /** + * The (base) name of the <tt>ConfigurationService</tt> property which + * indicates whether noise cancellation is to be performed for the captured + * audio. + */ + protected static final String PNAME_ECHOCANCEL = "echocancel"; + public static AudioSystem getAudioSystem(String locatorProtocol) { AudioSystem[] audioSystems = getAudioSystems(); @@ -424,6 +439,24 @@ public Format getFormat(InputStream audioInputStream) return null; } + /** + * Gets the (full) name of the <tt>ConfigurationService</tt> property which + * is associated with a (base) <tt>AudioSystem</tt>-specific property name. + * + * @param basePropertyName the (base) <tt>AudioSystem</tt>-specific property + * name of which the associated (full) <tt>ConfigurationService</tt> + * property name is to be returned + * @return the (full) name of the <tt>ConfigurationService</tt> property + * which is associated with the (base) <tt>AudioSystem</tt>-specific + * property name + */ + protected String getPropertyName(String basePropertyName) + { + return + DeviceConfiguration.PROP_AUDIO_SYSTEM + "." + getLocatorProtocol() + + "." + basePropertyName; + } + /** * Gets the selected device for a specific data flow: capture, notify or * playback. @@ -435,9 +468,43 @@ public Format getFormat(InputStream audioInputStream) public CaptureDeviceInfo2 getSelectedDevice(DataFlow dataFlow) { return - devices[dataFlow.ordinal()].getSelectedDevice( - getLocatorProtocol(), - getDevices(dataFlow)); + devices[dataFlow.ordinal()].getSelectedDevice(getDevices(dataFlow)); + } + + /** + * Gets the indicator which determines whether noise suppression is to be + * performed for captured audio. + * + * @return <tt>true</tt> if noise suppression is to be performed for + * captured audio; otherwise, <tt>false</tt> + */ + public boolean isDenoise() + { + ConfigurationService cfg = LibJitsi.getConfigurationService(); + boolean value = ((getFeatures() & FEATURE_DENOISE) == FEATURE_DENOISE); + + if (cfg != null) + value = cfg.getBoolean(getPropertyName(PNAME_DENOISE), value); + return value; + } + + /** + * Gets the indicator which determines whether echo cancellation is to be + * performed for captured audio. + * + * @return <tt>true</tt> if echo cancellation is to be performed for + * captured audio; otherwise, <tt>false</tt> + */ + public boolean isEchoCancel() + { + ConfigurationService cfg = LibJitsi.getConfigurationService(); + boolean value + = ((getFeatures() & FEATURE_ECHO_CANCELLATION) + == FEATURE_ECHO_CANCELLATION); + + if (cfg != null) + value = cfg.getBoolean(getPropertyName(PNAME_ECHOCANCEL), value); + return value; } /** @@ -490,16 +557,15 @@ protected void postInitializeSpecificDevices(DataFlow dataFlow) List<CaptureDeviceInfo2> activeDevices = getDevices(dataFlow); // Gets the default device. Devices devices = this.devices[dataFlow.ordinal()]; - String locatorProtocol = getLocatorProtocol(); CaptureDeviceInfo2 selectedActiveDevice - = devices.getSelectedDevice(locatorProtocol, activeDevices); + = devices.getSelectedDevice(activeDevices); // Sets the default device as selected. The function will fire a // property change only if the device has changed from a previous // configuration. The "set" part is important because only the fired // property event provides a way to get the hotplugged devices working // during a call. - devices.setDevice(locatorProtocol, selectedActiveDevice, false); + devices.setDevice(selectedActiveDevice, false); } /** @@ -559,6 +625,21 @@ protected void setCaptureDevices(List<CaptureDeviceInfo2> captureDevices) devices[DataFlow.CAPTURE.ordinal()].setDevices(captureDevices); } + /** + * Sets the indicator which determines whether noise suppression is to be + * performed for captured audio. + * + * @param denoise <tt>true</tt> if noise suppression is to be performed for + * captured audio; otherwise, <tt>false</tt> + */ + public void setDenoise(boolean denoise) + { + ConfigurationService cfg = LibJitsi.getConfigurationService(); + + if (cfg != null) + cfg.setProperty(getPropertyName(PNAME_DENOISE), denoise); + } + /** * Selects the active device. * @@ -573,10 +654,22 @@ public void setDevice( CaptureDeviceInfo2 device, boolean save) { - devices[dataFlow.ordinal()].setDevice( - getLocatorProtocol(), - device, - save); + devices[dataFlow.ordinal()].setDevice(device,save); + } + + /** + * Sets the indicator which determines whether echo cancellation is to be + * performed for captured audio. + * + * @param echoCancel <tt>true</tt> if echo cancellation is to be performed + * for captured audio; otherwise, <tt>false</tt> + */ + public void setEchoCancel(boolean echoCancel) + { + ConfigurationService cfg = LibJitsi.getConfigurationService(); + + if (cfg != null) + cfg.setProperty(getPropertyName(PNAME_ECHOCANCEL), echoCancel); } /** diff --git a/src/org/jitsi/impl/neomedia/device/DeviceConfiguration.java b/src/org/jitsi/impl/neomedia/device/DeviceConfiguration.java index 00aecb556d9a64362c70d65b9043339fa7f75206..bd60f99878eaad344618e79879737a0c60fa2601 100644 --- a/src/org/jitsi/impl/neomedia/device/DeviceConfiguration.java +++ b/src/org/jitsi/impl/neomedia/device/DeviceConfiguration.java @@ -123,20 +123,6 @@ public class DeviceConfiguration */ public static final int DEFAULT_VIDEO_WIDTH = 640; - /** - * The name of the <tt>boolean</tt> property which determines whether noise - * suppression is to be performed for captured audio. - */ - static final String PROP_AUDIO_DENOISE - = "net.java.sip.communicator.impl.neomedia.denoise"; - - /** - * The name of the <tt>boolean</tt> property which determines whether echo - * cancellation is to be performed for captured audio. - */ - static final String PROP_AUDIO_ECHOCANCEL - = "net.java.sip.communicator.impl.neomedia.echocancel"; - /** * The name of the <tt>long</tt> property which determines the filter length * in milliseconds to be used by the echo cancellation implementation. The @@ -907,41 +893,6 @@ public Dimension getVideoSize() return videoSize; } - /** - * Gets the indicator which determines whether noise suppression is to be - * performed for captured audio - * - * @return <tt>true</tt> if noise suppression is to be performed for - * captured audio; otherwise, <tt>false</tt> - */ - public boolean isDenoise() - { - ConfigurationService cfg = LibJitsi.getConfigurationService(); - boolean value = DEFAULT_AUDIO_DENOISE; - - if (cfg != null) - value = cfg.getBoolean(PROP_AUDIO_DENOISE, value); - - return value; - } - - /** - * Gets the indicator which determines whether echo cancellation is to be - * performed for captured audio. - * - * @return <tt>true</tt> if echo cancellation is to be performed for - * captured audio; otherwise, <tt>false</tt> - */ - public boolean isEchoCancel() - { - ConfigurationService cfg = LibJitsi.getConfigurationService(); - boolean value = DEFAULT_AUDIO_ECHOCANCEL; - - if (cfg != null) - value = cfg.getBoolean(PROP_AUDIO_ECHOCANCEL, value); - return value; - } - /** * Notifies this <tt>PropertyChangeListener</tt> about * <tt>PropertyChangeEvent</tt>s fired by, for example, the @@ -1178,36 +1129,6 @@ public void setAudioSystem(AudioSystem audioSystem, boolean save) } } - /** - * Sets the indicator which determines whether noise suppression is to be - * performed for captured audio. - * - * @param denoise <tt>true</tt> if noise suppression is to be performed for - * captured audio; otherwise, <tt>false</tt> - */ - public void setDenoise(boolean denoise) - { - ConfigurationService cfg = LibJitsi.getConfigurationService(); - - if (cfg != null) - cfg.setProperty(PROP_AUDIO_DENOISE, denoise); - } - - /** - * Sets the indicator which determines whether echo cancellation is to be - * performed for captured audio. - * - * @param echoCancel <tt>true</tt> if echo cancellation is to be performed - * for captured audio; otherwise, <tt>false</tt> - */ - public void setEchoCancel(boolean echoCancel) - { - ConfigurationService cfg = LibJitsi.getConfigurationService(); - - if (cfg != null) - cfg.setProperty(PROP_AUDIO_ECHOCANCEL, echoCancel); - } - /** * Sets and stores the frame rate. * diff --git a/src/org/jitsi/impl/neomedia/device/Devices.java b/src/org/jitsi/impl/neomedia/device/Devices.java index d4c2fc64157f3058f6aa34d04fbe893042b2df4a..49deeb961b6a6535b89bbe07bc2d0cc27ee289aa 100644 --- a/src/org/jitsi/impl/neomedia/device/Devices.java +++ b/src/org/jitsi/impl/neomedia/device/Devices.java @@ -149,19 +149,17 @@ public List<CaptureDeviceInfo2> getDevices() /** * Gets the selected active device. * - * @param locator The string representation of the locator. - * @param activeDevices The list of the active devices. - * - * @return The selected active device. + * @param activeDevices the list of the active devices + * @return the selected active device */ public CaptureDeviceInfo2 getSelectedDevice( - String locator, List<CaptureDeviceInfo2> activeDevices) { if (activeDevices != null) { String property = getPropDevice(); - loadDevicePreferences(locator, property); + + loadDevicePreferences(property); renameOldFashionedIdentifier(activeDevices); // Search if an active device is a new one (is not stored in the @@ -192,11 +190,7 @@ public CaptureDeviceInfo2 getSelectedDevice( // Adds the device in the preference list (to the end of the // list, or on top if selected. - saveDevice( - locator, - property, - activeDevice, - isSelected); + saveDevice(property, activeDevice, isSelected); } } @@ -235,55 +229,41 @@ else if(devicePreference.equals( * Loads device name ordered with user's preference from the * <tt>ConfigurationService</tt>. * - * @param locator The string representation of the locator. * @param property the name of the <tt>ConfigurationService</tt> property * which specifies the user's preference. */ - private void loadDevicePreferences(String locator, String property) + private void loadDevicePreferences(String property) { ConfigurationService cfg = LibJitsi.getConfigurationService(); if (cfg != null) { - String new_property - = DeviceConfiguration.PROP_AUDIO_SYSTEM - + "." - + locator - + "." - + property - + "_list"; - - String deviceIdentifiersString = cfg.getString(new_property); + String newProperty + = audioSystem.getPropertyName(property + "_list"); + String deviceIdentifiersString = cfg.getString(newProperty); synchronized(devicePreferences) { if (deviceIdentifiersString != null) { devicePreferences.clear(); - // We must parse the string in order to load the device - // list. - String[] deviceIdentifiers = deviceIdentifiersString - .substring(2, deviceIdentifiersString.length() - 2) - .split("\", \""); - for(int i = 0; i < deviceIdentifiers.length; ++i) - { - devicePreferences.add(deviceIdentifiers[i]); - } + // Parse the string into a device list. + String[] deviceIdentifiers + = deviceIdentifiersString + .substring(2, deviceIdentifiersString.length() - 2) + .split("\", \""); + + for (String deviceIdentifier : deviceIdentifiers) + devicePreferences.add(deviceIdentifier); } - // Else, use the old property to load the last preferred device. - // This whole "else" block may be removed in the future. else { - String old_property - = DeviceConfiguration.PROP_AUDIO_SYSTEM - + "." - + locator - + "." - + property; + // Use the old/legacy property to load the last preferred + // device. + String oldProperty = audioSystem.getPropertyName(property); - deviceIdentifiersString = cfg.getString(old_property); - - if (deviceIdentifiersString != null + deviceIdentifiersString = cfg.getString(oldProperty); + if ((deviceIdentifiersString != null) && !NoneAudioSystem.LOCATOR_PROTOCOL .equalsIgnoreCase(deviceIdentifiersString)) { @@ -346,7 +326,6 @@ private void renameOldFashionedIdentifier( /** * Saves the new selected device in top of the user preferences. * - * @param locator The string representation of the locator. * @param property the name of the <tt>ConfigurationService</tt> property * into which the user's preference with respect to the specified * <tt>CaptureDeviceInfo</tt> is to be saved @@ -354,7 +333,6 @@ private void renameOldFashionedIdentifier( * @param isSelected True if the device is the selected one. */ private void saveDevice( - String locator, String property, CaptureDeviceInfo2 device, boolean isSelected) @@ -370,39 +348,33 @@ private void saveDevice( isSelected); // Saves the user preferences. - writeDevicePreferences(locator, property); + writeDevicePreferences(property); } /** * Selects the active device. * - * @param locator The string representation of the locator. - * @param device The selected active device. - * @param save Flag set to true in order to save this choice in the - * configuration. False otherwise. + * @param device the selected active device + * @param save <tt>true</tt> to save the choice in the configuration; + * <tt>false</tt>, otherwise */ public void setDevice( - String locator, CaptureDeviceInfo2 device, boolean save) { // Checks if there is a change. if ((device == null) || !device.equals(this.device)) { + String property = getPropDevice(); CaptureDeviceInfo2 oldValue = this.device; // Saves the new selected device in top of the user preferences. if (save) - { - saveDevice( - locator, - getPropDevice(), - device, - true); - } + saveDevice(property, device, true); + this.device = device; - audioSystem.propertyChange(getPropDevice(), oldValue, this.device); + audioSystem.propertyChange(property, oldValue, this.device); } } @@ -424,20 +396,15 @@ public void setDevices(List<CaptureDeviceInfo2> devices) /** * Saves the device preferences and write it to the configuration file. * - * @param locator The string representation of the locator. * @param property the name of the <tt>ConfigurationService</tt> property */ - private void writeDevicePreferences(String locator, String property) + private void writeDevicePreferences(String property) { ConfigurationService cfg = LibJitsi.getConfigurationService(); if (cfg != null) { - property - = DeviceConfiguration.PROP_AUDIO_SYSTEM - + "." + locator - + "." + property - + "_list"; + property = audioSystem.getPropertyName(property + "_list"); StringBuilder value = new StringBuilder("[\""); diff --git a/src/org/jitsi/impl/neomedia/jmfext/media/protocol/portaudio/PortAudioStream.java b/src/org/jitsi/impl/neomedia/jmfext/media/protocol/portaudio/PortAudioStream.java index bf6fce83faec3d6a8932e82a05ca1c6f4c14b8d6..cfcbb3ba48de9e423be34f6940ce22170d5d17b9 100644 --- a/src/org/jitsi/impl/neomedia/jmfext/media/protocol/portaudio/PortAudioStream.java +++ b/src/org/jitsi/impl/neomedia/jmfext/media/protocol/portaudio/PortAudioStream.java @@ -387,34 +387,47 @@ private void connect() Format.NOT_SPECIFIED /* frameRate */, Format.byteArray); - MediaServiceImpl mediaServiceImpl - = NeomediaServiceUtils.getMediaServiceImpl(); - boolean denoise = DeviceConfiguration.DEFAULT_AUDIO_DENOISE; - boolean echoCancel = DeviceConfiguration.DEFAULT_AUDIO_ECHOCANCEL; + boolean denoise = false; + boolean echoCancel = false; long echoCancelFilterLengthInMillis = DeviceConfiguration .DEFAULT_AUDIO_ECHOCANCEL_FILTER_LENGTH_IN_MILLIS; - if (mediaServiceImpl != null) + if (audioQualityImprovement) { - DeviceConfiguration devCfg - = mediaServiceImpl.getDeviceConfiguration(); + AudioSystem audioSystem + = AudioSystem.getAudioSystem( + AudioSystem.LOCATOR_PROTOCOL_PORTAUDIO); - if (devCfg != null) + if (audioSystem != null) { - denoise = devCfg.isDenoise(); - echoCancel = devCfg.isEchoCancel(); - echoCancelFilterLengthInMillis - = devCfg.getEchoCancelFilterLengthInMillis(); + denoise = audioSystem.isDenoise(); + echoCancel = audioSystem.isEchoCancel(); + + if (echoCancel) + { + MediaServiceImpl mediaServiceImpl + = NeomediaServiceUtils.getMediaServiceImpl(); + + if (mediaServiceImpl != null) + { + DeviceConfiguration devCfg + = mediaServiceImpl.getDeviceConfiguration(); + + if (devCfg != null) + { + echoCancelFilterLengthInMillis + = devCfg.getEchoCancelFilterLengthInMillis(); + } + } + } } } - Pa.setDenoise(stream, audioQualityImprovement && denoise); + Pa.setDenoise(stream, denoise); Pa.setEchoFilterLengthInMillis( stream, - (audioQualityImprovement && echoCancel) - ? echoCancelFilterLengthInMillis - : 0); + echoCancel ? echoCancelFilterLengthInMillis : 0); // Pa_ReadStream has not been invoked yet. if (readIsMalfunctioningSince != NEVER)