mirror of https://bitbucket.org/ausocean/av.git
105 lines
2.4 KiB
Go
105 lines
2.4 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"flag"
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"net"
|
|
"time"
|
|
|
|
"../packet"
|
|
|
|
"github.com/beatgammit/rtsp"
|
|
)
|
|
|
|
func init() {
|
|
flag.Parse()
|
|
}
|
|
|
|
func main() {
|
|
if len(flag.Args()) >= 1 {
|
|
rtspUrl := flag.Args()[0]
|
|
rtpUrl := flag.Args()[1]
|
|
|
|
sess := rtsp.NewSession()
|
|
res, err := sess.Options(rtspUrl)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
fmt.Println("Options:")
|
|
fmt.Println(res)
|
|
|
|
res, err = sess.Describe(rtspUrl)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
fmt.Println("Describe:")
|
|
fmt.Println(res)
|
|
|
|
p, err := rtsp.ParseSdp(&io.LimitedReader{R: res.Body, N: res.ContentLength})
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
log.Printf("%+v", p)
|
|
|
|
fmt.Println("Setting up!")
|
|
rtpPort, rtcpPort := 17300, 17319
|
|
res, err = sess.Setup(rtpUrl, fmt.Sprintf("RTP/AVP;unicast;client_port=%d-%d", rtpPort, rtcpPort))
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
log.Println(res)
|
|
|
|
fmt.Println("Playing !")
|
|
res, err = sess.Play(rtspUrl, res.Header.Get("Session"))
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
log.Println(res)
|
|
|
|
// create udp connection for rtp stuff
|
|
rtpLaddr, err := net.ResolveUDPAddr("udp", "192.168.0.109:17300")
|
|
if err != nil {
|
|
fmt.Println("Local rtp addr not set!")
|
|
}
|
|
rtpAddr, err := net.ResolveUDPAddr("udp", "192.168.0.50:17300")
|
|
if err != nil {
|
|
fmt.Println("Resolving rtp address didn't work!")
|
|
}
|
|
rtpConn, err := net.DialUDP("udp", rtpLaddr, rtpAddr)
|
|
if err != nil {
|
|
fmt.Println("Rtp dial didn't work!")
|
|
}
|
|
|
|
// Create udp connection for rtcp stuff
|
|
rtcpLaddr, err := net.ResolveUDPAddr("udp", "192.168.0.109:17319")
|
|
if err != nil {
|
|
fmt.Println("Local ")
|
|
}
|
|
rtcpAddr, err := net.ResolveUDPAddr("udp", "192.168.0.50:17301")
|
|
if err != nil {
|
|
fmt.Println("resolving rtcp address didn't work!")
|
|
}
|
|
rtcpConn, err := net.DialUDP("udp", rtcpLaddr, rtcpAddr)
|
|
if err != nil {
|
|
fmt.Println("Rtcp dial didnt't work!")
|
|
}
|
|
|
|
// let's create a session that will store useful stuff from the connections
|
|
rtpSession := rtp.New(rtpConn, rtcpConn)
|
|
|
|
|
|
// Loop here until we get something in the channels
|
|
for {
|
|
fmt.Printf("Length of rtpChan: %v\n", len(rtpSession.RtpChan))
|
|
time.Sleep(1 * time.Second)
|
|
select {
|
|
case rtpPacket := <-rtpSession.RtpChan:
|
|
default:
|
|
}
|
|
}
|
|
}
|
|
}
|