Files
baji-vc/tests/avatar/FullActionGraphCheck.kt

78 lines
6.3 KiB
Kotlin

import com.gorios.lanvoice.avatar.*
/** Expected five bodies/eight TALK bridges/two dances, synthetic metadata only. */
@Suppress("UNCHECKED_CAST")
fun fullActionGraphCheck() {
for((width,height) in listOf(480 to 848,720 to 1280)) {
val pin="b".repeat(64)
val bodies=listOf("neutral","happy","sad","idle-breathe","idle-shift").associateWith { id->
val sha=java.security.MessageDigest.getInstance("SHA-256").digest(id.toByteArray()).joinToString("") { "%02x".format(it) }
dynamicPack(if(id=="sad") 49 else 97,24,sha,width,height)
}
fun clip(pack: ContinuousAvatarPack,path: String,audio: Boolean=false)=mapOf<String,Any?>(
"path" to path,"sha256" to pack.body.sha256,"width" to pack.body.width,"height" to pack.body.height,"hasAudio" to audio,
"frameCount" to pack.body.frameCount,"ptsUs" to pack.body.ptsUs,"durationUs" to pack.body.durationUs,
"fpsNumerator" to pack.body.fpsNumerator,"fpsDenominator" to pack.body.fpsDenominator)
val rows=bodies.map { (id,body)->mapOf<String,Any?>("id" to id,
"emotion" to if(id.startsWith("idle")) "neutral" else id,"visualIntensity" to if(id in setOf("happy","sad")) 1 else 0,
"mouthBodySha256" to body.body.sha256,"runtimeManifest" to mapOf("path" to "$id/manifest.json","sha256" to body.manifestSha),
"entryAnchor" to "A","exitAnchor" to "A","legalExitFrames" to if(id=="neutral") listOf(0,96) else listOf(body.body.frameCount-1),"loopEdge" to "$id-loop") }
val mouths=linkedMapOf<String,ContinuousAvatarPack>()
val loops=bodies.map { (id,body)->mapOf<String,Any?>("id" to "$id-loop","from" to id,"to" to id,
"fromFrame" to body.body.frameCount-1,"fromPtsUs" to body.body.ptsUs.last(),"toFrame" to 0,"toPtsUs" to 0L,
"fromAnchor" to "A","toAnchor" to "A","nativeLoop" to true,"clip" to clip(body,"$id/body.mp4")) }
val bridges=bodies.keys.filter { it!="neutral" }.flatMap { id->listOf("neutral" to id,id to "neutral").map { (from,to)->
val name="$from-$to";val sha=java.security.MessageDigest.getInstance("SHA-256").digest(name.toByteArray()).joinToString("") { "%02x".format(it) }
val own=dynamicPack(25,24,sha,width,height);mouths[name]=own
mapOf<String,Any?>("id" to name,"from" to from,"to" to to,"fromFrame" to bodies.getValue(from).body.frameCount-1,
"fromPtsUs" to bodies.getValue(from).body.ptsUs.last(),"toFrame" to 0,"toPtsUs" to 0L,"fromAnchor" to "A","toAnchor" to "A",
"mouthAllowed" to true,"mouthRuntimeManifest" to mapOf("path" to "$name/manifest.json","sha256" to own.manifestSha),
"clip" to clip(own,"$name/body.mp4"))
} }
val dance=dynamicPack(241,24,"f".repeat(64),width,height)
val actions=listOf("asset_01","asset_02").map { id->mapOf<String,Any?>("id" to id,"kind" to "dance",
"mouthAllowed" to false,"disallowTALK" to true,"entryAnchor" to "A","returnAnchor" to "A",
"sourcePackageId" to "neutral","sourceFrame" to 0,"sourcePtsUs" to 0L,
"returnPackageId" to "neutral","returnFrame" to 96,"returnPtsUs" to 4_000_000L,
"clip" to clip(dance,"$id.mp4",true),"audioEndUs" to 10_000_000L) }
val root=mapOf<String,Any?>("schemaVersion" to 2,"identityId" to "a01","packId" to "a01-expression-action-v1",
"fallbackPackageId" to "neutral","conversationPackages" to rows,"edges" to loops+bridges,"actions" to actions)
fun read(meta: Map<String,Any?> = root,bodyData: Map<String,ContinuousAvatarPack> = bodies,
bridgeData: Map<String,ContinuousAvatarPack> = mouths)=EmotionActionManifest.read(meta,pin,pin) { path,hash->
(bodyData[path.substringBefore('/')] ?: bridgeData[path.substringBefore('/')])?.takeIf { it.manifestSha==hash }
}
val index=checkNotNull(read());var assertions=0
check(index.packages.size==5 && index.edges.size==13 && index.edges.count { it.mouthRuntime!=null }==8);assertions++
check(index.actionPack?.assets?.size==2 && index.actionPack.assets.all { it.media?.ptsUs?.size==241 });assertions++
val bytes=index.packages.values.sumOf { it.rgbaBytes }+index.edges.mapNotNull { it.mouthRuntime }.sumOf { it.rgbaBytes }
check(bytes==bodies.values.sumOf { it.rgbaBytes }+mouths.values.sumOf { it.rgbaBytes } && bytes<=BodyTimeline.MAX_PACK_CACHE_BYTES);assertions++
for(change in listOf(mapOf("sourceFrame" to 95),mapOf("sourcePtsUs" to 1L),mapOf("returnPtsUs" to 1L),
mapOf("sourcePackageId" to "idle-breathe"),mapOf("returnPackageId" to "idle-shift"))) {
check(read(root+("actions" to listOf(actions[0]+change,actions[1])))==null);assertions++
}
for(name in mouths.keys) {
val wrong=mouths.getValue(name).copy(body=mouths.getValue(name).body.copy(sha256=bodies.getValue("neutral").body.sha256))
check(read(bridgeData=mouths+(name to wrong))==null);assertions++
}
check(index.packages.values.all { it.body.width==width && it.body.height==height } &&
index.edges.all { it.clip.width==width && it.clip.height==height } &&
index.actionPack!!.assets.all { it.media!!.width==width && it.media.height==height });assertions++
val otherWidth=if(width==480) 720 else 480;val otherHeight=if(height==848) 1280 else 848
val wrongShape=bodies.getValue("happy").let { it.copy(body=it.body.copy(width=otherWidth,height=otherHeight)) }
check(read(bodyData=bodies+("happy" to wrongShape))==null);assertions++
for(i in (loops+bridges).indices) {
val changed=(loops+bridges).mapIndexed { j,e -> if(j==i) e+("clip" to (e["clip"] as Map<String,Any?>)+
mapOf("width" to otherWidth,"height" to otherHeight)) else e }
check(read(root+("edges" to changed))==null);assertions++
}
for(i in actions.indices) {
val changed=actions.mapIndexed { j,a -> if(j==i) a+("clip" to (a["clip"] as Map<String,Any?>)+
mapOf("width" to otherWidth,"height" to otherHeight)) else a }
check(read(root+("actions" to changed))==null);assertions++
}
val inflated=bodies.mapValues { (_,body)->body.copy(patches=body.patches.map { it.copy(width=80,height=44) }) }
check(inflated.values.all { it.rgbaBytes<=BodyTimeline.MAX_RGBA_BYTES } && read(bodyData=inflated)==null);assertions++
println("PASS: $assertions ${width}x$height full5-body/13-edge/8-own-bridge/two241-frame-action parser assertions; RGBA=$bytes bytes, source0/return96/4s binding and total-cache rejection; fixtures only")
}
}