Skip to content

Commit

Permalink
plugin loading
Browse files Browse the repository at this point in the history
  • Loading branch information
olir committed Mar 30, 2018
1 parent 29703d3 commit f577c6a
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,11 @@ private SegmentVideoFilter loadExternalFilterInstance(String filterClassName, St
URLClassLoader childLoader = getLoader(ref);
Class filterClass = Class.forName(filterClassName, true, childLoader);
SegmentVideoFilter filter = (SegmentVideoFilter) filterClass.newInstance();
Method filterInitMethod = filterClass.getMethod("init");
filterInitMethod.invoke(filter);
// Method filterInitMethod = filterClass.getMethod("init");
// filterInitMethod.invoke(filter);
return filter;
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException
| SecurityException | IllegalArgumentException | InvocationTargetException | MalformedURLException e) {
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | MalformedURLException
| SecurityException | IllegalArgumentException /* | InvocationTargetException | NoSuchMethodException */ e) {
throw new RuntimeException(
"Failed loading filter " + filterClassName + " from " + ref,
e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ public abstract class NativeFilter {
private static UnsatisfiedLinkError error = null;
private static final Set<String> loadedLibraries = Collections.synchronizedSet(new HashSet<String>());

public static void loadLibrary(Class invokerClass) throws UnsatisfiedLinkError {
public static void prepareLoadLibrary(NativeFilter invoker) throws UnsatisfiedLinkError {
if (!loaderCalled) {
loaderCalled = true;
System.out.println("Working Directory = " + new File(".").getAbsolutePath());
try {
if (System.getProperty("os.arch").contains("64")
&& System.getProperty("sun.arch.data.model").contains("64")) {
// load 64-bit lib
loadLibrary(invokerClass, "jniplugin-64");
prepareLoadLibrary(invoker, "jniplugin-64");
} else {
// load 32-bit lib
loadLibrary(invokerClass, "jniplugin-32");
prepareLoadLibrary(invoker, "jniplugin-32");
}
} catch (UnsatisfiedLinkError t) {
System.out.println("sun.arch.data.model=" + System.getProperty("sun.arch.data.model"));
Expand All @@ -41,14 +41,14 @@ public static void loadLibrary(Class invokerClass) throws UnsatisfiedLinkError {
}
}

private static void loadLibrary(Class invokerClass, String libraryName) throws UnsatisfiedLinkError {
private static void prepareLoadLibrary(NativeFilter invoker, String libraryName) throws UnsatisfiedLinkError {
synchronized (loadedLibraries) {

if (loadedLibraries.contains(libraryName.intern()))
return;

try {
System.loadLibrary(libraryName);
invoker.loadLibrary(libraryName);
} catch (final UnsatisfiedLinkError e) {
if (!String.format("no %s in java.library.path", libraryName).equals(e.getMessage())) {
System.out.println(
Expand All @@ -58,7 +58,7 @@ private static void loadLibrary(Class invokerClass, String libraryName) throws U

String libFileName = libraryName + ".dll";
String location = "/" + libFileName;
InputStream binary = invokerClass.getResourceAsStream("/" + libFileName);
InputStream binary = invoker.getClass().getResourceAsStream("/" + libFileName);
if (binary == null)
throw new Error("binary not found: " + "/" + libFileName);

Expand Down Expand Up @@ -90,8 +90,7 @@ private static void loadLibrary(Class invokerClass, String libraryName) throws U
}

try {
//System.load(destination.normalize().toString());
System.loadLibrary(libraryName);
invoker.loadLibrary(libraryName);
} catch (UnsatisfiedLinkError x) {
System.out.println("!!! [1] UnsatisfiedLinkError: "+e.getMessage()+". But found binary in classpath -> Relocated to "+destination);
System.out.println(
Expand All @@ -109,7 +108,8 @@ private static void loadLibrary(Class invokerClass, String libraryName) throws U
}

protected NativeFilter() throws UnsatisfiedLinkError {
loadLibrary(this.getClass());
prepareLoadLibrary(this);
}

protected abstract void loadLibrary(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ public class MatBlender extends NativeFilter {
public MatBlender() throws UnsatisfiedLinkError {
}

protected void loadLibrary(String name) {
System.loadLibrary(name);
}

public native void init();
public native void process(Object mat, int frameId, Object context, Object overlay);
}
20 changes: 0 additions & 20 deletions plugin-opencv/java/src/main/java/cc0/JniTest.java

This file was deleted.

121 changes: 0 additions & 121 deletions plugin-opencv/java/src/main/java/cc0/cc0_package_legalcode.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
public class ExternalSample extends NativeFilter {
public ExternalSample() throws UnsatisfiedLinkError {
}


protected void loadLibrary(String name) {
System.loadLibrary(name);
}

public native void init();
public native void process(Object mat, int frameId, Object context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
public class NativeExample extends NativeFilter {
public NativeExample() throws UnsatisfiedLinkError {
}


protected void loadLibrary(String name) {
System.loadLibrary(name);
}

public native void init();
public native void process(Object mat, int frameId, Object context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ public class VideoEqualizer extends NativeFilter {
public VideoEqualizer() throws UnsatisfiedLinkError {
}

protected void loadLibrary(String name) {
System.loadLibrary(name);
}

public native void init();
public native void process(Object mat, int frameId, Object context, int brightness, int contrast, int saturation);
}
10 changes: 0 additions & 10 deletions plugin-opencv/native/src/main/native/jni_test.c

This file was deleted.

23 changes: 0 additions & 23 deletions plugin-opencv/native/src/main/native/jni_test.cpp

This file was deleted.

1 change: 0 additions & 1 deletion plugin-opencv/native/win32/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
<workingDirectory>${basedir}</workingDirectory>
<javahOutputFileName>nativeCode.h</javahOutputFileName>
<javahClassNames>
<javahClassName>cc0.JniTest</javahClassName>
<javahClassName>de.serviceflow.frankenstein.plugin.opencv.jni.NativeExample</javahClassName>
<javahClassName>de.serviceflow.frankenstein.plugin.opencv.jni.VideoEqualizer</javahClassName>
<javahClassName>de.serviceflow.frankenstein.plugin.opencv.jni.ExternalSample</javahClassName>
Expand Down
1 change: 0 additions & 1 deletion plugin-opencv/native/win64/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
<workingDirectory>${basedir}</workingDirectory>
<javahOutputFileName>nativeCode.h</javahOutputFileName>
<javahClassNames>
<javahClassName>cc0.JniTest</javahClassName>
<javahClassName>de.serviceflow.frankenstein.plugin.opencv.jni.NativeExample</javahClassName>
<javahClassName>de.serviceflow.frankenstein.plugin.opencv.jni.VideoEqualizer</javahClassName>
<javahClassName>de.serviceflow.frankenstein.plugin.opencv.jni.ExternalSample</javahClassName>
Expand Down

0 comments on commit f577c6a

Please sign in to comment.