Resolve RTX pair via OnTrack also. (#4190)
* Resolve RTX pair via OnTrack also. In simulcast probing path, the interceptor chain is not invoked for primary stream. Not sure if this is a recent change. Due to this, the RTX pair does not get resolved. Use the onTrack callback to resolve the pair. * remove debug
This commit is contained in:
+12
-3
@@ -2206,7 +2206,8 @@ func (p *ParticipantImpl) onMediaTrack(rtcTrack *webrtc.TrackRemote, rtpReceiver
|
|||||||
"kind", track.Kind().String(),
|
"kind", track.Kind().String(),
|
||||||
"webrtcTrackID", track.ID(),
|
"webrtcTrackID", track.ID(),
|
||||||
"rid", track.RID(),
|
"rid", track.RID(),
|
||||||
"SSRC", track.SSRC(),
|
"ssrc", track.SSRC(),
|
||||||
|
"rtxSsrc", track.RtxSSRC(),
|
||||||
"mime", mime.NormalizeMimeType(codec.MimeType),
|
"mime", mime.NormalizeMimeType(codec.MimeType),
|
||||||
"isReceiverAdded", isReceiverAdded,
|
"isReceiverAdded", isReceiverAdded,
|
||||||
"sdpRids", logger.StringSlice(sdpRids[:]),
|
"sdpRids", logger.StringSlice(sdpRids[:]),
|
||||||
@@ -2222,6 +2223,12 @@ func (p *ParticipantImpl) onMediaTrack(rtcTrack *webrtc.TrackRemote, rtpReceiver
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.TransportManager.RTPStreamPublished(
|
||||||
|
uint32(track.SSRC()),
|
||||||
|
p.TransportManager.GetPublisherMid(rtpReceiver),
|
||||||
|
track.RID(),
|
||||||
|
)
|
||||||
|
|
||||||
p.setIsPublisher(true)
|
p.setIsPublisher(true)
|
||||||
p.dirty.Store(true)
|
p.dirty.Store(true)
|
||||||
|
|
||||||
@@ -2231,7 +2238,8 @@ func (p *ParticipantImpl) onMediaTrack(rtcTrack *webrtc.TrackRemote, rtpReceiver
|
|||||||
"trackID", publishedTrack.ID(),
|
"trackID", publishedTrack.ID(),
|
||||||
"webrtcTrackID", track.ID(),
|
"webrtcTrackID", track.ID(),
|
||||||
"rid", track.RID(),
|
"rid", track.RID(),
|
||||||
"SSRC", track.SSRC(),
|
"ssrc", track.SSRC(),
|
||||||
|
"rtxSsrc", track.RtxSSRC(),
|
||||||
"mime", mime.NormalizeMimeType(codec.MimeType),
|
"mime", mime.NormalizeMimeType(codec.MimeType),
|
||||||
"trackInfo", logger.Proto(publishedTrack.ToProto()),
|
"trackInfo", logger.Proto(publishedTrack.ToProto()),
|
||||||
"fromSdp", fromSdp,
|
"fromSdp", fromSdp,
|
||||||
@@ -3069,7 +3077,8 @@ func (p *ParticipantImpl) mediaTrackReceived(track sfu.TrackRemote, rtpReceiver
|
|||||||
"kind", track.Kind().String(),
|
"kind", track.Kind().String(),
|
||||||
"trackID", track.ID(),
|
"trackID", track.ID(),
|
||||||
"rid", track.RID(),
|
"rid", track.RID(),
|
||||||
"SSRC", track.SSRC(),
|
"ssrc", track.SSRC(),
|
||||||
|
"rtxSsrc", track.RtxSSRC(),
|
||||||
"mime", mime.NormalizeMimeType(track.Codec().MimeType),
|
"mime", mime.NormalizeMimeType(track.Codec().MimeType),
|
||||||
"mid", mid,
|
"mid", mid,
|
||||||
)
|
)
|
||||||
|
|||||||
+34
-15
@@ -17,6 +17,7 @@ package rtc
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"maps"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"slices"
|
"slices"
|
||||||
@@ -226,6 +227,8 @@ type PCTransport struct {
|
|||||||
|
|
||||||
onNegotiationStateChanged func(state transport.NegotiationState)
|
onNegotiationStateChanged func(state transport.NegotiationState)
|
||||||
|
|
||||||
|
rtxInfoExtractorFactory *sfuinterceptor.RTXInfoExtractorFactory
|
||||||
|
|
||||||
// stream allocator for subscriber PC
|
// stream allocator for subscriber PC
|
||||||
streamAllocator *streamallocator.StreamAllocator
|
streamAllocator *streamallocator.StreamAllocator
|
||||||
|
|
||||||
@@ -313,7 +316,10 @@ type TransportParams struct {
|
|||||||
EnableDataTracks bool
|
EnableDataTracks 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, *sfuinterceptor.RTXInfoExtractorFactory, error) {
|
||||||
directionConfig := params.DirectionConfig
|
directionConfig := params.DirectionConfig
|
||||||
if params.AllowPlayoutDelay {
|
if params.AllowPlayoutDelay {
|
||||||
directionConfig.RTPHeaderExtension.Video = append(directionConfig.RTPHeaderExtension.Video, pd.PlayoutDelayURI)
|
directionConfig.RTPHeaderExtension.Video = append(directionConfig.RTPHeaderExtension.Video, pd.PlayoutDelayURI)
|
||||||
@@ -324,7 +330,7 @@ func newPeerConnection(params TransportParams, onBandwidthEstimator func(estimat
|
|||||||
// So, disable H.264 High Profile for SUBSCRIBER peer connection to ensure it is not offered.
|
// So, disable H.264 High Profile for SUBSCRIBER peer connection to ensure it is not offered.
|
||||||
me, err := createMediaEngine(params.EnabledCodecs, directionConfig, params.IsOfferer)
|
me, err := createMediaEngine(params.EnabledCodecs, directionConfig, params.IsOfferer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
se := params.Config.SettingEngine
|
se := params.Config.SettingEngine
|
||||||
@@ -478,18 +484,28 @@ func newPeerConnection(params TransportParams, onBandwidthEstimator func(estimat
|
|||||||
twccExtID := sfuutils.GetHeaderExtensionID(info.RTPHeaderExtensions, webrtc.RTPHeaderExtensionCapability{URI: sdp.TransportCCURI})
|
twccExtID := sfuutils.GetHeaderExtensionID(info.RTPHeaderExtensions, webrtc.RTPHeaderExtensionCapability{URI: sdp.TransportCCURI})
|
||||||
if twccExtID != 0 {
|
if twccExtID != 0 {
|
||||||
if buffer := params.Config.BufferFactory.GetBuffer(info.SSRC); buffer != nil {
|
if buffer := params.Config.BufferFactory.GetBuffer(info.SSRC); buffer != nil {
|
||||||
params.Logger.Debugw("set rtx twcc and ext id", "ssrc", info.SSRC, "twccExtID", twccExtID)
|
params.Logger.Debugw(
|
||||||
|
"set twcc and ext id",
|
||||||
|
"ssrc", info.SSRC,
|
||||||
|
"isRTX", mime.GetMimeTypeCodec(info.MimeType) == mime.MimeTypeCodecRTX,
|
||||||
|
"twccExtID", twccExtID,
|
||||||
|
)
|
||||||
buffer.SetTWCCAndExtID(params.Twcc, uint8(twccExtID))
|
buffer.SetTWCCAndExtID(params.Twcc, uint8(twccExtID))
|
||||||
} else {
|
} else {
|
||||||
params.Logger.Warnw("failed to get buffer for rtx stream", nil, "ssrc", info.SSRC)
|
params.Logger.Warnw("failed to get buffer for stream", nil, "ssrc", info.SSRC)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// put rtx interceptor behind unhandle simulcast interceptor so it can get the correct mid & rid
|
rtxInfoExtractorFactory := sfuinterceptor.NewRTXInfoExtractorFactory(
|
||||||
ir.Add(sfuinterceptor.NewRTXInfoExtractorFactory(setTWCCForVideo, func(repair, base uint32) {
|
setTWCCForVideo,
|
||||||
|
func(repair, base uint32) {
|
||||||
params.Logger.Debugw("rtx pair found from extension", "repair", repair, "base", base)
|
params.Logger.Debugw("rtx pair found from extension", "repair", repair, "base", base)
|
||||||
params.Config.BufferFactory.SetRTXPair(repair, base)
|
params.Config.BufferFactory.SetRTXPair(repair, base)
|
||||||
}, params.Logger))
|
},
|
||||||
|
params.Logger,
|
||||||
|
)
|
||||||
|
// put rtx interceptor behind unhandle simulcast interceptor so it can get the correct mid & rid
|
||||||
|
ir.Add(rtxInfoExtractorFactory)
|
||||||
|
|
||||||
api := webrtc.NewAPI(
|
api := webrtc.NewAPI(
|
||||||
webrtc.WithMediaEngine(me),
|
webrtc.WithMediaEngine(me),
|
||||||
@@ -497,7 +513,7 @@ func newPeerConnection(params TransportParams, onBandwidthEstimator func(estimat
|
|||||||
webrtc.WithInterceptorRegistry(ir),
|
webrtc.WithInterceptorRegistry(ir),
|
||||||
)
|
)
|
||||||
pc, err := api.NewPeerConnection(params.Config.Configuration)
|
pc, err := api.NewPeerConnection(params.Config.Configuration)
|
||||||
return pc, me, err
|
return pc, me, rtxInfoExtractorFactory, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPCTransport(params TransportParams) (*PCTransport, error) {
|
func NewPCTransport(params TransportParams) (*PCTransport, error) {
|
||||||
@@ -570,7 +586,7 @@ func NewPCTransport(params TransportParams) (*PCTransport, error) {
|
|||||||
|
|
||||||
func (t *PCTransport) createPeerConnection() (cc.BandwidthEstimator, error) {
|
func (t *PCTransport) createPeerConnection() (cc.BandwidthEstimator, error) {
|
||||||
var bwe cc.BandwidthEstimator
|
var bwe cc.BandwidthEstimator
|
||||||
pc, me, err := newPeerConnection(t.params, func(estimator cc.BandwidthEstimator) {
|
pc, me, rtxInfoExtractorFactory, err := newPeerConnection(t.params, func(estimator cc.BandwidthEstimator) {
|
||||||
bwe = estimator
|
bwe = estimator
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -607,9 +623,15 @@ func (t *PCTransport) createPeerConnection() (cc.BandwidthEstimator, error) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.me = me
|
t.me = me
|
||||||
|
|
||||||
|
t.rtxInfoExtractorFactory = rtxInfoExtractorFactory
|
||||||
return bwe, nil
|
return bwe, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *PCTransport) RTPStreamPublished(ssrc uint32, mid, rid string) {
|
||||||
|
t.rtxInfoExtractorFactory.SetStreamInfo(ssrc, mid, rid, "")
|
||||||
|
}
|
||||||
|
|
||||||
func (t *PCTransport) GetPacer() pacer.Pacer {
|
func (t *PCTransport) GetPacer() pacer.Pacer {
|
||||||
return t.pacer
|
return t.pacer
|
||||||
}
|
}
|
||||||
@@ -1123,11 +1145,10 @@ func (t *PCTransport) PendingRemoteDescription() *webrtc.SessionDescription {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *PCTransport) GetMid(rtpReceiver *webrtc.RTPReceiver) string {
|
func (t *PCTransport) GetMid(rtpReceiver *webrtc.RTPReceiver) string {
|
||||||
for _, tr := range t.pc.GetTransceivers() {
|
tr := rtpReceiver.RTPTransceiver()
|
||||||
if tr.Receiver() == rtpReceiver {
|
if tr != nil {
|
||||||
return tr.Mid()
|
return tr.Mid()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@@ -3156,9 +3177,7 @@ func nonSimulcastRTXRepairsFromSDP(s *sdp.SessionDescription, logger logger.Logg
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !ridFound {
|
if !ridFound {
|
||||||
for rtx, base := range rtxPairs {
|
maps.Copy(rtxRepairFlows, rtxPairs)
|
||||||
rtxRepairFlows[rtx] = base
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1023,3 +1023,11 @@ func (t *TransportManager) SetSubscriberChannelCapacity(channelCapacity int64) {
|
|||||||
func (t *TransportManager) hasRecentSignalLocked() bool {
|
func (t *TransportManager) hasRecentSignalLocked() bool {
|
||||||
return time.Since(t.lastSignalAt) < PingTimeoutSeconds*time.Second
|
return time.Since(t.lastSignalAt) < PingTimeoutSeconds*time.Second
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *TransportManager) RTPStreamPublished(ssrc uint32, mid, rid string) {
|
||||||
|
if t.params.UseOneShotSignallingMode || t.params.UseSinglePeerConnection {
|
||||||
|
t.publisher.RTPStreamPublished(ssrc, mid, rid)
|
||||||
|
} else {
|
||||||
|
t.subscriber.RTPStreamPublished(ssrc, mid, rid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -61,10 +61,15 @@ func (f *RTXInfoExtractorFactory) NewInterceptor(id string) (interceptor.Interce
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *RTXInfoExtractorFactory) setStreamInfo(ssrc uint32, mid, rid, rsid string) {
|
func (f *RTXInfoExtractorFactory) SetStreamInfo(ssrc uint32, mid, rid, rsid string) {
|
||||||
var repairSsrc, baseSsrc uint32
|
var repairSsrc, baseSsrc uint32
|
||||||
f.lock.Lock()
|
f.lock.Lock()
|
||||||
|
|
||||||
|
if mid == "" || (rid == "" && rsid == "") {
|
||||||
|
f.lock.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if rsid != "" {
|
if rsid != "" {
|
||||||
// repair stream found, find base stream
|
// repair stream found, find base stream
|
||||||
for base, info := range f.streams {
|
for base, info := range f.streams {
|
||||||
@@ -171,7 +176,7 @@ func (r *rtxInfoReader) Read(b []byte, a interceptor.Attributes) (int, intercept
|
|||||||
if mid != "" && (rid != "" || rsid != "") {
|
if mid != "" && (rid != "" || rsid != "") {
|
||||||
r.logger.Debugw("stream found", "mid", mid, "rid", rid, "rsid", rsid, "ssrc", header.SSRC)
|
r.logger.Debugw("stream found", "mid", mid, "rid", rid, "rsid", rsid, "ssrc", header.SSRC)
|
||||||
r.tryTimes = -1
|
r.tryTimes = -1
|
||||||
go r.factory.setStreamInfo(header.SSRC, mid, rid, rsid)
|
go r.factory.SetStreamInfo(header.SSRC, mid, rid, rsid)
|
||||||
} else {
|
} else {
|
||||||
// ignore padding only packet for probe count
|
// ignore padding only packet for probe count
|
||||||
if !(header.Padding && n-header.MarshalSize()-int(b[n-1]) == 0) {
|
if !(header.Padding && n-header.MarshalSize()-int(b[n-1]) == 0) {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ type TrackRemote interface {
|
|||||||
RID() string
|
RID() string
|
||||||
Msid() string
|
Msid() string
|
||||||
SSRC() webrtc.SSRC
|
SSRC() webrtc.SSRC
|
||||||
|
RtxSSRC() webrtc.SSRC
|
||||||
StreamID() string
|
StreamID() string
|
||||||
Kind() webrtc.RTPCodecType
|
Kind() webrtc.RTPCodecType
|
||||||
Codec() webrtc.RTPCodecParameters
|
Codec() webrtc.RTPCodecParameters
|
||||||
|
|||||||
Reference in New Issue
Block a user