From 1059b5e738c68a042ca8bd14f333f10b585dd832 Mon Sep 17 00:00:00 2001 From: Saxon Date: Tue, 14 May 2019 11:47:18 +0930 Subject: [PATCH] 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. --- revid/config.go | 3 +++ revid/revid.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/revid/config.go b/revid/config.go index 010af3fd..72400c60 100644 --- a/revid/config.go +++ b/revid/config.go @@ -74,6 +74,9 @@ type Config struct { Saturation int Exposure string AutoWhiteBalance string + RTSPURL string + RTPRecvAddr string + RTCPAddr string } // Possible modes for raspivid --exposure parameter. diff --git a/revid/revid.go b/revid/revid.go index 43c4f982..25453257 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -43,6 +43,8 @@ import ( "bitbucket.org/ausocean/av/codec/lex" "bitbucket.org/ausocean/av/container/flv" "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/utils/ioext" "bitbucket.org/ausocean/utils/logger" @@ -604,6 +606,48 @@ func (r *Revid) setupInputForFile() (func() error, error) { 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) { r.config.Logger.Log(logger.Info, pkg+"reading input data") r.err <- r.lexTo(r.encoders, read, delay)