Package org.jitsi.impl.neomedia
Class RTPConnectorInputStream<T extends Closeable>
- java.lang.Object
-
- org.jitsi.impl.neomedia.RTPConnectorInputStream<T>
-
- All Implemented Interfaces:
Closeable,AutoCloseable,javax.media.Controls,javax.media.protocol.Controls,javax.media.protocol.PushSourceStream,javax.media.protocol.SourceStream
- Direct Known Subclasses:
TransformInputStream
public abstract class RTPConnectorInputStream<T extends Closeable> extends Object implements javax.media.protocol.PushSourceStream, Closeable
- Author:
- Bing SU (nova.su@gmail.com), Lyubomir Marinov, Boris Grozev
-
-
Field Summary
Fields Modifier and Type Field Description static intPACKET_RECEIVE_BUFFER_LENGTHThe length in bytes of the buffers of RTPConnectorInputStream receiving packets from the network.static StringSO_RCVBUF_PNAMEThe name of the property which controls the size of the receive buffer whichRTPConnectorInputStreamwill request for the sockets that it uses.protected Tsocket
-
Constructor Summary
Constructors Modifier Constructor Description protectedRTPConnectorInputStream(T socket)Initializes a new RTPConnectorInputStream which is to receive packet data from a specific UDP socket.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddDatagramPacketFilter(org.jitsi.utils.DatagramPacketFilter datagramPacketFilter)Adds a DatagramPacketFilter which allows dropping DatagramPackets before they are converted into RawPackets.voidclose()Close this stream, stops the worker thread.protected RawPacket[]createRawPacket(DatagramPacket datagramPacket)Creates a new RawPacket from a specific DatagramPacket in order to have this instance receive its packet data through itsread(byte[], int, int)method.protected abstract voiddoLogPacket(DatagramPacket packet)Log the packet.booleanendOfStream()Provides a dummy implementation ofSourceStream.endOfStream()that always returns false.javax.media.protocol.ContentDescriptorgetContentDescriptor()Provides a dummy implementation ofSourceStream.getContentDescriptor()that always returns null.longgetContentLength()Provides a dummy implementation ofSourceStream.getContentLength()that always returns LENGTH_UNKNOWN.ObjectgetControl(String controlType)Provides a dummy implementation ofControls.getControl(String)that always returns null.Object[]getControls()Provides a dummy implementation ofControls.getControls()that always returns EMPTY_CONTROLS.protected org.jitsi.utils.DatagramPacketFilter[]getDatagramPacketFilters()Gets the DatagramPacketFilters which allow dropping DatagramPackets before they are converted into RawPackets.longgetLastActivityTime()Gets the time in milliseconds of the last activity related to this RTPConnectorInputStream.intgetMinimumTransferSize()Provides a dummy implementation ofPushSourceStream.getMinimumTransferSize()that always returns 2 * 1024.longgetNumberOfReceivedBytes()Returns the number of received bytes for the stream.protected PacketLoggingServicegetPacketLoggingService()Gets thePacketLoggingService(to be) utilized by this instance.intread(byte[] buffer, int offset, int length)Copies the content of the most recently received packet into buffer.protected intread(javax.media.Buffer buffer, byte[] data, int offset, int length)Copies the content of the most recently received packet into data.protected abstract voidreceive(DatagramPacket p)Receive packet.voidsetEnabled(boolean enabled)Enables or disables this RTPConnectorInputStream.voidsetPriority(int priority)Changes current thread priority.protected abstract voidsetReceiveBufferSize(int receiveBufferSize)static voidsetThreadPriority(Thread thread, int priority)Sets a specific priority on a specific Thread.voidsetTransferHandler(javax.media.protocol.SourceTransferHandler transferHandler)Sets the transferHandler that this connector should be notifying when new data is available for reading.
-
-
-
Field Detail
-
PACKET_RECEIVE_BUFFER_LENGTH
public static final int PACKET_RECEIVE_BUFFER_LENGTH
The length in bytes of the buffers of RTPConnectorInputStream receiving packets from the network.- See Also:
- Constant Field Values
-
SO_RCVBUF_PNAME
public static final String SO_RCVBUF_PNAME
The name of the property which controls the size of the receive buffer whichRTPConnectorInputStreamwill request for the sockets that it uses.
-
-
Constructor Detail
-
RTPConnectorInputStream
protected RTPConnectorInputStream(T socket)
Initializes a new RTPConnectorInputStream which is to receive packet data from a specific UDP socket.
-
-
Method Detail
-
setThreadPriority
public static void setThreadPriority(Thread thread, int priority)
Sets a specific priority on a specific Thread.- Parameters:
thread- the Thread to set the specified priority onpriority- the priority to set on the specified thread
-
getLastActivityTime
public long getLastActivityTime()
Gets the time in milliseconds of the last activity related to this RTPConnectorInputStream.- Returns:
- the time in milliseconds of the last activity related to this RTPConnectorInputStream
-
addDatagramPacketFilter
public void addDatagramPacketFilter(org.jitsi.utils.DatagramPacketFilter datagramPacketFilter)
Adds a DatagramPacketFilter which allows dropping DatagramPackets before they are converted into RawPackets.- Parameters:
datagramPacketFilter- the DatagramPacketFilter which allows dropping DatagramPackets before they are converted into RawPackets
-
close
public void close()
Close this stream, stops the worker thread.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
createRawPacket
protected RawPacket[] createRawPacket(DatagramPacket datagramPacket)
Creates a new RawPacket from a specific DatagramPacket in order to have this instance receive its packet data through itsread(byte[], int, int)method. Returns an array of RawPacket with the created packet as its first element (and null for the other elements). Allows extenders to intercept the packet data and possibly filter and/or modify it.- Parameters:
datagramPacket- the DatagramPacket containing the packet data- Returns:
- an array of RawPacket containing the RawPacket which contains the packet data of the specified DatagramPacket as its first element.
-
doLogPacket
protected abstract void doLogPacket(DatagramPacket packet)
Log the packet.- Parameters:
packet- packet to log
-
endOfStream
public boolean endOfStream()
Provides a dummy implementation ofSourceStream.endOfStream()that always returns false.- Specified by:
endOfStreamin interfacejavax.media.protocol.SourceStream- Returns:
- false, no matter what.
-
getContentDescriptor
public javax.media.protocol.ContentDescriptor getContentDescriptor()
Provides a dummy implementation ofSourceStream.getContentDescriptor()that always returns null.- Specified by:
getContentDescriptorin interfacejavax.media.protocol.SourceStream- Returns:
- null, no matter what.
-
getContentLength
public long getContentLength()
Provides a dummy implementation ofSourceStream.getContentLength()that always returns LENGTH_UNKNOWN.- Specified by:
getContentLengthin interfacejavax.media.protocol.SourceStream- Returns:
- LENGTH_UNKNOWN, no matter what.
-
getControl
public Object getControl(String controlType)
Provides a dummy implementation ofControls.getControl(String)that always returns null.- Specified by:
getControlin interfacejavax.media.Controls- Parameters:
controlType- ignored.- Returns:
- null, no matter what.
-
getControls
public Object[] getControls()
Provides a dummy implementation ofControls.getControls()that always returns EMPTY_CONTROLS.- Specified by:
getControlsin interfacejavax.media.Controls- Returns:
- EMPTY_CONTROLS, no matter what.
-
getDatagramPacketFilters
protected org.jitsi.utils.DatagramPacketFilter[] getDatagramPacketFilters()
Gets the DatagramPacketFilters which allow dropping DatagramPackets before they are converted into RawPackets.- Returns:
- the DatagramPacketFilters which allow dropping DatagramPackets before they are converted into RawPackets.
-
getMinimumTransferSize
public int getMinimumTransferSize()
Provides a dummy implementation ofPushSourceStream.getMinimumTransferSize()that always returns 2 * 1024.- Specified by:
getMinimumTransferSizein interfacejavax.media.protocol.PushSourceStream- Returns:
- 2 * 1024, no matter what.
-
getNumberOfReceivedBytes
public long getNumberOfReceivedBytes()
Returns the number of received bytes for the stream.- Returns:
- the number of received bytes
-
getPacketLoggingService
protected PacketLoggingService getPacketLoggingService()
Gets thePacketLoggingService(to be) utilized by this instance.- Returns:
- the
PacketLoggingService(to be) utilized by this instance
-
read
protected int read(javax.media.Buffer buffer, byte[] data, int offset, int length) throws IOExceptionCopies the content of the most recently received packet into data.- Parameters:
buffer- an optional Buffer instance associated with the specified data, offset and length and provided to the method in case the implementation would like to provide additional Buffer properties such as flagsdata- 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 data.length- the number of bytes available for writing in data.- Returns:
- the number of bytes read
- Throws:
IOException- if length is less than the size of the packet.
-
read
public int read(byte[] buffer, int offset, int length) throws IOExceptionCopies the content of the most recently received packet into buffer.- Specified by:
readin interfacejavax.media.protocol.PushSourceStream- 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 buffer.- Returns:
- the number of bytes read
- Throws:
IOException- if length is less than the size of the packet.
-
receive
protected abstract void receive(DatagramPacket p) throws IOException
Receive packet.- Parameters:
p- packet for receiving- Throws:
IOException- if something goes wrong during receiving
-
setEnabled
public void setEnabled(boolean enabled)
Enables or disables this RTPConnectorInputStream. While the stream is disabled, it does not accept any packets.- Parameters:
enabled- true to enable, false to disable.
-
setPriority
public void setPriority(int priority)
Changes current thread priority.- Parameters:
priority- the new priority.
-
setReceiveBufferSize
protected abstract void setReceiveBufferSize(int receiveBufferSize) throws IOException- Throws:
IOException
-
setTransferHandler
public void setTransferHandler(javax.media.protocol.SourceTransferHandler transferHandler)
Sets the transferHandler that this connector should be notifying when new data is available for reading.- Specified by:
setTransferHandlerin interfacejavax.media.protocol.PushSourceStream- Parameters:
transferHandler- the transferHandler that this connector should be notifying when new data is available for reading.
-
-