Adds volume to RFC4733 dtmf packets and handling of an account property to change default value. Changes the default minimum tone duration.

cusax-fix
Damian Minkov 12 years ago
parent 908d7a0bd5
commit 08d32c8183

@ -6,18 +6,13 @@
*/
package net.java.sip.communicator.impl.protocol.jabber;
import java.util.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.OperationFailedException;
import net.java.sip.communicator.service.protocol.media.*;
import net.java.sip.communicator.util.*;
import org.jitsi.service.configuration.*;
import org.jitsi.service.neomedia.*;
import org.jitsi.service.neomedia.codec.*;
import org.jitsi.service.neomedia.format.*;
import org.jitsi.service.protocol.*;
import org.jitsi.util.StringUtils; // Disambiguation
/**
* Class responsible for sending a DTMF Tone using using rfc4733 or Inband.
@ -25,7 +20,7 @@
* @author Damian Minkov
*/
public class OperationSetDTMFJabberImpl
implements OperationSetDTMF
extends AbstractOperationSetDTMF
{
/**
* Our class logger.
@ -33,21 +28,6 @@ public class OperationSetDTMFJabberImpl
private static final Logger logger
= Logger.getLogger(OperationSetDTMFJabberImpl.class);
/**
* The DTMF method used to send tones.
*/
private DTMFMethod dtmfMethod;
/**
* The minimal tone duration.
*/
private int minimalToneDuration;
/**
* The maximal tone duration.
*/
private int maximalToneDuration;
/**
* Constructor.
*
@ -55,9 +35,7 @@ public class OperationSetDTMFJabberImpl
*/
public OperationSetDTMFJabberImpl(ProtocolProviderServiceJabberImpl pps)
{
this.dtmfMethod = this.getDTMFMethod(pps);
this.minimalToneDuration = this.getMinimalToneDuration(pps);
this.maximalToneDuration = this.getMaximalToneDuration();
super(pps);
}
/**
@ -117,7 +95,8 @@ public synchronized void startSendingDTMF(CallPeer callPeer, DTMFTone tone)
tone,
cpDTMFMethod,
minimalToneDuration,
maximalToneDuration);
maximalToneDuration,
volume);
}
/**
@ -165,124 +144,4 @@ public synchronized void stopSendingDTMF(CallPeer callPeer)
((AudioMediaStream)cp.getMediaHandler().getStream(MediaType.AUDIO))
.stopSendingDTMF(cpDTMFMethod);
}
/**
* Checks whether rfc4733 is negotiated for this call.
* @param peer the call peer.
* @return whether we can use rfc4733 in this call.
*/
private boolean isRFC4733Active(CallPeerJabberImpl peer)
{
Iterator<MediaFormat> iter =
peer.getMediaHandler().getStream(MediaType.AUDIO)
.getDynamicRTPPayloadTypes().values().iterator();
while (iter.hasNext())
{
MediaFormat mediaFormat = iter.next();
if(mediaFormat.getEncoding().equals(Constants.TELEPHONE_EVENT))
return true;
}
return false;
}
/**
* Returns the corresponding DTMF method used for this account.
*
* @param pps the Jabber Protocol provider service
*
* @return the DTMFEnum corresponding to the DTMF method set for this
* account.
*/
private DTMFMethod getDTMFMethod(ProtocolProviderServiceJabberImpl pps)
{
AccountID accountID = pps.getAccountID();
String dtmfString = accountID.getAccountPropertyString("DTMF_METHOD");
// Verifies that the DTMF_METHOD property string is correctly set.
// If not, sets this account to the "auto" DTMF method and corrects the
// property string.
if(dtmfString == null
|| (!dtmfString.equals("AUTO_DTMF")
&& !dtmfString.equals("RTP_DTMF")
&& !dtmfString.equals("INBAND_DTMF")))
{
dtmfString = "AUTO_DTMF";
accountID.putAccountProperty("DTMF_METHOD", dtmfString);
}
if(dtmfString.equals("AUTO_DTMF"))
{
return DTMFMethod.AUTO_DTMF;
}
else if(dtmfString.equals("RTP_DTMF"))
{
return DTMFMethod.RTP_DTMF;
}
else // if(dtmfString.equals(INBAND_DTMF"))
{
return DTMFMethod.INBAND_DTMF;
}
}
/**
* Gets the minimal DTMF tone duration for this account.
*
* @param pps the Jabber Protocol provider service
*
* @return The minimal DTMF tone duration for this account.
*/
private int getMinimalToneDuration(ProtocolProviderServiceJabberImpl pps)
{
AccountID accountID = pps.getAccountID();
String minimalToneDurationString
= accountID.getAccountPropertyString("DTMF_MINIMAL_TONE_DURATION");
int minimalToneDuration
= OperationSetDTMF.DEFAULT_DTMF_MINIMAL_TONE_DURATION;
// Check if there is a specific value for this account.
if(!StringUtils.isNullOrEmpty(minimalToneDurationString))
{
minimalToneDuration = Integer.valueOf(minimalToneDurationString);
}
// Else look at the global property.
else
{
ConfigurationService cfg
= JabberActivator.getConfigurationService();
// Check if there is a custom value for the minimal tone duration.
if(cfg != null)
{
minimalToneDuration = cfg.getInt(
OperationSetDTMF.PROP_MINIMAL_RTP_DTMF_TONE_DURATION,
minimalToneDuration);
}
}
return minimalToneDuration;
}
/**
* Gets the maximal DTMF tone duration for this account.
*
* @return The maximal DTMF tone duration for this account.
*/
private int getMaximalToneDuration()
{
int maximalToneDuration
= OperationSetDTMF.DEFAULT_DTMF_MAXIMAL_TONE_DURATION;
// Look at the global property.
ConfigurationService cfg
= JabberActivator.getConfigurationService();
// Check if there is a custom value for the maximal tone duration.
if(cfg != null)
{
maximalToneDuration = cfg.getInt(
OperationSetDTMF.PROP_MAXIMAL_RTP_DTMF_TONE_DURATION,
maximalToneDuration);
}
return maximalToneDuration;
}
}

