feat: validate per-body mouth timelines and reviewed conversation routes
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
import com.gorios.lanvoice.avatar.*
|
||||
import com.gorios.lanvoice.dialogue.RoleEmotion
|
||||
import android.media.CodecFixture
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.SurfaceTexture
|
||||
import android.view.Surface
|
||||
import android.os.TestScheduler
|
||||
import android.opengl.GLFixture
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun dynamicRuntimeFixture(count: Int=121,fpsN: Int=30,fpsD: Int=1,sha: String="c".repeat(64)): Map<String,Any?> {
|
||||
val old=continuousFixture()
|
||||
val pts=List(count) { it*1_000_000L*fpsD/fpsN }
|
||||
val base=(old["patches"] as List<Map<String,Any?>>).first()
|
||||
val patches=pts.mapIndexed { i,t ->
|
||||
val levels=List(5) { l -> mapOf<String,Any?>("levelIndex" to l,"aperture" to l/4f,"path" to "patches/f$i-l$l.png","sha256" to sha) }
|
||||
base+mapOf("frameIndex" to i,"ptsUs" to t,"levels" to levels,"path" to levels[4]["path"],"sha256" to sha)
|
||||
}
|
||||
val states=(old["mouthStates"] as List<Map<String,Any?>>).map { state ->
|
||||
val n=(state["globalAlphaByFrame"] as List<*>).size
|
||||
state+("ptsUs" to List(n) { it*1_000_000L/24 })
|
||||
}
|
||||
return old+mapOf("schemaVersion" to 2,"packId" to "a01-expression-action-v1-test-runtime-04",
|
||||
"body" to (old["body"] as Map<String,Any?>)+mapOf("sha256" to sha,"frameCount" to count,
|
||||
"fpsNumerator" to fpsN,"fpsDenominator" to fpsD,"ptsUs" to pts,"durationUs" to (count*1_000_000L*fpsD+fpsN/2)/fpsN),
|
||||
"patches" to patches,"mouthStates" to states,"patchFormat" to mapOf("bodySha256" to sha,
|
||||
"format" to "PNG RGBA 8bit","alphaEncoding" to "straight_unassociated","apertureLevels" to listOf(0f,.25f,.5f,.75f,1f),"requiresRendererExtension" to true))
|
||||
}
|
||||
fun dynamicPack(count: Int,fps: Int,sha: String): ContinuousAvatarPack = checkNotNull(
|
||||
ContinuousAvatarManifest.read(dynamicRuntimeFixture(count,fps,1,sha),sha,sha,true,"dynamic/"))
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun dynamicBodyCheck() {
|
||||
var boundaries=0
|
||||
for((count,fpsN,fpsD) in listOf(Triple(121,30,1),Triple(49,24,1),Triple(61,30000,1001))) {
|
||||
val sha="c".repeat(64);val root=dynamicRuntimeFixture(count,fpsN,fpsD,sha)
|
||||
fun read(data: Map<String,Any?>)=ContinuousAvatarManifest.read(data,sha,sha,true,"fixture/")
|
||||
val pack=checkNotNull(read(root));check(pack.body.frameCount==count && pack.textureImages.size==count*5)
|
||||
val presenter=ContinuousFramePresenter(pack) { 0 }
|
||||
repeat(2) { loop ->
|
||||
for(i in 0 until count) {
|
||||
val pts=pack.body.ptsUs[i];presenter.decoded(pts)
|
||||
val frame=checkNotNull(presenter.present(pts*1000,loop*10000L+pts/1000) {})
|
||||
check(frame.key.index==i && frame.patch.ptsUs==pts && frame.key.loopOrdinal==loop.toLong())
|
||||
for(level in 0..4) {
|
||||
val s=selectMouthPatch(pack,i,level/4f)
|
||||
check(s.textureSlot==i*5+level && s.opacity==if(level==0) 0f else 1f)
|
||||
boundaries++
|
||||
}
|
||||
}
|
||||
presenter.wrap()
|
||||
}
|
||||
val body=root["body"] as Map<String,Any?>;val patches=root["patches"] as List<Map<String,Any?>>
|
||||
fun invalid(data: Map<String,Any?>) { check(read(data)==null);boundaries++ }
|
||||
invalid(root+("body" to body+("frameCount" to 97)))
|
||||
invalid(root+("body" to body+("durationUs" to 100_000_000L)))
|
||||
invalid(root+("body" to body+("fpsDenominator" to 0)))
|
||||
invalid(root+("body" to body+("ptsUs" to pack.body.ptsUs.dropLast(1))))
|
||||
invalid(root+("body" to body+("ptsUs" to listOf(1L)+pack.body.ptsUs.drop(1))))
|
||||
invalid(root+("patches" to listOf(patches[0]+("ptsUs" to 1L))+patches.drop(1)))
|
||||
invalid(root+("patches" to patches.dropLast(1)))
|
||||
invalid(root+("patches" to patches.map { it+mapOf("width" to 128,"height" to 128) }))
|
||||
invalid(root+("patchFormat" to (root["patchFormat"] as Map<String,Any?>)+("bodySha256" to "b".repeat(64))))
|
||||
invalid(root+("schemaVersion" to 1))
|
||||
invalid(root+("body" to body+("frameCount" to 721)))
|
||||
invalid(root+("body" to body+("frameCount" to 4_294_967_417L)))
|
||||
invalid(root+("body" to body+("fpsNumerator" to 61)))
|
||||
invalid(root+("body" to body+("ptsUs" to listOf(0L,0L)+pack.body.ptsUs.drop(2))))
|
||||
val levels=patches[0]["levels"] as List<Map<String,Any?>>
|
||||
invalid(root+("patches" to listOf(patches[0]+("levels" to levels.dropLast(1)))+patches.drop(1)))
|
||||
invalid(root+("patches" to listOf(patches[0]+("levels" to listOf(levels[0],levels[1]+("path" to levels[0]["path"]))+levels.drop(2)))+patches.drop(1)))
|
||||
val states=root["mouthStates"] as List<Map<String,Any?>>
|
||||
invalid(root+("mouthStates" to listOf(states[0]+("ptsUs" to listOf(0L)))+states.drop(1)))
|
||||
check(runCatching { ContinuousFramePresenter(pack).decoded(pack.body.ptsUs[1]) }.isFailure)
|
||||
check(runCatching { selectMouthPatch(pack,count,.5f) }.isFailure)
|
||||
if(fpsD==1) {
|
||||
TestScheduler.reset();CodecFixture.reset();GLFixture.reset();BitmapFactory.wrongSize=false
|
||||
CodecFixture.frames=count;CodecFixture.fps=fpsN
|
||||
CodecFixture.onRender={ pts -> SurfaceTexture.lastCreated?.emit(pts*1000) }
|
||||
val frames=mutableListOf<ComposedBodyFrame>();val errors=mutableListOf<String>()
|
||||
val renderer=ContinuousBodyRenderer(android.content.Context(),pack,Surface(SurfaceTexture(0)),480,848,
|
||||
{ frame,_ -> frames.add(frame) },errors::add)
|
||||
renderer.intent(true,1,1);TestScheduler.advanceBy((pack.body.durationUs/1000)*2+100)
|
||||
check(errors.isEmpty() && frames.size>count && frames[count].key.index==0 && frames[count].key.loopOrdinal==1L) {
|
||||
"dynamic renderer count=$count fps=$fpsN errors=$errors frames=${frames.size} wrap=${frames.getOrNull(count)?.key}"
|
||||
}
|
||||
check(frames.all { it.patch.ptsUs==pack.body.ptsUs[it.key.index] && it.selection.textureSlot in pack.textureImages.indices })
|
||||
renderer.close();TestScheduler.advanceBy(100)
|
||||
}
|
||||
}
|
||||
val sha="c".repeat(64);val root=dynamicRuntimeFixture();val body=root["body"] as Map<String,Any?>
|
||||
val pts=(body["ptsUs"] as List<Long>).mapIndexed { i,t -> t+if(i%2==1) 1000 else 0 }
|
||||
val patches=(root["patches"] as List<Map<String,Any?>>).mapIndexed { i,p -> p+("ptsUs" to pts[i]) }
|
||||
val variable=root+mapOf("body" to body+("ptsUs" to pts),"patches" to patches)
|
||||
check(ContinuousAvatarManifest.read(variable,sha,sha,true,"variable/")!=null)
|
||||
val curve=MouthCurve("opening",400,listOf(0f,.25f,1f),listOf(0L,100_000L,300_000L))
|
||||
val mouth=ContinuousMouth(continuousPack().curves+("opening" to curve))
|
||||
mouth.request(true,1,1);mouth.sample(0)
|
||||
check(kotlin.math.abs(mouth.sample(200).alpha-.625f)<.0001f)
|
||||
println("PASS: dynamic121/49/61 bodies + rational/nonuniform actual PTS, $boundaries frame/level/rejection checks; production decoder/render wrap on121@30/49@24, per-curve timing, SHA/cache/schema fences; fixtures only")
|
||||
}
|
||||
Reference in New Issue
Block a user