Skip to content

Commit d9a514d

Browse files
committed
feat(*): replace rtmp and flv by krtmp
1 parent de4f2ef commit d9a514d

File tree

63 files changed

+1406
-2189
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1406
-2189
lines changed

core/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ dependencies {
3535
testImplementation(libs.robolectric)
3636

3737
androidTestImplementation(project(":streampack-srt"))
38+
androidTestImplementation(project(":streampack-flv"))
3839
androidTestImplementation(project(":streampack-rtmp"))
3940

4041
androidTestImplementation(libs.androidx.test.core.ktx)

core/src/androidTest/java/io/github/thibaultbee/streampack/core/elements/endpoints/EndpointStateTest.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package io.github.thibaultbee.streampack.core.elements.endpoints
22

33
import androidx.test.platform.app.InstrumentationRegistry
4-
import io.github.thibaultbee.streampack.core.elements.endpoints.composites.CompositeEndpoint
5-
import io.github.thibaultbee.streampack.core.elements.endpoints.composites.muxers.flv.FlvMuxer
6-
import io.github.thibaultbee.streampack.core.elements.endpoints.composites.sinks.FileSink
4+
import io.github.thibaultbee.streampack.ext.flv.elements.endpoints.FlvFileEndpoint
75
import kotlinx.coroutines.Dispatchers
86
import kotlinx.coroutines.test.runTest
97
import org.junit.Test
@@ -37,7 +35,7 @@ class EndpointStateTest(private val endpoint: IEndpointInternal) {
3735
return arrayListOf(
3836
DynamicEndpoint(context, Dispatchers.Default, ioDispatcher),
3937
MediaMuxerEndpoint(context, ioDispatcher),
40-
CompositeEndpoint(FlvMuxer(isForFile = false), FileSink(ioDispatcher))
38+
FlvFileEndpoint(ioDispatcher)
4139
)
4240
}
4341
}

core/src/main/java/io/github/thibaultbee/streampack/core/elements/encoders/AudioCodecConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class AudioCodecConfig(
189189
48000
190190
)
191191

192-
internal fun isAacMimeType(mimeType: String) = mimeType.startsWith(MIMETYPE_AAC_PREFIX)
192+
fun isAacMimeType(mimeType: String) = mimeType.startsWith(MIMETYPE_AAC_PREFIX)
193193

