export structures for cloud (#220)
* export structures for cloud Co-authored-by: cnderrauber <zengjie9004@gmail.com>
This commit is contained in:
co-authored by
cnderrauber
parent
e37afdca6f
commit
6510692f23
+14
-7
@@ -23,7 +23,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
feedbackTypes = []webrtc.RTCPFeedback{
|
FeedbackTypes = []webrtc.RTCPFeedback{
|
||||||
{Type: webrtc.TypeRTCPFBGoogREMB},
|
{Type: webrtc.TypeRTCPFBGoogREMB},
|
||||||
{Type: webrtc.TypeRTCPFBNACK},
|
{Type: webrtc.TypeRTCPFBNACK},
|
||||||
{Type: webrtc.TypeRTCPFBNACK, Parameter: "pli"}}
|
{Type: webrtc.TypeRTCPFBNACK, Parameter: "pli"}}
|
||||||
@@ -62,7 +62,7 @@ type MediaTrack struct {
|
|||||||
maxUpFracLost uint8
|
maxUpFracLost uint8
|
||||||
maxUpFracLostTs time.Time
|
maxUpFracLostTs time.Time
|
||||||
|
|
||||||
onClose func()
|
onClose []func()
|
||||||
}
|
}
|
||||||
|
|
||||||
type MediaTrackParams struct {
|
type MediaTrackParams struct {
|
||||||
@@ -135,8 +135,11 @@ func (t *MediaTrack) SetMuted(muted bool) {
|
|||||||
t.lock.RUnlock()
|
t.lock.RUnlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *MediaTrack) OnClose(f func()) {
|
func (t *MediaTrack) AddOnClose(f func()) {
|
||||||
t.onClose = f
|
if f == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t.onClose = append(t.onClose, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *MediaTrack) IsSubscriber(subId string) bool {
|
func (t *MediaTrack) IsSubscriber(subId string) bool {
|
||||||
@@ -183,7 +186,7 @@ func (t *MediaTrack) AddSubscriber(sub types.Participant) error {
|
|||||||
ClockRate: codec.ClockRate,
|
ClockRate: codec.ClockRate,
|
||||||
Channels: codec.Channels,
|
Channels: codec.Channels,
|
||||||
SDPFmtpLine: codec.SDPFmtpLine,
|
SDPFmtpLine: codec.SDPFmtpLine,
|
||||||
RTCPFeedback: feedbackTypes,
|
RTCPFeedback: FeedbackTypes,
|
||||||
}, receiver, t.params.BufferFactory, sub.ID(), t.params.ReceiverConfig.PacketBufferSize)
|
}, receiver, t.params.BufferFactory, sub.ID(), t.params.ReceiverConfig.PacketBufferSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -376,8 +379,8 @@ func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.Tra
|
|||||||
t.lock.Unlock()
|
t.lock.Unlock()
|
||||||
t.RemoveAllSubscribers()
|
t.RemoveAllSubscribers()
|
||||||
t.params.Telemetry.TrackUnpublished(context.Background(), t.params.ParticipantID, t.ToProto(), uint32(track.SSRC()))
|
t.params.Telemetry.TrackUnpublished(context.Background(), t.params.ParticipantID, t.ToProto(), uint32(track.SSRC()))
|
||||||
if onclose != nil {
|
for _, f := range onclose {
|
||||||
onclose()
|
f()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
t.params.Telemetry.TrackPublished(context.Background(), t.params.ParticipantID, t.ToProto())
|
t.params.Telemetry.TrackPublished(context.Background(), t.params.ParticipantID, t.ToProto())
|
||||||
@@ -591,3 +594,7 @@ func (t *MediaTrack) DebugInfo() map[string]interface{} {
|
|||||||
|
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *MediaTrack) Receiver() sfu.TrackReceiver {
|
||||||
|
return t.receiver
|
||||||
|
}
|
||||||
|
|||||||
@@ -428,7 +428,6 @@ func (p *ParticipantImpl) Close() error {
|
|||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
for _, t := range p.publishedTracks {
|
for _, t := range p.publishedTracks {
|
||||||
// skip updates
|
// skip updates
|
||||||
t.OnClose(nil)
|
|
||||||
t.RemoveAllSubscribers()
|
t.RemoveAllSubscribers()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1079,7 +1078,7 @@ func (p *ParticipantImpl) handleTrackPublished(track types.PublishedTrack) {
|
|||||||
|
|
||||||
track.Start()
|
track.Start()
|
||||||
|
|
||||||
track.OnClose(func() {
|
track.AddOnClose(func() {
|
||||||
// cleanup
|
// cleanup
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
delete(p.publishedTracks, track.ID())
|
delete(p.publishedTracks, track.ID())
|
||||||
@@ -1088,7 +1087,6 @@ func (p *ParticipantImpl) handleTrackPublished(track types.PublishedTrack) {
|
|||||||
if p.IsReady() && p.onTrackUpdated != nil {
|
if p.IsReady() && p.onTrackUpdated != nil {
|
||||||
p.onTrackUpdated(p, track)
|
p.onTrackUpdated(p, track)
|
||||||
}
|
}
|
||||||
track.OnClose(nil)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if p.onTrackPublished != nil {
|
if p.onTrackPublished != nil {
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ func TestTrackPublishing(t *testing.T) {
|
|||||||
require.False(t, updated)
|
require.False(t, updated)
|
||||||
require.Len(t, p.publishedTracks, 1)
|
require.Len(t, p.publishedTracks, 1)
|
||||||
|
|
||||||
track.OnCloseArgsForCall(0)()
|
track.AddOnCloseArgsForCall(0)()
|
||||||
require.Len(t, p.publishedTracks, 0)
|
require.Len(t, p.publishedTracks, 0)
|
||||||
require.True(t, updated)
|
require.True(t, updated)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -113,9 +113,10 @@ type PublishedTrack interface {
|
|||||||
NumUpTracks() (uint32, uint32)
|
NumUpTracks() (uint32, uint32)
|
||||||
PublishLossPercentage() uint32
|
PublishLossPercentage() uint32
|
||||||
ToProto() *livekit.TrackInfo
|
ToProto() *livekit.TrackInfo
|
||||||
|
Receiver() sfu.TrackReceiver
|
||||||
|
|
||||||
// callbacks
|
// callbacks
|
||||||
OnClose(func())
|
AddOnClose(func())
|
||||||
}
|
}
|
||||||
|
|
||||||
//counterfeiter:generate . SubscribedTrack
|
//counterfeiter:generate . SubscribedTrack
|
||||||
|
|||||||
@@ -5,10 +5,16 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||||
|
"github.com/livekit/livekit-server/pkg/sfu"
|
||||||
livekit "github.com/livekit/protocol/proto"
|
livekit "github.com/livekit/protocol/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FakePublishedTrack struct {
|
type FakePublishedTrack struct {
|
||||||
|
AddOnCloseStub func(func())
|
||||||
|
addOnCloseMutex sync.RWMutex
|
||||||
|
addOnCloseArgsForCall []struct {
|
||||||
|
arg1 func()
|
||||||
|
}
|
||||||
AddSubscriberStub func(types.Participant) error
|
AddSubscriberStub func(types.Participant) error
|
||||||
addSubscriberMutex sync.RWMutex
|
addSubscriberMutex sync.RWMutex
|
||||||
addSubscriberArgsForCall []struct {
|
addSubscriberArgsForCall []struct {
|
||||||
@@ -95,11 +101,6 @@ type FakePublishedTrack struct {
|
|||||||
result1 uint32
|
result1 uint32
|
||||||
result2 uint32
|
result2 uint32
|
||||||
}
|
}
|
||||||
OnCloseStub func(func())
|
|
||||||
onCloseMutex sync.RWMutex
|
|
||||||
onCloseArgsForCall []struct {
|
|
||||||
arg1 func()
|
|
||||||
}
|
|
||||||
PublishLossPercentageStub func() uint32
|
PublishLossPercentageStub func() uint32
|
||||||
publishLossPercentageMutex sync.RWMutex
|
publishLossPercentageMutex sync.RWMutex
|
||||||
publishLossPercentageArgsForCall []struct {
|
publishLossPercentageArgsForCall []struct {
|
||||||
@@ -110,6 +111,16 @@ type FakePublishedTrack struct {
|
|||||||
publishLossPercentageReturnsOnCall map[int]struct {
|
publishLossPercentageReturnsOnCall map[int]struct {
|
||||||
result1 uint32
|
result1 uint32
|
||||||
}
|
}
|
||||||
|
ReceiverStub func() sfu.TrackReceiver
|
||||||
|
receiverMutex sync.RWMutex
|
||||||
|
receiverArgsForCall []struct {
|
||||||
|
}
|
||||||
|
receiverReturns struct {
|
||||||
|
result1 sfu.TrackReceiver
|
||||||
|
}
|
||||||
|
receiverReturnsOnCall map[int]struct {
|
||||||
|
result1 sfu.TrackReceiver
|
||||||
|
}
|
||||||
RemoveAllSubscribersStub func()
|
RemoveAllSubscribersStub func()
|
||||||
removeAllSubscribersMutex sync.RWMutex
|
removeAllSubscribersMutex sync.RWMutex
|
||||||
removeAllSubscribersArgsForCall []struct {
|
removeAllSubscribersArgsForCall []struct {
|
||||||
@@ -162,6 +173,38 @@ type FakePublishedTrack struct {
|
|||||||
invocationsMutex sync.RWMutex
|
invocationsMutex sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fake *FakePublishedTrack) AddOnClose(arg1 func()) {
|
||||||
|
fake.addOnCloseMutex.Lock()
|
||||||
|
fake.addOnCloseArgsForCall = append(fake.addOnCloseArgsForCall, struct {
|
||||||
|
arg1 func()
|
||||||
|
}{arg1})
|
||||||
|
stub := fake.AddOnCloseStub
|
||||||
|
fake.recordInvocation("AddOnClose", []interface{}{arg1})
|
||||||
|
fake.addOnCloseMutex.Unlock()
|
||||||
|
if stub != nil {
|
||||||
|
fake.AddOnCloseStub(arg1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakePublishedTrack) AddOnCloseCallCount() int {
|
||||||
|
fake.addOnCloseMutex.RLock()
|
||||||
|
defer fake.addOnCloseMutex.RUnlock()
|
||||||
|
return len(fake.addOnCloseArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakePublishedTrack) AddOnCloseCalls(stub func(func())) {
|
||||||
|
fake.addOnCloseMutex.Lock()
|
||||||
|
defer fake.addOnCloseMutex.Unlock()
|
||||||
|
fake.AddOnCloseStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakePublishedTrack) AddOnCloseArgsForCall(i int) func() {
|
||||||
|
fake.addOnCloseMutex.RLock()
|
||||||
|
defer fake.addOnCloseMutex.RUnlock()
|
||||||
|
argsForCall := fake.addOnCloseArgsForCall[i]
|
||||||
|
return argsForCall.arg1
|
||||||
|
}
|
||||||
|
|
||||||
func (fake *FakePublishedTrack) AddSubscriber(arg1 types.Participant) error {
|
func (fake *FakePublishedTrack) AddSubscriber(arg1 types.Participant) error {
|
||||||
fake.addSubscriberMutex.Lock()
|
fake.addSubscriberMutex.Lock()
|
||||||
ret, specificReturn := fake.addSubscriberReturnsOnCall[len(fake.addSubscriberArgsForCall)]
|
ret, specificReturn := fake.addSubscriberReturnsOnCall[len(fake.addSubscriberArgsForCall)]
|
||||||
@@ -614,38 +657,6 @@ func (fake *FakePublishedTrack) NumUpTracksReturnsOnCall(i int, result1 uint32,
|
|||||||
}{result1, result2}
|
}{result1, result2}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fake *FakePublishedTrack) OnClose(arg1 func()) {
|
|
||||||
fake.onCloseMutex.Lock()
|
|
||||||
fake.onCloseArgsForCall = append(fake.onCloseArgsForCall, struct {
|
|
||||||
arg1 func()
|
|
||||||
}{arg1})
|
|
||||||
stub := fake.OnCloseStub
|
|
||||||
fake.recordInvocation("OnClose", []interface{}{arg1})
|
|
||||||
fake.onCloseMutex.Unlock()
|
|
||||||
if stub != nil {
|
|
||||||
fake.OnCloseStub(arg1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fake *FakePublishedTrack) OnCloseCallCount() int {
|
|
||||||
fake.onCloseMutex.RLock()
|
|
||||||
defer fake.onCloseMutex.RUnlock()
|
|
||||||
return len(fake.onCloseArgsForCall)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fake *FakePublishedTrack) OnCloseCalls(stub func(func())) {
|
|
||||||
fake.onCloseMutex.Lock()
|
|
||||||
defer fake.onCloseMutex.Unlock()
|
|
||||||
fake.OnCloseStub = stub
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fake *FakePublishedTrack) OnCloseArgsForCall(i int) func() {
|
|
||||||
fake.onCloseMutex.RLock()
|
|
||||||
defer fake.onCloseMutex.RUnlock()
|
|
||||||
argsForCall := fake.onCloseArgsForCall[i]
|
|
||||||
return argsForCall.arg1
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fake *FakePublishedTrack) PublishLossPercentage() uint32 {
|
func (fake *FakePublishedTrack) PublishLossPercentage() uint32 {
|
||||||
fake.publishLossPercentageMutex.Lock()
|
fake.publishLossPercentageMutex.Lock()
|
||||||
ret, specificReturn := fake.publishLossPercentageReturnsOnCall[len(fake.publishLossPercentageArgsForCall)]
|
ret, specificReturn := fake.publishLossPercentageReturnsOnCall[len(fake.publishLossPercentageArgsForCall)]
|
||||||
@@ -699,6 +710,59 @@ func (fake *FakePublishedTrack) PublishLossPercentageReturnsOnCall(i int, result
|
|||||||
}{result1}
|
}{result1}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fake *FakePublishedTrack) Receiver() sfu.TrackReceiver {
|
||||||
|
fake.receiverMutex.Lock()
|
||||||
|
ret, specificReturn := fake.receiverReturnsOnCall[len(fake.receiverArgsForCall)]
|
||||||
|
fake.receiverArgsForCall = append(fake.receiverArgsForCall, struct {
|
||||||
|
}{})
|
||||||
|
stub := fake.ReceiverStub
|
||||||
|
fakeReturns := fake.receiverReturns
|
||||||
|
fake.recordInvocation("Receiver", []interface{}{})
|
||||||
|
fake.receiverMutex.Unlock()
|
||||||
|
if stub != nil {
|
||||||
|
return stub()
|
||||||
|
}
|
||||||
|
if specificReturn {
|
||||||
|
return ret.result1
|
||||||
|
}
|
||||||
|
return fakeReturns.result1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakePublishedTrack) ReceiverCallCount() int {
|
||||||
|
fake.receiverMutex.RLock()
|
||||||
|
defer fake.receiverMutex.RUnlock()
|
||||||
|
return len(fake.receiverArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakePublishedTrack) ReceiverCalls(stub func() sfu.TrackReceiver) {
|
||||||
|
fake.receiverMutex.Lock()
|
||||||
|
defer fake.receiverMutex.Unlock()
|
||||||
|
fake.ReceiverStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakePublishedTrack) ReceiverReturns(result1 sfu.TrackReceiver) {
|
||||||
|
fake.receiverMutex.Lock()
|
||||||
|
defer fake.receiverMutex.Unlock()
|
||||||
|
fake.ReceiverStub = nil
|
||||||
|
fake.receiverReturns = struct {
|
||||||
|
result1 sfu.TrackReceiver
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakePublishedTrack) ReceiverReturnsOnCall(i int, result1 sfu.TrackReceiver) {
|
||||||
|
fake.receiverMutex.Lock()
|
||||||
|
defer fake.receiverMutex.Unlock()
|
||||||
|
fake.ReceiverStub = nil
|
||||||
|
if fake.receiverReturnsOnCall == nil {
|
||||||
|
fake.receiverReturnsOnCall = make(map[int]struct {
|
||||||
|
result1 sfu.TrackReceiver
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fake.receiverReturnsOnCall[i] = struct {
|
||||||
|
result1 sfu.TrackReceiver
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
func (fake *FakePublishedTrack) RemoveAllSubscribers() {
|
func (fake *FakePublishedTrack) RemoveAllSubscribers() {
|
||||||
fake.removeAllSubscribersMutex.Lock()
|
fake.removeAllSubscribersMutex.Lock()
|
||||||
fake.removeAllSubscribersArgsForCall = append(fake.removeAllSubscribersArgsForCall, struct {
|
fake.removeAllSubscribersArgsForCall = append(fake.removeAllSubscribersArgsForCall, struct {
|
||||||
@@ -973,6 +1037,8 @@ func (fake *FakePublishedTrack) ToProtoReturnsOnCall(i int, result1 *livekit.Tra
|
|||||||
func (fake *FakePublishedTrack) Invocations() map[string][][]interface{} {
|
func (fake *FakePublishedTrack) Invocations() map[string][][]interface{} {
|
||||||
fake.invocationsMutex.RLock()
|
fake.invocationsMutex.RLock()
|
||||||
defer fake.invocationsMutex.RUnlock()
|
defer fake.invocationsMutex.RUnlock()
|
||||||
|
fake.addOnCloseMutex.RLock()
|
||||||
|
defer fake.addOnCloseMutex.RUnlock()
|
||||||
fake.addSubscriberMutex.RLock()
|
fake.addSubscriberMutex.RLock()
|
||||||
defer fake.addSubscriberMutex.RUnlock()
|
defer fake.addSubscriberMutex.RUnlock()
|
||||||
fake.getQualityForDimensionMutex.RLock()
|
fake.getQualityForDimensionMutex.RLock()
|
||||||
@@ -989,10 +1055,10 @@ func (fake *FakePublishedTrack) Invocations() map[string][][]interface{} {
|
|||||||
defer fake.nameMutex.RUnlock()
|
defer fake.nameMutex.RUnlock()
|
||||||
fake.numUpTracksMutex.RLock()
|
fake.numUpTracksMutex.RLock()
|
||||||
defer fake.numUpTracksMutex.RUnlock()
|
defer fake.numUpTracksMutex.RUnlock()
|
||||||
fake.onCloseMutex.RLock()
|
|
||||||
defer fake.onCloseMutex.RUnlock()
|
|
||||||
fake.publishLossPercentageMutex.RLock()
|
fake.publishLossPercentageMutex.RLock()
|
||||||
defer fake.publishLossPercentageMutex.RUnlock()
|
defer fake.publishLossPercentageMutex.RUnlock()
|
||||||
|
fake.receiverMutex.RLock()
|
||||||
|
defer fake.receiverMutex.RUnlock()
|
||||||
fake.removeAllSubscribersMutex.RLock()
|
fake.removeAllSubscribersMutex.RLock()
|
||||||
defer fake.removeAllSubscribersMutex.RUnlock()
|
defer fake.removeAllSubscribersMutex.RUnlock()
|
||||||
fake.removeSubscriberMutex.RLock()
|
fake.removeSubscriberMutex.RLock()
|
||||||
|
|||||||
@@ -7,14 +7,14 @@ import (
|
|||||||
// wrapper around WebRTC receiver, overriding its ID
|
// wrapper around WebRTC receiver, overriding its ID
|
||||||
|
|
||||||
type WrappedReceiver struct {
|
type WrappedReceiver struct {
|
||||||
sfu.Receiver
|
sfu.TrackReceiver
|
||||||
trackId string
|
trackId string
|
||||||
streamId string
|
streamId string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWrappedReceiver(receiver sfu.Receiver, trackId string, streamId string) WrappedReceiver {
|
func NewWrappedReceiver(receiver sfu.TrackReceiver, trackId string, streamId string) WrappedReceiver {
|
||||||
return WrappedReceiver{
|
return WrappedReceiver{
|
||||||
Receiver: receiver,
|
TrackReceiver: receiver,
|
||||||
trackId: trackId,
|
trackId: trackId,
|
||||||
streamId: streamId,
|
streamId: streamId,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ type ExtPacket struct {
|
|||||||
Packet rtp.Packet
|
Packet rtp.Packet
|
||||||
Payload interface{}
|
Payload interface{}
|
||||||
KeyFrame bool
|
KeyFrame bool
|
||||||
|
//audio level for voice, l&0x80 == 0 means audio level not present
|
||||||
|
AudioLevel uint8
|
||||||
RawPacket []byte
|
RawPacket []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,6 +386,7 @@ func (b *Buffer) calc(pkt []byte, arrivalTime int64) {
|
|||||||
if e := p.GetExtension(b.audioExt); e != nil && b.onAudioLevel != nil {
|
if e := p.GetExtension(b.audioExt); e != nil && b.onAudioLevel != nil {
|
||||||
ext := rtp.AudioLevelExtension{}
|
ext := rtp.AudioLevelExtension{}
|
||||||
if err := ext.Unmarshal(e); err == nil {
|
if err := ext.Unmarshal(e); err == nil {
|
||||||
|
ep.AudioLevel = e[0] | 0x80 // highest bit to indicate audio level present
|
||||||
duration := (int64(p.Timestamp) - int64(latestTimestamp)) * 1e3 / int64(b.clockRate)
|
duration := (int64(p.Timestamp) - int64(latestTimestamp)) * 1e3 / int64(b.clockRate)
|
||||||
if duration > 0 {
|
if duration > 0 {
|
||||||
b.onAudioLevel(ext.Level, uint32(duration))
|
b.onAudioLevel(ext.Level, uint32(duration))
|
||||||
|
|||||||
Reference in New Issue
Block a user