Class 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 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 of RTPConnectorOutputStream. 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.
    • Constructor Detail

      • RTPConnectorOutputStream

        protected RTPConnectorOutputStream()
        Initializes a new RTPConnectorOutputStream which is to send packet data out through a specific socket.
    • Method Detail

      • logDroppedPacket

        public static boolean logDroppedPacket​(int numDroppedPackets)
        Returns true if a warning should be logged after a queue has dropped numDroppedPackets packets.
        Parameters:
        numDroppedPackets - the number of dropped packets.
        Returns:
        true if a warning should be logged.
      • 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.
      • 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 its write(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 of buf starting at off with the specified len is copied into the buffer of the returned RawPacket.
        off - the offset of the packet data in buf
        len - the length of the packet data in buf
        context - the Object provided to write(byte[], int, int, java.lang.Object). The implementation of RTPConnectorOutputStream ignores the context.
        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 log
        target - 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 the PacketLoggingService (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 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.
      • 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
      • setEnabled

        public void setEnabled​(boolean enabled)
        Enables or disables this RTPConnectorOutputStream. While the stream is disabled, it suppresses actually sending any packets via send(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 set
        perMillis - 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)
        Implements OutputDataStream.write(byte[], int, int).
        Specified by:
        write in interface javax.media.rtp.OutputDataStream
        Parameters:
        buf - the byte[] to write into this OutputDataStream
        off - the offset in buf at which the bytes to be written into this OutputDataStream start
        len - the number of bytes in buf starting at off to be written into this OutputDataStream
        Returns:
        the number of bytes read from buf starting at off and not exceeding len and written into this OutputDataStream
      • syncWrite

        public int syncWrite​(byte[] buf,
                             int off,
                             int len)
        Writes a byte[] to this RTPConnectorOutputStream synchronously ( even when USE_SEND_THREAD is enabled).
        Returns:
        the number of bytes written.
      • write

        protected int write​(byte[] buf,
                            int off,
                            int len,
                            Object context)
        Implements OutputDataStream.write(byte[], int, int). Allows extenders to provide a context Object to invoked overridable methods such as packetize(byte[],int,int,Object).
        Parameters:
        buf - the byte[] to write into this OutputDataStream
        off - the offset in buf at which the bytes to be written into this OutputDataStream start
        len - the number of bytes in buf starting at off to be written into this OutputDataStream
        context - the Object to provide to invoked overridable methods such as packetize(byte[],int,int,Object)
        Returns:
        the number of bytes read from buf starting at off and not exceeding len and written into this OutputDataStream
      • 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.