revid/geovision.go: wrote Stop method implementation

This commit is contained in:
Saxon 2019-11-04 19:27:05 +10:30
parent 1497f4a575
commit ce8dc9a4b3
2 changed files with 40 additions and 30 deletions

View File

@ -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 <saxon@ausocean.org>
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")*/

View File

@ -6,7 +6,7 @@ AUTHORS
Saxon A. Nelson-Milton <saxon@ausocean.org>
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