Make sure native library loads use correct class loader
Merge of https://github.com/google/ExoPlayer/pull/9934 PiperOrigin-RevId: 429259055
This commit is contained in:
parent
bb7ee69870
commit
cbcf7cd69a
@ -19,7 +19,7 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
/** Configurable loader for native libraries. */
|
/** Configurable loader for native libraries. */
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
public final class LibraryLoader {
|
public abstract class LibraryLoader {
|
||||||
|
|
||||||
private static final String TAG = "LibraryLoader";
|
private static final String TAG = "LibraryLoader";
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ public final class LibraryLoader {
|
|||||||
loadAttempted = true;
|
loadAttempted = true;
|
||||||
try {
|
try {
|
||||||
for (String lib : nativeLibraries) {
|
for (String lib : nativeLibraries) {
|
||||||
System.loadLibrary(lib);
|
loadLibrary(lib);
|
||||||
}
|
}
|
||||||
isAvailable = true;
|
isAvailable = true;
|
||||||
} catch (UnsatisfiedLinkError exception) {
|
} catch (UnsatisfiedLinkError exception) {
|
||||||
@ -59,4 +59,17 @@ public final class LibraryLoader {
|
|||||||
}
|
}
|
||||||
return isAvailable;
|
return isAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be implemented to call {@code System.loadLibrary(name)}.
|
||||||
|
*
|
||||||
|
* <p>It's necessary for each subclass to implement this method because {@link
|
||||||
|
* System#loadLibrary(String)} uses reflection to obtain the calling class, which is then used to
|
||||||
|
* obtain the class loader to use when loading the native library. If this class were to implement
|
||||||
|
* the method directly, and if a subclass were to have a different class loader, then loading of
|
||||||
|
* the native library would fail.
|
||||||
|
*
|
||||||
|
* @param name The name of the library to load.
|
||||||
|
*/
|
||||||
|
protected abstract void loadLibrary(String name);
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,13 @@ public final class Gav1Library {
|
|||||||
MediaLibraryInfo.registerModule("media3.decoder.av1");
|
MediaLibraryInfo.registerModule("media3.decoder.av1");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final LibraryLoader LOADER = new LibraryLoader("gav1JNI");
|
private static final LibraryLoader LOADER =
|
||||||
|
new LibraryLoader("gav1JNI") {
|
||||||
|
@Override
|
||||||
|
protected void loadLibrary(String name) {
|
||||||
|
System.loadLibrary(name);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private Gav1Library() {}
|
private Gav1Library() {}
|
||||||
|
|
||||||
|
@ -34,7 +34,13 @@ public final class FfmpegLibrary {
|
|||||||
|
|
||||||
private static final String TAG = "FfmpegLibrary";
|
private static final String TAG = "FfmpegLibrary";
|
||||||
|
|
||||||
private static final LibraryLoader LOADER = new LibraryLoader("ffmpegJNI");
|
private static final LibraryLoader LOADER =
|
||||||
|
new LibraryLoader("ffmpegJNI") {
|
||||||
|
@Override
|
||||||
|
protected void loadLibrary(String name) {
|
||||||
|
System.loadLibrary(name);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private static @MonotonicNonNull String version;
|
private static @MonotonicNonNull String version;
|
||||||
private static int inputBufferPaddingSize = C.LENGTH_UNSET;
|
private static int inputBufferPaddingSize = C.LENGTH_UNSET;
|
||||||
|
@ -27,7 +27,13 @@ public final class FlacLibrary {
|
|||||||
MediaLibraryInfo.registerModule("media3.decoder.flac");
|
MediaLibraryInfo.registerModule("media3.decoder.flac");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final LibraryLoader LOADER = new LibraryLoader("flacJNI");
|
private static final LibraryLoader LOADER =
|
||||||
|
new LibraryLoader("flacJNI") {
|
||||||
|
@Override
|
||||||
|
protected void loadLibrary(String name) {
|
||||||
|
System.loadLibrary(name);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private FlacLibrary() {}
|
private FlacLibrary() {}
|
||||||
|
|
||||||
|
@ -29,7 +29,14 @@ public final class OpusLibrary {
|
|||||||
MediaLibraryInfo.registerModule("media3.decoder.opus");
|
MediaLibraryInfo.registerModule("media3.decoder.opus");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final LibraryLoader LOADER = new LibraryLoader("opusV2JNI");
|
private static final LibraryLoader LOADER =
|
||||||
|
new LibraryLoader("opusV2JNI") {
|
||||||
|
@Override
|
||||||
|
protected void loadLibrary(String name) {
|
||||||
|
System.loadLibrary(name);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private static @C.CryptoType int cryptoType = C.CRYPTO_TYPE_UNSUPPORTED;
|
private static @C.CryptoType int cryptoType = C.CRYPTO_TYPE_UNSUPPORTED;
|
||||||
|
|
||||||
private OpusLibrary() {}
|
private OpusLibrary() {}
|
||||||
|
@ -29,7 +29,14 @@ public final class VpxLibrary {
|
|||||||
MediaLibraryInfo.registerModule("media3.decoder.vpx");
|
MediaLibraryInfo.registerModule("media3.decoder.vpx");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final LibraryLoader LOADER = new LibraryLoader("vpx", "vpxV2JNI");
|
private static final LibraryLoader LOADER =
|
||||||
|
new LibraryLoader("vpx", "vpxV2JNI") {
|
||||||
|
@Override
|
||||||
|
protected void loadLibrary(String name) {
|
||||||
|
System.loadLibrary(name);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private static @C.CryptoType int cryptoType = C.CRYPTO_TYPE_UNSUPPORTED;
|
private static @C.CryptoType int cryptoType = C.CRYPTO_TYPE_UNSUPPORTED;
|
||||||
|
|
||||||
private VpxLibrary() {}
|
private VpxLibrary() {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user