Add control of playout delay (#1838)
* Add control of playout delay Add config to enable playout delay. The delay will be limited by [min,max] in the config option and calculated by upstream & downstream RTT. * check protocol version to enable playout delay * Move config to room, limit playout-delay update interval, solve comments * Remove adaptive playout-delay * Remove unused config
This commit is contained in:
@@ -152,6 +152,11 @@ keys:
|
|||||||
# enable_remote_unmute: true
|
# enable_remote_unmute: true
|
||||||
# # limit size of room and participant's metadata, 0 for no limit
|
# # limit size of room and participant's metadata, 0 for no limit
|
||||||
# max_metadata_size: 0
|
# max_metadata_size: 0
|
||||||
|
# # control playout delay in ms of video track (and associated audio track)
|
||||||
|
# playout_delay:
|
||||||
|
# enabled: true
|
||||||
|
# min: 100
|
||||||
|
# max: 300
|
||||||
|
|
||||||
# Webhooks
|
# Webhooks
|
||||||
# when configured, LiveKit notifies your URL handler with room events
|
# when configured, LiveKit notifies your URL handler with room events
|
||||||
|
|||||||
+13
-6
@@ -197,6 +197,12 @@ type StreamTrackersConfig struct {
|
|||||||
Screenshare StreamTrackerConfig `yaml:"screenshare,omitempty"`
|
Screenshare StreamTrackerConfig `yaml:"screenshare,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PlayoutDelayConfig struct {
|
||||||
|
Enabled bool `yaml:"enabled,omitempty"`
|
||||||
|
Min int `yaml:"min,omitempty"`
|
||||||
|
Max int `yaml:"max,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type VideoConfig struct {
|
type VideoConfig struct {
|
||||||
DynacastPauseDelay time.Duration `yaml:"dynacast_pause_delay,omitempty"`
|
DynacastPauseDelay time.Duration `yaml:"dynacast_pause_delay,omitempty"`
|
||||||
StreamTracker StreamTrackersConfig `yaml:"stream_tracker,omitempty"`
|
StreamTracker StreamTrackersConfig `yaml:"stream_tracker,omitempty"`
|
||||||
@@ -204,12 +210,13 @@ type VideoConfig struct {
|
|||||||
|
|
||||||
type RoomConfig struct {
|
type RoomConfig struct {
|
||||||
// enable rooms to be automatically created
|
// enable rooms to be automatically created
|
||||||
AutoCreate bool `yaml:"auto_create,omitempty"`
|
AutoCreate bool `yaml:"auto_create,omitempty"`
|
||||||
EnabledCodecs []CodecSpec `yaml:"enabled_codecs,omitempty"`
|
EnabledCodecs []CodecSpec `yaml:"enabled_codecs,omitempty"`
|
||||||
MaxParticipants uint32 `yaml:"max_participants,omitempty"`
|
MaxParticipants uint32 `yaml:"max_participants,omitempty"`
|
||||||
EmptyTimeout uint32 `yaml:"empty_timeout,omitempty"`
|
EmptyTimeout uint32 `yaml:"empty_timeout,omitempty"`
|
||||||
EnableRemoteUnmute bool `yaml:"enable_remote_unmute,omitempty"`
|
EnableRemoteUnmute bool `yaml:"enable_remote_unmute,omitempty"`
|
||||||
MaxMetadataSize uint32 `yaml:"max_metadata_size,omitempty"`
|
MaxMetadataSize uint32 `yaml:"max_metadata_size,omitempty"`
|
||||||
|
PlayoutDelay PlayoutDelayConfig `yaml:"playout_delay,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CodecSpec struct {
|
type CodecSpec struct {
|
||||||
|
|||||||
+2
-2
@@ -86,7 +86,7 @@ func NewWebRTCConfig(conf *config.Config) (*WebRTCConfig, error) {
|
|||||||
sdp.SDESRTPStreamIDURI,
|
sdp.SDESRTPStreamIDURI,
|
||||||
sdp.TransportCCURI,
|
sdp.TransportCCURI,
|
||||||
frameMarking,
|
frameMarking,
|
||||||
dd.ExtensionUrl,
|
dd.ExtensionURI,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RTCPFeedback: RTCPFeedbackConfig{
|
RTCPFeedback: RTCPFeedbackConfig{
|
||||||
@@ -106,7 +106,7 @@ func NewWebRTCConfig(conf *config.Config) (*WebRTCConfig, error) {
|
|||||||
subscriberConfig := DirectionConfig{
|
subscriberConfig := DirectionConfig{
|
||||||
StrictACKs: conf.RTC.StrictACKs,
|
StrictACKs: conf.RTC.StrictACKs,
|
||||||
RTPHeaderExtension: RTPHeaderExtensionConfig{
|
RTPHeaderExtension: RTPHeaderExtensionConfig{
|
||||||
Video: []string{dd.ExtensionUrl},
|
Video: []string{dd.ExtensionURI},
|
||||||
},
|
},
|
||||||
RTCPFeedback: RTCPFeedbackConfig{
|
RTCPFeedback: RTCPFeedbackConfig{
|
||||||
Video: []webrtc.RTCPFeedback{
|
Video: []webrtc.RTCPFeedback{
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ func (t *MediaTrackReceiver) SetPotentialCodecs(codecs []webrtc.RTPCodecParamete
|
|||||||
// that is munged in svc codec.
|
// that is munged in svc codec.
|
||||||
headersWithoutDD := make([]webrtc.RTPHeaderExtensionParameter, 0, len(headers))
|
headersWithoutDD := make([]webrtc.RTPHeaderExtensionParameter, 0, len(headers))
|
||||||
for _, h := range headers {
|
for _, h := range headers {
|
||||||
if h.URI != dependencydescriptor.ExtensionUrl {
|
if h.URI != dependencydescriptor.ExtensionURI {
|
||||||
headersWithoutDD = append(headersWithoutDD, h)
|
headersWithoutDD = append(headersWithoutDD, h)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -401,6 +401,13 @@ func (t *MediaTrackReceiver) Source() livekit.TrackSource {
|
|||||||
return t.trackInfo.Source
|
return t.trackInfo.Source
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *MediaTrackReceiver) Stream() string {
|
||||||
|
t.lock.RLock()
|
||||||
|
defer t.lock.RUnlock()
|
||||||
|
|
||||||
|
return t.trackInfo.Stream
|
||||||
|
}
|
||||||
|
|
||||||
func (t *MediaTrackReceiver) PublisherID() livekit.ParticipantID {
|
func (t *MediaTrackReceiver) PublisherID() livekit.ParticipantID {
|
||||||
return t.params.ParticipantID
|
return t.params.ParticipantID
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,20 +112,29 @@ func (t *MediaTrackSubscriptions) AddSubscriber(sub types.LocalParticipant, wr *
|
|||||||
for _, c := range codecs {
|
for _, c := range codecs {
|
||||||
c.RTCPFeedback = rtcpFeedback
|
c.RTCPFeedback = rtcpFeedback
|
||||||
}
|
}
|
||||||
|
|
||||||
|
streamID := wr.StreamID()
|
||||||
|
if sub.SupportSyncStreamID() && t.params.MediaTrack.Stream() != "" {
|
||||||
|
streamID = PackSyncStreamID(t.params.MediaTrack.PublisherID(), t.params.MediaTrack.Stream())
|
||||||
|
}
|
||||||
|
|
||||||
var trailer []byte
|
var trailer []byte
|
||||||
if t.params.MediaTrack.IsEncrypted() {
|
if t.params.MediaTrack.IsEncrypted() {
|
||||||
trailer = sub.GetTrailer()
|
trailer = sub.GetTrailer()
|
||||||
}
|
}
|
||||||
downTrack, err := sfu.NewDownTrack(
|
|
||||||
codecs,
|
downTrack, err := sfu.NewDownTrack(sfu.DowntrackParams{
|
||||||
wr,
|
Codecs: codecs,
|
||||||
sub.GetBufferFactory(),
|
Receiver: wr,
|
||||||
subscriberID,
|
BufferFactory: sub.GetBufferFactory(),
|
||||||
t.params.ReceiverConfig.PacketBufferSize,
|
SubID: subscriberID,
|
||||||
sub.GetPacer(),
|
StreamID: streamID,
|
||||||
trailer,
|
MaxTrack: t.params.ReceiverConfig.PacketBufferSize,
|
||||||
LoggerWithTrack(sub.GetLogger(), trackID, t.params.IsRelayed),
|
PlayoutDelayLimit: sub.GetPlayoutDelayConfig(),
|
||||||
)
|
Pacer: sub.GetPacer(),
|
||||||
|
Trailer: trailer,
|
||||||
|
Logger: LoggerWithTrack(sub.GetLogger(), trackID, t.params.IsRelayed),
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -200,6 +209,8 @@ func (t *MediaTrackSubscriptions) AddSubscriber(sub types.LocalParticipant, wr *
|
|||||||
reusingTransceiver.Store(true)
|
reusingTransceiver.Store(true)
|
||||||
rtpSender := existingTransceiver.Sender()
|
rtpSender := existingTransceiver.Sender()
|
||||||
if rtpSender != nil {
|
if rtpSender != nil {
|
||||||
|
// replaced track will bind immediately without negotiation, SetTransceiver first before bind
|
||||||
|
downTrack.SetTransceiver(existingTransceiver)
|
||||||
err := rtpSender.ReplaceTrack(downTrack)
|
err := rtpSender.ReplaceTrack(downTrack)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
sender = rtpSender
|
sender = rtpSender
|
||||||
@@ -260,9 +271,6 @@ func (t *MediaTrackSubscriptions) AddSubscriber(sub types.LocalParticipant, wr *
|
|||||||
subTrack.SetNeedsNegotiation(!replacedTrack)
|
subTrack.SetNeedsNegotiation(!replacedTrack)
|
||||||
subTrack.SetRTPSender(sender)
|
subTrack.SetRTPSender(sender)
|
||||||
|
|
||||||
sendParameters := sender.GetParameters()
|
|
||||||
downTrack.SetRTPHeaderExtensions(sendParameters.HeaderExtensions)
|
|
||||||
|
|
||||||
downTrack.SetTransceiver(transceiver)
|
downTrack.SetTransceiver(transceiver)
|
||||||
|
|
||||||
downTrack.OnCloseHandler(func(willBeResumed bool) {
|
downTrack.OnCloseHandler(func(willBeResumed bool) {
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ type ParticipantParams struct {
|
|||||||
SubscriberAllowPause bool
|
SubscriberAllowPause bool
|
||||||
SubscriptionLimitAudio int32
|
SubscriptionLimitAudio int32
|
||||||
SubscriptionLimitVideo int32
|
SubscriptionLimitVideo int32
|
||||||
|
PlayoutDelay *livekit.PlayoutDelay
|
||||||
}
|
}
|
||||||
|
|
||||||
type ParticipantImpl struct {
|
type ParticipantImpl struct {
|
||||||
@@ -1104,6 +1105,7 @@ func (p *ParticipantImpl) setupTransportManager() error {
|
|||||||
TCPFallbackRTTThreshold: p.params.TCPFallbackRTTThreshold,
|
TCPFallbackRTTThreshold: p.params.TCPFallbackRTTThreshold,
|
||||||
AllowUDPUnstableFallback: p.params.AllowUDPUnstableFallback,
|
AllowUDPUnstableFallback: p.params.AllowUDPUnstableFallback,
|
||||||
TURNSEnabled: p.params.TURNSEnabled,
|
TURNSEnabled: p.params.TURNSEnabled,
|
||||||
|
AllowPlayoutDelay: p.params.PlayoutDelay.GetEnabled() && p.SupportSyncStreamID(),
|
||||||
Logger: p.params.Logger,
|
Logger: p.params.Logger,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1584,6 +1586,10 @@ func (p *ParticipantImpl) addPendingTrackLocked(req *livekit.AddTrackRequest) *l
|
|||||||
DisableRed: req.DisableRed,
|
DisableRed: req.DisableRed,
|
||||||
Stereo: req.Stereo,
|
Stereo: req.Stereo,
|
||||||
Encryption: req.Encryption,
|
Encryption: req.Encryption,
|
||||||
|
Stream: req.Stream,
|
||||||
|
}
|
||||||
|
if ti.Stream == "" {
|
||||||
|
ti.Stream = StreamFromTrackSource(ti.Source)
|
||||||
}
|
}
|
||||||
p.setStableTrackID(req.Cid, ti)
|
p.setStableTrackID(req.Cid, ti)
|
||||||
for _, codec := range req.SimulcastCodecs {
|
for _, codec := range req.SimulcastCodecs {
|
||||||
@@ -2214,6 +2220,14 @@ func (p *ParticipantImpl) UpdateMediaLoss(nodeID livekit.NodeID, trackID livekit
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *ParticipantImpl) GetPlayoutDelayConfig() *livekit.PlayoutDelay {
|
||||||
|
return p.params.PlayoutDelay
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ParticipantImpl) SupportSyncStreamID() bool {
|
||||||
|
return p.ProtocolVersion().SupportSyncStreamID() && !p.params.ClientInfo.isFirefox()
|
||||||
|
}
|
||||||
|
|
||||||
func codecsFromMediaDescription(m *sdp.MediaDescription) (out []sdp.Codec, err error) {
|
func codecsFromMediaDescription(m *sdp.MediaDescription) (out []sdp.Codec, err error) {
|
||||||
s := &sdp.SessionDescription{
|
s := &sdp.SessionDescription{
|
||||||
MediaDescriptions: []*sdp.MediaDescription{m},
|
MediaDescriptions: []*sdp.MediaDescription{m},
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ func (p *ParticipantImpl) setCodecPreferencesVideoForPublisher(offer webrtc.Sess
|
|||||||
// remove dd extension if av1/vp9 not preferred
|
// remove dd extension if av1/vp9 not preferred
|
||||||
if !strings.Contains(strings.ToLower(mime), "av1") && !strings.Contains(strings.ToLower(mime), "vp9") {
|
if !strings.Contains(strings.ToLower(mime), "av1") && !strings.Contains(strings.ToLower(mime), "vp9") {
|
||||||
for i, attr := range unmatchVideo.Attributes {
|
for i, attr := range unmatchVideo.Attributes {
|
||||||
if strings.Contains(attr.Value, dd.ExtensionUrl) {
|
if strings.Contains(attr.Value, dd.ExtensionURI) {
|
||||||
unmatchVideo.Attributes[i] = unmatchVideo.Attributes[len(unmatchVideo.Attributes)-1]
|
unmatchVideo.Attributes[i] = unmatchVideo.Attributes[len(unmatchVideo.Attributes)-1]
|
||||||
unmatchVideo.Attributes = unmatchVideo.Attributes[:len(unmatchVideo.Attributes)-1]
|
unmatchVideo.Attributes = unmatchVideo.Attributes[:len(unmatchVideo.Attributes)-1]
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import (
|
|||||||
"github.com/livekit/livekit-server/pkg/config"
|
"github.com/livekit/livekit-server/pkg/config"
|
||||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||||
"github.com/livekit/livekit-server/pkg/sfu/pacer"
|
"github.com/livekit/livekit-server/pkg/sfu/pacer"
|
||||||
|
"github.com/livekit/livekit-server/pkg/sfu/rtpextension"
|
||||||
"github.com/livekit/livekit-server/pkg/sfu/streamallocator"
|
"github.com/livekit/livekit-server/pkg/sfu/streamallocator"
|
||||||
"github.com/livekit/livekit-server/pkg/telemetry"
|
"github.com/livekit/livekit-server/pkg/telemetry"
|
||||||
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
|
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
|
||||||
@@ -251,10 +252,17 @@ type TransportParams struct {
|
|||||||
ClientInfo ClientInfo
|
ClientInfo ClientInfo
|
||||||
IsOfferer bool
|
IsOfferer bool
|
||||||
IsSendSide bool
|
IsSendSide bool
|
||||||
|
AllowPlayoutDelay bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPeerConnection(params TransportParams, onBandwidthEstimator func(estimator cc.BandwidthEstimator)) (*webrtc.PeerConnection, *webrtc.MediaEngine, error) {
|
func newPeerConnection(params TransportParams, onBandwidthEstimator func(estimator cc.BandwidthEstimator)) (*webrtc.PeerConnection, *webrtc.MediaEngine, error) {
|
||||||
me, err := createMediaEngine(params.EnabledCodecs, params.DirectionConfig)
|
directionConfig := params.DirectionConfig
|
||||||
|
|
||||||
|
if params.AllowPlayoutDelay {
|
||||||
|
directionConfig.RTPHeaderExtension.Video = append(directionConfig.RTPHeaderExtension.Video, rtpextension.PlayoutDelayURI)
|
||||||
|
}
|
||||||
|
|
||||||
|
me, err := createMediaEngine(params.EnabledCodecs, directionConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ type TransportManagerParams struct {
|
|||||||
TCPFallbackRTTThreshold int
|
TCPFallbackRTTThreshold int
|
||||||
AllowUDPUnstableFallback bool
|
AllowUDPUnstableFallback bool
|
||||||
TURNSEnabled bool
|
TURNSEnabled bool
|
||||||
|
AllowPlayoutDelay bool
|
||||||
Logger logger.Logger
|
Logger logger.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,6 +185,7 @@ func NewTransportManager(params TransportManagerParams) (*TransportManager, erro
|
|||||||
ClientInfo: params.ClientInfo,
|
ClientInfo: params.ClientInfo,
|
||||||
IsOfferer: true,
|
IsOfferer: true,
|
||||||
IsSendSide: true,
|
IsSendSide: true,
|
||||||
|
AllowPlayoutDelay: params.AllowPlayoutDelay,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -295,6 +295,7 @@ type LocalParticipant interface {
|
|||||||
GetLogger() logger.Logger
|
GetLogger() logger.Logger
|
||||||
GetAdaptiveStream() bool
|
GetAdaptiveStream() bool
|
||||||
ProtocolVersion() ProtocolVersion
|
ProtocolVersion() ProtocolVersion
|
||||||
|
SupportSyncStreamID() bool
|
||||||
ConnectedAt() time.Time
|
ConnectedAt() time.Time
|
||||||
IsClosed() bool
|
IsClosed() bool
|
||||||
IsReady() bool
|
IsReady() bool
|
||||||
@@ -305,6 +306,7 @@ type LocalParticipant interface {
|
|||||||
GetClientConfiguration() *livekit.ClientConfiguration
|
GetClientConfiguration() *livekit.ClientConfiguration
|
||||||
GetICEConnectionType() ICEConnectionType
|
GetICEConnectionType() ICEConnectionType
|
||||||
GetBufferFactory() *buffer.Factory
|
GetBufferFactory() *buffer.Factory
|
||||||
|
GetPlayoutDelayConfig() *livekit.PlayoutDelay
|
||||||
|
|
||||||
SetResponseSink(sink routing.MessageSink)
|
SetResponseSink(sink routing.MessageSink)
|
||||||
CloseSignalConnection(reason SignallingCloseReason)
|
CloseSignalConnection(reason SignallingCloseReason)
|
||||||
@@ -429,6 +431,7 @@ type MediaTrack interface {
|
|||||||
Kind() livekit.TrackType
|
Kind() livekit.TrackType
|
||||||
Name() string
|
Name() string
|
||||||
Source() livekit.TrackSource
|
Source() livekit.TrackSource
|
||||||
|
Stream() string
|
||||||
|
|
||||||
ToProto() *livekit.TrackInfo
|
ToProto() *livekit.TrackInfo
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ package types
|
|||||||
|
|
||||||
type ProtocolVersion int
|
type ProtocolVersion int
|
||||||
|
|
||||||
const CurrentProtocol = 9
|
const CurrentProtocol = 10
|
||||||
|
|
||||||
func (v ProtocolVersion) SupportsPackedStreamId() bool {
|
func (v ProtocolVersion) SupportsPackedStreamId() bool {
|
||||||
return v > 0
|
return v > 0
|
||||||
@@ -71,3 +71,7 @@ func (v ProtocolVersion) SupportFastStart() bool {
|
|||||||
func (v ProtocolVersion) SupportHandlesDisconnectedUpdate() bool {
|
func (v ProtocolVersion) SupportHandlesDisconnectedUpdate() bool {
|
||||||
return v > 8
|
return v > 8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v ProtocolVersion) SupportSyncStreamID() bool {
|
||||||
|
return v > 9
|
||||||
|
}
|
||||||
|
|||||||
@@ -302,6 +302,16 @@ type FakeLocalMediaTrack struct {
|
|||||||
sourceReturnsOnCall map[int]struct {
|
sourceReturnsOnCall map[int]struct {
|
||||||
result1 livekit.TrackSource
|
result1 livekit.TrackSource
|
||||||
}
|
}
|
||||||
|
StreamStub func() string
|
||||||
|
streamMutex sync.RWMutex
|
||||||
|
streamArgsForCall []struct {
|
||||||
|
}
|
||||||
|
streamReturns struct {
|
||||||
|
result1 string
|
||||||
|
}
|
||||||
|
streamReturnsOnCall map[int]struct {
|
||||||
|
result1 string
|
||||||
|
}
|
||||||
ToProtoStub func() *livekit.TrackInfo
|
ToProtoStub func() *livekit.TrackInfo
|
||||||
toProtoMutex sync.RWMutex
|
toProtoMutex sync.RWMutex
|
||||||
toProtoArgsForCall []struct {
|
toProtoArgsForCall []struct {
|
||||||
@@ -1893,6 +1903,59 @@ func (fake *FakeLocalMediaTrack) SourceReturnsOnCall(i int, result1 livekit.Trac
|
|||||||
}{result1}
|
}{result1}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalMediaTrack) Stream() string {
|
||||||
|
fake.streamMutex.Lock()
|
||||||
|
ret, specificReturn := fake.streamReturnsOnCall[len(fake.streamArgsForCall)]
|
||||||
|
fake.streamArgsForCall = append(fake.streamArgsForCall, struct {
|
||||||
|
}{})
|
||||||
|
stub := fake.StreamStub
|
||||||
|
fakeReturns := fake.streamReturns
|
||||||
|
fake.recordInvocation("Stream", []interface{}{})
|
||||||
|
fake.streamMutex.Unlock()
|
||||||
|
if stub != nil {
|
||||||
|
return stub()
|
||||||
|
}
|
||||||
|
if specificReturn {
|
||||||
|
return ret.result1
|
||||||
|
}
|
||||||
|
return fakeReturns.result1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalMediaTrack) StreamCallCount() int {
|
||||||
|
fake.streamMutex.RLock()
|
||||||
|
defer fake.streamMutex.RUnlock()
|
||||||
|
return len(fake.streamArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalMediaTrack) StreamCalls(stub func() string) {
|
||||||
|
fake.streamMutex.Lock()
|
||||||
|
defer fake.streamMutex.Unlock()
|
||||||
|
fake.StreamStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalMediaTrack) StreamReturns(result1 string) {
|
||||||
|
fake.streamMutex.Lock()
|
||||||
|
defer fake.streamMutex.Unlock()
|
||||||
|
fake.StreamStub = nil
|
||||||
|
fake.streamReturns = struct {
|
||||||
|
result1 string
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalMediaTrack) StreamReturnsOnCall(i int, result1 string) {
|
||||||
|
fake.streamMutex.Lock()
|
||||||
|
defer fake.streamMutex.Unlock()
|
||||||
|
fake.StreamStub = nil
|
||||||
|
if fake.streamReturnsOnCall == nil {
|
||||||
|
fake.streamReturnsOnCall = make(map[int]struct {
|
||||||
|
result1 string
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fake.streamReturnsOnCall[i] = struct {
|
||||||
|
result1 string
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
func (fake *FakeLocalMediaTrack) ToProto() *livekit.TrackInfo {
|
func (fake *FakeLocalMediaTrack) ToProto() *livekit.TrackInfo {
|
||||||
fake.toProtoMutex.Lock()
|
fake.toProtoMutex.Lock()
|
||||||
ret, specificReturn := fake.toProtoReturnsOnCall[len(fake.toProtoArgsForCall)]
|
ret, specificReturn := fake.toProtoReturnsOnCall[len(fake.toProtoArgsForCall)]
|
||||||
@@ -2050,6 +2113,8 @@ func (fake *FakeLocalMediaTrack) Invocations() map[string][][]interface{} {
|
|||||||
defer fake.signalCidMutex.RUnlock()
|
defer fake.signalCidMutex.RUnlock()
|
||||||
fake.sourceMutex.RLock()
|
fake.sourceMutex.RLock()
|
||||||
defer fake.sourceMutex.RUnlock()
|
defer fake.sourceMutex.RUnlock()
|
||||||
|
fake.streamMutex.RLock()
|
||||||
|
defer fake.streamMutex.RUnlock()
|
||||||
fake.toProtoMutex.RLock()
|
fake.toProtoMutex.RLock()
|
||||||
defer fake.toProtoMutex.RUnlock()
|
defer fake.toProtoMutex.RUnlock()
|
||||||
fake.updateVideoLayersMutex.RLock()
|
fake.updateVideoLayersMutex.RLock()
|
||||||
|
|||||||
@@ -263,6 +263,16 @@ type FakeLocalParticipant struct {
|
|||||||
getPacerReturnsOnCall map[int]struct {
|
getPacerReturnsOnCall map[int]struct {
|
||||||
result1 pacer.Pacer
|
result1 pacer.Pacer
|
||||||
}
|
}
|
||||||
|
GetPlayoutDelayConfigStub func() *livekit.PlayoutDelay
|
||||||
|
getPlayoutDelayConfigMutex sync.RWMutex
|
||||||
|
getPlayoutDelayConfigArgsForCall []struct {
|
||||||
|
}
|
||||||
|
getPlayoutDelayConfigReturns struct {
|
||||||
|
result1 *livekit.PlayoutDelay
|
||||||
|
}
|
||||||
|
getPlayoutDelayConfigReturnsOnCall map[int]struct {
|
||||||
|
result1 *livekit.PlayoutDelay
|
||||||
|
}
|
||||||
GetPublishedTrackStub func(livekit.TrackID) types.MediaTrack
|
GetPublishedTrackStub func(livekit.TrackID) types.MediaTrack
|
||||||
getPublishedTrackMutex sync.RWMutex
|
getPublishedTrackMutex sync.RWMutex
|
||||||
getPublishedTrackArgsForCall []struct {
|
getPublishedTrackArgsForCall []struct {
|
||||||
@@ -772,6 +782,16 @@ type FakeLocalParticipant struct {
|
|||||||
arg2 livekit.TrackID
|
arg2 livekit.TrackID
|
||||||
arg3 bool
|
arg3 bool
|
||||||
}
|
}
|
||||||
|
SupportSyncStreamIDStub func() bool
|
||||||
|
supportSyncStreamIDMutex sync.RWMutex
|
||||||
|
supportSyncStreamIDArgsForCall []struct {
|
||||||
|
}
|
||||||
|
supportSyncStreamIDReturns struct {
|
||||||
|
result1 bool
|
||||||
|
}
|
||||||
|
supportSyncStreamIDReturnsOnCall map[int]struct {
|
||||||
|
result1 bool
|
||||||
|
}
|
||||||
ToProtoStub func() *livekit.ParticipantInfo
|
ToProtoStub func() *livekit.ParticipantInfo
|
||||||
toProtoMutex sync.RWMutex
|
toProtoMutex sync.RWMutex
|
||||||
toProtoArgsForCall []struct {
|
toProtoArgsForCall []struct {
|
||||||
@@ -2149,6 +2169,59 @@ func (fake *FakeLocalParticipant) GetPacerReturnsOnCall(i int, result1 pacer.Pac
|
|||||||
}{result1}
|
}{result1}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) GetPlayoutDelayConfig() *livekit.PlayoutDelay {
|
||||||
|
fake.getPlayoutDelayConfigMutex.Lock()
|
||||||
|
ret, specificReturn := fake.getPlayoutDelayConfigReturnsOnCall[len(fake.getPlayoutDelayConfigArgsForCall)]
|
||||||
|
fake.getPlayoutDelayConfigArgsForCall = append(fake.getPlayoutDelayConfigArgsForCall, struct {
|
||||||
|
}{})
|
||||||
|
stub := fake.GetPlayoutDelayConfigStub
|
||||||
|
fakeReturns := fake.getPlayoutDelayConfigReturns
|
||||||
|
fake.recordInvocation("GetPlayoutDelayConfig", []interface{}{})
|
||||||
|
fake.getPlayoutDelayConfigMutex.Unlock()
|
||||||
|
if stub != nil {
|
||||||
|
return stub()
|
||||||
|
}
|
||||||
|
if specificReturn {
|
||||||
|
return ret.result1
|
||||||
|
}
|
||||||
|
return fakeReturns.result1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) GetPlayoutDelayConfigCallCount() int {
|
||||||
|
fake.getPlayoutDelayConfigMutex.RLock()
|
||||||
|
defer fake.getPlayoutDelayConfigMutex.RUnlock()
|
||||||
|
return len(fake.getPlayoutDelayConfigArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) GetPlayoutDelayConfigCalls(stub func() *livekit.PlayoutDelay) {
|
||||||
|
fake.getPlayoutDelayConfigMutex.Lock()
|
||||||
|
defer fake.getPlayoutDelayConfigMutex.Unlock()
|
||||||
|
fake.GetPlayoutDelayConfigStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) GetPlayoutDelayConfigReturns(result1 *livekit.PlayoutDelay) {
|
||||||
|
fake.getPlayoutDelayConfigMutex.Lock()
|
||||||
|
defer fake.getPlayoutDelayConfigMutex.Unlock()
|
||||||
|
fake.GetPlayoutDelayConfigStub = nil
|
||||||
|
fake.getPlayoutDelayConfigReturns = struct {
|
||||||
|
result1 *livekit.PlayoutDelay
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) GetPlayoutDelayConfigReturnsOnCall(i int, result1 *livekit.PlayoutDelay) {
|
||||||
|
fake.getPlayoutDelayConfigMutex.Lock()
|
||||||
|
defer fake.getPlayoutDelayConfigMutex.Unlock()
|
||||||
|
fake.GetPlayoutDelayConfigStub = nil
|
||||||
|
if fake.getPlayoutDelayConfigReturnsOnCall == nil {
|
||||||
|
fake.getPlayoutDelayConfigReturnsOnCall = make(map[int]struct {
|
||||||
|
result1 *livekit.PlayoutDelay
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fake.getPlayoutDelayConfigReturnsOnCall[i] = struct {
|
||||||
|
result1 *livekit.PlayoutDelay
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
func (fake *FakeLocalParticipant) GetPublishedTrack(arg1 livekit.TrackID) types.MediaTrack {
|
func (fake *FakeLocalParticipant) GetPublishedTrack(arg1 livekit.TrackID) types.MediaTrack {
|
||||||
fake.getPublishedTrackMutex.Lock()
|
fake.getPublishedTrackMutex.Lock()
|
||||||
ret, specificReturn := fake.getPublishedTrackReturnsOnCall[len(fake.getPublishedTrackArgsForCall)]
|
ret, specificReturn := fake.getPublishedTrackReturnsOnCall[len(fake.getPublishedTrackArgsForCall)]
|
||||||
@@ -5008,6 +5081,59 @@ func (fake *FakeLocalParticipant) SubscriptionPermissionUpdateArgsForCall(i int)
|
|||||||
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
|
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) SupportSyncStreamID() bool {
|
||||||
|
fake.supportSyncStreamIDMutex.Lock()
|
||||||
|
ret, specificReturn := fake.supportSyncStreamIDReturnsOnCall[len(fake.supportSyncStreamIDArgsForCall)]
|
||||||
|
fake.supportSyncStreamIDArgsForCall = append(fake.supportSyncStreamIDArgsForCall, struct {
|
||||||
|
}{})
|
||||||
|
stub := fake.SupportSyncStreamIDStub
|
||||||
|
fakeReturns := fake.supportSyncStreamIDReturns
|
||||||
|
fake.recordInvocation("SupportSyncStreamID", []interface{}{})
|
||||||
|
fake.supportSyncStreamIDMutex.Unlock()
|
||||||
|
if stub != nil {
|
||||||
|
return stub()
|
||||||
|
}
|
||||||
|
if specificReturn {
|
||||||
|
return ret.result1
|
||||||
|
}
|
||||||
|
return fakeReturns.result1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) SupportSyncStreamIDCallCount() int {
|
||||||
|
fake.supportSyncStreamIDMutex.RLock()
|
||||||
|
defer fake.supportSyncStreamIDMutex.RUnlock()
|
||||||
|
return len(fake.supportSyncStreamIDArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) SupportSyncStreamIDCalls(stub func() bool) {
|
||||||
|
fake.supportSyncStreamIDMutex.Lock()
|
||||||
|
defer fake.supportSyncStreamIDMutex.Unlock()
|
||||||
|
fake.SupportSyncStreamIDStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) SupportSyncStreamIDReturns(result1 bool) {
|
||||||
|
fake.supportSyncStreamIDMutex.Lock()
|
||||||
|
defer fake.supportSyncStreamIDMutex.Unlock()
|
||||||
|
fake.SupportSyncStreamIDStub = nil
|
||||||
|
fake.supportSyncStreamIDReturns = struct {
|
||||||
|
result1 bool
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) SupportSyncStreamIDReturnsOnCall(i int, result1 bool) {
|
||||||
|
fake.supportSyncStreamIDMutex.Lock()
|
||||||
|
defer fake.supportSyncStreamIDMutex.Unlock()
|
||||||
|
fake.SupportSyncStreamIDStub = nil
|
||||||
|
if fake.supportSyncStreamIDReturnsOnCall == nil {
|
||||||
|
fake.supportSyncStreamIDReturnsOnCall = make(map[int]struct {
|
||||||
|
result1 bool
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fake.supportSyncStreamIDReturnsOnCall[i] = struct {
|
||||||
|
result1 bool
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
func (fake *FakeLocalParticipant) ToProto() *livekit.ParticipantInfo {
|
func (fake *FakeLocalParticipant) ToProto() *livekit.ParticipantInfo {
|
||||||
fake.toProtoMutex.Lock()
|
fake.toProtoMutex.Lock()
|
||||||
ret, specificReturn := fake.toProtoReturnsOnCall[len(fake.toProtoArgsForCall)]
|
ret, specificReturn := fake.toProtoReturnsOnCall[len(fake.toProtoArgsForCall)]
|
||||||
@@ -5703,6 +5829,8 @@ func (fake *FakeLocalParticipant) Invocations() map[string][][]interface{} {
|
|||||||
defer fake.getLoggerMutex.RUnlock()
|
defer fake.getLoggerMutex.RUnlock()
|
||||||
fake.getPacerMutex.RLock()
|
fake.getPacerMutex.RLock()
|
||||||
defer fake.getPacerMutex.RUnlock()
|
defer fake.getPacerMutex.RUnlock()
|
||||||
|
fake.getPlayoutDelayConfigMutex.RLock()
|
||||||
|
defer fake.getPlayoutDelayConfigMutex.RUnlock()
|
||||||
fake.getPublishedTrackMutex.RLock()
|
fake.getPublishedTrackMutex.RLock()
|
||||||
defer fake.getPublishedTrackMutex.RUnlock()
|
defer fake.getPublishedTrackMutex.RUnlock()
|
||||||
fake.getPublishedTracksMutex.RLock()
|
fake.getPublishedTracksMutex.RLock()
|
||||||
@@ -5831,6 +5959,8 @@ func (fake *FakeLocalParticipant) Invocations() map[string][][]interface{} {
|
|||||||
defer fake.subscriptionPermissionMutex.RUnlock()
|
defer fake.subscriptionPermissionMutex.RUnlock()
|
||||||
fake.subscriptionPermissionUpdateMutex.RLock()
|
fake.subscriptionPermissionUpdateMutex.RLock()
|
||||||
defer fake.subscriptionPermissionUpdateMutex.RUnlock()
|
defer fake.subscriptionPermissionUpdateMutex.RUnlock()
|
||||||
|
fake.supportSyncStreamIDMutex.RLock()
|
||||||
|
defer fake.supportSyncStreamIDMutex.RUnlock()
|
||||||
fake.toProtoMutex.RLock()
|
fake.toProtoMutex.RLock()
|
||||||
defer fake.toProtoMutex.RUnlock()
|
defer fake.toProtoMutex.RUnlock()
|
||||||
fake.toProtoWithVersionMutex.RLock()
|
fake.toProtoWithVersionMutex.RLock()
|
||||||
|
|||||||
@@ -236,6 +236,16 @@ type FakeMediaTrack struct {
|
|||||||
sourceReturnsOnCall map[int]struct {
|
sourceReturnsOnCall map[int]struct {
|
||||||
result1 livekit.TrackSource
|
result1 livekit.TrackSource
|
||||||
}
|
}
|
||||||
|
StreamStub func() string
|
||||||
|
streamMutex sync.RWMutex
|
||||||
|
streamArgsForCall []struct {
|
||||||
|
}
|
||||||
|
streamReturns struct {
|
||||||
|
result1 string
|
||||||
|
}
|
||||||
|
streamReturnsOnCall map[int]struct {
|
||||||
|
result1 string
|
||||||
|
}
|
||||||
ToProtoStub func() *livekit.TrackInfo
|
ToProtoStub func() *livekit.TrackInfo
|
||||||
toProtoMutex sync.RWMutex
|
toProtoMutex sync.RWMutex
|
||||||
toProtoArgsForCall []struct {
|
toProtoArgsForCall []struct {
|
||||||
@@ -1474,6 +1484,59 @@ func (fake *FakeMediaTrack) SourceReturnsOnCall(i int, result1 livekit.TrackSour
|
|||||||
}{result1}
|
}{result1}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fake *FakeMediaTrack) Stream() string {
|
||||||
|
fake.streamMutex.Lock()
|
||||||
|
ret, specificReturn := fake.streamReturnsOnCall[len(fake.streamArgsForCall)]
|
||||||
|
fake.streamArgsForCall = append(fake.streamArgsForCall, struct {
|
||||||
|
}{})
|
||||||
|
stub := fake.StreamStub
|
||||||
|
fakeReturns := fake.streamReturns
|
||||||
|
fake.recordInvocation("Stream", []interface{}{})
|
||||||
|
fake.streamMutex.Unlock()
|
||||||
|
if stub != nil {
|
||||||
|
return stub()
|
||||||
|
}
|
||||||
|
if specificReturn {
|
||||||
|
return ret.result1
|
||||||
|
}
|
||||||
|
return fakeReturns.result1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeMediaTrack) StreamCallCount() int {
|
||||||
|
fake.streamMutex.RLock()
|
||||||
|
defer fake.streamMutex.RUnlock()
|
||||||
|
return len(fake.streamArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeMediaTrack) StreamCalls(stub func() string) {
|
||||||
|
fake.streamMutex.Lock()
|
||||||
|
defer fake.streamMutex.Unlock()
|
||||||
|
fake.StreamStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeMediaTrack) StreamReturns(result1 string) {
|
||||||
|
fake.streamMutex.Lock()
|
||||||
|
defer fake.streamMutex.Unlock()
|
||||||
|
fake.StreamStub = nil
|
||||||
|
fake.streamReturns = struct {
|
||||||
|
result1 string
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeMediaTrack) StreamReturnsOnCall(i int, result1 string) {
|
||||||
|
fake.streamMutex.Lock()
|
||||||
|
defer fake.streamMutex.Unlock()
|
||||||
|
fake.StreamStub = nil
|
||||||
|
if fake.streamReturnsOnCall == nil {
|
||||||
|
fake.streamReturnsOnCall = make(map[int]struct {
|
||||||
|
result1 string
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fake.streamReturnsOnCall[i] = struct {
|
||||||
|
result1 string
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
func (fake *FakeMediaTrack) ToProto() *livekit.TrackInfo {
|
func (fake *FakeMediaTrack) ToProto() *livekit.TrackInfo {
|
||||||
fake.toProtoMutex.Lock()
|
fake.toProtoMutex.Lock()
|
||||||
ret, specificReturn := fake.toProtoReturnsOnCall[len(fake.toProtoArgsForCall)]
|
ret, specificReturn := fake.toProtoReturnsOnCall[len(fake.toProtoArgsForCall)]
|
||||||
@@ -1615,6 +1678,8 @@ func (fake *FakeMediaTrack) Invocations() map[string][][]interface{} {
|
|||||||
defer fake.setMutedMutex.RUnlock()
|
defer fake.setMutedMutex.RUnlock()
|
||||||
fake.sourceMutex.RLock()
|
fake.sourceMutex.RLock()
|
||||||
defer fake.sourceMutex.RUnlock()
|
defer fake.sourceMutex.RUnlock()
|
||||||
|
fake.streamMutex.RLock()
|
||||||
|
defer fake.streamMutex.RUnlock()
|
||||||
fake.toProtoMutex.RLock()
|
fake.toProtoMutex.RLock()
|
||||||
defer fake.toProtoMutex.RUnlock()
|
defer fake.toProtoMutex.RUnlock()
|
||||||
fake.updateVideoLayersMutex.RLock()
|
fake.updateVideoLayersMutex.RLock()
|
||||||
|
|||||||
@@ -42,6 +42,25 @@ func PackStreamID(participantID livekit.ParticipantID, trackID livekit.TrackID)
|
|||||||
return string(participantID) + trackIdSeparator + string(trackID)
|
return string(participantID) + trackIdSeparator + string(trackID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PackSyncStreamID(participantID livekit.ParticipantID, stream string) string {
|
||||||
|
return string(participantID) + trackIdSeparator + stream
|
||||||
|
}
|
||||||
|
|
||||||
|
func StreamFromTrackSource(source livekit.TrackSource) string {
|
||||||
|
// group camera/mic, screenshare/audio together
|
||||||
|
switch source {
|
||||||
|
case livekit.TrackSource_SCREEN_SHARE:
|
||||||
|
return "screen"
|
||||||
|
case livekit.TrackSource_SCREEN_SHARE_AUDIO:
|
||||||
|
return "screen"
|
||||||
|
case livekit.TrackSource_CAMERA:
|
||||||
|
return "camera"
|
||||||
|
case livekit.TrackSource_MICROPHONE:
|
||||||
|
return "camera"
|
||||||
|
}
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
|
|
||||||
func PackDataTrackLabel(participantID livekit.ParticipantID, trackID livekit.TrackID, label string) string {
|
func PackDataTrackLabel(participantID livekit.ParticipantID, trackID livekit.TrackID, label string) string {
|
||||||
return string(participantID) + trackIdSeparator + string(trackID) + trackIdSeparator + label
|
return string(participantID) + trackIdSeparator + string(trackID) + trackIdSeparator + label
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,4 +151,9 @@ func applyDefaultRoomConfig(room *livekit.Room, conf *config.RoomConfig) {
|
|||||||
FmtpLine: codec.FmtpLine,
|
FmtpLine: codec.FmtpLine,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
room.PlayoutDelay = &livekit.PlayoutDelay{
|
||||||
|
Enabled: conf.PlayoutDelay.Enabled,
|
||||||
|
Min: uint32(conf.PlayoutDelay.Min),
|
||||||
|
Max: uint32(conf.PlayoutDelay.Max),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -390,6 +390,7 @@ func (r *RoomManager) StartSession(
|
|||||||
SubscriberAllowPause: subscriberAllowPause,
|
SubscriberAllowPause: subscriberAllowPause,
|
||||||
SubscriptionLimitAudio: r.config.Limit.SubscriptionLimitAudio,
|
SubscriptionLimitAudio: r.config.Limit.SubscriptionLimitAudio,
|
||||||
SubscriptionLimitVideo: r.config.Limit.SubscriptionLimitVideo,
|
SubscriptionLimitVideo: r.config.Limit.SubscriptionLimitVideo,
|
||||||
|
PlayoutDelay: protoRoom.PlayoutDelay,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ func (b *Buffer) Bind(params webrtc.RTPParameters, codec webrtc.RTPCodecCapabili
|
|||||||
|
|
||||||
for _, ext := range params.HeaderExtensions {
|
for _, ext := range params.HeaderExtensions {
|
||||||
switch ext.URI {
|
switch ext.URI {
|
||||||
case dd.ExtensionUrl:
|
case dd.ExtensionURI:
|
||||||
b.ddExt = uint8(ext.ID)
|
b.ddExt = uint8(ext.ID)
|
||||||
frc := NewFrameRateCalculatorDD(b.clockRate, b.logger)
|
frc := NewFrameRateCalculatorDD(b.clockRate, b.logger)
|
||||||
for i := range b.frameRateCalculator {
|
for i := range b.frameRateCalculator {
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ const (
|
|||||||
|
|
||||||
AllChainsAreActive = uint32(0)
|
AllChainsAreActive = uint32(0)
|
||||||
|
|
||||||
ExtensionUrl = "https://aomediacodec.github.io/av1-rtp-spec/#dependency-descriptor-rtp-header-extension"
|
ExtensionURI = "https://aomediacodec.github.io/av1-rtp-spec/#dependency-descriptor-rtp-header-extension"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------
|
||||||
|
|||||||
+129
-102
@@ -37,6 +37,7 @@ import (
|
|||||||
"github.com/livekit/livekit-server/pkg/sfu/connectionquality"
|
"github.com/livekit/livekit-server/pkg/sfu/connectionquality"
|
||||||
dd "github.com/livekit/livekit-server/pkg/sfu/dependencydescriptor"
|
dd "github.com/livekit/livekit-server/pkg/sfu/dependencydescriptor"
|
||||||
"github.com/livekit/livekit-server/pkg/sfu/pacer"
|
"github.com/livekit/livekit-server/pkg/sfu/pacer"
|
||||||
|
"github.com/livekit/livekit-server/pkg/sfu/rtpextension"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TrackSender defines an interface send media to remote peer
|
// TrackSender defines an interface send media to remote peer
|
||||||
@@ -183,6 +184,19 @@ type DownTrackStreamAllocatorListener interface {
|
|||||||
|
|
||||||
type ReceiverReportListener func(dt *DownTrack, report *rtcp.ReceiverReport)
|
type ReceiverReportListener func(dt *DownTrack, report *rtcp.ReceiverReport)
|
||||||
|
|
||||||
|
type DowntrackParams struct {
|
||||||
|
Codecs []webrtc.RTPCodecParameters
|
||||||
|
Receiver TrackReceiver
|
||||||
|
BufferFactory *buffer.Factory
|
||||||
|
SubID livekit.ParticipantID
|
||||||
|
StreamID string
|
||||||
|
MaxTrack int
|
||||||
|
PlayoutDelayLimit *livekit.PlayoutDelay
|
||||||
|
Pacer pacer.Pacer
|
||||||
|
Logger logger.Logger
|
||||||
|
Trailer []byte
|
||||||
|
}
|
||||||
|
|
||||||
// DownTrack implements TrackLocal, is the track used to write packets
|
// DownTrack implements TrackLocal, is the track used to write packets
|
||||||
// to SFU Subscriber, the track handle the packets for simple, simulcast
|
// to SFU Subscriber, the track handle the packets for simple, simulcast
|
||||||
// and SVC Publisher.
|
// and SVC Publisher.
|
||||||
@@ -192,17 +206,13 @@ type ReceiverReportListener func(dt *DownTrack, report *rtcp.ReceiverReport)
|
|||||||
// - closed
|
// - closed
|
||||||
// once closed, a DownTrack cannot be re-used.
|
// once closed, a DownTrack cannot be re-used.
|
||||||
type DownTrack struct {
|
type DownTrack struct {
|
||||||
logger logger.Logger
|
params DowntrackParams
|
||||||
id livekit.TrackID
|
id livekit.TrackID
|
||||||
subscriberID livekit.ParticipantID
|
kind webrtc.RTPCodecType
|
||||||
kind webrtc.RTPCodecType
|
mime string
|
||||||
mime string
|
ssrc uint32
|
||||||
ssrc uint32
|
payloadType uint8
|
||||||
streamID string
|
sequencer *sequencer
|
||||||
maxTrack int
|
|
||||||
payloadType uint8
|
|
||||||
sequencer *sequencer
|
|
||||||
bufferFactory *buffer.Factory
|
|
||||||
|
|
||||||
forwarder *Forwarder
|
forwarder *Forwarder
|
||||||
|
|
||||||
@@ -211,8 +221,8 @@ type DownTrack struct {
|
|||||||
absSendTimeExtID int
|
absSendTimeExtID int
|
||||||
transportWideExtID int
|
transportWideExtID int
|
||||||
dependencyDescriptorExtID int
|
dependencyDescriptorExtID int
|
||||||
receiver TrackReceiver
|
playoutDelayExtID int
|
||||||
transceiver *webrtc.RTPTransceiver
|
transceiver atomic.Pointer[webrtc.RTPTransceiver]
|
||||||
writeStream webrtc.TrackLocalWriter
|
writeStream webrtc.TrackLocalWriter
|
||||||
rtcpReader *buffer.RTCPReader
|
rtcpReader *buffer.RTCPReader
|
||||||
|
|
||||||
@@ -250,12 +260,13 @@ type DownTrack struct {
|
|||||||
bytesSent atomic.Uint32
|
bytesSent atomic.Uint32
|
||||||
bytesRetransmitted atomic.Uint32
|
bytesRetransmitted atomic.Uint32
|
||||||
|
|
||||||
|
playoutDelayBytes atomic.Value //bytes of marshalled playout delay
|
||||||
|
playoudDelayAcked atomic.Bool
|
||||||
|
|
||||||
pacer pacer.Pacer
|
pacer pacer.Pacer
|
||||||
|
|
||||||
maxLayerNotifierCh chan struct{}
|
maxLayerNotifierCh chan struct{}
|
||||||
|
|
||||||
trailer []byte
|
|
||||||
|
|
||||||
cbMu sync.RWMutex
|
cbMu sync.RWMutex
|
||||||
onStatsUpdate func(dt *DownTrack, stat *livekit.AnalyticsStat)
|
onStatsUpdate func(dt *DownTrack, stat *livekit.AnalyticsStat)
|
||||||
onMaxSubscribedLayerChanged func(dt *DownTrack, layer int32)
|
onMaxSubscribedLayerChanged func(dt *DownTrack, layer int32)
|
||||||
@@ -264,16 +275,8 @@ type DownTrack struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewDownTrack returns a DownTrack.
|
// NewDownTrack returns a DownTrack.
|
||||||
func NewDownTrack(
|
func NewDownTrack(params DowntrackParams) (*DownTrack, error) {
|
||||||
codecs []webrtc.RTPCodecParameters,
|
codecs := params.Codecs
|
||||||
r TrackReceiver,
|
|
||||||
bf *buffer.Factory,
|
|
||||||
subID livekit.ParticipantID,
|
|
||||||
mt int,
|
|
||||||
pacer pacer.Pacer,
|
|
||||||
trailer []byte,
|
|
||||||
logger logger.Logger,
|
|
||||||
) (*DownTrack, error) {
|
|
||||||
var kind webrtc.RTPCodecType
|
var kind webrtc.RTPCodecType
|
||||||
switch {
|
switch {
|
||||||
case strings.HasPrefix(codecs[0].MimeType, "audio/"):
|
case strings.HasPrefix(codecs[0].MimeType, "audio/"):
|
||||||
@@ -285,24 +288,18 @@ func NewDownTrack(
|
|||||||
}
|
}
|
||||||
|
|
||||||
d := &DownTrack{
|
d := &DownTrack{
|
||||||
logger: logger,
|
params: params,
|
||||||
id: r.TrackID(),
|
id: params.Receiver.TrackID(),
|
||||||
subscriberID: subID,
|
|
||||||
maxTrack: mt,
|
|
||||||
streamID: r.StreamID(),
|
|
||||||
bufferFactory: bf,
|
|
||||||
receiver: r,
|
|
||||||
upstreamCodecs: codecs,
|
upstreamCodecs: codecs,
|
||||||
kind: kind,
|
kind: kind,
|
||||||
codec: codecs[0].RTPCodecCapability,
|
codec: codecs[0].RTPCodecCapability,
|
||||||
pacer: pacer,
|
pacer: params.Pacer,
|
||||||
trailer: trailer,
|
|
||||||
maxLayerNotifierCh: make(chan struct{}, 20),
|
maxLayerNotifierCh: make(chan struct{}, 20),
|
||||||
}
|
}
|
||||||
d.forwarder = NewForwarder(
|
d.forwarder = NewForwarder(
|
||||||
d.kind,
|
d.kind,
|
||||||
d.logger,
|
params.Logger,
|
||||||
d.receiver.GetReferenceLayerRTPTimestamp,
|
d.params.Receiver.GetReferenceLayerRTPTimestamp,
|
||||||
d.getExpectedRTPTimestamp,
|
d.getExpectedRTPTimestamp,
|
||||||
)
|
)
|
||||||
d.forwarder.OnParkedLayerExpired(func() {
|
d.forwarder.OnParkedLayerExpired(func() {
|
||||||
@@ -314,7 +311,7 @@ func NewDownTrack(
|
|||||||
d.rtpStats = buffer.NewRTPStats(buffer.RTPStatsParams{
|
d.rtpStats = buffer.NewRTPStats(buffer.RTPStatsParams{
|
||||||
ClockRate: d.codec.ClockRate,
|
ClockRate: d.codec.ClockRate,
|
||||||
IsReceiverReportDriven: true,
|
IsReceiverReportDriven: true,
|
||||||
Logger: d.logger,
|
Logger: params.Logger,
|
||||||
})
|
})
|
||||||
d.deltaStatsSnapshotId = d.rtpStats.NewSnapshotId()
|
d.deltaStatsSnapshotId = d.rtpStats.NewSnapshotId()
|
||||||
d.deltaStatsOverriddenSnapshotId = d.rtpStats.NewSnapshotId()
|
d.deltaStatsOverriddenSnapshotId = d.rtpStats.NewSnapshotId()
|
||||||
@@ -325,7 +322,7 @@ func NewDownTrack(
|
|||||||
GetDeltaStats: d.getDeltaStats,
|
GetDeltaStats: d.getDeltaStats,
|
||||||
GetDeltaStatsOverridden: d.getDeltaStatsOverridden,
|
GetDeltaStatsOverridden: d.getDeltaStatsOverridden,
|
||||||
GetLastReceiverReportTime: func() time.Time { return d.rtpStats.LastReceiverReport() },
|
GetLastReceiverReportTime: func() time.Time { return d.rtpStats.LastReceiverReport() },
|
||||||
Logger: d.logger.WithValues("direction", "down"),
|
Logger: params.Logger.WithValues("direction", "down"),
|
||||||
})
|
})
|
||||||
d.connectionStats.OnStatsUpdate(func(_cs *connectionquality.ConnectionStats, stat *livekit.AnalyticsStat) {
|
d.connectionStats.OnStatsUpdate(func(_cs *connectionquality.ConnectionStats, stat *livekit.AnalyticsStat) {
|
||||||
if onStatsUpdate := d.getOnStatsUpdate(); onStatsUpdate != nil {
|
if onStatsUpdate := d.getOnStatsUpdate(); onStatsUpdate != nil {
|
||||||
@@ -333,6 +330,18 @@ func NewDownTrack(
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// set initial playout delay to minimum value
|
||||||
|
|
||||||
|
if d.params.PlayoutDelayLimit.GetEnabled() && d.params.PlayoutDelayLimit.GetMin() > 0 {
|
||||||
|
delay := rtpextension.PlayoutDelayFromValue(
|
||||||
|
uint16(d.params.PlayoutDelayLimit.GetMin()),
|
||||||
|
uint16(d.params.PlayoutDelayLimit.GetMax()),
|
||||||
|
)
|
||||||
|
b, err := delay.Marshal()
|
||||||
|
if err == nil {
|
||||||
|
d.playoutDelayBytes.Store(b)
|
||||||
|
}
|
||||||
|
}
|
||||||
if d.kind == webrtc.RTPCodecTypeVideo {
|
if d.kind == webrtc.RTPCodecTypeVideo {
|
||||||
go d.maxLayerNotifierWorker()
|
go d.maxLayerNotifierWorker()
|
||||||
}
|
}
|
||||||
@@ -362,7 +371,7 @@ func (d *DownTrack) Bind(t webrtc.TrackLocalContext) (webrtc.RTPCodecParameters,
|
|||||||
err := webrtc.ErrUnsupportedCodec
|
err := webrtc.ErrUnsupportedCodec
|
||||||
onBinding := d.onBinding
|
onBinding := d.onBinding
|
||||||
d.bindLock.Unlock()
|
d.bindLock.Unlock()
|
||||||
d.logger.Infow("bind error for unsupported codec", "codecs", d.upstreamCodecs, "remoteParameters", t.CodecParameters())
|
d.params.Logger.Infow("bind error for unsupported codec", "codecs", d.upstreamCodecs, "remoteParameters", t.CodecParameters())
|
||||||
if onBinding != nil {
|
if onBinding != nil {
|
||||||
onBinding(err)
|
onBinding(err)
|
||||||
}
|
}
|
||||||
@@ -371,17 +380,17 @@ func (d *DownTrack) Bind(t webrtc.TrackLocalContext) (webrtc.RTPCodecParameters,
|
|||||||
|
|
||||||
// if a downtrack is closed before bind, it already unsubscribed from client, don't do subsequent operation and return here.
|
// if a downtrack is closed before bind, it already unsubscribed from client, don't do subsequent operation and return here.
|
||||||
if d.IsClosed() {
|
if d.IsClosed() {
|
||||||
d.logger.Debugw("DownTrack closed before bind")
|
d.params.Logger.Debugw("DownTrack closed before bind")
|
||||||
d.bindLock.Unlock()
|
d.bindLock.Unlock()
|
||||||
return codec, nil
|
return codec, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
d.logger.Debugw("DownTrack.Bind", "codecs", d.upstreamCodecs, "matchCodec", codec, "ssrc", t.SSRC())
|
d.params.Logger.Debugw("DownTrack.Bind", "codecs", d.upstreamCodecs, "matchCodec", codec, "ssrc", t.SSRC())
|
||||||
d.ssrc = uint32(t.SSRC())
|
d.ssrc = uint32(t.SSRC())
|
||||||
d.payloadType = uint8(codec.PayloadType)
|
d.payloadType = uint8(codec.PayloadType)
|
||||||
d.writeStream = t.WriteStream()
|
d.writeStream = t.WriteStream()
|
||||||
d.mime = strings.ToLower(codec.MimeType)
|
d.mime = strings.ToLower(codec.MimeType)
|
||||||
if rr := d.bufferFactory.GetOrNew(packetio.RTCPBufferPacket, uint32(t.SSRC())).(*buffer.RTCPReader); rr != nil {
|
if rr := d.params.BufferFactory.GetOrNew(packetio.RTCPBufferPacket, uint32(t.SSRC())).(*buffer.RTCPReader); rr != nil {
|
||||||
rr.OnPacket(func(pkt []byte) {
|
rr.OnPacket(func(pkt []byte) {
|
||||||
d.handleRTCP(pkt)
|
d.handleRTCP(pkt)
|
||||||
})
|
})
|
||||||
@@ -389,9 +398,9 @@ func (d *DownTrack) Bind(t webrtc.TrackLocalContext) (webrtc.RTPCodecParameters,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if d.kind == webrtc.RTPCodecTypeAudio {
|
if d.kind == webrtc.RTPCodecTypeAudio {
|
||||||
d.sequencer = newSequencer(d.maxTrack, 0, d.logger)
|
d.sequencer = newSequencer(d.params.MaxTrack, 0, d.params.Logger)
|
||||||
} else {
|
} else {
|
||||||
d.sequencer = newSequencer(d.maxTrack, maxPadding, d.logger)
|
d.sequencer = newSequencer(d.params.MaxTrack, maxPadding, d.params.Logger)
|
||||||
}
|
}
|
||||||
|
|
||||||
d.codec = codec.RTPCodecCapability
|
d.codec = codec.RTPCodecCapability
|
||||||
@@ -401,9 +410,18 @@ func (d *DownTrack) Bind(t webrtc.TrackLocalContext) (webrtc.RTPCodecParameters,
|
|||||||
d.bound.Store(true)
|
d.bound.Store(true)
|
||||||
d.bindLock.Unlock()
|
d.bindLock.Unlock()
|
||||||
|
|
||||||
d.forwarder.DetermineCodec(d.codec, d.receiver.HeaderExtensions())
|
// Bind is called under RTPSender.mu lock, call the RTPSender.GetParameters in goroutine to avoid deadlock
|
||||||
|
go func() {
|
||||||
|
if tr := d.transceiver.Load(); tr != nil {
|
||||||
|
extensions := tr.Sender().GetParameters().HeaderExtensions
|
||||||
|
d.params.Logger.Debugw("negotiated downtrack extensions", "extensions", extensions)
|
||||||
|
d.SetRTPHeaderExtensions(extensions)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
d.logger.Debugw("downtrack bound")
|
d.forwarder.DetermineCodec(d.codec, d.params.Receiver.HeaderExtensions())
|
||||||
|
|
||||||
|
d.params.Logger.Debugw("downtrack bound")
|
||||||
d.onBindAndConnected()
|
d.onBindAndConnected()
|
||||||
|
|
||||||
return codec, nil
|
return codec, nil
|
||||||
@@ -417,7 +435,7 @@ func (d *DownTrack) Unbind(_ webrtc.TrackLocalContext) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *DownTrack) TrackInfoAvailable() {
|
func (d *DownTrack) TrackInfoAvailable() {
|
||||||
ti := d.receiver.TrackInfo()
|
ti := d.params.Receiver.TrackInfo()
|
||||||
if ti == nil {
|
if ti == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -495,9 +513,9 @@ func (d *DownTrack) ID() string { return string(d.id) }
|
|||||||
func (d *DownTrack) Codec() webrtc.RTPCodecCapability { return d.codec }
|
func (d *DownTrack) Codec() webrtc.RTPCodecCapability { return d.codec }
|
||||||
|
|
||||||
// StreamID is the group this track belongs too. This must be unique
|
// StreamID is the group this track belongs too. This must be unique
|
||||||
func (d *DownTrack) StreamID() string { return d.streamID }
|
func (d *DownTrack) StreamID() string { return d.params.StreamID }
|
||||||
|
|
||||||
func (d *DownTrack) SubscriberID() livekit.ParticipantID { return d.subscriberID }
|
func (d *DownTrack) SubscriberID() livekit.ParticipantID { return d.params.SubID }
|
||||||
|
|
||||||
// Sets RTP header extensions for this track
|
// Sets RTP header extensions for this track
|
||||||
func (d *DownTrack) SetRTPHeaderExtensions(rtpHeaderExtensions []webrtc.RTPHeaderExtensionParameter) {
|
func (d *DownTrack) SetRTPHeaderExtensions(rtpHeaderExtensions []webrtc.RTPHeaderExtensionParameter) {
|
||||||
@@ -505,10 +523,12 @@ func (d *DownTrack) SetRTPHeaderExtensions(rtpHeaderExtensions []webrtc.RTPHeade
|
|||||||
switch ext.URI {
|
switch ext.URI {
|
||||||
case sdp.ABSSendTimeURI:
|
case sdp.ABSSendTimeURI:
|
||||||
d.absSendTimeExtID = ext.ID
|
d.absSendTimeExtID = ext.ID
|
||||||
|
case dd.ExtensionURI:
|
||||||
|
d.dependencyDescriptorExtID = ext.ID
|
||||||
|
case rtpextension.PlayoutDelayURI:
|
||||||
|
d.playoutDelayExtID = ext.ID
|
||||||
case sdp.TransportCCURI:
|
case sdp.TransportCCURI:
|
||||||
d.transportWideExtID = ext.ID
|
d.transportWideExtID = ext.ID
|
||||||
case dd.ExtensionUrl:
|
|
||||||
d.dependencyDescriptorExtID = ext.ID
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -528,18 +548,18 @@ func (d *DownTrack) SSRC() uint32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *DownTrack) Stop() error {
|
func (d *DownTrack) Stop() error {
|
||||||
if d.transceiver != nil {
|
if tr := d.transceiver.Load(); tr != nil {
|
||||||
return d.transceiver.Stop()
|
return tr.Stop()
|
||||||
}
|
}
|
||||||
return errors.New("downtrack transceiver does not exist")
|
return errors.New("downtrack transceiver does not exist")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DownTrack) SetTransceiver(transceiver *webrtc.RTPTransceiver) {
|
func (d *DownTrack) SetTransceiver(transceiver *webrtc.RTPTransceiver) {
|
||||||
d.transceiver = transceiver
|
d.transceiver.Store(transceiver)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DownTrack) GetTransceiver() *webrtc.RTPTransceiver {
|
func (d *DownTrack) GetTransceiver() *webrtc.RTPTransceiver {
|
||||||
return d.transceiver
|
return d.transceiver.Load()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DownTrack) maybeStartKeyFrameRequester() {
|
func (d *DownTrack) maybeStartKeyFrameRequester() {
|
||||||
@@ -551,7 +571,6 @@ func (d *DownTrack) maybeStartKeyFrameRequester() {
|
|||||||
//
|
//
|
||||||
d.stopKeyFrameRequester()
|
d.stopKeyFrameRequester()
|
||||||
|
|
||||||
// SVC-TODO : don't need pli/lrr when layer comes down
|
|
||||||
locked, layer := d.forwarder.CheckSync()
|
locked, layer := d.forwarder.CheckSync()
|
||||||
if !locked {
|
if !locked {
|
||||||
go d.keyFrameRequester(d.keyFrameRequestGeneration.Load(), layer)
|
go d.keyFrameRequester(d.keyFrameRequestGeneration.Load(), layer)
|
||||||
@@ -584,8 +603,8 @@ func (d *DownTrack) keyFrameRequester(generation uint32, layer int32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if d.connected.Load() {
|
if d.connected.Load() {
|
||||||
d.logger.Debugw("sending PLI for layer lock", "generation", generation, "layer", layer)
|
d.params.Logger.Debugw("sending PLI for layer lock", "generation", generation, "layer", layer)
|
||||||
d.receiver.SendPLI(layer, false)
|
d.params.Receiver.SendPLI(layer, false)
|
||||||
d.rtpStats.UpdateLayerLockPliAndTime(1)
|
d.rtpStats.UpdateLayerLockPliAndTime(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -605,7 +624,7 @@ func (d *DownTrack) postMaxLayerNotifierEvent() {
|
|||||||
select {
|
select {
|
||||||
case d.maxLayerNotifierCh <- struct{}{}:
|
case d.maxLayerNotifierCh <- struct{}{}:
|
||||||
default:
|
default:
|
||||||
d.logger.Warnw("max layer notifier event queue full", nil)
|
d.params.Logger.Warnw("max layer notifier event queue full", nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -619,7 +638,7 @@ func (d *DownTrack) maxLayerNotifierWorker() {
|
|||||||
maxLayerSpatial = d.forwarder.GetMaxSubscribedSpatial()
|
maxLayerSpatial = d.forwarder.GetMaxSubscribedSpatial()
|
||||||
}
|
}
|
||||||
if onMaxSubscribedLayerChanged := d.getOnMaxLayerChanged(); onMaxSubscribedLayerChanged != nil {
|
if onMaxSubscribedLayerChanged := d.getOnMaxLayerChanged(); onMaxSubscribedLayerChanged != nil {
|
||||||
d.logger.Infow("max subscribed layer changed", "maxLayerSpatial", maxLayerSpatial)
|
d.params.Logger.Infow("max subscribed layer changed", "maxLayerSpatial", maxLayerSpatial)
|
||||||
onMaxSubscribedLayerChanged(d, maxLayerSpatial)
|
onMaxSubscribedLayerChanged(d, maxLayerSpatial)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -634,7 +653,7 @@ func (d *DownTrack) WriteRTP(extPkt *buffer.ExtPacket, layer int32) error {
|
|||||||
tp, err := d.forwarder.GetTranslationParams(extPkt, layer)
|
tp, err := d.forwarder.GetTranslationParams(extPkt, layer)
|
||||||
if tp.shouldDrop {
|
if tp.shouldDrop {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.logger.Errorw("write rtp packet failed", err)
|
d.params.Logger.Errorw("write rtp packet failed", err)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -654,13 +673,19 @@ func (d *DownTrack) WriteRTP(extPkt *buffer.ExtPacket, layer int32) error {
|
|||||||
|
|
||||||
hdr, err := d.getTranslatedRTPHeader(extPkt, tp)
|
hdr, err := d.getTranslatedRTPHeader(extPkt, tp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.logger.Errorw("write rtp packet failed", err)
|
d.params.Logger.Errorw("write rtp packet failed", err)
|
||||||
if pool != nil {
|
if pool != nil {
|
||||||
PacketFactory.Put(pool)
|
PacketFactory.Put(pool)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extensions := []pacer.ExtensionData{{ID: uint8(d.dependencyDescriptorExtID), Payload: tp.ddBytes}}
|
||||||
|
if d.playoutDelayExtID != 0 && !d.playoudDelayAcked.Load() {
|
||||||
|
if val := d.playoutDelayBytes.Load(); val != nil {
|
||||||
|
extensions = append(extensions, pacer.ExtensionData{ID: uint8(d.playoutDelayExtID), Payload: val.([]byte)})
|
||||||
|
}
|
||||||
|
}
|
||||||
if d.sequencer != nil {
|
if d.sequencer != nil {
|
||||||
d.sequencer.push(
|
d.sequencer.push(
|
||||||
extPkt.Packet.SequenceNumber,
|
extPkt.Packet.SequenceNumber,
|
||||||
@@ -675,7 +700,7 @@ func (d *DownTrack) WriteRTP(extPkt *buffer.ExtPacket, layer int32) error {
|
|||||||
|
|
||||||
d.pacer.Enqueue(pacer.Packet{
|
d.pacer.Enqueue(pacer.Packet{
|
||||||
Header: hdr,
|
Header: hdr,
|
||||||
Extensions: []pacer.ExtensionData{{ID: uint8(d.dependencyDescriptorExtID), Payload: tp.ddBytes}},
|
Extensions: extensions,
|
||||||
Payload: payload,
|
Payload: payload,
|
||||||
AbsSendTimeExtID: uint8(d.absSendTimeExtID),
|
AbsSendTimeExtID: uint8(d.absSendTimeExtID),
|
||||||
TransportWideExtID: uint8(d.transportWideExtID),
|
TransportWideExtID: uint8(d.transportWideExtID),
|
||||||
@@ -869,7 +894,7 @@ func (d *DownTrack) CloseWithFlush(flush bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
d.bindLock.Lock()
|
d.bindLock.Lock()
|
||||||
d.logger.Debugw("close down track", "flushBlankFrame", flush)
|
d.params.Logger.Debugw("close down track", "flushBlankFrame", flush)
|
||||||
if d.bound.Load() {
|
if d.bound.Load() {
|
||||||
if d.forwarder != nil {
|
if d.forwarder != nil {
|
||||||
d.forwarder.Mute(true)
|
d.forwarder.Mute(true)
|
||||||
@@ -893,12 +918,12 @@ func (d *DownTrack) CloseWithFlush(flush bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
d.bound.Store(false)
|
d.bound.Store(false)
|
||||||
d.logger.Debugw("closing sender", "kind", d.kind)
|
d.params.Logger.Debugw("closing sender", "kind", d.kind)
|
||||||
}
|
}
|
||||||
d.receiver.DeleteDownTrack(d.subscriberID)
|
d.params.Receiver.DeleteDownTrack(d.params.SubID)
|
||||||
|
|
||||||
if d.rtcpReader != nil && flush {
|
if d.rtcpReader != nil && flush {
|
||||||
d.logger.Debugw("downtrack close rtcp reader")
|
d.params.Logger.Debugw("downtrack close rtcp reader")
|
||||||
d.rtcpReader.Close()
|
d.rtcpReader.Close()
|
||||||
d.rtcpReader.OnPacket(nil)
|
d.rtcpReader.OnPacket(nil)
|
||||||
}
|
}
|
||||||
@@ -906,7 +931,7 @@ func (d *DownTrack) CloseWithFlush(flush bool) {
|
|||||||
d.bindLock.Unlock()
|
d.bindLock.Unlock()
|
||||||
d.connectionStats.Close()
|
d.connectionStats.Close()
|
||||||
d.rtpStats.Stop()
|
d.rtpStats.Stop()
|
||||||
d.logger.Infow("rtp stats", "direction", "downstream", "mime", d.mime, "ssrc", d.ssrc, "stats", d.rtpStats.ToString())
|
d.params.Logger.Infow("rtp stats", "direction", "downstream", "mime", d.mime, "ssrc", d.ssrc, "stats", d.rtpStats.ToString())
|
||||||
|
|
||||||
close(d.maxLayerNotifierCh)
|
close(d.maxLayerNotifierCh)
|
||||||
|
|
||||||
@@ -1088,17 +1113,17 @@ func (d *DownTrack) IsDeficient() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *DownTrack) BandwidthRequested() int64 {
|
func (d *DownTrack) BandwidthRequested() int64 {
|
||||||
_, brs := d.receiver.GetLayeredBitrate()
|
_, brs := d.params.Receiver.GetLayeredBitrate()
|
||||||
return d.forwarder.BandwidthRequested(brs)
|
return d.forwarder.BandwidthRequested(brs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DownTrack) DistanceToDesired() float64 {
|
func (d *DownTrack) DistanceToDesired() float64 {
|
||||||
al, brs := d.receiver.GetLayeredBitrate()
|
al, brs := d.params.Receiver.GetLayeredBitrate()
|
||||||
return d.forwarder.DistanceToDesired(al, brs)
|
return d.forwarder.DistanceToDesired(al, brs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DownTrack) AllocateOptimal(allowOvershoot bool) VideoAllocation {
|
func (d *DownTrack) AllocateOptimal(allowOvershoot bool) VideoAllocation {
|
||||||
al, brs := d.receiver.GetLayeredBitrate()
|
al, brs := d.params.Receiver.GetLayeredBitrate()
|
||||||
allocation := d.forwarder.AllocateOptimal(al, brs, allowOvershoot)
|
allocation := d.forwarder.AllocateOptimal(al, brs, allowOvershoot)
|
||||||
d.maybeStartKeyFrameRequester()
|
d.maybeStartKeyFrameRequester()
|
||||||
d.maybeAddTransition(allocation.BandwidthNeeded, allocation.DistanceToDesired, allocation.PauseReason)
|
d.maybeAddTransition(allocation.BandwidthNeeded, allocation.DistanceToDesired, allocation.PauseReason)
|
||||||
@@ -1106,7 +1131,7 @@ func (d *DownTrack) AllocateOptimal(allowOvershoot bool) VideoAllocation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *DownTrack) ProvisionalAllocatePrepare() {
|
func (d *DownTrack) ProvisionalAllocatePrepare() {
|
||||||
al, brs := d.receiver.GetLayeredBitrate()
|
al, brs := d.params.Receiver.GetLayeredBitrate()
|
||||||
d.forwarder.ProvisionalAllocatePrepare(al, brs)
|
d.forwarder.ProvisionalAllocatePrepare(al, brs)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1120,13 +1145,13 @@ func (d *DownTrack) ProvisionalAllocate(availableChannelCapacity int64, layers b
|
|||||||
|
|
||||||
func (d *DownTrack) ProvisionalAllocateGetCooperativeTransition(allowOvershoot bool) VideoTransition {
|
func (d *DownTrack) ProvisionalAllocateGetCooperativeTransition(allowOvershoot bool) VideoTransition {
|
||||||
transition := d.forwarder.ProvisionalAllocateGetCooperativeTransition(allowOvershoot)
|
transition := d.forwarder.ProvisionalAllocateGetCooperativeTransition(allowOvershoot)
|
||||||
d.logger.Debugw("stream: cooperative transition", "transition", transition)
|
d.params.Logger.Debugw("stream: cooperative transition", "transition", transition)
|
||||||
return transition
|
return transition
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DownTrack) ProvisionalAllocateGetBestWeightedTransition() VideoTransition {
|
func (d *DownTrack) ProvisionalAllocateGetBestWeightedTransition() VideoTransition {
|
||||||
transition := d.forwarder.ProvisionalAllocateGetBestWeightedTransition()
|
transition := d.forwarder.ProvisionalAllocateGetBestWeightedTransition()
|
||||||
d.logger.Debugw("stream: best weighted transition", "transition", transition)
|
d.params.Logger.Debugw("stream: best weighted transition", "transition", transition)
|
||||||
return transition
|
return transition
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1138,7 +1163,7 @@ func (d *DownTrack) ProvisionalAllocateCommit() VideoAllocation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *DownTrack) AllocateNextHigher(availableChannelCapacity int64, allowOvershoot bool) (VideoAllocation, bool) {
|
func (d *DownTrack) AllocateNextHigher(availableChannelCapacity int64, allowOvershoot bool) (VideoAllocation, bool) {
|
||||||
al, brs := d.receiver.GetLayeredBitrate()
|
al, brs := d.params.Receiver.GetLayeredBitrate()
|
||||||
allocation, available := d.forwarder.AllocateNextHigher(availableChannelCapacity, al, brs, allowOvershoot)
|
allocation, available := d.forwarder.AllocateNextHigher(availableChannelCapacity, al, brs, allowOvershoot)
|
||||||
d.maybeStartKeyFrameRequester()
|
d.maybeStartKeyFrameRequester()
|
||||||
d.maybeAddTransition(allocation.BandwidthNeeded, allocation.DistanceToDesired, allocation.PauseReason)
|
d.maybeAddTransition(allocation.BandwidthNeeded, allocation.DistanceToDesired, allocation.PauseReason)
|
||||||
@@ -1146,14 +1171,14 @@ func (d *DownTrack) AllocateNextHigher(availableChannelCapacity int64, allowOver
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *DownTrack) GetNextHigherTransition(allowOvershoot bool) (VideoTransition, bool) {
|
func (d *DownTrack) GetNextHigherTransition(allowOvershoot bool) (VideoTransition, bool) {
|
||||||
_, brs := d.receiver.GetLayeredBitrate()
|
_, brs := d.params.Receiver.GetLayeredBitrate()
|
||||||
transition, available := d.forwarder.GetNextHigherTransition(brs, allowOvershoot)
|
transition, available := d.forwarder.GetNextHigherTransition(brs, allowOvershoot)
|
||||||
d.logger.Debugw("stream: get next higher layer", "transition", transition, "available", available, "bitrates", brs)
|
d.params.Logger.Debugw("stream: get next higher layer", "transition", transition, "available", available, "bitrates", brs)
|
||||||
return transition, available
|
return transition, available
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DownTrack) Pause() VideoAllocation {
|
func (d *DownTrack) Pause() VideoAllocation {
|
||||||
al, brs := d.receiver.GetLayeredBitrate()
|
al, brs := d.params.Receiver.GetLayeredBitrate()
|
||||||
allocation := d.forwarder.Pause(al, brs)
|
allocation := d.forwarder.Pause(al, brs)
|
||||||
d.maybeStartKeyFrameRequester()
|
d.maybeStartKeyFrameRequester()
|
||||||
d.maybeAddTransition(allocation.BandwidthNeeded, allocation.DistanceToDesired, allocation.PauseReason)
|
d.maybeAddTransition(allocation.BandwidthNeeded, allocation.DistanceToDesired, allocation.PauseReason)
|
||||||
@@ -1165,7 +1190,7 @@ func (d *DownTrack) Resync() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *DownTrack) CreateSourceDescriptionChunks() []rtcp.SourceDescriptionChunk {
|
func (d *DownTrack) CreateSourceDescriptionChunks() []rtcp.SourceDescriptionChunk {
|
||||||
if !d.bound.Load() {
|
if !d.bound.Load() || d.transceiver.Load() == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return []rtcp.SourceDescriptionChunk{
|
return []rtcp.SourceDescriptionChunk{
|
||||||
@@ -1173,13 +1198,13 @@ func (d *DownTrack) CreateSourceDescriptionChunks() []rtcp.SourceDescriptionChun
|
|||||||
Source: d.ssrc,
|
Source: d.ssrc,
|
||||||
Items: []rtcp.SourceDescriptionItem{{
|
Items: []rtcp.SourceDescriptionItem{{
|
||||||
Type: rtcp.SDESCNAME,
|
Type: rtcp.SDESCNAME,
|
||||||
Text: d.streamID,
|
Text: d.params.StreamID,
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
Source: d.ssrc,
|
Source: d.ssrc,
|
||||||
Items: []rtcp.SourceDescriptionItem{{
|
Items: []rtcp.SourceDescriptionItem{{
|
||||||
Type: rtcp.SDESType(15),
|
Type: rtcp.SDESType(15),
|
||||||
Text: d.transceiver.Mid(),
|
Text: d.transceiver.Load().Mid(),
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -1194,7 +1219,7 @@ func (d *DownTrack) CreateSenderReport() *rtcp.SenderReport {
|
|||||||
if clockLayer == buffer.InvalidLayerSpatial {
|
if clockLayer == buffer.InvalidLayerSpatial {
|
||||||
clockLayer = d.forwarder.GetReferenceLayerSpatial()
|
clockLayer = d.forwarder.GetReferenceLayerSpatial()
|
||||||
}
|
}
|
||||||
return d.rtpStats.GetRtcpSenderReport(d.ssrc, d.receiver.GetCalculatedClockRate(clockLayer))
|
return d.rtpStats.GetRtcpSenderReport(d.ssrc, d.params.Receiver.GetCalculatedClockRate(clockLayer))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DownTrack) writeBlankFrameRTP(duration float32, generation uint32) chan struct{} {
|
func (d *DownTrack) writeBlankFrameRTP(duration float32, generation uint32) chan struct{} {
|
||||||
@@ -1243,7 +1268,7 @@ func (d *DownTrack) writeBlankFrameRTP(duration float32, generation uint32) chan
|
|||||||
|
|
||||||
snts, frameEndNeeded, err := d.forwarder.GetSnTsForBlankFrames(frameRate, 1)
|
snts, frameEndNeeded, err := d.forwarder.GetSnTsForBlankFrames(frameRate, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.logger.Warnw("could not get SN/TS for blank frame", err)
|
d.params.Logger.Warnw("could not get SN/TS for blank frame", err)
|
||||||
close(done)
|
close(done)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -1262,7 +1287,7 @@ func (d *DownTrack) writeBlankFrameRTP(duration float32, generation uint32) chan
|
|||||||
|
|
||||||
payload, err := getBlankFrame(frameEndNeeded)
|
payload, err := getBlankFrame(frameEndNeeded)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.logger.Warnw("could not get blank frame", err)
|
d.params.Logger.Warnw("could not get blank frame", err)
|
||||||
close(done)
|
close(done)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -1293,13 +1318,13 @@ func (d *DownTrack) writeBlankFrameRTP(duration float32, generation uint32) chan
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *DownTrack) maybeAddTrailer(buf []byte) int {
|
func (d *DownTrack) maybeAddTrailer(buf []byte) int {
|
||||||
if len(buf) < len(d.trailer) {
|
if len(buf) < len(d.params.Trailer) {
|
||||||
d.logger.Warnw("trailer too big", nil, "bufLen", len(buf), "trailerLen", len(d.trailer))
|
d.params.Logger.Warnw("trailer too big", nil, "bufLen", len(buf), "trailerLen", len(d.params.Trailer))
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
copy(buf, d.trailer)
|
copy(buf, d.params.Trailer)
|
||||||
return len(d.trailer)
|
return len(d.params.Trailer)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DownTrack) getOpusBlankFrame(_frameEndNeeded bool) ([]byte, error) {
|
func (d *DownTrack) getOpusBlankFrame(_frameEndNeeded bool) ([]byte, error) {
|
||||||
@@ -1366,7 +1391,7 @@ func (d *DownTrack) getH264BlankFrame(_frameEndNeeded bool) ([]byte, error) {
|
|||||||
func (d *DownTrack) handleRTCP(bytes []byte) {
|
func (d *DownTrack) handleRTCP(bytes []byte) {
|
||||||
pkts, err := rtcp.Unmarshal(bytes)
|
pkts, err := rtcp.Unmarshal(bytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.logger.Errorw("unmarshal rtcp receiver packets err", err)
|
d.params.Logger.Errorw("unmarshal rtcp receiver packets err", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1375,8 +1400,8 @@ func (d *DownTrack) handleRTCP(bytes []byte) {
|
|||||||
if pliOnce {
|
if pliOnce {
|
||||||
_, layer := d.forwarder.CheckSync()
|
_, layer := d.forwarder.CheckSync()
|
||||||
if layer != buffer.InvalidLayerSpatial && !d.forwarder.IsAnyMuted() {
|
if layer != buffer.InvalidLayerSpatial && !d.forwarder.IsAnyMuted() {
|
||||||
d.logger.Debugw("sending PLI RTCP", "layer", layer)
|
d.params.Logger.Debugw("sending PLI RTCP", "layer", layer)
|
||||||
d.receiver.SendPLI(layer, false)
|
d.params.Receiver.SendPLI(layer, false)
|
||||||
d.isNACKThrottled.Store(true)
|
d.isNACKThrottled.Store(true)
|
||||||
d.rtpStats.UpdatePliTime()
|
d.rtpStats.UpdatePliTime()
|
||||||
pliOnce = false
|
pliOnce = false
|
||||||
@@ -1424,6 +1449,8 @@ func (d *DownTrack) handleRTCP(bytes []byte) {
|
|||||||
if sal := d.getStreamAllocatorListener(); sal != nil {
|
if sal := d.getStreamAllocatorListener(); sal != nil {
|
||||||
sal.OnRTCPReceiverReport(d, r)
|
sal.OnRTCPReceiverReport(d, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d.playoudDelayAcked.Store(true)
|
||||||
}
|
}
|
||||||
if len(rr.Reports) > 0 {
|
if len(rr.Reports) > 0 {
|
||||||
d.listenerLock.RLock()
|
d.listenerLock.RLock()
|
||||||
@@ -1513,7 +1540,7 @@ func (d *DownTrack) retransmitPackets(nacks []uint16) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
pktBuff := *src
|
pktBuff := *src
|
||||||
n, err := d.receiver.ReadRTP(pktBuff, uint8(meta.layer), meta.sourceSeqNo)
|
n, err := d.params.Receiver.ReadRTP(pktBuff, uint8(meta.layer), meta.sourceSeqNo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
break
|
break
|
||||||
@@ -1528,7 +1555,7 @@ func (d *DownTrack) retransmitPackets(nacks []uint16) {
|
|||||||
|
|
||||||
var pkt rtp.Packet
|
var pkt rtp.Packet
|
||||||
if err = pkt.Unmarshal(pktBuff[:n]); err != nil {
|
if err = pkt.Unmarshal(pktBuff[:n]); err != nil {
|
||||||
d.logger.Errorw("unmarshalling rtp packet failed in retransmit", err)
|
d.params.Logger.Errorw("unmarshalling rtp packet failed in retransmit", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
pkt.Header.Marker = meta.marker
|
pkt.Header.Marker = meta.marker
|
||||||
@@ -1542,7 +1569,7 @@ func (d *DownTrack) retransmitPackets(nacks []uint16) {
|
|||||||
if d.mime == "video/vp8" && len(pkt.Payload) > 0 && len(meta.codecBytes) != 0 {
|
if d.mime == "video/vp8" && len(pkt.Payload) > 0 && len(meta.codecBytes) != 0 {
|
||||||
var incomingVP8 buffer.VP8
|
var incomingVP8 buffer.VP8
|
||||||
if err = incomingVP8.Unmarshal(pkt.Payload); err != nil {
|
if err = incomingVP8.Unmarshal(pkt.Payload); err != nil {
|
||||||
d.logger.Errorw("unmarshalling VP8 packet err", err)
|
d.params.Logger.Errorw("unmarshalling VP8 packet err", err)
|
||||||
PacketFactory.Put(pool)
|
PacketFactory.Put(pool)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -1633,9 +1660,9 @@ func (d *DownTrack) DebugInfo() map[string]interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return map[string]interface{}{
|
return map[string]interface{}{
|
||||||
"SubscriberID": d.subscriberID,
|
"SubscriberID": d.params.SubID,
|
||||||
"TrackID": d.id,
|
"TrackID": d.id,
|
||||||
"StreamID": d.streamID,
|
"StreamID": d.params.StreamID,
|
||||||
"SSRC": d.ssrc,
|
"SSRC": d.ssrc,
|
||||||
"MimeType": d.codec.MimeType,
|
"MimeType": d.codec.MimeType,
|
||||||
"Bound": d.bound.Load(),
|
"Bound": d.bound.Load(),
|
||||||
@@ -1697,7 +1724,7 @@ func (d *DownTrack) onBindAndConnected() {
|
|||||||
if d.kind == webrtc.RTPCodecTypeVideo {
|
if d.kind == webrtc.RTPCodecTypeVideo {
|
||||||
_, layer := d.forwarder.CheckSync()
|
_, layer := d.forwarder.CheckSync()
|
||||||
if layer != buffer.InvalidLayerSpatial {
|
if layer != buffer.InvalidLayerSpatial {
|
||||||
d.receiver.SendPLI(layer, true)
|
d.params.Receiver.SendPLI(layer, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1711,7 +1738,7 @@ func (d *DownTrack) sendPaddingOnMute() {
|
|||||||
// let uptrack have chance to send packet before we send padding
|
// let uptrack have chance to send packet before we send padding
|
||||||
time.Sleep(waitBeforeSendPaddingOnMute)
|
time.Sleep(waitBeforeSendPaddingOnMute)
|
||||||
|
|
||||||
d.logger.Debugw("sending padding on mute")
|
d.params.Logger.Debugw("sending padding on mute")
|
||||||
if d.kind == webrtc.RTPCodecTypeVideo {
|
if d.kind == webrtc.RTPCodecTypeVideo {
|
||||||
d.sendPaddingOnMuteForVideo()
|
d.sendPaddingOnMuteForVideo()
|
||||||
} else if d.mime == "audio/opus" {
|
} else if d.mime == "audio/opus" {
|
||||||
@@ -1741,7 +1768,7 @@ func (d *DownTrack) sendSilentFrameOnMuteForOpus() {
|
|||||||
}
|
}
|
||||||
snts, _, err := d.forwarder.GetSnTsForBlankFrames(frameRate, 1)
|
snts, _, err := d.forwarder.GetSnTsForBlankFrames(frameRate, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.logger.Warnw("could not get SN/TS for blank frame", err)
|
d.params.Logger.Warnw("could not get SN/TS for blank frame", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for i := 0; i < len(snts); i++ {
|
for i := 0; i < len(snts); i++ {
|
||||||
@@ -1758,7 +1785,7 @@ func (d *DownTrack) sendSilentFrameOnMuteForOpus() {
|
|||||||
|
|
||||||
payload, err := d.getOpusBlankFrame(false)
|
payload, err := d.getOpusBlankFrame(false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.logger.Warnw("could not get blank frame", err)
|
d.params.Logger.Warnw("could not get blank frame", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1801,7 +1828,7 @@ type sendPacketMetadata struct {
|
|||||||
func (d *DownTrack) packetSent(md interface{}, hdr *rtp.Header, payloadSize int, sendTime time.Time, sendError error) {
|
func (d *DownTrack) packetSent(md interface{}, hdr *rtp.Header, payloadSize int, sendTime time.Time, sendError error) {
|
||||||
spmd, ok := md.(sendPacketMetadata)
|
spmd, ok := md.(sendPacketMetadata)
|
||||||
if !ok {
|
if !ok {
|
||||||
d.logger.Errorw("invalid send packet metadata", nil)
|
d.params.Logger.Errorw("invalid send packet metadata", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1840,7 +1867,7 @@ func (d *DownTrack) packetSent(md interface{}, hdr *rtp.Header, payloadSize int,
|
|||||||
if spmd.isKeyFrame {
|
if spmd.isKeyFrame {
|
||||||
d.isNACKThrottled.Store(false)
|
d.isNACKThrottled.Store(false)
|
||||||
d.rtpStats.UpdateKeyFrame(1)
|
d.rtpStats.UpdateKeyFrame(1)
|
||||||
d.logger.Debugw(
|
d.params.Logger.Debugw(
|
||||||
"forwarded key frame",
|
"forwarded key frame",
|
||||||
"layer", spmd.layer,
|
"layer", spmd.layer,
|
||||||
"rtpsn", hdr.SequenceNumber,
|
"rtpsn", hdr.SequenceNumber,
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ func (f *Forwarder) DetermineCodec(codec webrtc.RTPCodecCapability, extensions [
|
|||||||
searchDone:
|
searchDone:
|
||||||
for _, ext := range extensions {
|
for _, ext := range extensions {
|
||||||
switch ext.URI {
|
switch ext.URI {
|
||||||
case dd.ExtensionUrl:
|
case dd.ExtensionURI:
|
||||||
isDDAvailable = true
|
isDDAvailable = true
|
||||||
break searchDone
|
break searchDone
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-7
@@ -126,8 +126,8 @@ type WebRTCReceiver struct {
|
|||||||
onStatsUpdate func(w *WebRTCReceiver, stat *livekit.AnalyticsStat)
|
onStatsUpdate func(w *WebRTCReceiver, stat *livekit.AnalyticsStat)
|
||||||
onMaxLayerChange func(maxLayer int32)
|
onMaxLayerChange func(maxLayer int32)
|
||||||
|
|
||||||
primaryReceiver atomic.Value // *RedPrimaryReceiver
|
primaryReceiver atomic.Pointer[RedPrimaryReceiver]
|
||||||
redReceiver atomic.Value // *RedReceiver
|
redReceiver atomic.Pointer[RedReceiver]
|
||||||
redPktWriter func(pkt *buffer.ExtPacket, spatialLayer int32)
|
redPktWriter func(pkt *buffer.ExtPacket, spatialLayer int32)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +232,7 @@ func NewWebRTCReceiver(
|
|||||||
w.connectionStats.Start(w.trackInfo)
|
w.connectionStats.Start(w.trackInfo)
|
||||||
|
|
||||||
for _, ext := range receiver.GetParameters().HeaderExtensions {
|
for _, ext := range receiver.GetParameters().HeaderExtensions {
|
||||||
if ext.URI == dd.ExtensionUrl {
|
if ext.URI == dd.ExtensionURI {
|
||||||
w.streamTrackerManager.AddDependencyDescriptorTrackers()
|
w.streamTrackerManager.AddDependencyDescriptorTrackers()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -624,10 +624,10 @@ func (w *WebRTCReceiver) forwardRTP(layer int32) {
|
|||||||
w.closed.Store(true)
|
w.closed.Store(true)
|
||||||
w.closeTracks()
|
w.closeTracks()
|
||||||
if pr := w.primaryReceiver.Load(); pr != nil {
|
if pr := w.primaryReceiver.Load(); pr != nil {
|
||||||
pr.(*RedPrimaryReceiver).Close()
|
pr.Close()
|
||||||
}
|
}
|
||||||
if pr := w.redReceiver.Load(); pr != nil {
|
if pr := w.redReceiver.Load(); pr != nil {
|
||||||
pr.(*RedReceiver).Close()
|
pr.Close()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -731,7 +731,7 @@ func (w *WebRTCReceiver) GetPrimaryReceiverForRed() TrackReceiver {
|
|||||||
w.bufferMu.Unlock()
|
w.bufferMu.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return w.primaryReceiver.Load().(*RedPrimaryReceiver)
|
return w.primaryReceiver.Load()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WebRTCReceiver) GetRedReceiver() TrackReceiver {
|
func (w *WebRTCReceiver) GetRedReceiver() TrackReceiver {
|
||||||
@@ -750,7 +750,7 @@ func (w *WebRTCReceiver) GetRedReceiver() TrackReceiver {
|
|||||||
w.bufferMu.Unlock()
|
w.bufferMu.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return w.redReceiver.Load().(*RedReceiver)
|
return w.redReceiver.Load()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WebRTCReceiver) GetTemporalLayerFpsForSpatial(layer int32) []float32 {
|
func (w *WebRTCReceiver) GetTemporalLayerFpsForSpatial(layer int32) []float32 {
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package rtpextension
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
PlayoutDelayURI = "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay"
|
||||||
|
|
||||||
|
playoutDelayExtensionSize = 3
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
errPlayoutDelayOverflow = errors.New("playout delay overflow")
|
||||||
|
errTooSmall = errors.New("buffer too small")
|
||||||
|
)
|
||||||
|
|
||||||
|
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||||
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
// | ID | len=2 | MIN delay | MAX delay |
|
||||||
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
// The wired MIN/MAX delay is in 10ms unit
|
||||||
|
|
||||||
|
type PlayOutDelay struct {
|
||||||
|
Min, Max uint16 // delay in ms
|
||||||
|
}
|
||||||
|
|
||||||
|
func PlayoutDelayFromValue(min, max uint16) PlayOutDelay {
|
||||||
|
if min >= (1<<12)*10 {
|
||||||
|
min = (1<<12 - 1) * 10
|
||||||
|
}
|
||||||
|
if max >= (1<<12)*10 {
|
||||||
|
max = (1<<12 - 1) * 10
|
||||||
|
}
|
||||||
|
return PlayOutDelay{Min: min, Max: max}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p PlayOutDelay) Marshal() ([]byte, error) {
|
||||||
|
min, max := p.Min/10, p.Max/10
|
||||||
|
if min >= 1<<12 || max >= 1<<12 {
|
||||||
|
return nil, errPlayoutDelayOverflow
|
||||||
|
}
|
||||||
|
|
||||||
|
return []byte{byte(min >> 4), byte(min<<4) | byte(max>>8), byte(max)}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PlayOutDelay) Unmarshal(rawData []byte) error {
|
||||||
|
if len(rawData) < playoutDelayExtensionSize {
|
||||||
|
return errTooSmall
|
||||||
|
}
|
||||||
|
|
||||||
|
p.Min = (binary.BigEndian.Uint16(rawData) >> 4) * 10
|
||||||
|
p.Max = (binary.BigEndian.Uint16(rawData[1:]) & 0x0FFF) * 10
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package rtpextension
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPlayoutDelay(t *testing.T) {
|
||||||
|
p1 := PlayOutDelay{Min: 100, Max: 200}
|
||||||
|
b, err := p1.Marshal()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, b, playoutDelayExtensionSize)
|
||||||
|
var p2 PlayOutDelay
|
||||||
|
err = p2.Unmarshal(b)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, p1, p2)
|
||||||
|
|
||||||
|
// overflow
|
||||||
|
p3 := PlayOutDelay{Min: 100, Max: (1 << 12) * 10}
|
||||||
|
_, err = p3.Marshal()
|
||||||
|
require.ErrorIs(t, err, errPlayoutDelayOverflow)
|
||||||
|
|
||||||
|
// too small
|
||||||
|
p4 := PlayOutDelay{}
|
||||||
|
err = p4.Unmarshal([]byte{0x00, 0x00})
|
||||||
|
require.ErrorIs(t, err, errTooSmall)
|
||||||
|
|
||||||
|
// from value
|
||||||
|
p5 := PlayoutDelayFromValue(1<<12*10, 1<<12*10+10)
|
||||||
|
_, err = p5.Marshal()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, uint16((1<<12)-1)*10, p5.Min)
|
||||||
|
require.Equal(t, uint16((1<<12)-1)*10, p5.Max)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user