Skip to content

Commit

Permalink
fix(core): fix audio video frames synchronization for RTMP by forcing…
Browse files Browse the repository at this point in the history
… a new header type 0 when timestamp are back in time
  • Loading branch information
ThibaultBee committed Jan 3, 2024
1 parent 05bda7d commit d8bd67f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 326 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import io.github.thibaultbee.streampack.internal.data.Frame
import io.github.thibaultbee.streampack.internal.data.Packet
import io.github.thibaultbee.streampack.internal.data.PacketType
import io.github.thibaultbee.streampack.internal.interfaces.ISourceOrientationProvider
import io.github.thibaultbee.streampack.internal.muxers.AbstractSortingMuxer
import io.github.thibaultbee.streampack.internal.muxers.IMuxer
import io.github.thibaultbee.streampack.internal.muxers.IMuxerListener
import io.github.thibaultbee.streampack.internal.muxers.flv.tags.AVTagsFactory
import io.github.thibaultbee.streampack.internal.muxers.flv.tags.FlvHeader
Expand All @@ -33,12 +33,12 @@ class FlvMuxer(
override var listener: IMuxerListener? = null,
initialStreams: List<Config>? = null,
private val writeToFile: Boolean,
) : AbstractSortingMuxer() {
) : IMuxer {
override val helper = FlvMuxerHelper()
private val streams = mutableListOf<Config>()
override val hasAudio: Boolean
private val hasAudio: Boolean
get() = streams.any { it.mimeType.isAudio }
override val hasVideo: Boolean
private val hasVideo: Boolean
get() = streams.any { it.mimeType.isVideo }
private var startUpTime: Long? = null
private var hasFirstFrame = false
Expand Down Expand Up @@ -73,16 +73,17 @@ class FlvMuxer(

frame.pts -= startUpTime!!
val flvTags = AVTagsFactory(frame, streams[streamPid]).build()
val flvPacket = flvTags.map {
Packet(
it.write(), frame.pts, if (frame.isVideo) {
PacketType.VIDEO
} else {
PacketType.AUDIO
}
flvTags.forEach {
listener?.onOutputFrame(
Packet(
it.write(), frame.pts, if (frame.isVideo) {
PacketType.VIDEO
} else {
PacketType.AUDIO
}
)
)
}
queue(flvPacket)
}

override fun addStreams(streamsConfig: List<Config>): Map<Config, Int> {
Expand Down Expand Up @@ -117,7 +118,6 @@ class FlvMuxer(
startUpTime = null
hasFirstFrame = false
streams.clear()
super.stopStream()
}

override fun release() {
Expand All @@ -131,5 +131,4 @@ class FlvMuxer(
require(streams.count { it.mimeType.isAudio } <= 1) { "Only one audio stream is supported by FLV" }
require(streams.count { it.mimeType.isVideo } <= 1) { "Only one video stream is supported by FLV" }
}

}
}

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion extensions/rtmp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ext {

dependencies {
implementation project(':core')
implementation 'video.api:rtmpdroid:1.1.0'
implementation 'video.api:rtmpdroid:1.2.1'

implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'
implementation "androidx.core:core-ktx:${androidxCoreVersion}"
Expand Down

0 comments on commit d8bd67f

Please sign in to comment.