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(),
|
||||
"webrtcTrackID", track.ID(),
|
||||
"rid", track.RID(),
|
||||
"SSRC", track.SSRC(),
|
||||
"ssrc", track.SSRC(),
|
||||
"rtxSsrc", track.RtxSSRC(),
|
||||
"mime", mime.NormalizeMimeType(codec.MimeType),
|
||||
"isReceiverAdded", isReceiverAdded,
|
||||
"sdpRids", logger.StringSlice(sdpRids[:]),
|
||||
@@ -2222,6 +2223,12 @@ func (p *ParticipantImpl) onMediaTrack(rtcTrack *webrtc.TrackRemote, rtpReceiver
|
||||
return
|
||||
}
|
||||
|
||||
p.TransportManager.RTPStreamPublished(
|
||||
uint32(track.SSRC()),
|
||||
p.TransportManager.GetPublisherMid(rtpReceiver),
|
||||
track.RID(),
|
||||
)
|
||||
|
||||
p.setIsPublisher(true)
|
||||
p.dirty.Store(true)
|
||||
|
||||
@@ -2231,7 +2238,8 @@ func (p *ParticipantImpl) onMediaTrack(rtcTrack *webrtc.TrackRemote, rtpReceiver
|
||||
"trackID", publishedTrack.ID(),
|
||||
"webrtcTrackID", track.ID(),
|
||||
"rid", track.RID(),
|
||||
"SSRC", track.SSRC(),
|
||||
"ssrc", track.SSRC(),
|
||||
"rtxSsrc", track.RtxSSRC(),
|
||||
"mime", mime.NormalizeMimeType(codec.MimeType),
|
||||
"trackInfo", logger.Proto(publishedTrack.ToProto()),
|
||||
"fromSdp", fromSdp,
|
||||
@@ -3069,7 +3077,8 @@ func (p *ParticipantImpl) mediaTrackReceived(track sfu.TrackRemote, rtpReceiver
|
||||
"kind", track.Kind().String(),
|
||||
"trackID", track.ID(),
|
||||
"rid", track.RID(),
|
||||
"SSRC", track.SSRC(),
|
||||
"ssrc", track.SSRC(),
|
||||
"rtxSsrc", track.RtxSSRC(),
|
||||
"mime", mime.NormalizeMimeType(track.Codec().MimeType),
|
||||
"mid", mid,
|
||||
)
|
||||
|
||||
+36
-17
@@ -17,6 +17,7 @@ package rtc
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"maps"
|
||||
"math/rand"
|
||||
"net"
|
||||
"slices"
|
||||
@@ -226,6 +227,8 @@ type PCTransport struct {
|
||||
|
||||
onNegotiationStateChanged func(state transport.NegotiationState)
|
||||
|
||||
rtxInfoExtractorFactory *sfuinterceptor.RTXInfoExtractorFactory
|
||||
|
||||
// stream allocator for subscriber PC
|
||||
streamAllocator *streamallocator.StreamAllocator
|
||||
|
||||
@@ -313,7 +316,10 @@ type TransportParams struct {
|
||||
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
|
||||
if params.AllowPlayoutDelay {
|
||||
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.
|
||||
me, err := createMediaEngine(params.EnabledCodecs, directionConfig, params.IsOfferer)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
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})
|
||||
if twccExtID != 0 {
|
||||
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))
|
||||
} 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
rtxInfoExtractorFactory := sfuinterceptor.NewRTXInfoExtractorFactory(
|
||||
setTWCCForVideo,
|
||||
func(repair, base uint32) {
|
||||
params.Logger.Debugw("rtx pair found from extension", "repair", repair, "base", base)
|
||||
params.Config.BufferFactory.SetRTXPair(repair, base)
|
||||
},
|
||||
params.Logger,
|
||||
)
|
||||
// put rtx interceptor behind unhandle simulcast interceptor so it can get the correct mid & rid
|
||||
ir.Add(sfuinterceptor.NewRTXInfoExtractorFactory(setTWCCForVideo, func(repair, base uint32) {
|
||||
params.Logger.Debugw("rtx pair found from extension", "repair", repair, "base", base)
|
||||
params.Config.BufferFactory.SetRTXPair(repair, base)
|
||||
}, params.Logger))
|
||||
ir.Add(rtxInfoExtractorFactory)
|
||||
|
||||
api := webrtc.NewAPI(
|
||||
webrtc.WithMediaEngine(me),
|
||||
@@ -497,7 +513,7 @@ func newPeerConnection(params TransportParams, onBandwidthEstimator func(estimat
|
||||
webrtc.WithInterceptorRegistry(ir),
|
||||
)
|
||||
pc, err := api.NewPeerConnection(params.Config.Configuration)
|
||||
return pc, me, err
|
||||
return pc, me, rtxInfoExtractorFactory, err
|
||||
}
|
||||
|
||||
func NewPCTransport(params TransportParams) (*PCTransport, error) {
|
||||
@@ -570,7 +586,7 @@ func NewPCTransport(params TransportParams) (*PCTransport, error) {
|
||||
|
||||
func (t *PCTransport) createPeerConnection() (cc.BandwidthEstimator, error) {
|
||||
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
|
||||
})
|
||||
if err != nil {
|
||||
@@ -607,9 +623,15 @@ func (t *PCTransport) createPeerConnection() (cc.BandwidthEstimator, error) {
|
||||
})
|
||||
|
||||
t.me = me
|
||||
|
||||
t.rtxInfoExtractorFactory = rtxInfoExtractorFactory
|
||||
return bwe, nil
|
||||
}
|
||||
|
||||
func (t *PCTransport) RTPStreamPublished(ssrc uint32, mid, rid string) {
|
||||
t.rtxInfoExtractorFactory.SetStreamInfo(ssrc, mid, rid, "")
|
||||
}
|
||||
|
||||
func (t *PCTransport) GetPacer() pacer.Pacer {
|
||||
return t.pacer
|
||||
}
|
||||
@@ -1123,10 +1145,9 @@ func (t *PCTransport) PendingRemoteDescription() *webrtc.SessionDescription {
|
||||
}
|
||||
|
||||
func (t *PCTransport) GetMid(rtpReceiver *webrtc.RTPReceiver) string {
|
||||
for _, tr := range t.pc.GetTransceivers() {
|
||||
if tr.Receiver() == rtpReceiver {
|
||||
return tr.Mid()
|
||||
}
|
||||
tr := rtpReceiver.RTPTransceiver()
|
||||
if tr != nil {
|
||||
return tr.Mid()
|
||||
}
|
||||
|
||||
return ""
|
||||
@@ -3156,9 +3177,7 @@ func nonSimulcastRTXRepairsFromSDP(s *sdp.SessionDescription, logger logger.Logg
|
||||
}
|
||||
}
|
||||
if !ridFound {
|
||||
for rtx, base := range rtxPairs {
|
||||
rtxRepairFlows[rtx] = base
|
||||
}
|
||||
maps.Copy(rtxRepairFlows, rtxPairs)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1023,3 +1023,11 @@ func (t *TransportManager) SetSubscriberChannelCapacity(channelCapacity int64) {
|
||||
func (t *TransportManager) hasRecentSignalLocked() bool {
|
||||
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
|
||||
}
|
||||
|
||||
func (f *RTXInfoExtractorFactory) setStreamInfo(ssrc uint32, mid, rid, rsid string) {
|
||||
func (f *RTXInfoExtractorFactory) SetStreamInfo(ssrc uint32, mid, rid, rsid string) {
|
||||
var repairSsrc, baseSsrc uint32
|
||||
f.lock.Lock()
|
||||
|
||||
if mid == "" || (rid == "" && rsid == "") {
|
||||
f.lock.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
if rsid != "" {
|
||||
// repair stream found, find base stream
|
||||
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 != "") {
|
||||
r.logger.Debugw("stream found", "mid", mid, "rid", rid, "rsid", rsid, "ssrc", header.SSRC)
|
||||
r.tryTimes = -1
|
||||
go r.factory.setStreamInfo(header.SSRC, mid, rid, rsid)
|
||||
go r.factory.SetStreamInfo(header.SSRC, mid, rid, rsid)
|
||||
} else {
|
||||
// ignore padding only packet for probe count
|
||||
if !(header.Padding && n-header.MarshalSize()-int(b[n-1]) == 0) {
|
||||
|
||||
@@ -21,6 +21,7 @@ type TrackRemote interface {
|
||||
RID() string
|
||||
Msid() string
|
||||
SSRC() webrtc.SSRC
|
||||
RtxSSRC() webrtc.SSRC
|
||||
StreamID() string
|
||||
Kind() webrtc.RTPCodecType
|
||||
Codec() webrtc.RTPCodecParameters
|
||||
|
||||
Reference in New Issue
Block a user