mirror of https://github.com/sipwise/jitsi.git
cusax-fix
parent
d6f516bf9e
commit
ce9ca06ac2
@ -1,232 +0,0 @@
|
||||
/*
|
||||
* SIP Communicator, 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.protocol.jabber.mediamgr;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.java.sip.communicator.impl.protocol.jabber.*;
|
||||
//import net.java.sip.communicator.service.media.*;
|
||||
//import net.java.sip.communicator.service.media.event.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
import org.jivesoftware.smackx.jingle.*;
|
||||
import org.jivesoftware.smackx.jingle.media.*;
|
||||
import org.jivesoftware.smackx.jingle.nat.*;
|
||||
|
||||
/**
|
||||
* This Class implements a JingleMediaSession. which serve as a wrapper
|
||||
* for a RtpFlow, allowing us to receive and transmit audio.
|
||||
*
|
||||
* based on Thiago Camargo's media manager from jingle
|
||||
*
|
||||
* @author Symphorien Wanko
|
||||
*/
|
||||
public class AudioMediaSession
|
||||
extends JingleMediaSession
|
||||
// implements MediaListener
|
||||
{
|
||||
/**
|
||||
* the logger used by this class
|
||||
*/
|
||||
private static final Logger logger
|
||||
= Logger.getLogger(AudioMediaSession.class);
|
||||
|
||||
/**
|
||||
* An audio media session encapsulate a RtpFlow which handle media transfer
|
||||
*/
|
||||
// private RtpFlow rtpFlow = null;
|
||||
|
||||
/**
|
||||
* Creates an AudioMediaSession with defined payload type,
|
||||
* remote and local candidates
|
||||
*
|
||||
* @param payloadType Payload used by jmf
|
||||
* @param remote the remote information.
|
||||
* @param local the local information.
|
||||
* @param jingleSession the session for which we create a media session
|
||||
*/
|
||||
public AudioMediaSession(PayloadType payloadType, TransportCandidate remote
|
||||
, TransportCandidate local, JingleSession jingleSession)
|
||||
{
|
||||
this(payloadType, remote, local, null, null);
|
||||
initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is used only to match the one of our super class.
|
||||
* In SC, An audioSession don't need the media locator asked by
|
||||
* <tt>jingleMediaSession</tt> because the locator is handled
|
||||
* by the media service.
|
||||
*
|
||||
* @param payloadType Payload used by jmf
|
||||
* @param remote the remote information.
|
||||
* @param local the local information.
|
||||
* @param locator media locator
|
||||
* @param jingleSession the session for which we create a media session
|
||||
*/
|
||||
private AudioMediaSession(PayloadType payloadType, TransportCandidate remote
|
||||
, TransportCandidate local, String locator, JingleSession jingleSession)
|
||||
{
|
||||
//super(payloadType, remote, local, locator==null?"dsound://":locator, jingleSession);
|
||||
super(payloadType, remote, local, locator, jingleSession);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the RtpFlow to make us able to send and receive audio media
|
||||
*/
|
||||
public void initialize()
|
||||
{
|
||||
String remoteIp;
|
||||
String localIp;
|
||||
int localPort;
|
||||
int remotePort;
|
||||
|
||||
// if (getLocal().getSymmetric() != null)
|
||||
// {
|
||||
// remoteIp = getLocal().getIp();
|
||||
// localIp = getLocal().getLocalIp();
|
||||
// localPort = getFreePort();
|
||||
// remotePort = getLocal().getSymmetric().getPort();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
if (getLocal().getSymmetric() != null)
|
||||
{
|
||||
logger.warn("oops : unexpected situation ... ");
|
||||
// TODO : if this situation happens only one
|
||||
// un comment the above code wich is meant to handle this
|
||||
}
|
||||
|
||||
remoteIp = getRemote().getIp();
|
||||
localIp = getLocal().getLocalIp();
|
||||
localPort = getLocal().getPort();
|
||||
remotePort = getRemote().getPort();
|
||||
if (logger.isInfoEnabled())
|
||||
logger.info("AudioMediaSession : " + localIp + ":" + localPort +
|
||||
" <-> " + remoteIp + ":" + remotePort);
|
||||
// }
|
||||
|
||||
Map<String, List<String>> mediaEncoding
|
||||
= MediaUtils.getAudioEncoding(getPayloadType().getId());
|
||||
// try
|
||||
// {
|
||||
// rtpFlow = JabberActivator.getMediaService().
|
||||
// createRtpFlow(
|
||||
// localIp, localPort,
|
||||
// remoteIp, remotePort,
|
||||
// mediaEncoding);
|
||||
// }
|
||||
// catch (MediaException ex)
|
||||
// {
|
||||
// logger.error("failed to create a RtpFlow between " +
|
||||
// localIp + ":" + localPort + " and " +
|
||||
// remoteIp + ":" + remotePort, ex);
|
||||
// rtpFlow = null;
|
||||
// throw new RuntimeException("failed to create a RtpFlow between "
|
||||
// + localIp + ":" + localPort + " and "
|
||||
// + remoteIp + ":" + remotePort,
|
||||
// ex);
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements <tt>startTransmit</tt> from <tt>JingleMediaSession.</tt>
|
||||
*/
|
||||
public void startTrasmit()
|
||||
{
|
||||
// rtpFlow.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements <tt>startReceive</tt> from <tt>JingleMediaSession.</tt>
|
||||
*/
|
||||
public void startReceive()
|
||||
{}
|
||||
|
||||
/**
|
||||
* Implements <tt>setTrasmit</tt> from <tt>JingleMediaSession.</tt>
|
||||
*
|
||||
* @param active pause the transmission if false, resume otherwise
|
||||
*/
|
||||
public void setTrasmit(boolean active)
|
||||
{
|
||||
// if (active)
|
||||
// rtpFlow.resume();
|
||||
// else
|
||||
// rtpFlow.pause();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements <tt>stopTrasmit</tt> from <tt>JingleMediaSession.</tt>
|
||||
*/
|
||||
public void stopTrasmit()
|
||||
{
|
||||
//if (rtpFlow != null)
|
||||
// rtpFlow.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements <tt>stopReceive</tt> from <tt>JingleMediaSession.</tt>
|
||||
*/
|
||||
public void stopReceive()
|
||||
{}
|
||||
|
||||
// /**
|
||||
// * Obtain a free port we can use.
|
||||
// *
|
||||
// * @return A free port number.
|
||||
// */
|
||||
// protected int getFreePort()
|
||||
// {
|
||||
// //perhaps this method will be better in an utily class
|
||||
//
|
||||
// ServerSocket ss;
|
||||
// int freePort = 0;
|
||||
//
|
||||
// for (int i = 0; i < 10; i++)
|
||||
// {
|
||||
// freePort = (int) (10000 + Math.round(Math.random() * 10000));
|
||||
// freePort = freePort % 2 == 0 ? freePort : freePort + 1;
|
||||
// try
|
||||
// {
|
||||
// ss = new ServerSocket(freePort);
|
||||
// freePort = ss.getLocalPort();
|
||||
// ss.close();
|
||||
// return freePort;
|
||||
// }
|
||||
// catch (IOException e)
|
||||
// {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// try
|
||||
// {
|
||||
// ss = new ServerSocket(0);
|
||||
// freePort = ss.getLocalPort();
|
||||
// ss.close();
|
||||
// }
|
||||
// catch (IOException e)
|
||||
// {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// return freePort;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Implementation of <tt>receivedMediaStream</tt> from
|
||||
* <tt>RtpFlow</tt>.
|
||||
*/
|
||||
// public void receivedMediaStream(MediaEvent evt)
|
||||
// {
|
||||
// mediaReceived(evt.getFrom());
|
||||
// }
|
||||
//
|
||||
// public void mediaServiceStatusChanged()
|
||||
// {
|
||||
// }
|
||||
}
|
||||
@ -1,130 +0,0 @@
|
||||
/*
|
||||
* SIP Communicator, 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.protocol.jabber.mediamgr;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.java.sip.communicator.impl.protocol.jabber.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
import org.jivesoftware.smackx.jingle.*;
|
||||
import org.jivesoftware.smackx.jingle.media.*;
|
||||
import org.jivesoftware.smackx.jingle.nat.*;
|
||||
|
||||
/**
|
||||
* Implements a JingleMediaManager backed by JMF.
|
||||
* based on Thiago Camargo's media manager from jingle
|
||||
*
|
||||
* @author Symphorien Wanko
|
||||
*/
|
||||
public class JingleScMediaManager extends JingleMediaManager
|
||||
{
|
||||
/**
|
||||
* Logger for this class
|
||||
*/
|
||||
private final Logger logger = Logger.getLogger(JingleScMediaManager.class);
|
||||
|
||||
/**
|
||||
* List of payload that this media manager supports. This list is based on
|
||||
* the one reported by the media service.
|
||||
*/
|
||||
private final List<PayloadType> payloads = new ArrayList<PayloadType>();
|
||||
|
||||
/**
|
||||
* Creates a new instance of JingleScMediaManager
|
||||
*/
|
||||
public JingleScMediaManager()
|
||||
{
|
||||
setupPayloads();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new jingleMediaSession
|
||||
*
|
||||
* @param payloadType payloadType
|
||||
* @param remote remote Candidate
|
||||
* @param local local Candidate
|
||||
* @param jingleSession the session for which we create a media session
|
||||
*
|
||||
* @return JingleMediaSession
|
||||
*/
|
||||
public JingleMediaSession createMediaSession(
|
||||
PayloadType payloadType,
|
||||
TransportCandidate remote,
|
||||
TransportCandidate local, JingleSession jingleSession)
|
||||
{
|
||||
return new AudioMediaSession(payloadType, remote, local, jingleSession);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup API supported Payloads
|
||||
*
|
||||
* http://tools.ietf.org/html/rfc3551#page-32 to view the correspondence
|
||||
* between PayloadType and codec
|
||||
*/
|
||||
private void setupPayloads()
|
||||
{
|
||||
|
||||
/*
|
||||
* Initializing audioEnc to new String[0] isn't better than setting it
|
||||
* to null upon an exception because the former causes an allocation.
|
||||
* Besides, the exception is supposes to happen in rare/exceptional
|
||||
* situations i.e. in most of the cases the allocation will immediately
|
||||
* be thrown away as garbage. Checking for null is faster.
|
||||
*/
|
||||
String[] audioEnc = null;
|
||||
|
||||
try
|
||||
{
|
||||
audioEnc = null;// JabberActivator.getMediaService().
|
||||
//getSupportedAudioEncodings();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
audioEnc = null;
|
||||
|
||||
logger.warn("Cannot get Audio encodings!", e);
|
||||
}
|
||||
|
||||
if (audioEnc != null)
|
||||
{
|
||||
for (String audioEncI : audioEnc)
|
||||
{
|
||||
int payloadType =
|
||||
MediaUtils.getPayloadType(Integer.parseInt(audioEncI));
|
||||
String payloadName = MediaUtils.getPayloadName(payloadType);
|
||||
|
||||
if (payloadName != null)
|
||||
{
|
||||
payloads
|
||||
.add(new PayloadType.Audio(payloadType, payloadName));
|
||||
}
|
||||
else if (payloadType >= 0)
|
||||
{
|
||||
payloads
|
||||
.add(new PayloadType.Audio(payloadType, audioEncI));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (payloads.isEmpty())
|
||||
{
|
||||
logger.warn("The list of payloads supported" +
|
||||
" by JmfMediaManager is empty ");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all supported Payloads for this Manager
|
||||
*
|
||||
* @return The Payload List
|
||||
*/
|
||||
|
||||
public List<PayloadType> getPayloads()
|
||||
{
|
||||
return payloads;
|
||||
}
|
||||
}
|
||||
@ -1,218 +0,0 @@
|
||||
/*
|
||||
* SIP Communicator, 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.protocol.jabber.mediamgr;
|
||||
|
||||
import java.util.*;
|
||||
import javax.media.format.*;
|
||||
import javax.sdp.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
//
|
||||
// TODO: merge this MediaUtils with the one in impl/media
|
||||
// There is a MediaUtils class in package impl.media
|
||||
// which isn't exposed by the media service. It will
|
||||
// be a good idea to find a mean to merge this two
|
||||
// class somewhere
|
||||
//
|
||||
/**
|
||||
* Media utils
|
||||
* A collection of static methods related to media.
|
||||
*
|
||||
* @author Symphorien Wanko
|
||||
*/
|
||||
public abstract class MediaUtils
|
||||
{
|
||||
|
||||
/**
|
||||
* logger of this class
|
||||
*/
|
||||
private static final Logger logger =
|
||||
Logger.getLogger(MediaUtils.class);
|
||||
|
||||
/**
|
||||
* <tt>getAudioEncoding</tt> return an <tt>Hashtable</tt>
|
||||
* with one entry in a format wich can be directly passed
|
||||
* to the media service for creating a <tt>RtpFlow</tt>
|
||||
* based on this encoding.
|
||||
*
|
||||
* @param payloadType the payload type
|
||||
* @return an hashtable ready to be passed to media service
|
||||
*/
|
||||
public static Map<String, List<String>> getAudioEncoding(int payloadType)
|
||||
{
|
||||
Map<String, List<String>> ht = new Hashtable<String, List<String>>();
|
||||
List<String> list = new ArrayList<String>();
|
||||
ht.put("audio", list);
|
||||
// most of the format aren't handled by SC now
|
||||
// but itsn't a problem. it will facilitates
|
||||
// updates when more codecs will become available
|
||||
// in SC.
|
||||
switch (payloadType)
|
||||
{
|
||||
case SdpConstants.PCMU:
|
||||
list.add(AudioFormat.ULAW_RTP);
|
||||
return ht;
|
||||
case SdpConstants.GSM:
|
||||
list.add(AudioFormat.GSM_RTP);
|
||||
return ht;
|
||||
case SdpConstants.G723:
|
||||
list.add(AudioFormat.G723_RTP);
|
||||
return ht;
|
||||
case SdpConstants.DVI4_8000:
|
||||
list.add(AudioFormat.DVI_RTP);
|
||||
return ht;
|
||||
case SdpConstants.DVI4_16000:
|
||||
list.add(AudioFormat.DVI_RTP);
|
||||
return ht;
|
||||
//case SdpConstants.LPC:
|
||||
// list.add(AudioFormat...);
|
||||
// return ht;
|
||||
case SdpConstants.PCMA:
|
||||
list.add(AudioFormat.ALAW);
|
||||
return ht;
|
||||
//case SdpConstants.G722:
|
||||
// list.add(AudioFormat...);
|
||||
// return ht;
|
||||
//case SdpConstants.L16_1CH:
|
||||
// list.add(AudioFormat...);
|
||||
// return ht;
|
||||
//case SdpConstants.L16_2CH:
|
||||
// list.add(AudioFormat...);
|
||||
// return ht;
|
||||
//case SdpConstants.QCELP:
|
||||
// list.add(AudioFormat...);
|
||||
// return ht;
|
||||
//case SdpConstants.CN:
|
||||
// list.add(AudioFormat...);
|
||||
// return ht;
|
||||
//case SdpConstants.MPA:
|
||||
// list.add(AudioFormat...);
|
||||
// return ht;
|
||||
case SdpConstants.G728:
|
||||
list.add(AudioFormat.G728_RTP);
|
||||
return ht;
|
||||
case SdpConstants.DVI4_11025:
|
||||
list.add(AudioFormat.DVI_RTP);
|
||||
return ht;
|
||||
case SdpConstants.DVI4_22050:
|
||||
list.add(AudioFormat.DVI_RTP);
|
||||
return ht;
|
||||
case SdpConstants.G729:
|
||||
list.add(AudioFormat.G729_RTP);
|
||||
return ht;
|
||||
default:
|
||||
//throw new IllegalStateException("Unknown payload type");
|
||||
logger.warn("unknown payload type : " + payloadType);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gives the name wich correspond to a payload type
|
||||
*
|
||||
* @param payloadType the type of the payload
|
||||
* @return the string corresponding to the payload
|
||||
*/
|
||||
public static String getPayloadName(int payloadType)
|
||||
{
|
||||
// for update, seee http://tools.ietf.org/html/rfc3551#page-32
|
||||
switch (payloadType)
|
||||
{
|
||||
case SdpConstants.PCMU:
|
||||
return "PCMU";
|
||||
case SdpConstants.GSM:
|
||||
return "GSM";
|
||||
case SdpConstants.G723:
|
||||
return "G723";
|
||||
case SdpConstants.DVI4_8000:
|
||||
return "DVI4_8000";
|
||||
case SdpConstants.DVI4_16000:
|
||||
return "DVI4_16000";
|
||||
case SdpConstants.LPC:
|
||||
return "LPC";
|
||||
case SdpConstants.PCMA:
|
||||
return "PCMA";
|
||||
case SdpConstants.G722:
|
||||
return "G722";
|
||||
case SdpConstants.L16_1CH:
|
||||
return "L16_1CH";
|
||||
case SdpConstants.L16_2CH:
|
||||
return "L16_2CH";
|
||||
case SdpConstants.QCELP:
|
||||
return "QCELP";
|
||||
case SdpConstants.CN:
|
||||
return "CN";
|
||||
case SdpConstants.MPA:
|
||||
return "MPA";
|
||||
case SdpConstants.G728:
|
||||
return "G728";
|
||||
case SdpConstants.DVI4_11025:
|
||||
return "DVI4_11025";
|
||||
case SdpConstants.DVI4_22050:
|
||||
return "DVI4_22050";
|
||||
case SdpConstants.G729:
|
||||
return "G729";
|
||||
default:
|
||||
//throw new IllegalStateException("Unknown payload type");
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("unknown payload type : " + payloadType);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a <tt>SdpConstant</tt> to the corresponding payload type.
|
||||
*
|
||||
* @param sdpConstant the sdp constant to convert.
|
||||
* @return the payload type which match the provided sdp constant.
|
||||
*/
|
||||
public static int getPayloadType(int sdpConstant)
|
||||
{
|
||||
switch (sdpConstant)
|
||||
{
|
||||
case SdpConstants.PCMU:
|
||||
return 0;
|
||||
case SdpConstants.GSM:
|
||||
return 3;
|
||||
case SdpConstants.G723:
|
||||
return 4;
|
||||
case SdpConstants.DVI4_8000:
|
||||
return 5;
|
||||
case SdpConstants.DVI4_16000:
|
||||
return 6;
|
||||
case SdpConstants.LPC:
|
||||
return 7;
|
||||
case SdpConstants.PCMA:
|
||||
return 8;
|
||||
case SdpConstants.G722:
|
||||
return 9;
|
||||
case SdpConstants.L16_1CH:
|
||||
return 10;
|
||||
case SdpConstants.L16_2CH:
|
||||
return 11;
|
||||
case SdpConstants.QCELP:
|
||||
return 12;
|
||||
case SdpConstants.CN:
|
||||
return 13;
|
||||
case SdpConstants.MPA:
|
||||
return 14;
|
||||
case SdpConstants.G728:
|
||||
return 15;
|
||||
case SdpConstants.DVI4_11025:
|
||||
return 16;
|
||||
case SdpConstants.DVI4_22050:
|
||||
return 17;
|
||||
case SdpConstants.G729:
|
||||
return 18;
|
||||
default:
|
||||
//throw new IllegalStateException("Unknown sdp constant");
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("unknown sdp constant : " + sdpConstant);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue