Add stream camera controls and preserve playback on changes
This commit is contained in:
1 parent
d820c71417
commit
f275db1616
25 files changed
+1042
-280
No files matched your search
@@ -0,0 +1,28 @@
|
||||
package com.utun.chat.data
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
class StreamCameraModesTest {
|
||||
private fun mode(camera: String, width: Int, height: Int, fps: Int) =
|
||||
StreamCaptureMode(camera, width, height, fps, fps, fps >= 120, "codec", 2_000_000)
|
||||
|
||||
@Test fun cameraChangePreservesExactMode() {
|
||||
val previous = mode("back", 1920, 1080, 120)
|
||||
val modes = listOf(mode("front", 1280, 720, 30), mode("front", 1920, 1080, 120))
|
||||
assertEquals(modes[1], StreamCameraModes.choose(modes, previous))
|
||||
}
|
||||
|
||||
@Test fun cameraChangeUsesLowerRateAtSameResolution() {
|
||||
val previous = mode("back", 1920, 1080, 240)
|
||||
val modes = listOf(mode("front", 1280, 720, 30), mode("front", 1920, 1080, 30), mode("front", 1920, 1080, 120))
|
||||
assertEquals(modes[2], StreamCameraModes.choose(modes, previous))
|
||||
}
|
||||
|
||||
@Test fun defaultAndUnsupportedModeUse720p30() {
|
||||
val modes = listOf(mode("other", 640, 480, 30), mode("other", 1280, 720, 30), mode("other", 1920, 1080, 120))
|
||||
assertEquals(modes[1], StreamCameraModes.choose(modes))
|
||||
assertEquals(modes[1], StreamCameraModes.choose(modes, mode("back", 1920, 1080, 30)))
|
||||
assertNull(StreamCameraModes.choose(emptyList()))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.utun.chat.data
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class StreamOrientationTest {
|
||||
@Test fun rearCameraRotationFollowsManualOrientation() {
|
||||
assertEquals(listOf(90, 0, 270, 180), StreamOrientation.values().map { it.sensorRotation(90, false) })
|
||||
assertEquals(listOf(270, 180, 90, 0), StreamOrientation.values().map { it.sensorRotation(270, false) })
|
||||
}
|
||||
|
||||
@Test fun frontCameraUsesOppositeSensorCompensation() {
|
||||
assertEquals(listOf(270, 0, 90, 180), StreamOrientation.values().map { it.sensorRotation(270, true) })
|
||||
assertEquals(listOf(90, 180, 270, 0), StreamOrientation.values().map { it.sensorRotation(90, true) })
|
||||
}
|
||||
|
||||
@Test fun camerasWithZeroSensorRotationKeepAllFourDirections() {
|
||||
assertEquals(listOf(0, 270, 180, 90), StreamOrientation.values().map { it.sensorRotation(0, false) })
|
||||
assertEquals(listOf(0, 90, 180, 270), StreamOrientation.values().map { it.sensorRotation(0, true) })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.utun.chat.data
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
class StreamPreviewTest {
|
||||
@Test fun manualRotationMovesRearTopMarkerWithoutRotatingCameraPreview() {
|
||||
val camera = StreamPreviewCamera(90, false)
|
||||
val display = StreamOrientation.values().map {
|
||||
StreamVideoDisplay.forFrame(it.sensorRotation(90, false), camera, 0)
|
||||
}
|
||||
assertEquals(listOf(90, 90, 90, 90), display.map { it.rotation })
|
||||
assertEquals(listOf(0, 90, 180, 270), display.map { it.top })
|
||||
}
|
||||
|
||||
@Test fun frontCameraTopMarkerUsesItsOwnSensorDirection() {
|
||||
val camera = StreamPreviewCamera(270, true)
|
||||
val display = StreamOrientation.values().map {
|
||||
StreamVideoDisplay.forFrame(it.sensorRotation(270, true), camera, 0)
|
||||
}
|
||||
assertEquals(listOf(270, 270, 270, 270), display.map { it.rotation })
|
||||
assertEquals(listOf(0, 270, 180, 90), display.map { it.top })
|
||||
}
|
||||
|
||||
@Test fun previewFollowsScreenWhileBroadcastKeepsManualOrientation() {
|
||||
assertEquals(StreamVideoDisplay(0, 270), StreamVideoDisplay.forFrame(90, StreamPreviewCamera(90, false), 90))
|
||||
assertEquals(StreamVideoDisplay(0, 90), StreamVideoDisplay.forFrame(270, StreamPreviewCamera(270, true), 90))
|
||||
}
|
||||
|
||||
@Test fun remoteViewerKeepsBroadcastRotationWithoutLocalMarker() {
|
||||
for (rotation in listOf(0, 90, 180, 270))
|
||||
assertEquals(StreamVideoDisplay(rotation, null), StreamVideoDisplay.forFrame(rotation, null, 90))
|
||||
}
|
||||
|
||||
@Test fun cameraSwitchRetainsPoseForAlreadyQueuedFrames() {
|
||||
val preview = StreamPreview()
|
||||
val rear = StreamPreviewCamera(90, false)
|
||||
val front = StreamPreviewCamera(270, true)
|
||||
preview.register(1, rear); preview.register(3, front)
|
||||
assertEquals(rear, preview.camera(1))
|
||||
assertEquals(front, preview.camera(3))
|
||||
assertNull(preview.camera(2))
|
||||
for (revision in 4L..40L) preview.register(revision, rear)
|
||||
assertNull(preview.camera(1))
|
||||
assertEquals(rear, preview.camera(9))
|
||||
assertEquals(rear, preview.camera(40))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user