mirror of https://bitbucket.org/ausocean/av.git
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.
This commit is contained in:
parent
83122d0ac5
commit
6b9f552610
|
@ -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 {
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue