Support bridge-owned TALK layers and recover free P4a candidate
This commit is contained in:
+4
-1
@@ -31,6 +31,7 @@ if (avatarUiCandidate && !avatarNatural) {
|
||||
def naturalManifestSha = providers.gradleProperty('naturalManifestSha').orNull ?: ''
|
||||
def emotionManifestSha = providers.gradleProperty('emotionManifestSha').orNull ?: ''
|
||||
if (emotionManifestSha && !(emotionManifestSha ==~ /[0-9a-f]{64}/)) throw new GradleException('Emotion graph requires exact external manifest SHA')
|
||||
if (emotionManifestSha && (!avatarActionCandidate || !avatarMouthCandidate || !avatarNatural || actionVersionCode < 17)) throw new GradleException('Emotion candidate requires own-mouth runtime and a fresh code >=17')
|
||||
if (avatarNatural && !(naturalManifestSha ==~ /[0-9a-f]{64}/)) {
|
||||
throw new GradleException('Natural debug candidate requires exact runtime manifest SHA')
|
||||
}
|
||||
@@ -66,6 +67,7 @@ def stagePackagedAssets = tasks.register('stagePackagedAssets', Sync) {
|
||||
from('src/main/assets')
|
||||
exclude 'avatar/a01-v1/**', 'avatar/a01-standing-v2/**'
|
||||
if (!avatarMouthCandidate) exclude 'avatar/a01-neutral-graph-v1/runtime-04/**'
|
||||
if (!emotionManifestSha) exclude 'avatar/a01-expression-action-v1/**'
|
||||
into(packagedAssets)
|
||||
}
|
||||
|
||||
@@ -86,7 +88,8 @@ android {
|
||||
buildFeatures { compose true; buildConfig true }
|
||||
buildTypes {
|
||||
debug {
|
||||
if (avatarActionCandidate) versionNameSuffix '-stage-dev'
|
||||
if (emotionManifestSha) versionNameSuffix '-emotion-stage-dev'
|
||||
else if (avatarActionCandidate) versionNameSuffix '-stage-dev'
|
||||
else if (avatarMouthCandidate) versionNameSuffix '-mouth-dev'
|
||||
else if (avatarUiCandidate) versionNameSuffix '-ui-dev'
|
||||
else if (avatarNatural) versionNameSuffix '-natural-dev'
|
||||
|
||||
@@ -4,6 +4,9 @@ import com.gorios.lanvoice.dialogue.ReplyEmotion
|
||||
|
||||
/** One Activity-owned binding shared by VoiceSession and its persistent avatar view. */
|
||||
class AvatarMediaBinding : ActionPlayer {
|
||||
val currentPackageId: String? get() = driver?.currentPackageId
|
||||
val visualStatus: String get() = driver?.visualStatus ?: "renderer_unavailable"
|
||||
val selection: RoleVisualSelection? get() = driver?.selection
|
||||
private var driver: ConversationMediaDriver?=null
|
||||
private var prepared: ReplyEmotion?=null
|
||||
private var reply: ReplyEmotion?=null
|
||||
|
||||
@@ -87,7 +87,7 @@ fun CallScreen(state: VoiceUiState,entry: EntryPhase,permissionMessage: String?,
|
||||
LaunchedEffect(state.voiceActive,pack) {
|
||||
if(state.voiceActive) while(true) {
|
||||
val selected=latestAvatar
|
||||
DiagnosticLog.record("avatar","desired=${selected.desiredMode.name.lowercase()} actual=${latestVideo.actual} reason=${latestVideo.reason} requested=${selected.requestedEmotion.emotion.wire}/${selected.requestedEmotion.intensity} selected=${selected.resolvedAssetEmotion.emotion.wire}/${selected.resolvedAssetEmotion.intensity} fallback=${selected.emotionFallback}")
|
||||
DiagnosticLog.record("avatar","desired=${selected.desiredMode.name.lowercase()} actual=${latestVideo.actual} reason=${latestVideo.reason} requested=${selected.requestedEmotion.emotion.wire}/${selected.requestedEmotion.intensity} current_visual=${mediaBinding?.currentPackageId ?: "unavailable"} visual_status=${mediaBinding?.visualStatus ?: "legacy_neutral"}")
|
||||
delay(1_000)
|
||||
}
|
||||
}
|
||||
@@ -127,7 +127,10 @@ fun CallScreen(state: VoiceUiState,entry: EntryPhase,permissionMessage: String?,
|
||||
Text("角色:${state.roleLabel}",fontSize=13.sp)
|
||||
Text("请求表达:"+if(state.replyEmotion.turnId==null) "尚未收到" else "${state.replyEmotion.label} (${state.replyEmotion.emotion.wire}/${state.replyEmotion.intensity})",fontSize=12.sp)
|
||||
state.previousReplyEmotion?.let { Text("上一轮:${it.label}",fontSize=12.sp) }
|
||||
Text("解析素材:中立0 · ${video.actual};意图 ${avatar.desiredMode.name.lowercase()}"+if(avatar.emotionFallback) "(素材缺失,回退中立)" else "",fontSize=12.sp)
|
||||
val visualId=mediaBinding?.currentPackageId
|
||||
val visualEmotion=pack?.emotionAction?.visuals?.firstOrNull { it.id==visualId }?.emotion
|
||||
Text("当前画面:${visualEmotion?.label ?: if(pack?.emotionAction!=null) "过渡或未呈现" else "中立"} · ${video.actual}",fontSize=12.sp)
|
||||
Text("视觉选择:${mediaBinding?.selection?.let { "${it.visualEmotion.wire}/${it.visualIntensity}" } ?: "未选择"} · ${mediaBinding?.visualStatus ?: "旧中立素材"}",fontSize=12.sp)
|
||||
AvatarDiagnostics(pack,video)
|
||||
Text("AEC:${state.aec.name} · 效果待真机验证",fontSize=12.sp)
|
||||
Row {
|
||||
@@ -175,6 +178,8 @@ fun EngineeringPreviewScreen(pack: AvatarPack?,micGranted: Boolean,cameraGranted
|
||||
var override by remember { mutableStateOf<AvatarMode?>(null) }
|
||||
var restart by remember { mutableStateOf(0L) }
|
||||
var video by remember { mutableStateOf(VideoPresentation()) }
|
||||
val offlineBinding=remember(pack) { AvatarMediaBinding() }
|
||||
var emotionLabel by remember { mutableStateOf("") }
|
||||
DisposableEffect(activity) {
|
||||
val observer=LifecycleEventObserver { _,event ->
|
||||
if(event==Lifecycle.Event.ON_RESUME) resumed=true
|
||||
@@ -183,19 +188,32 @@ fun EngineeringPreviewScreen(pack: AvatarPack?,micGranted: Boolean,cameraGranted
|
||||
activity.lifecycle.addObserver(observer)
|
||||
onDispose { activity.lifecycle.removeObserver(observer) }
|
||||
}
|
||||
LaunchedEffect(resumed,restart) {
|
||||
LaunchedEffect(resumed,restart,override) {
|
||||
if(resumed) {
|
||||
val start=android.os.SystemClock.elapsedRealtime()
|
||||
while(true) { trace=OfflineAvatarTrace.at(android.os.SystemClock.elapsedRealtime()-start);delay(20) }
|
||||
val emotionSequence=OfflineEmotionSequence(1000+restart)
|
||||
if(pack?.emotionAction!=null) offlineBinding.beginTurn(1000+restart)
|
||||
while(true) {
|
||||
val elapsed=android.os.SystemClock.elapsedRealtime()-start
|
||||
trace=OfflineAvatarTrace.at(elapsed)
|
||||
if(pack?.emotionAction!=null) {
|
||||
val visual=pack.emotionAction.visuals.firstOrNull { it.id==offlineBinding.currentPackageId }?.emotion
|
||||
val sample=emotionSequence.at(elapsed,visual)
|
||||
offlineBinding.intent(sample.reply,when(override) { AvatarMode.TALK->true;AvatarMode.IDLE->false;else->sample.talking })
|
||||
emotionLabel=sample.label
|
||||
if(elapsed>=60_000) break
|
||||
}
|
||||
delay(20)
|
||||
}
|
||||
}
|
||||
}
|
||||
CleanAvatarScaffold(avatar={
|
||||
AvatarPortrait(pack,override ?: trace.mode,trace.turn+restart*100,trace.generation+restart*100,Modifier.fillMaxSize()) { video=it }
|
||||
AvatarPortrait(pack,override ?: trace.mode,trace.turn+restart*100,trace.generation+restart*100,Modifier.fillMaxSize(),if(pack?.emotionAction!=null) offlineBinding else null) { video=it }
|
||||
},settings={
|
||||
Text("离线 avatar · 无连接 / 不录音 / 不采集相机",fontSize=13.sp)
|
||||
Text("可手动申请权限;授权后仍不启动采集",fontSize=12.sp)
|
||||
PermissionSettings(micGranted,cameraGranted,micSettings,cameraSettings,permissionPending,onAuthorizeMic,onAuthorizeCamera)
|
||||
Text("合成意图:${override?.name ?: trace.label}",fontSize=12.sp)
|
||||
Text("合成意图:${override?.name ?: if(pack?.emotionAction!=null) emotionLabel else trace.label}",fontSize=12.sp)
|
||||
AvatarDiagnostics(pack,video)
|
||||
Row(horizontalArrangement=Arrangement.spacedBy(8.dp)) {
|
||||
TextButton(onClick={override=AvatarMode.IDLE}) { Text("Idle") }
|
||||
|
||||
@@ -29,7 +29,7 @@ class ContinuousBodyRenderer(private val context: Context,private val pack: Cont
|
||||
private val output: Surface,private var width: Int,private var height: Int,
|
||||
private val presented: (ComposedBodyFrame,Long)->Unit,private val failure: (String)->Unit,
|
||||
private val automatic: Boolean=true,private val startFrame: Int=0,private val mayLoop: Boolean=true,
|
||||
private val mouthEnabled: Boolean=true,private val ended: ()->Unit={}) {
|
||||
private val mouthEnabled: Boolean=true,private val sharedMouth: ConversationMouthClock?=null,private val ended: ()->Unit={}) {
|
||||
private val alive=AtomicBoolean(true)
|
||||
private val releaseLock=Any()
|
||||
private val releaseCallbacks=mutableListOf<()->Unit>()
|
||||
@@ -37,7 +37,7 @@ class ContinuousBodyRenderer(private val context: Context,private val pack: Cont
|
||||
private val thread=HandlerThread("avatar-body-gl").apply { start() }
|
||||
private val worker=Handler(thread.looper)
|
||||
private val main=Handler(Looper.getMainLooper())
|
||||
private val gate=ContinuousFramePresenter(pack,mouthEnabled=mouthEnabled,startFrame=startFrame)
|
||||
private val gate=ContinuousFramePresenter(pack,mouthEnabled=mouthEnabled,startFrame=startFrame,sharedMouth=sharedMouth)
|
||||
private var display: EGLDisplay=EGL14.EGL_NO_DISPLAY
|
||||
private var eglContext: EGLContext=EGL14.EGL_NO_CONTEXT
|
||||
private var window: EGLSurface=EGL14.EGL_NO_SURFACE
|
||||
@@ -77,6 +77,13 @@ class ContinuousBodyRenderer(private val context: Context,private val pack: Cont
|
||||
|
||||
init { worker.post { guarded { initialize(); pump() } } }
|
||||
fun intent(talk: Boolean,generation: Long,revision: Long) { worker.post { if(alive.get()) gate.intent(talk,generation,revision,SystemClock.elapsedRealtime()) } }
|
||||
fun activateMouth(talk: Boolean,generation: Long,revision: Long,ready: ()->Unit) {
|
||||
worker.post { guarded {
|
||||
gate.intent(talk,generation,revision,SystemClock.elapsedRealtime())
|
||||
val value=gate.recompose(SystemClock.elapsedRealtime()) { draw(it) } ?: return@guarded
|
||||
main.post { if(alive.get()) { presented(value,SystemClock.elapsedRealtime()-startedMs);ready() } }
|
||||
} }
|
||||
}
|
||||
fun resize(w: Int,h: Int) { worker.post { if(alive.get()) { width=w; height=h } } }
|
||||
fun advance() { worker.post { guarded { if(held) {
|
||||
held=false;worker.removeCallbacks(heldTick)
|
||||
|
||||
@@ -13,12 +13,12 @@ data class ComposedBodyFrame(val key: BodyFrameKey,val patch: RegisteredMouthPat
|
||||
/** The real EGL renderer uses this gate immediately around updateTexImage + draw/swap.
|
||||
* No other thread can choose a patch or change body phase. close() fences stale output. */
|
||||
class ContinuousFramePresenter(private val pack: ContinuousAvatarPack,
|
||||
private val mouthEnabled: Boolean=true,startFrame: Int=0,choose: (Int)->Int = { kotlin.random.Random.nextInt(it) }) {
|
||||
private val mouthEnabled: Boolean=true,startFrame: Int=0,private val sharedMouth: ConversationMouthClock?=null,choose: (Int)->Int = { kotlin.random.Random.nextInt(it) }) {
|
||||
private val clock=ContinuousFrameClock(pack.body.frameCount,pack.body.ptsUs,startFrame)
|
||||
private val mouth=ContinuousMouth(pack.curves,choose)
|
||||
private var active=true
|
||||
private var heldKey: BodyFrameKey?=null
|
||||
fun intent(talk: Boolean,generation: Long,revision: Long,nowMs: Long?=null): Boolean = active && mouth.request(talk && mouthEnabled,generation,revision,nowMs)
|
||||
fun intent(talk: Boolean,generation: Long,revision: Long,nowMs: Long?=null): Boolean = active && if(sharedMouth!=null && mouthEnabled) sharedMouth.intent(this,pack.curves,talk,generation,revision,nowMs ?: 0) else mouth.request(talk && mouthEnabled,generation,revision,nowMs)
|
||||
fun decoded(ptsUs: Long): BodyFrameKey { check(active); return clock.decoded(ptsUs) }
|
||||
fun present(timestampNs: Long,nowMs: Long,drawAndSwap: (ComposedBodyFrame)->Unit): ComposedBodyFrame? {
|
||||
if(!active) return null
|
||||
@@ -31,12 +31,12 @@ class ContinuousFramePresenter(private val pack: ContinuousAvatarPack,
|
||||
return compose(heldKey ?: return null,nowMs,drawAndSwap)
|
||||
}
|
||||
private fun compose(key: BodyFrameKey,nowMs: Long,drawAndSwap: (ComposedBodyFrame)->Unit): ComposedBodyFrame {
|
||||
val sample=mouth.sample(nowMs)
|
||||
val sample=if(sharedMouth!=null && mouthEnabled) sharedMouth.sample(this,nowMs) else mouth.sample(nowMs)
|
||||
val frame=if(mouthEnabled) ComposedBodyFrame(key,pack.patches[key.index],sample,selectMouthPatch(pack,key.index,sample.alpha))
|
||||
else ComposedBodyFrame(key,RegisteredMouthPatch(key.index,key.ptsUs,"","",0f,0f,1,1),sample,MouthPatchSelection(-1,0,0f))
|
||||
drawAndSwap(frame) // Exactly one atomic composition; failed swap is not presented.
|
||||
return frame
|
||||
}
|
||||
fun wrap() { check(active); clock.wrap() }
|
||||
fun close() { active=false }
|
||||
fun close() { active=false;sharedMouth?.release(this) }
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ data class MouthLayerSample(val phase: String, val alpha: Float, val generation:
|
||||
val phaseWaitMs: Long=0)
|
||||
|
||||
/** Body-independent authored phase controller. No perceived-mouth SLA is inferred. */
|
||||
class ContinuousMouth(private val curves: Map<String,MouthCurve>, private val choose: (Int)->Int = { kotlin.random.Random.nextInt(it) }) {
|
||||
class ContinuousMouth(private var curves: Map<String,MouthCurve>, private val choose: (Int)->Int = { kotlin.random.Random.nextInt(it) }) {
|
||||
private var desired = false
|
||||
private var generation = -1L
|
||||
private var revision = -1L
|
||||
@@ -16,6 +16,17 @@ class ContinuousMouth(private val curves: Map<String,MouthCurve>, private val ch
|
||||
private var initialized = false
|
||||
private var previousTalk: String? = null
|
||||
private var requestedAt: Long? = null
|
||||
fun rebind(next: Map<String,MouthCurve>,nowMs: Long) {
|
||||
if(curves==next) return
|
||||
if(initialized && phase!="idle") {
|
||||
sample(nowMs)
|
||||
if(phase!="idle") {
|
||||
val fraction=(nowMs-startedAt).toDouble()/curves.getValue(phase).durationMs
|
||||
startedAt=nowMs-(fraction*next.getValue(phase).durationMs).toLong()
|
||||
}
|
||||
}
|
||||
curves=next
|
||||
}
|
||||
fun request(talk: Boolean, generation: Long, revision: Long,nowMs: Long?=null): Boolean {
|
||||
if (generation < this.generation || generation == this.generation && revision <= this.revision) return false
|
||||
this.generation=generation; this.revision=revision; desired=talk
|
||||
@@ -101,3 +112,34 @@ fun composeMouthChannel(body: Float,patch: Float,mask: Float,global: Float): Flo
|
||||
val a=mask*global
|
||||
return body*(1-a)+patch*a
|
||||
}
|
||||
|
||||
|
||||
/** Shared phase only: every presenter still indexes its own body/patch/UV data.
|
||||
* Hidden surfaces never advance this clock. Global generation/revision fences also
|
||||
* prevent a retired worker from taking ownership back after a boundary switch. */
|
||||
class ConversationMouthClock {
|
||||
private var owner: Any?=null
|
||||
private val lastSamples=java.util.IdentityHashMap<Any,MouthLayerSample>()
|
||||
private var controller: ContinuousMouth?=null
|
||||
private var generation=-1L
|
||||
private var revision=-1L
|
||||
private var time=0L
|
||||
@Synchronized fun intent(token: Any,curves: Map<String,MouthCurve>,talk: Boolean,generation: Long,revision: Long,nowMs: Long): Boolean {
|
||||
if(generation<this.generation || generation==this.generation && revision<=this.revision) return false
|
||||
time=maxOf(time,nowMs)
|
||||
val current=controller ?: ContinuousMouth(curves).also { controller=it }
|
||||
current.rebind(curves,time)
|
||||
current.request(talk,generation,revision,time)
|
||||
owner=token;this.generation=generation;this.revision=revision
|
||||
return true
|
||||
}
|
||||
@Synchronized fun sample(token: Any,nowMs: Long): MouthLayerSample {
|
||||
if(token!==owner) return lastSamples[token] ?: MouthLayerSample("idle",0f,generation,revision)
|
||||
time=maxOf(time,nowMs)
|
||||
return checkNotNull(controller).sample(time).also { lastSamples[token]=it }
|
||||
}
|
||||
@Synchronized fun release(token: Any) {
|
||||
lastSamples.remove(token);if(owner===token) owner=null
|
||||
if(owner==null && lastSamples.isEmpty()) controller=null // No expired phase across background restart.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ interface CompositeMediaPort {
|
||||
frame: (BodyFrameKey,Boolean)->Unit,ended: ()->Unit,failed: ()->Unit)
|
||||
fun advance()
|
||||
fun mouth(talk: Boolean,generation: Long,revision: Long)
|
||||
fun activateMouth(talk: Boolean,generation: Long,revision: Long,ready: ()->Unit) {
|
||||
mouth(talk,generation,revision);ready()
|
||||
}
|
||||
fun close(released: ()->Unit)
|
||||
}
|
||||
interface MusicMediaPort {
|
||||
@@ -21,16 +24,27 @@ interface MusicMediaPort {
|
||||
* New intent during a bridge finishes that edge and then routes the latest target. */
|
||||
class ConversationMediaDriver(private val index: EmotionActionIndex,
|
||||
private val create: (Int)->CompositeMediaPort,private val music: MusicMediaPort,
|
||||
private val reveal: (Int?)->Unit,private val report: (String,BodyFrameKey?)->Unit = { _,_-> }) : ActionPlayer {
|
||||
private val reveal: (Int?)->Unit,private val report: (String,BodyFrameKey?)->Unit = { _,_-> },
|
||||
private val allowSilentEdges: Boolean=false) : ActionPlayer {
|
||||
private data class Slot(val number: Int,val port: CompositeMediaPort,val pack: ContinuousAvatarPack,
|
||||
val entry: Int,val packageId: String?,var key: BodyFrameKey?=null,var live: Boolean=true,var closedMouth: Boolean=false)
|
||||
private val slots=mutableListOf<Slot>()
|
||||
private var visible: Slot?=null
|
||||
private var revealing: Slot?=null
|
||||
private var target: Slot?=null
|
||||
private var bridge: Slot?=null
|
||||
private var edge: ConversationEdge?=null
|
||||
private var selectedId=index.fallbackId
|
||||
var selection: RoleVisualSelection?=null;private set
|
||||
val currentPackageId: String? get() = if(inBridge || actionStarted) null else visible?.packageId
|
||||
val visualStatus: String get() = when {
|
||||
!active -> "renderer_stopped"
|
||||
actionStarted -> "action_mouth_disabled"
|
||||
inBridge -> "bridge_own_mouth"
|
||||
edge!=null || revealing!=null -> "queued_emotion_safe_exit_or_prepared_surface"
|
||||
visible?.packageId!=selectedId -> "queued_emotion_path_or_layer_unavailable"
|
||||
else -> selection?.reason ?: "no_model_expression"
|
||||
}
|
||||
private var turn: Long?=null
|
||||
private var seq=-1L
|
||||
private var generation=0L
|
||||
@@ -49,9 +63,9 @@ class ConversationMediaDriver(private val index: EmotionActionIndex,
|
||||
private val releaseWaiters=mutableListOf<()->Unit>()
|
||||
fun beginTurn(id: Long?) {
|
||||
if(id==turn) return
|
||||
turn=id;seq=-1;generation++;revision=0;talk=false
|
||||
turn=id;seq=-1;generation++;revision=0;talk=false;selection=null
|
||||
selectedId=visible?.packageId ?: index.fallbackId
|
||||
if(!inBridge) discardRoute()
|
||||
if(!inBridge && revealing==null) discardRoute()
|
||||
applyMouth()
|
||||
}
|
||||
fun start() {
|
||||
@@ -82,7 +96,8 @@ class ConversationMediaDriver(private val index: EmotionActionIndex,
|
||||
if(active && !inBridge && !actionStarted) plan()
|
||||
}
|
||||
private fun applyMouth() {
|
||||
visible?.port?.mouth(talk && action==null && !inBridge && edge==null && visible?.packageId==selectedId,generation,++revision)
|
||||
val current=revealing ?: visible
|
||||
current?.port?.mouth(talk && action==null && current.pack.apertureMode,generation,++revision)
|
||||
}
|
||||
private fun loopEdge(id: String)=index.edges.first { it.from==id && it.to==id && (index.loopIds[id]==null || it.id==index.loopIds[id]) }
|
||||
private fun prepare(id: String,frame: Int): Slot = prepare(index.packages.getValue(id),frame,true,loopEdge(id).nativeLoop,id)
|
||||
@@ -106,7 +121,9 @@ class ConversationMediaDriver(private val index: EmotionActionIndex,
|
||||
} else if(returning) restoreAction(slot) else plan()
|
||||
}
|
||||
},{
|
||||
if(active && visible===slot && inBridge) finishBridge()
|
||||
if(active && slot.live && visible===slot && inBridge && revealing==null) {
|
||||
if(slot.key?.index==slot.pack.body.frameCount-1) finishBridge() else fail()
|
||||
}
|
||||
},{ if(active && slot.live && slot in slots) fail() })
|
||||
return slot
|
||||
}
|
||||
@@ -116,7 +133,7 @@ class ConversationMediaDriver(private val index: EmotionActionIndex,
|
||||
private fun plan() {
|
||||
val source=visible ?: return
|
||||
val key=source.key ?: return
|
||||
if(inBridge || !active || returning || actionStarted) return
|
||||
if(inBridge || revealing!=null || !active || returning || actionStarted) return
|
||||
val wanted=if(action!=null) checkNotNull(action?.media).sourcePackage else selectedId
|
||||
var reviewedLoop: ConversationEdge?=null
|
||||
if(source.packageId==wanted) {
|
||||
@@ -138,18 +155,23 @@ class ConversationMediaDriver(private val index: EmotionActionIndex,
|
||||
visualIntensity=0,packageId=index.fallbackId,degraded=true,reason="whole_package_path_unavailable")
|
||||
return
|
||||
}
|
||||
if(next.mouthRuntime==null && !allowSilentEdges) {
|
||||
report("queued_emotion_bridge_has_no_own_mouth",key);return
|
||||
}
|
||||
if(target!=null && (target?.packageId!=next.to || target?.entry!=next.toFrame)) { discardTarget();return }
|
||||
if(slots.size+(if(target==null) 2 else 1)>3) return
|
||||
edge=next
|
||||
if(target==null) target=prepare(next.to,next.toFrame)
|
||||
bridge=prepare(ContinuousAvatarPack(next.clip,emptyList(),emptyMap(),index.root,"",false),0,false,false,null)
|
||||
bridge=prepare(next.mouthRuntime ?: ContinuousAvatarPack(next.clip,emptyList(),emptyMap(),index.root,"",false),0,next.mouthRuntime!=null,false,null)
|
||||
applyMouth()
|
||||
}
|
||||
val current=edge ?: return
|
||||
if(source.closedMouth && key.index==current.fromFrame && target?.key?.index==current.toFrame && bridge?.key?.index==0) {
|
||||
if((current.mouthRuntime!=null || source.closedMouth) && key.index==current.fromFrame && target?.key?.index==current.toFrame && bridge?.key?.index==0) {
|
||||
val destination=checkNotNull(bridge)
|
||||
inBridge=true;visible=destination;closeSlot(source);reveal(destination.number)
|
||||
report("bridge",destination.key);destination.port.advance()
|
||||
activate(destination) {
|
||||
inBridge=true;visible=destination;closeSlot(source);reveal(destination.number)
|
||||
report("bridge",destination.key);destination.port.advance()
|
||||
}
|
||||
}
|
||||
}
|
||||
private fun finishBridge() {
|
||||
@@ -157,9 +179,20 @@ class ConversationMediaDriver(private val index: EmotionActionIndex,
|
||||
val destination=target ?: return fail()
|
||||
val current=edge ?: return fail()
|
||||
if(destination.key?.index!=current.toFrame) return fail()
|
||||
visible=destination;target=null;bridge=null;edge=null;inBridge=false
|
||||
closeSlot(old);reveal(destination.number);report("body_${destination.packageId}",destination.key)
|
||||
applyMouth();plan();if(!actionStarted && !holdExit(destination)) destination.port.advance()
|
||||
activate(destination) {
|
||||
visible=destination;target=null;bridge=null;edge=null;inBridge=false
|
||||
closeSlot(old);reveal(destination.number);report("body_${destination.packageId}",destination.key)
|
||||
applyMouth();plan();if(!actionStarted && !holdExit(destination)) destination.port.advance()
|
||||
}
|
||||
}
|
||||
private fun activate(destination: Slot,ready: ()->Unit) {
|
||||
if(revealing!=null) return
|
||||
revealing=destination
|
||||
destination.port.activateMouth(talk && action==null && destination.pack.apertureMode,generation,++revision) {
|
||||
if(active && destination.live && revealing===destination) {
|
||||
revealing=null;ready()
|
||||
}
|
||||
}
|
||||
}
|
||||
private fun discardTarget() { target?.let(::closeSlot);target=null }
|
||||
private fun discardRoute() { bridge?.let(::closeSlot);bridge=null;edge=null;discardTarget() }
|
||||
@@ -202,7 +235,7 @@ class ConversationMediaDriver(private val index: EmotionActionIndex,
|
||||
musicEpoch++;action=null;actionStarted=false;returning=false;musicReady=false
|
||||
actionFinished=null;actionFailed=null;talk=false;generation++;revision=0
|
||||
reveal(null);releaseWaiters.add(released)
|
||||
active=false;visible=null;target=null;bridge=null;edge=null;inBridge=false
|
||||
active=false;visible=null;revealing=null;target=null;bridge=null;edge=null;inBridge=false
|
||||
closing++ // Music barrier exists before any synchronous port release callback.
|
||||
slots.toList().forEach(::closeSlot)
|
||||
music.close { closing--;releasedIfDone() }
|
||||
|
||||
@@ -43,6 +43,7 @@ class EmotionActionAvatarView(context: Context,private val pack: AvatarPack,
|
||||
private fun start() {
|
||||
if(!active || released || driver!=null || textures.any { !it.isAvailable }) return
|
||||
val index=checkNotNull(pack.emotionAction)
|
||||
val mouthClock=ConversationMouthClock()
|
||||
val music=AndroidMusicPort(context,textures[3]);movie=music
|
||||
val current=ConversationMediaDriver(index,{ slot ->
|
||||
object: CompositeMediaPort {
|
||||
@@ -52,11 +53,14 @@ class EmotionActionAvatarView(context: Context,private val pack: AvatarPack,
|
||||
renderer=ContinuousBodyRenderer(context,pack,Surface(checkNotNull(textures[slot].surfaceTexture)),
|
||||
textures[slot].width,textures[slot].height,{ value,_->
|
||||
frame(value.key,value.mouth.phase=="idle" && value.selection.opacity==0f)
|
||||
},{ reason->report(VideoPresentation(reason=reason));failed() },automatic=false,startFrame=entryFrame,mayLoop=loop,mouthEnabled=mouth,ended=ended)
|
||||
},{ reason->report(VideoPresentation(reason=reason));failed() },automatic=false,startFrame=entryFrame,mayLoop=loop,mouthEnabled=mouth,sharedMouth=mouthClock,ended=ended)
|
||||
renderers[slot]=renderer
|
||||
}
|
||||
override fun advance() { renderer?.advance() }
|
||||
override fun mouth(talk: Boolean,generation: Long,revision: Long) { renderer?.intent(talk,generation,revision) }
|
||||
override fun activateMouth(talk: Boolean,generation: Long,revision: Long,ready: ()->Unit) {
|
||||
renderer?.activateMouth(talk,generation,revision,ready)
|
||||
}
|
||||
override fun close(released: ()->Unit) { val old=renderer;renderer=null
|
||||
if(renderers[slot]===old) renderers[slot]=null
|
||||
old?.close(released) ?: released()
|
||||
|
||||
@@ -6,7 +6,7 @@ data class EmotionActionIndex(val fallbackId: String, val packages: Map<String,C
|
||||
val visuals: List<TalkPackage>, val actionPack: ReviewedActionPack?, val edges: List<ConversationEdge> = emptyList(),val root: String="",
|
||||
val loopIds: Map<String,String> = emptyMap())
|
||||
data class ConversationEdge(val id: String,val from: String,val to: String,val fromFrame: Int,val toFrame: Int,
|
||||
val clip: ContinuousBodyAsset,val nativeLoop: Boolean=false)
|
||||
val clip: ContinuousBodyAsset,val nativeLoop: Boolean=false,val mouthRuntime: ContinuousAvatarPack?=null)
|
||||
|
||||
/** Exact external manifest pin admits the whole graph. Self-approval fields have no effect.
|
||||
* loadRuntime must hash-check exact bytes and all body/patch files before returning a pack.
|
||||
@@ -70,11 +70,29 @@ object EmotionActionManifest {
|
||||
if(nativeLoop) require(edge["from"]==edge["to"] && integer(edge["fromFrame"])==from.body.frameCount-1L &&
|
||||
integer(edge["toFrame"])==0L && hash(clip["sha256"])==from.body.sha256 && pts==from.body.ptsUs &&
|
||||
integer(clip["durationUs"])==from.body.durationUs)
|
||||
val mouthRuntime=edge["mouthRuntimeManifest"]?.let { value ->
|
||||
require(!nativeLoop) // Native loops already use their exact package layer.
|
||||
val reference=obj(value)
|
||||
val runtime=checkNotNull(loadRuntime(path(reference["path"]),hash(reference["sha256"])))
|
||||
require(runtime.apertureMode && runtime.patches.size==count && runtime.patches.all { it.levels.size==5 })
|
||||
require(runtime.body.sha256==clip["sha256"] && runtime.body.frameCount==count &&
|
||||
runtime.body.ptsUs==pts && runtime.patches.map { it.ptsUs }==pts &&
|
||||
runtime.body.width==integer(clip["width"]).toInt() && runtime.body.height==integer(clip["height"]).toInt() &&
|
||||
runtime.body.durationUs==integer(clip["durationUs"]) &&
|
||||
runtime.body.fpsNumerator==integer(clip["fpsNumerator"]).toInt() &&
|
||||
runtime.body.fpsDenominator==integer(clip["fpsDenominator"]).toInt())
|
||||
runtime
|
||||
}
|
||||
require(edge["mouthAllowed"]==null || edge["mouthAllowed"] is Boolean)
|
||||
require(edge["mouthAllowed"]!=true || nativeLoop || mouthRuntime!=null)
|
||||
require(mouthRuntime==null || edge["mouthAllowed"]!=false)
|
||||
ConversationEdge(edge["id"] as String,edge["from"] as String,edge["to"] as String,
|
||||
integer(edge["fromFrame"]).toInt(),integer(edge["toFrame"]).toInt(),
|
||||
ContinuousBodyAsset(path(clip["path"]),hash(clip["sha256"]),480,848,pts.size,
|
||||
integer(clip["durationUs"]),pts,boundedInt(clip["fpsNumerator"],120_000),boundedInt(clip["fpsDenominator"],10_000)),nativeLoop)
|
||||
integer(clip["durationUs"]),pts,boundedInt(clip["fpsNumerator"],120_000),boundedInt(clip["fpsDenominator"],10_000)),nativeLoop,mouthRuntime)
|
||||
}
|
||||
require(packages.values.sumOf { it.rgbaBytes }+
|
||||
admittedEdges.mapNotNull { it.mouthRuntime }.sumOf { it.rgbaBytes }<=BodyTimeline.MAX_PACK_CACHE_BYTES)
|
||||
val admitted=visuals.map { visual ->
|
||||
val row=rows.single { it["id"]==visual.id }
|
||||
require(row["entryAnchor"]=="A" && row["exitAnchor"]=="A")
|
||||
|
||||
@@ -23,3 +23,29 @@ object OfflineAvatarTrace {
|
||||
return Intent(mode,cycle*2+if(time>=15_000) 2 else 1,epoch,label)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** A finite sequence gated by actual rendered body identity, never assumed bridge time. */
|
||||
class OfflineEmotionSequence(private val turn: Long) {
|
||||
private val steps=listOf(com.gorios.lanvoice.dialogue.RoleEmotion.NEUTRAL,
|
||||
com.gorios.lanvoice.dialogue.RoleEmotion.HAPPY,com.gorios.lanvoice.dialogue.RoleEmotion.NEUTRAL,
|
||||
com.gorios.lanvoice.dialogue.RoleEmotion.SAD,com.gorios.lanvoice.dialogue.RoleEmotion.NEUTRAL)
|
||||
private var step=0
|
||||
private var arrivedAt: Long?=null
|
||||
private var finished=false
|
||||
data class Sample(val reply: com.gorios.lanvoice.dialogue.ReplyEmotion,val talking: Boolean,val label: String)
|
||||
fun at(elapsedMs: Long,visualEmotion: com.gorios.lanvoice.dialogue.RoleEmotion?): Sample {
|
||||
if(visualEmotion==steps[step] && arrivedAt==null) arrivedAt=elapsedMs
|
||||
if(visualEmotion!=steps[step]) arrivedAt=null
|
||||
val arrived=arrivedAt
|
||||
if(!finished && arrived!=null && elapsedMs-arrived>=2000) {
|
||||
if(step<steps.lastIndex) { step++;arrivedAt=null } else finished=true
|
||||
}
|
||||
if(elapsedMs>=60_000) finished=true // Bound failed/unavailable asset traces, no fabricated arrival.
|
||||
val emotion=steps[step]
|
||||
val talk=!finished && arrivedAt!=null && elapsedMs-checkNotNull(arrivedAt) in 200..1400
|
||||
return Sample(com.gorios.lanvoice.dialogue.ReplyEmotion(emotion,if(emotion==com.gorios.lanvoice.dialogue.RoleEmotion.NEUTRAL) 0 else 2,
|
||||
com.gorios.lanvoice.dialogue.EmotionSource.MODEL,turn,step.toLong()+1),talk,
|
||||
if(finished) "emotion trace ended" else "synthetic ${emotion.wire} / actual-body gate")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user