Beispiel #1
0
func simpleRtp() {
	fmt.Println("Starting simple RTP test.")

	// Create a UDP transport with "local" address and use this for a "local" RTP session
	// The RTP session uses the transport to receive and send RTP packets to the remote peer.
	tpLocal, _ := rtp.NewTransportUDP(local, localPort)

	// TransportUDP implements TransportWrite and TransportRecv interfaces thus
	// use it to initialize the Session for both interfaces.
	rsLocal = rtp.NewSession(tpLocal, tpLocal)

	// Add address of a remote peer (participant)
	rsLocal.AddRemote(&rtp.Address{remote.IP, remotePort, remotePort + 1})

	// Create a media stream.
	// The SSRC identifies the stream. Each stream has its own sequence number and other
	// context. A RTP session can have several RTP stream for example to send several
	// streams of the same media.
	//
	strLocalIdx, _ := rsLocal.NewSsrcStreamOut(&rtp.Address{local.IP, localPort, localPort + 1}, 1020304, 4711)
	rsLocal.SsrcStreamOutForIndex(strLocalIdx).SetPayloadType(0)

	// Create the same set for a "remote" peer and use the "local" as its remote peer.
	tpRemote, _ := rtp.NewTransportUDP(remote, remotePort)
	rsRemote = rtp.NewSession(tpRemote, tpRemote)
	rsRemote.AddRemote(&rtp.Address{local.IP, localPort, localPort + 1})

	strRemoteIdx, _ := rsRemote.NewSsrcStreamOut(&rtp.Address{remote.IP, remotePort, remotePort + 1}, 4030201, 815)
	rsRemote.SsrcStreamOutForIndex(strRemoteIdx).SetPayloadType(0)

	go receivePacketLocal()
	go receivePacketRemote()

	// simple RTP: just listen on the RTP and RTCP receive transports. Do not start Session.
	rsLocal.ListenOnTransports()
	rsRemote.ListenOnTransports()

	// Just connect to control event channel, however in simple RTP mode GoRTP does not report any events.
	go sendLocalToRemote()
	go sendRemoteToLocal()

	time.Sleep(8e9)

	stop = true
	time.Sleep(30e6) // allow the sender to drain

	stopRemoteRecv <- true
	stopLocalRecv <- true
	stopRemoteCtrl <- true
	stopLocalCtrl <- true

	// Just close the receivers, no need to close a session.
	rsLocal.CloseRecv()
	rsRemote.CloseRecv()

	time.Sleep(10e6)

	fmt.Printf("Simple RTP test done.")

}
Beispiel #2
0
func fullDuplex() {
	fmt.Println("Starting full duplex test.")

	// Create a UDP transport with "local" address and use this for a "local" RTP session
	// The RTP session uses the transport to receive and send RTP packets to the remote peer.
	tpLocal, _ := rtp.NewTransportUDP(local, localPort)

	// TransportUDP implements TransportWrite and TransportRecv interfaces thus
	// use it to initialize the Session for both interfaces.
	rsLocal = rtp.NewSession(tpLocal, tpLocal)

	// Add address of a remote peer (participant)
	rsLocal.AddRemote(&rtp.Address{remote.IP, remotePort, remotePort + 1})

	// Create a media stream.
	// The SSRC identifies the stream. Each stream has its own sequence number and other
	// context. A RTP session can have several RTP stream for example to send several
	// streams of the same media.
	//
	strLocalIdx, _ := rsLocal.NewSsrcStreamOut(&rtp.Address{local.IP, localPort, localPort + 1}, 1020304, 4711)
	rsLocal.SsrcStreamOutForIndex(strLocalIdx).SetPayloadType(0)

	// Create the same set for a "remote" peer and use the "local" as its remote peer
	tpRemote, _ := rtp.NewTransportUDP(remote, remotePort)
	rsRemote = rtp.NewSession(tpRemote, tpRemote)
	rsRemote.AddRemote(&rtp.Address{local.IP, localPort, localPort + 1})

	strRemoteIdx, _ := rsRemote.NewSsrcStreamOut(&rtp.Address{remote.IP, remotePort, remotePort + 1}, 4030201, 815)
	rsRemote.SsrcStreamOutForIndex(strRemoteIdx).SetPayloadType(0)

	go receivePacketLocal()
	go receivePacketRemote()

	go receiveCtrlLocal()
	go receiveCtrlRemote()

	rsLocal.StartSession()
	rsRemote.StartSession()

	go sendLocalToRemote()
	go sendRemoteToLocal()

	time.Sleep(8e9)

	stop = true
	time.Sleep(30e6) // allow the sender to drain

	stopRemoteRecv <- true
	stopLocalRecv <- true
	stopRemoteCtrl <- true
	stopLocalCtrl <- true

	rsLocal.CloseSession()
	rsRemote.CloseSession()

	time.Sleep(10e6)

	fmt.Println("Full duplex test done.")
}
Beispiel #3
0
func main() {
	tpLocal, _ := rtp.NewTransportUDP(local, localPort)
	rsLocal = rtp.NewSession(tpLocal, tpLocal)

	rsLocal.ListenOnTransports()
	go receivePacketLocal()

	time.Sleep(8e9)
}