Skip to content

Commit

Permalink
fix(sfu): just copy payload for vp8 temporal
Browse files Browse the repository at this point in the history
  • Loading branch information
OrlandoCo committed May 11, 2021
1 parent 4b5bfff commit 791b19e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
7 changes: 3 additions & 4 deletions pkg/sfu/downtrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,7 @@ 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)
payload := extPkt.Packet.Payload

var (
picID uint16
Expand All @@ -412,6 +410,7 @@ func (d *DownTrack) writeSimulcastRTP(extPkt *buffer.ExtPacket) error {
d.snOffset++
return nil
}
payload = d.payload
}
}

Expand Down Expand Up @@ -441,7 +440,7 @@ func (d *DownTrack) writeSimulcastRTP(extPkt *buffer.ExtPacket) error {
hdr.SSRC = d.ssrc
hdr.PayloadType = d.payloadType

_, err := d.writeStream.WriteRTP(&hdr, d.payload)
_, err := d.writeStream.WriteRTP(&hdr, payload)
if err != nil {
Logger.Error(err, "Write packet err")
}
Expand Down
19 changes: 11 additions & 8 deletions pkg/sfu/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,37 @@ 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) (picID uint16, tlz0Idx uint8, drop bool) {
func setVP8TemporalLayer(p *buffer.ExtPacket, d *DownTrack) (picID uint16, tlz0Idx uint8, drop bool) {
pkt, ok := p.Payload.(buffer.VP8)
if !ok {
return 0, 0, false
}

layer := atomic.LoadInt32(&s.temporalLayer)
layer := atomic.LoadInt32(&d.temporalLayer)
currentLayer := uint16(layer)
currentTargetLayer := uint16(layer >> 16)
// Check if temporal getLayer is requested
if currentTargetLayer != currentLayer {
if pkt.TID <= uint8(currentTargetLayer) {
atomic.StoreInt32(&s.temporalLayer, int32(currentTargetLayer)<<16|int32(currentTargetLayer))
atomic.StoreInt32(&d.temporalLayer, int32(currentTargetLayer)<<16|int32(currentTargetLayer))
}
} else if pkt.TID > uint8(currentLayer) {
drop = true
return
}

picID = pkt.PictureID - s.simulcast.refPicID + s.simulcast.pRefPicID + 1
tlz0Idx = pkt.TL0PICIDX - s.simulcast.refTlZIdx + s.simulcast.pRefTlZIdx + 1
d.payload = d.payload[:len(p.Packet.Payload)]
copy(d.payload, p.Packet.Payload)

picID = pkt.PictureID - d.simulcast.refPicID + d.simulcast.pRefPicID + 1
tlz0Idx = pkt.TL0PICIDX - d.simulcast.refTlZIdx + d.simulcast.pRefTlZIdx + 1

if p.Head {
s.simulcast.lPicID = picID
s.simulcast.lTlZIdx = tlz0Idx
d.simulcast.lPicID = picID
d.simulcast.lTlZIdx = tlz0Idx
}

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

return
}
Expand Down

0 comments on commit 791b19e

Please sign in to comment.