@ -6,19 +6,14 @@
*/
package net.java.sip.communicator.impl.protocol.sip;
import java.util.*;
import net.java.sip.communicator.impl.protocol.sip.dtmf.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.OperationFailedException;
import net.java.sip.communicator.service.protocol.media.*;
import net.java.sip.communicator.util.*;
import org.jitsi.service.configuration.*;
import org.jitsi.service.neomedia.*;
import org.jitsi.service.neomedia.codec.*;
import org.jitsi.service.neomedia.format.*;
import org.jitsi.service.protocol.*;
import org.jitsi.util.StringUtils; // Disambiguation
/**
* Class responsible for sending a DTMF Tone using SIP INFO or using rfc4733.
@ -27,7 +22,7 @@
* @author Vincent Lucas
*/
public class OperationSetDTMFSipImpl
implements OperationSetDTMF
extends AbstractOperationSetDTMF
{
/**
* Our class logger.
@ -35,26 +30,11 @@ public class OperationSetDTMFSipImpl
private static final Logger logger
= Logger.getLogger(OperationSetDTMFSipImpl.class);
/**
* The DTMF method used to send tones.
*/
private DTMFMethod dtmfMethod;
/**
* DTMF mode sending DTMF as sip info.
*/
private final DTMFInfo dtmfModeInfo;
/**
* The minimal tone duration.
*/
private int minimalToneDuration;
/**
* The maximal tone duration.
*/
private int maximalToneDuration;
/**
* Constructor.
*
@ -62,9 +42,8 @@ public class OperationSetDTMFSipImpl
*/
public OperationSetDTMFSipImpl(ProtocolProviderServiceSipImpl pps)
{
this.dtmfMethod = this.getDTMFMethod(pps);
this.minimalToneDuration = this.getMinimalToneDuration(pps);
this.maximalToneDuration = this.getMaximalToneDuration();
super(pps);
dtmfModeInfo = new DTMFInfo(pps);
}
@ -134,7 +113,8 @@ public synchronized void startSendingDTMF(CallPeer callPeer, DTMFTone tone)
tone,
cpDTMFMethod,
minimalToneDuration,
maximalToneDuration);
maximalToneDuration,
volume);
}
}
@ -194,26 +174,6 @@ public synchronized void stopSendingDTMF(CallPeer callPeer)
}
}
/**
* Checks whether rfc4733 is negotiated for this call.
* @param peer the call peer.
* @return whether we can use rfc4733 in this call.
*/
private boolean isRFC4733Active(CallPeerSipImpl peer)
{
Iterator<MediaFormat> iter =
peer.getMediaHandler().getStream(MediaType.AUDIO)
.getDynamicRTPPayloadTypes().values().iterator();
while (iter.hasNext())
{
MediaFormat mediaFormat = iter.next();
if(mediaFormat.getEncoding().equals(Constants.TELEPHONE_EVENT))
return true;
}
return false;
}
/**
* Returns DTMFInfo mode implementation.
* @return DTMFInfo mode implementation.
@ -222,108 +182,4 @@ DTMFInfo getDtmfModeInfo()
{
return dtmfModeInfo;
}
/**
* Returns the corresponding DTMF method used for this account.
*
* @param pps the SIP Protocol provider service
*
* @return the DTMFEnum corresponding to the DTMF method set for this
* account.
*/
private DTMFMethod getDTMFMethod(ProtocolProviderServiceSipImpl pps)
{
AccountID accountID = pps.getAccountID();
String dtmfString = accountID.getAccountPropertyString("DTMF_METHOD");
// Verifies that the DTMF_METHOD property string is correctly set.
// If not, sets this account to the "auto" DTMF method and corrects the
// property string.
if(dtmfString == null
|| (!dtmfString.equals("AUTO_DTMF")
&& !dtmfString.equals("RTP_DTMF")
&& !dtmfString.equals("SIP_INFO_DTMF")
&& !dtmfString.equals("INBAND_DTMF")))
{
dtmfString = "AUTO_DTMF";
accountID.putAccountProperty("DTMF_METHOD", dtmfString);
}
if(dtmfString.equals("AUTO_DTMF"))
{
return DTMFMethod.AUTO_DTMF;
}
else if(dtmfString.equals("RTP_DTMF"))
{
return DTMFMethod.RTP_DTMF;
}
else if(dtmfString.equals("SIP_INFO_DTMF"))
{
return DTMFMethod.SIP_INFO_DTMF;
}
else // if(dtmfString.equals(INBAND_DTMF"))
{
return DTMFMethod.INBAND_DTMF;
}
}
/**
* Gets the minimal DTMF tone duration for this account.
*
* @param pps the SIP Protocol provider service
*
* @return The minimal DTMF tone duration for this account.
*/
private int getMinimalToneDuration(ProtocolProviderServiceSipImpl pps)
{
AccountID accountID = pps.getAccountID();
String minimalToneDurationString
= accountID.getAccountPropertyString("DTMF_MINIMAL_TONE_DURATION");
int minimalToneDuration
= OperationSetDTMF.DEFAULT_DTMF_MINIMAL_TONE_DURATION;
// Check if there is a specific value for this account.
if(!StringUtils.isNullOrEmpty(minimalToneDurationString))
{
minimalToneDuration = Integer.valueOf(minimalToneDurationString);
}
// Else look at the global property.
else
{
ConfigurationService cfg = SipActivator.getConfigurationService();
// Check if there is a custom value for the minimal tone duration.
if(cfg != null)
{
minimalToneDuration = cfg.getInt(
OperationSetDTMF.PROP_MINIMAL_RTP_DTMF_TONE_DURATION,
minimalToneDuration);
}
}
return minimalToneDuration;
}
/**
* Gets the maximal DTMF tone duration for this account.
*
* @return The maximal DTMF tone duration for this account.
*/
private int getMaximalToneDuration()
{
int maximalToneDuration
= OperationSetDTMF.DEFAULT_DTMF_MAXIMAL_TONE_DURATION;
// Look at the global property.
ConfigurationService cfg
= SipActivator.getConfigurationService();
// Check if there is a custom value for the maximal tone duration.
if(cfg != null)
{
maximalToneDuration = cfg.getInt(
OperationSetDTMF.PROP_MAXIMAL_RTP_DTMF_TONE_DURATION,
maximalToneDuration);
}
return maximalToneDuration;
}
}

