public class MediaCodecWebpDecoder
extends java.lang.Object
Rendering to a Surface
:
byte[] webp = ...; MediaCodecWebpDecoder decoder = new MediaCodecWebpDecoder(new Surface(...)); MediaCodecWebpDecoder.OutputBuffer image = decoder.decode(webp); decoder.releaseOutputBuffer(true);
Retrieving the decoded image in a byte buffer:
byte[] webp = ...; MediaCodecWebpDecoder decoder = new MediaCodecWebpDecoder(new Surface(...)); MediaCodecWebpDecoder.OutputBuffer image = decoder.decode(webp); byte[] array = new byte[image.info.size]; array.buffer.rewind(); array.buffer.get(array, 0, array.length); decoder.releaseOutputBuffer(false);
Modifier and Type | Class and Description |
---|---|
static class |
MediaCodecWebpDecoder.CodecUnavailableException |
static class |
MediaCodecWebpDecoder.OutputBuffer
Wrapper class for the ByteBuffer, BufferInfo, MediaFormat returned by MediaCodec.
|
Constructor and Description |
---|
MediaCodecWebpDecoder(boolean useSoftwareDecoder)
Creates a MediaCodec based WebP decoder without an associated Surface.
|
MediaCodecWebpDecoder(Surface surface,
boolean useSoftwareDecoder)
Creates a MediaCodec based WebP decoder.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
MediaCodecWebpDecoder.OutputBuffer |
decode(byte[] webp)
Decodes a WebP image using MediaCodec.
|
int |
getHeight() |
MediaCodec |
getMediaCodec()
Returns the associated MediaCodec decoder.
|
Surface |
getSurface()
Returns the configured surface.
|
int |
getWidth() |
void |
releaseOutputBuffer(boolean render)
Releases the buffer returned by decode().
|
void |
reset(Surface s)
Sets the Surface to be used with the codec.
|
public MediaCodecWebpDecoder(Surface surface, boolean useSoftwareDecoder) throws MediaCodecWebpDecoder.CodecUnavailableException
surface
- Surface to use for renderinguseSoftwareDecoder
- if true forces the use of a software decoderMediaCodecWebpDecoder.CodecUnavailableException
- if the requested VP8 decoder is unavailableandroid.media.MediaCodec
public MediaCodecWebpDecoder(boolean useSoftwareDecoder) throws MediaCodecWebpDecoder.CodecUnavailableException
public void reset(Surface s)
decode(byte[])
.public void close()
public int getWidth()
public int getHeight()
public Surface getSurface()
public MediaCodec getMediaCodec()
public void releaseOutputBuffer(boolean render)
render
- if set to true renders the buffer to the configured Surfacepublic MediaCodecWebpDecoder.OutputBuffer decode(byte[] webp) throws java.lang.IllegalArgumentException
webp
- byte array containing a lossy (VP8) WebP imageOutputBuffer
referencing the decoded image on success, null
otherwisejava.lang.IllegalArgumentException
- if webp
is not a valid WebP fileMediaCodecWebpDecoder.OutputBuffer