Skip to content

Commit 44c7631

Browse files
committed
refactor(*): backport streamer interfaces from next version
1 parent 7b857ce commit 44c7631

File tree

32 files changed

+490
-315
lines changed

32 files changed

+490
-315
lines changed

core/src/androidTest/java/io/github/thibaultbee/streampack/core/streamer/file/CameraStreamerFileTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import io.github.thibaultbee.streampack.core.elements.endpoints.composites.sinks
3636
import io.github.thibaultbee.streampack.core.streamers.single.AudioConfig
3737
import io.github.thibaultbee.streampack.core.streamers.single.CameraSingleStreamer
3838
import io.github.thibaultbee.streampack.core.streamers.single.VideoConfig
39-
import io.github.thibaultbee.streampack.core.streamers.single.setConfig
4039
import io.github.thibaultbee.streampack.core.utils.FileUtils
4140
import kotlinx.coroutines.test.runTest
4241
import org.junit.Rule

core/src/androidTest/java/io/github/thibaultbee/streampack/core/streamer/file/CameraStreamerMultiStreamTest.kt renamed to core/src/androidTest/java/io/github/thibaultbee/streampack/core/streamer/file/CameraStreamerMultiEndpointTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import io.github.thibaultbee.streampack.core.configuration.mediadescriptor.UriMe
2828
import io.github.thibaultbee.streampack.core.streamers.single.AudioConfig
2929
import io.github.thibaultbee.streampack.core.streamers.single.CameraSingleStreamer
3030
import io.github.thibaultbee.streampack.core.streamers.single.VideoConfig
31-
import io.github.thibaultbee.streampack.core.streamers.single.setConfig
3231
import io.github.thibaultbee.streampack.core.utils.FileUtils
3332
import kotlinx.coroutines.test.runTest
3433
import org.junit.Rule
@@ -40,7 +39,7 @@ import kotlin.time.Duration.Companion.seconds
4039
* Test [CameraSingleStreamer] with multiple streams.
4140
*/
4241
@LargeTest
43-
class CameraStreamerMultiStreamTest {
42+
class CameraStreamerMultiEndpointTest {
4443
private val context: Context = InstrumentationRegistry.getInstrumentation().context
4544
private val streamer = CameraSingleStreamer(context)
4645

core/src/androidTest/java/io/github/thibaultbee/streampack/core/streamer/file/StreamerUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ object StreamerUtils {
2424
while (i < numOfLoop) {
2525
i++
2626
delay(pollDuration)
27-
assertTrue(streamer.isStreaming.value)
27+
assertTrue(streamer.isStreamingFlow.value)
2828
}
2929
}
3030
streamer.stopStream()

core/src/androidTest/java/io/github/thibaultbee/streampack/core/streamer/state/AudioOnlyStreamerStateTest.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import androidx.test.rule.GrantPermissionRule
2323
import io.github.thibaultbee.streampack.core.configuration.mediadescriptor.MediaDescriptor
2424
import io.github.thibaultbee.streampack.core.configuration.mediadescriptor.UriMediaDescriptor
2525
import io.github.thibaultbee.streampack.core.streamers.single.AudioOnlySingleStreamer
26-
import io.github.thibaultbee.streampack.core.streamers.single.setConfig
2726
import io.github.thibaultbee.streampack.core.streamers.single.startStream
2827
import io.github.thibaultbee.streampack.core.utils.ConfigurationUtils
2928
import io.github.thibaultbee.streampack.core.utils.FileUtils
@@ -55,14 +54,14 @@ class AudioOnlyStreamerStateTest(private val descriptor: MediaDescriptor) {
5554

5655
// Single method calls
5756
@Test
58-
fun configureAudioOnlyTest() {
57+
fun configureAudioOnlyTest() = runTest {
5958
streamer.setAudioConfig(
6059
ConfigurationUtils.dummyValidAudioConfig()
6160
)
6261
}
6362

6463
@Test
65-
fun configureVideoOnlyTest() {
64+
fun configureVideoOnlyTest() = runTest {
6665
try {
6766
streamer.setVideoConfig(
6867
ConfigurationUtils.dummyValidVideoConfig()
@@ -73,7 +72,7 @@ class AudioOnlyStreamerStateTest(private val descriptor: MediaDescriptor) {
7372
}
7473

7574
@Test
76-
fun configureTest() {
75+
fun configureTest() = runTest {
7776
try {
7877
streamer.setConfig(
7978
ConfigurationUtils.dummyValidAudioConfig(),
@@ -85,7 +84,7 @@ class AudioOnlyStreamerStateTest(private val descriptor: MediaDescriptor) {
8584
}
8685

8786
@Test
88-
fun configureErrorTest() {
87+
fun configureErrorTest() = runTest {
8988
try {
9089
streamer.setAudioConfig(
9190
ConfigurationUtils.dummyInvalidAudioConfig()
@@ -105,7 +104,7 @@ class AudioOnlyStreamerStateTest(private val descriptor: MediaDescriptor) {
105104
}
106105

107106
@Test
108-
fun configureReleaseTest() {
107+
fun configureReleaseTest() = runTest {
109108
streamer.setAudioConfig(
110109
ConfigurationUtils.dummyValidAudioConfig()
111110
)
@@ -151,7 +150,7 @@ class AudioOnlyStreamerStateTest(private val descriptor: MediaDescriptor) {
151150
}
152151

153152
@Test
154-
fun multipleConfigureTest() {
153+
fun multipleConfigureTest() = runTest {
155154
(0..10).forEach { _ ->
156155
streamer.setAudioConfig(
157156
ConfigurationUtils.dummyValidAudioConfig()

core/src/androidTest/java/io/github/thibaultbee/streampack/core/streamer/state/CameraStreamerStateTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import io.github.thibaultbee.streampack.core.streamer.surface.SurfaceUtils
2727
import io.github.thibaultbee.streampack.core.streamer.surface.SurfaceViewTestActivity
2828
import io.github.thibaultbee.streampack.core.streamers.interfaces.startPreview
2929
import io.github.thibaultbee.streampack.core.streamers.single.CameraSingleStreamer
30-
import io.github.thibaultbee.streampack.core.streamers.single.setConfig
3130
import io.github.thibaultbee.streampack.core.streamers.single.startStream
3231
import io.github.thibaultbee.streampack.core.utils.ConfigurationUtils
3332
import io.github.thibaultbee.streampack.core.utils.FileUtils

core/src/androidTest/java/io/github/thibaultbee/streampack/core/streamer/state/StreamerStateTest.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
package io.github.thibaultbee.streampack.core.streamer.state
1717

1818
import io.github.thibaultbee.streampack.core.configuration.mediadescriptor.MediaDescriptor
19-
import io.github.thibaultbee.streampack.core.streamers.single.ICoroutineSingleStreamer
20-
import io.github.thibaultbee.streampack.core.streamers.single.setConfig
19+
import io.github.thibaultbee.streampack.core.streamers.interfaces.releaseBlocking
20+
import io.github.thibaultbee.streampack.core.streamers.single.SingleStreamer
2121
import io.github.thibaultbee.streampack.core.streamers.single.startStream
2222
import io.github.thibaultbee.streampack.core.utils.ConfigurationUtils
2323
import kotlinx.coroutines.test.runTest
@@ -28,11 +28,11 @@ import org.junit.Test
2828
abstract class StreamerStateTest(
2929
protected val descriptor: MediaDescriptor
3030
) {
31-
protected abstract val streamer: ICoroutineSingleStreamer
31+
protected abstract val streamer: SingleStreamer
3232

3333
@After
3434
open fun tearDown() {
35-
streamer.release()
35+
streamer.releaseBlocking()
3636
}
3737

3838
@Test
@@ -48,29 +48,29 @@ abstract class StreamerStateTest(
4848

4949
// Single method calls
5050
@Test
51-
open fun configureAudioOnlyTest() {
51+
open fun configureAudioOnlyTest() = runTest {
5252
streamer.setAudioConfig(
5353
ConfigurationUtils.dummyValidAudioConfig()
5454
)
5555
}
5656

5757
@Test
58-
open fun configureVideoOnlyTest() {
58+
open fun configureVideoOnlyTest() = runTest {
5959
streamer.setVideoConfig(
6060
ConfigurationUtils.dummyValidVideoConfig()
6161
)
6262
}
6363

6464
@Test
65-
open fun configureTest() {
65+
open fun configureTest() = runTest {
6666
streamer.setConfig(
6767
ConfigurationUtils.dummyValidAudioConfig(),
6868
ConfigurationUtils.dummyValidVideoConfig()
6969
)
7070
}
7171

7272
@Test
73-
open fun configureErrorTest() {
73+
open fun configureErrorTest() = runTest {
7474
try {
7575
streamer.setConfig(
7676
ConfigurationUtils.dummyInvalidAudioConfig(),
@@ -102,7 +102,7 @@ abstract class StreamerStateTest(
102102
}
103103

104104
@Test
105-
fun releaseTest() {
105+
fun releaseTest() = runTest {
106106
streamer.release()
107107
}
108108

@@ -117,7 +117,7 @@ abstract class StreamerStateTest(
117117
}
118118

119119
@Test
120-
open fun configureReleaseTest() {
120+
open fun configureReleaseTest() = runTest {
121121
streamer.setConfig(
122122
ConfigurationUtils.dummyValidAudioConfig(),
123123
ConfigurationUtils.dummyValidVideoConfig()
@@ -156,7 +156,7 @@ abstract class StreamerStateTest(
156156

157157
// Stress test
158158
@Test
159-
open fun multipleConfigureTest() {
159+
open fun multipleConfigureTest() = runTest {
160160
(0..10).forEach { _ ->
161161
streamer.setConfig(
162162
ConfigurationUtils.dummyValidAudioConfig(),

core/src/main/java/io/github/thibaultbee/streampack/core/elements/endpoints/CombineEndpoint.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ open class CombineEndpoint(protected val endpointInternals: List<IEndpointIntern
5656

5757
/**
5858
* Whether at least one endpoint is open.
59-
* This is a combination of all endpoints' [IEndpoint.isOpen].
59+
* This is a combination of all endpoints' [IEndpoint.isOpenFlow].
6060
*
61-
* To verify if a specific endpoint is open, use [IEndpoint.isOpen] of the endpoint.
61+
* To verify if a specific endpoint is open, use [IEndpoint.isOpenFlow] of the endpoint.
6262
*/
63-
override val isOpen: StateFlow<Boolean> =
64-
combineStates(*endpointInternals.map { it.isOpen }.toTypedArray()) { _ ->
65-
endpointInternals.any { it.isOpen.value }
63+
override val isOpenFlow: StateFlow<Boolean> =
64+
combineStates(*endpointInternals.map { it.isOpenFlow }.toTypedArray()) { _ ->
65+
endpointInternals.any { it.isOpenFlow.value }
6666
}
6767

6868
/**
@@ -190,7 +190,7 @@ open class CombineEndpoint(protected val endpointInternals: List<IEndpointIntern
190190

191191
endpointInternals.forEach { endpoint ->
192192
try {
193-
if (endpoint.isOpen.value) {
193+
if (endpoint.isOpenFlow.value) {
194194
val endpointStreamId = endpointsToStreamIdsMap[Pair(endpoint, streamPid)]!!
195195
endpoint.write(frame, endpointStreamId)
196196

core/src/main/java/io/github/thibaultbee/streampack/core/elements/endpoints/DynamicEndpoint.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ open class DynamicEndpoint(
6363
private var rtmpEndpoint: IEndpointInternal? = null
6464

6565
@OptIn(ExperimentalCoroutinesApi::class)
66-
override val isOpen: StateFlow<Boolean> = DerivedStateFlow(
67-
getValue = { _endpoint?.isOpen?.value ?: false },
68-
flow = endpointFlow.flatMapLatest { it?.isOpen ?: MutableStateFlow(false) }
66+
override val isOpenFlow: StateFlow<Boolean> = DerivedStateFlow(
67+
getValue = { _endpoint?.isOpenFlow?.value ?: false },
68+
flow = endpointFlow.flatMapLatest { it?.isOpenFlow ?: MutableStateFlow(false) }
6969
)
7070

7171
/**
@@ -80,7 +80,7 @@ open class DynamicEndpoint(
8080
get() = endpoint.metrics
8181

8282
override suspend fun open(descriptor: MediaDescriptor) {
83-
if (isOpen.value) {
83+
if (isOpenFlow.value) {
8484
Logger.w(TAG, "DynamicEndpoint is already opened")
8585
return
8686
}

core/src/main/java/io/github/thibaultbee/streampack/core/elements/endpoints/IEndpoint.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ interface IEndpoint {
7777
* Whether if the endpoint is opened.
7878
* For example, if the file is opened for [FileSink].
7979
*/
80-
val isOpen: StateFlow<Boolean>
80+
val isOpenFlow: StateFlow<Boolean>
8181

8282
/**
8383
* A info to verify supported formats.

core/src/main/java/io/github/thibaultbee/streampack/core/elements/endpoints/MediaMuxerEndpoint.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ class MediaMuxerEndpoint(
6161
override val metrics: Any
6262
get() = TODO("Not yet implemented")
6363

64-
private val _isOpen = MutableStateFlow(false)
65-
override val isOpen: StateFlow<Boolean> = _isOpen
64+
private val _isOpenFlow = MutableStateFlow(false)
65+
override val isOpenFlow: StateFlow<Boolean> = _isOpenFlow
6666

6767
override suspend fun open(descriptor: MediaDescriptor) {
68-
if (isOpen.value) {
68+
if (isOpenFlow.value) {
6969
Logger.w(TAG, "MediaMuxerEndpoint is already opened")
7070
return
7171
}
@@ -121,7 +121,7 @@ class MediaMuxerEndpoint(
121121
throw t
122122
}
123123

124-
_isOpen.emit(true)
124+
_isOpenFlow.emit(true)
125125
}
126126

127127
override suspend fun write(
@@ -209,7 +209,7 @@ class MediaMuxerEndpoint(
209209
numOfStreams = 0
210210
streamIdToTrackId.clear()
211211
mediaMuxer = null
212-
_isOpen.emit(false)
212+
_isOpenFlow.emit(false)
213213
}
214214
}
215215

0 commit comments

Comments
 (0)