aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java
diff options
context:
space:
mode:
authorLyubomir Marinov <lyubomir.marinov@jitsi.org>2011-12-20 00:44:34 +0000
committerLyubomir Marinov <lyubomir.marinov@jitsi.org>2011-12-20 00:44:34 +0000
commit3bb4311fb951c454a7646341cae197f8c66d59a8 (patch)
tree37cda93682162d6e010f7797725594f8010cf4a0 /src/net/java
parentd69f6a830faf6bf2a3180da720ec08d7ca18c310 (diff)
downloadjitsi-3bb4311fb951c454a7646341cae197f8c66d59a8.zip
jitsi-3bb4311fb951c454a7646341cae197f8c66d59a8.tar.gz
jitsi-3bb4311fb951c454a7646341cae197f8c66d59a8.tar.bz2
Refactors (neomeida's) volume control for the purposes of optimization, simplification.
Diffstat (limited to 'src/net/java')
-rw-r--r--src/net/java/sip/communicator/impl/neomedia/AbstractVolumeControl.java146
-rw-r--r--src/net/java/sip/communicator/impl/neomedia/InputVolumeControlImpl.java30
-rw-r--r--src/net/java/sip/communicator/impl/neomedia/MediaServiceImpl.java40
-rw-r--r--src/net/java/sip/communicator/impl/neomedia/OutputVolumeControlImpl.java30
-rw-r--r--src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/portaudio/PortAudioStream.java17
-rw-r--r--src/net/java/sip/communicator/impl/neomedia/jmfext/media/renderer/audio/PortAudioRenderer.java12
-rw-r--r--src/net/java/sip/communicator/service/neomedia/InputVolumeControl.java22
-rw-r--r--src/net/java/sip/communicator/service/neomedia/MediaService.java18
-rw-r--r--src/net/java/sip/communicator/service/neomedia/OutputVolumeControl.java22
-rw-r--r--src/net/java/sip/communicator/service/neomedia/VolumeControl.java16
10 files changed, 141 insertions, 212 deletions
diff --git a/src/net/java/sip/communicator/impl/neomedia/AbstractVolumeControl.java b/src/net/java/sip/communicator/impl/neomedia/AbstractVolumeControl.java
index e552a80..946f8c2 100644
--- a/src/net/java/sip/communicator/impl/neomedia/AbstractVolumeControl.java
+++ b/src/net/java/sip/communicator/impl/neomedia/AbstractVolumeControl.java
@@ -24,8 +24,9 @@ import net.java.sip.communicator.util.*;
* functionalities to work as one.
*
* @author Damian Minkov
+ * @author Lyubomir Marinov
*/
-public abstract class AbstractVolumeControl
+public class AbstractVolumeControl
implements VolumeControl,
GainControl
{
@@ -55,8 +56,8 @@ public abstract class AbstractVolumeControl
* The <tt>VolumeChangeListener</tt> interested in volume change events
* through VolumeControl Interface.
*/
- private List<VolumeChangeListener> volumeChangeListeners =
- new ArrayList<VolumeChangeListener>();
+ private final List<VolumeChangeListener> volumeChangeListeners
+ = new ArrayList<VolumeChangeListener>();
/**
* Listeners interested in volume change inside jmf.
@@ -66,12 +67,12 @@ public abstract class AbstractVolumeControl
/**
* The current volume level.
*/
- private float currentVolumeLevel = DEFAULT_VOLUME_LEVEL;
+ private float volumeLevel = DEFAULT_VOLUME_LEVEL;
/**
* Current mute state, by default we start unmuted.
*/
- private boolean currentMuteState = false;
+ private boolean mute = false;
/**
* Current level in db.
@@ -81,34 +82,53 @@ public abstract class AbstractVolumeControl
/**
* The initial volume level, when this instance was created.
*/
- private float initialVolumeLevel = DEFAULT_VOLUME_LEVEL;
+ private final float initialVolumeLevel;
/**
- * Creates volume control instance and initialise initial level value
- * if stored in config service.
+ * The name of the configuration property which specifies the value of the
+ * volume level of this <tt>AbstractVolumeControl</tt>.
*/
- AbstractVolumeControl()
+ private final String volumeLevelConfigurationPropertyName;
+
+ /**
+ * Creates volume control instance and initializes initial level value
+ * if stored in the configuration service.
+ *
+ * @param volumeLevelConfigurationPropertyName the name of the configuration
+ * property which specifies the value of the volume level of the new
+ * instance
+ */
+ public AbstractVolumeControl(
+ String volumeLevelConfigurationPropertyName)
{
+ this.volumeLevelConfigurationPropertyName
+ = volumeLevelConfigurationPropertyName;
+
// read initial level from config service if any
- String initialLevel =
- NeomediaActivator.getConfigurationService()
- .getString(getStoreLevelPropertyName());
+ String initialVolumeLevelString
+ = NeomediaActivator.getConfigurationService().getString(
+ this.volumeLevelConfigurationPropertyName);
+ float initialVolumeLevel = DEFAULT_VOLUME_LEVEL;
+
try
{
- if(initialLevel != null)
+ if (initialVolumeLevelString != null)
{
- currentVolumeLevel = Float.valueOf(initialLevel);
- initialVolumeLevel = currentVolumeLevel;
-
+ initialVolumeLevel = Float.parseFloat(initialVolumeLevelString);
if(logger.isDebugEnabled())
- logger.debug("Restore volume: "
- + currentVolumeLevel);
+ {
+ logger.debug(
+ "Restored volume: " + initialVolumeLevelString);
+ }
}
}
catch(Throwable t)
{
logger.warn("Error restoring volume", t);
}
+
+ this.initialVolumeLevel = initialVolumeLevel;
+ this.volumeLevel = this.initialVolumeLevel;
}
/**
@@ -170,7 +190,7 @@ public abstract class AbstractVolumeControl
*/
public float getVolume()
{
- return currentVolumeLevel;
+ return volumeLevel;
}
/**
@@ -183,7 +203,7 @@ public abstract class AbstractVolumeControl
*/
public float getLevel()
{
- return this.currentVolumeLevel;
+ return volumeLevel;
}
/**
@@ -250,22 +270,22 @@ public abstract class AbstractVolumeControl
*/
private float setVolumeLevel(float value)
{
- if(this.currentVolumeLevel == value)
+ if (volumeLevel == value)
return value;
if(value < MIN_VOLUME_LEVEL)
- this.currentVolumeLevel = MIN_VOLUME_LEVEL;
+ volumeLevel = MIN_VOLUME_LEVEL;
else if(value > MAX_VOLUME_LEVEL)
- this.currentVolumeLevel = MAX_VOLUME_LEVEL;
+ volumeLevel = MAX_VOLUME_LEVEL;
else
- this.currentVolumeLevel = value;
+ volumeLevel = value;
fireVolumeChange();
// save the level change, so we can restore it on next run
NeomediaActivator.getConfigurationService().setProperty(
- getStoreLevelPropertyName(),
- String.valueOf(currentVolumeLevel));
+ this.volumeLevelConfigurationPropertyName,
+ String.valueOf(volumeLevel));
float f1 = value / initialVolumeLevel;
db = (float)((Math.log((double)f1 != 0.0D ?
@@ -274,7 +294,7 @@ public abstract class AbstractVolumeControl
fireGainEvents();
- return this.currentVolumeLevel;
+ return volumeLevel;
}
/**
@@ -284,14 +304,13 @@ public abstract class AbstractVolumeControl
*/
public void setMute(boolean mute)
{
- if(mute == this.currentMuteState)
- return;
-
- this.currentMuteState = mute;
-
- fireVolumeChange();
+ if (this.mute != mute)
+ {
+ this.mute = mute;
- fireGainEvents();
+ fireVolumeChange();
+ fireGainEvents();
+ }
}
/**
@@ -301,7 +320,7 @@ public abstract class AbstractVolumeControl
*/
public boolean getMute()
{
- return this.currentMuteState;
+ return mute;
}
/**
@@ -321,20 +340,16 @@ public abstract class AbstractVolumeControl
if(this.db != gain)
{
this.db = gain;
+
float f1 = (float)Math.pow(10D, (double)this.db / 20D);
- this.currentVolumeLevel = f1 * this.initialVolumeLevel;
- if((double)this.currentVolumeLevel < 0.0D)
- {
- setVolumeLevel(0.0F);
- }
- else if((double)this.currentVolumeLevel > 1.0D)
- {
- setVolumeLevel(1.0F);
- }
- else
- {
- setVolumeLevel(this.currentVolumeLevel);
- }
+ float volumeLevel = f1 * this.initialVolumeLevel;
+
+ if(volumeLevel < 0.0F)
+ volumeLevel = 0.0F;
+ else if(volumeLevel > 1.0F)
+ volumeLevel = 1.0F;
+
+ setVolumeLevel(volumeLevel);
}
return this.db;
}
@@ -361,7 +376,6 @@ public abstract class AbstractVolumeControl
{
if(gainChangeListeners == null)
gainChangeListeners = new ArrayList<GainChangeListener>();
-
gainChangeListeners.add(listener);
}
}
@@ -388,9 +402,7 @@ public abstract class AbstractVolumeControl
synchronized(volumeChangeListeners)
{
if(!volumeChangeListeners.contains(listener))
- {
volumeChangeListeners.add(listener);
- }
}
}
@@ -412,21 +424,20 @@ public abstract class AbstractVolumeControl
*/
private void fireVolumeChange()
{
- List<VolumeChangeListener> copyVolumeListeners;
+ VolumeChangeListener[] ls;
+
synchronized(volumeChangeListeners)
{
- copyVolumeListeners =
- new ArrayList<VolumeChangeListener>(volumeChangeListeners);
+ ls
+ = volumeChangeListeners.toArray(
+ new VolumeChangeListener[volumeChangeListeners.size()]);
}
- VolumeChangeEvent changeEvent = new VolumeChangeEvent(
- this, this.currentVolumeLevel, this.currentMuteState);
+ VolumeChangeEvent changeEvent
+ = new VolumeChangeEvent(this, volumeLevel, mute);
-
- for(VolumeChangeListener l : copyVolumeListeners)
- {
+ for(VolumeChangeListener l : ls)
l.volumeChange(changeEvent);
- }
}
/**
@@ -436,14 +447,11 @@ public abstract class AbstractVolumeControl
{
if(gainChangeListeners != null)
{
- GainChangeEvent gainchangeevent =
- new GainChangeEvent(
- this, currentMuteState, db, currentVolumeLevel);
+ GainChangeEvent gainchangeevent
+ = new GainChangeEvent(this, mute, db, volumeLevel);
for(GainChangeListener gainchangelistener : gainChangeListeners)
- {
gainchangelistener.gainChange(gainchangeevent);
- }
}
}
@@ -455,12 +463,4 @@ public abstract class AbstractVolumeControl
{
return null;
}
-
- /**
- * Implementers return the property name they use to store
- * sound level information.
- *
- * @return sound level property name for storing configuration.
- */
- abstract String getStoreLevelPropertyName();
}
diff --git a/src/net/java/sip/communicator/impl/neomedia/InputVolumeControlImpl.java b/src/net/java/sip/communicator/impl/neomedia/InputVolumeControlImpl.java
deleted file mode 100644
index 9ecd30b..0000000
--- a/src/net/java/sip/communicator/impl/neomedia/InputVolumeControlImpl.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package net.java.sip.communicator.impl.neomedia;
-
-import net.java.sip.communicator.service.neomedia.*;
-
-/**
- * Controls media service capture volume.
- *
- * @author Damian Minkov
- */
-public class InputVolumeControlImpl
- extends AbstractVolumeControl
- implements InputVolumeControl
-{
- /**
- * Returns the property we use to store input sound level.
- *
- * @return sound level property name for storing configuration.
- */
- @Override
- String getStoreLevelPropertyName()
- {
- return CAPTURE_VOLUME_LEVEL_PROPERTY_NAME;
- }
-}
diff --git a/src/net/java/sip/communicator/impl/neomedia/MediaServiceImpl.java b/src/net/java/sip/communicator/impl/neomedia/MediaServiceImpl.java
index a969505..6d30ea3 100644
--- a/src/net/java/sip/communicator/impl/neomedia/MediaServiceImpl.java
+++ b/src/net/java/sip/communicator/impl/neomedia/MediaServiceImpl.java
@@ -134,12 +134,12 @@ public class MediaServiceImpl
/**
* The volume control of the media service playback.
*/
- private static OutputVolumeControl outputVolumeControl;
+ private static VolumeControl outputVolumeControl;
/**
* The volume control of the media service capture.
*/
- private static InputVolumeControl inputVolumeControl;
+ private static VolumeControl inputVolumeControl;
/**
* Lock to protected reinitialization of video devices.
@@ -591,28 +591,40 @@ public class MediaServiceImpl
}
/**
- * Returns the control that handles current playback levels.
+ * Gets the <tt>VolumeControl</tt> which controls the volume level of audio
+ * output/playback.
*
- * @return the volume playback control.
+ * @return the <tt>VolumeControl</tt> which controls the volume level of
+ * audio output/playback
+ * @see MediaService#getOutputVolumeControl()
*/
- public OutputVolumeControl getOutputVolumeControl()
+ public VolumeControl getOutputVolumeControl()
{
- if(outputVolumeControl == null)
- outputVolumeControl = new OutputVolumeControlImpl();
-
+ if (outputVolumeControl == null)
+ {
+ outputVolumeControl
+ = new AbstractVolumeControl(
+ VolumeControl.PLAYBACK_VOLUME_LEVEL_PROPERTY_NAME);
+ }
return outputVolumeControl;
}
/**
- * Returns the control that handles current capture levels.
+ * Gets the <tt>VolumeControl</tt> which controls the volume level of audio
+ * input/capture.
*
- * @return the volume capture control.
+ * @return the <tt>VolumeControl</tt> which controls the volume level of
+ * audio input/capture
+ * @see MediaService#getInputVolumeControl()
*/
- public InputVolumeControl getInputVolumeControl()
+ public VolumeControl getInputVolumeControl()
{
- if(inputVolumeControl == null)
- inputVolumeControl = new InputVolumeControlImpl();
-
+ if (inputVolumeControl == null)
+ {
+ inputVolumeControl
+ = new AbstractVolumeControl(
+ VolumeControl.CAPTURE_VOLUME_LEVEL_PROPERTY_NAME);
+ }
return inputVolumeControl;
}
diff --git a/src/net/java/sip/communicator/impl/neomedia/OutputVolumeControlImpl.java b/src/net/java/sip/communicator/impl/neomedia/OutputVolumeControlImpl.java
deleted file mode 100644
index 9114625..0000000
--- a/src/net/java/sip/communicator/impl/neomedia/OutputVolumeControlImpl.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package net.java.sip.communicator.impl.neomedia;
-
-import net.java.sip.communicator.service.neomedia.*;
-
-/**
- * Controls media service playback volume.
- *
- * @author Damian Minkov
- */
-public class OutputVolumeControlImpl
- extends AbstractVolumeControl
- implements OutputVolumeControl
-{
- /**
- * Returns the property we use to store output sound level.
- *
- * @return sound level property name for storing configuration.
- */
- @Override
- String getStoreLevelPropertyName()
- {
- return PLAYBACK_VOLUME_LEVEL_PROPERTY_NAME;
- }
-}
diff --git a/src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/portaudio/PortAudioStream.java b/src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/portaudio/PortAudioStream.java
index 8322d03..4b2ec14 100644
--- a/src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/portaudio/PortAudioStream.java
+++ b/src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/portaudio/PortAudioStream.java
@@ -66,6 +66,12 @@ public class PortAudioStream
private int framesPerBuffer;
/**
+ * The <tt>GainControl</tt> through which the volume/gain of captured media
+ * is controlled.
+ */
+ private final GainControl gainControl;
+
+ /**
* Native pointer to a PaStreamParameters object.
*/
private long inputParameters = 0;
@@ -87,11 +93,6 @@ public class PortAudioStream
private boolean streamIsBusy = false;
/**
- * Volume Control used to control volume of current captured media.
- */
- private final GainControl volumeControl;
-
- /**
* Initializes a new <tt>PortAudioStream</tt> instance which is to have its
* <tt>Format</tt>-related information abstracted by a specific
* <tt>FormatControl</tt>.
@@ -113,7 +114,7 @@ public class PortAudioStream
this.audioQualityImprovement = audioQualityImprovement;
- this.volumeControl
+ gainControl
= (GainControl)
NeomediaActivator.getMediaServiceImpl().getInputVolumeControl();
}
@@ -191,10 +192,10 @@ public class PortAudioStream
}
// if we have some volume setting apply them
- if(volumeControl != null)
+ if (gainControl != null)
{
AbstractVolumeControl.applyGain(
- volumeControl,
+ gainControl,
bufferData, 0, bytesPerBuffer);
}
diff --git a/src/net/java/sip/communicator/impl/neomedia/jmfext/media/renderer/audio/PortAudioRenderer.java b/src/net/java/sip/communicator/impl/neomedia/jmfext/media/renderer/audio/PortAudioRenderer.java
index 8c6be84..e48aa61 100644
--- a/src/net/java/sip/communicator/impl/neomedia/jmfext/media/renderer/audio/PortAudioRenderer.java
+++ b/src/net/java/sip/communicator/impl/neomedia/jmfext/media/renderer/audio/PortAudioRenderer.java
@@ -145,10 +145,10 @@ public class PortAudioRenderer
private Format[] supportedInputFormats;
/**
- * The <tt>GainControl</tt> used to control volume/gain of current played
- * media.
+ * The <tt>GainControl</tt> through which volume/gain of rendered media is
+ * controlled.
*/
- private GainControl gainControl = null;
+ private final GainControl gainControl;
/**
* Initializes a new <tt>PortAudioRenderer</tt> instance.
@@ -166,12 +166,14 @@ public class PortAudioRenderer
*/
public PortAudioRenderer(boolean enableVolumeControl)
{
- if(enableVolumeControl)
- this.gainControl
+ if (enableVolumeControl)
+ gainControl
= (GainControl)
NeomediaActivator
.getMediaServiceImpl()
.getOutputVolumeControl();
+ else
+ gainControl = null;
}
/**
diff --git a/src/net/java/sip/communicator/service/neomedia/InputVolumeControl.java b/src/net/java/sip/communicator/service/neomedia/InputVolumeControl.java
deleted file mode 100644
index 128cd0f..0000000
--- a/src/net/java/sip/communicator/service/neomedia/InputVolumeControl.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package net.java.sip.communicator.service.neomedia;
-
-/**
- * Controls the capture volume in media service.
- *
- * @author Damian Minkov
- */
-public interface InputVolumeControl
- extends VolumeControl
-{
- /**
- * Property for storing level into configuration.
- */
- public final static String CAPTURE_VOLUME_LEVEL_PROPERTY_NAME
- = "net.java.sip.communicator.service.media.CAPTURE_VOLUME_LEVEL";
-}
diff --git a/src/net/java/sip/communicator/service/neomedia/MediaService.java b/src/net/java/sip/communicator/service/neomedia/MediaService.java
index b521115..d8a23a3 100644
--- a/src/net/java/sip/communicator/service/neomedia/MediaService.java
+++ b/src/net/java/sip/communicator/service/neomedia/MediaService.java
@@ -145,16 +145,22 @@ public interface MediaService
public SDesControl createSDesControl();
/**
- * Returns the control that handles current playback levels.
- * @return the volume playback control.
+ * Gets the <tt>VolumeControl</tt> which controls the volume level of audio
+ * output/playback.
+ *
+ * @return the <tt>VolumeControl</tt> which controls the volume level of
+ * audio output/playback
*/
- public OutputVolumeControl getOutputVolumeControl();
+ public VolumeControl getOutputVolumeControl();
/**
- * Returns the control that handles current capture levels.
- * @return the volume capture control.
+ * Gets the <tt>VolumeControl</tt> which controls the volume level of audio
+ * input/capture.
+ *
+ * @return the <tt>VolumeControl</tt> which controls the volume level of
+ * audio input/capture
*/
- public InputVolumeControl getInputVolumeControl();
+ public VolumeControl getInputVolumeControl();
/**
* Get available <tt>ScreenDevice</tt>s.
diff --git a/src/net/java/sip/communicator/service/neomedia/OutputVolumeControl.java b/src/net/java/sip/communicator/service/neomedia/OutputVolumeControl.java
deleted file mode 100644
index 674c2a3..0000000
--- a/src/net/java/sip/communicator/service/neomedia/OutputVolumeControl.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package net.java.sip.communicator.service.neomedia;
-
-/**
- * Controls the playback volume in media service.
- *
- * @author Damian Minkov
- */
-public interface OutputVolumeControl
- extends VolumeControl
-{
- /**
- * Property for storing level into configuration.
- */
- public final static String PLAYBACK_VOLUME_LEVEL_PROPERTY_NAME
- = "net.java.sip.communicator.service.media.PLAYBACK_VOLUME_LEVEL";
-}
diff --git a/src/net/java/sip/communicator/service/neomedia/VolumeControl.java b/src/net/java/sip/communicator/service/neomedia/VolumeControl.java
index 9b7b6b2..2294569 100644
--- a/src/net/java/sip/communicator/service/neomedia/VolumeControl.java
+++ b/src/net/java/sip/communicator/service/neomedia/VolumeControl.java
@@ -10,14 +10,26 @@ import net.java.sip.communicator.service.neomedia.event.*;
/**
* Control for volume level in media service.
- * @see InputVolumeControl
- * @see OutputVolumeControl
*
* @author Damian Minkov
*/
public interface VolumeControl
{
/**
+ * The name of the configuration property which specifies the volume level
+ * of audio input.
+ */
+ public final static String CAPTURE_VOLUME_LEVEL_PROPERTY_NAME
+ = "net.java.sip.communicator.service.media.CAPTURE_VOLUME_LEVEL";
+
+ /**
+ * The name of the configuration property which specifies the volume level
+ * of audio output.
+ */
+ public final static String PLAYBACK_VOLUME_LEVEL_PROPERTY_NAME
+ = "net.java.sip.communicator.service.media.PLAYBACK_VOLUME_LEVEL";
+
+ /**
* Current volume value.
* @return the current volume level.
*/