You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello and happy new year,
I am working on a webrtc pion-to-browser implementation on a server with high packet loss, thus I'm thinking i should utilize received NACKs and retransmit lost packets to fix this problem.
This is the basic workflow of the existing code(with help from preexisting examples):
Read from static RTP stream(ffmpeg) and write to track:
// read rtp video packets from ffmpeg on some portvListener, err=net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP(receiveIP), Port: receivePort})
iferr!=nil {
panic(err)
}
// define video codecvarcodec= webrtc.RTPCodecCapability{MimeType: webrtc.MimeTypeH264}
// define new track from local streamvideoTrack, err=webrtc.NewTrackLocalStaticRTP(vCodec, "video", vTrackName)
iferr!=nil {
panic(err)
}
// read maximum of RTCBufferSize from udp listener and write to trackgofunc() {
inboundRTPPacket:=make([]byte, RTCBufferSize)
for {
n, _, err:=vListener.ReadFrom(inboundRTPPacket)
iferr!=nil {
break
}
if_, err=videoTrack.Write(inboundRTPPacket[:n]); err!=nil {
iferrors.Is(err, io.ErrClosedPipe) {
break
}
panic(err)
}
}
}()
Use the previously defined track and stream to clients connecting to the pion server:
// create a MediaEngine object to configure the supported codecm:=&webrtc.MediaEngine{}
// setup the codecs to useiferr:=m.RegisterCodec(webrtc.RTPCodecParameters{
RTPCodecCapability: codec,
PayloadType: 96,
}, webrtc.RTPCodecTypeVideo); err!=nil {
panic(err)
}
// enable interceptors for NACK/RTCP Reports supporti:=&interceptor.Registry{}
// Use the default set of interceptorsiferr:=webrtc.RegisterDefaultInterceptors(m, i); err!=nil {
panic(err)
}
// Create the API object with the MediaEngineapi:=webrtc.NewAPI(webrtc.WithMediaEngine(m), webrtc.WithInterceptorRegistry(i))
// define configuration and create a new peerConnectionconfiguration= webrtc.Configuration{
ICEServers: []webrtc.ICEServer{
{
URLs: []string{"stun:stun.l.google.com:19302"},
},
},
}
serverConnection, err:=api.NewPeerConnection(configuration)
iferr!=nil {
panic(err)
}
Read incoming RTCP packets. This is where i assume i need to aknowledge NACKs and make retransmissions:
// Add previously created track to peer connectionrtcpReader, err:=serverConnection.AddTrack(videoTrack)
iferr!=nil {
panic(err)
}
// read maximum of RTCBufferSize from incoming RTCP packets and parse itgofunc() {
rtcpBuffer:=make([]byte, RTCBufferSize)
for {
n, attributes, err:=rtcpVReader.Read(rtcpBuffer)
iferr!=nil {
break
}
// detect NACK and retransmit lost packages(?)
}
}()
Is there a streamlined way of retransmitting lost packets, or do i need to create an implementation myself? I've seen solutions like this about how to handle retransmission:
The main question here is if I should obey all the retransmission requests or not. The way this is implemented in Google's WebRTC implementation right now is this one:
Keep a copy of the packets sent in the last 1000 msecs (the "history").
When a NACK is received try to send the packets requests if we still have them in the history.
But... (rtp_sender.cc)
Ignore the request if the packet has been resent in the last RTT msecs.
Ignore the request if we are sending too many retransmissions. There is a rate limiter (retransmission_rate_limiter) that is apparently configured to the whole channel bandwidth estimation.
If pacing is enabled insert this packet in the queue with normal priority.
I would love to hear any suggestions or other solutions to this problem. I would also appreciate if you could link me to any helpful resources or existing implementations to help with it.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello and happy new year,
I am working on a webrtc pion-to-browser implementation on a server with high packet loss, thus I'm thinking i should utilize received NACKs and retransmit lost packets to fix this problem.
This is the basic workflow of the existing code(with help from preexisting examples):
Is there a streamlined way of retransmitting lost packets, or do i need to create an implementation myself? I've seen solutions like this about how to handle retransmission:
I would love to hear any suggestions or other solutions to this problem. I would also appreciate if you could link me to any helpful resources or existing implementations to help with it.
Thank you for your time.
Beta Was this translation helpful? Give feedback.
All reactions