Class RTPConnectorInputStream<T extends Closeable>

  • 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 int PACKET_RECEIVE_BUFFER_LENGTH
      The length in bytes of the buffers of RTPConnectorInputStream receiving packets from the network.
      static String SO_RCVBUF_PNAME
      The name of the property which controls the size of the receive buffer which RTPConnectorInputStream will request for the sockets that it uses.
      protected T socket  
      • Fields inherited from interface javax.media.protocol.SourceStream

        LENGTH_UNKNOWN
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected RTPConnectorInputStream​(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
      void addDatagramPacketFilter​(org.jitsi.utils.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 of SourceStream.endOfStream() that always returns false.
      javax.media.protocol.ContentDescriptor getContentDescriptor()
      Provides a dummy implementation of SourceStream.getContentDescriptor() that always returns null.
      long getContentLength()
      Provides a dummy implementation of SourceStream.getContentLength() that always returns LENGTH_UNKNOWN.
      Object getControl​(String controlType)
      Provides a dummy implementation of Controls.getControl(String) that always returns null.
      Object[] getControls()
      Provides a dummy implementation of Controls.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.
      long getLastActivityTime()
      Gets the time in milliseconds of the last activity related to this RTPConnectorInputStream.
      int getMinimumTransferSize()
      Provides a dummy implementation of PushSourceStream.getMinimumTransferSize() that always returns 2 * 1024.
      long getNumberOfReceivedBytes()
      Returns the number of received bytes for the stream.
      protected PacketLoggingService getPacketLoggingService()
      Gets the PacketLoggingService (to be) utilized by this instance.
      int read​(byte[] buffer, int offset, int length)
      Copies the content of the most recently received packet into buffer.
      protected int read​(javax.media.Buffer buffer, byte[] data, int offset, int length)
      Copies the content of the most recently received packet into data.
      protected abstract void receive​(DatagramPacket p)
      Receive packet.
      void setEnabled​(boolean enabled)
      Enables or disables this RTPConnectorInputStream.
      void setPriority​(int priority)
      Changes current thread priority.
      protected abstract void setReceiveBufferSize​(int receiveBufferSize)  
      static void setThreadPriority​(Thread thread, int priority)
      Sets a specific priority on a specific Thread.
      void setTransferHandler​(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 which RTPConnectorInputStream will request for the sockets that it uses.
      • socket

        protected final T extends Closeable socket
    • 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 on
        priority - 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:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
      • 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. 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 of SourceStream.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 of SourceStream.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 of SourceStream.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 of Controls.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 of Controls.getControls() that always returns EMPTY_CONTROLS.
        Specified by:
        getControls in interface javax.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 of PushSourceStream.getMinimumTransferSize() that always returns 2 * 1024.
        Specified by:
        getMinimumTransferSize in interface javax.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 the PacketLoggingService (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 IOException
        Copies 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 flags
        data - 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 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.
      • 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:
        setTransferHandler in interface javax.media.protocol.PushSourceStream
        Parameters:
        transferHandler - the transferHandler that this connector should be notifying when new data is available for reading.