-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
391 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
app/src/main/java/de/screenflow/frankenstein/vf/segment/NativeExampleConfigController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package de.screenflow.frankenstein.vf.segment; | ||
|
||
public class NativeExampleConfigController { | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
app/src/main/java/de/screenflow/frankenstein/vf/segment/NativeExampleFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2017 Oliver Rode, https://github.com/olir/Frankenstein | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package de.screenflow.frankenstein.vf.segment; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
|
||
import org.opencv.core.Mat; | ||
|
||
public class NativeExampleFilter extends NativeSegmentFilter<NativeExampleConfigController> { | ||
|
||
private final static String JNI_FILTER_CLASS = "cc0.NativeExample"; | ||
|
||
private final Class jniProxyClass; | ||
private final Object jniProxy; | ||
private final Method jniProxyInitMethod; | ||
private final Method jniProxyProcessMethod; | ||
|
||
@SuppressWarnings("unchecked") | ||
public NativeExampleFilter() throws UnsatisfiedLinkError { | ||
super("native"); | ||
try { | ||
// use reflection when classing jni proxy class from Jar, so app do not depend on it. | ||
jniProxyClass = Class.forName(JNI_FILTER_CLASS); | ||
jniProxy = jniProxyClass.newInstance(); | ||
jniProxyInitMethod = jniProxyClass.getMethod("init"); | ||
jniProxyProcessMethod = jniProxyClass.getMethod("process", Object.class, Integer.class); | ||
jniProxyInitMethod.invoke(jniProxy); | ||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | ||
| SecurityException | IllegalArgumentException | InvocationTargetException e) { | ||
throw new RuntimeException("jni wrapper creation failed", e); | ||
} | ||
} | ||
|
||
@Override | ||
public Mat process(Mat sourceFrame, int frameId) { | ||
try { | ||
jniProxyProcessMethod.invoke(jniProxy, sourceFrame, frameId); | ||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { | ||
e.printStackTrace(); | ||
} | ||
return sourceFrame; | ||
} | ||
|
||
@Override | ||
protected void initializeController() { | ||
// getConfigController(). ... | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
app/src/main/java/de/screenflow/frankenstein/vf/segment/NativeSegmentFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright 2017 Oliver Rode, https://github.com/olir/Frankenstein | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package de.screenflow.frankenstein.vf.segment; | ||
|
||
import java.io.IOException; | ||
import java.util.PropertyResourceBundle; | ||
import java.util.ResourceBundle; | ||
|
||
import org.opencv.core.Mat; | ||
|
||
import de.screenflow.frankenstein.fxml.FxMain; | ||
import de.screenflow.frankenstein.vf.SegmentVideoFilter; | ||
import javafx.fxml.FXMLLoader; | ||
import javafx.scene.Scene; | ||
|
||
public abstract class NativeSegmentFilter<C> implements SegmentVideoFilter { | ||
private C configController = null; | ||
|
||
private final String identifier; | ||
private final PropertyResourceBundle bundleConfiguration; | ||
|
||
protected NativeSegmentFilter(String identifier) { | ||
this.identifier = identifier; | ||
|
||
bundleConfiguration = (PropertyResourceBundle) ResourceBundle | ||
.getBundle(getClass().getPackage().getName().replace('.', '/') + '/' + identifier, FxMain.getLocale()); | ||
} | ||
|
||
public final String toString() { | ||
return bundleConfiguration.getString("name"); | ||
} | ||
|
||
@Override | ||
public final SegmentVideoFilter createInstance() { | ||
try { | ||
return getClass().newInstance(); | ||
} catch (InstantiationException | IllegalAccessException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public final Scene createConfigurationScene(String stylesheet) { | ||
FXMLLoader loader = new FXMLLoader(getClass().getResource(identifier + ".fxml"), bundleConfiguration); | ||
try { | ||
loader.load(); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to create configuration scene for video filter '" + this + "'", e); | ||
} | ||
Scene scene = new Scene(loader.getRoot()); | ||
scene.getStylesheets().add(stylesheet); | ||
configController = loader.getController(); | ||
initializeController(); // custom initialization possible here | ||
return scene; | ||
} | ||
|
||
abstract protected void initializeController(); | ||
|
||
protected final C getConfigController() { | ||
return configController; | ||
} | ||
|
||
@Override | ||
public final Mat configure(Mat firstFrame) { | ||
return firstFrame; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/resources/de/screenflow/frankenstein/vf/segment/native.fxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.geometry.*?> | ||
<?import javafx.scene.text.*?> | ||
<?import javafx.scene.control.*?> | ||
<?import java.lang.*?> | ||
<?import javafx.scene.image.*?> | ||
<?import javafx.scene.layout.*?> | ||
<?import javafx.scene.layout.BorderPane?> | ||
|
||
<BorderPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.screenflow.frankenstein.vf.segment.NativeExampleConfigController"> | ||
</BorderPane> |
1 change: 1 addition & 0 deletions
1
app/src/main/resources/de/screenflow/frankenstein/vf/segment/native.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
name=Native Example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package cc0; | ||
|
||
public class JniExample extends NativeFilter { | ||
public JniExample() throws UnsatisfiedLinkError { | ||
} | ||
|
||
public static void main(String[] args) { | ||
new JniExample().helloNative(); | ||
} | ||
|
||
public native void helloNative(); | ||
|
||
public void process(Object mat, int frameId) { | ||
// not used | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package cc0; | ||
|
||
public class NativeExample extends NativeFilter { | ||
public NativeExample() throws UnsatisfiedLinkError { | ||
} | ||
|
||
public native void init(); | ||
public native void process(Object mat, int frameId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package cc0; | ||
|
||
import java.io.File; | ||
|
||
public abstract class NativeFilter { | ||
private static boolean loaderCalled = false; | ||
private static UnsatisfiedLinkError error = null; | ||
|
||
protected NativeFilter() 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 | ||
System.loadLibrary("jniplugin-64"); | ||
} else { | ||
// load 32-bit lib | ||
System.loadLibrary("jniplugin-32"); | ||
} | ||
} catch (UnsatisfiedLinkError t) { | ||
System.out.println("sun.arch.data.model=" + System.getProperty("sun.arch.data.model")); | ||
System.out.println("os.arch=" + System.getProperty("os.arch")); | ||
|
||
error = t; | ||
throw t; | ||
} | ||
if (error != null) | ||
throw error; // throw again | ||
} | ||
|
||
} | ||
|
||
public abstract void process(Object mat, int frameId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef JWMAT_H | ||
#define JWMAT_H | ||
|
||
#include <jni.h> | ||
|
||
class JwMat // begin declaration of the class | ||
{ | ||
public: // begin public section | ||
JwMat(JNIEnv* env); // constructor | ||
~JwMat(); // destructor | ||
private: // begin private section | ||
JNIEnv * env; // member variable | ||
}; | ||
|
||
|
||
#endif |
Oops, something went wrong.