Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.neomedia
Class RTPConnectorOutputStream

java.lang.Object
  extended by net.java.sip.communicator.impl.neomedia.RTPConnectorOutputStream
All Implemented Interfaces:
javax.media.rtp.OutputDataStream
Direct Known Subclasses:
RTPConnectorTCPOutputStream, RTPConnectorUDPOutputStream

public abstract class RTPConnectorOutputStream
extends Object
implements javax.media.rtp.OutputDataStream

Author:
Bing SU (nova.su@gmail.com), Lyubomir Marinov

Field Summary
static int MAX_PACKETS_PER_MILLIS_POLICY_PACKET_QUEUE_CAPACITY
          The maximum number of packets to be sent to be kept in the queue of MaxPacketsPerMillisPolicy.
protected  List<InetSocketAddress> targets
          Stream targets' IP addresses and ports.
 
Constructor Summary
RTPConnectorOutputStream()
          Initializes a new RTPConnectorOutputStream which is to send packet data out through a specific socket.
 
Method Summary
 void addTarget(InetAddress remoteAddr, int remotePort)
          Add a target to stream targets list
 void close()
          Close this output stream.
protected  RawPacket createRawPacket(byte[] buffer, int offset, int length)
          Creates a new RawPacket from a specific byte[] buffer in order to have this instance send its packet data through its write(byte[], int, int) method.
protected abstract  void doLogPacket(RawPacket packet, InetSocketAddress target)
          Logs a specific RawPacket associated with a specific remote address.
protected abstract  boolean isSocketValid()
          Returns whether or not this RTPConnectorOutputStream has a valid socket.
(package private) static boolean logPacket(long numOfPacket)
          Determines whether a RawPacket which has a specific number in the total number of sent RawPackets is to be logged by PacketLoggingService.
 boolean removeTarget(InetAddress remoteAddr, int remotePort)
          Remove a target from stream targets list
 void removeTargets()
          Remove all stream targets from this session.
protected abstract  void sendToTarget(RawPacket packet, InetSocketAddress target)
          Sends a specific RawPacket through this OutputDataStream to a specific InetSocketAddress.
 void setMaxPacketsPerMillis(int maxPackets, long perMillis)
          Sets the maximum number of RTP packets to be sent by this OutputDataStream through its DatagramSocket per a specific number of milliseconds.
 void setPriority(int priority)
          Changes current thread priority.
 int write(byte[] buffer, int offset, int length)
          Implements OutputDataStream.write(byte[], int, int).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_PACKETS_PER_MILLIS_POLICY_PACKET_QUEUE_CAPACITY

public static final int MAX_PACKETS_PER_MILLIS_POLICY_PACKET_QUEUE_CAPACITY
The maximum number of packets to be sent to be kept in the queue of MaxPacketsPerMillisPolicy. When the maximum is reached, the next attempt to write a new packet in the queue will block until at least one packet from the queue is sent. Defined in order to prevent OutOfMemoryErrors which, technically, may arise if the capacity of the queue is unlimited.

See Also:
Constant Field Values

targets

protected final List<InetSocketAddress> targets
Stream targets' IP addresses and ports.

Constructor Detail

RTPConnectorOutputStream

public RTPConnectorOutputStream()
Initializes a new RTPConnectorOutputStream which is to send packet data out through a specific socket.

Method Detail

addTarget

public void addTarget(InetAddress remoteAddr,
                      int remotePort)
Add a target to stream targets list

Parameters:
remoteAddr - target ip address
remotePort - target port

close

public void close()
Close this output stream.


createRawPacket

protected RawPacket createRawPacket(byte[] buffer,
                                    int offset,
                                    int length)
Creates a new RawPacket from a specific byte[] buffer in order to have this instance send its packet data through its write(byte[], int, int) method. Allows extenders to intercept the packet data and possibly filter and/or modify it.

Parameters:
buffer - the packet data to be sent to the targets of this instance
offset - the offset of the packet data in buffer
length - the length of the packet data in buffer
Returns:
a new RawPacket containing the packet data of the specified byte[] buffer or possibly its modification; null to ignore the packet data of the specified byte[] buffer and not send it to the targets of this instance through its write(byte[], int, int) method

removeTarget

public boolean removeTarget(InetAddress remoteAddr,
                            int remotePort)
Remove a target from stream targets list

Parameters:
remoteAddr - target ip address
remotePort - target port
Returns:
true if the target is in stream target list and can be removed; false, otherwise

removeTargets

public void removeTargets()
Remove all stream targets from this session.


logPacket

static boolean logPacket(long numOfPacket)
Determines whether a RawPacket which has a specific number in the total number of sent RawPackets is to be logged by PacketLoggingService.

Parameters:
numOfPacket - the number of the RawPacket in the total number of sent RawPackets
Returns:
true if the RawPacket with the specified numOfPacket is to be logged by PacketLoggingService; otherwise, false

sendToTarget

protected abstract void sendToTarget(RawPacket packet,
                                     InetSocketAddress target)
                              throws IOException
Sends a specific RawPacket through this OutputDataStream to a specific InetSocketAddress.

Parameters:
packet - the RawPacket to send through this OutputDataStream to the specified target
target - the InetSocketAddress to which the specified packet is to be sent through this OutputDataStream
Throws:
IOException - if anything goes wrong while sending the specified packet through this OutputDataStream to the specified target

doLogPacket

protected abstract void doLogPacket(RawPacket packet,
                                    InetSocketAddress target)
Logs a specific RawPacket associated with a specific remote address.

Parameters:
packet - packet to log
target - the remote address associated with the packet

isSocketValid

protected abstract boolean isSocketValid()
Returns whether or not this RTPConnectorOutputStream has a valid socket.

Returns:
true if this RTPConnectorOutputStream has a valid socket; false, otherwise

setMaxPacketsPerMillis

public void setMaxPacketsPerMillis(int maxPackets,
                                   long perMillis)
Sets the maximum number of RTP packets to be sent by this OutputDataStream through its DatagramSocket per a specific number of milliseconds.

Parameters:
maxPackets - the maximum number of RTP packets to be sent by this OutputDataStream through its DatagramSocket per the specified number of milliseconds; -1 if no maximum is to be set
perMillis - the number of milliseconds per which maxPackets are to be sent by this OutputDataStream through its DatagramSocket

write

public int write(byte[] buffer,
                 int offset,
                 int length)
Implements OutputDataStream.write(byte[], int, int).

Specified by:
write in interface javax.media.rtp.OutputDataStream
Parameters:
buffer - the byte[] that we'd like to copy the content of the packet to.
offset - the position where we are supposed to start writing in buffer.
length - the number of bytes available for writing in inBuffer.
Returns:
the number of bytes read

setPriority

public void setPriority(int priority)
Changes current thread priority.

Parameters:
priority - the new priority.

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.