Skip to content

Commit

Permalink
fix(sfu): fix packet temporal change mod packet payload
Browse files Browse the repository at this point in the history
  • Loading branch information
OrlandoCo committed May 11, 2021
1 parent cf118ae commit 4b5bfff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
7 changes: 5 additions & 2 deletions pkg/sfu/downtrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,17 @@ func (d *DownTrack) writeSimulcastRTP(extPkt *buffer.ExtPacket) error {
newSN := extPkt.Packet.SequenceNumber - d.snOffset
newTS := extPkt.Packet.Timestamp - d.tsOffset

d.payload = d.payload[:len(extPkt.Packet.Payload)]
copy(d.payload, extPkt.Packet.Payload)

var (
picID uint16
tlz0Idx uint8
)
if d.simulcast.temporalSupported {
if d.mime == "video/vp8" {
drop := false
if extPkt.Packet.Payload, picID, tlz0Idx, drop = setVP8TemporalLayer(extPkt, d); drop {
if picID, tlz0Idx, drop = setVP8TemporalLayer(extPkt, d); drop {
// Pkt not in temporal getLayer update sequence number offset to avoid gaps
d.snOffset++
return nil
Expand Down Expand Up @@ -438,7 +441,7 @@ func (d *DownTrack) writeSimulcastRTP(extPkt *buffer.ExtPacket) error {
hdr.SSRC = d.ssrc
hdr.PayloadType = d.payloadType

_, err := d.writeStream.WriteRTP(&hdr, extPkt.Packet.Payload)
_, err := d.writeStream.WriteRTP(&hdr, d.payload)
if err != nil {
Logger.Error(err, "Write packet err")
}
Expand Down
11 changes: 3 additions & 8 deletions pkg/sfu/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ func (a *atomicBool) get() bool {
// setVp8TemporalLayer is a helper to detect and modify accordingly the vp8 payload to reflect
// temporal changes in the SFU.
// VP8 temporal layers implemented according https://tools.ietf.org/html/rfc7741
func setVP8TemporalLayer(p *buffer.ExtPacket, s *DownTrack) (payload []byte, picID uint16, tlz0Idx uint8, drop bool) {
func setVP8TemporalLayer(p *buffer.ExtPacket, s *DownTrack) (picID uint16, tlz0Idx uint8, drop bool) {
pkt, ok := p.Payload.(buffer.VP8)
if !ok {
return p.Packet.Payload, 0, 0, false
return 0, 0, false
}

layer := atomic.LoadInt32(&s.temporalLayer)
Expand All @@ -48,10 +48,6 @@ func setVP8TemporalLayer(p *buffer.ExtPacket, s *DownTrack) (payload []byte, pic
drop = true
return
}
// If we are here modify payload
payload = s.payload
payload = payload[:len(p.Packet.Payload)]
copy(payload, p.Packet.Payload)

picID = pkt.PictureID - s.simulcast.refPicID + s.simulcast.pRefPicID + 1
tlz0Idx = pkt.TL0PICIDX - s.simulcast.refTlZIdx + s.simulcast.pRefTlZIdx + 1
Expand All @@ -61,7 +57,7 @@ func setVP8TemporalLayer(p *buffer.ExtPacket, s *DownTrack) (payload []byte, pic
s.simulcast.lTlZIdx = tlz0Idx
}

modifyVP8TemporalPayload(payload, pkt.PicIDIdx, pkt.TlzIdx, picID, tlz0Idx, pkt.MBit)
modifyVP8TemporalPayload(s.payload, pkt.PicIDIdx, pkt.TlzIdx, picID, tlz0Idx, pkt.MBit)

return
}
Expand All @@ -75,7 +71,6 @@ func modifyVP8TemporalPayload(payload []byte, picIDIdx, tlz0Idx int, picID uint1
payload[picIDIdx+1] = pid[1]
}
payload[tlz0Idx] = tlz0ID

}

func timeToNtp(ns int64) uint64 {
Expand Down

0 comments on commit 4b5bfff

Please sign in to comment.