Package org.jitsi.impl.neomedia
Class RTPConnectorOutputStream
- java.lang.Object
-
- org.jitsi.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, Boris Grozev
-
-
Field Summary
Fields Modifier and Type Field Description static intPACKET_QUEUE_CAPACITYThe maximum number of packets to be sent to be kept in the queue ofRTPConnectorOutputStream.static intPOOL_CAPACITYThe maximum size of the queues used as pools for unused objects.protected List<InetSocketAddress>targetsStream targets' IP addresses and ports.
-
Constructor Summary
Constructors Modifier Constructor Description protectedRTPConnectorOutputStream()Initializes a new RTPConnectorOutputStream which is to send packet data out through a specific socket.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddTarget(InetAddress remoteAddr, int remotePort)Add a target to stream targets listvoidclose()Close this output stream.protected abstract voiddoLogPacket(RawPacket packet, InetSocketAddress target)Logs a specific RawPacket associated with a specific remote address.longgetNumberOfBytesSent()Returns the number of bytes sent trough this streamlonggetOutputBitrate()longgetOutputBitrate(long now)protected PacketLoggingServicegetPacketLoggingService()Gets thePacketLoggingService(to be) utilized by this instance.protected abstract booleanisSocketValid()Returns whether or not this RTPConnectorOutputStream has a valid socket.static booleanlogDroppedPacket(int numDroppedPackets)Returns true if a warning should be logged after a queue has droppednumDroppedPacketspackets.protected RawPacket[]packetize(byte[] buf, int off, int len, Object context)Creates a RawPacket element from a specific byte[] buffer in order to have this instance send its packet data through itswrite(byte[], int, int)method.booleanremoveTarget(InetAddress remoteAddr, int remotePort)Remove a target from stream targets listvoidremoveTargets()Remove all stream targets from this session.protected abstract voidsendToTarget(RawPacket packet, InetSocketAddress target)Sends a specific RawPacket through this OutputDataStream to a specific InetSocketAddress.voidsetEnabled(boolean enabled)Enables or disables this RTPConnectorOutputStream.booleansetMaxPacketsPerMillis(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.voidsetPriority(int priority)Changes current thread priority.intsyncWrite(byte[] buf, int off, int len)Writes a byte[] to thisRTPConnectorOutputStreamsynchronously ( even whenUSE_SEND_THREADis enabled).intwrite(byte[] buf, int off, int len)ImplementsOutputDataStream.write(byte[], int, int).protected intwrite(byte[] buf, int off, int len, Object context)ImplementsOutputDataStream.write(byte[], int, int).
-
-
-
Field Detail
-
PACKET_QUEUE_CAPACITY
public static final int PACKET_QUEUE_CAPACITY
The maximum number of packets to be sent to be kept in the queue ofRTPConnectorOutputStream. When the maximum is reached, the next attempt to write a new packet in the queue will result in the first packet in the queue being dropped. Defined in order to prevent OutOfMemoryErrors which may arise if the capacity of the queue is unlimited.
-
POOL_CAPACITY
public static final int POOL_CAPACITY
The maximum size of the queues used as pools for unused objects.
-
targets
protected final List<InetSocketAddress> targets
Stream targets' IP addresses and ports.
-
-
Method Detail
-
logDroppedPacket
public static boolean logDroppedPacket(int numDroppedPackets)
Returns true if a warning should be logged after a queue has droppednumDroppedPacketspackets.- Parameters:
numDroppedPackets- the number of dropped packets.- Returns:
trueif a warning should be logged.
-
addTarget
public void addTarget(InetAddress remoteAddr, int remotePort)
Add a target to stream targets list- Parameters:
remoteAddr- target ip addressremotePort- target port
-
close
public void close()
Close this output stream.
-
packetize
protected RawPacket[] packetize(byte[] buf, int off, int len, Object context)
Creates a RawPacket element from a specific byte[] buffer in order to have this instance send its packet data through itswrite(byte[], int, int)method. Returns an array of one or more elements, with the created RawPacket as its first element (and null for all other elements) Allows extenders to intercept the array and possibly filter and/or modify it.- Parameters:
buf- the packet data to be sent to the targets of this instance. The contents ofbufstarting atoffwith the specifiedlenis copied into the buffer of the returnedRawPacket.off- the offset of the packet data in buflen- the length of the packet data in bufcontext- theObjectprovided towrite(byte[], int, int, java.lang.Object). The implementation ofRTPConnectorOutputStreamignores thecontext.- Returns:
- an array with a single RawPacket containing the packet data of the specified byte[] buffer.
-
doLogPacket
protected abstract void doLogPacket(RawPacket packet, InetSocketAddress target)
Logs a specific RawPacket associated with a specific remote address.- Parameters:
packet- packet to logtarget- the remote address associated with the packet
-
getNumberOfBytesSent
public long getNumberOfBytesSent()
Returns the number of bytes sent trough this stream- Returns:
- the number of bytes sent
-
getPacketLoggingService
protected PacketLoggingService getPacketLoggingService()
Gets thePacketLoggingService(to be) utilized by this instance.- Returns:
- the
PacketLoggingService(to be) utilized by this instance
-
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
-
removeTarget
public boolean removeTarget(InetAddress remoteAddr, int remotePort)
Remove a target from stream targets list- Parameters:
remoteAddr- target ip addressremotePort- 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.
-
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 targettarget- 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
-
setEnabled
public void setEnabled(boolean enabled)
Enables or disables this RTPConnectorOutputStream. While the stream is disabled, it suppresses actually sending any packets viasend(RawPacket).- Parameters:
enabled- true to enable, false to disable.
-
setMaxPacketsPerMillis
public boolean 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 setperMillis- the number of milliseconds per which maxPackets are to be sent by this OutputDataStream through its DatagramSocket
-
setPriority
public void setPriority(int priority)
Changes current thread priority.- Parameters:
priority- the new priority.
-
write
public int write(byte[] buf, int off, int len)ImplementsOutputDataStream.write(byte[], int, int).- Specified by:
writein interfacejavax.media.rtp.OutputDataStream- Parameters:
buf- thebyte[]to write into thisOutputDataStreamoff- the offset inbufat which thebytes to be written into thisOutputDataStreamstartlen- the number ofbytes inbufstarting atoffto be written into thisOutputDataStream- Returns:
- the number of
bytes read frombufstarting atoffand not exceedinglenand written into thisOutputDataStream
-
syncWrite
public int syncWrite(byte[] buf, int off, int len)Writes a byte[] to thisRTPConnectorOutputStreamsynchronously ( even whenUSE_SEND_THREADis enabled).- Returns:
- the number of bytes written.
-
write
protected int write(byte[] buf, int off, int len, Object context)ImplementsOutputDataStream.write(byte[], int, int). Allows extenders to provide a contextObjectto invoked overridable methods such aspacketize(byte[],int,int,Object).- Parameters:
buf- thebyte[]to write into thisOutputDataStreamoff- the offset inbufat which thebytes to be written into thisOutputDataStreamstartlen- the number ofbytes inbufstarting atoffto be written into thisOutputDataStreamcontext- theObjectto provide to invoked overridable methods such aspacketize(byte[],int,int,Object)- Returns:
- the number of
bytes read frombufstarting atoffand not exceedinglenand written into thisOutputDataStream
-
getOutputBitrate
public long getOutputBitrate()
- Returns:
- the current output bitrate in bits per second.
-
getOutputBitrate
public long getOutputBitrate(long now)
- Parameters:
now- the current time.- Returns:
- the current output bitrate in bits per second.
-
-