Do not get tripped by default values. (#1284)
* Do not get tripped by default values.
The following scenario declared the second message a dupe incorrectly
- UpdateSubscription{subscribe: true}: This message initialized quality
to default which is livekit.VideoQuality_LOW
- UpdateTrackSettings{quality: livekit.VideoQuality_LOW} - this one got
tripped as duplicate because the previous message initialized quality
to LOW.
Fix it by recording whether track settings have been seen.
no auto subscribe + quality setting to LOW test failed before this
change and passes with this change.
* patch all track setting fields
This commit is contained in:
@@ -17,31 +17,38 @@ const (
|
|||||||
// --------------------------------------------------
|
// --------------------------------------------------
|
||||||
|
|
||||||
type subscriptionSetting struct {
|
type subscriptionSetting struct {
|
||||||
isEnabled bool
|
isEnabled bool
|
||||||
quality livekit.VideoQuality
|
trackSettingsSeen bool
|
||||||
width uint32
|
quality livekit.VideoQuality
|
||||||
height uint32
|
width uint32
|
||||||
fps uint32
|
height uint32
|
||||||
|
fps uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func subscriptionSettingFromUpdateSubscription(us *livekit.UpdateSubscription) *subscriptionSetting {
|
func subscriptionSettingFromUpdateSubscription(us *livekit.UpdateSubscription, existing *subscriptionSetting) *subscriptionSetting {
|
||||||
return &subscriptionSetting{
|
var ss subscriptionSetting
|
||||||
isEnabled: us.Subscribe,
|
if existing != nil {
|
||||||
|
ss = *existing
|
||||||
}
|
}
|
||||||
|
ss.isEnabled = us.Subscribe
|
||||||
|
return &ss
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func subscriptionSettingFromUpdateTrackSettings(uts *livekit.UpdateTrackSettings) *subscriptionSetting {
|
func subscriptionSettingFromUpdateTrackSettings(uts *livekit.UpdateTrackSettings) *subscriptionSetting {
|
||||||
return &subscriptionSetting{
|
return &subscriptionSetting{
|
||||||
isEnabled: !uts.Disabled,
|
isEnabled: !uts.Disabled,
|
||||||
quality: uts.Quality,
|
trackSettingsSeen: true,
|
||||||
width: uts.Width,
|
quality: uts.Quality,
|
||||||
height: uts.Height,
|
width: uts.Width,
|
||||||
fps: uts.Fps,
|
height: uts.Height,
|
||||||
|
fps: uts.Fps,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *subscriptionSetting) Equal(other *subscriptionSetting) bool {
|
func (s *subscriptionSetting) Equal(other *subscriptionSetting) bool {
|
||||||
return s.isEnabled == other.isEnabled &&
|
return s.isEnabled == other.isEnabled &&
|
||||||
|
s.trackSettingsSeen == other.trackSettingsSeen &&
|
||||||
s.quality == other.quality &&
|
s.quality == other.quality &&
|
||||||
s.width == other.width &&
|
s.width == other.width &&
|
||||||
s.height == other.height &&
|
s.height == other.height &&
|
||||||
@@ -111,8 +118,15 @@ func (s *SubscriptionDeduper) updateSubscriptionsFromUpdateSubscription(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newSetting := subscriptionSettingFromUpdateSubscription(us)
|
|
||||||
for trackID := range trackIDs {
|
for trackID := range trackIDs {
|
||||||
|
var existingSetting *subscriptionSetting
|
||||||
|
existingState := s.getSubscriptionState(participantKey, trackID)
|
||||||
|
if existingState != nil {
|
||||||
|
existingSetting = existingState.setting
|
||||||
|
}
|
||||||
|
|
||||||
|
newSetting := subscriptionSettingFromUpdateSubscription(us, existingSetting)
|
||||||
|
|
||||||
isTrackDupe := s.detectDupe(participantKey, trackID, newSetting)
|
isTrackDupe := s.detectDupe(participantKey, trackID, newSetting)
|
||||||
if !isTrackDupe {
|
if !isTrackDupe {
|
||||||
isDupe = false
|
isDupe = false
|
||||||
@@ -160,8 +174,7 @@ func (s *SubscriptionDeduper) detectDupe(
|
|||||||
updatedSetting *subscriptionSetting,
|
updatedSetting *subscriptionSetting,
|
||||||
) bool {
|
) bool {
|
||||||
isDupe := true
|
isDupe := true
|
||||||
participantSubscriptions := s.getOrCreateParticipantSubscriptions(participantKey)
|
state := s.getSubscriptionState(participantKey, trackID)
|
||||||
state := participantSubscriptions[trackID]
|
|
||||||
if state == nil || !state.setting.Equal(updatedSetting) {
|
if state == nil || !state.setting.Equal(updatedSetting) {
|
||||||
// new track seen or subscription setting change
|
// new track seen or subscription setting change
|
||||||
state = &subscriptionState{
|
state = &subscriptionState{
|
||||||
@@ -177,8 +190,18 @@ func (s *SubscriptionDeduper) detectDupe(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !isDupe {
|
if !isDupe {
|
||||||
participantSubscriptions[trackID] = state
|
s.setSubscriptionState(participantKey, trackID, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
return isDupe
|
return isDupe
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *SubscriptionDeduper) getSubscriptionState(participantKey livekit.ParticipantKey, trackID livekit.TrackID) *subscriptionState {
|
||||||
|
participantSubscriptions := s.getOrCreateParticipantSubscriptions(participantKey)
|
||||||
|
return participantSubscriptions[trackID]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SubscriptionDeduper) setSubscriptionState(participantKey livekit.ParticipantKey, trackID livekit.TrackID, state *subscriptionState) {
|
||||||
|
participantSubscriptions := s.getOrCreateParticipantSubscriptions(participantKey)
|
||||||
|
participantSubscriptions[trackID] = state
|
||||||
|
}
|
||||||
|
|||||||
@@ -74,8 +74,21 @@ func TestSubscriptionDeduper(t *testing.T) {
|
|||||||
}
|
}
|
||||||
require.True(t, sd.Dedupe("p0", us))
|
require.True(t, sd.Dedupe("p0", us))
|
||||||
|
|
||||||
// update track settings, should not be a dupe
|
// update track settings with quality, should not be a dupe
|
||||||
uts := &livekit.SignalRequest{
|
uts := &livekit.SignalRequest{
|
||||||
|
Message: &livekit.SignalRequest_TrackSetting{
|
||||||
|
TrackSetting: &livekit.UpdateTrackSettings{
|
||||||
|
TrackSids: []string{
|
||||||
|
"p1.track1",
|
||||||
|
},
|
||||||
|
Quality: livekit.VideoQuality_LOW,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
require.False(t, sd.Dedupe("p0", uts))
|
||||||
|
|
||||||
|
// update track settings with dimensions, should not be a dupe
|
||||||
|
uts = &livekit.SignalRequest{
|
||||||
Message: &livekit.SignalRequest_TrackSetting{
|
Message: &livekit.SignalRequest_TrackSetting{
|
||||||
TrackSetting: &livekit.UpdateTrackSettings{
|
TrackSetting: &livekit.UpdateTrackSettings{
|
||||||
TrackSids: []string{
|
TrackSids: []string{
|
||||||
|
|||||||
Reference in New Issue
Block a user