|
|
|
@@ -0,0 +1,126 @@
|
|
|
|
|
package tv.orbit.classic
|
|
|
|
|
|
|
|
|
|
import android.app.Activity
|
|
|
|
|
import android.net.Uri
|
|
|
|
|
import android.os.Bundle
|
|
|
|
|
import android.os.Handler
|
|
|
|
|
import android.os.Looper
|
|
|
|
|
import android.os.SystemClock
|
|
|
|
|
import android.view.WindowManager
|
|
|
|
|
import androidx.media3.common.C
|
|
|
|
|
import androidx.media3.common.MediaItem
|
|
|
|
|
import androidx.media3.common.PlaybackException
|
|
|
|
|
import androidx.media3.common.Player
|
|
|
|
|
import androidx.media3.common.Tracks
|
|
|
|
|
import androidx.media3.datasource.DefaultDataSource
|
|
|
|
|
import androidx.media3.exoplayer.ExoPlayer
|
|
|
|
|
import androidx.media3.exoplayer.source.DefaultMediaSourceFactory
|
|
|
|
|
import androidx.media3.ui.PlayerView
|
|
|
|
|
import org.json.JSONObject
|
|
|
|
|
import java.io.File
|
|
|
|
|
import java.security.MessageDigest
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The playback test for AVI and frame-rate matching (Paul, 9 November 2026). It's in the playtest build only (a separate app
|
|
|
|
|
* with its own data), opened from adb only, and plays only the approved test clips (assets/playtest-approved.txt, checked by
|
|
|
|
|
* SHA-256) from its own folder, through Orbit's own player set-up, container rule and frame-rate matcher:
|
|
|
|
|
* adb push fps-25.mkv /sdcard/Android/data/tv.orbit.classic.playtest/files/playtest/
|
|
|
|
|
* adb shell am start -W -n tv.orbit.classic.playtest/tv.orbit.classic.PlaytestFileActivity --es file fps-25.mkv --es frame_rate on --es avi off
|
|
|
|
|
* The switches apply to this one test run only, in memory. Each run follows the same script:
|
|
|
|
|
* - play from the start;
|
|
|
|
|
* - at 8 s, seek to 40 s (as tuning in mid-programme does);
|
|
|
|
|
* - at 16 s, stop and reopen at the same point (recovery);
|
|
|
|
|
* - at 26 s, end and put the display mode back.
|
|
|
|
|
* If a playback error happens, it's retried once. Results go to files/playtest/results/<file>.json and to logcat (tag
|
|
|
|
|
* OrbitPlaytest): the container decision, formats, decoder support, frame rate, display mode before and after, first-frame
|
|
|
|
|
* time, stalls, errors and recovery.
|
|
|
|
|
*/
|
|
|
|
|
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
|
|
|
|
|
class PlaytestFileActivity : Activity() {
|
|
|
|
|
private val main = Handler(Looper.getMainLooper())
|
|
|
|
|
private val result = JSONObject()
|
|
|
|
|
private var player: ExoPlayer? = null
|
|
|
|
|
private var startedAt = 0L
|
|
|
|
|
private var ready = false
|
|
|
|
|
private var stalls = 0
|
|
|
|
|
private var retried = false
|
|
|
|
|
private var reopenedAt = 0L
|
|
|
|
|
private var finished = false
|
|
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
|
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
|
|
|
|
val name = intent.getStringExtra("file").orEmpty()
|
|
|
|
|
PlayerSwitches.avi = intent.getStringExtra("avi") == "on"
|
|
|
|
|
PlayerSwitches.frameRate = intent.getStringExtra("frame_rate") == "on"
|
|
|
|
|
result.put("file", name).put("avi", PlayerSwitches.avi).put("frameRate", PlayerSwitches.frameRate)
|
|
|
|
|
val approved = assets.open("playtest-approved.txt").bufferedReader().readLines().mapNotNull { l -> l.split(' ').takeIf { it.size == 2 }?.let { it[0] to it[1] } }.toMap()
|
|
|
|
|
val file = File(getExternalFilesDir("playtest"), name)
|
|
|
|
|
val refusal = when {
|
|
|
|
|
name !in approved -> "not an approved test file"
|
|
|
|
|
!file.isFile -> "not found in the playtest folder"
|
|
|
|
|
sha256(file) != approved[name] -> "checksum doesn't match the approved file"
|
|
|
|
|
supportedDirectContainer(name.substringAfterLast('.')) == null -> "container not played directly (as Orbit: unplayable, left out of plans)"
|
|
|
|
|
else -> null
|
|
|
|
|
}
|
|
|
|
|
if (refusal != null) { result.put("outcome", "refused").put("reason", refusal); end(); return }
|
|
|
|
|
val view = PlayerView(this).apply { useController = false }
|
|
|
|
|
setContentView(view)
|
|
|
|
|
result.put("modeBefore", modeNow())
|
|
|
|
|
val p = ExoPlayer.Builder(this, programmeRenderers(this)).setLoadControl(programmeLoadControl())
|
|
|
|
|
.setMediaSourceFactory(DefaultMediaSourceFactory(DefaultDataSource.Factory(this), OrbitExtractorsFactory())).build()
|
|
|
|
|
player = p; view.player = p
|
|
|
|
|
p.addListener(object : Player.Listener {
|
|
|
|
|
override fun onTracksChanged(tracks: Tracks) {
|
|
|
|
|
val video = tracks.groups.firstOrNull { it.type == C.TRACK_TYPE_VIDEO }
|
|
|
|
|
val audio = tracks.groups.firstOrNull { it.type == C.TRACK_TYPE_AUDIO }
|
|
|
|
|
video?.getTrackFormat(0)?.let { f -> result.put("video", JSONObject().put("mime", f.sampleMimeType).put("codecs", f.codecs).put("width", f.width)
|
|
|
|
|
.put("height", f.height).put("fps", f.frameRate.toDouble()).put("decoder", video.isSupported)) }
|
|
|
|
|
audio?.getTrackFormat(0)?.let { f -> result.put("audio", JSONObject().put("mime", f.sampleMimeType).put("decoder", audio.isSupported)) }
|
|
|
|
|
if (video != null && !video.isSupported) { result.put("outcome", "no video decoder (as Orbit: unplayable, moves on)"); end(); return }
|
|
|
|
|
if (PlayerSwitches.frameRate) video?.getTrackFormat(0)?.frameRate?.let { FrameRateMatch.apply(window, it) }
|
|
|
|
|
main.postDelayed({ result.put("modeDuring", modeNow()) }, 4_000)
|
|
|
|
|
}
|
|
|
|
|
override fun onRenderedFirstFrame() {
|
|
|
|
|
if (!result.has("firstFrameMs")) result.put("firstFrameMs", SystemClock.elapsedRealtime() - startedAt)
|
|
|
|
|
if (reopenedAt > 0 && !result.has("recoveredMs")) result.put("recoveredMs", SystemClock.elapsedRealtime() - reopenedAt)
|
|
|
|
|
}
|
|
|
|
|
override fun onPlaybackStateChanged(state: Int) {
|
|
|
|
|
if (state == Player.STATE_BUFFERING && ready) stalls++
|
|
|
|
|
if (state == Player.STATE_READY) ready = true
|
|
|
|
|
}
|
|
|
|
|
override fun onPlayerError(error: PlaybackException) {
|
|
|
|
|
result.accumulate("errors", error.errorCodeName)
|
|
|
|
|
if (!retried) { retried = true; ready = false; p.prepare(); p.play() }
|
|
|
|
|
else { result.put("outcome", "failed after one retry"); end() }
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
startedAt = SystemClock.elapsedRealtime()
|
|
|
|
|
p.setMediaItem(MediaItem.fromUri(Uri.fromFile(file))); p.prepare(); p.play()
|
|
|
|
|
main.postDelayed({ p.seekTo(40_000) }, 8_000)
|
|
|
|
|
main.postDelayed({ val at = p.currentPosition; ready = false; p.stop(); reopenedAt = SystemClock.elapsedRealtime(); p.seekTo(at); p.prepare(); p.play() }, 16_000)
|
|
|
|
|
main.postDelayed({ if (!result.has("outcome")) result.put("outcome", if (result.has("recoveredMs")) "played" else "played, but didn't recover after reopening"); end() }, 26_000)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun modeNow(): String = window.decorView.display?.mode?.let { "${it.physicalWidth}x${it.physicalHeight}@${"%.3f".format(it.refreshRate)}" } ?: "unknown"
|
|
|
|
|
|
|
|
|
|
private fun end() {
|
|
|
|
|
if (finished) return
|
|
|
|
|
finished = true
|
|
|
|
|
main.removeCallbacksAndMessages(null)
|
|
|
|
|
result.put("stalls", stalls).put("retried", retried)
|
|
|
|
|
player?.let { result.put("positionMs", it.currentPosition); it.release() }
|
|
|
|
|
FrameRateMatch.reset(window)
|
|
|
|
|
main.postDelayed({
|
|
|
|
|
result.put("modeAfter", modeNow())
|
|
|
|
|
val out = File(getExternalFilesDir("playtest"), "results").apply { mkdirs() }
|
|
|
|
|
File(out, "${result.optString("file").ifBlank { "unnamed" }.replace('/', '_')}.json").writeText(result.toString(2))
|
|
|
|
|
android.util.Log.i("OrbitPlaytest", result.toString())
|
|
|
|
|
finish()
|
|
|
|
|
}, 3_000)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onStop() { super.onStop(); if (!finished) { result.put("outcome", "left early"); end() } }
|
|
|
|
|
|
|
|
|
|
private fun sha256(f: File) = MessageDigest.getInstance("SHA-256").digest(f.readBytes()).joinToString("") { "%02x".format(it) }
|
|
|
|
|
}
|