webrtc: fix race condition when broadcasting RTP packets (#2117)

This commit is contained in:
Alessandro Ros 2023-07-29 00:43:10 +02:00 committed by GitHub
parent e4bd1b35a2
commit dfc8e1fa91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 7 deletions

View File

@ -12,11 +12,22 @@ import (
"github.com/bluenviron/gortsplib/v3/pkg/formats/rtpvp9"
"github.com/bluenviron/gortsplib/v3/pkg/media"
"github.com/bluenviron/gortsplib/v3/pkg/ringbuffer"
"github.com/pion/rtp"
"github.com/pion/webrtc/v3"
"github.com/bluenviron/mediamtx/internal/formatprocessor"
)
// workaround until this gets tagged:
// https://github.com/pion/rtp/pull/234
func rtpPacketCopyForMarshal(in *rtp.Packet) *rtp.Packet {
return &rtp.Packet{
Header: in.Header,
Payload: in.Payload,
PaddingSize: in.PaddingSize,
}
}
type webRTCOutgoingTrack struct {
sender *webrtc.RTPSender
media *media.Media
@ -65,7 +76,7 @@ func newWebRTCOutgoingTrackVideo(medias media.Medias) (*webRTCOutgoingTrack, err
}
for _, pkt := range packets {
webRTCTrak.WriteRTP(pkt)
webRTCTrak.WriteRTP(rtpPacketCopyForMarshal(pkt))
}
return nil
@ -112,7 +123,7 @@ func newWebRTCOutgoingTrackVideo(medias media.Medias) (*webRTCOutgoingTrack, err
}
for _, pkt := range packets {
webRTCTrak.WriteRTP(pkt)
webRTCTrak.WriteRTP(rtpPacketCopyForMarshal(pkt))
}
return nil
@ -159,7 +170,7 @@ func newWebRTCOutgoingTrackVideo(medias media.Medias) (*webRTCOutgoingTrack, err
}
for _, pkt := range packets {
webRTCTrak.WriteRTP(pkt)
webRTCTrak.WriteRTP(rtpPacketCopyForMarshal(pkt))
}
return nil
@ -219,7 +230,7 @@ func newWebRTCOutgoingTrackVideo(medias media.Medias) (*webRTCOutgoingTrack, err
}
for _, pkt := range packets {
webRTCTrak.WriteRTP(pkt)
webRTCTrak.WriteRTP(rtpPacketCopyForMarshal(pkt))
}
return nil
@ -254,7 +265,7 @@ func newWebRTCOutgoingTrackAudio(medias media.Medias) (*webRTCOutgoingTrack, err
track: webRTCTrak,
cb: func(unit formatprocessor.Unit) error {
for _, pkt := range unit.GetRTPPackets() {
webRTCTrak.WriteRTP(pkt)
webRTCTrak.WriteRTP(rtpPacketCopyForMarshal(pkt))
}
return nil
@ -284,7 +295,7 @@ func newWebRTCOutgoingTrackAudio(medias media.Medias) (*webRTCOutgoingTrack, err
track: webRTCTrak,
cb: func(unit formatprocessor.Unit) error {
for _, pkt := range unit.GetRTPPackets() {
webRTCTrak.WriteRTP(pkt)
webRTCTrak.WriteRTP(rtpPacketCopyForMarshal(pkt))
}
return nil
@ -321,7 +332,7 @@ func newWebRTCOutgoingTrackAudio(medias media.Medias) (*webRTCOutgoingTrack, err
track: webRTCTrak,
cb: func(unit formatprocessor.Unit) error {
for _, pkt := range unit.GetRTPPackets() {
webRTCTrak.WriteRTP(pkt)
webRTCTrak.WriteRTP(rtpPacketCopyForMarshal(pkt))
}
return nil