Jitsi: the OpenSource Java VoIP and Instant Messaging client.

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

java.lang.Object
  extended by net.java.sip.communicator.impl.neomedia.RTPConnectorInputStream
All Implemented Interfaces:
Runnable, javax.media.Controls, javax.media.protocol.PushSourceStream, javax.media.protocol.SourceStream
Direct Known Subclasses:
RTPConnectorTCPInputStream, RTPConnectorUDPInputStream

public abstract class RTPConnectorInputStream
extends Object
implements javax.media.protocol.PushSourceStream, Runnable

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

Field Summary
protected  boolean closed
          Whether this stream is closed.
protected  boolean ioError
          Caught an IO exception during read from socket
protected  RawPacket pkt
          The packet data to be read out of this instance through its read(byte[], int, int) method.
protected  Thread receiverThread
          The Thread receiving packets.
 
Fields inherited from interface javax.media.protocol.SourceStream
LENGTH_UNKNOWN
 
Constructor Summary
RTPConnectorInputStream()
          Initializes a new RTPConnectorInputStream which is to receive packet data from a specific UDP socket.
 
Method Summary
 void addDatagramPacketFilter(org.ice4j.socket.DatagramPacketFilter datagramPacketFilter)
          Adds a DatagramPacketFilter which allows dropping DatagramPackets before they are converted into RawPackets.
 void close()
          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 its read(byte[], int, int) method.
protected abstract  void doLogPacket(DatagramPacket packet)
          Log the packet.
 boolean endOfStream()
          Provides a dummy implementation to endOfStream() that always returns false.
 javax.media.protocol.ContentDescriptor getContentDescriptor()
          Provides a dummy implementation to getContentDescriptor() that always returns null.
 long getContentLength()
          Provides a dummy implementation to getContentLength() that always returns LENGTH_UNKNOWN.
 Object getControl(String controlType)
          Provides a dummy implementation to getControl(String) that always returns null.
 Object[] getControls()
          Provides a dummy implementation to getControls() that always returns EMPTY_CONTROLS.
 org.ice4j.socket.DatagramPacketFilter[] getDatagramPacketFilters()
          Gets the DatagramPacketFilters which allow dropping DatagramPackets before they are converted into RawPackets.
 int getMinimumTransferSize()
          Provides a dummy implementation to getMinimumTransferSize() that always returns 2 * 1024.
 int read(byte[] buffer, int offset, int length)
          Copies the content of the most recently received packet into buffer.
protected abstract  void receivePacket(DatagramPacket p)
          Receive packet.
 void run()
          Listens for incoming datagrams, stores them for reading by the read method and notifies the local transferHandler that there's data to be read.
 void setPriority(int priority)
          Changes current thread priority.
 void setTransferHandler(javax.media.protocol.SourceTransferHandler transferHandler)
          Sets the transferHandler that this connector should be notifying when new data is available for reading.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

closed

protected boolean closed
Whether this stream is closed. Used to control the termination of worker thread.


ioError

protected boolean ioError
Caught an IO exception during read from socket


pkt

protected RawPacket pkt
The packet data to be read out of this instance through its read(byte[], int, int) method.


receiverThread

protected Thread receiverThread
The Thread receiving packets.

Constructor Detail

RTPConnectorInputStream

public RTPConnectorInputStream()
Initializes a new RTPConnectorInputStream which is to receive packet data from a specific UDP socket.

Method Detail

close

public void close()
Close this stream, stops the worker thread.


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 its read(byte[], int, int) method. Allows extenders to intercept the packet data and possibly filter and/or modify it.

Parameters:
datagramPacket - the DatagramPacket containing the packet data
Returns:
a new RawPacket containing the packet data of the specified DatagramPacket or possibly its modification; null to ignore the packet data of the specified DatagramPacket and not make it available to this instance through its read(byte[], int, int) method

endOfStream

public boolean endOfStream()
Provides a dummy implementation to endOfStream() that always returns false.

Specified by:
endOfStream in interface javax.media.protocol.SourceStream
Returns:
false, no matter what.

getContentDescriptor

public javax.media.protocol.ContentDescriptor getContentDescriptor()
Provides a dummy implementation to getContentDescriptor() that always returns null.

Specified by:
getContentDescriptor in interface javax.media.protocol.SourceStream
Returns:
null, no matter what.

getContentLength

public long getContentLength()
Provides a dummy implementation to getContentLength() that always returns LENGTH_UNKNOWN.

Specified by:
getContentLength in interface javax.media.protocol.SourceStream
Returns:
LENGTH_UNKNOWN, no matter what.

getControl

public Object getControl(String controlType)
Provides a dummy implementation to getControl(String) that always returns null.

Specified by:
getControl in interface javax.media.Controls
Parameters:
controlType - ignored.
Returns:
null, no matter what.

getControls

public Object[] getControls()
Provides a dummy implementation to getControls() that always returns EMPTY_CONTROLS.

Specified by:
getControls in interface javax.media.Controls
Returns:
EMPTY_CONTROLS, no matter what.

getMinimumTransferSize

public int getMinimumTransferSize()
Provides a dummy implementation to getMinimumTransferSize() that always returns 2 * 1024.

Specified by:
getMinimumTransferSize in interface javax.media.protocol.PushSourceStream
Returns:
2 * 1024, no matter what.

read

public int read(byte[] buffer,
                int offset,
                int length)
         throws IOException
Copies the content of the most recently received packet into buffer.

Specified by:
read in interface javax.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.

doLogPacket

protected abstract void doLogPacket(DatagramPacket packet)
Log the packet.

Parameters:
packet - packet to log

receivePacket

protected abstract void receivePacket(DatagramPacket p)
                               throws IOException
Receive packet.

Parameters:
p - packet for receiving
Throws:
IOException - if something goes wrong during receiving

run

public void run()
Listens for incoming datagrams, stores them for reading by the read method and notifies the local transferHandler that there's data to be read.

Specified by:
run in interface Runnable

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:
setTransferHandler in interface javax.media.protocol.PushSourceStream
Parameters:
transferHandler - the transferHandler that this connector should be notifying when new data is available for reading.

setPriority

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

Parameters:
priority - the new priority.

getDatagramPacketFilters

public org.ice4j.socket.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.

addDatagramPacketFilter

public void addDatagramPacketFilter(org.ice4j.socket.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

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

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