diff options
author | Nik <nikvaessen@users.noreply.github.com> | 2016-07-05 23:48:14 +0200 |
---|---|---|
committer | Ingo Bauersachs <ingo@jitsi.org> | 2016-07-05 23:48:14 +0200 |
commit | 3961c5df59d60e0edc0f9ab02fb07b24d122cff6 (patch) | |
tree | 0159ef32f68d1efda3c425e098c999a9015da35d | |
parent | a8b817046cb049acd51008d6466d89fedcdd0524 (diff) | |
download | jitsi-3961c5df59d60e0edc0f9ab02fb07b24d122cff6.zip jitsi-3961c5df59d60e0edc0f9ab02fb07b24d122cff6.tar.gz jitsi-3961c5df59d60e0edc0f9ab02fb07b24d122cff6.tar.bz2 |
code clean up (#277)
* code cleanup
* code cleanup
* code cleanup
* code cleanup
9 files changed, 269 insertions, 208 deletions
diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/CallPeerJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/CallPeerJabberImpl.java index ef78202..69af6ae 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/CallPeerJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/CallPeerJabberImpl.java @@ -1610,14 +1610,17 @@ public class CallPeerJabberImpl */ public void setSenders(MediaType mediaType, SendersEnum senders) { - if (mediaType == null) - return; - else if (MediaType.AUDIO.equals(mediaType)) - this.audioSenders = senders; - else if (MediaType.VIDEO.equals(mediaType)) - this.videoSenders = senders; - else - throw new IllegalArgumentException("mediaType"); + switch(mediaType) + { + case AUDIO: + this.audioSenders = senders; + break; + case VIDEO: + this.videoSenders = senders; + break; + default: + throw new IllegalArgumentException("mediaType"); + } } /** diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/CallPeerMediaHandlerJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/CallPeerMediaHandlerJabberImpl.java index 2c8845d..979d696 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/CallPeerMediaHandlerJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/CallPeerMediaHandlerJabberImpl.java @@ -937,19 +937,18 @@ public class CallPeerMediaHandlerJabberImpl if (supportedTransports != null && supportedTransports.length > 0) { - for (int i = 0; i < supportedTransports.length; i++) + for(String supportedTransport : supportedTransports) { if (ProtocolProviderServiceJabberImpl. URN_XMPP_JINGLE_ICE_UDP_1. - equals(supportedTransports[i])) + equals(supportedTransport)) { - transportManager - = new IceUdpTransportManager(peer); + transportManager = new IceUdpTransportManager(peer); break; } else if (ProtocolProviderServiceJabberImpl. - URN_XMPP_JINGLE_RAW_UDP_0. - equals(supportedTransports[i])) + URN_XMPP_JINGLE_RAW_UDP_0. + equals(supportedTransport)) { transportManager = new RawUdpTransportManager(peer); @@ -1117,12 +1116,11 @@ public class CallPeerMediaHandlerJabberImpl List<Component> visualComponents = new LinkedList<Component>(); - for (int i = 0; i < remoteSSRCs.length; i++) + for(int remoteSSRC : remoteSSRCs) { - int remoteSSRC = remoteSSRCs[i]; Component visualComponent - = videoStream.getVisualComponent( - 0xFFFFFFFFL & remoteSSRC); + = videoStream.getVisualComponent( + 0xFFFFFFFFL & remoteSSRC); if (visualComponent != null) visualComponents.add(visualComponent); @@ -1605,7 +1603,7 @@ public class CallPeerMediaHandlerJabberImpl { List<MediaFormat> fmts = supportedFormats; - if(fmts.size() > 0) + if(!fmts.isEmpty()) { MediaFormat fmt = fmts.get(0); @@ -2108,21 +2106,17 @@ public class CallPeerMediaHandlerJabberImpl * TODO The transportManager is going to be changed so it may need to be * disposed of prior to the change. */ - - if (xmlns.equals( - ProtocolProviderServiceJabberImpl.URN_XMPP_JINGLE_ICE_UDP_1)) + switch (xmlns) { - transportManager = new IceUdpTransportManager(peer); - } - else if (xmlns.equals( - ProtocolProviderServiceJabberImpl.URN_XMPP_JINGLE_RAW_UDP_0)) - { - transportManager = new RawUdpTransportManager(peer); - } - else - { - throw new IllegalArgumentException( - "Unsupported Jingle transport " + xmlns); + case ProtocolProviderServiceJabberImpl.URN_XMPP_JINGLE_ICE_UDP_1: + transportManager = new IceUdpTransportManager(peer); + break; + case ProtocolProviderServiceJabberImpl.URN_XMPP_JINGLE_RAW_UDP_0: + transportManager = new RawUdpTransportManager(peer); + break; + default: + throw new IllegalArgumentException("Unsupported Jingle " + + "transport " + xmlns); } synchronized(transportManagerSyncRoot) diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/IceUdpTransportManager.java b/src/net/java/sip/communicator/impl/protocol/jabber/IceUdpTransportManager.java index 1f4e3d8..d326b96 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/IceUdpTransportManager.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/IceUdpTransportManager.java @@ -58,11 +58,21 @@ public class IceUdpTransportManager = Logger.getLogger(IceUdpTransportManager.class); /** + * Default STUN server address. + */ + protected static final String DEFAULT_STUN_SERVER_ADDRESS = "stun.jitsi.net"; + + /** + * Default STUN server port. + */ + protected static final int DEFAULT_STUN_SERVER_PORT = 3478; + + /** * The ICE <tt>Component</tt> IDs in their common order used, for example, * by <tt>DefaultStreamConnector</tt>, <tt>MediaStreamTarget</tt>. */ private static final int[] COMPONENT_IDS - = new int[] { Component.RTP, Component.RTCP }; + = new int[] { Component.RTP, Component.RTCP }; /** * This is where we keep our answer between the time we get the offer and @@ -76,15 +86,6 @@ public class IceUdpTransportManager */ protected final Agent iceAgent; - /** - * Default STUN server address. - */ - protected static final String DEFAULT_STUN_SERVER_ADDRESS = "stun.jitsi.net"; - - /** - * Default STUN server port. - */ - protected static final int DEFAULT_STUN_SERVER_PORT = 3478; /** * Creates a new instance of this transport manager, binding it to the @@ -156,7 +157,10 @@ public class IceUdpTransportManager // in case user has canceled the login window if(credentials == null) + { + logger.info("Credentials were null. User has most likely canceled the login operation"); return null; + } //extract the password the user passed us. char[] pass = credentials.getPassword(); @@ -164,7 +168,10 @@ public class IceUdpTransportManager // the user didn't provide us a password (i.e. canceled the // operation) if(pass == null) + { + logger.info("Password was null. User has most likely canceled the login operation"); return null; + } password = new String(pass); if (credentials.isPasswordPersistent()) @@ -398,13 +405,17 @@ public class IceUdpTransportManager if (selectedPair != null) { DatagramSocket streamConnectorSocket - = selectedPair.getLocalCandidate(). - getDatagramSocket(); + = selectedPair.getDatagramSocket(); if (streamConnectorSocket != null) { streamConnectorSockets[i] = streamConnectorSocket; streamConnectorSocketCount++; + logger.trace("Added a streamConnectorSocket to the array " + + "StreamConnectorSocket and increased " + + "the count of streamConnectorSocketCount by one to " + + streamConnectorSocketCount); + } } } @@ -742,20 +753,25 @@ public class IceUdpTransportManager ex); } - //let's now update the next port var as best we can: we would assume - //that all local candidates are bound on the same port and set it - //to the one just above. if the assumption is wrong the next bind - //would simply include one more bind retry. + // Attempt to minimize subsequent bind retries: see if we have allocated + // any ports from the dynamic range, and if so update the port tracker. + // Do NOT update the port tracker with non-dynamic ports (e.g. 4443 + // coming from TCP) because this will force it to revert back it its + // configured min port. When maxPort is reached, allocation will begin + // from minPort again, so we don't have to worry about wraps. try { - portTracker.setNextPort( - 1 - + stream - .getComponent(Component.RTCP) - .getLocalCandidates() - .get(0) - .getTransportAddress() - .getPort()); + int maxAllocatedPort = getMaxAllocatedPort( + stream, + portTracker.getMinPort(), + portTracker.getMaxPort()); + + if(maxAllocatedPort > 0) + { + int nextPort = 1 + maxAllocatedPort; + portTracker.setNextPort(nextPort); + logger.debug("Updating the port tracker min port: " + nextPort); + } } catch(Throwable t) { @@ -768,6 +784,48 @@ public class IceUdpTransportManager } /** + * @return the highest local port used by any of the local candidates of + * {@code iceStream}, which falls in the range [{@code min}, {@code max}]. + */ + private int getMaxAllocatedPort(IceMediaStream iceStream, int min, int max) + { + return + Math.max( + getMaxAllocatedPort( + iceStream.getComponent(Component.RTP), + min, max), + getMaxAllocatedPort( + iceStream.getComponent(Component.RTCP), + min, max)); + } + + /** + * @return the highest local port used by any of the local candidates of + * {@code component}, which falls in the range [{@code min}, {@code max}]. + */ + private int getMaxAllocatedPort(Component component, int min, int max) + { + int maxAllocatedPort = -1; + + if (component != null) + { + for (LocalCandidate candidate : component.getLocalCandidates()) + { + int candidatePort = candidate.getTransportAddress().getPort(); + + if (min <= candidatePort + && candidatePort <= max + && maxAllocatedPort < candidatePort) + { + maxAllocatedPort = candidatePort; + } + } + } + + return maxAllocatedPort; + } + + /** * Simply returns the list of local candidates that we gathered during the * harvest. * @@ -898,8 +956,12 @@ public class IceUdpTransportManager = transport.getChildExtensionsOfType( CandidatePacketExtension.class); - if (iceAgentStateIsRunning && (candidates.size() == 0)) + if (iceAgentStateIsRunning && candidates.isEmpty()) + { + logger.info("connectivity establishment has not been started " + + "because candidate list is empty"); return false; + } String media = e.getKey(); IceMediaStream stream = iceAgent.getStream(media); diff --git a/src/net/java/sip/communicator/impl/protocol/sip/CallPeerMediaHandlerSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/CallPeerMediaHandlerSipImpl.java index c4193a5..24c5f6f 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/CallPeerMediaHandlerSipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/CallPeerMediaHandlerSipImpl.java @@ -87,7 +87,7 @@ public class CallPeerMediaHandlerSipImpl * Whether other party is able to change video quality settings. * Normally its whether we have detected existence of imageattr in sdp. */ - boolean supportQualityControls; + private boolean supportQualityControls; /** * The current quality controls for this peer media handler if any. @@ -98,7 +98,7 @@ public class CallPeerMediaHandlerSipImpl * The lock we use to make sure that we won't be processing a second * offer/answer exchange while a . */ - private Object offerAnswerLock = new Object(); + private final Object offerAnswerLock = new Object(); /** * Creates a new handler that will be managing media streams for @@ -164,7 +164,7 @@ public class CallPeerMediaHandlerSipImpl throws OperationFailedException { //Audio Media Description - Vector<MediaDescription> mediaDescs = createMediaDescriptions(); + List<MediaDescription> mediaDescs = createMediaDescriptions(); //wrap everything up in a session description String userName @@ -197,7 +197,7 @@ public class CallPeerMediaHandlerSipImpl * for reasons like - problems with device interaction, allocating ports, * etc. */ - private Vector<MediaDescription> createMediaDescriptions() + private List<MediaDescription> createMediaDescriptions() throws OperationFailedException { //Audio Media Description @@ -215,12 +215,16 @@ public class CallPeerMediaHandlerSipImpl receiveQualityPreset = qualityControls.getRemoteSendMaxPreset(); } - for (MediaType mediaType : MediaType.values()) + for (MediaType mediaType : new MediaType[] { MediaType.AUDIO , MediaType.VIDEO}) { MediaDevice dev = getDefaultDevice(mediaType); if (!isDeviceActive(dev, sendQualityPreset, receiveQualityPreset)) + { + logger.warn("No active device for " + mediaType.toString() + + " was found!"); continue; + } MediaDirection direction = dev.getDirection().and(getDirectionUserPreference(mediaType)); @@ -339,7 +343,7 @@ public class CallPeerMediaHandlerSipImpl * it is known that the other endpoint supports this * profile" and "[o]ther profiles MAY also be used." */ - updateMediaDescriptionForZrtp(mediaType, md, null); + updateMediaDescriptionForZrtp(mediaType, md); if (SrtpControl.RTP_SAVP.equals(proto) || SrtpControl.RTP_SAVPF.equals(proto)) { @@ -400,7 +404,7 @@ public class CallPeerMediaHandlerSipImpl { //create the media descriptions reflecting our current state. - Vector<MediaDescription> newMediaDescs = createMediaDescriptions(); + List<MediaDescription> newMediaDescs = createMediaDescriptions(); SessionDescription newOffer = SdpUtils.createSessionUpdateDescription( sdescToUpdate, getTransportManager().getLastUsedLocalHost(), @@ -510,7 +514,7 @@ public class CallPeerMediaHandlerSipImpl throws OperationFailedException, IllegalArgumentException { - Vector<MediaDescription> answerDescriptions + List<MediaDescription> answerDescriptions = createMediaDescriptionsForAnswer(newOffer); // wrap everything up in a session description SessionDescription newAnswer @@ -555,10 +559,11 @@ public class CallPeerMediaHandlerSipImpl boolean rejectedAvpOfferDueToSavpMandatory = false; AccountID accountID = getPeer().getProtocolProvider().getAccountID(); - int savpOption - = accountID.getAccountPropertyBoolean( - ProtocolProviderFactory.DEFAULT_ENCRYPTION, - true) + boolean useDefaultEncryption = + accountID.getAccountPropertyBoolean( + ProtocolProviderFactory.DEFAULT_ENCRYPTION , true); + + int savpOption = useDefaultEncryption ? accountID.getAccountPropertyInt( ProtocolProviderFactory.SAVP_OPTION, ProtocolProviderFactory.SAVP_OFF) @@ -638,7 +643,7 @@ public class CallPeerMediaHandlerSipImpl { mutuallySupportedFormats = null; } - else if(mediaType.equals(MediaType.VIDEO) + else if(MediaType.VIDEO.equals(mediaType) && (qualityControls != null)) { /* @@ -705,18 +710,18 @@ public class CallPeerMediaHandlerSipImpl = getTransportManager().getStreamConnector(mediaType); // check for options from remote party and set them locally - if(mediaType.equals(MediaType.VIDEO)) + if(MediaType.VIDEO.equals(mediaType)) { // update stream MediaStream stream = getStream(MediaType.VIDEO); - if(stream != null && dev != null) + if(stream != null) { List<MediaFormat> fmts = intersectFormats( getLocallySupportedFormats(dev), remoteFormats); - if(fmts.size() > 0) + if(!fmts.isEmpty()) { MediaFormat fmt = fmts.get(0); @@ -809,7 +814,7 @@ public class CallPeerMediaHandlerSipImpl { if(remoteDescriptions.size() > 1) { - if(mediaType.equals(MediaType.AUDIO)) + if(MediaType.AUDIO.equals(mediaType)) { masterStream = true; masterStreamSet = true; @@ -1192,8 +1197,7 @@ public class CallPeerMediaHandlerSipImpl */ private boolean updateMediaDescriptionForZrtp( MediaType mediaType, - MediaDescription localMd, - MediaDescription remoteMd) + MediaDescription localMd) { MediaAwareCallPeer<?, ?, ?> peer = getPeer(); AccountID accountID = peer.getProtocolProvider().getAccountID(); @@ -1499,7 +1503,7 @@ public class CallPeerMediaHandlerSipImpl // check for options from remote party and set // is quality controls supported - if(mediaType.equals(MediaType.VIDEO)) + if(MediaType.VIDEO.equals(mediaType)) { supportQualityControls = SdpUtils.containsAttribute(mediaDescription, "imageattr"); @@ -1544,7 +1548,7 @@ public class CallPeerMediaHandlerSipImpl { if(remoteDescriptions.size() > 1) { - if(mediaType.equals(MediaType.AUDIO)) + if(MediaType.AUDIO.equals(mediaType)) { masterStream = true; masterStreamSet = true; @@ -1882,7 +1886,7 @@ public class CallPeerMediaHandlerSipImpl // ZRTP else if(srtpControlType == SrtpControlType.ZRTP) { - if(updateMediaDescriptionForZrtp(mediaType, localMd, remoteMd)) + if(updateMediaDescriptionForZrtp(mediaType, localMd)); { // Stop once an encryption advertisement has been chosen. return; diff --git a/src/net/java/sip/communicator/impl/protocol/sip/CallSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/CallSipImpl.java index 0471d1a..bae70a2 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/CallSipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/CallSipImpl.java @@ -96,16 +96,9 @@ public class CallSipImpl public static final String EXTRA_HEADER_VALUE = "EXTRA_HEADER_VALUE"; /** - * When starting call we may have quality preferences we must use - * for the call. - */ - private QualityPreset initialQualityPreferences; - - /** - * A reference to the <tt>SipMessageFactory</tt> instance that we should - * use when creating requests. + * Maximum number of retransmissions that will be sent. */ - private final SipMessageFactory messageFactory; + private static final int MAX_RETRANSMISSIONS = 3; /** * The name of the property under which the user may specify the number of @@ -113,19 +106,27 @@ public class CallSipImpl * 180. */ private static final String RETRANSMITS_RINGING_INTERVAL - = "net.java.sip.communicator.impl.protocol.sip" - + ".RETRANSMITS_RINGING_INTERVAL"; + = "net.java.sip.communicator.impl.protocol.sip" + + ".RETRANSMITS_RINGING_INTERVAL"; /** - * The default amount of time (in milliseconds) for the initial interval for - * retransmissions of response 180. - */ + * The default amount of time (in milliseconds) for the initial interval for + * retransmissions of response 180. + */ private static final int DEFAULT_RETRANSMITS_RINGING_INTERVAL = 500; /** - * Maximum number of retransmissions that will be sent. + * When starting call we may have quality preferences we must use + * for the call. */ - private static final int MAX_RETRANSMISSIONS = 3; + private QualityPreset initialQualityPreferences; + + /** + * A reference to the <tt>SipMessageFactory</tt> instance that we should + * use when creating requests. + */ + private final SipMessageFactory messageFactory; + /** * The amount of time (in milliseconds) for the initial interval for @@ -405,24 +406,21 @@ public class CallSipImpl logger.trace("Looking for peer with dialog: " + dialog + "among " + getCallPeerCount() + " calls"); } - while (callPeers.hasNext()) + for (CallPeerSipImpl callPeer : getCallPeerList()) { - CallPeerSipImpl cp = callPeers.next(); - - if (cp.getDialog() == dialog) + if (callPeer.getDialog() == dialog) { if (logger.isTraceEnabled()) - logger.trace("Returning cp=" + cp); - return cp; + logger.trace("Returning cp=" + callPeer); + return callPeer; } else { if (logger.isTraceEnabled()) - logger.trace("Ignoring cp=" + cp + " because cp.dialog=" - + cp.getDialog() + " while dialog=" + dialog); + logger.trace("Ignoring cp=" + callPeer + " because cp.dialog=" + + callPeer.getDialog() + " while dialog=" + dialog); } } - return null; } @@ -467,7 +465,7 @@ public class CallSipImpl // Transport preference String forceTransport = null; javax.sip.address.URI calleeURI = calleeAddress.getURI(); - if(calleeURI.getScheme().toLowerCase().equals("sips")) + if("sips".equals(calleeURI.getScheme().toLowerCase())) { // MUST use TLS forceTransport = "TLS"; @@ -571,7 +569,7 @@ public class CallSipImpl String alternativeIMPPAddress = null; if (infoHeader != null && infoHeader.getParameter("purpose") != null - && infoHeader.getParameter("purpose").equals("impp")) + && "impp".equals(infoHeader.getParameter("purpose"))) { alternativeIMPPAddress = infoHeader.getInfo().toString(); } @@ -603,7 +601,7 @@ public class CallSipImpl { if (logger.isTraceEnabled()) logger.trace("will send ringing response: "); - if(peer.getState().equals(CallPeerState.INCOMING_CALL)) + if( CallPeerState.INCOMING_CALL.equals(peer.getState()) ) { response = messageFactory.createResponse(Response.RINGING, invite); @@ -698,10 +696,10 @@ public class CallSipImpl */ public void reInvite() throws OperationFailedException { - Iterator<CallPeerSipImpl> peers = getCallPeers(); - - while (peers.hasNext()) - peers.next().sendReInvite(); + for(CallPeerSipImpl peer : getCallPeerList()) + { + peer.sendReInvite(); + } } /** @@ -792,8 +790,8 @@ public class CallSipImpl { try { - if(!peer.getState().equals( - CallPeerState.INCOMING_CALL)) + if( !CallPeerState.INCOMING_CALL.equals( + peer.getState()) ) { timer.cancel(); } diff --git a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicTelephonySipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicTelephonySipImpl.java index 5ee32c9..fc99643 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicTelephonySipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicTelephonySipImpl.java @@ -434,7 +434,10 @@ public class OperationSetBasicTelephonySipImpl CSeqHeader cseq = ((CSeqHeader) response.getHeader(CSeqHeader.NAME)); if (cseq == null) + { logger.error("An incoming response did not contain a CSeq header"); + return false; + } String method = cseq.getMethod(); @@ -1163,11 +1166,7 @@ public class OperationSetBasicTelephonySipImpl protocolProvider.getAccountID().getService() , 399, reasonText); } - catch(InvalidArgumentException e) - { - logger.error("Cannot create warning header", e); - } - catch(ParseException e) + catch(InvalidArgumentException | ParseException e) { logger.error("Cannot create warning header", e); } @@ -1458,11 +1457,7 @@ public class OperationSetBasicTelephonySipImpl { serverTransaction.sendResponse(accepted); } - catch (InvalidArgumentException ex) - { - failure = ex; - } - catch (SipException ex) + catch (InvalidArgumentException | SipException ex) { failure = ex; } diff --git a/src/net/java/sip/communicator/impl/protocol/sip/sdp/SdpUtils.java b/src/net/java/sip/communicator/impl/protocol/sip/sdp/SdpUtils.java index 47c26a9..2339404 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/sdp/SdpUtils.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/sdp/SdpUtils.java @@ -568,7 +568,7 @@ public class SdpUtils public static SessionDescription createSessionDescription( InetAddress localAddress, String userName, - Vector<MediaDescription> mediaDescriptions) + List<MediaDescription> mediaDescriptions) throws OperationFailedException { SessionDescription sessDescr = null; @@ -614,8 +614,9 @@ public class SdpUtils sessDescr.setConnection(c); if ( mediaDescriptions != null) - sessDescr.setMediaDescriptions(mediaDescriptions); - + { + sessDescr.setMediaDescriptions( new Vector<>(mediaDescriptions)); + } return sessDescr; } catch (SdpException exc) @@ -656,7 +657,7 @@ public class SdpUtils public static SessionDescription createSessionUpdateDescription( SessionDescription descToUpdate, InetAddress newConnectionAddress, - Vector<MediaDescription> newMediaDescriptions) + List<MediaDescription> newMediaDescriptions) throws OperationFailedException { SessionDescription update = createSessionDescription( @@ -1712,7 +1713,7 @@ public class SdpUtils * <tt>descs</tt> <tt>Vector</tt>. */ private static MediaDescription removeMediaDesc( - Vector<MediaDescription> descs, + List<MediaDescription> descs, MediaType type) { for (Iterator<MediaDescription> i = descs.iterator(); i.hasNext();) diff --git a/src/net/java/sip/communicator/service/protocol/media/CallPeerMediaHandler.java b/src/net/java/sip/communicator/service/protocol/media/CallPeerMediaHandler.java index e8d168b..de2d03a 100644 --- a/src/net/java/sip/communicator/service/protocol/media/CallPeerMediaHandler.java +++ b/src/net/java/sip/communicator/service/protocol/media/CallPeerMediaHandler.java @@ -374,7 +374,7 @@ public abstract class CallPeerMediaHandler<T extends MediaAwareCallPeer<?,?,?>> if (call == null) return; - for (MediaType mediaType : MediaType.values()) + for (MediaType mediaType : new MediaType[] {MediaType.AUDIO, MediaType.VIDEO} ) { MediaStream stream = getStream(mediaType); @@ -689,7 +689,7 @@ public abstract class CallPeerMediaHandler<T extends MediaAwareCallPeer<?,?,?>> return (transportManager == null) - ? null + ? 0 : transportManager.getHarvestingTime(harvesterName); } @@ -942,7 +942,9 @@ public abstract class CallPeerMediaHandler<T extends MediaAwareCallPeer<?,?,?>> /** * Returns the number of harvesting for this agent. * - * @return The number of harvesting for this agent. + * @return The number of harvesting for this agent. 0 if this harvester + * does not exists, if the ICE agent is null, or + * if the agent has never harvested with this harvester. */ public int getNbHarvesting() { @@ -950,7 +952,7 @@ public abstract class CallPeerMediaHandler<T extends MediaAwareCallPeer<?,?,?>> return (transportManager == null) - ? null + ? 0 : transportManager.getNbHarvesting(); } @@ -961,7 +963,8 @@ public abstract class CallPeerMediaHandler<T extends MediaAwareCallPeer<?,?,?>> * @param harvesterName The class name if the harvester. * * @return The number of harvesting time for the harvester given in - * parameter. + * parameter. 0 if this harvester does not exists, if the ICE agent is null, or if the + * agent has never harvested with this harvester. */ public int getNbHarvesting(String harvesterName) { @@ -969,7 +972,7 @@ public abstract class CallPeerMediaHandler<T extends MediaAwareCallPeer<?,?,?>> return (transportManager == null) - ? null + ? 0 : transportManager.getNbHarvesting(harvesterName); } @@ -1054,7 +1057,7 @@ public abstract class CallPeerMediaHandler<T extends MediaAwareCallPeer<?,?,?>> * Returns the total harvesting time (in ms) for all harvesters. * * @return The total harvesting time (in ms) for all the harvesters. 0 if - * the ICE agent is null, or if the agent has nevers harvested. + * the ICE agent is null, or if the agent has never harvested. */ public long getTotalHarvestingTime() { @@ -1062,7 +1065,7 @@ public abstract class CallPeerMediaHandler<T extends MediaAwareCallPeer<?,?,?>> return (transportManager == null) - ? null + ? 0 : transportManager.getTotalHarvestingTime(); } diff --git a/src/net/java/sip/communicator/service/protocol/media/TransportManager.java b/src/net/java/sip/communicator/service/protocol/media/TransportManager.java index 7906199..a8222e0 100644 --- a/src/net/java/sip/communicator/service/protocol/media/TransportManager.java +++ b/src/net/java/sip/communicator/service/protocol/media/TransportManager.java @@ -107,6 +107,76 @@ public abstract class TransportManager<U extends MediaAwareCallPeer<?, ?, ?>> private static final int DEFAULT_HOLE_PUNCH_PKT_COUNT = 3; /** + * Returns the port tracker that we are supposed to use when binding ports + * for the specified {@link MediaType}. + * + * @param mediaType the media type that we want to obtain the port tracker + * for. Use <tt>null</tt> to obtain the default port tracker. + * + * @return the port tracker that we are supposed to use when binding ports + * for the specified {@link MediaType}. + */ + protected static PortTracker getPortTracker(MediaType mediaType) + { + //make sure our port numbers reflect the configuration service settings + initializePortNumbers(); + + if (mediaType != null) + { + switch (mediaType) + { + case AUDIO: + if (audioPortTracker != null) + return audioPortTracker; + else + break; + case VIDEO: + if (videoPortTracker != null) + return videoPortTracker; + else + break; + case DATA: + if (dataPortTracker != null) + return dataPortTracker; + else + break; + } + } + + return defaultPortTracker; + } + + /** + * Returns the port tracker that we are supposed to use when binding ports + * for the {@link MediaType} indicated by the string param. If we do not + * recognize the string as a valid media type, we simply return the default + * port tracker. + * + * @param mediaTypeStr the name of the media type that we want to obtain a + * port tracker for. + * + * @return the port tracker that we are supposed to use when binding ports + * for the {@link MediaType} with the specified name or the default tracker + * in case the name doesn't ring a bell. + */ + protected static PortTracker getPortTracker(String mediaTypeStr) + { + try + { + return getPortTracker(MediaType.parseString(mediaTypeStr)); + } + catch (Exception e) + { + logger.info( + "Returning default port tracker for unrecognized media type: " + + mediaTypeStr); + + return defaultPortTracker; + } + } + + + /** * The {@link MediaAwareCallPeer} whose traffic we will be taking care of. */ private U callPeer; @@ -461,7 +531,7 @@ public abstract class TransportManager<U extends MediaAwareCallPeer<?, ?, ?>> try { - StreamConnector connector = getStreamConnector(type); + final StreamConnector connector = getStreamConnector(type); if(connector.getProtocol() == StreamConnector.Protocol.TCP) return; @@ -530,7 +600,7 @@ public abstract class TransportManager<U extends MediaAwareCallPeer<?, ?, ?>> "Set traffic class for " + type + " to " + trafficClass); try { - StreamConnector connector = getStreamConnector(type); + final StreamConnector connector = getStreamConnector(type); synchronized(connector) { @@ -630,75 +700,6 @@ public abstract class TransportManager<U extends MediaAwareCallPeer<?, ?, ?>> } /** - * Returns the port tracker that we are supposed to use when binding ports - * for the specified {@link MediaType}. - * - * @param mediaType the media type that we want to obtain the port tracker - * for. Use <tt>null</tt> to obtain the default port tracker. - * - * @return the port tracker that we are supposed to use when binding ports - * for the specified {@link MediaType}. - */ - protected static PortTracker getPortTracker(MediaType mediaType) - { - //make sure our port numbers reflect the configuration service settings - initializePortNumbers(); - - if (mediaType != null) - { - switch (mediaType) - { - case AUDIO: - if (audioPortTracker != null) - return audioPortTracker; - else - break; - case VIDEO: - if (videoPortTracker != null) - return videoPortTracker; - else - break; - case DATA: - if (dataPortTracker != null) - return dataPortTracker; - else - break; - } - } - - return defaultPortTracker; - } - - /** - * Returns the port tracker that we are supposed to use when binding ports - * for the {@link MediaType} indicated by the string param. If we do not - * recognize the string as a valid media type, we simply return the default - * port tracker. - * - * @param mediaTypeStr the name of the media type that we want to obtain a - * port tracker for. - * - * @return the port tracker that we are supposed to use when binding ports - * for the {@link MediaType} with the specified name or the default tracker - * in case the name doesn't ring a bell. - */ - protected static PortTracker getPortTracker(String mediaTypeStr) - { - try - { - return getPortTracker(MediaType.parseString(mediaTypeStr)); - } - catch (Exception e) - { - logger.info( - "Returning default port tracker for unrecognized media type: " - + mediaTypeStr); - - return defaultPortTracker; - } - } - - /** * Returns the extended type of the candidate selected if this transport * manager is using ICE. * |