org.lastbamboo.common.ice
Class IceMediaStreamImpl

java.lang.Object
  extended by org.lastbamboo.common.ice.IceMediaStreamImpl
All Implemented Interfaces:
EventListener, IceMediaStream, org.littleshoot.mina.common.IoServiceListener

public class IceMediaStreamImpl
extends Object
implements IceMediaStream

Class containing an ICE media stream. Each media stream contains a single ICE check list, as described in ICE section 5.7.


Constructor Summary
IceMediaStreamImpl(IceAgent iceAgent, org.lastbamboo.common.offer.answer.IceMediaStreamDesc streamDesc, IceCandidateGatherer gatherer, IceStunUdpPeer udpPeer)
          Creates a new ICE media stream.
 
Method Summary
 void addLocalCandidate(IceCandidate localCandidate)
          Adds a local candidate.
 void addPair(IceCandidatePair pair)
          Adds the specified ICE candidate pair to the check list.
 IceCandidate addRemotePeerReflexive(org.littleshoot.stun.stack.message.BindingRequest request, InetSocketAddress localAddress, InetSocketAddress remoteAddress, boolean isUdp)
          Adds a peer reflexive candidate to the list of remote candidates.
 void addTriggeredPair(IceCandidatePair pair)
          Adds a pair to the triggered check queue.
 void addValidPair(IceCandidatePair pair)
          Adds a new valid pair.
 void close()
          Perform any necessary close operations for the media stream.
 byte[] encodeCandidates()
          Encodes this media stream in SDP.
 void establishStream(Collection<IceCandidate> remoteCandidates)
          Establishes a media stream using the answer data from the remote host.
 IceCheckListState getCheckListState()
          Gets the state of the check list.
 IceCandidate getLocalCandidate(InetSocketAddress localAddress, boolean isUdp)
          Accessor for the local candidate associate with the specified local address.
 Collection<IceCandidate> getLocalCandidates()
          Accessor for the local candidates for this stream.
 Queue<IceCandidatePair> getNominatedPairs()
          Accessor for all nominated pairs for this stream.
 IceCandidatePair getPair(InetSocketAddress localAddress, InetSocketAddress remoteAddress, boolean isUdp)
          Accesses the pair matching the specified local and remote addresses, if any.
 InetAddress getPublicAddress()
           
 IceCandidate getRemoteCandidate(InetSocketAddress remoteAddress, boolean isUdp)
          Accessor for the remote candidate associate with the specified remote address.
 IceStunUdpPeer getStunUdpPeer()
           
 Queue<IceCandidatePair> getValidPairs()
          Accessor for all valid pairs for this stream.
 boolean hasHigherPriorityPendingPair(IceCandidatePair pair)
          Checks whether or not there are existing pairs on either the triggered check list or the normal check list.
 boolean hasRemoteCandidate(InetSocketAddress remoteAddress, boolean isUdp)
          Checks whether or not the specified remote address matches any of the addresses of remote candidates.
 boolean hasRemoteCandidateInSdp(InetSocketAddress remoteAddress, boolean isUdp)
          Checks whether or not the specified remote address matches any of the addresses of remote candidates.
 void onNominated(IceCandidatePair pair)
          Notifies the media stream that there's been a nominated pair.
 void recomputePairPriorities(boolean controlling)
          Recomputes the priorities of pairs in checklists.
 void serviceActivated(org.littleshoot.mina.common.IoService service, SocketAddress serviceAddress, org.littleshoot.mina.common.IoHandler handler, org.littleshoot.mina.common.IoServiceConfig config)
           
 void serviceDeactivated(org.littleshoot.mina.common.IoService service, SocketAddress serviceAddress, org.littleshoot.mina.common.IoHandler handler, org.littleshoot.mina.common.IoServiceConfig config)
           
 void sessionCreated(org.littleshoot.mina.common.IoSession session)
           
 void sessionDestroyed(org.littleshoot.mina.common.IoSession session)
           
 void setCheckListState(IceCheckListState state)
          Sets the state of the check list.
 void start(IceCheckList checkList, Collection<IceCandidate> localCandidates, IceCheckScheduler scheduler)
          Starts gathering candidates and executing ICE.
 String toString()
           
 void updateCheckListAndTimerStates()
          Implements ICE section 7.1.2.3.
 void updatePairStates(IceCandidatePair generatingPair)
          Called when connectivity checks have created a new valid pair and the media stream needs to update the states of other pairs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IceMediaStreamImpl

public IceMediaStreamImpl(IceAgent iceAgent,
                          org.lastbamboo.common.offer.answer.IceMediaStreamDesc streamDesc,
                          IceCandidateGatherer gatherer,
                          IceStunUdpPeer udpPeer)
Creates a new ICE media stream.

Parameters:
iceAgent - The ICE agent.
streamDesc - The description of the stream to create.
gatherer - The class that will gather ICE candidates for the stream.
Method Detail

start

public void start(IceCheckList checkList,
                  Collection<IceCandidate> localCandidates,
                  IceCheckScheduler scheduler)
