Run real call video receive tests with controlled native and codec boundaries

This commit is contained in:
evgeny committed 2026-10-29 13:34:24 +01:00
1 parent a13213335e
commit e7cae9f03f
3 files changed
+77 -1

No files matched your search

+1 -1
View File
@@ -84,7 +84,7 @@ val testJniLog by tasks.registering(Exec::class) {
// Зависимость только между задачами: host-модели не входят в classpath приложения/APK.
tasks.withType<org.gradle.api.tasks.testing.Test>().configureEach {
dependsOn(":router-tests:test", ":capture-tests:test", ":language-tests:test", ":call-service-tests:test", testJniLog)
dependsOn(":router-tests:test", ":capture-tests:test", ":language-tests:test", ":call-service-tests:test", ":video-tests:test", testJniLog)
val messageLinkCases = rootProject.file("../chatgui/tests/message_links_cases.tsv")
inputs.file(messageLinkCases)
systemProperty("utun.messageLinkCases", messageLinkCases.absolutePath)
@@ -21,3 +21,4 @@ include(":router-tests")
include(":capture-tests")
include(":language-tests")
include(":call-service-tests")
include(":video-tests")
@@ -0,0 +1,75 @@
package com.utun.chat.data
import android.media.MediaCodec
import android.media.MediaFormat
import java.util.concurrent.ConcurrentLinkedQueue
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.CopyOnWriteArrayList
import java.util.concurrent.atomic.AtomicLong
/** Только журнал приложения; тест проверяет диагностику настоящего RX. */
object LogManager {
data class Entry(val level: String, val category: String, val message: String)
val entries = CopyOnWriteArrayList<Entry>()
fun addLog(level: String, category: String, message: String) {
entries.add(Entry(level, category, message)); System.err.println("[$level] [$category] $message")
}
}
/** Граница аппаратной пробы; сам RX и разбор uAV2 KEY компилируются из приложения. */
class CallVideoCodec { companion object {
data class DecoderMode(val name: String = "host.decoder", val pipeline: Int = 0) {
fun supports(format: CallVideoFormat) = format.codec == 1
}
data class Decoder(val modes: List<DecoderMode> = listOf(DecoderMode()))
fun validateKey(bytes: ByteArray, format: CallVideoFormat) { StreamVideoCodec.fromId(format.codec).unpackKey(bytes) }
fun decoderFormat(format: CallVideoFormat, decoder: MediaCodec, config: ByteArray): MediaFormat =
StreamVideoCodec.fromId(format.codec).decoderFormat(format.width, format.height, format.rotation, config)
} }
object NativeLib {
fun callAudioClock(id: Long, now: Long, out: LongArray): Boolean { out[5] = 1; return true }
}
/** Native playout/encoded FIFO: только управляемые границы, без загрузки JNI/декодирования/сетевого ядра. */
object CallVideoNative {
data class Frame(val format: CallVideoFormat, val pts: Long, val bytes: ByteArray, val key: Boolean = true)
val frames = ConcurrentLinkedQueue<Frame>()
val live = ConcurrentHashMap.newKeySet<Long>()
val rejected = CopyOnWriteArrayList<Long>()
val accepted = CopyOnWriteArrayList<Long>()
val presented = CopyOnWriteArrayList<Long>()
val counter = AtomicLong()
@Volatile var failures = emptySet<String>()
@Volatile var onCreate: () -> Unit = {}
@Volatile var onPull: () -> Unit = {}
val destroys = CopyOnWriteArrayList<Long>()
val keyRequests = AtomicLong()
fun reset() {
frames.clear(); live.clear(); rejected.clear(); accepted.clear(); presented.clear(); destroys.clear()
failures = emptySet(); onCreate = {}; onPull = {}; keyRequests.set(0)
}
private fun access(operation: String) { check(operation !in failures) { "native $operation failed" } }
fun playoutCreate(id: Long): Long {
onCreate(); access("create")
if ("create zero" in failures) return 0
return counter.incrementAndGet().also { live.add(it) }
}
fun playoutDestroy(handle: Long) { access("destroy"); check(live.remove(handle)); destroys.add(handle) }
fun playoutReset(handle: Long) { access("reset"); check(handle in live) }
fun playoutStep(handle: Long, pts: Long, received: Long, now: Long, interval: Int, queued: Int, reserve: Int): Long {
access("step"); check(handle in live); return 0
}
fun playoutPresented(handle: Long, pts: Long, now: Long) { access("presented"); check(handle in live); presented.add(pts) }
fun requestKey(id: Long) { access("key"); keyRequests.incrementAndGet() }
fun pull(id: Long, meta: LongArray): ByteArray? {
onPull(); access("pull")
val frame = frames.poll() ?: return null
frame.format.array().copyInto(meta); meta[9] = 1; meta[10] = frame.pts; meta[11] = if (frame.key) 1 else 0
meta[12] = System.nanoTime() / 1000
return frame.bytes
}
fun decoded(id: Long, generation: Long, success: Boolean) {
access("decoded"); (if (success) accepted else rejected).add(generation)
}
}