feat: add neutral avatar video call MVP in Android 0.6.0

This commit is contained in:
zenord
2026-10-12 15:12:57 +08:00
parent 4d305ad0df
commit fdd91234b5
39 changed files with 1325 additions and 184 deletions
+64
View File
@@ -0,0 +1,64 @@
import com.gorios.lanvoice.avatar.*
import com.gorios.lanvoice.audio.PlaybackActivity
import com.gorios.lanvoice.dialogue.*
import android.content.Context
import android.media.MediaPlayer
import android.view.TextureView
fun main() {
val controller = AvatarController()
for (emotion in RoleEmotion.entries) for (intensity in if (emotion == RoleEmotion.NEUTRAL) listOf(0) else listOf(1,2)) {
val request = ReplyEmotion(emotion, intensity, EmotionSource.MODEL,7L,2)
val selected = controller.select(true,request,PlaybackActivity(7,3,true,960,1920))
check(selected.mode == AvatarMode.TALK && selected.requestedEmotion == request)
check(selected.resolvedAssetEmotion == AssetEmotion())
check(selected.emotionFallback == (emotion != RoleEmotion.NEUTRAL))
check(controller.select(false,request,PlaybackActivity(7,3,true,960,1920)).mode == AvatarMode.WAITING)
check(controller.select(true,request,PlaybackActivity(6,2,true,960,1920)).mode == AvatarMode.IDLE)
check(controller.select(true,request,null).mode == AvatarMode.IDLE)
}
val call = CallIntent()
check(!call.consumeStart(true,true,true))
check(call.dial(false,false) && !call.dial(false,false))
check(!call.consumeStart(true,true,false))
call.background(); check(call.pending)
call.cancel(); call.permissionResult(true)
check(!call.consumeStart(true,true,true)) // canceled permission cannot resurrect a call
check(call.dial(false,false)); call.permissionResult(false); check(!call.pending)
check(call.dial(false,true)); check(!call.consumeStart(true,false,true))
check(!call.consumeStart(false,true,true)); check(call.consumeStart(true,true,true))
check(!call.consumeStart(true,true,true))
call.resumeAfterCameraPermission(true); call.background(true)
check(call.consumeStart(true,true,true))
check(call.dial(false,true)); call.background(); check(!call.pending)
val view = AvatarVideoView(Context(),AvatarPack("idle.mp4","talk.mp4","static.png","waiting.png"))
view.render(AvatarMode.IDLE,true)
check(MediaPlayer.created.size == 2)
val players = MediaPlayer.created.toList()
check(players.all { it.looping && it.volume == 0f })
val textures = view.children.filterIsInstance<TextureView>()
players.forEach { it.prepared?.invoke(it) }
players[0].info?.invoke(players[0],MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START,0)
view.render(AvatarMode.TALK,true)
check(textures.all { it.alpha == 0f }) // first-frame gate, static stays visible
players[1].info?.invoke(players[1],MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START,0)
check(textures[1].alpha == 1f && textures[0].alpha == 0f)
repeat(10) { view.render(if (it%2==0) AvatarMode.IDLE else AvatarMode.TALK,true) }
check(MediaPlayer.created.size == 2) // switches don't recreate or seek players
view.render(AvatarMode.WAITING,true)
check(players.all { it.released } && textures.all { it.alpha == 0f })
view.render(AvatarMode.IDLE,true)
check(MediaPlayer.created.size == 4)
players[1].info?.invoke(players[1],MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START,0)
check(textures.all { it.alpha == 0f }) // stale callbacks can't show old talk
val latest = MediaPlayer.created.takeLast(2)
latest[0].error?.invoke(latest[0],1,0)
check(latest.all { it.released } && textures.all { it.alpha == 0f })
view.render(AvatarMode.TALK,true); check(MediaPlayer.created.size == 4) // fail to static for the current run
view.render(AvatarMode.IDLE,false); view.render(AvatarMode.IDLE,true)
check(MediaPlayer.created.size == 6)
view.dispose(); check(MediaPlayer.created.all { it.released })
AvatarVideoView(Context(),null).render(AvatarMode.TALK,true)
println("PASS: seven requested labels preserved/neutral resolved fallback, old-turn fence; explicit dial/permission/cancel/background; actual video view two muted loops/first-frame gate/switch reuse/stale callback/failure/static/missing pack/lifecycle")
}
+2
View File
@@ -0,0 +1,2 @@
package android.os
object SystemClock { fun elapsedRealtime() = System.nanoTime()/1000000 }
+10
View File
@@ -0,0 +1,10 @@
package android.content
class Context { val assets = Assets() }
class Assets {
fun open(path: String) = java.io.ByteArrayInputStream(byteArrayOf())
fun openFd(path: String) = Descriptor()
}
class Descriptor : java.io.Closeable {
val fileDescriptor = java.io.FileDescriptor(); val startOffset = 0L; val length = 20L
override fun close() {}
}
+2
View File
@@ -0,0 +1,2 @@
package com.gorios.lanvoice.diag
object DiagnosticLog { fun record(tag: String,msg: String) {} }
+4
View File
@@ -0,0 +1,4 @@
package android.graphics
class Matrix { fun setScale(x: Float,y: Float,px: Float,py: Float) {} }
class SurfaceTexture
object BitmapFactory { fun decodeStream(input: java.io.InputStream): Any? = Any() }
+21
View File
@@ -0,0 +1,21 @@
package android.media
import android.view.Surface
class MediaPlayer {
companion object { const val MEDIA_INFO_VIDEO_RENDERING_START = 3; val created = mutableListOf<MediaPlayer>() }
init { created.add(this) }
var prepared: ((MediaPlayer)->Unit)? = null
var info: ((MediaPlayer,Int,Int)->Boolean)? = null
var error: ((MediaPlayer,Int,Int)->Boolean)? = null
var isLooping = false; val looping get() = isLooping
var volume = 1f; var released = false; var started = false
val videoWidth = 480; val videoHeight = 848
fun setSurface(surface: Surface) {}
fun setVolume(left: Float,right: Float) { volume = left }
fun setDataSource(fd: java.io.FileDescriptor, offset: Long,length: Long) {}
fun setOnPreparedListener(callback: (MediaPlayer)->Unit) { prepared = callback }
fun setOnInfoListener(callback: (MediaPlayer,Int,Int)->Boolean) { info = callback }
fun setOnErrorListener(callback: (MediaPlayer,Int,Int)->Boolean) { error = callback }
fun prepareAsync() {}
fun start() { started = true }
fun release() { released = true }
}
+3
View File
@@ -0,0 +1,3 @@
package com.gorios.lanvoice.avatar
// File loading is separately verified against imported APK bytes; no Android assets here.
data class AvatarPack(val idle: String,val talk: String,val fallback: String,val waiting: String)
+18
View File
@@ -0,0 +1,18 @@
package android.view
import android.content.Context
import android.graphics.SurfaceTexture
import android.graphics.Matrix
class Surface(texture: SurfaceTexture) { fun release() {} }
class TextureView(context: Context) {
var alpha = 1f; var isOpaque = true
val isAvailable = true; val surfaceTexture = SurfaceTexture()
val width = 480; val height = 848
var surfaceTextureListener: SurfaceTextureListener? = null
fun setTransform(matrix: Matrix) {}
interface SurfaceTextureListener {
fun onSurfaceTextureAvailable(texture: SurfaceTexture,w: Int,h: Int)
fun onSurfaceTextureSizeChanged(texture: SurfaceTexture,w: Int,h: Int)
fun onSurfaceTextureUpdated(texture: SurfaceTexture)
fun onSurfaceTextureDestroyed(texture: SurfaceTexture): Boolean
}
}
+14
View File
@@ -0,0 +1,14 @@
package android.widget
import android.content.Context
open class FrameLayout(val context: Context) {
class LayoutParams(w: Int,h: Int)
val children = mutableListOf<Any>()
fun addView(view: Any, params: LayoutParams) { children.add(view) }
open fun onDetachedFromWindow() {}
}
class ImageView(context: Context) {
enum class ScaleType { FIT_CENTER }
var scaleType = ScaleType.FIT_CENTER; var alpha = 1f
fun setImageBitmap(bitmap: Any?) {}
fun setImageDrawable(drawable: Any?) {}
}