diff --git a/pkg/rtc/participant.go b/pkg/rtc/participant.go index 2ef16843d..47b7d7f01 100644 --- a/pkg/rtc/participant.go +++ b/pkg/rtc/participant.go @@ -101,7 +101,8 @@ type ParticipantParams struct { PLIThrottleConfig config.PLIThrottleConfig CongestionControlConfig config.CongestionControlConfig // codecs that are enabled for this room - EnabledCodecs []*livekit.Codec + PublishEnabledCodecs []*livekit.Codec + SubscribeEnabledCodecs []*livekit.Codec Logger logger.Logger SimTracks map[uint32]SimulcastTrackInfo Grants *auth.ClaimGrants @@ -249,7 +250,7 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) { p.state.Store(livekit.ParticipantInfo_JOINING) p.grants = params.Grants p.SetResponseSink(params.Sink) - p.setupEnabledCodecs(params.EnabledCodecs, params.ClientConf.GetDisabledCodecs()) + p.setupEnabledCodecs(params.PublishEnabledCodecs, params.SubscribeEnabledCodecs, params.ClientConf.GetDisabledCodecs()) p.supervisor.OnPublicationError(p.onPublicationError) @@ -2334,9 +2335,7 @@ func (p *ParticipantImpl) SendDataPacket(dp *livekit.DataPacket, data []byte) er return err } -func (p *ParticipantImpl) setupEnabledCodecs(codecs []*livekit.Codec, disabledCodecs *livekit.DisabledCodecs) { - subscribeCodecs := make([]*livekit.Codec, 0, len(codecs)) - publishCodecs := make([]*livekit.Codec, 0, len(codecs)) +func (p *ParticipantImpl) setupEnabledCodecs(publishEnabledCodecs []*livekit.Codec, subscribeEnabledCodecs []*livekit.Codec, disabledCodecs *livekit.DisabledCodecs) { shouldDisable := func(c *livekit.Codec, disabled []*livekit.Codec) bool { for _, disableCodec := range disabled { // disable codec's fmtp is empty means disable this codec entirely @@ -2346,22 +2345,22 @@ func (p *ParticipantImpl) setupEnabledCodecs(codecs []*livekit.Codec, disabledCo } return false } - for _, c := range codecs { - var publishDisabled bool - var subscribeDisabled bool + + publishCodecs := make([]*livekit.Codec, 0, len(publishEnabledCodecs)) + for _, c := range publishEnabledCodecs { + if shouldDisable(c, disabledCodecs.GetCodecs()) || shouldDisable(c, disabledCodecs.GetPublish()) { + continue + } + publishCodecs = append(publishCodecs, c) + } + p.enabledPublishCodecs = publishCodecs + + subscribeCodecs := make([]*livekit.Codec, 0, len(subscribeEnabledCodecs)) + for _, c := range subscribeEnabledCodecs { if shouldDisable(c, disabledCodecs.GetCodecs()) { - publishDisabled = true - subscribeDisabled = true - } else if shouldDisable(c, disabledCodecs.GetPublish()) { - publishDisabled = true - } - if !publishDisabled { - publishCodecs = append(publishCodecs, c) - } - if !subscribeDisabled { - subscribeCodecs = append(subscribeCodecs, c) + continue } + subscribeCodecs = append(subscribeCodecs, c) } p.enabledSubscribeCodecs = subscribeCodecs - p.enabledPublishCodecs = publishCodecs } diff --git a/pkg/rtc/participant_internal_test.go b/pkg/rtc/participant_internal_test.go index 2b2ce2505..2256a70ca 100644 --- a/pkg/rtc/participant_internal_test.go +++ b/pkg/rtc/participant_internal_test.go @@ -748,19 +748,20 @@ func newParticipantForTestWithOpts(identity livekit.ParticipantIdentity, opts *p } sid := livekit.ParticipantID(utils.NewGuid(utils.ParticipantPrefix)) p, _ := NewParticipant(ParticipantParams{ - SID: sid, - Identity: identity, - Config: rtcConf, - Sink: &routingfakes.FakeMessageSink{}, - ProtocolVersion: opts.protocolVersion, - PLIThrottleConfig: conf.RTC.PLIThrottle, - Grants: grants, - EnabledCodecs: enabledCodecs, - ClientConf: opts.clientConf, - ClientInfo: ClientInfo{ClientInfo: opts.clientInfo}, - Logger: LoggerWithParticipant(logger.GetLogger(), identity, sid, false), - Telemetry: &telemetryfakes.FakeTelemetryService{}, - VersionGenerator: utils.NewDefaultTimedVersionGenerator(), + SID: sid, + Identity: identity, + Config: rtcConf, + Sink: &routingfakes.FakeMessageSink{}, + ProtocolVersion: opts.protocolVersion, + PLIThrottleConfig: conf.RTC.PLIThrottle, + Grants: grants, + PublishEnabledCodecs: enabledCodecs, + SubscribeEnabledCodecs: enabledCodecs, + ClientConf: opts.clientConf, + ClientInfo: ClientInfo{ClientInfo: opts.clientInfo}, + Logger: LoggerWithParticipant(logger.GetLogger(), identity, sid, false), + Telemetry: &telemetryfakes.FakeTelemetryService{}, + VersionGenerator: utils.NewDefaultTimedVersionGenerator(), }) p.isPublisher.Store(opts.publisher) p.updateState(livekit.ParticipantInfo_ACTIVE) diff --git a/pkg/service/roommanager.go b/pkg/service/roommanager.go index 918e847bf..738d1dd13 100644 --- a/pkg/service/roommanager.go +++ b/pkg/service/roommanager.go @@ -393,7 +393,8 @@ func (r *RoomManager) StartSession( Trailer: room.Trailer(), PLIThrottleConfig: r.config.RTC.PLIThrottle, CongestionControlConfig: r.config.RTC.CongestionControl, - EnabledCodecs: protoRoom.EnabledCodecs, + PublishEnabledCodecs: protoRoom.EnabledCodecs, + SubscribeEnabledCodecs: protoRoom.EnabledCodecs, Grants: pi.Grants, Logger: pLogger, ClientConf: clientConf,