Take AudioFeatures from AddTrack. (#3635)
* Take AudioFeatures from AddTrack. * use slices.Compact * feedback * remove early bail
This commit is contained in:
@@ -38,6 +38,7 @@ import (
|
||||
"github.com/livekit/livekit-server/pkg/sfu/mime"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/rtpstats"
|
||||
"github.com/livekit/livekit-server/pkg/telemetry"
|
||||
sutils "github.com/livekit/livekit-server/pkg/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -780,7 +781,9 @@ func (t *MediaTrackReceiver) UpdateAudioTrack(update *livekit.UpdateLocalAudioTr
|
||||
t.lock.Lock()
|
||||
trackInfo := t.TrackInfo()
|
||||
clonedInfo := utils.CloneProto(trackInfo)
|
||||
clonedInfo.AudioFeatures = update.Features
|
||||
|
||||
clonedInfo.AudioFeatures = sutils.DedupeSlice(update.Features)
|
||||
|
||||
clonedInfo.Stereo = false
|
||||
clonedInfo.DisableDtx = false
|
||||
for _, feature := range update.Features {
|
||||
@@ -791,6 +794,7 @@ func (t *MediaTrackReceiver) UpdateAudioTrack(update *livekit.UpdateLocalAudioTr
|
||||
clonedInfo.DisableDtx = true
|
||||
}
|
||||
}
|
||||
|
||||
if proto.Equal(trackInfo, clonedInfo) {
|
||||
t.lock.Unlock()
|
||||
return
|
||||
|
||||
@@ -2344,6 +2344,7 @@ func (p *ParticipantImpl) addPendingTrackLocked(req *livekit.AddTrackRequest) *l
|
||||
Encryption: req.Encryption,
|
||||
Stream: req.Stream,
|
||||
BackupCodecPolicy: backupCodecPolicy,
|
||||
AudioFeatures: sutils.DedupeSlice(req.AudioFeatures),
|
||||
}
|
||||
if req.Stereo && !slices.Contains(ti.AudioFeatures, livekit.AudioTrackFeature_TF_STEREO) {
|
||||
ti.AudioFeatures = append(ti.AudioFeatures, livekit.AudioTrackFeature_TF_STEREO)
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"slices"
|
||||
)
|
||||
|
||||
func DedupeSlice[T cmp.Ordered](s []T) []T {
|
||||
slices.Sort(s)
|
||||
return slices.Compact(s)
|
||||
}
|
||||
Reference in New Issue
Block a user