mirror of
https://github.com/pion/webrtc.git
synced 2025-10-03 22:36:29 +08:00
Process RTCP Packets in OnTrack examples
TWCC and Receiver Reports are needed for a good default experience
This commit is contained in:
@@ -64,6 +64,18 @@ func main() { // nolint:gocognit
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// Read incoming RTCP packets
|
||||||
|
// Before these packets are returned they are processed by interceptors. For things
|
||||||
|
// like TWCC and RTCP Reports this needs to be called.
|
||||||
|
go func() {
|
||||||
|
rtcpBuf := make([]byte, 1500)
|
||||||
|
for {
|
||||||
|
if _, _, rtcpErr := receiver.Read(rtcpBuf); rtcpErr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
// Create a local track, all our SFU clients will be fed via this track
|
// Create a local track, all our SFU clients will be fed via this track
|
||||||
localTrack, newTrackErr := webrtc.NewTrackLocalStaticRTP(remoteTrack.Codec().RTPCodecCapability, "video", "pion")
|
localTrack, newTrackErr := webrtc.NewTrackLocalStaticRTP(remoteTrack.Codec().RTPCodecCapability, "video", "pion")
|
||||||
if newTrackErr != nil {
|
if newTrackErr != nil {
|
||||||
|
@@ -110,6 +110,18 @@ func main() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// Read incoming RTCP packets
|
||||||
|
// Before these packets are returned they are processed by interceptors. For things
|
||||||
|
// like TWCC and RTCP Reports this needs to be called.
|
||||||
|
go func() {
|
||||||
|
rtcpBuf := make([]byte, 1500)
|
||||||
|
for {
|
||||||
|
if _, _, rtcpErr := receiver.Read(rtcpBuf); rtcpErr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
fmt.Printf("Track has started, of type %d: %s \n", track.PayloadType(), track.Codec().MimeType)
|
fmt.Printf("Track has started, of type %d: %s \n", track.PayloadType(), track.Codec().MimeType)
|
||||||
for {
|
for {
|
||||||
// Read RTP packets being sent to Pion
|
// Read RTP packets being sent to Pion
|
||||||
|
@@ -132,6 +132,18 @@ func main() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// Read incoming RTCP packets
|
||||||
|
// Before these packets are returned they are processed by interceptors. For things
|
||||||
|
// like TWCC and RTCP Reports this needs to be called.
|
||||||
|
go func() {
|
||||||
|
rtcpBuf := make([]byte, 1500)
|
||||||
|
for {
|
||||||
|
if _, _, rtcpErr := receiver.Read(rtcpBuf); rtcpErr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
b := make([]byte, 1500)
|
b := make([]byte, 1500)
|
||||||
rtpPacket := &rtp.Packet{}
|
rtpPacket := &rtp.Packet{}
|
||||||
for {
|
for {
|
||||||
|
@@ -116,6 +116,18 @@ func main() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// Read incoming RTCP packets
|
||||||
|
// Before these packets are returned they are processed by interceptors. For things
|
||||||
|
// like TWCC and RTCP Reports this needs to be called.
|
||||||
|
go func() {
|
||||||
|
rtcpBuf := make([]byte, 1500)
|
||||||
|
for {
|
||||||
|
if _, _, rtcpErr := receiver.Read(rtcpBuf); rtcpErr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
codec := track.Codec()
|
codec := track.Codec()
|
||||||
if strings.EqualFold(codec.MimeType, webrtc.MimeTypeOpus) {
|
if strings.EqualFold(codec.MimeType, webrtc.MimeTypeOpus) {
|
||||||
fmt.Println("Got Opus track, saving to disk as output.opus (48 kHz, 2 channels)")
|
fmt.Println("Got Opus track, saving to disk as output.opus (48 kHz, 2 channels)")
|
||||||
|
@@ -123,8 +123,6 @@ func main() {
|
|||||||
peerConnection.OnTrack(func(track *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) {
|
peerConnection.OnTrack(func(track *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) {
|
||||||
fmt.Println("Track has started")
|
fmt.Println("Track has started")
|
||||||
|
|
||||||
// Start reading from all the streams and sending them to the related output track
|
|
||||||
rid := track.RID()
|
|
||||||
go func() {
|
go func() {
|
||||||
ticker := time.NewTicker(3 * time.Second)
|
ticker := time.NewTicker(3 * time.Second)
|
||||||
for range ticker.C {
|
for range ticker.C {
|
||||||
@@ -134,6 +132,21 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// Read incoming RTCP packets
|
||||||
|
// Before these packets are returned they are processed by interceptors. For things
|
||||||
|
// like TWCC and RTCP Reports this needs to be called.
|
||||||
|
go func() {
|
||||||
|
rtcpBuf := make([]byte, 1500)
|
||||||
|
for {
|
||||||
|
if _, _, rtcpErr := receiver.Read(rtcpBuf); rtcpErr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Start reading from all the streams and sending them to the related output track
|
||||||
|
rid := track.RID()
|
||||||
for {
|
for {
|
||||||
// Read RTP packets being sent to Pion
|
// Read RTP packets being sent to Pion
|
||||||
packet, _, readErr := track.ReadRTP()
|
packet, _, readErr := track.ReadRTP()
|
||||||
|
@@ -80,6 +80,18 @@ func main() { // nolint:gocognit
|
|||||||
|
|
||||||
// Set a handler for when a new remote track starts
|
// Set a handler for when a new remote track starts
|
||||||
peerConnection.OnTrack(func(track *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) {
|
peerConnection.OnTrack(func(track *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) {
|
||||||
|
// Read incoming RTCP packets
|
||||||
|
// Before these packets are returned they are processed by interceptors. For things
|
||||||
|
// like TWCC and RTCP Reports this needs to be called.
|
||||||
|
go func() {
|
||||||
|
rtcpBuf := make([]byte, 1500)
|
||||||
|
for {
|
||||||
|
if _, _, rtcpErr := receiver.Read(rtcpBuf); rtcpErr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
fmt.Printf("Track has started, of type %d: %s \n", track.PayloadType(), track.Codec().MimeType)
|
fmt.Printf("Track has started, of type %d: %s \n", track.PayloadType(), track.Codec().MimeType)
|
||||||
trackNum := trackCount
|
trackNum := trackCount
|
||||||
trackCount++
|
trackCount++
|
||||||
|
Reference in New Issue
Block a user