Triton Mobile SDK for Android 3.5.1
This is a custom android player made by Triton Digital
Loading...
Searching...
No Matches
com.tritondigital.net.streaming.proxy.utils.QueueInputStream Class Reference
Inheritance diagram for com.tritondigital.net.streaming.proxy.utils.QueueInputStream:

Public Member Functions

 QueueInputStream (int bufferSize)
 Constructor, set the size of the circular buffer.
 
void put (byte[] newBuf)
 Adds new data at the end of the buffer.
 
void put (byte[] newBuf, int newBufLen)
 
int read () throws IOException
 
int read (byte[] b, int off, int len) throws IOException
 
void close ()
 

Detailed Description

Replacement for the PpipedInputStream / PipedOutputStream pair for the decoder.

On some platforms such as Android Api Level < 9, PipedInputStream are slow and have an unsettable buffer size.

This InputStream has the same functionalities:

  1. Add data to the stream (acts like an OutputStream converted to an InputStream).
  2. Thread safe, can write from and thread and read from an y thread. The thread will however block if there is an operation already in progress.
  3. Blocks when trying to read from an empty stream or add to a full stream.
  4. Uses an internal circular buffer for good performances an no allocations.

It has the minimal code to do this, it may not be very scalable for now but it has everything needed for the client to put data in the queue and for the decoder to read it efficiently, with passive wait when the client cannot put more data because the queue is full or when the decoder cannot read data because the queue is empty. It has been tester with 2 threads and both a small 64B and a large 16kB buffers.

Member Function Documentation

◆ put() [1/2]

void com.tritondigital.net.streaming.proxy.utils.QueueInputStream.put ( byte[]  newBuf)

Adds new data at the end of the buffer.

Convenience method to add all the data from newBuf.

◆ put() [2/2]

void com.tritondigital.net.streaming.proxy.utils.QueueInputStream.put ( byte[]  newBuf,
int  newBufLen 
)

Adds new data at the end of the buffer. Adds the given length of the given buffer. If there is not enough room for the entire new data, the maximum data is written to the circular buffer, then the thread blocks until there is some data that is read from the stream, which would free room for additional bytes of the new data.

Returns when all the new data has been written to the buffer, which may mean multiple blocks if the consumer is slower or if the new data is significantly larger than internal circular buffer.

If there is a thread blocked in reading, it is unblocked (only one thread is unblocked at a time).

◆ read() [1/2]

int com.tritondigital.net.streaming.proxy.utils.QueueInputStream.read ( ) throws IOException

Reads a single byte of data from the beginning of the buffer. If the stream is empty, the thread blocks until new data is added to the queue, then the byte is read.

If there is a thread blocked in adding new data to a full queue, it is unblocked (only one thread is unblocked at a time).

◆ read() [2/2]

int com.tritondigital.net.streaming.proxy.utils.QueueInputStream.read ( byte[]  b,
int  off,
int  len 
) throws IOException

Reads data from the beginning of the buffer. If there is less data than requested, the maximum data is read from the circular buffer and this count is returned. If the stream is empty, the thread blocks until new data is added to the queue, then the minimum count between the newly added data and the requested size is read.

If there is a thread blocked in adding new data to a full queue, it is unblocked (only one thread is unblocked at a time).

Returns
The number of bytes read or -1 on error.

The documentation for this class was generated from the following file: