[Android] method to flush the pipeline
authorJaeyun <jy1210.jung@samsung.com>
Fri, 2 Apr 2021 11:39:25 +0000 (20:39 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Thu, 29 Apr 2021 09:46:06 +0000 (18:46 +0900)
NNStreamer Android lib, add new method to flush the pipeline.

Signed-off-by: Jaeyun <jy1210.jung@samsung.com>
java/android/nnstreamer/src/main/java/org/nnsuite/nnstreamer/Pipeline.java
java/android/nnstreamer/src/main/jni/nnstreamer-native-pipeline.c

index c69424c..4bc6a5d 100644 (file)
@@ -34,6 +34,7 @@ public final class Pipeline implements AutoCloseable {
     private native void nativeDestroy(long handle);
     private native boolean nativeStart(long handle);
     private native boolean nativeStop(long handle);
+    private native boolean nativeFlush(long handle, boolean start);
     private native int nativeGetState(long handle);
     private native boolean nativeInputData(long handle, String name, TensorsData data);
     private native String[] nativeGetSwitchPads(long handle, String name);
@@ -203,6 +204,23 @@ public final class Pipeline implements AutoCloseable {
     }
 
     /**
+     * Clears all data and resets the pipeline.
+     * During the flush operation, the pipeline is stopped and after the operation is done,
+     * the pipeline is resumed and ready to start the data flow.
+     *
+     * @param start The flag to start the pipeline after the flush operation is done
+     *
+     * @throws IllegalStateException if failed to flush the pipeline
+     */
+    public void flush(boolean start) {
+        checkPipelineHandle();
+
+        if (!nativeFlush(mHandle, start)) {
+            throw new IllegalStateException("Failed to flush the pipeline");
+        }
+    }
+
+    /**
      * Gets the state of pipeline.
      *
      * @return The state of pipeline
index a41e91a..f722575 100644 (file)
@@ -554,6 +554,28 @@ nns_native_pipe_stop (JNIEnv * env, jobject thiz, jlong handle)
 /**
  * @brief Native method for pipeline API.
  */
+static jboolean
+nns_native_pipe_flush (JNIEnv * env, jobject thiz, jlong handle, jboolean start)
+{
+  pipeline_info_s *pipe_info = NULL;
+  ml_pipeline_h pipe;
+  int status;
+
+  pipe_info = CAST_TO_TYPE (handle, pipeline_info_s *);
+  pipe = pipe_info->pipeline_handle;
+
+  status = ml_pipeline_flush (pipe, (start == JNI_TRUE));
+  if (status != ML_ERROR_NONE) {
+    nns_loge ("Failed to flush the pipeline.");
+    return JNI_FALSE;
+  }
+
+  return JNI_TRUE;
+}
+
+/**
+ * @brief Native method for pipeline API.
+ */
 static jint
 nns_native_pipe_get_state (JNIEnv * env, jobject thiz, jlong handle)
 {
@@ -913,6 +935,7 @@ static JNINativeMethod native_methods_pipeline[] = {
   {"nativeDestroy", "(J)V", (void *) nns_native_pipe_destroy},
   {"nativeStart", "(J)Z", (void *) nns_native_pipe_start},
   {"nativeStop", "(J)Z", (void *) nns_native_pipe_stop},
+  {"nativeFlush", "(JZ)Z", (void *) nns_native_pipe_flush},
   {"nativeGetState", "(J)I", (void *) nns_native_pipe_get_state},
   {"nativeInputData", "(JLjava/lang/String;L" NNS_CLS_TDATA ";)Z",
       (void *) nns_native_pipe_input_data},