org.mobicents.media.server.impl.rtp
Class RtpSocketImpl

java.lang.Object
  extended by org.mobicents.media.server.impl.rtp.RtpSocketImpl
All Implemented Interfaces:
org.mobicents.media.server.spi.rtp.RtpSocket

public class RtpSocketImpl
extends java.lang.Object
implements org.mobicents.media.server.spi.rtp.RtpSocket

Author:
Oleg Kulikov

Field Summary
protected  java.util.Collection<org.mobicents.media.server.spi.dsp.Codec> codecs
           
protected  org.mobicents.media.server.spi.MediaType media
          Media type
protected  boolean registered
           
protected  java.net.InetSocketAddress remoteAddress
           
 
Constructor Summary
RtpSocketImpl(RtpFactory factory, java.util.Collection<org.mobicents.media.server.spi.dsp.Codec> codecs, org.mobicents.media.server.spi.MediaType media)
          Creates a new instance of RtpSocket
 
Method Summary
 void bind()
          Binds Datagram to the address sprecified.
protected  void close()
           
 org.mobicents.media.server.spi.rtp.AVProfile getAVProfile()
          Gets currently used audio/video profile
 long getBytesReceived()
          Statistical method.
 long getBytesSent()
          Statistical method.
 RtpClock getClock()
          Gets current RTP clock instance.
 java.util.Collection<org.mobicents.media.server.spi.dsp.Codec> getCodecs()
          Gets the list of used codecs.
 org.mobicents.media.Format getFormat()
          Gets the currently used format.
 int getJitter()
          Gets the jitter for time of packet arrival
 RtpSocketListener getListener()
          Gets the currently assigned listener.
 java.lang.String getLocalAddress()
          Gets address to which this socked is bound.
 int getLocalPort()
          Returns port number to which this socked is bound.
 int getPacketsReceived()
          Gets the number of received packets
 int getPacketsSent()
          Gets the number of sent packets
 ReceiveStream getReceiveStream()
          Gets receiver stream.
 SendStream getSendStream()
          (Non Java-doc).
 boolean isClosed()
           
protected  void notify(java.lang.Exception e)
          Notifies the listener that something goes wrong.
 void receive(RtpPacket rtpPacket)
          This method is called when rtp socket receives new rtp frame.
protected  void register(java.nio.channels.Selector selector)
          Registers this socket usign specified selector.
 void release()
          Closes this socket and resets its streams; This method is called by RtpSocket user.
 void send(byte[] packet)
          Sends rtp packet to the remote peer.
 void send(RtpPacket packet)
          Sends media data to remote peer.
 void setClock(RtpClock clock)
          Assign RTP clock implementation.
 void setDtmfPayload(int dtmf)
          Assigns RFC2833 DTMF playload number.
 void setFormat(int payloadId, org.mobicents.media.Format format)
          Specifies format and payload id which will be used by this socket for transmission This methods should be used by other components which are responsible for SDP negotiation.
 void setJitter(int jitter)
          Assign new value of packet time arrival jitter.
 void setListener(RtpSocketListener listener)
          Assigns listener which will receive notifications.
 void setPeer(java.net.InetAddress address, int port)
          Assigns remote end.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

media

protected org.mobicents.media.server.spi.MediaType media
Media type


remoteAddress

protected java.net.InetSocketAddress remoteAddress

codecs

protected java.util.Collection<org.mobicents.media.server.spi.dsp.Codec> codecs

registered

protected boolean registered
Constructor Detail

RtpSocketImpl

public RtpSocketImpl(RtpFactory factory,
                     java.util.Collection<org.mobicents.media.server.spi.dsp.Codec> codecs,
                     org.mobicents.media.server.spi.MediaType media)
              throws java.io.IOException,
                     org.mobicents.media.server.spi.ResourceUnavailableException
Creates a new instance of RtpSocket

Parameters:
timer - used to synchronize receiver stream.
rtpMap - RTP payloads list.
Throws:
java.io.IOException
org.mobicents.media.server.spi.ResourceUnavailableException
Method Detail

bind

public void bind()
          throws java.io.IOException,
                 org.mobicents.media.server.spi.ResourceUnavailableException
Binds Datagram to the address sprecified.

Specified by:
bind in interface org.mobicents.media.server.spi.rtp.RtpSocket
Throws:
java.io.IOException
org.mobicents.media.server.spi.ResourceUnavailableException

register

protected void register(java.nio.channels.Selector selector)
                 throws java.nio.channels.ClosedChannelException
Registers this socket usign specified selector.

Parameters:
selector - the selector for registration.
Throws:
java.nio.channels.ClosedChannelException

getFormat

public org.mobicents.media.Format getFormat()
Gets the currently used format.

Returns:
the format instance.

getCodecs

public java.util.Collection<org.mobicents.media.server.spi.dsp.Codec> getCodecs()
Gets the list of used codecs.

Specified by:
getCodecs in interface org.mobicents.media.server.spi.rtp.RtpSocket
Returns:
list of codecs.

