Skip to content

Commit

Permalink
Merge pull request jitsi#26 from bbaldino/rtx-cleanup
Browse files Browse the repository at this point in the history
Rtx cleanup
  • Loading branch information
bgrozev committed Mar 21, 2019
2 parents 1ef0895 + a20920b commit d13dac4
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 6 deletions.
59 changes: 59 additions & 0 deletions src/main/kotlin/org/jitsi/nlj/rtp/RtxPacket.kt
@@ -0,0 +1,59 @@
/*
* Copyright @ 2018 - present 8x8, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jitsi.nlj.rtp

import org.jitsi.nlj.util.shiftPayloadLeft
import org.jitsi.nlj.util.shiftPayloadRight
import org.jitsi.rtp.extensions.bytearray.putShort
import org.jitsi.rtp.rtp.RtpPacket
import org.jitsi.rtp.util.getShortAsInt

/**
* https://tools.ietf.org/html/rfc4588#section-4
*
* 0 1 2 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | RTP Header |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | OSN | |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
* | Original RTP Packet Payload |
* | |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
class RtxPacket {
companion object {
fun getOriginalSequenceNumber(rtxPacket: RtpPacket): Int =
rtxPacket.buffer.getShortAsInt(rtxPacket.offset + rtxPacket.headerLength)

/**
* Removes the original sequence number by shifting the payload 2 bytes
* to the left and reducing the length of the packet by 2
*/
fun removeOriginalSequenceNumber(rtxPacket: RtpPacket) {
rtxPacket.shiftPayloadLeft(2)
rtxPacket.length = rtxPacket.length - 2
}

fun addOriginalSequenceNumber(rtpPacket: RtpPacket) {
rtpPacket.shiftPayloadRight(2)
rtpPacket.length = rtpPacket.length + 2
rtpPacket.buffer.putShort(rtpPacket.offset + rtpPacket.headerLength, rtpPacket.sequenceNumber.toShort())
}
}
}
Expand Up @@ -21,6 +21,7 @@ import org.jitsi.nlj.RtpPayloadTypeAddedEvent
import org.jitsi.nlj.RtpPayloadTypeClearEvent
import org.jitsi.nlj.SsrcAssociationEvent
import org.jitsi.nlj.format.RtxPayloadType
import org.jitsi.nlj.rtp.RtxPacket
import org.jitsi.nlj.rtp.SsrcAssociationType
import org.jitsi.nlj.stats.NodeStatsBlock
import org.jitsi.nlj.transform.node.TransformerNode
Expand Down Expand Up @@ -70,13 +71,12 @@ class RtxHandler : TransformerNode("RTX handler") {
return null
}

val originalSeqNum = rtpPacket.originalSequenceNumber
val originalSeqNum = RtxPacket.getOriginalSequenceNumber(rtpPacket)
val originalPt = associatedPayloadTypes[rtpPacket.payloadType.toPositiveInt()]!!
val originalSsrc = associatedSsrcs[rtpPacket.ssrc]!!

// Move the payload 2 bytes to the left
rtpPacket.shiftPayloadLeft(2)
rtpPacket.length = rtpPacket.length - 2
RtxPacket.removeOriginalSequenceNumber(rtpPacket)
rtpPacket.sequenceNumber = originalSeqNum
rtpPacket.payloadType = originalPt
rtpPacket.ssrc = originalSsrc
Expand Down
Expand Up @@ -21,6 +21,7 @@ import org.jitsi.nlj.RtpPayloadTypeAddedEvent
import org.jitsi.nlj.RtpPayloadTypeClearEvent
import org.jitsi.nlj.SsrcAssociationEvent
import org.jitsi.nlj.format.RtxPayloadType
import org.jitsi.nlj.rtp.RtxPacket
import org.jitsi.nlj.rtp.SsrcAssociationType
import org.jitsi.nlj.stats.NodeStatsBlock
import org.jitsi.nlj.transform.node.TransformerNode
Expand Down Expand Up @@ -71,9 +72,7 @@ class RetransmissionSender : TransformerNode("Retransmission sender") {
// in the map, get the value and increment it by 1
val rtxSeqNum = rtxStreamSeqNums.merge(rtxSsrc, 1, Integer::sum)!!

rtpPacket.shiftPayloadRight(2)
rtpPacket.length = rtpPacket.length + 2
rtpPacket.originalSequenceNumber = rtpPacket.sequenceNumber
RtxPacket.addOriginalSequenceNumber(rtpPacket)

rtpPacket.ssrc = rtxSsrc
rtpPacket.payloadType = rtxPt
Expand Down

0 comments on commit d13dac4

Please sign in to comment.