Initialize Android playback before handling its first media packet
This commit is contained in:
1 parent
acf374df4e
commit
f3bc2909e1
1 file changed
+12
-10
@@ -74,6 +74,16 @@ class StreamPlayerEngine(private val group: Long, private val source: Long, priv
|
||||
val info = MediaCodec.BufferInfo()
|
||||
var clockState: LongArray? = null
|
||||
|
||||
fun observeStatus(meta: LongArray?) {
|
||||
if (meta == null || meta[5] and 1 == 0L) return
|
||||
ready = if (localPreview != null) meta[1] else meta[0]
|
||||
if (playback != 0L) return
|
||||
audioEnabled = localPreview == null && meta[5] and 2 != 0L
|
||||
playback = NativeLib.streamPlaybackCreate(id, meta[3], audioEnabled)
|
||||
check(playback != 0L); position = meta[3]; generation = meta[4]
|
||||
LogManager.addLog("INFO", "stream", "playback starts id=$id PTS=$position generation=$generation fixedPrefill=0")
|
||||
}
|
||||
|
||||
fun resetVideo() {
|
||||
try { decoder?.stop(); decoder?.release() }
|
||||
catch (e: Exception) { LogManager.addLog("WARN", "video", "decoder reset id=$id: ${e.message}") }
|
||||
@@ -128,16 +138,7 @@ class StreamPlayerEngine(private val group: Long, private val source: Long, priv
|
||||
check(NativeLib.streamOpen(id, group, source, audio = localPreview == null, epoch = epoch)) { "Viewer open refused" }
|
||||
while (running && surface.isValid) {
|
||||
check(NativeLib.isReady()) { "Core stopped" }
|
||||
val meta = NativeLib.streamStatus(id)
|
||||
if (meta != null && meta[5] and 1 != 0L) {
|
||||
ready = if (localPreview != null) meta[1] else meta[0]
|
||||
if (playback == 0L) {
|
||||
audioEnabled = localPreview == null && meta[5] and 2 != 0L
|
||||
playback = NativeLib.streamPlaybackCreate(id, meta[3], audioEnabled)
|
||||
check(playback != 0L); position = meta[3]; generation = meta[4]
|
||||
LogManager.addLog("INFO", "stream", "playback starts id=$id PTS=$position generation=$generation fixedPrefill=0")
|
||||
}
|
||||
}
|
||||
observeStatus(NativeLib.streamStatus(id))
|
||||
val now = System.nanoTime()
|
||||
val played = playedFrames(now)
|
||||
val deviceLead = (written - played).coerceAtLeast(0) * 1_000_000 / 48000
|
||||
@@ -153,6 +154,7 @@ class StreamPlayerEngine(private val group: Long, private val source: Long, priv
|
||||
val broadcastRotation = b.short.toInt() and 65535; val pts = b.long; val size = b.int
|
||||
val revision = b.int.toLong() and 0xffffffffL
|
||||
check(size == b.remaining())
|
||||
if (kind in 1..2 && playback == 0L) observeStatus(NativeLib.streamStatus(id))
|
||||
when (kind) {
|
||||
1 -> {
|
||||
val camera = localPreview?.camera(revision)
|
||||
|
||||
Reference in new issue
Block a user