setFormat

public void setFormat(int payloadId,
                      org.mobicents.media.Format format)
Specifies format and payload id which will be used by this socket for transmission This methods should be used by other components which are responsible for SDP negotiation. The socket itself can not negotiate SDP.

Specified by:
setFormat in interface org.mobicents.media.server.spi.rtp.RtpSocket
Parameters:
payloadId - rtp payload number
format - the format object.

setDtmfPayload

public void setDtmfPayload(int dtmf)
Assigns RFC2833 DTMF playload number.

Specified by:
setDtmfPayload in interface org.mobicents.media.server.spi.rtp.RtpSocket
Parameters:
dtmf - the DTMF payload number.

getLocalAddress

public java.lang.String getLocalAddress()
Gets address to which this socked is bound.

Specified by:
getLocalAddress in interface org.mobicents.media.server.spi.rtp.RtpSocket
Returns:
either local address to which this socket is bound or public address in case of NAT translation.

getLocalPort

public int getLocalPort()
Returns port number to which this socked is bound.

Specified by:
getLocalPort in interface org.mobicents.media.server.spi.rtp.RtpSocket
Returns:
port number or -1 if socket not bound.

getJitter

public int getJitter()
Gets the jitter for time of packet arrival

Specified by:
getJitter in interface org.mobicents.media.server.spi.rtp.RtpSocket
Returns:
the value of jitter in milliseconds.

setJitter

public void setJitter(int jitter)
Assign new value of packet time arrival jitter.

Specified by:
setJitter in interface org.mobicents.media.server.spi.rtp.RtpSocket
Parameters:
jitter - the value of jitter in milliseconds.

setClock

public void setClock(RtpClock clock)
Assign RTP clock implementation.

Parameters:
clock - the RTP clock instance;

getClock

public RtpClock getClock()
Gets current RTP clock instance.

Returns:
the RTP clock instance.

getReceiveStream

public ReceiveStream getReceiveStream()
Gets receiver stream.

Specified by:
getReceiveStream in interface org.mobicents.media.server.spi.rtp.RtpSocket
Returns:
receiver stream instance.

getAVProfile

public org.mobicents.media.server.spi.rtp.AVProfile getAVProfile()
Gets currently used audio/video profile

Specified by:
getAVProfile in interface org.mobicents.media.server.spi.rtp.RtpSocket
Returns:

getPacketsReceived

public int getPacketsReceived()
Gets the number of received packets

Specified by:
getPacketsReceived in interface org.mobicents.media.server.spi.rtp.RtpSocket
Returns:
the number of packets received

getPacketsSent

public int getPacketsSent()
Gets the number of sent packets

Specified by:
getPacketsSent in interface org.mobicents.media.server.spi.rtp.RtpSocket
Returns:
the number of sent packets.

release

public void release()
Closes this socket and resets its streams; This method is called by RtpSocket user.

Specified by:
release in interface org.mobicents.media.server.spi.rtp.RtpSocket

close

protected void close()

isClosed

public boolean isClosed()

getListener

public RtpSocketListener getListener()
Gets the currently assigned listener.

Returns:
the listener instance.

setListener

public void setListener(RtpSocketListener listener)
Assigns listener which will receive notifications.

Parameters:
listener - the listener instance.

setPeer

public void setPeer(java.net.InetAddress address,
                    int port)
             throws java.io.IOException
Assigns remote end.

Specified by:
setPeer in interface org.mobicents.media.server.spi.rtp.RtpSocket
Parameters:
address - the address of the remote party.
port - the port number of the remote party.
Throws:
java.io.IOException

getSendStream

public SendStream getSendStream()
(Non Java-doc).

Specified by:
getSendStream in interface org.mobicents.media.server.spi.rtp.RtpSocket
See Also:
org.mobicents.media.server.impl.rtp.RtpSocket#startSendStream(PushBufferDataSource);

send

public void send(RtpPacket packet)
          throws java.io.IOException
Sends media data to remote peer. This method uses blocking sending to make sure that data is out in time.

Parameters:
RtpPacket - - the packet which contains media data and rtp header
Throws:
java.io.IOException

send

public void send(byte[] packet)
          throws java.io.IOException
Sends rtp packet to the remote peer.

Parameters:
packet - the rtp packet as binary arrary
Throws:
java.io.IOException

receive

public void receive(RtpPacket rtpPacket)
This method is called when rtp socket receives new rtp frame.

Parameters:
rtpPacket -

notify

protected void notify(java.lang.Exception e)
Notifies the listener that something goes wrong.

Parameters:
e - the exception.

getBytesReceived

public long getBytesReceived()
Statistical method.

Specified by:
getBytesReceived in interface org.mobicents.media.server.spi.rtp.RtpSocket
Returns:
the number of bytes received.

getBytesSent

public long getBytesSent()
Statistical method.

Specified by:
getBytesSent in interface org.mobicents.media.server.spi.rtp.RtpSocket
Returns:
the number of bytes sent.


Copyright © 2010. All Rights Reserved.