|
Triton Mobile SDK for Android 3.5.1
This is a custom android player made by Triton Digital
|
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 () |
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:
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.
| 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.
| 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).
| 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).
| 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).