Description copied from interface: IceMediaStream
Starts gathering candidates and executing ICE.

Specified by:
start in interface IceMediaStream
Parameters:
checkList - The candidate pair check list.
localCandidates - The local candidates.
scheduler - The check scheduler.

encodeCandidates

public byte[] encodeCandidates()
Description copied from interface: IceMediaStream
Encodes this media stream in SDP.

Specified by:
encodeCandidates in interface IceMediaStream
Returns:
The media stream encoded in SDP.

establishStream

public void establishStream(Collection<IceCandidate> remoteCandidates)
Description copied from interface: IceMediaStream
Establishes a media stream using the answer data from the remote host.

Specified by:
establishStream in interface IceMediaStream
Parameters:
remoteCandidates - The answer from the remote host.

addRemotePeerReflexive

public IceCandidate addRemotePeerReflexive(org.littleshoot.stun.stack.message.BindingRequest request,
                                           InetSocketAddress localAddress,
                                           InetSocketAddress remoteAddress,
                                           boolean isUdp)
Description copied from interface: IceMediaStream
Adds a peer reflexive candidate to the list of remote candidates.

Specified by:
addRemotePeerReflexive in interface IceMediaStream
Parameters:
request - The BindingRequest that initiated the establishment of a new peer reflexive candidate.
localAddress - The local address the request was sent to. This allows us to match the local address with the local candidate it was sent to. We use that to determine the component ID of the new peer reflexive candidate.
remoteAddress - The remote address of the peer that sent the Binding Request.
isUdp - Whether the candidate should be a UDP candidate or not.
Returns:
The new peer reflexive remote candidate.

getValidPairs

public Queue<IceCandidatePair> getValidPairs()
Description copied from interface: IceMediaStream
Accessor for all valid pairs for this stream.

Specified by:
getValidPairs in interface IceMediaStream
Returns:
The Queue of all valid pairs for this stream.

addLocalCandidate

public void addLocalCandidate(IceCandidate localCandidate)
Description copied from interface: IceMediaStream
Adds a local candidate.

Specified by:
addLocalCandidate in interface IceMediaStream
Parameters:
localCandidate - The local candidate to add.

getLocalCandidate

public IceCandidate getLocalCandidate(InetSocketAddress localAddress,
                                      boolean isUdp)
Description copied from interface: IceMediaStream
Accessor for the local candidate associate with the specified local address.

Specified by:
getLocalCandidate in interface IceMediaStream
Parameters:
localAddress - The local address to look for.
Returns:
The candidate associated with the specified local address, or null if there's no associated candidate.

getRemoteCandidate

public IceCandidate getRemoteCandidate(InetSocketAddress remoteAddress,
                                       boolean isUdp)
Description copied from interface: IceMediaStream
Accessor for the remote candidate associate with the specified remote address.

Specified by:
getRemoteCandidate in interface IceMediaStream
Parameters:
remoteAddress - The remote address to look for.
isUdp - Whether to search for UDP candidates.
Returns:
The candidate associated with the specified remote address, or null if there's no associated candidate.

hasRemoteCandidate

public boolean hasRemoteCandidate(InetSocketAddress remoteAddress,
                                  boolean isUdp)
Description copied from interface: IceMediaStream
Checks whether or not the specified remote address matches any of the addresses of remote candidates. This is typically used when checking for peer reflexive candidates. If it's an address we don't know about, it's typically a new peer reflexive candidate.

Specified by:
hasRemoteCandidate in interface IceMediaStream
Parameters:
remoteAddress - The remote address to check.
isUdp - Whether or not the candidate is UDP.
Returns:
true if the address matches the address of a remote candidate we already know about, otherwise false.

hasRemoteCandidateInSdp

public boolean hasRemoteCandidateInSdp(InetSocketAddress remoteAddress,
                                       boolean isUdp)
Description copied from interface: IceMediaStream
Checks whether or not the specified remote address matches any of the addresses of remote candidates. This is typically used when checking for peer reflexive candidates. If it's an address we don't know about, it's typically a new peer reflexive candidate.

Specified by:
hasRemoteCandidateInSdp in interface IceMediaStream
Parameters:
remoteAddress - The remote address to check.
isUdp - Whether or not the candidate is UDP.
Returns:
true if the address matches the address of a remote candidate we already know about, otherwise false.

getPair

public IceCandidatePair getPair(InetSocketAddress localAddress,
                                InetSocketAddress remoteAddress,
                                boolean isUdp)
Description copied from interface: IceMediaStream
Accesses the pair matching the specified local and remote addresses, if any.

Specified by:
getPair in interface IceMediaStream
Parameters:
localAddress - The address for the local candidate.
remoteAddress - The address for the remote candidate.
isUdp - Whether or not the pair is UDP.
Returns:
The pair matching both addresses, or null if no such pair exists.

updatePairStates

public void updatePairStates(IceCandidatePair generatingPair)
Description copied from interface: IceMediaStream
Called when connectivity checks have created a new valid pair and the media stream needs to update the states of other pairs.

