Skip to content

Commit 9358036

Browse files
committed
refactor(core): add an API to retrieve the streamConfigs in IMuxerInternal
1 parent ab499f5 commit 9358036

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import io.github.thibaultbee.streampack.core.elements.endpoints.composites.muxer
2626
import io.github.thibaultbee.streampack.core.elements.endpoints.composites.muxers.IMuxerInternal
2727
import io.github.thibaultbee.streampack.core.elements.endpoints.composites.sinks.ISinkInternal
2828
import io.github.thibaultbee.streampack.core.elements.endpoints.composites.sinks.SinkConfiguration
29-
import io.github.thibaultbee.streampack.core.logger.Logger
3029
import kotlinx.coroutines.flow.StateFlow
3130
import kotlinx.coroutines.runBlocking
3231

@@ -79,18 +78,16 @@ class CompositeEndpoint(
7978

8079
override fun addStreams(streamConfigs: List<CodecConfig>): Map<CodecConfig, Int> {
8180
val streamIds = muxer.addStreams(streamConfigs)
82-
configurations.addAll(streamConfigs)
8381
return streamIds
8482
}
8583

8684
override fun addStream(streamConfig: CodecConfig): Int {
8785
val streamId = muxer.addStream(streamConfig)
88-
configurations.add(streamConfig)
8986
return streamId
9087
}
9188

9289
override suspend fun startStream() {
93-
sink.configure(SinkConfiguration(configurations))
90+
sink.configure(SinkConfiguration(muxer.streamConfigs))
9491
sink.startStream()
9592
muxer.startStream()
9693
}
@@ -103,7 +100,6 @@ class CompositeEndpoint(
103100
override suspend fun stopStream() {
104101
muxer.stopStream()
105102
sink.stopStream()
106-
configurations.clear()
107103
}
108104

109105
class EndpointInfo(

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ interface IMuxerInternal :
2626
Releasable {
2727
var listener: IMuxerListener?
2828

29+
val streamConfigs: List<CodecConfig>
30+
2931
interface IMuxerListener {
3032
fun onOutputFrame(packet: Packet)
3133
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class FlvMuxer(
3939
private var startUpTime: Long? = null
4040
private var hasFirstFrame = false
4141

42+
override val streamConfigs: List<CodecConfig>
43+
get() = streams.map { it.config }
44+
4245
override fun write(frame: Frame, streamPid: Int) {
4346
synchronized(this) {
4447
if (!hasFirstFrame) {

core/src/main/java/io/github/thibaultbee/streampack/core/elements/endpoints/composites/muxers/mp4/Mp4Muxer.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ class Mp4Muxer(
5454
private var dataOffset: Long = 0
5555
private var sequenceNumber = DEFAULT_SEQUENCE_NUMBER
5656

57+
override val streamConfigs: List<CodecConfig>
58+
get() = tracks.map { it.config }
59+
5760
override fun write(frame: Frame, streamPid: Int) {
5861
synchronized(this) {
5962
if (segmenter!!.mustWriteSegment(frame)) {
@@ -64,16 +67,13 @@ class Mp4Muxer(
6467
}
6568

6669
override fun addStreams(streamsConfig: List<CodecConfig>): Map<CodecConfig, Int> {
67-
val newTracks = mutableListOf<Track>()
6870
streamsConfig.forEach { config ->
6971
val track = Track(getNewId(), config, timescale)
70-
newTracks.add(track)
7172
tracks.add(track)
7273
}
7374

7475
val streamMap = mutableMapOf<CodecConfig, Int>()
75-
newTracks.forEach { streamMap[it.config] = it.id }
76-
return streamMap
76+
return streamsConfig.associateWith { streamMap[it]!! }
7777
}
7878

7979
override fun addStream(streamConfig: CodecConfig): Int {

core/src/main/java/io/github/thibaultbee/streampack/core/elements/endpoints/composites/muxers/ts/TsMuxer.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class TsMuxer : IMuxerInternal {
6262
listener, tsServices, tsId, packetCount = 0
6363
)
6464

65+
override val streamConfigs: List<CodecConfig>
66+
get() = tsServices.flatMap { it.streams }.map { it.config }
67+
6568
/**
6669
* Encodes a frame to MPEG-TS format.
6770
* Each audio frames and each video key frames must come with an extra buffer containing sps, pps,...

0 commit comments

Comments
 (0)