diff --git a/externals/nnstreamer b/externals/nnstreamer
index 0ab11fd..81a95ee 160000
--- a/externals/nnstreamer
+++ b/externals/nnstreamer
@@ -1 +1 @@
-Subproject commit 0ab11fdbcf2c0a40937f30978b6bc42736a094ab
+Subproject commit 81a95ee4555e698ece334c5edb014eac7a4fe806
diff --git a/ml_inference_offloading/src/main/AndroidManifest.xml b/ml_inference_offloading/src/main/AndroidManifest.xml
index c572016..e334201 100644
--- a/ml_inference_offloading/src/main/AndroidManifest.xml
+++ b/ml_inference_offloading/src/main/AndroidManifest.xml
@@ -4,6 +4,8 @@
+
+
? = null
+
+ try {
+ files = am.list("models/")
+ } catch (e: java.lang.Exception) {
+ Log.e(TAG, "#### Failed to get asset file list")
+ e.printStackTrace()
+ return
+ }
+
+ // Copy files into app-specific directory.
+ for (filename in files!!) {
+ try {
+ val inFile = am.open("models/$filename")
+ val outDir = getExternalFilesDir(null)!!.absolutePath
+ val outFile = File(outDir, filename)
+ val out: OutputStream = FileOutputStream(outFile)
+
+ val buffer = ByteArray(1024)
+ var read: Int
+ while ((inFile.read(buffer).also { read = it }) != -1) {
+ out.write(buffer, 0, read)
+ }
+
+ inFile.close()
+ out.flush()
+ out.close()
+ } catch (e: IOException) {
+ Log.e(TAG, "Failed to copy file: $filename")
+ e.printStackTrace()
+ return
+ }
+ }
+ }
+
private fun initNNStreamer() {
if (this.initialized) {
return
@@ -135,11 +189,55 @@ class MainService : Service() {
}
}
+ private fun isPortAvailable(port: Int): Boolean {
+ var result = false
+ if (port < 0) {
+ return result
+ }
+
+ val portChecker = thread() {
+ try {
+ val serverSocket = ServerSocket(port)
+ serverSocket.close()
+ result = true
+ } catch (e: Exception) {
+ Log.e(TAG, e.toString())
+ }
+ }
+ portChecker.join()
+ return result
+ }
+
+ private fun findPort(): Int {
+ var port = -1
+ val portFinder = thread() {
+ try {
+ val serverSocket = ServerSocket(0)
+ Log.i(TAG, "listening on port: " + serverSocket.localPort)
+ port = serverSocket.localPort
+ serverSocket.close()
+ } catch (e: Exception) {
+ Log.e(TAG, e.toString())
+ }
+ }
+ portFinder.join()
+ return port
+ }
+
fun startServer() {
- TODO("Not yet implemented")
+ if (!isPortAvailable(port)) {
+ port = findPort()
+ }
+
+ val desc = "tensor_query_serversrc host=" + HOST_ADDR + " port=" + port.toString() + " ! " +
+ "other/tensor,format=static,dimension=(string)3:224:224:1,type=uint8,framerate=0/1 ! " +
+ "tensor_filter framework=tensorflow-lite model=" + model.getAbsolutePath() + " ! " +
+ "other/tensor,format=static,dimension=(string)1001:1,type=uint8,framerate=0/1 ! tensor_query_serversink async=false"
+ tensorQueryServer = Pipeline(desc, null)
+ tensorQueryServer.start()
}
fun stopServer() {
- TODO("Not yet implemented")
+ tensorQueryServer.close()
}
}