mirror of
https://github.com/lkmio/lkm.git
synced 2025-09-27 11:32:26 +08:00
fix: webrtc拉流丢包没有重传问题
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/lkmio/lkm/stream"
|
"github.com/lkmio/lkm/stream"
|
||||||
"github.com/pion/webrtc/v3"
|
"github.com/pion/webrtc/v3"
|
||||||
"github.com/pion/webrtc/v3/pkg/media"
|
"github.com/pion/webrtc/v3/pkg/media"
|
||||||
|
"io"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -72,12 +73,27 @@ func (s *Sink) StartStreaming(transStream stream.TransStream) error {
|
|||||||
remoteTrack, err = webrtc.NewTrackLocalStaticSample(webrtc.RTPCodecCapability{MimeType: mimeType}, id, "pion")
|
remoteTrack, err = webrtc.NewTrackLocalStaticSample(webrtc.RTPCodecCapability{MimeType: mimeType}, id, "pion")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if _, err := connection.AddTransceiverFromTrack(remoteTrack, webrtc.RTPTransceiverInit{Direction: webrtc.RTPTransceiverDirectionSendonly}); err != nil {
|
}
|
||||||
return err
|
|
||||||
} else if _, err = connection.AddTrack(remoteTrack); err != nil {
|
transceiver, err := connection.AddTransceiverFromTrack(remoteTrack, webrtc.RTPTransceiverInit{Direction: webrtc.RTPTransceiverDirectionSendonly})
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pion需要在外部读取rtcp包,才会处理nack包丢包重传. https://github.com/pion/interceptor/blob/e1874104865b23ba465ecc505f959daf156cc2a5/pkg/nack/responder_interceptor.go#L82
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
_, _, err := transceiver.Sender().ReadRTCP()
|
||||||
|
if err == nil {
|
||||||
|
continue
|
||||||
|
} else if io.EOF == err || io.ErrClosedPipe == err {
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
println(err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
s.tracks[index] = remoteTrack
|
s.tracks[index] = remoteTrack
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user