Fix action playback source clock using controlled video decode
This commit is contained in:
@@ -8,30 +8,51 @@ 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()
|
||||
// Exact device report: compositor output clock jumped from0 to47,741,893,941us.
|
||||
// Reproduce the old failure independently, then pass that same output sequence
|
||||
// through the production adapter while source codec frames remain exact.
|
||||
val reported=listOf(0L,47_741_893_941_000L,47_742_026_182_000L)
|
||||
check(reported.drop(1).none { ts->asset.media!!.ptsUs.any { kotlin.math.abs(it-ts/1000)<=2 } });assertions++
|
||||
for(mode in listOf("report_clock","early_audio_end","native_error","wrong_codec_pts","missing_audio_end","cancel")) {
|
||||
TestScheduler.reset();android.media.CodecFixture.reset();MediaPlayer.created.clear()
|
||||
val media=asset.media!!
|
||||
android.media.CodecFixture.emitNativeSurface=true
|
||||
android.media.CodecFixture.timelines[media.root+media.path]=media.ptsUs
|
||||
android.media.CodecFixture.audioPaths.add(media.root+media.path)
|
||||
if(mode=="wrong_codec_pts") android.media.CodecFixture.timestampOffsetUs=10_000
|
||||
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)}
|
||||
port.prepare(media,{ready=true},{first++},{ended++},{failures++})
|
||||
val native=MediaPlayer.created.last();native.prepared!!(native)
|
||||
TestScheduler.until { ready || failures>0 }
|
||||
if(mode=="wrong_codec_pts") {
|
||||
check(!ready && failures==1 && messages.any { "event=video_decoder_or_gl " in it });assertions++
|
||||
} else {
|
||||
check(ready && first==0 && native.videoSurface==null);assertions++
|
||||
native.info!!(native,MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START,0);check(first==0);assertions++
|
||||
port.start();check(first==1 && native.started);assertions++
|
||||
reported.forEach(port::latched)
|
||||
check(failures==0 && ended==0);assertions++
|
||||
when(mode) {
|
||||
"report_clock","early_audio_end" -> {
|
||||
if(mode=="early_audio_end") {
|
||||
native.completion!!(native);check(failures==1 && ended==0);assertions++
|
||||
} else {
|
||||
TestScheduler.advanceBy(1200);check(ended==0);assertions++
|
||||
native.completion!!(native)
|
||||
check(ended==1 && failures==0 && messages.any { "event=final_codec_frame " in it });assertions++
|
||||
}
|
||||
}
|
||||
"native_error" -> { native.error!!(native,1,2);check(failures==1 && ended==0);assertions++ }
|
||||
"missing_audio_end" -> { TestScheduler.advanceBy(3300);check(failures==1 && ended==0);assertions++ }
|
||||
}
|
||||
}
|
||||
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.
|
||||
val prior=ended;reported.forEach(port::latched);TestScheduler.advanceBy(100)
|
||||
check(ended==prior && release==1);assertions++
|
||||
}
|
||||
class Player: ActionPlayer {
|
||||
lateinit var end: (ActionEnd)->Unit;lateinit var failure: ()->Unit;lateinit var release: ()->Unit
|
||||
@@ -61,6 +82,7 @@ fun playbackDiagnosticCheck() {
|
||||
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 }
|
||||
index.actionPack?.assets?.mapNotNull { it.media }?.forEach { android.media.CodecFixture.timelines[it.root+it.path]=it.ptsUs;android.media.CodecFixture.audioPaths.add(it.root+it.path) }
|
||||
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})
|
||||
|
||||
Reference in New Issue
Block a user