Skip to content

Commit

Permalink
fix srt retry
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Nov 3, 2023
1 parent 6e864a3 commit d917778
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
8 changes: 5 additions & 3 deletions srt/src/main/java/com/pedro/srt/mpeg2ts/packets/AacPacket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ class AacPacket(
callback(packets)
}

override fun resetPacket() {
sampleRate = 44100
isStereo = true
override fun resetPacket(resetInfo: Boolean) {
if (resetInfo) {
sampleRate = 44100
isStereo = true
}
}

fun sendAudioInfo(sampleRate: Int, stereo: Boolean) {
Expand Down
6 changes: 3 additions & 3 deletions srt/src/main/java/com/pedro/srt/mpeg2ts/packets/BasePacket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ abstract class BasePacket(
callback: (List<MpegTsPacket>) -> Unit
)

abstract fun resetPacket()
abstract fun resetPacket(resetInfo: Boolean)

fun reset() {
fun reset(resetInfo: Boolean) {
mpegTsPacketizer.reset()
resetPacket()
resetPacket(resetInfo)
}

fun setLimitSize(limitSize: Int) {
Expand Down
10 changes: 6 additions & 4 deletions srt/src/main/java/com/pedro/srt/mpeg2ts/packets/H26XPacket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,12 @@ class H26XPacket(
callback(packets)
}

override fun resetPacket() {
vps = null
sps = null
pps = null
override fun resetPacket(resetInfo: Boolean) {
if (resetInfo) {
vps = null
sps = null
pps = null
}
configSend = false
}

Expand Down
9 changes: 3 additions & 6 deletions srt/src/main/java/com/pedro/srt/srt/SrtClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,11 @@ class SrtClient(private val connectCheckerSrt: ConnectCheckerSrt) {
}

private suspend fun disconnect(clear: Boolean) {
if (isStreaming) srtSender.stop()
val error = runCatching {
if (isStreaming) srtSender.stop(clear)
runCatching {
commandsManager.writeShutdown(socket)
socket?.close()
}.exceptionOrNull()
if (error != null) {
Log.e(TAG, "disconnect error", error)
}
socket?.close()
if (clear) {
reTries = numRetry
doingRetry = false
Expand Down
6 changes: 3 additions & 3 deletions srt/src/main/java/com/pedro/srt/srt/SrtSender.kt
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,13 @@ class SrtSender(
}
}

suspend fun stop() {
suspend fun stop(clear: Boolean) {
running = false
psiManager.reset()
service.clear()
mpegTsPacketizer.reset()
aacPacket.reset()
h26XPacket.reset()
aacPacket.reset(clear)
h26XPacket.reset(clear)
resetSentAudioFrames()
resetSentVideoFrames()
resetDroppedAudioFrames()
Expand Down
3 changes: 3 additions & 0 deletions srt/src/main/java/com/pedro/srt/utils/SrtSocket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@ class SrtSocket(private val host: String, private val port: Int) {
private val TAG = "SrtSocket"
private var socket: DatagramSocket? = null
private var packetSize = Constants.MTU
private val timeout = 5000

fun connect() {
val address = InetAddress.getByName(host)
socket = DatagramSocket()
socket?.connect(address, port)
socket?.soTimeout = timeout
}

fun close() {
if (socket?.isClosed == false) {
socket?.disconnect()
socket?.close()
socket = null
}
Expand Down

0 comments on commit d917778

Please sign in to comment.