194194
private fun getAacProfileFromMimeType(mimeType: String) = when (mimeType) {
195195
MediaFormat.MIMETYPE_AUDIO_AAC -> MediaCodecInfo.CodecProfileLevel.AACObjectLC

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import io.github.thibaultbee.streampack.core.elements.data.FrameWithCloseable
2222
import io.github.thibaultbee.streampack.core.elements.encoders.CodecConfig
2323
import io.github.thibaultbee.streampack.core.elements.endpoints.composites.CompositeEndpoint
2424
import io.github.thibaultbee.streampack.core.elements.endpoints.composites.CompositeEndpoints
25-
import io.github.thibaultbee.streampack.core.elements.endpoints.composites.muxers.flv.FlvMuxer
2625
import io.github.thibaultbee.streampack.core.elements.endpoints.composites.muxers.ts.TsMuxer
2726
import io.github.thibaultbee.streampack.core.elements.endpoints.composites.muxers.ts.data.TSServiceInfo
2827
import io.github.thibaultbee.streampack.core.elements.endpoints.composites.sinks.ContentSink
@@ -205,22 +204,14 @@ open class DynamicEndpoint(
205204

206205
private fun getFlvFileEndpoint(): IEndpointInternal {
207206
if (flvFileEndpoint == null) {
208-
flvFileEndpoint = CompositeEndpoint(
209-
FlvMuxer(
210-
isForFile = true
211-
), FileSink(ioDispatcher)
212-
)
207+
flvFileEndpoint = Endpoints.createFlvFileEndpoint(ioDispatcher)
213208
}
214209
return flvFileEndpoint!!
215210
}
216211

217212
private fun getFlvContentEndpoint(): IEndpointInternal {
218213
if (flvContentEndpoint == null) {
219-
flvContentEndpoint = CompositeEndpoint(
220-
FlvMuxer(
221-
isForFile = true
222-
), ContentSink(context, ioDispatcher)
223-
)
214+
flvContentEndpoint = Endpoints.createFlvContentEndpoint(context, ioDispatcher)
224215
}
225216
return flvContentEndpoint!!
226217
}
@@ -253,7 +244,7 @@ open class DynamicEndpoint(
253244

254245
private fun getRtmpEndpoint(): IEndpointInternal {
255246
if (rtmpEndpoint == null) {
256-
rtmpEndpoint = CompositeEndpoints.createRtmpEndpoint(ioDispatcher)
247+
rtmpEndpoint = Endpoints.createRtmpEndpoint(ioDispatcher)
257248
}
258249
return rtmpEndpoint!!
259250
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package io.github.thibaultbee.streampack.core.elements.endpoints
2+
3+
import android.content.Context
4+
import kotlinx.coroutines.CoroutineDispatcher
5+
6+
object Endpoints {
7+
/**
8+
* Creates an endpoint for RTMP (with a FLV muxer)
9+
*/
10+
internal fun createRtmpEndpoint(coroutineDispatcher: CoroutineDispatcher): IEndpointInternal {
11+
return try {
12+
val clazz =
13+
Class.forName("io.github.thibaultbee.streampack.ext.rtmp.elements.endpoints.RtmpEndpoint")
14+
clazz.getConstructor(CoroutineDispatcher::class.java)
15+
.newInstance(coroutineDispatcher) as IEndpointInternal
16+
} catch (e: ClassNotFoundException) {
17+
// Expected if the app was built without the RTMP extension.
18+
throw ClassNotFoundException(
19+
"Attempting to stream RTMP stream without depending on the RTMP extension",
20+
e
21+
)
22+
} catch (t: Throwable) {
23+
// The RTMP extension is present, but instantiation failed.
24+
throw RuntimeException("Error instantiating RTMP extension", t)
25+
}
26+
}
27+
28+
/**
29+
* Creates an endpoint for FLV File
30+
*/
31+
internal fun createFlvFileEndpoint(coroutineDispatcher: CoroutineDispatcher): IEndpointInternal {
32+
return try {
33+
val clazz =
34+
Class.forName("io.github.thibaultbee.streampack.ext.flv.elements.endpoints.FlvFileEndpoint")
35+
clazz.getConstructor(CoroutineDispatcher::class.java)
36+
.newInstance(coroutineDispatcher) as IEndpointInternal
37+
} catch (e: ClassNotFoundException) {
38+
// Expected if the app was built without the FLV extension.
39+
throw ClassNotFoundException(
40+
"Attempting to stream FLV stream without depending on the FLV extension",
41+
e
42+
)
43+
} catch (t: Throwable) {
44+
// The FLV extension is present, but instantiation failed.
45+
throw RuntimeException("Error instantiating FLV file extension", t)
46+
}
47+
}
48+
49+
50+
/**
51+
* Creates an endpoint for FLV File
52+
*/
53+
internal fun createFlvContentEndpoint(
54+
context: Context,
55+
coroutineDispatcher: CoroutineDispatcher
56+
): IEndpointInternal {
57+
return try {
58+
val clazz =
59+
Class.forName("io.github.thibaultbee.streampack.ext.flv.elements.endpoints.FlvContentEndpoint")
60+
clazz.getConstructor(Context::class.java, CoroutineDispatcher::class.java)
61+
.newInstance(context, coroutineDispatcher) as IEndpointInternal
62+
} catch (e: ClassNotFoundException) {
63+
// Expected if the app was built without the FLV extension.
64+
throw ClassNotFoundException(
65+
"Attempting to stream FLV stream without depending on the FLV extension",
66+
e
67+
)
68+
} catch (t: Throwable) {
69+
// The FLV extension is present, but instantiation failed.
70+
throw RuntimeException("Error instantiating FLV content extension", t)
71+
}
72+
}
73+
}

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

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package io.github.thibaultbee.streampack.core.elements.endpoints.composites
1717

1818
import io.github.thibaultbee.streampack.core.elements.endpoints.IEndpointInternal
1919
import io.github.thibaultbee.streampack.core.elements.endpoints.composites.muxers.IMuxerInternal
20-
import io.github.thibaultbee.streampack.core.elements.endpoints.composites.muxers.flv.FlvMuxer
2120
import io.github.thibaultbee.streampack.core.elements.endpoints.composites.muxers.ts.TsMuxer
2221
import io.github.thibaultbee.streampack.core.elements.endpoints.composites.muxers.ts.data.TSServiceInfo
2322
import io.github.thibaultbee.streampack.core.elements.endpoints.composites.sinks.ISinkInternal
@@ -42,36 +41,6 @@ object CompositeEndpoints {
4241
return CompositeEndpoint(muxer, sink)
4342
}
4443

45-
/**
46-
* Creates an endpoint for RTMP (with a FLV muxer)
47-
*/
48-
internal fun createRtmpEndpoint(coroutineDispatcher: CoroutineDispatcher): IEndpointInternal {
49-
val sink = createRtmpSink(coroutineDispatcher)
50-
return CompositeEndpoint(
51-
FlvMuxer(
52-
isForFile = false
53-
), sink
54-
)
55-
}
56-
57-
private fun createRtmpSink(coroutineDispatcher: CoroutineDispatcher): ISinkInternal {
58-
return try {
59-
val clazz =
60-
Class.forName("io.github.thibaultbee.streampack.ext.rtmp.elements.endpoints.composites.sinks.RtmpSink")
61-
clazz.getConstructor(CoroutineDispatcher::class.java)
62-
.newInstance(coroutineDispatcher) as ISinkInternal
63-
} catch (e: ClassNotFoundException) {
64-
// Expected if the app was built without the RTMP extension.
65-
throw ClassNotFoundException(
66-
"Attempting to stream RTMP stream without depending on the RTMP extension",
67-
e
68-
)
69-
} catch (t: Throwable) {
70-
// The RTMP extension is present, but instantiation failed.
71-
throw RuntimeException("Error instantiating RTMP extension", t)
72-
}
73-
}
74-
7544
private fun createSrtSink(coroutineDispatcher: CoroutineDispatcher): ISinkInternal {
7645
return try {
7746
val clazz =

core/src/main/java/io/github/thibaultbee/streampack/core/elements/endpoints/composites/muxers/flv/FlvMuxer.kt

Lines changed: 0 additions & 153 deletions
This file was deleted.

0 commit comments

Comments
 (0)