add disabled_codecs to client conf, and disable it at server side (#755)
* add disabled_codecs to client conf, and disable it at server side * update go mod
This commit is contained in:
@@ -13,7 +13,7 @@ require (
|
|||||||
github.com/google/wire v0.5.0
|
github.com/google/wire v0.5.0
|
||||||
github.com/gorilla/websocket v1.4.2
|
github.com/gorilla/websocket v1.4.2
|
||||||
github.com/hashicorp/golang-lru v0.5.4
|
github.com/hashicorp/golang-lru v0.5.4
|
||||||
github.com/livekit/protocol v0.13.3-0.20220607094330-e36e6426a094
|
github.com/livekit/protocol v0.13.3-0.20220608063907-5e0777215366
|
||||||
github.com/livekit/rtcscore-go v0.0.0-20220524203225-dfd1ba40744a
|
github.com/livekit/rtcscore-go v0.0.0-20220524203225-dfd1ba40744a
|
||||||
github.com/mackerelio/go-osstat v0.2.1
|
github.com/mackerelio/go-osstat v0.2.1
|
||||||
github.com/magefile/mage v1.13.0
|
github.com/magefile/mage v1.13.0
|
||||||
|
|||||||
@@ -137,6 +137,8 @@ github.com/livekit/protocol v0.13.3-0.20220530102138-51a8116f88b2 h1:ioAZAmtoQnH
|
|||||||
github.com/livekit/protocol v0.13.3-0.20220530102138-51a8116f88b2/go.mod h1:BLtSeVmn2rLP37xjzw7gHgaAmkWl3L/L9bPvgSbaOfo=
|
github.com/livekit/protocol v0.13.3-0.20220530102138-51a8116f88b2/go.mod h1:BLtSeVmn2rLP37xjzw7gHgaAmkWl3L/L9bPvgSbaOfo=
|
||||||
github.com/livekit/protocol v0.13.3-0.20220607094330-e36e6426a094 h1:DwZfNfyg5LaX3N1Eh19rcycTcyzpgqH0DpEkhB1CnI8=
|
github.com/livekit/protocol v0.13.3-0.20220607094330-e36e6426a094 h1:DwZfNfyg5LaX3N1Eh19rcycTcyzpgqH0DpEkhB1CnI8=
|
||||||
github.com/livekit/protocol v0.13.3-0.20220607094330-e36e6426a094/go.mod h1:BLtSeVmn2rLP37xjzw7gHgaAmkWl3L/L9bPvgSbaOfo=
|
github.com/livekit/protocol v0.13.3-0.20220607094330-e36e6426a094/go.mod h1:BLtSeVmn2rLP37xjzw7gHgaAmkWl3L/L9bPvgSbaOfo=
|
||||||
|
github.com/livekit/protocol v0.13.3-0.20220608063907-5e0777215366 h1:wm0ftw/i8oZr4lxQLnV4iDpG32T3cUhy6K6wQ5OFqe8=
|
||||||
|
github.com/livekit/protocol v0.13.3-0.20220608063907-5e0777215366/go.mod h1:BLtSeVmn2rLP37xjzw7gHgaAmkWl3L/L9bPvgSbaOfo=
|
||||||
github.com/livekit/rtcscore-go v0.0.0-20220524203225-dfd1ba40744a h1:cENjhGfslLSDV07gt8ASy47Wd12Q0kBS7hsdunyQ62I=
|
github.com/livekit/rtcscore-go v0.0.0-20220524203225-dfd1ba40744a h1:cENjhGfslLSDV07gt8ASy47Wd12Q0kBS7hsdunyQ62I=
|
||||||
github.com/livekit/rtcscore-go v0.0.0-20220524203225-dfd1ba40744a/go.mod h1:116ych8UaEs9vfIE8n6iZCZ30iagUFTls0vRmC+Ix5U=
|
github.com/livekit/rtcscore-go v0.0.0-20220524203225-dfd1ba40744a/go.mod h1:116ych8UaEs9vfIE8n6iZCZ30iagUFTls0vRmC+Ix5U=
|
||||||
github.com/mackerelio/go-osstat v0.2.1 h1:5AeAcBEutEErAOlDz6WCkEvm6AKYgHTUQrfwm5RbeQc=
|
github.com/mackerelio/go-osstat v0.2.1 h1:5AeAcBEutEErAOlDz6WCkEvm6AKYgHTUQrfwm5RbeQc=
|
||||||
|
|||||||
@@ -7,4 +7,11 @@ var StaticConfigurations = []ConfigurationItem{
|
|||||||
// Configuration: &livekit.ClientConfiguration{ResumeConnection: livekit.ClientConfigSetting_DISABLED},
|
// Configuration: &livekit.ClientConfiguration{ResumeConnection: livekit.ClientConfigSetting_DISABLED},
|
||||||
// Merge: false,
|
// Merge: false,
|
||||||
// },
|
// },
|
||||||
|
// {
|
||||||
|
// Match: &ScriptMatch{Expr: `c.browser == "safari" && c.os == "ios"`},
|
||||||
|
// Configuration: &livekit.ClientConfiguration{DisabledCodecs: &livekit.DisabledCodecs{Codecs: []*livekit.Codec{
|
||||||
|
// &livekit.Codec{Mime: "video/vp9"},
|
||||||
|
// }}},
|
||||||
|
// Merge: false,
|
||||||
|
// },
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-1
@@ -170,6 +170,22 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
|
|||||||
if p.updateCache, err = lru.New(32); err != nil {
|
if p.updateCache, err = lru.New(32); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enabledCodecs := make([]*livekit.Codec, 0, len(p.params.EnabledCodecs))
|
||||||
|
for _, c := range p.params.EnabledCodecs {
|
||||||
|
var disabled bool
|
||||||
|
for _, disableCodec := range p.params.ClientConf.GetDisabledCodecs().GetCodecs() {
|
||||||
|
// disable codec's fmtp is empty means disable this codec entirely
|
||||||
|
if strings.EqualFold(c.Mime, disableCodec.Mime) && (disableCodec.FmtpLine == "" || disableCodec.FmtpLine == c.FmtpLine) {
|
||||||
|
disabled = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !disabled {
|
||||||
|
enabledCodecs = append(enabledCodecs, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
p.publisher, err = NewPCTransport(TransportParams{
|
p.publisher, err = NewPCTransport(TransportParams{
|
||||||
ParticipantID: p.params.SID,
|
ParticipantID: p.params.SID,
|
||||||
ParticipantIdentity: p.params.Identity,
|
ParticipantIdentity: p.params.Identity,
|
||||||
@@ -178,7 +194,7 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
|
|||||||
Config: params.Config,
|
Config: params.Config,
|
||||||
CongestionControlConfig: params.CongestionControlConfig,
|
CongestionControlConfig: params.CongestionControlConfig,
|
||||||
Telemetry: p.params.Telemetry,
|
Telemetry: p.params.Telemetry,
|
||||||
EnabledCodecs: p.params.EnabledCodecs,
|
EnabledCodecs: enabledCodecs,
|
||||||
Logger: LoggerWithPCTarget(params.Logger, livekit.SignalTarget_PUBLISHER),
|
Logger: LoggerWithPCTarget(params.Logger, livekit.SignalTarget_PUBLISHER),
|
||||||
SimTracks: params.SimTracks,
|
SimTracks: params.SimTracks,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package rtc
|
package rtc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pion/webrtc/v3"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
||||||
@@ -436,10 +438,55 @@ func TestSetStableTrackID(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDisableCodecs(t *testing.T) {
|
||||||
|
participant := newParticipantForTestWithOpts(livekit.ParticipantIdentity("123"), &participantOpts{
|
||||||
|
publisher: false,
|
||||||
|
clientConf: &livekit.ClientConfiguration{
|
||||||
|
DisabledCodecs: &livekit.DisabledCodecs{
|
||||||
|
Codecs: []*livekit.Codec{
|
||||||
|
{Mime: "video/h264"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
participant.SetMigrateState(types.MigrateStateComplete)
|
||||||
|
|
||||||
|
pc, err := webrtc.NewPeerConnection(webrtc.Configuration{})
|
||||||
|
require.NoError(t, err)
|
||||||
|
transceiver, err := pc.AddTransceiverFromKind(webrtc.RTPCodecTypeVideo, webrtc.RTPTransceiverInit{Direction: webrtc.RTPTransceiverDirectionSendrecv})
|
||||||
|
require.NoError(t, err)
|
||||||
|
sdp, err := pc.CreateOffer(nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
pc.SetLocalDescription(sdp)
|
||||||
|
codecs := transceiver.Receiver().GetParameters().Codecs
|
||||||
|
var found264 bool
|
||||||
|
for _, c := range codecs {
|
||||||
|
if strings.EqualFold(c.MimeType, "video/h264") {
|
||||||
|
found264 = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
require.True(t, found264)
|
||||||
|
|
||||||
|
// negotiated codec should not contain h264
|
||||||
|
anwser, err := participant.HandleOffer(sdp)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NoError(t, pc.SetRemoteDescription(anwser), anwser.SDP, sdp.SDP)
|
||||||
|
codecs = transceiver.Receiver().GetParameters().Codecs
|
||||||
|
found264 = false
|
||||||
|
for _, c := range codecs {
|
||||||
|
if strings.EqualFold(c.MimeType, "video/h264") {
|
||||||
|
found264 = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
require.False(t, found264)
|
||||||
|
}
|
||||||
|
|
||||||
type participantOpts struct {
|
type participantOpts struct {
|
||||||
permissions *livekit.ParticipantPermission
|
permissions *livekit.ParticipantPermission
|
||||||
protocolVersion types.ProtocolVersion
|
protocolVersion types.ProtocolVersion
|
||||||
publisher bool
|
publisher bool
|
||||||
|
clientConf *livekit.ClientConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
func newParticipantForTestWithOpts(identity livekit.ParticipantIdentity, opts *participantOpts) *ParticipantImpl {
|
func newParticipantForTestWithOpts(identity livekit.ParticipantIdentity, opts *participantOpts) *ParticipantImpl {
|
||||||
@@ -465,6 +512,14 @@ func newParticipantForTestWithOpts(identity livekit.ParticipantIdentity, opts *p
|
|||||||
grants.Video.SetCanPublishData(opts.permissions.CanPublishData)
|
grants.Video.SetCanPublishData(opts.permissions.CanPublishData)
|
||||||
grants.Video.SetCanSubscribe(opts.permissions.CanSubscribe)
|
grants.Video.SetCanSubscribe(opts.permissions.CanSubscribe)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enabledCodecs := make([]*livekit.Codec, 0, len(conf.Room.EnabledCodecs))
|
||||||
|
for _, c := range conf.Room.EnabledCodecs {
|
||||||
|
enabledCodecs = append(enabledCodecs, &livekit.Codec{
|
||||||
|
Mime: c.Mime,
|
||||||
|
FmtpLine: c.FmtpLine,
|
||||||
|
})
|
||||||
|
}
|
||||||
p, _ := NewParticipant(ParticipantParams{
|
p, _ := NewParticipant(ParticipantParams{
|
||||||
SID: livekit.ParticipantID(utils.NewGuid(utils.ParticipantPrefix)),
|
SID: livekit.ParticipantID(utils.NewGuid(utils.ParticipantPrefix)),
|
||||||
Identity: identity,
|
Identity: identity,
|
||||||
@@ -473,6 +528,8 @@ func newParticipantForTestWithOpts(identity livekit.ParticipantIdentity, opts *p
|
|||||||
ProtocolVersion: opts.protocolVersion,
|
ProtocolVersion: opts.protocolVersion,
|
||||||
PLIThrottleConfig: conf.RTC.PLIThrottle,
|
PLIThrottleConfig: conf.RTC.PLIThrottle,
|
||||||
Grants: grants,
|
Grants: grants,
|
||||||
|
EnabledCodecs: enabledCodecs,
|
||||||
|
ClientConf: opts.clientConf,
|
||||||
})
|
})
|
||||||
p.isPublisher.Store(opts.publisher)
|
p.isPublisher.Store(opts.publisher)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user