68 lines
4.1 KiB
Kotlin
68 lines
4.1 KiB
Kotlin
import com.gorios.lanvoice.avatar.*
|
|
import android.os.TestScheduler
|
|
import android.media.CodecFixture
|
|
import android.media.MediaPlayer
|
|
import android.view.TextureView
|
|
|
|
/** Fixed numeric metadata from code20 offline report, no user media or conversation. */
|
|
fun reportedActionClockCheck() {
|
|
var checks=0
|
|
val base=mediaFixtureIndex().actionPack!!.assets.first().media!!
|
|
val media=base.copy(ptsUs=List(241) { it*1_000_000L/24 },durationUs=10_041_667,audioEndUs=10_000_000)
|
|
for(mode in listOf("report_first_zero","report_first_epoch","rounding_1us","invalid_codec_timebase","missing_source_zero","missing_source_final","cancel_late_callbacks")) {
|
|
TestScheduler.reset();CodecFixture.reset();MediaPlayer.created.clear();CodecFixture.emitNativeSurface=true
|
|
CodecFixture.audioPaths.add(media.root+media.path)
|
|
CodecFixture.timelines[media.root+media.path]=when(mode) {
|
|
"missing_source_zero"->media.ptsUs.drop(1)
|
|
"missing_source_final"->media.ptsUs.dropLast(1)
|
|
else->media.ptsUs
|
|
}
|
|
CodecFixture.timestampOffsetUs=when(mode) { "rounding_1us"->1;"invalid_codec_timebase"->47_741_893_941;else->0 }
|
|
val output=TextureView(android.content.Context());val messages=mutableListOf<String>()
|
|
val port=AndroidMusicPort(android.content.Context(),output,messages::add)
|
|
var ready=false;var first=0;var end=0;var failures=0
|
|
port.prepare(media,{ready=true},{first++},{end++},{failures++})
|
|
val audio=MediaPlayer.created.single();audio.prepared!!(audio)
|
|
port.latched(0);audio.info!!(audio,MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START,0)
|
|
check(first==0 && end==0);checks++ // Neither output timestamp nor info grants source entry.
|
|
TestScheduler.until { ready || failures>0 }
|
|
if(mode in setOf("invalid_codec_timebase","missing_source_zero")) {
|
|
check(!ready && failures==1 && end==0);checks++
|
|
} else {
|
|
check(ready && audio.videoSurface==null && first==0) { "mode=$mode ready=$ready failures=$failures" };checks++
|
|
port.start();check(first==1);checks++
|
|
if(mode=="cancel_late_callbacks") {
|
|
val stale=audio.completion!!;var releases=0
|
|
TestScheduler.advanceBy(249);port.latched(47_741_893_941_000)
|
|
port.close { releases++ };TestScheduler.advanceBy(1)
|
|
stale(audio);audio.error!!(audio,1,2);TestScheduler.advanceBy(11_000)
|
|
check(releases==1 && end==0 && failures==0 && audio.released);checks++
|
|
} else {
|
|
repeat(241) { i->
|
|
// An EGL output update can skip, use0, an epoch clock, ns, or a repeated value.
|
|
// None may be relabelled as a source frame or satisfy completion.
|
|
TestScheduler.advanceBy(42)
|
|
port.latched(when {
|
|
mode=="report_first_zero" && i==0->0
|
|
i==0->47_742_026_182_000
|
|
i%17==0->0
|
|
i%13==0->41_666_000
|
|
else->47_741_893_941_000+i*41_666_000L
|
|
})
|
|
if(mode!="missing_source_final") { check(failures==0 && end==0);checks++ }
|
|
}
|
|
if(mode=="missing_source_final") { check(failures==1 && end==0);checks++ }
|
|
else {
|
|
audio.currentPosition=10_042;audio.completion!!(audio)
|
|
TestScheduler.until { end==1 || failures>0 }
|
|
check(end==1 && failures==0 && messages.any { "event=final_codec_frame " in it && "frame=240 " in it && "pts_us=${10_000_000L+CodecFixture.timestampOffsetUs} " in it });checks++
|
|
audio.completion!!(audio);check(end==1);checks++
|
|
}
|
|
}
|
|
}
|
|
var released=false;port.close { released=true };TestScheduler.advanceBy(1)
|
|
check(released && audio.released);checks++
|
|
}
|
|
println("PASS: $checks production code20 report-clock replay/full241-source-frame/zero-epoch-output/1us-rounding/invalid-codec-timebase/missing-source-endpoint/native-end/cancel-release assertions; native Android/GPU not_run")
|
|
}
|