mirror of https://bitbucket.org/ausocean/av.git
revid/geovision.go: wrote Stop method implementation
This commit is contained in:
parent
1497f4a575
commit
ce8dc9a4b3
|
@ -1,12 +1,13 @@
|
||||||
/*
|
/*
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
geovision.go
|
geovision.go provides an implementation of the AVDevice interface for the
|
||||||
|
GeoVision IP camera.
|
||||||
|
|
||||||
AUTHORS
|
AUTHORS
|
||||||
Saxon A. Nelson-Milton <saxon@ausocean.org>
|
Saxon A. Nelson-Milton <saxon@ausocean.org>
|
||||||
|
|
||||||
LICENSE
|
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
|
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
|
under the terms of the GNU General Public License as published by the
|
||||||
|
@ -27,6 +28,7 @@ package revid
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"bitbucket.org/ausocean/av/codec/codecutil"
|
"bitbucket.org/ausocean/av/codec/codecutil"
|
||||||
|
@ -61,6 +63,9 @@ var (
|
||||||
type GeoVision struct {
|
type GeoVision struct {
|
||||||
cfg Config
|
cfg Config
|
||||||
log Logger
|
log Logger
|
||||||
|
rtpClt *rtp.Client
|
||||||
|
rtspClt *rtsp.Client
|
||||||
|
rtcpClt *rtcp.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGeovision(l Logger) *GeoVision { return &GeoVision{log: l} }
|
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 {
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("could not create RTSP client: %w", err)
|
return fmt.Errorf("could not create RTSP client: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
g.log.Log(logger.Info, pkg+"created RTSP client")
|
g.log.Log(logger.Info, pkg+"created RTSP client")
|
||||||
|
|
||||||
resp, err := rtspClt.Options()
|
resp, err := g.rtspClt.Options()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("options request unsuccessful: %w", err)
|
return fmt.Errorf("options request unsuccessful: %w", err)
|
||||||
}
|
}
|
||||||
g.log.Log(logger.Debug, pkg+"RTSP OPTIONS response", "response", resp.String())
|
g.log.Log(logger.Debug, pkg+"RTSP OPTIONS response", "response", resp.String())
|
||||||
|
|
||||||
resp, err = rtspClt.Describe()
|
resp, err = g.rtspClt.Describe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("describe request unsuccessful: %w", err)
|
return fmt.Errorf("describe request unsuccessful: %w", err)
|
||||||
}
|
}
|
||||||
g.log.Log(logger.Debug, pkg+"RTSP DESCRIBE response", "response", resp.String())
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("setup request unsuccessful: %w", err)
|
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")
|
g.log.Log(logger.Info, pkg+"RTSP session setup complete")
|
||||||
|
|
||||||
rtpClt, err := rtp.NewClient(rtpCltAddr)
|
g.rtpClt, err = rtp.NewClient(rtpCltAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not create RTP client: %w", err)
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("could not create RTCP client: %w", err)
|
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.
|
// Check errors from RTCP client until it has stopped running.
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
err, ok := <-rtcpClt.Err()
|
err, ok := <-g.rtcpClt.Err()
|
||||||
if ok {
|
if ok {
|
||||||
g.log.Log(logger.Warning, pkg+"RTCP error", "error", err.Error())
|
g.log.Log(logger.Warning, pkg+"RTCP error", "error", err.Error())
|
||||||
} else {
|
} else {
|
||||||
|
@ -213,13 +223,10 @@ func (g *GeoVision) Start() error {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Start the RTCP client.
|
// Start the RTCP client.
|
||||||
rtcpClt.Start()
|
g.rtcpClt.Start()
|
||||||
|
|
||||||
g.log.Log(logger.Info, pkg+"RTCP client started")
|
g.log.Log(logger.Info, pkg+"RTCP client started")
|
||||||
|
|
||||||
g.log.Log(logger.Info, pkg+"started input processor")
|
resp, err = g.rtspClt.Play()
|
||||||
|
|
||||||
resp, err = rtspClt.Play()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("play request unsuccessful: %w", err)
|
return fmt.Errorf("play request unsuccessful: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -229,17 +236,20 @@ func (g *GeoVision) Start() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
func (g *GeoVision) Stop() error {
|
||||||
err := rtpClt.Close()
|
err := g.rtpClt.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not close RTP client: %w", err)
|
return fmt.Errorf("could not close RTP client: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = rtspClt.Close()
|
err = g.rtspClt.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not close RTSP client: %w", err)
|
return fmt.Errorf("could not close RTSP client: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rtcpClt.Stop()
|
g.rtcpClt.Stop()
|
||||||
|
|
||||||
g.log.Log(logger.Info, pkg+"RTP, RTSP and RTCP clients stopped and closed")*/
|
g.log.Log(logger.Info, pkg+"RTP, RTSP and RTCP clients stopped and closed")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ AUTHORS
|
||||||
Saxon A. Nelson-Milton <saxon@ausocean.org>
|
Saxon A. Nelson-Milton <saxon@ausocean.org>
|
||||||
|
|
||||||
LICENSE
|
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
|
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
|
under the terms of the GNU General Public License as published by the
|
||||||
|
|
Loading…
Reference in New Issue