From 9a506e82fc45cb1940379056317f9fde1c48fa32 Mon Sep 17 00:00:00 2001 From: Vincent Lucas <chenzo@jitsi.org> Date: Thu, 13 Dec 2012 16:44:34 +0000 Subject: [PATCH] Activates update for reloadable audio systems in order to activate them if the number of devices changes from 0 to something greater. --- .../neomedia/device/DeviceConfiguration.java | 71 +++++++++++++++++-- 1 file changed, 66 insertions(+), 5 deletions(-) diff --git a/src/org/jitsi/impl/neomedia/device/DeviceConfiguration.java b/src/org/jitsi/impl/neomedia/device/DeviceConfiguration.java index d41bce55..33fc22e2 100644 --- a/src/org/jitsi/impl/neomedia/device/DeviceConfiguration.java +++ b/src/org/jitsi/impl/neomedia/device/DeviceConfiguration.java @@ -209,6 +209,9 @@ public class DeviceConfiguration */ public static final String VIDEO_CAPTURE_DEVICE = "VIDEO_CAPTURE_DEVICE"; + /** + * The currently selected audio system. + */ private AudioSystem audioSystem; /** @@ -265,6 +268,9 @@ public DeviceConfiguration() registerCustomRenderers(); fixRenderers(); + + //Registers this device configuration to all reloadable device sytem. + registerToDeviceSystemPropertyChangeListener(); } /** @@ -491,15 +497,27 @@ public void setAudioSystem(AudioSystem audioSystem, boolean save) { if (this.audioSystem != audioSystem) { - if (this.audioSystem != null) + // Removes the registration to change listener only if this audio + // sytem does not supports reinitialize. + if (this.audioSystem != null + && (this.audioSystem.getFeatures() + & DeviceSystem.FEATURE_REINITIALIZE) == 0) + { this.audioSystem.removePropertyChangeListener(this); + } AudioSystem oldValue = this.audioSystem; this.audioSystem = audioSystem; + // Registers the new selected audio system. Even if every + // reloadable audio systems are already registered, the check for + // dupplicate entries will be done by the addPropertyChangeListener + // function. if (this.audioSystem != null) + { this.audioSystem.addPropertyChangeListener(this); + } if (save) { @@ -994,10 +1012,24 @@ public void propertyChange(PropertyChangeEvent event) || AUDIO_NOTIFY_DEVICE.equals(propertyName) || AUDIO_PLAYBACK_DEVICE.equals(propertyName)) { - firePropertyChange( - propertyName, - event.getOldValue(), - event.getNewValue()); + CaptureDeviceInfo deviceInfo + = (CaptureDeviceInfo) event.getOldValue(); + if(deviceInfo == null) + { + deviceInfo = (CaptureDeviceInfo) event.getNewValue(); + } + + // Fire an event on the selected device, only if the event is + // generated by the selected audio system. + if(deviceInfo == null + || deviceInfo.getLocator().getProtocol().equals( + getAudioSystem().getLocatorProtocol())) + { + firePropertyChange( + propertyName, + event.getOldValue(), + event.getNewValue()); + } } else if (DeviceSystem.PROP_DEVICES.equals(propertyName)) { @@ -1125,4 +1157,33 @@ private void extractConfiguredVideoCaptureDevices() logger.info("No Video Device was found."); } } + + /** + * Registers this device configuration to all reloadable device sytem, in + * order to receive events from device systems which are not currently + * selected. I.e. a device system which changes its number of device from 0 + * to 1 or more, is becoming available and can be selected by the user. + */ + private void registerToDeviceSystemPropertyChangeListener() + { + // Look at all kind of device systems: audio and video. + for(MediaType mediaType: MediaType.values()) + { + DeviceSystem[] deviceSystems + = DeviceSystem.getDeviceSystems(mediaType); + if(deviceSystems != null) + { + for (DeviceSystem deviceSystem : deviceSystems) + { + // If the device system is reloadable, then register this + // device configuration. + if((deviceSystem.getFeatures() + & DeviceSystem.FEATURE_REINITIALIZE) != 0) + { + deviceSystem.addPropertyChangeListener(this); + } + } + } + } + } } -- GitLab