mirror of
https://github.com/samsonjs/media.git
synced 2026-04-02 10:45:51 +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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the underlying libopus library is available.
|
||||
*/
|
||||
public static boolean isLibopusAvailable() {
|
||||
return OpusDecoder.isLibopusAvailable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the version of underlying libopus library.
|
||||
*
|
||||
* @return version of the underlying libopus library.
|
||||
*/
|
||||
public static String getLibopusVersion() {
|
||||
return OpusDecoder.getLibopusVersion();
|
||||
return isLibopusAvailable() ? OpusDecoder.getLibopusVersion() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -26,13 +26,21 @@ import java.nio.ByteBuffer;
|
|||
*/
|
||||
/* package */ class OpusDecoder {
|
||||
|
||||
private final long nativeDecoderContext;
|
||||
|
||||
private static final boolean IS_AVAILABLE;
|
||||
static {
|
||||
System.loadLibrary("opus");
|
||||
System.loadLibrary("opusJNI");
|
||||
boolean isAvailable;
|
||||
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.
|
||||
*
|
||||
|
|
@ -81,6 +89,13 @@ import java.nio.ByteBuffer;
|
|||
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.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -151,12 +151,17 @@ public final class LibvpxVideoTrackRenderer extends SampleSourceTrackRenderer {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the version of underlying libvpx library.
|
||||
*
|
||||
* @return version of the underlying libvpx library.
|
||||
* Returns whether the underlying libvpx library is available.
|
||||
*/
|
||||
public static boolean isLibvpxAvailable() {
|
||||
return VpxDecoder.isLibvpxAvailable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the version of the underlying libvpx library if available, otherwise {@code null}.
|
||||
*/
|
||||
public static String getLibvpxVersion() {
|
||||
return VpxDecoder.getLibvpxVersion();
|
||||
return isLibvpxAvailable() ? VpxDecoder.getLibvpxVersion() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -24,13 +24,21 @@ import java.nio.ByteBuffer;
|
|||
*/
|
||||
/* package */ class VpxDecoder {
|
||||
|
||||
private final long vpxDecContext;
|
||||
|
||||
private static final boolean IS_AVAILABLE;
|
||||
static {
|
||||
System.loadLibrary("vpx");
|
||||
System.loadLibrary("vpxJNI");
|
||||
boolean isAvailable;
|
||||
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.
|
||||
*
|
||||
|
|
@ -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.
|
||||
* @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 {
|
||||
if (vpxDecode(vpxDecContext, encoded, size) != 0) {
|
||||
throw new VpxDecoderException("libvpx decode error: " + vpxGetErrorMessage(vpxDecContext));
|
||||
|
|
@ -69,6 +77,13 @@ import java.nio.ByteBuffer;
|
|||
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.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in a new issue