private boolean mHasTeardownFunction = false;
private boolean mHasSetValueFunction = false;
private boolean mHasGetValueFunction = false;
+ private boolean mHasResetFunction = false;
private boolean mTornDown = false;
public NativeProgram(String nativeLibName, String nativeFunctionPrefix) {
String getValueFuncName = nativeFunctionPrefix + "_getvalue";
mHasGetValueFunction = bindGetValueFunction(getValueFuncName);
+ String resetFuncName = nativeFunctionPrefix + "_reset";
+ mHasResetFunction = bindResetFunction(resetFuncName);
+
// Initialize the native code
if (mHasInitFunction && !callNativeInit()) {
throw new RuntimeException("Could not initialize NativeProgram!");
}
}
- public void tearDown() {
+ public void tearDown() {
if (mTornDown) return;
if (mHasTeardownFunction && !callNativeTeardown()) {
throw new RuntimeException("Could not tear down NativeProgram!");
}
@Override
+ public void reset() {
+ if (mHasResetFunction && !callNativeReset()) {
+ throw new RuntimeException("Could not reset NativeProgram!");
+ }
+ }
+
+ @Override
protected void finalize() throws Throwable {
tearDown();
}
private native boolean bindSetValueFunction(String funcName);
private native boolean bindGetValueFunction(String funcName);
private native boolean bindProcessFunction(String funcName);
+ private native boolean bindResetFunction(String funcName);
private native boolean bindTeardownFunction(String funcName);
private native boolean callNativeInit();
private native boolean callNativeSetValue(String key, String value);
private native String callNativeGetValue(String key);
private native boolean callNativeProcess(NativeFrame[] inputs, NativeFrame output);
+ private native boolean callNativeReset();
private native boolean callNativeTeardown();
}
public abstract void setHostValue(String variableName, Object value);
public abstract Object getHostValue(String variableName);
+
+ public void reset() {
+ }
}
return ToJBool(program && func_name && program->BindProcessFunction(ToCppString(env, func_name)));
}
+jboolean Java_android_filterfw_core_NativeProgram_bindResetFunction(JNIEnv* env,
+ jobject thiz,
+ jstring func_name) {
+ NativeProgram* program = ConvertFromJava<NativeProgram>(env, thiz);
+ return ToJBool(program &&
+ func_name &&
+ program->BindResetFunction(ToCppString(env, func_name)));
+}
+
jboolean Java_android_filterfw_core_NativeProgram_bindTeardownFunction(JNIEnv* env,
jobject thiz,
jstring func_name) {
return ToJBool(program->CallProcess(input_buffers, input_sizes, output_data, output_size));
}
+jboolean Java_android_filterfw_core_NativeProgram_callNativeReset(JNIEnv* env, jobject thiz) {
+ NativeProgram* program = ConvertFromJava<NativeProgram>(env, thiz);
+ return ToJBool(program && program->CallReset());
+}
+
jboolean Java_android_filterfw_core_NativeProgram_callNativeTeardown(JNIEnv* env, jobject thiz) {
NativeProgram* program = ConvertFromJava<NativeProgram>(env, thiz);
return ToJBool(program && program->CallTeardown());
jstring func_name);
JNIEXPORT jboolean JNICALL
+Java_android_filterfw_core_NativeProgram_bindResetFunction(JNIEnv* env,
+ jobject thiz,
+ jstring func_name);
+
+JNIEXPORT jboolean JNICALL
Java_android_filterfw_core_NativeProgram_bindTeardownFunction(JNIEnv* env,
jobject thiz,
jstring func_name);
jobject output);
JNIEXPORT jboolean JNICALL
+Java_android_filterfw_core_NativeProgram_callNativeReset(JNIEnv* env, jobject thiz);
+
+JNIEXPORT jboolean JNICALL
Java_android_filterfw_core_NativeProgram_callNativeTeardown(JNIEnv* env, jobject thiz);
#ifdef __cplusplus
setvalue_function_(NULL),
getvalue_function_(NULL),
process_function_(NULL),
+ reset_function_(NULL),
teardown_function_(NULL),
user_data_(NULL) {
}
return getvalue_function_ != NULL;
}
+bool NativeProgram::BindResetFunction(const std::string& func_name) {
+ if (!lib_handle_)
+ return false;
+ reset_function_ = reinterpret_cast<ResetFunctionPtr>(dlsym(lib_handle_, func_name.c_str()));
+ return reset_function_ != NULL;
+}
+
bool NativeProgram::BindTeardownFunction(const std::string& func_name) {
if (!lib_handle_)
return false;
return std::string();
}
+bool NativeProgram::CallReset() {
+ if (reset_function_) {
+ reset_function_(user_data_);
+ return true;
+ }
+ return false;
+}
+
bool NativeProgram::CallTeardown() {
if (teardown_function_) {
teardown_function_(user_data_);
typedef void (*SetValueFunctionPtr)(const char*, const char*, void*);
typedef void (*GetValueFunctionPtr)(const char*, char*, int, void*);
typedef int (*ProcessFunctionPtr)(const char**, const int*, int, char*, int, void*);
+typedef void (*ResetFunctionPtr)(void*);
typedef void (*TeardownFunctionPtr)(void*);
class NativeProgram {
bool BindSetValueFunction(const std::string& func_name);
bool BindGetValueFunction(const std::string& func_name);
bool BindProcessFunction(const std::string& func_name);
+ bool BindResetFunction(const std::string& func_name);
bool BindTeardownFunction(const std::string& func_name);
bool CallInit();
const std::vector<int>& input_sizes,
char* output,
int output_size);
+ bool CallReset();
bool CallTeardown();
private:
SetValueFunctionPtr setvalue_function_;
GetValueFunctionPtr getvalue_function_;
ProcessFunctionPtr process_function_;
+ ResetFunctionPtr reset_function_;
TeardownFunctionPtr teardown_function_;
// Pointer to user data