
public class ReadableWritableChannelHandler extends Object implements IURLProtocolHandler
ReadableByteChannel
objects or write to WritableByteChannel object.
The IURLProtocolHandler.URL_RDWR mode is not supported, and
isStreamed(String, int) will always return true.
| Modifier and Type | Field and Description |
|---|---|
static boolean |
CLOSE_STREAM_ON_CLOSE
Whether or not this class will default calling
Closeable.close() on a stream when
close() is called on this method. |
SEEK_CUR, SEEK_END, SEEK_SET, SEEK_SIZE, URL_RDONLY_MODE, URL_RDWR, URL_WRONLY_MODE| Constructor and Description |
|---|
ReadableWritableChannelHandler(ReadableByteChannel channel)
Create a handler that can only be opened for reading.
|
ReadableWritableChannelHandler(ReadableByteChannel in,
WritableByteChannel out,
boolean closeStreamOnClose)
Creates a new handler.
|
ReadableWritableChannelHandler(WritableByteChannel channel)
Create a handler that can only be opened for writing.
|
| Modifier and Type | Method and Description |
|---|---|
int |
close()
A request to close() from FFMPEG
|
Channel |
getOpenChannel()
Returns the channel currently
open(String, int). |
ReadableByteChannel |
getReadChannel()
Returns the channel we'd input from if asked.
|
WritableByteChannel |
getWriteChannel()
Returns the channel we'd output to if asked.
|
boolean |
isCloseStreamOnClose()
Will this handler call
Closeable.close() automatically
when its close() method is called by Humble Video? |
boolean |
isStreamed(String url,
int flags)
Special callback made by Humble Video in order to determine if your
stream supports streaming.
|
int |
open(String url,
int flags)
This method gets called by FFMPEG when it opens a file.
|
int |
read(byte[] buf,
int size)
This method gets called by FFMPEG when it tries to read data.
|
long |
seek(long offset,
int whence)
A request from FFMPEG to seek to a position in the stream.
|
int |
write(byte[] buf,
int size)
This method gets called by FFMPEG when it tries to write data.
|
public static final boolean CLOSE_STREAM_ON_CLOSE
Closeable.close() on a stream when
close() is called on this method. Can be
overriden in constructors.public ReadableWritableChannelHandler(ReadableByteChannel channel)
channel - an input channel.public ReadableWritableChannelHandler(WritableByteChannel channel)
channel - an output channelpublic ReadableWritableChannelHandler(ReadableByteChannel in, WritableByteChannel out, boolean closeStreamOnClose)
IURLProtocolHandler.URL_RDONLY_MODE or
IURLProtocolHandler.URL_WRONLY_MODE, but not at
the same time.
IURLProtocolHandler.URL_RDWR mode is not supported
by this handler.
in - The channel to read from if asked to.out - The channel to write from if asked to.closeStreamOnClose - Whether or not to automatically
call Closeable.close() on the given channel
when close() is called.public int close()
close in interface IURLProtocolHandlerpublic int open(String url, int flags)
open in interface IURLProtocolHandlerurl - The URL to openflags - The flags (e.g. IURLProtocolHandler.URL_RDONLY_MODE)public int read(byte[] buf,
int size)
For non-blocking IO, return:
io.humble.video.Error#typeToErrorNumber(io.humble.video.Error.Type)
pass in io.humble.video.Error.Type#ERROR_AGAIN for the error type. This
returns the platform specific number for EAGAIN on your platform
signaling that callers should try again later.
Alternately implementors may block until data is returning, but they should then
respect the Thread.isInterrupted() setting.
read in interface IURLProtocolHandlerbuf - The buffer to write your data to.size - The number of bytes in buf data available for you to write the data that FFMPEG will read.public long seek(long offset,
int whence)
seek in interface IURLProtocolHandleroffset - The offset in bytes.whence - Where that offset is relative to. Follow the C stdlib fseek() conventions EXCEPT
IURLProtocolHandler.SEEK_SIZE should return back the size of the stream in bytes if known without adjusting
the seek pointer.public int write(byte[] buf,
int size)
For non-blocking IO, return:
io.humble.video.Error#typeToErrorNumber(io.humble.video.Error.Type)
pass in io.humble.video.Error.Type#ERROR_AGAIN for the error type. This
returns the platform specific number for EAGAIN on your platform
signaling that callers should try again later.
Alternately implementators may block until data is returning, but they should then
respect the Thread.isInterrupted() setting.
write in interface IURLProtocolHandlerbuf - The data you should write.size - The number of bytes in buf.public boolean isStreamed(String url, int flags)
If this method returns true, Humble Video will assume it cannot seek backwards in this container.
This has one main practical consequence. When writing it means certain container formats (e.g. the MOV container) will not be usable as it requires seeking back to the start of a file to write MOV required header information once the entire file has been encoded.
But if your medium is streaming, you'll want to return true for this, and then FFMPEG will not attempt to seek back in time.
Always true for this class.isStreamed in interface IURLProtocolHandlerurl - The URL that would be passed to IURLProtocolHandler.open(String, int)flags - The flags that would be passed to IURLProtocolHandler.open(String, int)public ReadableByteChannel getReadChannel()
public WritableByteChannel getWriteChannel()
public Channel getOpenChannel()
open(String, int).public boolean isCloseStreamOnClose()
Closeable.close() automatically
when its close() method is called by Humble Video?Copyright © 2018 Humble Software. All rights reserved.