📄 mediamanager.java
字号:
}
}
finally
{
console.logExit();
}
}
protected void startReceiver(String remoteAddress)
{
try
{
console.logEntry();
avReceiver = new AVReceiver(new String[]
{
remoteAddress + "/" + getAudioPort() +"/1"},sipProp);
avReceiver.setMediaManager(this);
avReceiver.initialize();
receivers.add(avReceiver);
}
finally
{
console.logExit();
}
}
protected void stopReceiver(String LocalAddress)
{
/*try
{
console.logEntry();
if (avReceiver != null)
{
//on ferme la reception dans lengthcas ou il n'u a plus de transm
if(avTransmitters.size()==0)
avReceiver.close(LocalAddress);
//avReceiver = null;
//avReceiver.
}
}
finally
{
console.logExit();
}*/
try
{
console.logEntry();
for (int i = receivers.size() - 1; i >= 0; i--)
{
try
{
( (AVReceiver) receivers.elementAt(i)).close(LocalAddress);
} //Catch everything that comes out as we wouldn't want
//Some null pointer prevent us from closing a device and thus
//render it unusable
catch (Exception exc)
{
console.error("Could not close receiver " + i, exc);
}
receivers.removeElementAt(i);
}
}
finally
{
console.logExit();
}
}
protected void stopReceiver()
{
try
{
console.logEntry();
if (avReceiver != null)
{
avReceiver.close();
avReceiver = null;
}
}
finally
{
console.logExit();
}
}
/**
* Only stops the receiver without deleting it. After calling this method
* one can call softStartReceiver to relauch reception.
*/
public void softStopReceiver()
{
try
{
console.logEntry();
if (avReceiver != null)
{
avReceiver.close();
this.firePlayerStopped();
}
else
console.debug(
"Attempt to soft stop reception for a null avReceiver");
}
finally
{
console.logExit();
}
}
/**
* Starts a receiver that has been stopped using softStopReceiver().
*/
public void softStartReceiver()
{
try
{
console.logEntry();
if (avReceiver != null)
{
avReceiver.initialize();
}
else
console.error(
"acReceiver is null. Use softStartReceiver only for receivers "
+"that had been stopped using softStopReceiver()");
}finally
{
console.logExit();
}
}
void firePlayerStarting(Player player)
{
try
{
console.logEntry();
MediaEvent evt = new MediaEvent(player);
for (int i = listeners.size() - 1; i >= 0; i--)
{
( (MediaListener) listeners.get(i)).playerStarting(evt);
}
}
finally
{
console.logExit();
}
}
void firePlayerStopped()
{
try
{
console.logEntry();
for (int i = listeners.size() - 1; i >= 0; i--)
{
( (MediaListener) listeners.get(i)).playerStopped();
}
}
finally
{
console.logExit();
}
}
void fireNonFatalMediaError(Throwable cause)
{
try
{
console.logEntry();
MediaErrorEvent evt = new MediaErrorEvent(cause);
for (int i = listeners.size() - 1; i >= 0; i--)
{
( (MediaListener) listeners.get(i)).nonFatalMediaErrorOccurred(
evt);
}
}
finally
{
console.logExit();
}
}
public void addMediaListener(MediaListener listener)
{
try
{
console.logEntry();
listeners.add(listener);
}
finally
{
console.logExit();
}
}
InetAddress getLocalHost() throws MediaException
{
try
{
console.logEntry();
String hostAddress = sipProp.getProperty("net.java.sip.communicator.media.IP_ADDRESS");
InetAddress lh ;
lh = InetAddress.getByName(hostAddress);
console.debug(hostAddress);
return lh;
}
catch (Exception ex)
{
ex.toString();
return null;
}
}
public String generateSdpDescription() throws MediaException
{
try
{
console.logEntry();
checkIfStarted();
try
{
SessionDescription sessDescr = sdpFactory.
createSessionDescription();
//"v=0"
Version v = sdpFactory.createVersion(0);
InetSocketAddress publicAudioAddress = NetworkAddressManager.getPublicAddressFor(Integer.parseInt(getAudioPort()));
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(
Utils.getProperty("user.name").replace(' ', '_'), 0, 0, "IN", addrType, publicIpAddress.getHostAddress());
//"s=-"
SessionName s = sdpFactory.createSessionName("-");
//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
surfacePreferredEncodings(getReceivableAudioFormats());
String[] formats = getReceivableAudioFormats();
MediaDescription am = sdpFactory.createMediaDescription("audio", publicAudioAddress.getPort(), 1, "RTP/AVP",formats);
if (!isAudioTransmissionSupported())
{
am.setAttribute("recvonly", null);
//--------Video media description
}
surfacePreferredEncodings(getReceivableVideoFormats());
//"m=video 22222 RTP/AVP 34";
String[] vformats = getReceivableVideoFormats();
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);
if (console.isDebugEnabled())
{
console.debug("Generated SDP - " + sessDescr.toString());
}
return sessDescr.toString();
}
catch (SdpException exc)
{
console.error(
"An SDP exception occurred while generating local sdp description",
exc);
throw new MediaException(
"An SDP exception occurred while generating local sdp description",
exc);
}
}
finally
{
console.logExit();
}
}
public String getAudioPort()
{
try
{
console.logEntry();
String audioPort = this.audioPort;
return audioPort == null ? "22224" : audioPort;
}
finally
{
console.logExit();
}
}
protected void finalize()
{
try
{
console.logEntry();
try
{
if (avDataSource != null)
{
avDataSource.disconnect();
}
}
catch (Exception exc)
{
console.error("Failed to disconnect data source:" +
exc.getMessage());
}
}
finally
{
console.logExit();
}
}
public boolean isStarted()
{
return isStarted;
}
protected void checkIfStarted() throws MediaException
{
if (!isStarted())
{
console.error("The MediaManager had not been properly started! "
+ "Impossible to continue");
throw new MediaException(
"The MediaManager had not been properly started! "
+ "Impossible to continue");
}
}
protected boolean isAudioTransmissionSupported()
{
return transmittableAudioFormats.size() > 0;
}
protected boolean isMediaTransmittable(String media)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -