From 6b9f5526103fa37a6a017270deba4ba817b0308a Mon Sep 17 00:00:00 2001 From: Saxon Date: Wed, 10 Apr 2019 13:12:31 +0930 Subject: [PATCH] protocol/rtsp: removed rtsp-util/main.go and create cmd/stream/main.go cmd/stream/main.go will be a simple client that sets up an rtsp connection and asks for the server to stream. --- protocol/rtsp/cmd/stream/main.go | 54 +++++++++++++++++++++ protocol/rtsp/rtsp-util/main.go | 82 -------------------------------- 2 files changed, 54 insertions(+), 82 deletions(-) create mode 100644 protocol/rtsp/cmd/stream/main.go delete mode 100644 protocol/rtsp/rtsp-util/main.go diff --git a/protocol/rtsp/cmd/stream/main.go b/protocol/rtsp/cmd/stream/main.go new file mode 100644 index 00000000..7a9a5d87 --- /dev/null +++ b/protocol/rtsp/cmd/stream/main.go @@ -0,0 +1,54 @@ +package main + +import ( + "flag" + "fmt" + "io" + "log" + + "bitbucket.org/ausocean/av/protocol/rtsp" +) + +func main() { + rtspServerPtr := flag.String("rtsp-server", "", "The RTSP server we would like to get video from") + clientPortPtr := flag.Uint("port", 6870, "The port on the client we would like to receive RTP on") + trackPtr := flag.String("track", "track1", "The track that we would like to receive media from") + flag.Parse() + + sess := rtsp.NewSession() + res, err := sess.Options(*rtspServerPtr) + if err != nil { + log.Fatalln(err) + } + fmt.Println("Options:") + fmt.Println(res) + + res, err = sess.Describe(*rtspServerPtr) + 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) + + res, err = sess.Setup(*rtspServerPtr+"/"+*trackPtr, fmt.Sprintf("RTP/AVP;unicast;client_port=%d-%d", *clientPortPtr, *clientPortPtr+1)) + if err != nil { + log.Fatalln(err) + } + log.Println(res) + + res, err = sess.Play(*rtspServerPtr, res.Header.Get("Session")) + if err != nil { + log.Fatalln(err) + } + log.Println(res) + + // Send back rtcp + for { + } +} diff --git a/protocol/rtsp/rtsp-util/main.go b/protocol/rtsp/rtsp-util/main.go deleted file mode 100644 index 74c92e45..00000000 --- a/protocol/rtsp/rtsp-util/main.go +++ /dev/null @@ -1,82 +0,0 @@ -package main - -import ( - "bytes" - "flag" - "fmt" - "io" - "log" - - "rtsp" -) - -func init() { - flag.Parse() -} - -const sampleRequest = `OPTIONS rtsp://example.com/media.mp4 RTSP/1.0 -CSeq: 1 -Require: implicit-play -Proxy-Require: gzipped-messages - -` - -const sampleResponse = `RTSP/1.0 200 OK -CSeq: 1 -Public: DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE - -` - -func main() { - if len(flag.Args()) >= 1 { - rtspUrl := flag.Args()[0] - - 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) - - rtpPort, rtcpPort := 8000, 8001 - res, err = sess.Setup(rtspUrl, fmt.Sprintf("RTP/AVP;unicast;client_port=%d-%d", rtpPort, rtcpPort)) - if err != nil { - log.Fatalln(err) - } - log.Println(res) - - res, err = sess.Play(rtspUrl, res.Header.Get("Session")) - if err != nil { - log.Fatalln(err) - } - log.Println(res) - } else { - r, err := rtsp.ReadRequest(bytes.NewBufferString(sampleRequest)) - if err != nil { - fmt.Println(err) - } else { - fmt.Println(r) - } - - res, err := rtsp.ReadResponse(bytes.NewBufferString(sampleResponse)) - if err != nil { - fmt.Println(err) - } else { - fmt.Println(res) - } - } -}