|
|
|
|
@ -60,6 +60,7 @@ class CallVideoEngine(private val context: Context, private val id: Long) {
|
|
|
|
|
private var realtime = false |
|
|
|
|
private var sensorOffset: Long? = null |
|
|
|
|
private var openedAt = 0L |
|
|
|
|
private var lastCaptureAt = 0L |
|
|
|
|
private var reportAt = 0L |
|
|
|
|
private var encodedBytes = 0L |
|
|
|
|
private var encodedFrames = 0 |
|
|
|
|
@ -119,6 +120,7 @@ class CallVideoEngine(private val context: Context, private val id: Long) {
|
|
|
|
|
if (stopped) return |
|
|
|
|
try { |
|
|
|
|
val s = CallVideoNative.status(id) ?: return |
|
|
|
|
check(s[5] == 0L) { "Core rejected video format" } |
|
|
|
|
if (s[6] >= 300000 && s[7] >= s[6]) mutable.value = mutable.value.copy(range = CallVideoBitrateRange((s[6] / 1000).toInt(), (s[7] / 1000).toInt())) |
|
|
|
|
if (keySerial != s[0]) { keySerial = s[0]; needKey = true } |
|
|
|
|
val current = format |
|
|
|
|
@ -145,7 +147,8 @@ class CallVideoEngine(private val context: Context, private val id: Long) {
|
|
|
|
|
if (peer != null) change(peer) |
|
|
|
|
} |
|
|
|
|
drain() |
|
|
|
|
if (active != null && System.nanoTime() - openedAt > 8_000_000_000 && lastPts < 0) fail("Camera produced no frames") |
|
|
|
|
if (active != null && !opening && !closing && lastCaptureAt != 0L |
|
|
|
|
&& System.nanoTime() - lastCaptureAt > 8_000_000_000) fail("Camera stopped producing frames") |
|
|
|
|
} catch (e: Exception) { fail("Video worker: ${e.message}") } |
|
|
|
|
if (!stopped) handler.postDelayed(::tick, 10) |
|
|
|
|
} |
|
|
|
|
@ -202,6 +205,7 @@ class CallVideoEngine(private val context: Context, private val id: Long) {
|
|
|
|
|
try { |
|
|
|
|
if (stopped || token != cameraToken || !wanted.enabled) return@setOnImageAvailableListener |
|
|
|
|
val now = System.nanoTime() |
|
|
|
|
lastCaptureAt = now |
|
|
|
|
val offset = if (realtime) now - SystemClock.elapsedRealtimeNanos() else sensorOffset ?: (now - image.timestamp).also { |
|
|
|
|
sensorOffset = it; LogManager.addLog("WARN", "call", "camera timestamp calibrated from arrival id=$id offset=$it") |
|
|
|
|
} |
|
|
|
|
@ -229,7 +233,7 @@ class CallVideoEngine(private val context: Context, private val id: Long) {
|
|
|
|
|
} catch (e: Exception) { fail("Camera encode: ${e.message}") } |
|
|
|
|
finally { image.close() } |
|
|
|
|
}, handler) |
|
|
|
|
opening = true; openedAt = System.nanoTime() |
|
|
|
|
opening = true; openedAt = System.nanoTime(); lastCaptureAt = openedAt |
|
|
|
|
manager.openCamera(settings.camera, object : CameraDevice.StateCallback() { |
|
|
|
|
override fun onOpened(device: CameraDevice) { |
|
|
|
|
opening = false; camera = device |
|
|
|
|
|