mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Add libopus/libvpx availability checks
This commit is contained in:
parent
4422e8a015
commit
dd4d4e8f7e
4 changed files with 56 additions and 14 deletions
|
|
@ -119,13 +119,20 @@ public final class LibopusAudioTrackRenderer extends SampleSourceTrackRenderer
|
||||||
formatHolder = new MediaFormatHolder();
|
formatHolder = new MediaFormatHolder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the underlying libopus library is available.
|
||||||
|
*/
|
||||||
|
public static boolean isLibopusAvailable() {
|
||||||
|
return OpusDecoder.isLibopusAvailable();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the version of underlying libopus library.
|
* Get the version of underlying libopus library.
|
||||||
*
|
*
|
||||||
* @return version of the underlying libopus library.
|
* @return version of the underlying libopus library.
|
||||||
*/
|
*/
|
||||||
public static String getLibopusVersion() {
|
public static String getLibopusVersion() {
|
||||||
return OpusDecoder.getLibopusVersion();
|
return isLibopusAvailable() ? OpusDecoder.getLibopusVersion() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,21 @@ import java.nio.ByteBuffer;
|
||||||
*/
|
*/
|
||||||
/* package */ class OpusDecoder {
|
/* package */ class OpusDecoder {
|
||||||
|
|
||||||
private final long nativeDecoderContext;
|
private static final boolean IS_AVAILABLE;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
System.loadLibrary("opus");
|
boolean isAvailable;
|
||||||
System.loadLibrary("opusJNI");
|
try {
|
||||||
|
System.loadLibrary("opus");
|
||||||
|
System.loadLibrary("opusJNI");
|
||||||
|
isAvailable = true;
|
||||||
|
} catch (UnsatisfiedLinkError exception) {
|
||||||
|
isAvailable = false;
|
||||||
|
}
|
||||||
|
IS_AVAILABLE = isAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final long nativeDecoderContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the Opus Decoder.
|
* Creates the Opus Decoder.
|
||||||
*
|
*
|
||||||
|
|
@ -81,6 +89,13 @@ import java.nio.ByteBuffer;
|
||||||
opusReset(nativeDecoderContext);
|
opusReset(nativeDecoderContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the underlying libopus library is available.
|
||||||
|
*/
|
||||||
|
public static boolean isLibopusAvailable() {
|
||||||
|
return IS_AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the version string of the underlying libopus decoder.
|
* Returns the version string of the underlying libopus decoder.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -151,12 +151,17 @@ public final class LibvpxVideoTrackRenderer extends SampleSourceTrackRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the version of underlying libvpx library.
|
* Returns whether the underlying libvpx library is available.
|
||||||
*
|
*/
|
||||||
* @return version of the underlying libvpx library.
|
public static boolean isLibvpxAvailable() {
|
||||||
|
return VpxDecoder.isLibvpxAvailable();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the version of the underlying libvpx library if available, otherwise {@code null}.
|
||||||
*/
|
*/
|
||||||
public static String getLibvpxVersion() {
|
public static String getLibvpxVersion() {
|
||||||
return VpxDecoder.getLibvpxVersion();
|
return isLibvpxAvailable() ? VpxDecoder.getLibvpxVersion() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -24,13 +24,21 @@ import java.nio.ByteBuffer;
|
||||||
*/
|
*/
|
||||||
/* package */ class VpxDecoder {
|
/* package */ class VpxDecoder {
|
||||||
|
|
||||||
private final long vpxDecContext;
|
private static final boolean IS_AVAILABLE;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
System.loadLibrary("vpx");
|
boolean isAvailable;
|
||||||
System.loadLibrary("vpxJNI");
|
try {
|
||||||
|
System.loadLibrary("vpx");
|
||||||
|
System.loadLibrary("vpxJNI");
|
||||||
|
isAvailable = true;
|
||||||
|
} catch (UnsatisfiedLinkError exception) {
|
||||||
|
isAvailable = false;
|
||||||
|
}
|
||||||
|
IS_AVAILABLE = isAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final long vpxDecContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the VP9 Decoder.
|
* Creates the VP9 Decoder.
|
||||||
*
|
*
|
||||||
|
|
@ -54,7 +62,7 @@ import java.nio.ByteBuffer;
|
||||||
* @return 0 on success with a frame to render. 1 on success without a frame to render.
|
* @return 0 on success with a frame to render. 1 on success without a frame to render.
|
||||||
* @throws VpxDecoderException on decode failure.
|
* @throws VpxDecoderException on decode failure.
|
||||||
*/
|
*/
|
||||||
public int decode(ByteBuffer encoded, int size, OutputBuffer outputBuffer, boolean outputRgb)
|
public int decode(ByteBuffer encoded, int size, OutputBuffer outputBuffer, boolean outputRgb)
|
||||||
throws VpxDecoderException {
|
throws VpxDecoderException {
|
||||||
if (vpxDecode(vpxDecContext, encoded, size) != 0) {
|
if (vpxDecode(vpxDecContext, encoded, size) != 0) {
|
||||||
throw new VpxDecoderException("libvpx decode error: " + vpxGetErrorMessage(vpxDecContext));
|
throw new VpxDecoderException("libvpx decode error: " + vpxGetErrorMessage(vpxDecContext));
|
||||||
|
|
@ -69,6 +77,13 @@ import java.nio.ByteBuffer;
|
||||||
vpxClose(vpxDecContext);
|
vpxClose(vpxDecContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the underlying libvpx library is available.
|
||||||
|
*/
|
||||||
|
public static boolean isLibvpxAvailable() {
|
||||||
|
return IS_AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the version string of the underlying libvpx decoder.
|
* Returns the version string of the underlying libvpx decoder.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue