xuning

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

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