From ce8dc9a4b3e843c9f4e3869e917fc623fcc641d6 Mon Sep 17 00:00:00 2001 From: Saxon Date: Mon, 4 Nov 2019 19:27:05 +1030 Subject: [PATCH] revid/geovision.go: wrote Stop method implementation --- revid/geovision.go | 68 ++++++++++++++++++++++++++-------------------- revid/raspivid.go | 2 +- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/revid/geovision.go b/revid/geovision.go index de029e7c..708d8e51 100644 --- a/revid/geovision.go +++ b/revid/geovision.go @@ -1,12 +1,13 @@ /* DESCRIPTION - geovision.go + geovision.go provides an implementation of the AVDevice interface for the + GeoVision IP camera. AUTHORS Saxon A. Nelson-Milton LICENSE - Copyright (C) 2017-2019 the Australian Ocean Lab (AusOcean) + Copyright (C) 2019 the Australian Ocean Lab (AusOcean) It is free software: you can redistribute it and/or modify them under the terms of the GNU General Public License as published by the @@ -27,6 +28,7 @@ package revid import ( "errors" "fmt" + "net" "time" "bitbucket.org/ausocean/av/codec/codecutil" @@ -59,8 +61,11 @@ var ( ) type GeoVision struct { - cfg Config - log Logger + cfg Config + log Logger + rtpClt *rtp.Client + rtspClt *rtsp.Client + rtcpClt *rtcp.Client } func NewGeovision(l Logger) *GeoVision { return &GeoVision{log: l} } @@ -156,26 +161,31 @@ func (g *GeoVision) Set(c Config) error { } func (g *GeoVision) Start() error { - rtspClt, local, remote, err := rtsp.NewClient("rtsp://" + ipCamUser + ":" + ipCamPass + "@" + g.cfg.CameraIP + ":8554/" + "CH002.sdp") + var ( + local, remote *net.TCPAddr + err error + ) + + g.rtspClt, local, remote, err = rtsp.NewClient("rtsp://" + ipCamUser + ":" + ipCamPass + "@" + g.cfg.CameraIP + ":8554/" + "CH002.sdp") if err != nil { return fmt.Errorf("could not create RTSP client: %w", err) } g.log.Log(logger.Info, pkg+"created RTSP client") - resp, err := rtspClt.Options() + resp, err := g.rtspClt.Options() if err != nil { return fmt.Errorf("options request unsuccessful: %w", err) } g.log.Log(logger.Debug, pkg+"RTSP OPTIONS response", "response", resp.String()) - resp, err = rtspClt.Describe() + resp, err = g.rtspClt.Describe() if err != nil { return fmt.Errorf("describe request unsuccessful: %w", err) } g.log.Log(logger.Debug, pkg+"RTSP DESCRIBE response", "response", resp.String()) - resp, err = rtspClt.Setup("track1", fmt.Sprintf("RTP/AVP;unicast;client_port=%d-%d", rtpPort, rtcpPort)) + resp, err = g.rtspClt.Setup("track1", fmt.Sprintf("RTP/AVP;unicast;client_port=%d-%d", rtpPort, rtcpPort)) if err != nil { return fmt.Errorf("setup request unsuccessful: %w", err) } @@ -188,12 +198,12 @@ func (g *GeoVision) Start() error { g.log.Log(logger.Info, pkg+"RTSP session setup complete") - rtpClt, err := rtp.NewClient(rtpCltAddr) + g.rtpClt, err = rtp.NewClient(rtpCltAddr) if err != nil { return fmt.Errorf("could not create RTP client: %w", err) } - rtcpClt, err := rtcp.NewClient(rtcpCltAddr, rtcpSvrAddr, rtpClt, g.log.Log) + g.rtcpClt, err = rtcp.NewClient(rtcpCltAddr, rtcpSvrAddr, g.rtpClt, g.log.Log) if err != nil { return fmt.Errorf("could not create RTCP client: %w", err) } @@ -203,7 +213,7 @@ func (g *GeoVision) Start() error { // Check errors from RTCP client until it has stopped running. go func() { for { - err, ok := <-rtcpClt.Err() + err, ok := <-g.rtcpClt.Err() if ok { g.log.Log(logger.Warning, pkg+"RTCP error", "error", err.Error()) } else { @@ -213,13 +223,10 @@ func (g *GeoVision) Start() error { }() // Start the RTCP client. - rtcpClt.Start() - + g.rtcpClt.Start() g.log.Log(logger.Info, pkg+"RTCP client started") - g.log.Log(logger.Info, pkg+"started input processor") - - resp, err = rtspClt.Play() + resp, err = g.rtspClt.Play() if err != nil { return fmt.Errorf("play request unsuccessful: %w", err) } @@ -229,17 +236,20 @@ func (g *GeoVision) Start() error { return nil } -/* -err := rtpClt.Close() -if err != nil { - return fmt.Errorf("could not close RTP client: %w", err) +func (g *GeoVision) Stop() error { + err := g.rtpClt.Close() + if err != nil { + return fmt.Errorf("could not close RTP client: %w", err) + } + + err = g.rtspClt.Close() + if err != nil { + return fmt.Errorf("could not close RTSP client: %w", err) + } + + g.rtcpClt.Stop() + + g.log.Log(logger.Info, pkg+"RTP, RTSP and RTCP clients stopped and closed") + + return nil } - -err = rtspClt.Close() -if err != nil { - return fmt.Errorf("could not close RTSP client: %w", err) -} - -rtcpClt.Stop() - -g.log.Log(logger.Info, pkg+"RTP, RTSP and RTCP clients stopped and closed")*/ diff --git a/revid/raspivid.go b/revid/raspivid.go index d28f521f..8e57202e 100644 --- a/revid/raspivid.go +++ b/revid/raspivid.go @@ -6,7 +6,7 @@ AUTHORS Saxon A. Nelson-Milton LICENSE - Copyright (C) 2017-2019 the Australian Ocean Lab (AusOcean) + Copyright (C) 2019 the Australian Ocean Lab (AusOcean) It is free software: you can redistribute it and/or modify them under the terms of the GNU General Public License as published by the