From a96069969d1c39d759cac25c7999fa84c2a3032e Mon Sep 17 00:00:00 2001 From: David Zhao Date: Sun, 14 Feb 2021 14:30:23 -0800 Subject: [PATCH] support audio level extension & active speaker detection (#20) * send active speaker updates with audio level * add test on loudness sorting * use a float to represent audio level --- pkg/config/config.go | 24 +- pkg/rtc/audiolevel.go | 70 +++++ pkg/rtc/audiolevel_test.go | 65 ++++ pkg/rtc/mediatrack.go | 31 +- pkg/rtc/participant.go | 44 ++- pkg/rtc/participant_internal_test.go | 4 +- pkg/rtc/room.go | 84 ++++- pkg/rtc/room_test.go | 68 +++- pkg/rtc/types/interfaces.go | 2 + pkg/rtc/types/typesfakes/fake_participant.go | 149 +++++++++ pkg/service/roommanager.go | 9 +- pkg/service/utils.go | 2 + pkg/service/wire_gen.go | 3 +- proto/livekit/rtc.pb.go | 315 ++++++++++++++----- proto/rtc.proto | 14 + 15 files changed, 775 insertions(+), 109 deletions(-) create mode 100644 pkg/rtc/audiolevel.go create mode 100644 pkg/rtc/audiolevel_test.go diff --git a/pkg/config/config.go b/pkg/config/config.go index 7a531d28..979d8c41 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -12,6 +12,7 @@ type Config struct { Port uint32 `yaml:"port"` RTC RTCConfig `yaml:"rtc"` Redis RedisConfig `yaml:"redis"` + Audio AudioConfig `yaml:"audio"` KeyFile string `yaml:"key_file"` Keys map[string]string `yaml:"keys"` LogLevel string `yaml:"log_level"` @@ -25,10 +26,21 @@ type RTCConfig struct { StunServers []string `yaml:"stun_servers"` UseExternalIP bool `yaml:"use_external_ip"` + // Max bitrate for REMB MaxBitrate uint64 `yaml:"max_bitrate"` MaxBufferTime int `yaml:"max_buffer_time"` } +type AudioConfig struct { + // minimum level to be considered active, 0-127, where 0 is loudest + ActiveLevel uint8 `yaml:"active_level"` + // percentile to measure, a participant is considered active if it has exceeded the ActiveLevel more than + // MinPercentile% of the time + MinPercentile uint8 `yaml:"min_percentile"` + // interval to update clients, in ms + UpdateInterval uint32 `yaml:"update_interval"` +} + type RedisConfig struct { Address string `yaml:"address"` Password string `yaml:"password"` @@ -43,8 +55,14 @@ func NewConfig(confString string) (*Config, error) { ICEPortRangeEnd: 10000, StunServers: []string{ "stun.l.google.com:19302", + "stun1.l.google.com:19302", }, - MaxBitrate: 2 * 1024 * 1024, // 3 mbps + MaxBitrate: 3 * 1024 * 1024, // 3 mbps + }, + Audio: AudioConfig{ + ActiveLevel: 40, + MinPercentile: 20, + UpdateInterval: 1000, }, Redis: RedisConfig{}, Keys: map[string]string{}, @@ -102,3 +120,7 @@ func (conf *Config) unmarshalKeys(keys string) error { } return nil } + +func GetAudioConfig(conf *Config) AudioConfig { + return conf.Audio +} diff --git a/pkg/rtc/audiolevel.go b/pkg/rtc/audiolevel.go new file mode 100644 index 00000000..dc45d7d1 --- /dev/null +++ b/pkg/rtc/audiolevel.go @@ -0,0 +1,70 @@ +package rtc + +import ( + "sync/atomic" +) + +const ( + // number of samples to compute moving average over + averageSamples = 40 + silentAudioLevel = uint8(127) +) + +// keeps track of audio level for a participant +type AudioLevel struct { + levelThreshold uint8 + minPercentile uint8 + currentLevel atomic.Value + // min samples to be considered active + minSamples uint32 + + // for Observe goroutine use + // keeps track of current running average + sum uint32 + activeSamples uint32 + numSamples uint32 +} + +func NewAudioLevel(activeLevel uint8, minPercentile uint8) *AudioLevel { + l := &AudioLevel{ + levelThreshold: activeLevel, + minPercentile: minPercentile, + minSamples: uint32(minPercentile) * averageSamples / 100, + } + l.currentLevel.Store(silentAudioLevel) + return l +} + +// Observes a new sample, must be called from the same thread +func (l *AudioLevel) Observe(level uint8) { + l.numSamples++ + + if level <= l.levelThreshold { + l.activeSamples++ + l.sum += uint32(level) + } + + if l.numSamples >= averageSamples { + // compute and reset + if l.activeSamples >= l.minSamples { + l.currentLevel.Store(uint8(l.sum / l.activeSamples)) + } else { + // nil to represent not noisy + l.currentLevel.Store(silentAudioLevel) + } + l.sum = 0 + l.activeSamples = 0 + l.numSamples = 0 + } +} + +// returns current audio level, 0 (loudest) to 127 (silent) +func (l *AudioLevel) GetLevel() (level uint8, noisy bool) { + level = l.currentLevel.Load().(uint8) + noisy = level != silentAudioLevel + return +} + +func convertAudioLevel(level uint8) float32 { + return (127 - float32(level)) / 127 +} diff --git a/pkg/rtc/audiolevel_test.go b/pkg/rtc/audiolevel_test.go new file mode 100644 index 00000000..c87b3db9 --- /dev/null +++ b/pkg/rtc/audiolevel_test.go @@ -0,0 +1,65 @@ +package rtc_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/livekit/livekit-server/pkg/rtc" +) + +const ( + defaultActiveLevel = 30 + // requires two noisy samples to count + defaultPercentile = 5 +) + +func TestAudioLevel(t *testing.T) { + t.Run("initially to return not noisy, within a few samples", func(t *testing.T) { + a := rtc.NewAudioLevel(defaultActiveLevel, defaultPercentile) + _, noisy := a.GetLevel() + assert.False(t, noisy) + + observeSamples(a, 35, 5) + _, noisy = a.GetLevel() + assert.False(t, noisy) + }) + + t.Run("not noisy when all samples are below threshold", func(t *testing.T) { + a := rtc.NewAudioLevel(defaultActiveLevel, defaultPercentile) + + observeSamples(a, 35, 100) + _, noisy := a.GetLevel() + assert.False(t, noisy) + }) + + t.Run("not noisy when less than percentile samples are above threshold", func(t *testing.T) { + a := rtc.NewAudioLevel(defaultActiveLevel, defaultPercentile) + + observeSamples(a, 35, 39) + observeSamples(a, 25, 1) + observeSamples(a, 35, 1) + + _, noisy := a.GetLevel() + assert.False(t, noisy) + }) + + t.Run("noisy when higher than percentile samples are above threshold", func(t *testing.T) { + a := rtc.NewAudioLevel(defaultActiveLevel, defaultPercentile) + + observeSamples(a, 35, 37) + observeSamples(a, 25, 1) + observeSamples(a, 29, 2) + + level, noisy := a.GetLevel() + assert.True(t, noisy) + assert.Less(t, level, uint8(defaultActiveLevel)) + assert.Greater(t, level, uint8(25)) + }) +} + +func observeSamples(a *rtc.AudioLevel, level uint8, count int) { + for i := 0; i < count; i++ { + a.Observe(level) + } +} diff --git a/pkg/rtc/mediatrack.go b/pkg/rtc/mediatrack.go index 1cd7afe7..6b62e1c4 100644 --- a/pkg/rtc/mediatrack.go +++ b/pkg/rtc/mediatrack.go @@ -12,6 +12,7 @@ import ( "github.com/pion/webrtc/v3" "github.com/pion/webrtc/v3/pkg/rtcerr" + "github.com/livekit/livekit-server/pkg/config" "github.com/livekit/livekit-server/pkg/logger" "github.com/livekit/livekit-server/pkg/rtc/types" "github.com/livekit/livekit-server/pkg/utils" @@ -33,13 +34,14 @@ type MediaTrack struct { participantId string muted utils.AtomicFlag - ssrc webrtc.SSRC - name string - streamID string - kind livekit.TrackType - codec webrtc.RTPCodecParameters - conf ReceiverConfig - onClose func() + ssrc webrtc.SSRC + name string + streamID string + kind livekit.TrackType + codec webrtc.RTPCodecParameters + receiverConf ReceiverConfig + audioConf config.AudioConfig + onClose func() // channel to send RTCP packets to the source rtcpCh chan []rtcp.Packet @@ -47,12 +49,13 @@ type MediaTrack struct { // map of target participantId -> *SubscribedTrack subscribedTracks map[string]*SubscribedTrack twcc *twcc.Responder + audioLevel *AudioLevel receiver sfu.Receiver //lastNack int64 lastPLI time.Time } -func NewMediaTrack(trackId string, pId string, rtcpCh chan []rtcp.Packet, conf ReceiverConfig, track *webrtc.TrackRemote) *MediaTrack { +func NewMediaTrack(trackId string, pId string, rtcpCh chan []rtcp.Packet, track *webrtc.TrackRemote, rc ReceiverConfig, ac config.AudioConfig) *MediaTrack { t := &MediaTrack{ id: trackId, participantId: pId, @@ -60,7 +63,8 @@ func NewMediaTrack(trackId string, pId string, rtcpCh chan []rtcp.Packet, conf R streamID: track.StreamID(), kind: ToProtoTrackKind(track.Kind()), codec: track.Codec(), - conf: conf, + receiverConf: rc, + audioConf: ac, rtcpCh: rtcpCh, lock: sync.RWMutex{}, subscribedTracks: make(map[string]*SubscribedTrack), @@ -209,7 +213,10 @@ func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.Tra }) if t.Kind() == livekit.TrackType_AUDIO { - // TODO: audio level stuff + t.audioLevel = NewAudioLevel(t.audioConf.ActiveLevel, t.audioConf.MinPercentile) + buff.OnAudioLevel(func(level uint8) { + t.audioLevel.Observe(level) + }) } else if t.Kind() == livekit.TrackType_VIDEO { if twcc != nil { buff.OnTransportWideCC(func(sn uint16, timeNS int64, marker bool) { @@ -259,8 +266,8 @@ func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.Tra t.receiver.AddUpTrack(track, buff) buff.Bind(receiver.GetParameters(), buffer.Options{ - BufferTime: t.conf.maxBufferTime, - MaxBitRate: t.conf.maxBitrate, + BufferTime: t.receiverConf.maxBufferTime, + MaxBitRate: t.receiverConf.maxBitrate, }) } diff --git a/pkg/rtc/participant.go b/pkg/rtc/participant.go index 8c0d417f..3c362a1f 100644 --- a/pkg/rtc/participant.go +++ b/pkg/rtc/participant.go @@ -13,6 +13,7 @@ import ( "github.com/pkg/errors" "github.com/thoas/go-funk" + "github.com/livekit/livekit-server/pkg/config" "github.com/livekit/livekit-server/pkg/logger" "github.com/livekit/livekit-server/pkg/routing" "github.com/livekit/livekit-server/pkg/rtc/types" @@ -32,6 +33,7 @@ type ParticipantImpl struct { subscriber *PCTransport responseSink routing.MessageSink receiverConfig ReceiverConfig + audioConfig config.AudioConfig isClosed utils.AtomicFlag identity string // JSON encoded metadata to pass to clients @@ -58,14 +60,15 @@ type ParticipantImpl struct { onClose func(types.Participant) } -func NewParticipant(identity string, conf *WebRTCConfig, rs routing.MessageSink, receiverConfig ReceiverConfig) (*ParticipantImpl, error) { +func NewParticipant(identity string, conf *WebRTCConfig, rs routing.MessageSink, rc ReceiverConfig, ac config.AudioConfig) (*ParticipantImpl, error) { // TODO: check to ensure params are valid, id and identity can't be empty p := &ParticipantImpl{ id: utils.NewGuid(utils.ParticipantPrefix), identity: identity, responseSink: rs, - receiverConfig: receiverConfig, + receiverConfig: rc, + audioConfig: ac, rtcpCh: make(chan []rtcp.Packet, 50), subscribedTracks: make(map[string][]types.SubscribedTrack), lock: sync.RWMutex{}, @@ -392,6 +395,20 @@ func (p *ParticipantImpl) SendParticipantUpdate(participants []*livekit.Particip }) } +func (p *ParticipantImpl) SendActiveSpeakers(speakers []*livekit.SpeakerInfo) error { + if !p.IsReady() { + return nil + } + + return p.responseSink.WriteMessage(&livekit.SignalResponse{ + Message: &livekit.SignalResponse_Speaker{ + Speaker: &livekit.ActiveSpeakerUpdate{ + Speakers: speakers, + }, + }, + }) +} + func (p *ParticipantImpl) SetTrackMuted(trackId string, muted bool) { p.lock.RLock() defer p.lock.RUnlock() @@ -412,6 +429,27 @@ func (p *ParticipantImpl) SetTrackMuted(trackId string, muted bool) { } } +func (p *ParticipantImpl) GetAudioLevel() (level uint8, noisy bool) { + p.lock.RLock() + defer p.lock.RUnlock() + level = silentAudioLevel + for _, pt := range p.publishedTracks { + if mt, ok := pt.(*MediaTrack); ok { + if mt.audioLevel == nil { + continue + } + tl, tn := mt.audioLevel.GetLevel() + if tn { + noisy = true + if tl < level { + level = tl + } + } + } + } + return +} + func (p *ParticipantImpl) SubscriberPC() *webrtc.PeerConnection { return p.subscriber.pc } @@ -529,7 +567,7 @@ func (p *ParticipantImpl) onMediaTrack(track *webrtc.TrackRemote, rtpReceiver *w logger.Debugw("using existing mediatrack, simulcast", "rid", track.RID()) mt = trk } else { - mt = NewMediaTrack(ti.Sid, p.id, p.rtcpCh, p.receiverConfig, track) + mt = NewMediaTrack(ti.Sid, p.id, p.rtcpCh, track, p.receiverConfig, p.audioConfig) mt.name = ti.Name newTrack = true } diff --git a/pkg/rtc/participant_internal_test.go b/pkg/rtc/participant_internal_test.go index 4b8864c8..534baa74 100644 --- a/pkg/rtc/participant_internal_test.go +++ b/pkg/rtc/participant_internal_test.go @@ -5,6 +5,7 @@ import ( "github.com/stretchr/testify/assert" + "github.com/livekit/livekit-server/pkg/config" "github.com/livekit/livekit-server/pkg/routing" "github.com/livekit/livekit-server/pkg/routing/routingfakes" "github.com/livekit/livekit-server/pkg/rtc/types" @@ -123,6 +124,7 @@ func newParticipantForTest(identity string) *ParticipantImpl { identity, &WebRTCConfig{}, &routingfakes.FakeMessageSink{}, - ReceiverConfig{}) + ReceiverConfig{}, + config.AudioConfig{}) return p } diff --git a/pkg/rtc/room.go b/pkg/rtc/room.go index 35d07e21..7a0c8698 100644 --- a/pkg/rtc/room.go +++ b/pkg/rtc/room.go @@ -1,12 +1,11 @@ package rtc import ( + "sort" "sync" "sync/atomic" "time" - "github.com/thoas/go-funk" - "github.com/livekit/livekit-server/pkg/logger" "github.com/livekit/livekit-server/pkg/rtc/types" "github.com/livekit/livekit-server/pkg/utils" @@ -29,16 +28,21 @@ type Room struct { leftAt atomic.Value isClosed utils.AtomicFlag + // for active speaker updates + audioUpdateInterval uint32 + lastActiveSpeakers []*livekit.SpeakerInfo + onParticipantChanged func(p types.Participant) onClose func() } -func NewRoom(room *livekit.Room, config WebRTCConfig) *Room { +func NewRoom(room *livekit.Room, config WebRTCConfig, audioUpdateInterval uint32) *Room { r := &Room{ - Room: *room, - config: config, - lock: sync.RWMutex{}, - participants: make(map[string]types.Participant), + Room: *room, + config: config, + audioUpdateInterval: audioUpdateInterval, + lock: sync.RWMutex{}, + participants: make(map[string]types.Participant), } if r.EmptyTimeout == 0 { r.EmptyTimeout = DefaultEmptyTimeout @@ -46,6 +50,7 @@ func NewRoom(room *livekit.Room, config WebRTCConfig) *Room { if r.CreationTime == 0 { r.CreationTime = time.Now().Unix() } + go r.audioUpdateWorker() return r } @@ -58,7 +63,32 @@ func (r *Room) GetParticipant(identity string) types.Participant { func (r *Room) GetParticipants() []types.Participant { r.lock.RLock() defer r.lock.RUnlock() - return funk.Values(r.participants).([]types.Participant) + participants := make([]types.Participant, 0, len(r.participants)) + for _, p := range r.participants { + participants = append(participants, p) + } + return participants +} + +func (r *Room) GetActiveSpeakers() []*livekit.SpeakerInfo { + participants := r.GetParticipants() + speakers := make([]*livekit.SpeakerInfo, 0, len(participants)) + for _, p := range participants { + level, active := p.GetAudioLevel() + if !active { + continue + } + speakers = append(speakers, &livekit.SpeakerInfo{ + Sid: p.ID(), + Level: convertAudioLevel(level), + Active: active, + }) + } + + sort.Slice(speakers, func(i, j int) bool { + return speakers[i].Level > speakers[j].Level + }) + return speakers } func (r *Room) FirstJoinedAt() int64 { @@ -271,11 +301,9 @@ func (r *Room) onTrackUpdated(p types.Participant, track types.PublishedTrack) { // broadcast an update about participant p func (r *Room) broadcastParticipantState(p types.Participant) { - r.lock.RLock() - defer r.lock.RUnlock() - updates := ToProtoParticipants([]types.Participant{p}) - for _, op := range r.participants { + participants := r.GetParticipants() + for _, op := range participants { // skip itself && closed participants if p.ID() == op.ID() || op.State() == livekit.ParticipantInfo_DISCONNECTED { continue @@ -289,3 +317,35 @@ func (r *Room) broadcastParticipantState(p types.Participant) { } } } + +func (r *Room) sendSpeakerUpdates(speakers []*livekit.SpeakerInfo) { + for _, p := range r.GetParticipants() { + p.SendActiveSpeakers(speakers) + } +} + +func (r *Room) audioUpdateWorker() { + for { + if r.isClosed.Get() { + return + } + + speakers := r.GetActiveSpeakers() + + // see if an update is needed + if len(speakers) == len(r.lastActiveSpeakers) { + for i, speaker := range speakers { + if speaker.Sid != r.lastActiveSpeakers[i].Sid { + r.sendSpeakerUpdates(speakers) + break + } + } + } else { + r.sendSpeakerUpdates(speakers) + } + + r.lastActiveSpeakers = speakers + + time.Sleep(time.Duration(r.audioUpdateInterval) * time.Millisecond) + } +} diff --git a/pkg/rtc/room_test.go b/pkg/rtc/room_test.go index c662e9b4..66b07c2c 100644 --- a/pkg/rtc/room_test.go +++ b/pkg/rtc/room_test.go @@ -15,8 +15,9 @@ import ( ) const ( - numParticipants = 3 - defaultDelay = 10 * time.Millisecond + numParticipants = 3 + defaultDelay = 10 * time.Millisecond + audioUpdateInterval = 25 ) func init() { @@ -199,17 +200,78 @@ func TestNewTrack(t *testing.T) { }) } +func TestActiveSpeakers(t *testing.T) { + t.Parallel() + audioUpdateDuration := (audioUpdateInterval + 2) * time.Millisecond + t.Run("participant should not be getting audio updates", func(t *testing.T) { + rm := newRoomWithParticipants(t, 1) + p := rm.GetParticipants()[0].(*typesfakes.FakeParticipant) + assert.Empty(t, rm.GetActiveSpeakers()) + + time.Sleep(audioUpdateDuration) + + assert.Zero(t, p.SendActiveSpeakersCallCount()) + }) + + t.Run("speakers should be sorted by loudness", func(t *testing.T) { + rm := newRoomWithParticipants(t, 2) + participants := rm.GetParticipants() + p := participants[0].(*typesfakes.FakeParticipant) + p2 := participants[1].(*typesfakes.FakeParticipant) + p.GetAudioLevelReturns(10, true) + p2.GetAudioLevelReturns(20, true) + + speakers := rm.GetActiveSpeakers() + assert.Len(t, speakers, 2) + assert.Equal(t, p.ID(), speakers[0].Sid) + assert.Equal(t, p2.ID(), speakers[1].Sid) + }) + + t.Run("participants are getting updates when active", func(t *testing.T) { + rm := newRoomWithParticipants(t, 2) + participants := rm.GetParticipants() + p := participants[0].(*typesfakes.FakeParticipant) + time.Sleep(time.Millisecond) // let the first update cycle run + p.GetAudioLevelReturns(30, true) + + speakers := rm.GetActiveSpeakers() + assert.NotEmpty(t, speakers) + assert.Equal(t, p.ID(), speakers[0].Sid) + + time.Sleep(audioUpdateDuration) + + // everyone should've received updates + for _, op := range participants { + op := op.(*typesfakes.FakeParticipant) + assert.Equal(t, 1, op.SendActiveSpeakersCallCount()) + } + + // after another cycle, we are not getting any new updates since unchanged + time.Sleep(audioUpdateDuration) + for _, op := range participants { + op := op.(*typesfakes.FakeParticipant) + assert.Equal(t, 1, op.SendActiveSpeakersCallCount()) + } + + // no longer speaking, send update with empty items + p.GetAudioLevelReturns(127, false) + time.Sleep(audioUpdateDuration) + assert.Equal(t, 2, p.SendActiveSpeakersCallCount()) + assert.Empty(t, p.SendActiveSpeakersArgsForCall(1)) + }) +} + func newRoomWithParticipants(t *testing.T, num int) *rtc.Room { rm := rtc.NewRoom( &livekit.Room{Name: "room"}, rtc.WebRTCConfig{}, + audioUpdateInterval, ) for i := 0; i < num; i++ { identity := fmt.Sprintf("p%d", i) participant := newMockParticipant(identity) err := rm.Join(participant) assert.NoError(t, err) - //rm.participants[participant.ID()] = participant } return rm } diff --git a/pkg/rtc/types/interfaces.go b/pkg/rtc/types/interfaces.go index 1d7d3497..dc584e9f 100644 --- a/pkg/rtc/types/interfaces.go +++ b/pkg/rtc/types/interfaces.go @@ -41,7 +41,9 @@ type Participant interface { RemoveSubscriber(peerId string) SendJoinResponse(info *livekit.Room, otherParticipants []Participant) error SendParticipantUpdate(participants []*livekit.ParticipantInfo) error + SendActiveSpeakers(speakers []*livekit.SpeakerInfo) error SetTrackMuted(trackId string, muted bool) + GetAudioLevel() (level uint8, noisy bool) Start() Close() error diff --git a/pkg/rtc/types/typesfakes/fake_participant.go b/pkg/rtc/types/typesfakes/fake_participant.go index 20960e31..ce996f3c 100644 --- a/pkg/rtc/types/typesfakes/fake_participant.go +++ b/pkg/rtc/types/typesfakes/fake_participant.go @@ -58,6 +58,18 @@ type FakeParticipant struct { closeReturnsOnCall map[int]struct { result1 error } + GetAudioLevelStub func() (uint8, bool) + getAudioLevelMutex sync.RWMutex + getAudioLevelArgsForCall []struct { + } + getAudioLevelReturns struct { + result1 uint8 + result2 bool + } + getAudioLevelReturnsOnCall map[int]struct { + result1 uint8 + result2 bool + } GetResponseSinkStub func() routing.MessageSink getResponseSinkMutex sync.RWMutex getResponseSinkArgsForCall []struct { @@ -163,6 +175,17 @@ type FakeParticipant struct { removeSubscriberArgsForCall []struct { arg1 string } + SendActiveSpeakersStub func([]*livekit.SpeakerInfo) error + sendActiveSpeakersMutex sync.RWMutex + sendActiveSpeakersArgsForCall []struct { + arg1 []*livekit.SpeakerInfo + } + sendActiveSpeakersReturns struct { + result1 error + } + sendActiveSpeakersReturnsOnCall map[int]struct { + result1 error + } SendJoinResponseStub func(*livekit.Room, []types.Participant) error sendJoinResponseMutex sync.RWMutex sendJoinResponseArgsForCall []struct { @@ -499,6 +522,62 @@ func (fake *FakeParticipant) CloseReturnsOnCall(i int, result1 error) { }{result1} } +func (fake *FakeParticipant) GetAudioLevel() (uint8, bool) { + fake.getAudioLevelMutex.Lock() + ret, specificReturn := fake.getAudioLevelReturnsOnCall[len(fake.getAudioLevelArgsForCall)] + fake.getAudioLevelArgsForCall = append(fake.getAudioLevelArgsForCall, struct { + }{}) + stub := fake.GetAudioLevelStub + fakeReturns := fake.getAudioLevelReturns + fake.recordInvocation("GetAudioLevel", []interface{}{}) + fake.getAudioLevelMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *FakeParticipant) GetAudioLevelCallCount() int { + fake.getAudioLevelMutex.RLock() + defer fake.getAudioLevelMutex.RUnlock() + return len(fake.getAudioLevelArgsForCall) +} + +func (fake *FakeParticipant) GetAudioLevelCalls(stub func() (uint8, bool)) { + fake.getAudioLevelMutex.Lock() + defer fake.getAudioLevelMutex.Unlock() + fake.GetAudioLevelStub = stub +} + +func (fake *FakeParticipant) GetAudioLevelReturns(result1 uint8, result2 bool) { + fake.getAudioLevelMutex.Lock() + defer fake.getAudioLevelMutex.Unlock() + fake.GetAudioLevelStub = nil + fake.getAudioLevelReturns = struct { + result1 uint8 + result2 bool + }{result1, result2} +} + +func (fake *FakeParticipant) GetAudioLevelReturnsOnCall(i int, result1 uint8, result2 bool) { + fake.getAudioLevelMutex.Lock() + defer fake.getAudioLevelMutex.Unlock() + fake.GetAudioLevelStub = nil + if fake.getAudioLevelReturnsOnCall == nil { + fake.getAudioLevelReturnsOnCall = make(map[int]struct { + result1 uint8 + result2 bool + }) + } + fake.getAudioLevelReturnsOnCall[i] = struct { + result1 uint8 + result2 bool + }{result1, result2} +} + func (fake *FakeParticipant) GetResponseSink() routing.MessageSink { fake.getResponseSinkMutex.Lock() ret, specificReturn := fake.getResponseSinkReturnsOnCall[len(fake.getResponseSinkArgsForCall)] @@ -1082,6 +1161,72 @@ func (fake *FakeParticipant) RemoveSubscriberArgsForCall(i int) string { return argsForCall.arg1 } +func (fake *FakeParticipant) SendActiveSpeakers(arg1 []*livekit.SpeakerInfo) error { + var arg1Copy []*livekit.SpeakerInfo + if arg1 != nil { + arg1Copy = make([]*livekit.SpeakerInfo, len(arg1)) + copy(arg1Copy, arg1) + } + fake.sendActiveSpeakersMutex.Lock() + ret, specificReturn := fake.sendActiveSpeakersReturnsOnCall[len(fake.sendActiveSpeakersArgsForCall)] + fake.sendActiveSpeakersArgsForCall = append(fake.sendActiveSpeakersArgsForCall, struct { + arg1 []*livekit.SpeakerInfo + }{arg1Copy}) + stub := fake.SendActiveSpeakersStub + fakeReturns := fake.sendActiveSpeakersReturns + fake.recordInvocation("SendActiveSpeakers", []interface{}{arg1Copy}) + fake.sendActiveSpeakersMutex.Unlock() + if stub != nil { + return stub(arg1) + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *FakeParticipant) SendActiveSpeakersCallCount() int { + fake.sendActiveSpeakersMutex.RLock() + defer fake.sendActiveSpeakersMutex.RUnlock() + return len(fake.sendActiveSpeakersArgsForCall) +} + +func (fake *FakeParticipant) SendActiveSpeakersCalls(stub func([]*livekit.SpeakerInfo) error) { + fake.sendActiveSpeakersMutex.Lock() + defer fake.sendActiveSpeakersMutex.Unlock() + fake.SendActiveSpeakersStub = stub +} + +func (fake *FakeParticipant) SendActiveSpeakersArgsForCall(i int) []*livekit.SpeakerInfo { + fake.sendActiveSpeakersMutex.RLock() + defer fake.sendActiveSpeakersMutex.RUnlock() + argsForCall := fake.sendActiveSpeakersArgsForCall[i] + return argsForCall.arg1 +} + +func (fake *FakeParticipant) SendActiveSpeakersReturns(result1 error) { + fake.sendActiveSpeakersMutex.Lock() + defer fake.sendActiveSpeakersMutex.Unlock() + fake.SendActiveSpeakersStub = nil + fake.sendActiveSpeakersReturns = struct { + result1 error + }{result1} +} + +func (fake *FakeParticipant) SendActiveSpeakersReturnsOnCall(i int, result1 error) { + fake.sendActiveSpeakersMutex.Lock() + defer fake.sendActiveSpeakersMutex.Unlock() + fake.SendActiveSpeakersStub = nil + if fake.sendActiveSpeakersReturnsOnCall == nil { + fake.sendActiveSpeakersReturnsOnCall = make(map[int]struct { + result1 error + }) + } + fake.sendActiveSpeakersReturnsOnCall[i] = struct { + result1 error + }{result1} +} + func (fake *FakeParticipant) SendJoinResponse(arg1 *livekit.Room, arg2 []types.Participant) error { var arg2Copy []types.Participant if arg2 != nil { @@ -1590,6 +1735,8 @@ func (fake *FakeParticipant) Invocations() map[string][][]interface{} { defer fake.addTrackMutex.RUnlock() fake.closeMutex.RLock() defer fake.closeMutex.RUnlock() + fake.getAudioLevelMutex.RLock() + defer fake.getAudioLevelMutex.RUnlock() fake.getResponseSinkMutex.RLock() defer fake.getResponseSinkMutex.RUnlock() fake.handleAnswerMutex.RLock() @@ -1616,6 +1763,8 @@ func (fake *FakeParticipant) Invocations() map[string][][]interface{} { defer fake.removeSubscribedTrackMutex.RUnlock() fake.removeSubscriberMutex.RLock() defer fake.removeSubscriberMutex.RUnlock() + fake.sendActiveSpeakersMutex.RLock() + defer fake.sendActiveSpeakersMutex.RUnlock() fake.sendJoinResponseMutex.RLock() defer fake.sendJoinResponseMutex.RUnlock() fake.sendParticipantUpdateMutex.RLock() diff --git a/pkg/service/roommanager.go b/pkg/service/roommanager.go index b178120f..889d9d7d 100644 --- a/pkg/service/roommanager.go +++ b/pkg/service/roommanager.go @@ -7,6 +7,7 @@ import ( "github.com/thoas/go-funk" + "github.com/livekit/livekit-server/pkg/config" "github.com/livekit/livekit-server/pkg/logger" "github.com/livekit/livekit-server/pkg/routing" "github.com/livekit/livekit-server/pkg/rtc" @@ -28,14 +29,16 @@ type RoomManager struct { router routing.Router currentNode routing.LocalNode config *rtc.WebRTCConfig + audioConfig config.AudioConfig rooms map[string]*rtc.Room } -func NewRoomManager(rp RoomStore, router routing.Router, currentNode routing.LocalNode, selector routing.NodeSelector, config *rtc.WebRTCConfig) *RoomManager { +func NewRoomManager(rp RoomStore, router routing.Router, currentNode routing.LocalNode, selector routing.NodeSelector, config *rtc.WebRTCConfig, ac config.AudioConfig) *RoomManager { return &RoomManager{ lock: sync.RWMutex{}, roomStore: rp, config: config, + audioConfig: ac, router: router, selector: selector, currentNode: currentNode, @@ -177,7 +180,7 @@ func (r *RoomManager) StartSession(roomName, identity, metadata string, reconnec "num_participants", len(room.GetParticipants()), ) - participant, err = rtc.NewParticipant(identity, r.config, responseSink, r.config.Receiver) + participant, err = rtc.NewParticipant(identity, r.config, responseSink, r.config.Receiver, r.audioConfig) if err != nil { logger.Errorw("could not create participant", "error", err) return @@ -214,7 +217,7 @@ func (r *RoomManager) getOrCreateRoom(roomName string) (*rtc.Room, error) { return nil, err } - room = rtc.NewRoom(ri, *r.config) + room = rtc.NewRoom(ri, *r.config, r.audioConfig.UpdateInterval) room.OnClose(func() { if err := r.DeleteRoom(roomName); err != nil { logger.Errorw("could not delete room", "error", err) diff --git a/pkg/service/utils.go b/pkg/service/utils.go index 5ed511bb..ee8a00f4 100644 --- a/pkg/service/utils.go +++ b/pkg/service/utils.go @@ -6,6 +6,7 @@ import ( "github.com/google/wire" "go.uber.org/zap" + "github.com/livekit/livekit-server/pkg/config" "github.com/livekit/livekit-server/pkg/logger" "github.com/livekit/livekit-server/pkg/routing" "github.com/livekit/livekit-server/pkg/rtc" @@ -17,6 +18,7 @@ var ServiceSet = wire.NewSet( NewRTCService, NewLivekitServer, NewRoomManager, + config.GetAudioConfig, wire.Bind(new(livekit.RoomService), new(*RoomService)), externalIpFromNode, ) diff --git a/pkg/service/wire_gen.go b/pkg/service/wire_gen.go index 857bf481..c67e9cc6 100644 --- a/pkg/service/wire_gen.go +++ b/pkg/service/wire_gen.go @@ -21,7 +21,8 @@ func InitializeServer(conf *config.Config, keyProvider auth.KeyProvider, roomSto if err != nil { return nil, err } - roomManager := NewRoomManager(roomStore, router, currentNode, selector, webRTCConfig) + audioConfig := config.GetAudioConfig(conf) + roomManager := NewRoomManager(roomStore, router, currentNode, selector, webRTCConfig, audioConfig) roomService, err := NewRoomService(roomManager) if err != nil { return nil, err diff --git a/proto/livekit/rtc.pb.go b/proto/livekit/rtc.pb.go index ba4cf4e5..a05d3194 100644 --- a/proto/livekit/rtc.pb.go +++ b/proto/livekit/rtc.pb.go @@ -223,6 +223,7 @@ type SignalResponse struct { // *SignalResponse_Trickle // *SignalResponse_Update // *SignalResponse_TrackPublished + // *SignalResponse_Speaker Message isSignalResponse_Message `protobuf_oneof:"message"` } @@ -307,6 +308,13 @@ func (x *SignalResponse) GetTrackPublished() *TrackPublishedResponse { return nil } +func (x *SignalResponse) GetSpeaker() *ActiveSpeakerUpdate { + if x, ok := x.GetMessage().(*SignalResponse_Speaker); ok { + return x.Speaker + } + return nil +} + type isSignalResponse_Message interface { isSignalResponse_Message() } @@ -341,6 +349,11 @@ type SignalResponse_TrackPublished struct { TrackPublished *TrackPublishedResponse `protobuf:"bytes,6,opt,name=track_published,json=trackPublished,proto3,oneof"` } +type SignalResponse_Speaker struct { + // list of active speakers + Speaker *ActiveSpeakerUpdate `protobuf:"bytes,7,opt,name=speaker,proto3,oneof"` +} + func (*SignalResponse_Join) isSignalResponse_Message() {} func (*SignalResponse_Answer) isSignalResponse_Message() {} @@ -353,6 +366,8 @@ func (*SignalResponse_Update) isSignalResponse_Message() {} func (*SignalResponse_TrackPublished) isSignalResponse_Message() {} +func (*SignalResponse_Speaker) isSignalResponse_Message() {} + type AddTrackRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -793,6 +808,118 @@ func (x *ParticipantUpdate) GetParticipants() []*ParticipantInfo { return nil } +type ActiveSpeakerUpdate struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Speakers []*SpeakerInfo `protobuf:"bytes,1,rep,name=speakers,proto3" json:"speakers,omitempty"` +} + +func (x *ActiveSpeakerUpdate) Reset() { + *x = ActiveSpeakerUpdate{} + if protoimpl.UnsafeEnabled { + mi := &file_rtc_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ActiveSpeakerUpdate) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ActiveSpeakerUpdate) ProtoMessage() {} + +func (x *ActiveSpeakerUpdate) ProtoReflect() protoreflect.Message { + mi := &file_rtc_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ActiveSpeakerUpdate.ProtoReflect.Descriptor instead. +func (*ActiveSpeakerUpdate) Descriptor() ([]byte, []int) { + return file_rtc_proto_rawDescGZIP(), []int{10} +} + +func (x *ActiveSpeakerUpdate) GetSpeakers() []*SpeakerInfo { + if x != nil { + return x.Speakers + } + return nil +} + +type SpeakerInfo struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Sid string `protobuf:"bytes,1,opt,name=sid,proto3" json:"sid,omitempty"` + // audio level, 0-1.0, 1 is loudest + Level float32 `protobuf:"fixed32,2,opt,name=level,proto3" json:"level,omitempty"` + // true if speaker is currently active + Active bool `protobuf:"varint,3,opt,name=active,proto3" json:"active,omitempty"` +} + +func (x *SpeakerInfo) Reset() { + *x = SpeakerInfo{} + if protoimpl.UnsafeEnabled { + mi := &file_rtc_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SpeakerInfo) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SpeakerInfo) ProtoMessage() {} + +func (x *SpeakerInfo) ProtoReflect() protoreflect.Message { + mi := &file_rtc_proto_msgTypes[11] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SpeakerInfo.ProtoReflect.Descriptor instead. +func (*SpeakerInfo) Descriptor() ([]byte, []int) { + return file_rtc_proto_rawDescGZIP(), []int{11} +} + +func (x *SpeakerInfo) GetSid() string { + if x != nil { + return x.Sid + } + return "" +} + +func (x *SpeakerInfo) GetLevel() float32 { + if x != nil { + return x.Level + } + return 0 +} + +func (x *SpeakerInfo) GetActive() bool { + if x != nil { + return x.Active + } + return false +} + var File_rtc_proto protoreflect.FileDescriptor var file_rtc_proto_rawDesc = []byte{ @@ -821,7 +948,7 @@ var file_rtc_proto_rawDesc = []byte{ 0x74, 0x2e, 0x4d, 0x75, 0x74, 0x65, 0x54, 0x72, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x48, 0x00, 0x52, 0x0e, 0x6d, 0x75, 0x74, 0x65, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x64, 0x42, 0x09, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, - 0xeb, 0x02, 0x0a, 0x0e, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0xa5, 0x03, 0x0a, 0x0e, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2b, 0x0a, 0x04, 0x6a, 0x6f, 0x69, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2e, 0x4a, 0x6f, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x48, 0x00, 0x52, 0x04, 0x6a, 0x6f, 0x69, 0x6e, 0x12, @@ -843,60 +970,73 @@ var file_rtc_proto_rawDesc = []byte{ 0x1f, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2e, 0x54, 0x72, 0x61, 0x63, 0x6b, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x65, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x48, 0x00, 0x52, 0x0e, 0x74, 0x72, 0x61, 0x63, 0x6b, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, - 0x65, 0x64, 0x42, 0x09, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x5f, 0x0a, - 0x0f, 0x41, 0x64, 0x64, 0x54, 0x72, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x12, 0x10, 0x0a, 0x03, 0x63, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x63, - 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x26, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, - 0x20, 0x01, 0x28, 0x0e, 0x32, 0x12, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2e, 0x54, - 0x72, 0x61, 0x63, 0x6b, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x65, - 0x0a, 0x0e, 0x54, 0x72, 0x69, 0x63, 0x6b, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x12, 0x24, 0x0a, 0x0d, 0x63, 0x61, 0x6e, 0x64, 0x69, 0x64, 0x61, 0x74, 0x65, 0x49, 0x6e, 0x69, - 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x63, 0x61, 0x6e, 0x64, 0x69, 0x64, 0x61, - 0x74, 0x65, 0x49, 0x6e, 0x69, 0x74, 0x12, 0x2d, 0x0a, 0x06, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x15, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, - 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x6c, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x52, 0x06, 0x74, - 0x61, 0x72, 0x67, 0x65, 0x74, 0x22, 0x3a, 0x0a, 0x10, 0x4d, 0x75, 0x74, 0x65, 0x54, 0x72, 0x61, - 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x69, 0x64, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x73, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x6d, - 0x75, 0x74, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x6d, 0x75, 0x74, 0x65, - 0x64, 0x22, 0x14, 0x0a, 0x12, 0x4e, 0x65, 0x67, 0x6f, 0x74, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0xdd, 0x01, 0x0a, 0x0c, 0x4a, 0x6f, 0x69, 0x6e, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x21, 0x0a, 0x04, 0x72, 0x6f, 0x6f, 0x6d, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, - 0x2e, 0x52, 0x6f, 0x6f, 0x6d, 0x52, 0x04, 0x72, 0x6f, 0x6f, 0x6d, 0x12, 0x3a, 0x0a, 0x0b, 0x70, - 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x18, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2e, 0x50, 0x61, 0x72, 0x74, 0x69, - 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x0b, 0x70, 0x61, 0x72, 0x74, - 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x12, 0x47, 0x0a, 0x12, 0x6f, 0x74, 0x68, 0x65, 0x72, - 0x5f, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x73, 0x18, 0x03, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2e, 0x50, 0x61, - 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x11, 0x6f, - 0x74, 0x68, 0x65, 0x72, 0x50, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x73, - 0x12, 0x25, 0x0a, 0x0e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, - 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, - 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x54, 0x0a, 0x16, 0x54, 0x72, 0x61, 0x63, 0x6b, - 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x65, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x12, 0x10, 0x0a, 0x03, 0x63, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, - 0x63, 0x69, 0x64, 0x12, 0x28, 0x0a, 0x05, 0x74, 0x72, 0x61, 0x63, 0x6b, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2e, 0x54, 0x72, 0x61, - 0x63, 0x6b, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x05, 0x74, 0x72, 0x61, 0x63, 0x6b, 0x22, 0x3a, 0x0a, - 0x12, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, - 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x64, 0x70, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x73, 0x64, 0x70, 0x22, 0x51, 0x0a, 0x11, 0x50, 0x61, 0x72, - 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x3c, - 0x0a, 0x0c, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x73, 0x18, 0x01, - 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2e, 0x50, - 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x0c, - 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x73, 0x2a, 0x2d, 0x0a, 0x0c, - 0x53, 0x69, 0x67, 0x6e, 0x61, 0x6c, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x12, 0x0d, 0x0a, 0x09, - 0x50, 0x55, 0x42, 0x4c, 0x49, 0x53, 0x48, 0x45, 0x52, 0x10, 0x00, 0x12, 0x0e, 0x0a, 0x0a, 0x53, - 0x55, 0x42, 0x53, 0x43, 0x52, 0x49, 0x42, 0x45, 0x52, 0x10, 0x01, 0x42, 0x31, 0x5a, 0x2f, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, - 0x74, 0x2f, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, - 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x62, 0x06, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x64, 0x12, 0x38, 0x0a, 0x07, 0x73, 0x70, 0x65, 0x61, 0x6b, 0x65, 0x72, 0x18, 0x07, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2e, 0x41, 0x63, + 0x74, 0x69, 0x76, 0x65, 0x53, 0x70, 0x65, 0x61, 0x6b, 0x65, 0x72, 0x55, 0x70, 0x64, 0x61, 0x74, + 0x65, 0x48, 0x00, 0x52, 0x07, 0x73, 0x70, 0x65, 0x61, 0x6b, 0x65, 0x72, 0x42, 0x09, 0x0a, 0x07, + 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x5f, 0x0a, 0x0f, 0x41, 0x64, 0x64, 0x54, 0x72, + 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x63, 0x69, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x63, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, + 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, + 0x12, 0x26, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x12, + 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2e, 0x54, 0x72, 0x61, 0x63, 0x6b, 0x54, 0x79, + 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x65, 0x0a, 0x0e, 0x54, 0x72, 0x69, 0x63, + 0x6b, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x24, 0x0a, 0x0d, 0x63, 0x61, + 0x6e, 0x64, 0x69, 0x64, 0x61, 0x74, 0x65, 0x49, 0x6e, 0x69, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0d, 0x63, 0x61, 0x6e, 0x64, 0x69, 0x64, 0x61, 0x74, 0x65, 0x49, 0x6e, 0x69, 0x74, + 0x12, 0x2d, 0x0a, 0x06, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, + 0x32, 0x15, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x61, + 0x6c, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x52, 0x06, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x22, + 0x3a, 0x0a, 0x10, 0x4d, 0x75, 0x74, 0x65, 0x54, 0x72, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x03, 0x73, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x6d, 0x75, 0x74, 0x65, 0x64, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x6d, 0x75, 0x74, 0x65, 0x64, 0x22, 0x14, 0x0a, 0x12, 0x4e, + 0x65, 0x67, 0x6f, 0x74, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x22, 0xdd, 0x01, 0x0a, 0x0c, 0x4a, 0x6f, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x21, 0x0a, 0x04, 0x72, 0x6f, 0x6f, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x0d, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2e, 0x52, 0x6f, 0x6f, 0x6d, 0x52, + 0x04, 0x72, 0x6f, 0x6f, 0x6d, 0x12, 0x3a, 0x0a, 0x0b, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, + 0x70, 0x61, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x6c, 0x69, 0x76, + 0x65, 0x6b, 0x69, 0x74, 0x2e, 0x50, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, + 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x0b, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, + 0x74, 0x12, 0x47, 0x0a, 0x12, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x5f, 0x70, 0x61, 0x72, 0x74, 0x69, + 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, + 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2e, 0x50, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, + 0x61, 0x6e, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x11, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x50, 0x61, + 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x73, 0x12, 0x25, 0x0a, 0x0e, 0x73, 0x65, + 0x72, 0x76, 0x65, 0x72, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, + 0x6e, 0x22, 0x54, 0x0a, 0x16, 0x54, 0x72, 0x61, 0x63, 0x6b, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, + 0x68, 0x65, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x63, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x63, 0x69, 0x64, 0x12, 0x28, 0x0a, + 0x05, 0x74, 0x72, 0x61, 0x63, 0x6b, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x6c, + 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2e, 0x54, 0x72, 0x61, 0x63, 0x6b, 0x49, 0x6e, 0x66, 0x6f, + 0x52, 0x05, 0x74, 0x72, 0x61, 0x63, 0x6b, 0x22, 0x3a, 0x0a, 0x12, 0x53, 0x65, 0x73, 0x73, 0x69, + 0x6f, 0x6e, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, + 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, + 0x65, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x64, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, + 0x73, 0x64, 0x70, 0x22, 0x51, 0x0a, 0x11, 0x50, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, + 0x6e, 0x74, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x3c, 0x0a, 0x0c, 0x70, 0x61, 0x72, 0x74, + 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, + 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2e, 0x50, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, + 0x70, 0x61, 0x6e, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x0c, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, + 0x69, 0x70, 0x61, 0x6e, 0x74, 0x73, 0x22, 0x47, 0x0a, 0x13, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, + 0x53, 0x70, 0x65, 0x61, 0x6b, 0x65, 0x72, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x30, 0x0a, + 0x08, 0x73, 0x70, 0x65, 0x61, 0x6b, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x14, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2e, 0x53, 0x70, 0x65, 0x61, 0x6b, 0x65, + 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x08, 0x73, 0x70, 0x65, 0x61, 0x6b, 0x65, 0x72, 0x73, 0x22, + 0x4d, 0x0a, 0x0b, 0x53, 0x70, 0x65, 0x61, 0x6b, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x10, + 0x0a, 0x03, 0x73, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x73, 0x69, 0x64, + 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x02, 0x52, + 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x63, 0x74, 0x69, 0x76, 0x65, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x61, 0x63, 0x74, 0x69, 0x76, 0x65, 0x2a, 0x2d, + 0x0a, 0x0c, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x6c, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x12, 0x0d, + 0x0a, 0x09, 0x50, 0x55, 0x42, 0x4c, 0x49, 0x53, 0x48, 0x45, 0x52, 0x10, 0x00, 0x12, 0x0e, 0x0a, + 0x0a, 0x53, 0x55, 0x42, 0x53, 0x43, 0x52, 0x49, 0x42, 0x45, 0x52, 0x10, 0x01, 0x42, 0x31, 0x5a, + 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6c, 0x69, 0x76, 0x65, + 0x6b, 0x69, 0x74, 0x2f, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2d, 0x73, 0x65, 0x72, 0x76, + 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -912,7 +1052,7 @@ func file_rtc_proto_rawDescGZIP() []byte { } var file_rtc_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_rtc_proto_msgTypes = make([]protoimpl.MessageInfo, 10) +var file_rtc_proto_msgTypes = make([]protoimpl.MessageInfo, 12) var file_rtc_proto_goTypes = []interface{}{ (SignalTarget)(0), // 0: livekit.SignalTarget (*SignalRequest)(nil), // 1: livekit.SignalRequest @@ -925,10 +1065,12 @@ var file_rtc_proto_goTypes = []interface{}{ (*TrackPublishedResponse)(nil), // 8: livekit.TrackPublishedResponse (*SessionDescription)(nil), // 9: livekit.SessionDescription (*ParticipantUpdate)(nil), // 10: livekit.ParticipantUpdate - (TrackType)(0), // 11: livekit.TrackType - (*Room)(nil), // 12: livekit.Room - (*ParticipantInfo)(nil), // 13: livekit.ParticipantInfo - (*TrackInfo)(nil), // 14: livekit.TrackInfo + (*ActiveSpeakerUpdate)(nil), // 11: livekit.ActiveSpeakerUpdate + (*SpeakerInfo)(nil), // 12: livekit.SpeakerInfo + (TrackType)(0), // 13: livekit.TrackType + (*Room)(nil), // 14: livekit.Room + (*ParticipantInfo)(nil), // 15: livekit.ParticipantInfo + (*TrackInfo)(nil), // 16: livekit.TrackInfo } var file_rtc_proto_depIdxs = []int32{ 9, // 0: livekit.SignalRequest.offer:type_name -> livekit.SessionDescription @@ -943,18 +1085,20 @@ var file_rtc_proto_depIdxs = []int32{ 4, // 9: livekit.SignalResponse.trickle:type_name -> livekit.TrickleRequest 10, // 10: livekit.SignalResponse.update:type_name -> livekit.ParticipantUpdate 8, // 11: livekit.SignalResponse.track_published:type_name -> livekit.TrackPublishedResponse - 11, // 12: livekit.AddTrackRequest.type:type_name -> livekit.TrackType - 0, // 13: livekit.TrickleRequest.target:type_name -> livekit.SignalTarget - 12, // 14: livekit.JoinResponse.room:type_name -> livekit.Room - 13, // 15: livekit.JoinResponse.participant:type_name -> livekit.ParticipantInfo - 13, // 16: livekit.JoinResponse.other_participants:type_name -> livekit.ParticipantInfo - 14, // 17: livekit.TrackPublishedResponse.track:type_name -> livekit.TrackInfo - 13, // 18: livekit.ParticipantUpdate.participants:type_name -> livekit.ParticipantInfo - 19, // [19:19] is the sub-list for method output_type - 19, // [19:19] is the sub-list for method input_type - 19, // [19:19] is the sub-list for extension type_name - 19, // [19:19] is the sub-list for extension extendee - 0, // [0:19] is the sub-list for field type_name + 11, // 12: livekit.SignalResponse.speaker:type_name -> livekit.ActiveSpeakerUpdate + 13, // 13: livekit.AddTrackRequest.type:type_name -> livekit.TrackType + 0, // 14: livekit.TrickleRequest.target:type_name -> livekit.SignalTarget + 14, // 15: livekit.JoinResponse.room:type_name -> livekit.Room + 15, // 16: livekit.JoinResponse.participant:type_name -> livekit.ParticipantInfo + 15, // 17: livekit.JoinResponse.other_participants:type_name -> livekit.ParticipantInfo + 16, // 18: livekit.TrackPublishedResponse.track:type_name -> livekit.TrackInfo + 15, // 19: livekit.ParticipantUpdate.participants:type_name -> livekit.ParticipantInfo + 12, // 20: livekit.ActiveSpeakerUpdate.speakers:type_name -> livekit.SpeakerInfo + 21, // [21:21] is the sub-list for method output_type + 21, // [21:21] is the sub-list for method input_type + 21, // [21:21] is the sub-list for extension type_name + 21, // [21:21] is the sub-list for extension extendee + 0, // [0:21] is the sub-list for field type_name } func init() { file_rtc_proto_init() } @@ -1084,6 +1228,30 @@ func file_rtc_proto_init() { return nil } } + file_rtc_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ActiveSpeakerUpdate); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_rtc_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SpeakerInfo); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } file_rtc_proto_msgTypes[0].OneofWrappers = []interface{}{ (*SignalRequest_Offer)(nil), @@ -1100,6 +1268,7 @@ func file_rtc_proto_init() { (*SignalResponse_Trickle)(nil), (*SignalResponse_Update)(nil), (*SignalResponse_TrackPublished)(nil), + (*SignalResponse_Speaker)(nil), } type x struct{} out := protoimpl.TypeBuilder{ @@ -1107,7 +1276,7 @@ func file_rtc_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_rtc_proto_rawDesc, NumEnums: 1, - NumMessages: 10, + NumMessages: 12, NumExtensions: 0, NumServices: 0, }, diff --git a/proto/rtc.proto b/proto/rtc.proto index bc6500c4..13a2249d 100644 --- a/proto/rtc.proto +++ b/proto/rtc.proto @@ -34,6 +34,8 @@ message SignalResponse { ParticipantUpdate update = 5; // sent to the participant when their track has been published TrackPublishedResponse track_published = 6; + // list of active speakers + ActiveSpeakerUpdate speaker = 7; } } @@ -83,3 +85,15 @@ message SessionDescription { message ParticipantUpdate { repeated ParticipantInfo participants = 1; } + +message ActiveSpeakerUpdate { + repeated SpeakerInfo speakers = 1; +} + +message SpeakerInfo { + string sid = 1; + // audio level, 0-1.0, 1 is loudest + float level = 2; + // true if speaker is currently active + bool active = 3; +}