diff --git a/tools/chatgui-android/app/src/main/java/com/utun/chat/data/StreamPlayerEngine.kt b/tools/chatgui-android/app/src/main/java/com/utun/chat/data/StreamPlayerEngine.kt index 08ce0ccb..0b535bea 100644 --- a/tools/chatgui-android/app/src/main/java/com/utun/chat/data/StreamPlayerEngine.kt +++ b/tools/chatgui-android/app/src/main/java/com/utun/chat/data/StreamPlayerEngine.kt @@ -205,6 +205,12 @@ class StreamPlayerEngine(private val group: Long, private val source: Long, priv if (index >= 0) { val eos = info.flags and MediaCodec.BUFFER_FLAG_END_OF_STREAM != 0 output = StreamDecodePump.Output(index, info.presentationTimeUs, eos, eos && info.size == 0) + if (!output.empty && video.firstOutputPts == null) { + val decodedAtUs = System.nanoTime() / 1000 + LogManager.addLog("INFO", "video", "viewer first decoded frame id=$id revision=$videoRevision " + + "PTS=${output.pts} inputs=${video.inputCount} decoderLeadUs=${maxOf(0, video.lastInputPts - output.pts)} " + + "elapsedUs=${decodedAtUs - requestedAtUs} decodeUs=${decodedAtUs - firstInputAtUs}") + } } break } @@ -212,18 +218,15 @@ class StreamPlayerEngine(private val group: Long, private val source: Long, priv output }, release = { output, render -> - decoder!!.releaseOutputBuffer(output.index, render) - if (render) { - lastShownPts = output.pts - if (!firstShown) { - firstShown = true - LogManager.addLog("INFO", "stream", "android first frame id=$id stage=display_submit " + - "elapsedUs=${System.nanoTime() / 1000 - requestedAtUs} PTS=${output.pts} clockUs=$position " + - "readyUs=$ready readyAheadUs=${ready - output.pts} avUs=${output.pts - position} " + - "deviceLeadUs=${playback?.leadUs}") - } - mutableStatus.value = R.string.stream_live + if (render && !firstShown) { + firstShown = true + LogManager.addLog("INFO", "stream", "android first frame id=$id stage=display_submit " + + "elapsedUs=${System.nanoTime() / 1000 - requestedAtUs} PTS=${output.pts} clockUs=$position " + + "readyUs=$ready readyAheadUs=${ready - output.pts} avUs=${output.pts - position} " + + "deviceLeadUs=${playback?.leadUs}") } + decoder!!.releaseOutputBuffer(output.index, render) + if (render) { lastShownPts = output.pts; mutableStatus.value = R.string.stream_live } } ) @@ -318,12 +321,7 @@ class StreamPlayerEngine(private val group: Long, private val source: Long, priv } } if (!ended && (!opened || waitingKey) && System.nanoTime() > deadline) error("Viewer open timeout") - if (!playbackStarted && video.firstOutputPts != null) { - playbackStarted = true - LogManager.addLog("INFO", "video", "viewer first decoded frame id=$id revision=$videoRevision " + - "PTS=${video.firstOutputPts} inputs=${video.inputCount} decoderLeadUs=${video.decoderLeadUs} " + - "elapsedUs=${System.nanoTime() / 1000 - requestedAtUs} decodeUs=${System.nanoTime() / 1000 - firstInputAtUs}") - } + if (!playbackStarted && video.firstOutputPts != null) playbackStarted = true if (playbackStarted && playback != null && ready >= 0) { val lateVideo = !video.ended && (video.firstOutputPts == null || (video.oldestSubmittedPts >= 0 && video.oldestSubmittedPts < position - 10000))