@ -18,9 +18,9 @@ public interface OperationSetDTMF
extends OperationSet
{
/**
* The minimal tone duration value for RFC4733 is 70 ms.
* The minimal tone duration value for RFC4733 is 100 ms.
*/
public static final int DEFAULT_DTMF_MINIMAL_TONE_DURATION = 70;
public static final int DEFAULT_DTMF_MINIMAL_TONE_DURATION = 100;
/**
* The maximal tone duration value is -1 in order to stop sending tone only
@ -28,6 +28,11 @@ public interface OperationSetDTMF
*/
public static final int DEFAULT_DTMF_MAXIMAL_TONE_DURATION = -1;
/**
* The default tone volume value.
*/
public static final int DEFAULT_DTMF_TONE_VOLUME = 10;
/**
* The name of the <tt>ConfigurationService</tt> <tt>int</tt> property
* which indicates the minimal duration for a DTMF tone.

@ -0,0 +1,205 @@
/*
* 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.protocol.media;
import net.java.sip.communicator.service.protocol.*;
import org.jitsi.service.configuration.*;
import org.jitsi.service.neomedia.*;
import org.jitsi.service.neomedia.codec.*;
import org.jitsi.service.neomedia.format.*;
import org.jitsi.util.*;
import java.util.*;
/**
* Represents a default/base implementation of <tt>OperationSetDTMF</tt>
* which attempts to make it easier for implementers to provide complete
* solutions while focusing on implementation-specific functionality.
*
* @author Damian Minkov
*/
public abstract class AbstractOperationSetDTMF
implements OperationSetDTMF
{
/**
* The DTMF method used to send tones.
*/
protected DTMFMethod dtmfMethod;
/**
* The minimal tone duration.
*/
protected int minimalToneDuration;
/**
* The maximal tone duration.
*/
protected int maximalToneDuration;
/**
* The tone volume.
*/
protected int volume;
/**
* Creates the <tt>AbstractOperationSetDTMF</tt> and initialize
* some settings.
*
* @param pps the protocol provider.
*/
public AbstractOperationSetDTMF(ProtocolProviderService pps)
{
this.dtmfMethod = getDTMFMethod(pps);
this.minimalToneDuration = getMinimalToneDurationSetting(pps);
this.maximalToneDuration = getMaximalToneDurationSetting();
this.volume = getVolumeSetting(pps);
}
/**
* Gets the minimal DTMF tone duration for this account.
*
* @param pps the Protocol provider service
*
* @return The minimal DTMF tone duration for this account.
*/
private static int getMinimalToneDurationSetting(ProtocolProviderService pps)
{
AccountID accountID = pps.getAccountID();
String minimalToneDurationString
= accountID.getAccountPropertyString("DTMF_MINIMAL_TONE_DURATION");
int minimalToneDuration
= OperationSetDTMF.DEFAULT_DTMF_MINIMAL_TONE_DURATION;
// Check if there is a specific value for this account.
if(!StringUtils.isNullOrEmpty(minimalToneDurationString))
{
minimalToneDuration = Integer.valueOf(minimalToneDurationString);
}
// Else look at the global property.
else
{
ConfigurationService cfg =
ProtocolProviderActivator.getConfigurationService();
// Check if there is a custom value for the minimal tone duration.
if(cfg != null)
{
minimalToneDuration = cfg.getInt(
OperationSetDTMF.PROP_MINIMAL_RTP_DTMF_TONE_DURATION,
minimalToneDuration);
}
}
return minimalToneDuration;
}
/**
* Gets the maximal DTMF tone duration for this account.
*
* @return The maximal DTMF tone duration for this account.
*/
private static int getMaximalToneDurationSetting()
{
int maximalToneDuration
= OperationSetDTMF.DEFAULT_DTMF_MAXIMAL_TONE_DURATION;
// Look at the global property.
ConfigurationService cfg
= ProtocolProviderActivator.getConfigurationService();
// Check if there is a custom value for the maximal tone duration.
if(cfg != null)
{
maximalToneDuration = cfg.getInt(
OperationSetDTMF.PROP_MAXIMAL_RTP_DTMF_TONE_DURATION,
maximalToneDuration);
}
return maximalToneDuration;
}
/**
* Returns the corresponding DTMF method used for this account.
*
* @param pps the Protocol provider service
*
* @return the DTMFEnum corresponding to the DTMF method set for this
* account.
*/
private static DTMFMethod getDTMFMethod(ProtocolProviderService pps)
{
AccountID accountID = pps.getAccountID();
String dtmfString = accountID.getAccountPropertyString("DTMF_METHOD");
// Verifies that the DTMF_METHOD property string is correctly set.
// If not, sets this account to the "auto" DTMF method and corrects the
// property string.
if(dtmfString == null
|| (!dtmfString.equals("AUTO_DTMF")
&& !dtmfString.equals("RTP_DTMF")
&& !dtmfString.equals("SIP_INFO_DTMF")
&& !dtmfString.equals("INBAND_DTMF")))
{
dtmfString = "AUTO_DTMF";
accountID.putAccountProperty("DTMF_METHOD", dtmfString);
}
if(dtmfString.equals("AUTO_DTMF"))
{
return DTMFMethod.AUTO_DTMF;
}
else if(dtmfString.equals("RTP_DTMF"))
{
return DTMFMethod.RTP_DTMF;
}
else if(dtmfString.equals("SIP_INFO_DTMF"))
{
return DTMFMethod.SIP_INFO_DTMF;
}
else // if(dtmfString.equals(INBAND_DTMF"))
{
return DTMFMethod.INBAND_DTMF;
}
}
/**
* Checks whether rfc4733 is negotiated for this call.
* @param peer the call peer.
* @return whether we can use rfc4733 in this call.
*/
protected static boolean isRFC4733Active(MediaAwareCallPeer peer)
{
Iterator<MediaFormat> iter =
peer.getMediaHandler().getStream(MediaType.AUDIO)
.getDynamicRTPPayloadTypes().values().iterator();
while (iter.hasNext())
{
MediaFormat mediaFormat = iter.next();
if(mediaFormat.getEncoding().equals(Constants.TELEPHONE_EVENT))
return true;
}
return false;
}
/**
* Gets the DTMF tone volume for this account.
*
* @return The DTMF tone volume for this account.
*/
private static int getVolumeSetting(ProtocolProviderService pps)
{
AccountID accountID = pps.getAccountID();
String volumeString
= accountID.getAccountPropertyString("DTMF_TONE_VOLUME");
int vol = OperationSetDTMF.DEFAULT_DTMF_TONE_VOLUME;
// Check if there is a specific value for this account.
if(!StringUtils.isNullOrEmpty(volumeString))
{
vol = Integer.valueOf(vol);
}
return vol;
}
}
Loading…
Cancel
Save