Add bounded native playback diagnostics and sensor-free dance inspection
This commit is contained in:
@@ -6,6 +6,7 @@ import android.media.MediaPlayer
|
||||
import android.view.TextureView
|
||||
|
||||
fun main() {
|
||||
playbackDiagnosticCheck()
|
||||
boundedRuntimeDiagnosticCheck()
|
||||
dynamicBodyCheck()
|
||||
actionCheck()
|
||||
|
||||
@@ -7,6 +7,7 @@ class MediaPlayer {
|
||||
var info: ((MediaPlayer,Int,Int)->Boolean)? = null
|
||||
var error: ((MediaPlayer,Int,Int)->Boolean)? = null
|
||||
var completion: ((MediaPlayer)->Unit)? = null
|
||||
var currentPosition = 0
|
||||
var isLooping = false; val looping get() = isLooping
|
||||
var volume = 1f; var released = false; var started = false
|
||||
val videoWidth = 480; val videoHeight = 848
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
import com.gorios.lanvoice.avatar.*
|
||||
import com.gorios.lanvoice.diag.DiagnosticLog
|
||||
import android.os.TestScheduler
|
||||
import android.media.MediaPlayer
|
||||
import android.view.TextureView
|
||||
import android.graphics.SurfaceTexture
|
||||
|
||||
fun playbackDiagnosticCheck() {
|
||||
var assertions=0
|
||||
val asset=mediaFixtureIndex().actionPack!!.assets.first()
|
||||
for(reason in listOf("first_frame_not_zero","timestamp_not_indexed","timestamp_regressed","native_error","native_ended_missing_final","duration_early")) {
|
||||
TestScheduler.reset();MediaPlayer.created.clear()
|
||||
val view=TextureView(android.content.Context());val messages=mutableListOf<String>()
|
||||
val port=AndroidMusicPort(android.content.Context(),view,messages::add)
|
||||
var ready=false;var first=0;var ended=0;var failures=0
|
||||
port.prepare(asset.media!!,{ready=true},{first++},{ended++},{failures++})
|
||||
val native=MediaPlayer.created.last();native.prepared!!(native);check(ready);assertions++
|
||||
port.start();native.info!!(native,MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START,0)
|
||||
check(first==0 && ended==0);assertions++ // Info does not claim surface presentation.
|
||||
when(reason) {
|
||||
"first_frame_not_zero"->port.latched(asset.media.ptsUs[1]*1000)
|
||||
"timestamp_not_indexed"->port.latched(123456789)
|
||||
"timestamp_regressed"->{port.latched(0);port.latched(asset.media.ptsUs[1]*1000);port.latched(0)}
|
||||
"native_error"->native.error!!(native,1,2)
|
||||
"native_ended_missing_final"->{port.latched(0);native.completion!!(native);TestScheduler.advanceBy(2001)}
|
||||
"duration_early"->{port.latched(0);port.latched(asset.media.ptsUs.last()*1000);native.completion!!(native)}
|
||||
}
|
||||
check(failures==1 && ended==0 && messages.any { "event=$reason " in it });assertions++
|
||||
port.latched(123456789);port.latched(asset.media.ptsUs.last()*1000);TestScheduler.advanceBy(1001);native.completion!!(native)
|
||||
check(failures==1 && ended==0);assertions++ // No error flood.
|
||||
var release=0;port.close { release++ };TestScheduler.advanceBy(1)
|
||||
check(native.released && release==1 && messages.last().contains("event=released"));assertions++
|
||||
native.prepared!!(native);native.info!!(native,3,0);native.completion!!(native);native.error!!(native,1,2)
|
||||
check(failures==1 && ended==0);assertions++ // Old native callbacks fenced.
|
||||
}
|
||||
class Player: ActionPlayer {
|
||||
lateinit var end: (ActionEnd)->Unit;lateinit var failure: ()->Unit;lateinit var release: ()->Unit
|
||||
val ids=mutableListOf<String>()
|
||||
override fun play(asset: ActionAsset,finished: (ActionEnd)->Unit,failed: ()->Unit) {ids.add(asset.id);end=finished;failure=failed}
|
||||
override fun stop(released: ()->Unit) {release=released}
|
||||
}
|
||||
val p=Player();var now=0L;val events=mutableListOf<Pair<Boolean,String>>()
|
||||
val demo=OfflineDancePreview(mediaFixtureIndex().actionPack,p,{now}) {a,s->events.add(a to s)}
|
||||
check(!demo.play("unknown") && p.ids.isEmpty());assertions++
|
||||
check(demo.play("asset_01") && !demo.play("asset_02"));assertions++
|
||||
val old=p.end;old(ActionEnd(true,true,true)) // Early end is failure, never completion.
|
||||
check(demo.active && events.none { it.second=="completed" });assertions++
|
||||
p.release();check(!demo.active);assertions++
|
||||
check(demo.play("asset_02"));assertions++
|
||||
old(ActionEnd(true,true,true));check(demo.active);assertions++
|
||||
now=1001;p.end(ActionEnd(true,true,true));check(!demo.active && events.last().second=="completed");assertions++
|
||||
check(demo.play("asset_01"));assertions++
|
||||
val stale=p.failure;demo.cancel("background");demo.cancel();check(!demo.play("asset_02"));assertions++
|
||||
p.release();stale();check(!demo.active && events.last().second=="released");assertions++
|
||||
check(demo.play("asset_02"));assertions++
|
||||
p.failure();p.release();check(!demo.active && p.ids==listOf("asset_01","asset_02","asset_01","asset_02"));assertions++
|
||||
// Local controls exercise the actual persistent View + renderer + native music callbacks.
|
||||
for(id in listOf("asset_01","asset_02")) {
|
||||
TestScheduler.reset();android.media.CodecFixture.reset();MediaPlayer.created.clear()
|
||||
android.media.CodecFixture.emitNativeSurface=true
|
||||
val index=mediaFixtureIndex()
|
||||
index.packages.values.forEach { android.media.CodecFixture.timelines[it.root+it.body.path]=it.body.ptsUs }
|
||||
index.edges.mapNotNull { it.mouthRuntime }.forEach { android.media.CodecFixture.timelines[it.root+it.body.path]=it.body.ptsUs }
|
||||
val binding=AvatarMediaBinding();val view=EmotionActionAvatarView(android.content.Context(),AvatarPack(fallback="fixture.png",emotionAction=index),binding) {}
|
||||
view.render(true);TestScheduler.advanceBy(1)
|
||||
val local=OfflineDancePreview(index.actionPack,binding,{TestScheduler.now})
|
||||
check(local.play(id));assertions++
|
||||
TestScheduler.until { MediaPlayer.created.isNotEmpty() }
|
||||
val native=MediaPlayer.created.last();native.prepared!!(native)
|
||||
TestScheduler.until { native.started }
|
||||
val texture=(view.javaClass.getDeclaredField("textures").apply { isAccessible=true }.get(view) as List<TextureView>).last()
|
||||
val start=TestScheduler.now
|
||||
val media=index.actionPack!!.assets.single { it.id==id }.media!!
|
||||
for(pts in media.ptsUs) {
|
||||
TestScheduler.advanceBy((start+pts/1000-TestScheduler.now).coerceAtLeast(0))
|
||||
texture.surfaceTexture.timestamp=pts*1000
|
||||
texture.surfaceTextureListener!!.onSurfaceTextureUpdated(texture.surfaceTexture)
|
||||
TestScheduler.advanceBy(1)
|
||||
check(texture.alpha==1f && local.active);assertions++
|
||||
}
|
||||
TestScheduler.advanceBy((start+1000-TestScheduler.now).coerceAtLeast(0))
|
||||
native.completion!!(native)
|
||||
TestScheduler.until { !local.active }
|
||||
check(native.released && texture.alpha==0f && binding.diagnosticState.contains("event=released"));assertions++
|
||||
view.dispose();TestScheduler.advanceBy(50)
|
||||
}
|
||||
println("PASS: $assertions production native failure reasons/info-vs-latched/stale-callback/release and sensor-free offline dance lifecycle assertions; strict media gate retained, native Android/GPU not_run")
|
||||
}
|
||||
@@ -232,6 +232,19 @@ class PackageTests(unittest.TestCase):
|
||||
with self.subTest(kind=kind),self.assertRaises(ValueError):
|
||||
pack.verify_runtime_fix_assets(new,'0'*64 if kind=='pin' else pin)
|
||||
|
||||
def test_diagnostic_requires_frozen_full_pack_and_fresh_version(self):
|
||||
report={'manifest_sha256':pack.RUNTIME_FIX_PIN}
|
||||
with patch.object(pack,'tested_source'),patch.object(pack,'packaging_tests_current'),patch.object(pack,'read_json',return_value={'edges':[{'nativeLoop':True}]}),patch.object(pack,'next_version',return_value=20),patch.object(pack.subprocess,'run',side_effect=RuntimeError('build_sentinel')) as build:
|
||||
for full,pin,code in ((False,pack.RUNTIME_FIX_PIN,20),(True,'0'*64,20),(True,pack.RUNTIME_FIX_PIN,19)):
|
||||
with self.subTest(full=full,pin=pin,code=code),self.assertRaises(ValueError):
|
||||
pack.publish({'manifest_sha256':pin},self.base,code,full,False,True)
|
||||
build.assert_not_called()
|
||||
with self.assertRaisesRegex(RuntimeError,'build_sentinel'):
|
||||
pack.publish(report,self.base,20,True,False,True)
|
||||
command=build.call_args.args[0]
|
||||
self.assertIn('-PavatarPlaybackDiagnostic=true',command)
|
||||
self.assertIn('-PactionVersionCode=20',command)
|
||||
|
||||
def test_cli_no_pin_no_import_no_output(self):
|
||||
self.manifest.write_text(json.dumps(self.index));out=self.base/'no-pin-output'
|
||||
result=subprocess.run([sys.executable,str(ROOT/'scripts/package-avatar-emotion.py'),
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.gorios.lanvoice.avatar.*
|
||||
import com.gorios.lanvoice.net.*
|
||||
|
||||
fun checkActionSession() {
|
||||
checkLocalPreviewCaptureFence()
|
||||
checkActionFollowupSession()
|
||||
val sha="a".repeat(64);val states=mutableListOf<VoiceUiState>()
|
||||
val prepared=mutableListOf<com.gorios.lanvoice.dialogue.ReplyEmotion?>()
|
||||
@@ -102,3 +103,21 @@ fun checkActionFollowupSession() {
|
||||
session.release();AudioPlayback.activityFence=null
|
||||
println("PASS: client normal action completion/new server speech turn accepted, future after emotion hidden, retired pre audio/emotion/drain rejected, independent after drain and duplicate completion fence; deterministic doubles only")
|
||||
}
|
||||
|
||||
fun checkLocalPreviewCaptureFence() {
|
||||
AudioCapture.confirmStopsAutomatically=false
|
||||
val s=VoiceSession("localhost",5011,{})
|
||||
val results=mutableListOf<Boolean>()
|
||||
s.suspendForLocalPreview(results::add);Handler.drain()
|
||||
check(results.isEmpty())
|
||||
AudioCapture.lastStopped!!(false);Handler.drain();check(results==listOf(false))
|
||||
AudioCapture.lastStopped!!(true);Handler.drain();check(results==listOf(false))
|
||||
s.suspendForLocalPreview(results::add);AudioCapture.lastStopped!!(true);Handler.drain()
|
||||
check(results==listOf(false,true))
|
||||
s.suspendForLocalPreview(results::add);s.foreground(connectAutomatically=false)
|
||||
AudioCapture.lastStopped!!(true);Handler.drain();check(results.last()==false)
|
||||
s.suspendForLocalPreview(results::add);val stale=AudioCapture.lastStopped!!;s.release()
|
||||
stale(true);Handler.drain();check(results.last()==false)
|
||||
AudioCapture.confirmStopsAutomatically=true
|
||||
println("PASS:6 production local-preview capture cleanup/unconfirmed/duplicate/foreground/release callback fences; AudioRecord double, device not_run")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user