revid: wrote basics of a startRTSPCamera func

Currently just connecting to RTSP server, requesting OPTIONS, DESCRIBE, SETUP and PLAY. Also creating RTP client and giving
this to process from for the lexer.
This commit is contained in:
Saxon 2019-05-14 11:47:18 +09:30
parent 6b64314d71
commit 1059b5e738
2 changed files with 47 additions and 0 deletions

View File

@ -74,6 +74,9 @@ type Config struct {
Saturation int Saturation int
Exposure string Exposure string
AutoWhiteBalance string AutoWhiteBalance string
RTSPURL string
RTPRecvAddr string
RTCPAddr string
} }
// Possible modes for raspivid --exposure parameter. // Possible modes for raspivid --exposure parameter.

View File

@ -43,6 +43,8 @@ import (
"bitbucket.org/ausocean/av/codec/lex" "bitbucket.org/ausocean/av/codec/lex"
"bitbucket.org/ausocean/av/container/flv" "bitbucket.org/ausocean/av/container/flv"
"bitbucket.org/ausocean/av/container/mts" "bitbucket.org/ausocean/av/container/mts"
"bitbucket.org/ausocean/av/protocol/rtp"
"bitbucket.org/ausocean/av/protocol/rtsp"
"bitbucket.org/ausocean/iot/pi/netsender" "bitbucket.org/ausocean/iot/pi/netsender"
"bitbucket.org/ausocean/utils/ioext" "bitbucket.org/ausocean/utils/ioext"
"bitbucket.org/ausocean/utils/logger" "bitbucket.org/ausocean/utils/logger"
@ -604,6 +606,48 @@ func (r *Revid) setupInputForFile() (func() error, error) {
return func() error { return f.Close() }, nil return func() error { return f.Close() }, nil
} }
func (r *Revid) startRTSPCamera() (func() error, error) {
rtspClt, err := rtsp.NewClient(r.config.RTSPURL)
if err != nil {
return nil, err
}
resp, err := rtspClt.Options()
if err != nil {
return nil, err
}
r.config.Logger.Log(logger.Info, pkg+"RTSP server OPTIONS response", "response", resp.String())
resp, err = rtspClt.Describe()
if err != nil {
return nil, err
}
r.config.Logger.Log(logger.Info, pkg+"RTSP server DESCRIBE response", "response", resp.String())
transport := fmt.Sprintf("RTP/AVP;unicast;client_port=%d-%d", strings.Split(r.config.RTPRecvAddr, ":")[1], strings.Split(r.config.RTCPAddr, ":")[1])
resp, err = rtspClt.Setup("track1", transport)
if err != nil {
return nil, err
}
r.config.Logger.Log(logger.Info, pkg+"RTSP server SETUP response", "response", resp.String())
resp, err = rtspClt.Play()
if err != nil {
return nil, err
}
// TODO(saxon): use rtcp client to maintain rtp stream.
rtpClt, err := rtp.NewClient(r.config.RTPRecvAddr)
if err != nil {
return nil, err
}
r.wg.Add(1)
go r.processFrom(rtpClt, time.Second/time.Duration(r.config.FrameRate))
return func() error { return nil }, nil
}
func (r *Revid) processFrom(read io.Reader, delay time.Duration) { func (r *Revid) processFrom(read io.Reader, delay time.Duration) {
r.config.Logger.Log(logger.Info, pkg+"reading input data") r.config.Logger.Log(logger.Info, pkg+"reading input data")
r.err <- r.lexTo(r.encoders, read, delay) r.err <- r.lexTo(r.encoders, read, delay)