From 54250f18426826b062f7ab9a5fd86a305a4bc28f Mon Sep 17 00:00:00 2001 From: Vincent Lucas <chenzo@jitsi.org> Date: Fri, 7 Dec 2012 14:17:19 +0000 Subject: [PATCH] Adds the device name and its state (connected or disconnected) for the "Device configuration has changed" pop-up notification. Adds a "New selected device" pop-up notification when the selected audio device has changed (for audio in, audio out and notifications). --- .../impl/neomedia/device/DeviceSystem.java | 89 +++++++++++++++---- 1 file changed, 74 insertions(+), 15 deletions(-) diff --git a/src/org/jitsi/impl/neomedia/device/DeviceSystem.java b/src/org/jitsi/impl/neomedia/device/DeviceSystem.java index 79caa0a8..8c957c3f 100644 --- a/src/org/jitsi/impl/neomedia/device/DeviceSystem.java +++ b/src/org/jitsi/impl/neomedia/device/DeviceSystem.java @@ -62,6 +62,18 @@ public abstract class DeviceSystem public static final String PROP_DEVICES = "devices"; + /** + * The list of devices connected at the last preInitialize. + */ + private static Vector<CaptureDeviceInfo> propertyChangeOldDevices + = new Vector<CaptureDeviceInfo>(); + + /** + * The list of devices connected at the last postInitialize. + */ + private static Vector<CaptureDeviceInfo> propertyChangeNewDevices + = new Vector<CaptureDeviceInfo>(); + /** * The list of <tt>DeviceSystem</tt>s which have been initialized. */ @@ -423,7 +435,38 @@ protected final void initialize() */ protected void postInitialize() { - firePropertyChange(PROP_DEVICES, null, null); + Format format = this.getFormat(); + + if (format != null) + { + // Gets the list of the actual connected devices. + propertyChangeNewDevices.removeAllElements(); + propertyChangeNewDevices.addAll( + CaptureDeviceManager.getDeviceList(format)); + + // Compares the previous conencted device list with the current one, + // in order to detect new connected or disconnected devices. + for(int i = 0; i < propertyChangeOldDevices.size(); ++i) + { + if(!propertyChangeNewDevices.remove( + propertyChangeOldDevices.get(i))) + { + // Old device is removed. + firePropertyChange( + PROP_DEVICES, + propertyChangeOldDevices.get(i), + null); + } + } + for(int i = 0; i < propertyChangeNewDevices.size(); ++i) + { + // New device is plugged in. + firePropertyChange( + PROP_DEVICES, + null, + propertyChangeNewDevices.get(i)); + } + } } /** @@ -435,26 +478,15 @@ protected void postInitialize() */ protected void preInitialize() { - Format format; - - switch (getMediaType()) - { - case AUDIO: - format = new AudioFormat(null); - break; - case VIDEO: - format = new VideoFormat(null); - break; - default: - format = null; - break; - } + Format format = this.getFormat(); if (format != null) { @SuppressWarnings("unchecked") Vector<CaptureDeviceInfo> cdis = CaptureDeviceManager.getDeviceList(format); + propertyChangeOldDevices.removeAllElements(); + propertyChangeOldDevices.addAll(cdis); if ((cdis != null) && (cdis.size() > 0)) { @@ -503,4 +535,31 @@ public String toString() { return getLocatorProtocol(); } + + /** + * Returns the format depending on the media type: AudioFormat for AUDIO, + * VideoFormat for VIDEO. Otherwise, returns null. + * + * @return The format depending on the media type: AudioFormat for AUDIO, + * VideoFormat for VIDEO. Otherwise, returns null. + */ + public Format getFormat() + { + Format format = null; + + switch (getMediaType()) + { + case AUDIO: + format = new AudioFormat(null); + break; + case VIDEO: + format = new VideoFormat(null); + break; + default: + format = null; + break; + } + + return format; + } } -- GitLab