Remove DD extension when AV1 not preferred (#1129)
This commit is contained in:
+27
-17
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/pion/sdp/v3"
|
"github.com/pion/sdp/v3"
|
||||||
"github.com/pion/webrtc/v3"
|
"github.com/pion/webrtc/v3"
|
||||||
|
|
||||||
|
dd "github.com/livekit/livekit-server/pkg/sfu/dependencydescriptor"
|
||||||
"github.com/livekit/protocol/livekit"
|
"github.com/livekit/protocol/livekit"
|
||||||
lksdp "github.com/livekit/protocol/sdp"
|
lksdp "github.com/livekit/protocol/sdp"
|
||||||
)
|
)
|
||||||
@@ -113,27 +114,36 @@ func (p *ParticipantImpl) setCodecPreferencesVideoForPublisher(offer webrtc.Sess
|
|||||||
}
|
}
|
||||||
p.pendingTracksLock.RUnlock()
|
p.pendingTracksLock.RUnlock()
|
||||||
|
|
||||||
if mime == "" {
|
|
||||||
return offer
|
|
||||||
}
|
|
||||||
|
|
||||||
codecs, err := codecsFromMediaDescription(lastVideo)
|
|
||||||
if err != nil {
|
|
||||||
return offer
|
|
||||||
}
|
|
||||||
|
|
||||||
mime = strings.ToUpper(mime)
|
mime = strings.ToUpper(mime)
|
||||||
var preferredCodecs, leftCodecs []string
|
// remove dd extension if av1 not preferred
|
||||||
for _, c := range codecs {
|
if !strings.Contains(mime, "AV1") {
|
||||||
if strings.HasSuffix(mime, strings.ToUpper(c.Name)) {
|
for i, attr := range lastVideo.Attributes {
|
||||||
preferredCodecs = append(preferredCodecs, strconv.FormatInt(int64(c.PayloadType), 10))
|
if strings.Contains(attr.Value, dd.ExtensionUrl) {
|
||||||
} else {
|
lastVideo.Attributes[i] = lastVideo.Attributes[len(lastVideo.Attributes)-1]
|
||||||
leftCodecs = append(leftCodecs, strconv.FormatInt(int64(c.PayloadType), 10))
|
lastVideo.Attributes = lastVideo.Attributes[:len(lastVideo.Attributes)-1]
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lastVideo.MediaName.Formats = append(lastVideo.MediaName.Formats[:0], preferredCodecs...)
|
if mime != "" {
|
||||||
lastVideo.MediaName.Formats = append(lastVideo.MediaName.Formats, leftCodecs...)
|
codecs, err := codecsFromMediaDescription(lastVideo)
|
||||||
|
if err != nil {
|
||||||
|
return offer
|
||||||
|
}
|
||||||
|
|
||||||
|
var preferredCodecs, leftCodecs []string
|
||||||
|
for _, c := range codecs {
|
||||||
|
if strings.HasSuffix(mime, strings.ToUpper(c.Name)) {
|
||||||
|
preferredCodecs = append(preferredCodecs, strconv.FormatInt(int64(c.PayloadType), 10))
|
||||||
|
} else {
|
||||||
|
leftCodecs = append(leftCodecs, strconv.FormatInt(int64(c.PayloadType), 10))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lastVideo.MediaName.Formats = append(lastVideo.MediaName.Formats[:0], preferredCodecs...)
|
||||||
|
lastVideo.MediaName.Formats = append(lastVideo.MediaName.Formats, leftCodecs...)
|
||||||
|
}
|
||||||
|
|
||||||
bytes, err := parsed.Marshal()
|
bytes, err := parsed.Marshal()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -510,7 +510,6 @@ func (b *Buffer) getExtPacket(rawPacket []byte, rtpPacket *rtp.Packet, arrivalTi
|
|||||||
b.logger.Warnw("could not unmarshal VP8 packet", err)
|
b.logger.Warnw("could not unmarshal VP8 packet", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
ep.Payload = vp8Packet
|
|
||||||
ep.KeyFrame = vp8Packet.IsKeyFrame
|
ep.KeyFrame = vp8Packet.IsKeyFrame
|
||||||
if ep.DependencyDescriptor == nil {
|
if ep.DependencyDescriptor == nil {
|
||||||
ep.Temporal = int32(vp8Packet.TID)
|
ep.Temporal = int32(vp8Packet.TID)
|
||||||
@@ -519,6 +518,7 @@ func (b *Buffer) getExtPacket(rawPacket []byte, rtpPacket *rtp.Packet, arrivalTi
|
|||||||
vp8Packet.TID = uint8(ep.Temporal)
|
vp8Packet.TID = uint8(ep.Temporal)
|
||||||
ep.Spatial = InvalidLayerSpatial // vp8 don't have spatial scalability, reset to -1
|
ep.Spatial = InvalidLayerSpatial // vp8 don't have spatial scalability, reset to -1
|
||||||
}
|
}
|
||||||
|
ep.Payload = vp8Packet
|
||||||
case "video/h264":
|
case "video/h264":
|
||||||
ep.KeyFrame = IsH264Keyframe(rtpPacket.Payload)
|
ep.KeyFrame = IsH264Keyframe(rtpPacket.Payload)
|
||||||
case "video/av1":
|
case "video/av1":
|
||||||
|
|||||||
Reference in New Issue
Block a user