xuning

启用ncnn提示成功并有新的问题

@@ -9,7 +9,7 @@ android { @@ -9,7 +9,7 @@ android {
9 9
10 defaultConfig { 10 defaultConfig {
11 applicationId "io.livekit.android.selfie" 11 applicationId "io.livekit.android.selfie"
12 - minSdk androidSdk.minVersion 12 + minSdk 24
13 targetSdk androidSdk.targetVersion 13 targetSdk androidSdk.targetVersion
14 versionCode 1 14 versionCode 1
15 versionName "1.0" 15 versionName "1.0"
@@ -42,22 +42,14 @@ import livekit.org.webrtc.EglBase @@ -42,22 +42,14 @@ import livekit.org.webrtc.EglBase
42 42
43 @OptIn(ExperimentalCamera2Interop::class) 43 @OptIn(ExperimentalCamera2Interop::class)
44 class MainViewModel(application: Application) : AndroidViewModel(application) { 44 class MainViewModel(application: Application) : AndroidViewModel(application) {
45 - 45 + val eglBase = EglBase.create()
  46 + private val processor = RVMNcnn(eglBase)
46 init { 47 init {
47 LiveKit.loggingLevel = LoggingLevel.INFO 48 LiveKit.loggingLevel = LoggingLevel.INFO
48 - // 加载 RVM 模型:mobilenetv3,目标尺寸640(sizeid=6),intra/inter=0,postproc=1(fast),CPU(cpugpu=0)  
49 - // 如需 GPU,可将 cpugpu=1 或 2(使用 turnip)  
50 - processor.loadModel(  
51 - application.getAssets(),  
52 - /* modelid */ 0,  
53 - /* sizeid */ 6,  
54 - /* intrainterid */ 0,  
55 - /* postprocid */ 1,  
56 - /* cpugpu */ 0  
57 - ) 49 +
58 } 50 }
59 51
60 - val eglBase = EglBase.create() 52 +
61 val room = LiveKit.create( 53 val room = LiveKit.create(
62 application, 54 application,
63 overrides = LiveKitOverrides( 55 overrides = LiveKitOverrides(
@@ -68,7 +60,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) { @@ -68,7 +60,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
68 private val virtualBackground = (AppCompatResources.getDrawable(application, R.drawable.background) as BitmapDrawable).bitmap 60 private val virtualBackground = (AppCompatResources.getDrawable(application, R.drawable.background) as BitmapDrawable).bitmap
69 61
70 private var blur = 16f 62 private var blur = 16f
71 - private val processor = RVMNcnn(eglBase) 63 +
72 64
73 private var cameraProvider: CameraCapturerUtils.CameraProvider? = null 65 private var cameraProvider: CameraCapturerUtils.CameraProvider? = null
74 66
@@ -10,11 +10,16 @@ android { @@ -10,11 +10,16 @@ android {
10 compileSdkVersion androidSdk.compileVersion 10 compileSdkVersion androidSdk.compileVersion
11 11
12 defaultConfig { 12 defaultConfig {
13 - minSdkVersion androidSdk.minVersion 13 + minSdkVersion 24
14 targetSdkVersion androidSdk.targetVersion 14 targetSdkVersion androidSdk.targetVersion
15 15
16 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 16 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 consumerProguardFiles "consumer-rules.pro" 17 consumerProguardFiles "consumer-rules.pro"
  18 +
  19 + ndk {
  20 + abiFilters 'arm64-v8a', 'x86_64'
  21 + // 如需兼容其它 ABI,可同时添加:'armeabi-v7a', 'x86', 'x86_64'
  22 + }
18 } 23 }
19 24
20 buildTypes { 25 buildTypes {
@@ -36,6 +41,12 @@ android { @@ -36,6 +41,12 @@ android {
36 includeAndroidResources = true 41 includeAndroidResources = true
37 } 42 }
38 } 43 }
  44 +
  45 + externalNativeBuild {
  46 + cmake {
  47 + path file('src/main/jni/CMakeLists.txt')
  48 + }
  49 + }
39 } 50 }
40 51
41 dokkaHtml { 52 dokkaHtml {
@@ -23,9 +23,15 @@ public class RVMNcnn extends NoDropVideoProcessor { @@ -23,9 +23,15 @@ public class RVMNcnn extends NoDropVideoProcessor {
23 public native boolean closeCamera(); 23 public native boolean closeCamera();
24 public native boolean setOutputWindow(Surface surface); 24 public native boolean setOutputWindow(Surface surface);
25 public native boolean setBackgroundImage(Bitmap bitmap); 25 public native boolean setBackgroundImage(Bitmap bitmap);
  26 + public native boolean processFrame();
26 27
27 static { 28 static {
  29 + try {
28 System.loadLibrary("rvmncnn"); 30 System.loadLibrary("rvmncnn");
  31 + android.util.Log.d("RVMNcnn", "System.loadLibrary(rvmncnn) success");
  32 + } catch (Throwable t) {
  33 + android.util.Log.e("RVMNcnn", "System.loadLibrary(rvmncnn) failed", t);
  34 + }
29 } 35 }
30 36
31 private final EglBase eglBase; 37 private final EglBase eglBase;
@@ -55,6 +61,8 @@ public class RVMNcnn extends NoDropVideoProcessor { @@ -55,6 +61,8 @@ public class RVMNcnn extends NoDropVideoProcessor {
55 @Override 61 @Override
56 public void onCapturerStarted(boolean started) { 62 public void onCapturerStarted(boolean started) {
57 if (started) { 63 if (started) {
  64 + surfaceTextureHelper.setTextureSize(640, 640);
  65 + android.util.Log.d("RVMNcnn", "onCapturerStarted: setOutputWindow + openCamera");
58 // Listen to frames produced from the output surface (rendered by native), 66 // Listen to frames produced from the output surface (rendered by native),
59 // and forward to target sink. 67 // and forward to target sink.
60 surfaceTextureHelper.stopListening(); 68 surfaceTextureHelper.stopListening();