Plug a couple of holes in stream transitions. (#1905)

* Plug a couple of holes in stream transitions.

1. Missed negative sign meant stealing bits from other tracks was not
   working.
2. When a track change (mute, unmute, subscription change) cannot be
   allocated, explicitly pause so that stream state update happens.

Refactor stream state update a bit to make it a bit cleaner.

* correct comment
This commit is contained in:
Raja Subramanian
2023-07-26 13:36:58 +05:30
committed by GitHub
parent 34a7b60991
commit 0484a68342
5 changed files with 67 additions and 50 deletions
+20 -12
View File
@@ -1,6 +1,8 @@
package streamallocator
import (
"fmt"
"github.com/livekit/protocol/livekit"
)
@@ -9,18 +11,21 @@ import (
type StreamState int
const (
StreamStateActive StreamState = iota
StreamStateInactive StreamState = iota
StreamStateActive
StreamStatePaused
)
func (s StreamState) String() string {
switch s {
case StreamStateInactive:
return "INACTIVE"
case StreamStateActive:
return "active"
return "ACTIVE"
case StreamStatePaused:
return "paused"
return "PAUSED"
default:
return "unknown"
return fmt.Sprintf("UNKNOWN: %d", int(s))
}
}
@@ -40,19 +45,22 @@ func NewStreamStateUpdate() *StreamStateUpdate {
return &StreamStateUpdate{}
}
func (s *StreamStateUpdate) HandleStreamingChange(isPaused bool, track *Track) {
if isPaused {
s.StreamStates = append(s.StreamStates, &StreamStateInfo{
ParticipantID: track.PublisherID(),
TrackID: track.ID(),
State: StreamStatePaused,
})
} else {
func (s *StreamStateUpdate) HandleStreamingChange(track *Track, streamState StreamState) {
switch streamState {
case StreamStateInactive:
// inactive is not a notification, could get into this state because of mute
case StreamStateActive:
s.StreamStates = append(s.StreamStates, &StreamStateInfo{
ParticipantID: track.PublisherID(),
TrackID: track.ID(),
State: StreamStateActive,
})
case StreamStatePaused:
s.StreamStates = append(s.StreamStates, &StreamStateInfo{
ParticipantID: track.PublisherID(),
TrackID: track.ID(),
State: StreamStatePaused,
})
}
}