Skip to content

Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.

Reduce Android webcam preview and packet overhead

AS8148316fd0563c95
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/ui/webcam/WebcamPreviewView.kt b/android/app/src/main/kotlin/app/nectarlink/android/ui/webcam/WebcamPreviewView.kt
new file mode 100644
index 0000000..c1ccbcd
--- /dev/null
+++ b/android/app/src/main/kotlin/app/nectarlink/android/ui/webcam/WebcamPreviewView.kt
@@ -0,0 +1,76 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+package app.nectarlink.android.ui.webcam
+
+import android.content.Context
+import android.graphics.Outline
+import android.view.SurfaceHolder
+import android.view.SurfaceView
+import android.view.View
+import android.view.ViewOutlineProvider
+import androidx.compose.ui.geometry.Size
+import androidx.compose.ui.graphics.Path
+import androidx.compose.ui.graphics.Shape
+import androidx.compose.ui.graphics.asAndroidPath
+import androidx.compose.ui.unit.Density
+import androidx.compose.ui.unit.LayoutDirection
+import app.nectarlink.android.webcam.WebcamPreviewTarget
+
+/** Display sink only: destroying this surface never reconfigures the camera. */
+internal class WebcamPreviewView(
+ context: Context,
+ private val onTargetChanged: (WebcamPreviewTarget?) -> Unit,
+) : SurfaceView(context), SurfaceHolder.Callback {
+ private var enabled = false
+ private var surfaceWidth = 0
+ private var surfaceHeight = 0
+
+ init {
+ holder.addCallback(this)
+ clipToOutline = true
+ }
+
+ fun setPreviewVisible(visible: Boolean) {
+ enabled = visible
+ publishTarget()
+ }
+
+ private fun publishTarget() {
+ onTargetChanged(if (enabled && holder.surface.isValid && surfaceWidth > 0 && surfaceHeight > 0) {
+ WebcamPreviewTarget(holder.surface, surfaceWidth, surfaceHeight)
+ } else null)
+ }
+
+ override fun surfaceCreated(holder: SurfaceHolder) {}
+
+ override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
+ surfaceWidth = width
+ surfaceHeight = height
+ publishTarget()
+ }
+
+ override fun surfaceDestroyed(holder: SurfaceHolder) {
+ surfaceWidth = 0
+ surfaceHeight = 0
+ onTargetChanged(null)
+ }
+
+ fun setPreviewShape(shape: Shape, density: Density, direction: LayoutDirection) {
+ outlineProvider = object : ViewOutlineProvider() {
+ override fun getOutline(view: View, outline: Outline) {
+ when (val result = shape.createOutline(Size(view.width.toFloat(), view.height.toFloat()), direction, density)) {
+ is androidx.compose.ui.graphics.Outline.Rectangle -> outline.setRect(0, 0, view.width, view.height)
+ is androidx.compose.ui.graphics.Outline.Rounded -> {
+ val path = Path().apply { addRoundRect(result.roundRect) }.asAndroidPath()
+ @Suppress("DEPRECATION")
+ outline.setConvexPath(path)
+ }
+ is androidx.compose.ui.graphics.Outline.Generic -> {
+ @Suppress("DEPRECATION")
+ outline.setConvexPath(result.path.asAndroidPath())
+ }
+ }
+ }
+ }
+ invalidateOutline()
+ }
+}
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/ui/webcam/WebcamScreen.kt b/android/app/src/main/kotlin/app/nectarlink/android/ui/webcam/WebcamScreen.kt
index 1110823..09b7b25 100644
--- a/android/app/src/main/kotlin/app/nectarlink/android/ui/webcam/WebcamScreen.kt
+++ b/android/app/src/main/kotlin/app/nectarlink/android/ui/webcam/WebcamScreen.kt
@@ -4,7 +4,6 @@ package app.nectarlink.android.ui.webcam
import android.Manifest
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
-import androidx.camera.view.PreviewView
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
@@ -47,6 +46,8 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.platform.LocalDensity
+import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.res.painterResource
@@ -55,6 +56,7 @@ import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
+import androidx.lifecycle.compose.LifecycleStartEffect
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import app.nectarlink.android.R
import app.nectarlink.android.core.Device
@@ -129,18 +131,13 @@ fun WebcamScreen(
}
}
- val previewView = remember {
- PreviewView(context).apply {
- scaleType = PreviewView.ScaleType.FILL_CENTER
- implementationMode = PreviewView.ImplementationMode.COMPATIBLE
- }
- }
-
- DisposableEffect(previewView) {
- WebcamService.attachUiPreview(previewView.surfaceProvider)
- onDispose {
- WebcamService.attachUiPreview(null)
- }
+ val previewView = remember { WebcamPreviewView(context, WebcamService::attachUiPreview) }
+ val previewShape = MaterialTheme.shapes.extraLarge
+ val previewDensity = LocalDensity.current
+ val previewDirection = LocalLayoutDirection.current
+ LifecycleStartEffect(previewView) {
+ previewView.setPreviewVisible(true)
+ onStopOrDispose { previewView.setPreviewVisible(false) }
}
val isStreamingHere = session.active && session.pcId == device.id
@@ -245,6 +242,7 @@ fun WebcamScreen(
if (isStreamingHere && hasCameraPermission) {
AndroidView(
factory = { previewView.detached() },
+ update = { it.setPreviewShape(previewShape, previewDensity, previewDirection) },
modifier = Modifier.fillMaxSize(),
)
} else {
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/webcam/CameraEncoder.kt b/android/app/src/main/kotlin/app/nectarlink/android/webcam/CameraEncoder.kt
index f7e1bad..6927b85 100644
--- a/android/app/src/main/kotlin/app/nectarlink/android/webcam/CameraEncoder.kt
+++ b/android/app/src/main/kotlin/app/nectarlink/android/webcam/CameraEncoder.kt
@@ -104,8 +104,7 @@ internal class CameraEncoder(
private var cameraProvider: ProcessCameraProvider? = null
private var boundCamera: Camera? = null
private var encoderPreview: Preview? = null
- private var uiPreview: Preview? = null
- private var pendingUiSurfaceProvider: Preview.SurfaceProvider? = null
+ @Volatile private var pendingUiPreview: WebcamPreviewTarget? = null
private var liveState = CameraLiveState(
width = widthForHeight(targetHeight),
height = targetHeight,
@@ -154,7 +153,6 @@ internal class CameraEncoder(
currentDisplayRotation = surfaceRotationToDegrees(rotation)
activeCodec?.pipe?.setTransform(currentSensorRotation, currentDisplayRotation)
encoderPreview?.targetRotation = rotation
- uiPreview?.targetRotation = rotation
requestKeyframe()
}
@@ -188,7 +186,6 @@ internal class CameraEncoder(
runCatching { cameraProvider?.unbindAll() }
boundCamera = null
encoderPreview = null
- uiPreview = null
}
surfaceExecutor.execute {
activeCodec?.stop()
@@ -245,10 +242,10 @@ internal class CameraEncoder(
}
}
- fun setUiSurfaceProvider(provider: Preview.SurfaceProvider?) {
+ fun setUiPreview(target: WebcamPreviewTarget?) {
main.post {
- pendingUiSurfaceProvider = provider
- uiPreview?.setSurfaceProvider(provider)
+ pendingUiPreview = target
+ activeCodec?.pipe?.setPreviewTarget(target)
}
}
@@ -315,6 +312,7 @@ internal class CameraEncoder(
started.pipe.updateTransform(info.rotationDegrees, info.isMirroring)
}
main.post {
+ if (activeCodec === started) started.pipe.setPreviewTarget(pendingUiPreview)
updateState { it.copy(width = started.width, height = started.height, camera = facingForRequest) }
}
request.provideSurface(inputSurface, surfaceExecutor) {
@@ -326,17 +324,6 @@ internal class CameraEncoder(
}
}
- val previewForUi = Preview.Builder()
- .setResolutionSelector(
- ResolutionSelector.Builder()
- .setAspectRatioStrategy(AspectRatioStrategy.RATIO_16_9_FALLBACK_AUTO_STRATEGY)
- .build(),
- )
- .setTargetRotation(rotation)
- .build()
- .also { it.setSurfaceProvider(pendingUiSurfaceProvider) }
- uiPreview = previewForUi
-
val requestedSelector = if (cameraFacing == "front") {
CameraSelector.DEFAULT_FRONT_CAMERA
} else {
@@ -354,13 +341,8 @@ internal class CameraEncoder(
provider.unbindAll()
val camera = runCatching {
- provider.bindToLifecycle(lifecycleOwner, selector, encPreview, previewForUi)
- }.getOrElse {
- // Fallback for single-stream legacy cameras: bind encPreview alone.
- runCatching {
- provider.bindToLifecycle(lifecycleOwner, selector, encPreview)
- }.getOrNull()
- }
+ provider.bindToLifecycle(lifecycleOwner, selector, encPreview)
+ }.onFailure { Log.w(TAG, "can't bind webcam camera output", it) }.getOrNull()
if (camera == null) {
Log.w(TAG, "failed to bind camera")
@@ -517,20 +499,22 @@ internal class CameraEncoder(
}
val index = codec.dequeueOutputBuffer(info, WAIT_US)
if (index < 0) continue
- val bytes = ByteArray(info.size)
- codec.getOutputBuffer(index)?.let { buf ->
- buf.position(info.offset)
- buf.get(bytes)
- }
- codec.releaseOutputBuffer(index, false)
- if (info.flags and MediaCodec.BUFFER_FLAG_END_OF_STREAM != 0) break
- if (info.flags and MediaCodec.BUFFER_FLAG_CODEC_CONFIG != 0) {
- parameters = bytes
- continue
- }
- if (bytes.isEmpty()) continue
val key = info.flags and MediaCodec.BUFFER_FLAG_KEY_FRAME != 0
- val payload = ensureAudAndParameters(bytes, parameters, key, codecName)
+ val payload = try {
+ if (info.flags and MediaCodec.BUFFER_FLAG_END_OF_STREAM != 0) break
+ val buffer = codec.getOutputBuffer(index) ?: continue
+ if (info.flags and MediaCodec.BUFFER_FLAG_CODEC_CONFIG != 0) {
+ parameters = ByteArray(info.size)
+ buffer.position(info.offset)
+ buffer.get(parameters)
+ continue
+ }
+ if (info.size == 0) continue
+ WebcamPacket.frame(buffer, info.offset, info.size, parameters, key, codecName)
+ } finally {
+ // The queued packet owns its bytes; release the codec slot before sending.
+ codec.releaseOutputBuffer(index, false)
+ }
val result = stream.send(
if (key) VideoPacketKind.KEYFRAME else VideoPacketKind.FRAME,
info.presentationTimeUs.toULong(),
@@ -562,10 +546,6 @@ internal class CameraEncoder(
private const val WAIT_US = 40_000L
private const val I_FRAME_INTERVAL_SEC = 2
- /** Annex B Access Unit Delimiter NAL (`00 00 00 01 09 F0`). */
- internal val AUD_NAL = byteArrayOf(0x00, 0x00, 0x00, 0x01, 0x09, 0xF0.toByte())
- internal val HEVC_AUD_NAL = byteArrayOf(0, 0, 0, 1, 0x46, 1, 0x50)
-
/** Only offer hardware HEVC encoding at the actual requested size/rate. */
private fun hevcEncoder(width: Int, height: Int, fps: Int): String? = runCatching {
MediaCodecList(MediaCodecList.REGULAR_CODECS).codecInfos.firstOrNull { info ->
@@ -714,49 +694,5 @@ internal class CameraEncoder(
}.getOrDefault(false)
}
- /**
- * Guarantees each access unit starts with the codec's Annex B Access
- * Unit Delimiter and keyframes include the cached parameter sets
- * (SPS/PPS for AVC, VPS/SPS/PPS for HEVC) right after the AUD so the PC's
- * Media Foundation decoder flushes every frame immediately.
- */
- internal fun ensureAudAndParameters(
- bytes: ByteArray,
- parameters: ByteArray,
- isKeyframe: Boolean,
- codecName: String = "h264",
- ): ByteArray {
- val aud = if (codecName == "h265") HEVC_AUD_NAL else AUD_NAL
- val stripped = stripLeadingAud(bytes, codecName)
- return if (isKeyframe && parameters.isNotEmpty()) {
- val cleanParams = stripLeadingAud(parameters, codecName)
- ByteArray(aud.size + cleanParams.size + stripped.size).also { out ->
- System.arraycopy(aud, 0, out, 0, aud.size)
- System.arraycopy(cleanParams, 0, out, aud.size, cleanParams.size)
- System.arraycopy(stripped, 0, out, aud.size + cleanParams.size, stripped.size)
- }
- } else {
- ByteArray(aud.size + stripped.size).also { out ->
- System.arraycopy(aud, 0, out, 0, aud.size)
- System.arraycopy(stripped, 0, out, aud.size, stripped.size)
- }
- }
- }
-
- private fun stripLeadingAud(data: ByteArray, codecName: String): ByteArray {
- fun startCode(at: Int): Int {
- if (at + 3 > data.size || data[at] != 0.toByte() || data[at + 1] != 0.toByte()) return 0
- if (data[at + 2] == 1.toByte()) return 3
- return if (at + 4 <= data.size && data[at + 2] == 0.toByte() && data[at + 3] == 1.toByte()) 4 else 0
- }
- val prefix = startCode(0)
- if (prefix == 0 || prefix >= data.size) return data
- val type = if (codecName == "h265") (data[prefix].toInt() ushr 1) and 0x3F else data[prefix].toInt() and 0x1F
- if (type != if (codecName == "h265") 35 else 9) return data
- for (at in prefix + 1 until data.size) {
- if (startCode(at) != 0) return data.copyOfRange(at, data.size)
- }
- return ByteArray(0)
- }
}
}
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/webcam/FrameQuad.kt b/android/app/src/main/kotlin/app/nectarlink/android/webcam/FrameQuad.kt
new file mode 100644
index 0000000..4fac92a
--- /dev/null
+++ b/android/app/src/main/kotlin/app/nectarlink/android/webcam/FrameQuad.kt
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+package app.nectarlink.android.webcam
+
+import java.nio.ByteBuffer
+import java.nio.ByteOrder
+import java.nio.FloatBuffer
+
+/** GL-thread-owned, reusable position/UV data for the upright FIT_CENTER image. */
+internal class FrameQuad(
+ private val srcWidth: Int,
+ private val srcHeight: Int,
+ private val dstWidth: Int,
+ private val dstHeight: Int,
+ private val fitCenter: Boolean = true,
+) {
+ val buffer: FloatBuffer = ByteBuffer.allocateDirect(16 * 4)
+ .order(ByteOrder.nativeOrder()).asFloatBuffer()
+ private var rotation = -1
+ private var swapsAxes = false
+ private var mirrored = false
+
+ fun update(degrees: Int, sourceSwapsAxes: Boolean, mirror: Boolean): Boolean {
+ val normalized = ((degrees % 360) + 360) % 360
+ if (rotation == normalized && swapsAxes == sourceSwapsAxes && mirrored == mirror) return false
+ rotation = normalized
+ swapsAxes = sourceSwapsAxes
+ mirrored = mirror
+
+ val uvWidth = if (sourceSwapsAxes) srcHeight.toFloat() else srcWidth.toFloat()
+ val uvHeight = if (sourceSwapsAxes) srcWidth.toFloat() else srcHeight.toFloat()
+ val width = if (normalized % 180 != 0) uvHeight else uvWidth
+ val height = if (normalized % 180 != 0) uvWidth else uvHeight
+ val aspect = (width / height.coerceAtLeast(1f)).coerceAtLeast(0.01f)
+ val targetAspect = (dstWidth.toFloat() / dstHeight.coerceAtLeast(1)).coerceAtLeast(0.01f)
+ val scaleX = if (fitCenter) {
+ if (aspect > targetAspect) 1f else aspect / targetAspect
+ } else {
+ if (aspect > targetAspect) aspect / targetAspect else 1f
+ }
+ val sx = scaleX * (if (mirror) -1f else 1f)
+ val sy = if (fitCenter) {
+ if (aspect > targetAspect) targetAspect / aspect else 1f
+ } else {
+ if (aspect > targetAspect) 1f else targetAspect / aspect
+ }
+ val uvs = when (normalized) {
+ 90 -> UV_90
+ 180 -> UV_180
+ 270 -> UV_270
+ else -> UV_0
+ }
+ buffer.position(0)
+ for (i in 0 until 4) {
+ buffer.put(if (i % 2 == 0) -sx else sx)
+ buffer.put(if (i < 2) -sy else sy)
+ buffer.put(uvs[i * 2])
+ buffer.put(uvs[i * 2 + 1])
+ }
+ buffer.position(0)
+ return true
+ }
+
+ private companion object {
+ val UV_0 = floatArrayOf(0f, 0f, 1f, 0f, 0f, 1f, 1f, 1f)
+ val UV_90 = floatArrayOf(0f, 1f, 0f, 0f, 1f, 1f, 1f, 0f)
+ val UV_180 = floatArrayOf(1f, 1f, 0f, 1f, 1f, 0f, 0f, 0f)
+ val UV_270 = floatArrayOf(1f, 0f, 1f, 1f, 0f, 0f, 0f, 1f)
+ }
+}
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/webcam/GlSurfacePipe.kt b/android/app/src/main/kotlin/app/nectarlink/android/webcam/GlSurfacePipe.kt
index 119efd9..d0474ef 100644
--- a/android/app/src/main/kotlin/app/nectarlink/android/webcam/GlSurfacePipe.kt
+++ b/android/app/src/main/kotlin/app/nectarlink/android/webcam/GlSurfacePipe.kt
@@ -13,9 +13,6 @@ import android.opengl.GLES20
import android.os.Handler
import android.os.HandlerThread
import android.view.Surface
-import java.nio.ByteBuffer
-import java.nio.ByteOrder
-import java.nio.FloatBuffer
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
@@ -45,6 +42,7 @@ internal class GlSurfacePipe(
@Volatile private var released = false
private var eglDisplay: EGLDisplay = EGL14.EGL_NO_DISPLAY
+ private var eglConfig: EGLConfig? = null
private var eglContext: EGLContext = EGL14.EGL_NO_CONTEXT
private var eglSurface: EGLSurface = EGL14.EGL_NO_SURFACE
private var oesTexId: Int = 0
@@ -58,10 +56,18 @@ internal class GlSurfacePipe(
private set
private val stMatrix = FloatArray(16)
- private val quadBuffer: FloatBuffer = ByteBuffer
- .allocateDirect(4 * 4 * 4)
- .order(ByteOrder.nativeOrder())
- .asFloatBuffer()
+ private val quad = FrameQuad(srcWidth, srcHeight, dstWidth, dstHeight)
+ private var lastTimestampNs = Long.MIN_VALUE
+ @Volatile private var previewTarget: WebcamPreviewTarget? = null
+ private var previewWindow = EGL14.EGL_NO_SURFACE
+ private var previewWindowTarget: WebcamPreviewTarget? = null
+ private var previewQuad: FrameQuad? = null
+
+ fun setPreviewTarget(target: WebcamPreviewTarget?) {
+ if (released) return
+ previewTarget = target
+ if (target == null) handler.post { if (previewTarget == null) releasePreviewWindow() }
+ }
init {
val ready = CountDownLatch(1)
@@ -91,7 +97,8 @@ internal class GlSurfacePipe(
override fun onFrameAvailable(st: SurfaceTexture?) {
if (released) return
- handler.post { drawFrame() }
+ // SurfaceTexture dispatches this callback on our GL handler already.
+ drawFrame()
}
fun release() {
@@ -127,6 +134,7 @@ internal class GlSurfacePipe(
val numConfigs = IntArray(1)
EGL14.eglChooseConfig(eglDisplay, attribList, 0, configs, 0, 1, numConfigs, 0)
val config = configs[0] ?: return
+ eglConfig = config
val ctxAttribs = intArrayOf(EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL14.EGL_NONE)
eglContext = EGL14.eglCreateContext(eglDisplay, config, EGL14.EGL_NO_CONTEXT, ctxAttribs, 0)
@@ -157,6 +165,7 @@ internal class GlSurfacePipe(
}
private fun drawFrame() {
+ if (released) return
val st = surfaceTexture ?: return
if (eglDisplay === EGL14.EGL_NO_DISPLAY || eglSurface === EGL14.EGL_NO_SURFACE) return
@@ -165,11 +174,11 @@ internal class GlSurfacePipe(
st.getTransformMatrix(stMatrix)
}.onFailure { return }
+ val tsNs = st.timestamp
+ if (tsNs == lastTimestampNs) return
+
// stMatrix is column-major 4x4: stMatrix[0] is dU/dX, stMatrix[1] is dV/dX.
val stSwapsAxes = kotlin.math.abs(stMatrix[1]) > kotlin.math.abs(stMatrix[0])
- // Dimensions of the image in UV space AFTER stMatrix is applied:
- val uvWidth = if (stSwapsAxes) srcHeight.toFloat() else srcWidth.toFloat()
- val uvHeight = if (stSwapsAxes) srcWidth.toFloat() else srcHeight.toFloat()
// If stMatrix already rotated the sensor to Surface.ROTATION_0, we only need
// to compensate for displayRotationDegrees (0 in portrait, 90 in landscape-left,
// 270 in landscape-right, 180 upside-down). Otherwise apply sensorRotationDegrees.
@@ -179,103 +188,68 @@ internal class GlSurfacePipe(
((sensorRotationDegrees % 360) + 360) % 360
}
- val uprightWidth = if (effectiveRot % 180 != 0) uvHeight else uvWidth
- val uprightHeight = if (effectiveRot % 180 != 0) uvWidth else uvHeight
- val srcAspect = (uprightWidth / uprightHeight.coerceAtLeast(1f)).coerceAtLeast(0.01f)
- val dstAspect = (dstWidth.toFloat() / dstHeight.coerceAtLeast(1).toFloat()).coerceAtLeast(0.01f)
-
- // Aspect-preserving FIT_CENTER vertex positions so the camera frame is never stretched:
- val posScaleX: Float
- val posScaleY: Float
- if (srcAspect > dstAspect) {
- posScaleX = 1f
- posScaleY = dstAspect / srcAspect
- } else {
- posScaleX = srcAspect / dstAspect
- posScaleY = 1f
- }
+ quad.update(effectiveRot, stSwapsAxes, mirrorHorizontally && !stSwapsAxes)
- updateQuadVertices(effectiveRot, posScaleX, posScaleY, mirrorHorizontally && !stSwapsAxes)
+ if (renderSurface(eglSurface, dstWidth, dstHeight, quad, tsNs)) lastTimestampNs = tsNs
- GLES20.glViewport(0, 0, dstWidth, dstHeight)
+ val target = previewTarget
+ try {
+ if (target == null || !target.surface.isValid) {
+ releasePreviewWindow()
+ return
+ }
+ if (previewWindowTarget !== target) {
+ releasePreviewWindow()
+ previewWindow = EGL14.eglCreateWindowSurface(eglDisplay, eglConfig, target.surface, intArrayOf(EGL14.EGL_NONE), 0)
+ if (previewWindow === EGL14.EGL_NO_SURFACE) return
+ previewWindowTarget = target
+ previewQuad = FrameQuad(srcWidth, srcHeight, target.width, target.height, fitCenter = false)
+ }
+ val localQuad = previewQuad ?: return
+ localQuad.update(effectiveRot, stSwapsAxes, mirrorHorizontally && !stSwapsAxes)
+ if (!renderSurface(previewWindow, target.width, target.height, localQuad, tsNs)) releasePreviewWindow()
+ } catch (_: Exception) {
+ // A disappearing display must never end the encoder stream.
+ releasePreviewWindow()
+ } finally {
+ EGL14.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)
+ }
+ }
+
+ private fun renderSurface(surface: EGLSurface, width: Int, height: Int, geometry: FrameQuad, timestampNs: Long): Boolean {
+ if (!EGL14.eglMakeCurrent(eglDisplay, surface, surface, eglContext)) return false
+ GLES20.glViewport(0, 0, width, height)
GLES20.glClearColor(0.07f, 0.075f, 0.09f, 1f)
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT)
-
GLES20.glUseProgram(program)
GLES20.glActiveTexture(GLES20.GL_TEXTURE0)
GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, oesTexId)
GLES20.glUniformMatrix4fv(uStMatrixLoc, 1, false, stMatrix, 0)
-
- quadBuffer.position(0)
- GLES20.glVertexAttribPointer(aPositionLoc, 2, GLES20.GL_FLOAT, false, 16, quadBuffer)
+ val vertices = geometry.buffer
+ vertices.position(0)
+ GLES20.glVertexAttribPointer(aPositionLoc, 2, GLES20.GL_FLOAT, false, 16, vertices)
GLES20.glEnableVertexAttribArray(aPositionLoc)
-
- quadBuffer.position(2)
- GLES20.glVertexAttribPointer(aTexCoordLoc, 2, GLES20.GL_FLOAT, false, 16, quadBuffer)
+ vertices.position(2)
+ GLES20.glVertexAttribPointer(aTexCoordLoc, 2, GLES20.GL_FLOAT, false, 16, vertices)
GLES20.glEnableVertexAttribArray(aTexCoordLoc)
-
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4)
-
- val tsNs = st.timestamp
- if (tsNs > 0L) {
- EGLExt.eglPresentationTimeANDROID(eglDisplay, eglSurface, tsNs)
- }
- EGL14.eglSwapBuffers(eglDisplay, eglSurface)
+ if (timestampNs > 0L) EGLExt.eglPresentationTimeANDROID(eglDisplay, surface, timestampNs)
+ return EGL14.eglSwapBuffers(eglDisplay, surface)
}
- private fun updateQuadVertices(
- effectiveRot: Int,
- posScaleX: Float,
- posScaleY: Float,
- mirror: Boolean,
- ) {
- val sx = if (mirror) -posScaleX else posScaleX
- val sy = posScaleY
- val posX = floatArrayOf(-sx, sx, -sx, sx)
- val posY = floatArrayOf(-sy, -sy, sy, sy)
-
- // Base UV corners: bl = (0f, 0f), br = (1f, 0f), tl = (0f, 1f), tr = (1f, 1f)
- // Surface.ROTATION_90 (standard landscape, phone rotated 90° CCW) puts phone's
- // top edge on the left and right edge on the top: bottom-left is tl, bottom-right
- // is bl, top-left is tr, top-right is br.
- val uvs = when (((effectiveRot % 360) + 360) % 360) {
- 90 -> floatArrayOf(
- 0f, 1f, // uv0 = tl
- 0f, 0f, // uv1 = bl
- 1f, 1f, // uv2 = tr
- 1f, 0f, // uv3 = br
- )
- 180 -> floatArrayOf(
- 1f, 1f, // uv0 = tr
- 0f, 1f, // uv1 = tl
- 1f, 0f, // uv2 = br
- 0f, 0f, // uv3 = bl
- )
- 270 -> floatArrayOf(
- 1f, 0f, // uv0 = br
- 1f, 1f, // uv1 = tr
- 0f, 0f, // uv2 = bl
- 0f, 1f, // uv3 = tl
- )
- else -> floatArrayOf(
- 0f, 0f, // uv0 = bl
- 1f, 0f, // uv1 = br
- 0f, 1f, // uv2 = tl
- 1f, 1f, // uv3 = tr
- )
- }
-
- quadBuffer.position(0)
- for (i in 0 until 4) {
- quadBuffer.put(posX[i])
- quadBuffer.put(posY[i])
- quadBuffer.put(uvs[i * 2])
- quadBuffer.put(uvs[i * 2 + 1])
+ private fun releasePreviewWindow() {
+ if (previewWindow !== EGL14.EGL_NO_SURFACE) {
+ EGL14.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)
+ EGL14.eglDestroySurface(eglDisplay, previewWindow)
}
- quadBuffer.position(0)
+ previewWindow = EGL14.EGL_NO_SURFACE
+ previewWindowTarget = null
+ previewQuad = null
}
private fun releaseGl() {
+ previewTarget = null
+ releasePreviewWindow()
runCatching { inputSurface?.release() }
inputSurface = null
runCatching {
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/webcam/WebcamPacket.kt b/android/app/src/main/kotlin/app/nectarlink/android/webcam/WebcamPacket.kt
new file mode 100644
index 0000000..6991151
--- /dev/null
+++ b/android/app/src/main/kotlin/app/nectarlink/android/webcam/WebcamPacket.kt
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+package app.nectarlink.android.webcam
+
+import java.nio.ByteBuffer
+
+/** Copies codec output directly into the final owned Annex B packet. */
+internal object WebcamPacket {
+ fun frame(
+ source: ByteBuffer,
+ offset: Int,
+ size: Int,
+ parameters: ByteArray,
+ keyframe: Boolean,
+ codec: String,
+ ): ByteArray {
+ require(offset >= 0 && size >= 0 && offset <= source.limit() - size)
+ val hevc = codec == "h265"
+ val aud = if (hevc) HEVC_AUD_NAL else AVC_AUD_NAL
+ val end = offset + size
+ val dataStart = afterAud(source, offset, end, hevc)
+ val params = if (keyframe && parameters.isNotEmpty()) ByteBuffer.wrap(parameters) else null
+ val paramsStart = if (params != null) afterAud(params, 0, params.limit(), hevc) else 0
+ val paramsSize = if (params != null) params.limit() - paramsStart else 0
+ return ByteArray(aud.size + paramsSize + end - dataStart).also { packet ->
+ System.arraycopy(aud, 0, packet, 0, aud.size)
+ if (paramsSize > 0) System.arraycopy(parameters, paramsStart, packet, aud.size, paramsSize)
+ // A duplicate preserves the MediaCodec buffer's position and limit.
+ source.duplicate().apply { position(dataStart); limit(end) }
+ .get(packet, aud.size + paramsSize, end - dataStart)
+ }
+ }
+
+ private fun afterAud(data: ByteBuffer, start: Int, end: Int, hevc: Boolean): Int {
+ fun startCode(at: Int): Int {
+ if (at + 3 > end || data.get(at) != 0.toByte() || data.get(at + 1) != 0.toByte()) return 0
+ if (data.get(at + 2) == 1.toByte()) return 3
+ return if (at + 4 <= end && data.get(at + 2) == 0.toByte() && data.get(at + 3) == 1.toByte()) 4 else 0
+ }
+ val prefix = startCode(start)
+ if (prefix == 0 || start + prefix >= end) return start
+ val type = if (hevc) (data.get(start + prefix).toInt() ushr 1) and 0x3F else data.get(start + prefix).toInt() and 0x1F
+ if (type != if (hevc) 35 else 9) return start
+ for (at in start + prefix + 1 until end) if (startCode(at) != 0) return at
+ return end
+ }
+
+ internal val AVC_AUD_NAL = byteArrayOf(0, 0, 0, 1, 9, 0xF0.toByte())
+ internal val HEVC_AUD_NAL = byteArrayOf(0, 0, 0, 1, 0x46, 1, 0x50)
+}
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/webcam/WebcamPreviewTarget.kt b/android/app/src/main/kotlin/app/nectarlink/android/webcam/WebcamPreviewTarget.kt
new file mode 100644
index 0000000..641b86a
--- /dev/null
+++ b/android/app/src/main/kotlin/app/nectarlink/android/webcam/WebcamPreviewTarget.kt
@@ -0,0 +1,7 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+package app.nectarlink.android.webcam
+
+import android.view.Surface
+
+/** The view owns the Surface; the encoder owns only its temporary EGL window. */
+internal data class WebcamPreviewTarget(val surface: Surface, val width: Int, val height: Int)
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/webcam/WebcamService.kt b/android/app/src/main/kotlin/app/nectarlink/android/webcam/WebcamService.kt
index 3850e7f..05cac6f 100644
--- a/android/app/src/main/kotlin/app/nectarlink/android/webcam/WebcamService.kt
+++ b/android/app/src/main/kotlin/app/nectarlink/android/webcam/WebcamService.kt
@@ -14,7 +14,6 @@ import android.os.Build
import android.os.Handler
import android.os.Looper
import android.util.Log
-import androidx.camera.core.Preview
import androidx.core.app.NotificationCompat
import androidx.core.app.ServiceCompat
import androidx.core.content.ContextCompat
@@ -200,7 +199,7 @@ class WebcamService : LifecycleService() {
}
},
)
- camEncoder.setUiSurfaceProvider(uiSurfaceProvider)
+ camEncoder.setUiPreview(uiPreviewTarget)
encoder = camEncoder
camEncoder.start()
}
@@ -287,7 +286,7 @@ class WebcamService : LifecycleService() {
private const val EXTRA_CAMERA = "camera"
@Volatile private var current: WebcamService? = null
- @Volatile private var uiSurfaceProvider: Preview.SurfaceProvider? = null
+ @Volatile private var uiPreviewTarget: WebcamPreviewTarget? = null
private val _session = MutableStateFlow(WebcamSession())
val session: StateFlow<WebcamSession> = _session.asStateFlow()
@@ -381,9 +380,9 @@ class WebcamService : LifecycleService() {
current?.encoder?.setTorch(on)
}
- fun attachUiPreview(provider: Preview.SurfaceProvider?) {
- uiSurfaceProvider = provider
- current?.encoder?.setUiSurfaceProvider(provider)
+ internal fun attachUiPreview(target: WebcamPreviewTarget?) {
+ uiPreviewTarget = target
+ current?.encoder?.setUiPreview(target)
}
fun createChannel(context: Context) {
diff --git a/android/app/src/test/kotlin/app/nectarlink/android/webcam/CameraEncoderTest.kt b/android/app/src/test/kotlin/app/nectarlink/android/webcam/CameraEncoderTest.kt
index 2aa9539..3db248d 100644
--- a/android/app/src/test/kotlin/app/nectarlink/android/webcam/CameraEncoderTest.kt
+++ b/android/app/src/test/kotlin/app/nectarlink/android/webcam/CameraEncoderTest.kt
@@ -1,43 +1,10 @@
// SPDX-License-Identifier: GPL-3.0-or-later
package app.nectarlink.android.webcam
-import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals
import org.junit.Test
class CameraEncoderTest {
- @Test
- fun `HEVC keyframes carry VPS SPS PPS and a codec specific AUD`() {
- val parameters = byteArrayOf(0, 0, 0, 1, 0x40, 1, 0x11, 0, 0, 0, 1, 0x42, 1, 0x22, 0, 0, 0, 1, 0x44, 1, 0x33)
- val idr = byteArrayOf(0, 0, 0, 1, 0x26, 1, 0x55)
- val aud = CameraEncoder.HEVC_AUD_NAL
- assertArrayEquals(aud + parameters + idr, CameraEncoder.ensureAudAndParameters(idr, parameters, true, "h265"))
- assertArrayEquals(aud + parameters + idr, CameraEncoder.ensureAudAndParameters(aud + idr, aud + parameters, true, "h265"))
- val shortAud = byteArrayOf(0, 0, 1, 0x46, 1, 0x50)
- assertArrayEquals(aud + idr, CameraEncoder.ensureAudAndParameters(shortAud + idr, parameters, false, "h265"))
- // Parameter-set headers must survive; HEVC types use different bits from AVC.
- assertArrayEquals(aud + parameters, CameraEncoder.ensureAudAndParameters(parameters, byteArrayOf(), false, "h265"))
- }
-
- @Test
- fun `prepends AUD and SPS PPS to keyframes and avoids duplicate AUD`() {
- val spsPps = byteArrayOf(0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x00, 0x00, 0x00, 0x01, 0x68, 0x11)
- val idrSlice = byteArrayOf(0x00, 0x00, 0x00, 0x01, 0x65, 0xAA.toByte())
-
- val keyOut = CameraEncoder.ensureAudAndParameters(idrSlice, spsPps, isKeyframe = true)
- assertArrayEquals(CameraEncoder.AUD_NAL + spsPps + idrSlice, keyOut)
-
- // When the encoder already emitted an AUD at the front of the slice, it is not duplicated.
- val idrWithAud = CameraEncoder.AUD_NAL + idrSlice
- val keyDedup = CameraEncoder.ensureAudAndParameters(idrWithAud, spsPps, isKeyframe = true)
- assertArrayEquals(CameraEncoder.AUD_NAL + spsPps + idrSlice, keyDedup)
-
- // Non-keyframe gets AUD prepended without SPS/PPS.
- val pSlice = byteArrayOf(0x00, 0x00, 0x00, 0x01, 0x41, 0x55)
- val pOut = CameraEncoder.ensureAudAndParameters(pSlice, spsPps, isKeyframe = false)
- assertArrayEquals(CameraEncoder.AUD_NAL + pSlice, pOut)
- }
-
@Test
fun `normalizes resolution height and selects matching width and bitrate`() {
assertEquals(720, CameraEncoder.normalizeHeight(720, supports4k = false))
diff --git a/android/app/src/test/kotlin/app/nectarlink/android/webcam/FrameQuadTest.kt b/android/app/src/test/kotlin/app/nectarlink/android/webcam/FrameQuadTest.kt
new file mode 100644
index 0000000..089c9c8
--- /dev/null
+++ b/android/app/src/test/kotlin/app/nectarlink/android/webcam/FrameQuadTest.kt
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+package app.nectarlink.android.webcam
+
+import org.junit.Assert.assertArrayEquals
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertTrue
+import org.junit.Test
+
+class FrameQuadTest {
+ @Test
+ fun `rotations preserve the existing UV mapping and letterbox upright portrait frames`() {
+ val expected = listOf(
+ floatArrayOf(0f, 0f, 1f, 0f, 0f, 1f, 1f, 1f),
+ floatArrayOf(0f, 1f, 0f, 0f, 1f, 1f, 1f, 0f),
+ floatArrayOf(1f, 1f, 0f, 1f, 1f, 0f, 0f, 0f),
+ floatArrayOf(1f, 0f, 1f, 1f, 0f, 0f, 0f, 1f),
+ )
+ for (rotation in 0..3) for (swapsAxes in listOf(false, true)) for (mirror in listOf(false, true)) {
+ val quad = FrameQuad(1920, 1080, 1920, 1080)
+ assertTrue(quad.update(rotation * 90, swapsAxes, mirror))
+ val portrait = swapsAxes xor (rotation % 2 != 0)
+ val width = (if (portrait) 81f / 256f else 1f) * (if (mirror) -1f else 1f)
+ val values = FloatArray(16)
+ for (i in 0..3) {
+ values[i * 4] = if (i % 2 == 0) -width else width
+ values[i * 4 + 1] = if (i < 2) -1f else 1f
+ values[i * 4 + 2] = expected[rotation][i * 2]
+ values[i * 4 + 3] = expected[rotation][i * 2 + 1]
+ }
+ val actual = FloatArray(16)
+ quad.buffer.duplicate().get(actual)
+ assertArrayEquals(values, actual, 0.00001f)
+ }
+ }
+
+ @Test
+ fun `caches unchanged transforms but refreshes mirror rotation and axis changes`() {
+ val quad = FrameQuad(1920, 1080, 1920, 1080)
+ assertTrue(quad.update(0, false, false))
+ assertFalse(quad.update(360, false, false))
+ assertTrue(quad.update(0, false, true))
+ assertFalse(quad.update(0, false, true))
+ assertTrue(quad.update(-90, false, true))
+ assertFalse(quad.update(270, false, true))
+ assertTrue(quad.update(270, true, true))
+ }
+
+ @Test
+ fun `wide source letterboxes vertically without stretching`() {
+ val quad = FrameQuad(3840, 1080, 1920, 1080)
+ quad.update(0, false, false)
+ assertArrayEquals(floatArrayOf(-1f, -0.5f, 0f, 0f, 1f, -0.5f, 1f, 0f,
+ -1f, 0.5f, 0f, 1f, 1f, 0.5f, 1f, 1f), FloatArray(16).also { quad.buffer.duplicate().get(it) }, 0.00001f)
+ }
+
+ @Test
+ fun `preview fills the viewport by cropping while encoder geometry still fits`() {
+ val wide = FrameQuad(3840, 1080, 1920, 1080, fitCenter = false)
+ wide.update(0, false, false)
+ assertArrayEquals(floatArrayOf(-2f, -1f, 0f, 0f, 2f, -1f, 1f, 0f,
+ -2f, 1f, 0f, 1f, 2f, 1f, 1f, 1f), FloatArray(16).also { wide.buffer.duplicate().get(it) }, 0.00001f)
+ val portrait = FrameQuad(1080, 1920, 1920, 1080, fitCenter = false)
+ portrait.update(0, false, false)
+ val actual = FloatArray(16).also { portrait.buffer.duplicate().get(it) }
+ assertArrayEquals(floatArrayOf(-1f, -256f / 81f, 0f, 0f, 1f, -256f / 81f, 1f, 0f,
+ -1f, 256f / 81f, 0f, 1f, 1f, 256f / 81f, 1f, 1f), actual, 0.00001f)
+ }
+}
diff --git a/android/app/src/test/kotlin/app/nectarlink/android/webcam/WebcamPacketTest.kt b/android/app/src/test/kotlin/app/nectarlink/android/webcam/WebcamPacketTest.kt
new file mode 100644
index 0000000..ee13522
--- /dev/null
+++ b/android/app/src/test/kotlin/app/nectarlink/android/webcam/WebcamPacketTest.kt
@@ -0,0 +1,97 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+package app.nectarlink.android.webcam
+
+import java.nio.ByteBuffer
+import org.junit.Assert.assertArrayEquals
+import org.junit.Assert.assertEquals
+import org.junit.Test
+
+class WebcamPacketTest {
+ private data class CodecFixture(
+ val codec: String,
+ val aud: ByteArray,
+ val slice: ByteArray,
+ val parameters: ByteArray,
+ )
+
+ @Test
+ fun `keyframes carry all codec parameter sets after one codec specific AUD`() {
+ val h264Parameters = byteArrayOf(
+ 0, 0, 0, 1, 0x67, 0x42,
+ 0, 0, 0, 1, 0x68, 0x11,
+ )
+ val h264Keyframe = byteArrayOf(0, 0, 0, 1, 0x65, 0x55)
+ assertArrayEquals(
+ WebcamPacket.AVC_AUD_NAL + h264Parameters + h264Keyframe,
+ WebcamPacket.frame(ByteBuffer.wrap(h264Keyframe), 0, h264Keyframe.size, h264Parameters, true, "h264"),
+ )
+
+ val hevcParameters = byteArrayOf(
+ 0, 0, 0, 1, 0x40, 1, 0x11,
+ 0, 0, 0, 1, 0x42, 1, 0x22,
+ 0, 0, 0, 1, 0x44, 1, 0x33,
+ )
+ val hevcKeyframe = byteArrayOf(0, 0, 0, 1, 0x26, 1, 0x55)
+ assertArrayEquals(
+ WebcamPacket.HEVC_AUD_NAL + hevcParameters + hevcKeyframe,
+ WebcamPacket.frame(ByteBuffer.wrap(hevcKeyframe), 0, hevcKeyframe.size, hevcParameters, true, "h265"),
+ )
+ }
+
+ @Test
+ fun `copies only the codec range from direct read-only buffers without changing cursor`() {
+ val payload = byteArrayOf(0, 0, 0, 1, 0x26, 1, 0x55)
+ val source = ByteBuffer.allocateDirect(64)
+ source.position(7)
+ source.put(payload)
+ source.put(0x7F)
+ source.limit(30)
+ source.position(2)
+ val readOnly = source.asReadOnlyBuffer()
+ val packet = WebcamPacket.frame(readOnly, 7, payload.size, byteArrayOf(), false, "h265")
+ assertArrayEquals(WebcamPacket.HEVC_AUD_NAL + payload, packet)
+ assertEquals(2, readOnly.position())
+ assertEquals(30, readOnly.limit())
+ source.put(7, 0x7E)
+ assertArrayEquals(WebcamPacket.HEVC_AUD_NAL + payload, packet)
+ }
+
+ @Test
+ fun `strips only leading AUDs for both codecs including nonzero offsets`() {
+ for (fixture in listOf(
+ CodecFixture("h264", WebcamPacket.AVC_AUD_NAL, byteArrayOf(0, 0, 1, 0x65, 0x22), byteArrayOf(0, 0, 1, 0x67, 0x44)),
+ CodecFixture("h265", WebcamPacket.HEVC_AUD_NAL, byteArrayOf(0, 0, 1, 0x26, 1, 0x22), byteArrayOf(0, 0, 1, 0x40, 1, 0x44)),
+ )) {
+ val shortAud = fixture.aud.copyOfRange(1, fixture.aud.size)
+ val source = ByteBuffer.wrap(byteArrayOf(99, 98) + shortAud + fixture.slice + byteArrayOf(97))
+ assertArrayEquals(
+ fixture.aud + fixture.parameters + fixture.slice,
+ WebcamPacket.frame(
+ source, 2, shortAud.size + fixture.slice.size,
+ fixture.aud + fixture.parameters, true, fixture.codec,
+ ),
+ )
+ assertArrayEquals(
+ fixture.aud + fixture.slice,
+ WebcamPacket.frame(source, 2, shortAud.size + fixture.slice.size, fixture.parameters, false, fixture.codec),
+ )
+ assertArrayEquals(
+ fixture.aud,
+ WebcamPacket.frame(ByteBuffer.wrap(fixture.aud), 0, fixture.aud.size, byteArrayOf(), false, fixture.codec),
+ )
+ }
+ }
+
+ @Test
+ fun `supports empty input and sliced buffers`() {
+ val slice = byteArrayOf(0, 0, 0, 1, 0x41, 0x55)
+ val source = ByteBuffer.wrap(byteArrayOf(99, 98) + slice).apply { position(2) }.slice()
+ assertArrayEquals(WebcamPacket.AVC_AUD_NAL + slice, WebcamPacket.frame(source, 0, slice.size, byteArrayOf(), false, "h264"))
+ assertArrayEquals(WebcamPacket.AVC_AUD_NAL, WebcamPacket.frame(source, source.limit(), 0, byteArrayOf(), false, "h264"))
+ }
+
+ @Test(expected = IllegalArgumentException::class)
+ fun `rejects a range extending beyond the codec buffer limit`() {
+ WebcamPacket.frame(ByteBuffer.allocate(20).apply { limit(8) }, 7, 2, byteArrayOf(), false, "h264")
+ }
+}
diff --git a/desktop/app/src/bridge/webcam.rs b/desktop/app/src/bridge/webcam.rs
index dd78f43..6fb59f9 100644
--- a/desktop/app/src/bridge/webcam.rs
+++ b/desktop/app/src/bridge/webcam.rs
@@ -63,9 +63,6 @@ pub mod qobject {
#[qinvokable]
fn stop(self: &Webcam);
#[qinvokable]
- #[cxx_name = "setPreviewActive"]
- fn set_preview_active(self: &Webcam, active: bool);
- #[qinvokable]
#[cxx_name = "setPreviewVisible"]
fn set_preview_visible(self: &Webcam, owner: &QString, active: bool);
}
@@ -171,9 +168,6 @@ impl qobject::Webcam {
webcam::stop();
}
- pub fn set_preview_active(&self, active: bool) {
- webcam::set_preview_active(active);
- }
pub fn set_preview_visible(&self, owner: &QString, active: bool) {
webcam::set_preview_visible(&String::from(owner), active);
}
diff --git a/desktop/app/src/webcam.rs b/desktop/app/src/webcam.rs
index 49ff480..a8ec677 100644
--- a/desktop/app/src/webcam.rs
+++ b/desktop/app/src/webcam.rs
@@ -455,12 +455,6 @@ fn refresh_idle_frame() {
}
}
-/// Marks whether the Settings webcam preview is on screen so the idle
-/// placeholder image is only held while needed.
-pub fn set_preview_active(active: bool) {
- set_preview_demand(1, active);
-}
-
/// Each view owns its request so hiding one cannot turn off another visible
/// preview. Window visibility participates in the QML demand expression.
pub fn set_preview_visible(owner: &str, active: bool) {