Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import org.junit.Assert.assertTrue
import org.junit.Test
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds

@OptIn(InternalStreamPackApi::class)
@LargeTest
Expand All @@ -62,7 +63,7 @@ class StreamerPipelineFileTest : DeviceTest() {
}

@Test
fun testAudioOrVideoStream() = runTest(timeout = TEST_TIMEOUT_MS.milliseconds) {
fun testAudioOrVideoStream() = runTest(timeout = TEST_TIMEOUT) {
// Add sources
streamerPipeline.setAudioSource(MicrophoneSourceFactory())
streamerPipeline.setVideoSource(CameraSourceFactory(context))
Expand Down Expand Up @@ -93,8 +94,8 @@ class StreamerPipelineFileTest : DeviceTest() {
}
videoOnlyOutput.startStream(videoOnlyDescriptor)

val duration: Duration = STREAM_DURATION_MS.milliseconds
val pollDuration: Duration = STREAM_POLLING_MS.milliseconds
val duration: Duration = STREAM_DURATION
val pollDuration: Duration = STREAM_POLLING
var i = 0
val numOfLoop = duration / pollDuration

Expand Down Expand Up @@ -133,9 +134,9 @@ class StreamerPipelineFileTest : DeviceTest() {
companion object {
private const val TAG = "StreamerPipelineFileTest"

private const val TEST_TIMEOUT_MS = 60_000L
private const val STREAM_DURATION_MS = 30_000L
private const val STREAM_POLLING_MS = 1_000L
private val TEST_TIMEOUT = 60.seconds
private val STREAM_DURATION = 30.seconds
private val STREAM_POLLING = 1.seconds

private const val VIDEO_WIDTH = 1280
private const val VIDEO_HEIGHT = 720
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds

@LargeTest
@RunWith(Parameterized::class)
Expand Down Expand Up @@ -92,7 +93,7 @@ class CameraDualStreamerFileTest(
}

@Test
fun writeToFile() = runTest(timeout = TEST_TIMEOUT_MS.milliseconds) {
fun writeToFile() = runTest(timeout = TEST_TIMEOUT) {
// Configure
streamer.setConfig(
audioConfig, videoConfig
Expand All @@ -103,8 +104,8 @@ class CameraDualStreamerFileTest(
streamer,
firstDescriptor,
secondDescriptor,
STREAM_DURATION_MS.milliseconds,
STREAM_POLLING_MS.milliseconds
STREAM_DURATION,
STREAM_POLLING
)
streamer.release()

Expand All @@ -128,9 +129,9 @@ class CameraDualStreamerFileTest(
companion object {
private const val TAG = "CameraDualStrFileTest"

private const val TEST_TIMEOUT_MS = 60_000L
private const val STREAM_DURATION_MS = 30_000L
private const val STREAM_POLLING_MS = 1_000L
private val TEST_TIMEOUT = 60.seconds
private val STREAM_DURATION = 30.seconds
private val STREAM_POLLING = 1.seconds

private const val VIDEO_WIDTH = 640
private const val VIDEO_HEIGHT = 360
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import org.junit.After
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds

@LargeTest
@RunWith(Parameterized::class)
Expand Down Expand Up @@ -76,7 +76,7 @@ class CameraSingleStreamerFileTest(
}

@Test
fun writeToFile() = runTest(timeout = TEST_TIMEOUT_MS.milliseconds) {
fun writeToFile() = runTest(timeout = TEST_TIMEOUT) {
// Run stream
streamer.setConfig(
audioConfig,
Expand All @@ -87,8 +87,8 @@ class CameraSingleStreamerFileTest(
StreamerUtils.runSingleStream(
streamer,
descriptor,
STREAM_DURATION_MS.milliseconds,
STREAM_POLLING_MS.milliseconds
STREAM_DURATION,
STREAM_POLLING
)
streamer.release()

Expand All @@ -105,9 +105,9 @@ class CameraSingleStreamerFileTest(
companion object {
private const val TAG = "CameraSinStrFileTest"

private const val TEST_TIMEOUT_MS = 60_000L
private const val STREAM_DURATION_MS = 30_000L
private const val STREAM_POLLING_MS = 1_000L
private val TEST_TIMEOUT = 60.seconds
private val STREAM_DURATION = 30.seconds
private val STREAM_POLLING = 1.seconds

private const val VIDEO_WIDTH = 640
private const val VIDEO_HEIGHT = 360
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.After
import org.junit.Test
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds

/**
* Test [cameraSingleStreamer] with multiple endpoint.
Expand All @@ -61,7 +62,7 @@ class CameraSingleStreamerMultiEndpointTest : DeviceTest() {
}

@Test
fun writeToEndpoints() = runTest(timeout = TEST_TIMEOUT_MS.milliseconds * descriptors.size) {
fun writeToEndpoints() = runTest(timeout = TEST_TIMEOUT * descriptors.size) {
val audioConfig = AudioConfig()
val videoConfig = VideoConfig(resolution = Size(VIDEO_WIDTH, VIDEO_HEIGHT))

Expand Down Expand Up @@ -94,8 +95,8 @@ class CameraSingleStreamerMultiEndpointTest : DeviceTest() {
StreamerUtils.runSingleStream(
streamer,
descriptor,
STREAM_DURATION_MS.milliseconds,
STREAM_POLLING_MS.milliseconds
STREAM_DURATION,
STREAM_POLLING
)

// Check file
Expand All @@ -122,9 +123,9 @@ class CameraSingleStreamerMultiEndpointTest : DeviceTest() {
companion object {
private const val TAG = "MultiEndpointTest"

private const val TEST_TIMEOUT_MS = 40_000L
private const val STREAM_DURATION_MS = 20_000L
private const val STREAM_POLLING_MS = 1_000L
private val TEST_TIMEOUT = 40.seconds
private val STREAM_DURATION = 20.seconds
private val STREAM_POLLING = 1.seconds

private const val VIDEO_WIDTH = 1280
private const val VIDEO_HEIGHT = 720
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ import io.github.thibaultbee.streampack.core.elements.utils.extensions.isNormali
import io.github.thibaultbee.streampack.core.elements.utils.extensions.launchIn
import io.github.thibaultbee.streampack.core.elements.utils.extensions.rotate
import io.github.thibaultbee.streampack.core.logger.Logger
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
Expand Down Expand Up @@ -1262,7 +1264,7 @@ class CameraSettings internal constructor(
afRectangles: List<MeteringRectangle>,
aeRectangles: List<MeteringRectangle>,
awbRectangles: List<MeteringRectangle>,
timeoutDurationMs: Long
timeoutDuration: Duration
) {
disableAutoCancel()

Expand All @@ -1284,9 +1286,9 @@ class CameraSettings internal constructor(

addFocusMetering(afRectangles, aeRectangles, awbRectangles)

// Auto cancel AF trigger after timeoutDurationMs
if (timeoutDurationMs > 0) {
autoCancelHandle = coroutineScope.launchIn(timeoutDurationMs)
// Auto cancel AF trigger after timeoutDuration
if (timeoutDuration.isPositive()) {
autoCancelHandle = coroutineScope.launchIn(timeoutDuration)
{
autoCancelHandle = null
try {
Expand All @@ -1308,7 +1310,7 @@ class CameraSettings internal constructor(
aePoints: List<PointF>,
awbPoints: List<PointF>,
fovAspectRatio: Rational,
timeoutDurationMs: Long
timeoutDuration: Duration
) {
val cropRegion = zoom.getCropSensorRegion()

Expand All @@ -1330,7 +1332,7 @@ class CameraSettings internal constructor(
"At least one of AF, AE, AWB rectangles must be non empty"
}

executeMetering(afRectangles, aeRectangles, awbRectangles, timeoutDurationMs)
executeMetering(afRectangles, aeRectangles, awbRectangles, timeoutDuration)
}

private fun disableAutoCancel() {
Expand Down Expand Up @@ -1429,14 +1431,14 @@ class CameraSettings internal constructor(
* @param point the point to focus
* @param factory the factory to normalize the view points
* @param viewRotationDegree the orientation of the field of view
* @param timeoutDurationMs duration in milliseconds after which the focus and metering will be cancelled automatically
* @param timeoutDuration duration after which the focus and metering will be cancelled automatically
*/
@RequiresPermission(Manifest.permission.CAMERA)
suspend fun tapToFocus(
point: PointF,
factory: MeteringPointFactory,
viewRotationDegree: Int,
timeoutDurationMs: Long
timeoutDuration: Duration
) {
val points = listOf(point)
return onTap(
Expand All @@ -1445,7 +1447,7 @@ class CameraSettings internal constructor(
emptyList(),
factory,
viewRotationDegree,
timeoutDurationMs
timeoutDuration
)
}

Expand All @@ -1459,7 +1461,7 @@ class CameraSettings internal constructor(
* @param awbPoints the points where the white balance is done
* @param factory the factory to normalize the view points
* @param viewRotationDegree the orientation of the view
* @param timeoutDurationMs duration in milliseconds after which the focus and metering will be cancelled automatically
* @param timeoutDuration duration after which the focus and metering will be cancelled automatically
*/
@RequiresPermission(Manifest.permission.CAMERA)
suspend fun onTap(
Expand All @@ -1468,7 +1470,7 @@ class CameraSettings internal constructor(
awbPoints: List<PointF>,
factory: MeteringPointFactory,
viewRotationDegree: Int,
timeoutDurationMs: Long = DEFAULT_AUTO_CANCEL_DURATION_MS
timeoutDuration: Duration = DEFAULT_AUTO_CANCEL_DURATION
) {
val relativeRotation =
getSensorRotationDegrees(
Expand All @@ -1483,7 +1485,7 @@ class CameraSettings internal constructor(
aePoints.map { normalizePoint(it, factory, relativeRotation, isFrontCamera) },
awbPoints.map { normalizePoint(it, factory, relativeRotation, isFrontCamera) },
Rational(1, 1),
timeoutDurationMs
timeoutDuration
)
}

Expand All @@ -1502,7 +1504,7 @@ class CameraSettings internal constructor(
private const val DEFAULT_AE_SIZE = DEFAULT_AF_SIZE * 1.5f
private const val DEFAULT_METERING_WEIGHT_MAX =
MeteringRectangle.METERING_WEIGHT_MAX
const val DEFAULT_AUTO_CANCEL_DURATION_MS = 5000L
val DEFAULT_AUTO_CANCEL_DURATION = 5000.milliseconds

private fun getPreferredAFMode(
characteristics: CameraCharacteristics, preferredMode: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.time.Duration.Companion.milliseconds

import kotlin.time.Duration

fun CoroutineScope.launchIn(
delayTimeInMs: Long,
delayTime: Duration,
context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
block: suspend CoroutineScope.() -> Unit
) = launch(context, start) {
delay(delayTimeInMs.milliseconds)
delay(delayTime)
block()
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,25 @@ interface IWithVideoSource {
}

/**
* Sets the [cameraId] as the new video source.
* Sets the camera [cameraId] as the new video source.
*
* Same as [IWithVideoSource.setVideoSource] with a [CameraSourceFactory].
*
* @param cameraId the camera id
*/
@RequiresPermission(Manifest.permission.CAMERA)
suspend fun IWithVideoSource.setCameraId(cameraId: String) {
suspend fun IWithVideoSource.setCameraSource(cameraId: String) {
setVideoSource(CameraSourceFactory(cameraId))
}

/**
* Sets the [Bitmap] as the new video source.
*
* Same as [IWithVideoSource.setVideoSource] with a [CameraSourceFactory].
* Same as [IWithVideoSource.setVideoSource] with a [BitmapSourceFactory].
*
* @param bitmap the [Bitmap] to stream
*/
suspend fun IWithVideoSource.setBitmap(bitmap: Bitmap) {
suspend fun IWithVideoSource.setBitmapSource(bitmap: Bitmap) {
setVideoSource(BitmapSourceFactory(bitmap))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import android.os.Handler
import android.os.HandlerThread
import io.github.thibaultbee.streampack.core.elements.utils.ProcessThreadPriorityValue
import java.util.concurrent.Executor
import kotlin.time.Duration

/**
* Helper class that wraps a Handler/HandlerThread combination and implements the [Executor]
Expand All @@ -36,8 +37,8 @@ class HandlerThreadExecutor(name: String, @ProcessThreadPriorityValue priority:
handler.post(runnable)
}

fun postDelayed(runnable: Runnable, delayMillis: Long) {
handler.postDelayed(runnable, delayMillis)
fun postDelayed(runnable: Runnable, delay: Duration) {
handler.postDelayed(runnable, delay.inWholeMilliseconds)
}

fun removeCallbacksAndMessages(token: Any) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import io.github.thibaultbee.streampack.core.elements.sources.video.camera.exten
import io.github.thibaultbee.streampack.core.elements.sources.video.mediaprojection.MediaProjectionVideoSourceFactory
import io.github.thibaultbee.streampack.core.elements.utils.RotationValue
import io.github.thibaultbee.streampack.core.elements.utils.extensions.displayRotation
import io.github.thibaultbee.streampack.core.interfaces.setCameraId
import io.github.thibaultbee.streampack.core.interfaces.setCameraSource
import io.github.thibaultbee.streampack.core.pipelines.DispatcherProvider
import io.github.thibaultbee.streampack.core.pipelines.IDispatcherProvider
import io.github.thibaultbee.streampack.core.pipelines.inputs.IAudioInput
Expand Down Expand Up @@ -78,7 +78,7 @@ suspend fun cameraDualStreamer(
dispatcherProvider = dispatcherProvider
)

streamer.setCameraId(cameraId)
streamer.setCameraSource(cameraId)
if (audioSourceFactory != null) {
streamer.setAudioSource(audioSourceFactory)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import io.github.thibaultbee.streampack.core.elements.sources.video.camera.exten
import io.github.thibaultbee.streampack.core.elements.sources.video.mediaprojection.MediaProjectionVideoSourceFactory
import io.github.thibaultbee.streampack.core.elements.utils.RotationValue
import io.github.thibaultbee.streampack.core.elements.utils.extensions.displayRotation
import io.github.thibaultbee.streampack.core.interfaces.setCameraId
import io.github.thibaultbee.streampack.core.interfaces.setCameraSource
import io.github.thibaultbee.streampack.core.pipelines.DispatcherProvider
import io.github.thibaultbee.streampack.core.pipelines.IDispatcherProvider
import io.github.thibaultbee.streampack.core.pipelines.inputs.IVideoInput
Expand Down Expand Up @@ -66,7 +66,7 @@ suspend fun cameraVideoOnlyDualStreamer(
surfaceProcessorFactory = surfaceProcessorFactory,
dispatcherProvider = dispatcherProvider
)
streamer.setCameraId(cameraId)
streamer.setCameraSource(cameraId)
return streamer
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import io.github.thibaultbee.streampack.core.elements.sources.video.camera.exten
import io.github.thibaultbee.streampack.core.elements.sources.video.mediaprojection.MediaProjectionVideoSourceFactory
import io.github.thibaultbee.streampack.core.elements.utils.RotationValue
import io.github.thibaultbee.streampack.core.elements.utils.extensions.displayRotation
import io.github.thibaultbee.streampack.core.interfaces.setCameraId
import io.github.thibaultbee.streampack.core.interfaces.setCameraSource
import io.github.thibaultbee.streampack.core.pipelines.AudioInputMode
import io.github.thibaultbee.streampack.core.pipelines.DispatcherProvider
import io.github.thibaultbee.streampack.core.pipelines.IDispatcherProvider
Expand Down Expand Up @@ -78,7 +78,7 @@ suspend fun cameraSingleStreamer(
surfaceProcessorFactory = surfaceProcessorFactory,
dispatcherProvider = dispatcherProvider
)
streamer.setCameraId(cameraId)
streamer.setCameraSource(cameraId)
if (audioSourceFactory != null) {
streamer.setAudioSource(audioSourceFactory)
}
Expand Down
Loading
Loading