Documentation
¶
Index ¶
- Variables
- type Camera
- func (c *Camera) GetJPEG(ops *VidOps) (image.Image, error)
- func (c *Camera) PostG711(audio io.ReadCloser) error
- func (c *Camera) SaveJPEG(ops *VidOps, path string) error
- func (c *Camera) SaveVideo(ops *VidOps, length time.Duration, maxsize int64, outputFile string) error
- func (c *Camera) SetSchedule(mode CameraMode, scheduleID int) error
- func (c *Camera) SetScheduleOverride(mode CameraMode, overrideID int) error
- func (c *Camera) StreamG711() (io.ReadCloser, error)
- func (c *Camera) StreamH264(ops *VidOps) (io.ReadCloser, error)
- func (c *Camera) StreamMJPG(ops *VidOps) (io.ReadCloser, error)
- func (c *Camera) StreamVideo(ops *VidOps, length time.Duration, maxsize int64) (io.ReadCloser, error)
- func (c *Camera) ToggleActions(arm CameraArmMode) error
- func (c *Camera) ToggleContinuous(arm CameraArmMode) error
- func (c *Camera) ToggleMotion(arm CameraArmMode) error
- func (c *Camera) TriggerMotion() error
- type CameraArmMode
- type CameraMode
- type CameraSchedule
- type Cameras
- type Duration
- type Event
- type EventType
- type Events
- func (e *Events) BindChan(event EventType, channel chan Event)
- func (e *Events) BindFunc(event EventType, callBack func(Event))
- func (e *Events) Custom(cameraNum int, msg string)
- func (e *Events) Stop()
- func (e *Events) UnbindAll()
- func (e *Events) UnbindChan(event EventType)
- func (e *Events) UnbindFunc(event EventType)
- func (e *Events) Watch(retryInterval time.Duration, refreshOnConfigChange bool)
- type File
- type Files
- func (f *Files) GetAll(cameraNums []int, from, to time.Time) ([]*File, error)
- func (f *Files) GetCCVideos(cameraNums []int, from, to time.Time) ([]*File, error)
- func (f *Files) GetFile(name string) (*File, error)
- func (f *Files) GetImages(cameraNums []int, from, to time.Time) ([]*File, error)
- func (f *Files) GetMCVideos(cameraNums []int, from, to time.Time) ([]*File, error)
- type PTZ
- func (z *PTZ) Down() error
- func (z *PTZ) DownLeft() error
- func (z *PTZ) DownRight() error
- func (z *PTZ) Home() error
- func (z *PTZ) Left() error
- func (z *PTZ) Preset(preset PTZpreset) error
- func (z *PTZ) PresetSave(preset PTZpreset) error
- func (z *PTZ) Right() error
- func (z *PTZ) Stop() error
- func (z *PTZ) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- func (z *PTZ) Up() error
- func (z *PTZ) UpLeft() error
- func (z *PTZ) UpRight() error
- func (z *PTZ) Zoom(in bool) error
- type PTZpreset
- type Server
- type ServerInfo
- type VidOps
- type YesNoBool
Constants ¶
This section is empty.
Variables ¶
var ( // ErrorUnknownEvent never really returns, but will fire if SecuritySpy // adds new events this library doesn't know about. ErrorUnknownEvent = errors.New("unknown event") // ErrorCAMParseFail will return if the camera number in an event stream does not exist. // If you see this, run Refresh() more often, or fix your flaky camera connection. ErrorCAMParseFail = errors.New("CAM parse failed") // ErrorIDParseFail will return if the camera number provided by the event stream is not a number. // This should never happen, but future versions of SecuritySpy could trigger this if formats change. ErrorIDParseFail = errors.New("ID parse failed") // ErrorCAMMissing like the errors above should never return. // This is triggered by a corrupted event format. ErrorCAMMissing = errors.New("CAM missing") // ErrorDateParseFail will only trigger if the time stamp format for events changes. ErrorDateParseFail = errors.New("timestamp parse failed") // ErrorDisconnect becomes the msg in a custom event when the SecSpy event stream is disconnected. ErrorDisconnect = errors.New("event stream disconnected") )
var ( // ErrorPathExists returns when a requested write path already exists. ErrorPathExists = errors.New("cannot overwrite existing path") // ErrorInvalidName returns when requesting a file download and the filename is invalid. ErrorInvalidName = errors.New("invalid file name") )
var ( // ErrorPTZNotOK is returned for any command that has a successful web request, // but the reply does not end with the word OK. ErrorPTZNotOK = errors.New("PTZ command not OK") // ErrorPTZRange returns when a PTZ preset outside of 1-8 is provided. ErrorPTZRange = errors.New("PTZ preset out of range 1-8") )
var ( // ErrorCmdNotOK is returned for any command that has a successful web request, // but the reply does not end with the word OK. ErrorCmdNotOK = errors.New("command unsuccessful") // DefaultTimeout it used for almost every request to SecuritySpy. Adjust as needed. DefaultTimeout = 10 * time.Second )
var Encoder = "/usr/local/bin/ffmpeg"
Encoder is the path to ffmpeg.
Functions ¶
This section is empty.
Types ¶
type Camera ¶
type Camera struct {
Number int `xml:"number"` // 0, 1, 2, 3, 4, 5, 6
Connected YesNoBool `xml:"connected"` // yes, yes, yes, yes, yes, ...
Width int `xml:"width"` // 2560, 2592, 2592, 3072, 2...
Height int `xml:"height"` // 1440, 1520, 1520, 2048, 1...
Mode YesNoBool `xml:"mode"` // active, active, active, a...
ModeC YesNoBool `xml:"mode-c"` // armed, armed, armed, arme...
ModeM YesNoBool `xml:"mode-m"` // armed, armed, armed, arme...
ModeA YesNoBool `xml:"mode-a"` // armed, armed, armed, arme...
HasAudio YesNoBool `xml:"hasaudio"` // yes, yes, no, yes, yes, y...
PTZ *PTZ `xml:"ptzcapabilities"` // 0, 0, 31, 0, 0, 0, 0
TimeSinceLastFrame Duration `xml:"timesincelastframe"` // 0, 0, 0, 0, 0, 0, 0
TimeSinceLastMotion Duration `xml:"timesincelastmotion"` // 689, 3796, 201, 12477, 15...
DeviceName string `xml:"devicename"` // ONVIF, ONVIF, ONVIF, ONVI...
DeviceType string `xml:"devicetype"` // Network, Network, Network...
Address string `xml:"address"` // 192.168.69.12, 192.168.69...
Port int `xml:"port"` // 80, 80, 80, 0=80
PortRTSP int `xml:"port-rtsp"` // 554, 0=554
Request string `xml:"request"` // /some/rtsp/math (manual only)
Name string `xml:"name"` // Porch, Door, Road, Garage...
Overlay YesNoBool `xml:"overlay"` // no, no, no, no, no, no, n...
OverlayText string `xml:"overlaytext"` // +d, +d, +d, +d, +d, +d, +...
Transformation int `xml:"transformation"` // 0, 1, 2, 3, 4, 5
AudioNetwork YesNoBool `xml:"audio_network"` // yes, yes, yes, yes, yes, ...
AudioDeviceName string `xml:"audio_devicename"` // Another Camera
MDenabled YesNoBool `xml:"md_enabled"` // yes, yes, yes, yes, yes, ...
MDsensitivity int `xml:"md_sensitivity"` // 51, 50, 47, 50, 50, 50, 5...
MDtriggerTimeX2 Duration `xml:"md_triggertime_x2"` // 2, 2, 1, 2, 2, 2, 2
MDcapture YesNoBool `xml:"md_capture"` // yes, yes, yes, yes, yes, ...
MDcaptureFPS float64 `xml:"md_capturefps"` // 20, 20, 20, 20, 20, 20, 2...
MDpreCapture Duration `xml:"md_precapture"` // 3, 4, 3, 3, 3, 2, 0
MDpostCapture Duration `xml:"md_postcapture"` // 10, 5, 5, 5, 5, 20, 15
MDcaptureImages YesNoBool `xml:"md_captureimages"` // no, no, no, no, no, no, n...
MDuploadImages YesNoBool `xml:"md_uploadimages"` // no, no, no, no, no, no, n...
MDeecordAudio YesNoBool `xml:"md_recordaudio"` // yes, yes, yes, yes, yes, ...
MDaudioTrigger YesNoBool `xml:"md_audiotrigger"` // no, no, no, no, no, no, n...
MDaudioThreshold int `xml:"md_audiothreshold"` // 50, 50, 50, 50, 50, 50, 5...
ActionScriptName string `xml:"action_scriptname"` // SS_SendiMessages.scpt, SS...
ActionSoundName string `xml:"action_soundname"` // sound_file_name
ActionResetTime Duration `xml:"action_resettime"` // 60, 60, 60, 60, 60, 60, 4...
TLcapture YesNoBool `xml:"tl_capture"` // no, no, no, no, no, no, n...
TLrecordAudio YesNoBool `xml:"tl_recordaudio"` // yes, yes, yes, yes, yes, ...
CurrentFPS float64 `xml:"current-fps"` // 20.000, 20.000, 20.000, 2...
ScheduleIDCC CameraSchedule `xml:"schedule-id-cc"` // 1, 1, 1, 1, 1, 1, 0
ScheduleIDMC CameraSchedule `xml:"schedule-id-mc"` // 1, 1, 1, 1, 1, 1, 1
ScheduleIDA CameraSchedule `xml:"schedule-id-a"` // 1, 1, 1, 1, 1, 1, 1
ScheduleOverrideCC CameraSchedule `xml:"schedule-override-cc"` // 0, 0, 0, 0, 0, 0, 0
ScheduleOverrideMC CameraSchedule `xml:"schedule-override-mc"` // 0, 0, 0, 0, 0, 0, 0
ScheduleOverrideA CameraSchedule `xml:"schedule-override-a"` // 0, 0, 0, 0, 0, 0, 0
PresetName1 string `xml:"preset-name-1"`
PresetName2 string `xml:"preset-name-2"`
PresetName3 string `xml:"preset-name-3"`
PresetName4 string `xml:"preset-name-4"`
PresetName5 string `xml:"preset-name-5"`
PresetName6 string `xml:"preset-name-6"`
PresetName7 string `xml:"preset-name-7"`
PresetName8 string `xml:"preset-name-8"`
Permissions int64 `xml:"permissions"` // 63167, 63167, 62975, 6316...
// contains filtered or unexported fields
}
Camera defines the data returned from the SecuritySpy API.
func (*Camera) PostG711 ¶
func (c *Camera) PostG711(audio io.ReadCloser) error
PostG711 makes a POST request to send audio to a camera with a speaker. Accepts an io.ReadCloser that will be closed. Probably an open file. This is untested. Report your success or failure!
func (*Camera) SaveVideo ¶
func (c *Camera) SaveVideo(ops *VidOps, length time.Duration, maxsize int64, outputFile string) error
SaveVideo saves a segment of video from a camera to a file using FFMPEG.
func (*Camera) SetSchedule ¶
func (c *Camera) SetSchedule(mode CameraMode, scheduleID int) error
SetSchedule configures a camera mode's primary schedule. Get a list of schedules/IDs from server.Info.Schedules
func (*Camera) SetScheduleOverride ¶
func (c *Camera) SetScheduleOverride(mode CameraMode, overrideID int) error
SetScheduleOverride temporarily overrides a camera mode's current schedule. Get a list of overrides/IDs from server.Info.ScheduleOverrides
func (*Camera) StreamG711 ¶
func (c *Camera) StreamG711() (io.ReadCloser, error)
StreamG711 makes a web request to retreive an G711 audio stream. Returns an io.ReadCloser that will (hopefully) never end.
func (*Camera) StreamH264 ¶
func (c *Camera) StreamH264(ops *VidOps) (io.ReadCloser, error)
StreamH264 makes a web request to retreive an H264 stream. Returns an io.ReadCloser that will (hopefully) never end.
func (*Camera) StreamMJPG ¶
func (c *Camera) StreamMJPG(ops *VidOps) (io.ReadCloser, error)
StreamMJPG makes a web request to retreive a motion JPEG stream. Returns an io.ReadCloser that will (hopefully) never end.
func (*Camera) StreamVideo ¶
func (c *Camera) StreamVideo(ops *VidOps, length time.Duration, maxsize int64) (io.ReadCloser, error)
StreamVideo streams a segment of video from a camera using FFMPEG.
func (*Camera) ToggleActions ¶
func (c *Camera) ToggleActions(arm CameraArmMode) error
ToggleActions arms (true) or disarms (false).
func (*Camera) ToggleContinuous ¶
func (c *Camera) ToggleContinuous(arm CameraArmMode) error
ToggleContinuous arms (true) or disarms (false).
func (*Camera) ToggleMotion ¶
func (c *Camera) ToggleMotion(arm CameraArmMode) error
ToggleMotion arms (true) or disarms (false).
func (*Camera) TriggerMotion ¶
TriggerMotion sets a camera as currently seeing motion. Other actions likely occur because of this!
type CameraArmMode ¶
type CameraArmMode rune
CameraArmMode locks arming to an integer of 0 or 1.
const ( CameraDisarm CameraArmMode = iota CameraArm )
Arming is either 0 or 1.
type CameraMode ¶
type CameraMode rune
CameraMode is a set of constants to deal with three specific camera modes.
const ( CameraModeAll CameraMode = 'X' CameraModeMotion CameraMode = 'M' CameraModeActions CameraMode = 'A' CameraModeContinuous CameraMode = 'C' )
Camera modes used by Camera scheduling methods.
type CameraSchedule ¶
CameraSchedule contains schedule info for a camera's properties.
func (*CameraSchedule) UnmarshalXML ¶
func (bit *CameraSchedule) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
UnmarshalXML stores a schedule ID into a cameraSchedule type.
type Cameras ¶
Cameras is an interface
type Duration ¶
Duration is used to convert the "Seconnds" given to us by the securityspy API into a go time.Duration.
func (*Duration) UnmarshalXML ¶
UnmarshalXML method converts seconds to time.Duration.
type Event ¶
type Event struct {
Time time.Time // Local time.
When time.Time // Server time.
ID int // Negative numbers are custom events.
Camera *Camera // Each event gets a camera interface.
Type EventType // Event identifier
Msg string // Event Text
Errors []error // Errors populated by parse errors.
}
Event Stream Reply is sent to callback channels and/or functions.
type EventType ¶
type EventType string
EventType is a set of constant strings validated with Event() method
const ( EventArmContinuous EventType = "ARM_C" EventDisarmContinuous EventType = "DISARM_C" EventArmMotion EventType = "ARM_M" EventDisarmMotion EventType = "DISARM_M" EventDisarmActions EventType = "DISARM_A" EventArmActions EventType = "ARM_A" EventSecSpyError EventType = "ERROR" EventConfigChange EventType = "CONFIGCHANGE" EventMotionDetected EventType = "MOTION" EventOnline EventType = "ONLINE" EventOffline EventType = "OFFLINE" // The following belong to the library, not securityspy. EventStreamDisconnect EventType = "DISCONNECTED" EventStreamConnect EventType = "CONNECTED" EventUnknownEvent EventType = "UNKNOWN" EventAllEvents EventType = "ALL" EventWatcherRefreshed EventType = "REFRESH" EventWatcherRefreshFail EventType = "REFRESHFAIL" EventStreamCustom EventType = "CUSTOM" )
Events
type Events ¶
type Events struct {
Running bool
// contains filtered or unexported fields
}
Events is the main Events interface.
func (*Events) UnbindAll ¶
func (e *Events) UnbindAll()
UnbindAll removes all event bindings and channels.
func (*Events) UnbindChan ¶
UnbindChan removes all bound channels for a particular event.
func (*Events) UnbindFunc ¶
UnbindFunc removes all bound callbacks for a particular event.
type File ¶
type File struct {
Title string `xml:"title"` // 01-12-2019 M Gate.m4v, 01...
Link struct {
Rel string `xml:"rel,attr"` // alternate, alternate, alternate
Type string `xml:"type,attr"` // video/quicktime, video/quicktime
Length int64 `xml:"length,attr"` // 358472320, 483306152, 900789978,
HREF string `xml:"href,attr"` // ++getfile/4/2018-10-17/10-17-2018+M+Gate.m4v
} `xml:"link"`
Updated time.Time `xml:"updated"` // 2019-01-12T08:57:58Z, 201...
CameraNum int `xml:"cameraNum"` // 0, 1, 2, 4, 5, 7, 9, 10, 11, 12, 13
GmtOffset time.Duration // the rest are copied in per-file from fileFeed.
Camera *Camera
// contains filtered or unexported fields
}
File represents a saved media file.
type Files ¶
type Files struct {
// contains filtered or unexported fields
}
Files powers the Files interface. It's really an extension of the Server interface.
func (*Files) GetCCVideos ¶
GetCCVideos returns a list of links to continuous-captured videos.
func (*Files) GetFile ¶
GetFile returns a file based on the name. It makes a lot of assumptions about file paths. Not all methods work with this. Avoid it if possible. This allows Get() and Save() to work.
type PTZ ¶
type PTZ struct {
// HasPanTilt is true if a camera can pan and tilt using PTZ controls.
HasPanTilt bool
// HasHome is true if the camera supports the home position PTZ command.
HasHome bool
// HasHome is true if the camera supports zooming in and out.
HasZoom bool
// HasPresets is true when the camera allows user-defined preset positions.
HasPresets bool
// Continuous is true if the camera supports continuous movement. Most cameras
// now days support this. You will need to call Camera.Stop() to stop movement.
Continuous bool
// contains filtered or unexported fields
}
PTZ are what "things" a camera can do.
func (*PTZ) PresetSave ¶
PresetSave instructs a preset to be saved. good luck!
func (*PTZ) Stop ¶
Stop instructs a camera to stop moving. That is, if you have a camera cool enough to support continuous motion. Most do not, so sadly this is unlikely to be useful to you.
func (*PTZ) UnmarshalXML ¶
UnmarshalXML method converts ptzCapbilities bitmask into true/false abilities.
type PTZpreset ¶
type PTZpreset rune
PTZpreset locks our poresets to a max of 8
const ( PTZpreset1 PTZpreset PTZpreset2 PTZpreset3 PTZpreset4 PTZpreset5 PTZpreset6 PTZpreset7 PTZpreset8 )
Presets are 1 through 8.
type Server ¶
type Server struct {
Files *Files
Events *Events
Cameras *Cameras
Info *ServerInfo
// contains filtered or unexported fields
}
Server is the main interface for this library. Contains sub-interfaces for cameras, ptz, files & events
func GetServer ¶
GetServer returns an iterface to interact with SecuritySpy. This is the only exportred function in the library. All of the other interfaces are accessed through this interface.
func (*Server) GetScripts ¶
GetScripts fetches and returns the list of script files. You can't do much with these.
func (*Server) GetSounds ¶
GetSounds fetches and returns the list of sound files. You can't do much with these.
type ServerInfo ¶
type ServerInfo struct {
Name string `xml:"name"` // SecuritySpy
Version string `xml:"version"` // 4.2.9
UUID string `xml:"uuid"` // C03L1333F8J3AkXIZS1O
EventStreamCount int64 `xml:"eventstreamcount"` // 99270
DDNSName string `xml:"ddns-name"` // domain.name.dyn
WanAddress string `xml:"wan-address"` // domain.name
ServerName string `xml:"server-name"`
BonjourName string `xml:"bonjour-name"`
IP1 string `xml:"ip1"` // 192.168.3.1
IP2 string `xml:"ip2"` // 192.168.69.3
HTTPEnabled YesNoBool `xml:"http-enabled"` // yes
HTTPPort int `xml:"http-port"` // 8000
HTTPPortWan int `xml:"http-port-wan"` // 8000
HTTPSEnabled YesNoBool `xml:"https-enabled"` // no
HTTPSPort int `xml:"https-port"` // 8001
HTTPSPortWan int `xml:"https-port-wan"` // 8001
CurrentTime time.Time `xml:"current-local-time"`
GmtOffset Duration `xml:"seconds-from-gmt"`
DateFormat string `xml:"date-format"`
TimeFormat string `xml:"time-format"`
// These are all copied in by Refresh()
Refreshed time.Time
ServerSchedules map[int]string
SchedulePresets map[int]string
ScheduleOverrides map[int]string
// If there is a chance of calling Refresh() while reading these maps, lock them.
sync.RWMutex
}
ServerInfo represents all the SecuritySpy server's information.
type YesNoBool ¶
YesNoBool is used to capture strings into boolean format.
func (*YesNoBool) UnmarshalXML ¶
UnmarshalXML method converts armed/disarmed, yes/no, active/inactive or 0/1 to true/false. Really it converts armed, yes, active, enabled, 1, true to true. Anything else is false.