Specified by:
updatePairStates in interface IceMediaStream
Parameters:
generatingPair - The pair that generated the valid pair.

updateCheckListAndTimerStates

public void updateCheckListAndTimerStates()
Description copied from interface: IceMediaStream
Implements ICE section 7.1.2.3. Check List and Timer State Updates.

Specified by:
updateCheckListAndTimerStates in interface IceMediaStream

addValidPair

public void addValidPair(IceCandidatePair pair)
Description copied from interface: IceMediaStream
Adds a new valid pair.

Specified by:
addValidPair in interface IceMediaStream
Parameters:
pair - The pair to add.

recomputePairPriorities

public void recomputePairPriorities(boolean controlling)
Description copied from interface: IceMediaStream
Recomputes the priorities of pairs in checklists. This can happen, for example, if our role has changed from controlling to controlled or vice versa.

Specified by:
recomputePairPriorities in interface IceMediaStream
Parameters:
controlling - The current controlling status of the agent.

addTriggeredPair

public void addTriggeredPair(IceCandidatePair pair)
Description copied from interface: IceMediaStream
Adds a pair to the triggered check queue.

Specified by:
addTriggeredPair in interface IceMediaStream
Parameters:
pair - The pair to add.

addPair

public void addPair(IceCandidatePair pair)
Description copied from interface: IceMediaStream
Adds the specified ICE candidate pair to the check list.

Specified by:
addPair in interface IceMediaStream
Parameters:
pair - The pair to add.

getCheckListState

public IceCheckListState getCheckListState()
Description copied from interface: IceMediaStream
Gets the state of the check list.

Specified by:
getCheckListState in interface IceMediaStream
Returns:
The state of the check list.

setCheckListState

public void setCheckListState(IceCheckListState state)
Description copied from interface: IceMediaStream
Sets the state of the check list.

Specified by:
setCheckListState in interface IceMediaStream
Parameters:
state - The state of the check list.

hasHigherPriorityPendingPair

public boolean hasHigherPriorityPendingPair(IceCandidatePair pair)
Description copied from interface: IceMediaStream
Checks whether or not there are existing pairs on either the triggered check list or the normal check list. For the normal check list, the pair must be in the FROZEN, WAITING, or IN PROGRESS states.

Specified by:
hasHigherPriorityPendingPair in interface IceMediaStream
Parameters:
pair - The pair to check.
Returns:
true if there's a higher priority pair that could still complete its check, otherwise false.

onNominated

public void onNominated(IceCandidatePair pair)
Description copied from interface: IceMediaStream
Notifies the media stream that there's been a nominated pair. The media stream follows the process in section 8.1.2, removing all Waiting and Frozen pairs in the check list and the triggered check queue and ceasing retransmissions for pairs that are In-Progress if their priorities are lower than the nominated pair.

Specified by:
onNominated in interface IceMediaStream
Parameters:
pair - The nominated pair.

getNominatedPairs

public Queue<IceCandidatePair> getNominatedPairs()
Description copied from interface: IceMediaStream
Accessor for all nominated pairs for this stream.

Specified by:
getNominatedPairs in interface IceMediaStream
Returns:
The Queue of all nominated pairs for this stream.

serviceActivated

public void serviceActivated(org.littleshoot.mina.common.IoService service,
                             SocketAddress serviceAddress,
                             org.littleshoot.mina.common.IoHandler handler,
                             org.littleshoot.mina.common.IoServiceConfig config)
Specified by:
serviceActivated in interface org.littleshoot.mina.common.IoServiceListener

serviceDeactivated

public void serviceDeactivated(org.littleshoot.mina.common.IoService service,
                               SocketAddress serviceAddress,
                               org.littleshoot.mina.common.IoHandler handler,
                               org.littleshoot.mina.common.IoServiceConfig config)
Specified by:
serviceDeactivated in interface org.littleshoot.mina.common.IoServiceListener

sessionCreated

public void sessionCreated(org.littleshoot.mina.common.IoSession session)
Specified by:
sessionCreated in interface org.littleshoot.mina.common.IoServiceListener

sessionDestroyed

public void sessionDestroyed(org.littleshoot.mina.common.IoSession session)
Specified by:
sessionDestroyed in interface org.littleshoot.mina.common.IoServiceListener

close

public void close()
Description copied from interface: IceMediaStream
Perform any necessary close operations for the media stream.

Specified by:
close in interface IceMediaStream

getLocalCandidates

public Collection<IceCandidate> getLocalCandidates()
Description copied from interface: IceMediaStream
Accessor for the local candidates for this stream.

Specified by:
getLocalCandidates in interface IceMediaStream
Returns:
The local candidates for this stream.

getPublicAddress

public InetAddress getPublicAddress()
Specified by:
getPublicAddress in interface IceMediaStream

toString

public String toString()
Overrides:
toString in class Object

getStunUdpPeer

public IceStunUdpPeer getStunUdpPeer()
Specified by:
getStunUdpPeer in interface IceMediaStream


Copyright © 2013 LittleShoot. All Rights Reserved.