初始化 TTVideoPlayer 工程:模块化播放框架、同同影音 App 与文档

Media3 内核播放框架(player-api/core/media3/source/render/lifecycle/telemetry)、
WebDAV/SMB/Jellyfin 来源、DLNA/Google Cast 投屏、RTMP 原生库与完整 App。
This commit is contained in:
tongtong committed 2026-11-30 18:13:40 +08:00
commit 922ec80bcc
147 files changed
+20169

No files matched your search

@@ -0,0 +1,44 @@
package com.ttstd.player.telemetry
import com.ttstd.player.api.*
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
/** 接收结构化数据;sink 应快速返回,上传由业务队列处理,不能阻塞播放器。 */
fun interface TelemetrySink { fun record(name: String, attributes: Map<String, String>) }
/** 不上传 URI/headers。会话标识由业务给出,不使用媒体地址充当标识。
* 流可能丢弃诊断事件,不用于计费。close 后停止采集,不释放播放器。
*/
class PlaybackTelemetry(
engine: PlayerEngine,
scope: CoroutineScope,
sessionId: String,
sink: TelemetrySink,
) : AutoCloseable {
private val job = SupervisorJob(scope.coroutineContext[Job])
private val collector = CoroutineScope(scope.coroutineContext + job)
init {
fun record(name: String, attrs: Map<String, String> = emptyMap()) {
// 业务 sink 异常不得终止采集或影响播放。
runCatching { sink.record(name, attrs + mapOf("sessionId" to sessionId, "engine" to engine.capabilities.engineName)) }
}
collector.launch(start = CoroutineStart.UNDISPATCHED) {
engine.events.collect { event ->
when (event) {
PlaybackEvent.FirstFrame -> record("first_frame")
PlaybackEvent.Ended -> record("ended")
is PlaybackEvent.Error -> record("error", mapOf("code" to event.error.code))
is PlaybackEvent.DecoderChanged -> record("decoder", mapOf("type" to event.type.name, "name" to event.name, "hardware" to (event.isHardware?.toString() ?: "unknown")))
is PlaybackEvent.DroppedFrames -> record("dropped_frames", mapOf("count" to "${event.count}", "elapsedMs" to "${event.elapsedMs}"))
is PlaybackEvent.StartupTime -> record("startup", mapOf("elapsedMs" to "${event.elapsedMs}"))
is PlaybackEvent.VideoSize -> record("video_size", mapOf("width" to "${event.width}", "height" to "${event.height}"))
}
}
}
collector.launch(start = CoroutineStart.UNDISPATCHED) {
engine.state.map { it.phase }.distinctUntilChanged().collect { record("phase", mapOf("value" to it.name)) }
}
}
override fun close() { job.cancel() }
}