📄 jmfmediamanager.java
字号:
AudioMediaSession audioMediaSession = new AudioMediaSession(audioFormat, remote, local, locator);
return audioMediaSession;
}
return null;
}
/**
* Creates a new AudioReceiverChannel Session for a given sdpData
*
* @param localPort localPort
* @return
* @throws MediaException
*/
public AudioReceiverChannel createAudioReceiverChannel(int localPort, String remoteIp, int remotePort) throws MediaException {
AudioReceiverChannel audioReceiverChannel = new AudioReceiverChannel(NetworkAddressManager.getLocalHost().getHostAddress(), localPort, remoteIp, remotePort);
return audioReceiverChannel;
}
/**
* Extract the supported formats for JMF from a Vector
*
* @param sdpFormats
* @return
* @throws MediaException
*/
protected ArrayList<String> extractTransmittableJmfFormats(Vector sdpFormats)
throws MediaException {
ArrayList jmfFormats = new ArrayList();
for (int i = 0; i < sdpFormats.size(); i++) {
int sdpFormat = -1;
String jmfFormat = AudioFormatUtils.findCorrespondingJmfFormat(sdpFormats
.elementAt(i).toString());
if (jmfFormat != null) {
jmfFormats.add(jmfFormat);
}
}
if (jmfFormats.size() == 0) {
throw new MediaException(
"None of the supplied sdp formats for is supported by SIP COMMUNICATOR");
}
return jmfFormats;
}
public SessionDescription generateSdpDescription() throws MediaException {
try {
SessionDescription sessDescr = sdpFactory
.createSessionDescription();
int audioPort, videoPort;
audioPort = (int) (5000 * Math.random()) + 5000;
if (audioPort % 2 != 0) audioPort++;
do {
videoPort = (int) (5000 * Math.random()) + 5000;
if (videoPort % 2 != 0) videoPort++;
}
while (audioPort == videoPort);
// videoPort = "22497";
// audioPort = "16251";
Version v = sdpFactory.createVersion(0);
InetSocketAddress publicVideoAddress = NetworkAddressManager
.getPublicAddressFor(videoPort);
InetSocketAddress publicAudioAddress = NetworkAddressManager
.getPublicAddressFor(audioPort);
InetAddress publicIpAddress = publicAudioAddress.getAddress();
String addrType = publicIpAddress instanceof Inet6Address ? "IP6"
: "IP4";
// spaces in the user name mess everything up.
// bug report - Alessandro Melzi
Origin o = sdpFactory.createOrigin(SIPConfig.getUserName()
.replace(' ', '_'), 20109217, 2, "IN", addrType,
publicIpAddress.getHostAddress());
// "s=-"
SessionName s = sdpFactory.createSessionName("<SIPmack>");
// c=
Connection c = sdpFactory.createConnection("IN", addrType,
publicIpAddress.getHostAddress());
// "t=0 0"
TimeDescription t = sdpFactory.createTimeDescription();
Vector timeDescs = new Vector();
timeDescs.add(t);
// --------Audio media description
// make sure preferred formats come first
String[] formats = new String[getAudioFormats().size()];
int i = 0;
for (AudioFormat audioFormat : getAudioFormats()) {
formats[i++] = AudioFormatUtils.findCorrespondingSdpFormat(audioFormat.getEncoding());
}
MediaDescription am = sdpFactory.createMediaDescription(
"audio", publicAudioAddress.getPort(), 1, "RTP/AVP",
formats);
//if (!isAudioTransmissionSupported()) {
//am.setAttribute("recvonly", null);
// --------Video media description
//} else {
am.setAttribute("sendrecv", null);
//}
am.setAttribute("rtmap:101", "telephone-event/"
+ publicAudioAddress.getPort());
Vector mediaDescs = new Vector();
mediaDescs.add(am);
sessDescr.setVersion(v);
sessDescr.setOrigin(o);
sessDescr.setConnection(c);
sessDescr.setSessionName(s);
sessDescr.setTimeDescriptions(timeDescs);
if (mediaDescs.size() > 0)
sessDescr.setMediaDescriptions(mediaDescs);
return sessDescr;
}
catch (SdpException exc) {
throw new MediaException(
"An SDP exception occurred while generating local sdp description",
exc);
}
}
/**
* Generates the Hold Description for a Call.
*
* @param setAudio set hold on Audio.
* @param setVideo set hold on Video.
* @param call the call that you want to hold.
* @return SessionDescription of a call.
* @throws MediaException
*/
public SessionDescription generateHoldSdpDescription(boolean setAudio, boolean setVideo, Call call)
throws MediaException {
try {
SessionDescription sessDescr = sdpFactory
.createSessionDescription();
Version v = sdpFactory.createVersion(0);
InetSocketAddress publicAudioAddress = NetworkAddressManager
.getPublicAddressFor(((MediaDescription) (call.getLocalSdpDescription().getMediaDescriptions(true).get(0))).getMedia().getMediaPort());
InetAddress publicIpAddress = publicAudioAddress.getAddress();
String addrType = publicIpAddress instanceof Inet6Address ? "IP6"
: "IP4";
Origin o = sdpFactory.createOrigin(SIPConfig.getUserName()
.replace(' ', '_'), 20109217, 2, "IN", addrType,
publicIpAddress.getHostAddress());
SessionName s = sdpFactory.createSessionName("<SIPmack>");
Connection c = sdpFactory.createConnection("IN", addrType,
publicIpAddress.getHostAddress());
TimeDescription t = sdpFactory.createTimeDescription();
Vector timeDescs = new Vector();
timeDescs.add(t);
String[] formats = new String[getAudioFormats().size()];
int i = 0;
for (AudioFormat audioFormat : getAudioFormats()) {
formats[i++] = AudioFormatUtils.findCorrespondingSdpFormat(audioFormat.getEncoding());
}
MediaDescription am = sdpFactory.createMediaDescription(
"audio", publicAudioAddress.getPort(), 1, "RTP/AVP",
formats);
am.setAttribute(setAudio ? "sendonly" : "sendrecv", null);
am.setAttribute("rtmap:101", "telephone-event/"
+ publicAudioAddress.getPort());
Vector mediaDescs = new Vector();
mediaDescs.add(am);
sessDescr.setVersion(v);
sessDescr.setOrigin(o);
sessDescr.setConnection(c);
sessDescr.setSessionName(s);
sessDescr.setTimeDescriptions(timeDescs);
if (mediaDescs.size() > 0)
sessDescr.setMediaDescriptions(mediaDescs);
return sessDescr;
}
catch (SdpException exc) {
throw new MediaException(
"An SDP exception occurred while generating local sdp description",
exc);
}
}
/**
* Runs JMFInit the first time the application is started so that capture
* devices are properly detected and initialized by JMF.
*/
public static void setupJMF() {
// .jmf is the place where we store the jmf.properties file used
// by JMF. if the directory does not exist or it does not contain
// a jmf.properties file. or if the jmf.properties file has 0 length
// then this is the first time we're running and should continue to
// with JMFInit
String homeDir = System.getProperty("user.home");
File jmfDir = new File(homeDir, ".jmf");
String classpath = System.getProperty("java.class.path");
classpath += System.getProperty("path.separator")
+ jmfDir.getAbsolutePath();
System.setProperty("java.class.path", classpath);
if (!jmfDir.exists())
jmfDir.mkdir();
File jmfProperties = new File(jmfDir, "jmf.properties");
if (!jmfProperties.exists()) {
try {
jmfProperties.createNewFile();
}
catch (IOException ex) {
System.out.println("Failed to create jmf.properties");
ex.printStackTrace();
}
}
// if we're running on linux checkout that libjmutil.so is where it
// should be and put it there.
runLinuxPreInstall();
//if (jmfProperties.length() == 0) {
new JMFInit(null, false);
//}
}
private static void runLinuxPreInstall() {
// @TODO Implement Linux Pre-Install
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -