(peerConnection *webrtc.PeerConnection)
| 293 | } |
| 294 | |
| 295 | func setupMediaForwarding(peerConnection *webrtc.PeerConnection) (*udpConn, *udpConn) { |
| 296 | |
| 297 | // Prepare udp conns |
| 298 | // Also update incoming packets with expected PayloadType, the browser may use |
| 299 | // a different value. We have to modify so our stream matches what rtp-forwarder.sdp expects |
| 300 | videoUDPConn, err := createUDPConnection(*ForwardingAddress, *RTPVideoForwardingPort, uint8(*RTPVideoPayloadType)) |
| 301 | |
| 302 | if err != nil { |
| 303 | log.Println(fmt.Sprintf("Error creating udp connection for video: " + err.Error())) |
| 304 | } |
| 305 | |
| 306 | audioUDPConn, err := createUDPConnection(*ForwardingAddress, *RTPAudioForwardingPort, uint8(*RTPAudioPayloadType)) |
| 307 | |
| 308 | if err != nil { |
| 309 | log.Println(fmt.Sprintf("Error creating udp connection for audio: " + err.Error())) |
| 310 | } |
| 311 | |
| 312 | peerConnection.OnTrack(func(track *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) { |
| 313 | |
| 314 | var trackType string = track.Kind().String() |
| 315 | fmt.Println(fmt.Sprintf("Got %s track from Unreal Engine Pixel Streaming WebRTC.", trackType)) |
| 316 | |
| 317 | var udpConnection *udpConn |
| 318 | switch trackType { |
| 319 | case "audio": |
| 320 | udpConnection = audioUDPConn |
| 321 | case "video": |
| 322 | udpConnection = videoUDPConn |
| 323 | default: |
| 324 | log.Println(fmt.Sprintf("Unsupported track type from Unreal Engine, track type: %s", trackType)) |
| 325 | } |
| 326 | |
| 327 | // Send RTCP message on an interval to the UE side. a PLI on an interval so that the publisher is pushing a keyframe every rtcpPLIInterval |
| 328 | go func() { |
| 329 | ticker := time.NewTicker(time.Millisecond * 2000) |
| 330 | for range ticker.C { |
| 331 | |
| 332 | // Send PLI (picture loss indicator) |
| 333 | if *RTCPSendPLI { |
| 334 | if rtcpErr := peerConnection.WriteRTCP([]rtcp.Packet{&rtcp.PictureLossIndication{MediaSSRC: uint32(track.SSRC())}}); rtcpErr != nil { |
| 335 | fmt.Println(rtcpErr) |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | // Send REMB (receiver-side estimated maximum bandwidth) |
| 340 | if *RTCPSendREMB { |
| 341 | if rtcpErr := peerConnection.WriteRTCP([]rtcp.Packet{&rtcp.ReceiverEstimatedMaximumBitrate{Bitrate: *REMB, SSRCs: []uint32{uint32(track.SSRC())}}}); rtcpErr != nil { |
| 342 | fmt.Println(rtcpErr) |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | }() |
| 347 | |
| 348 | b := make([]byte, 1500) |
| 349 | rtpPacket := &rtp.Packet{} |
| 350 | for { |
| 351 | // Read |
| 352 | n, _, readErr := track.Read(b) |
no test coverage detected