cam

package module
v0.0.0-...-f29cad3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2016 License: MIT Imports: 10 Imported by: 4

README

cam

Cam is a package for connecting to and streaming data from mjpeg-cameras in Go.

build status Coverage Status godoc reference go report card

Example

import (
  "fmt"
  "ioutil"

  "github.com/mmaelzer/cam"
)

func main() {
  camera := cam.Camera{
    URL: "http://64.122.208.241:8000/axis-cgi/mjpg/video.cgi?resolution=320x240"
  }

  frames, err := camera.Subscribe()
  if err != nil {
    panic(err)
  }

  for frame := range frames {
    filename := fmt.Sprintf("%d.jpeg", frame.Timestamp.UnixNano())
    ioutil.WriteFile(filename, frame.Bytes, 0644)
  }
}

Usage

type Camera
type Camera struct {
	Name     string // name of the camera; name will be passed along with frames
	URL      string // url of the camera
	Username string // optional username for basic authentication
	Password string // optional password for basic authentication
}

A Camera is a set of configuration data for an mjpeg camera

func (*Camera) Subscribe
func (cam *Camera) Subscribe() (<-chan Frame, error)

Subscribe creates a new channel that receives Frames. To unsubscribe, pass the returned channel to the Unsubscribe method.

func (*Camera) Unsubscribe
func (cam *Camera) Unsubscribe(unsub <-chan Frame) bool

Unsubscribe removes a channel returned from a Subscribe call from the list of cam listeners. Unsubscribe returns a boolean value of whether the channel was found and removed from the listeners.

type Frame
type Frame struct {
	CameraName string    // the source of frame
	Number     uint64    // a monotomically incremented frame count
	Timestamp  time.Time // time the frame was received
	Bytes      []byte    // jpeg data
}

A Frame is a container for jpeg data from a Camera

The MIT License

Copyright (c) 2015 Michael Maelzer

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Overview

Package cam provides a mjpeg camera client that allows for pipelining streams of jpeg data

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Camera

type Camera struct {
	Name      string // name of the camera; name will be passed along with frames
	URL       string // url of the camera
	Username  string // optional username for basic authentication
	Password  string // optional password for basic authentication
	Log       bool   // should log
	LastFrame *Frame
	Reconnect bool // should automatically retry
	// contains filtered or unexported fields
}

A Camera is a set of configuration data for an mjpeg camera

func (*Camera) Stop

func (cam *Camera) Stop()

Stop closes the camera connection and removes all listeners

func (*Camera) Subscribe

func (cam *Camera) Subscribe() (<-chan Frame, error)

Subscribe creates a new channel that receives Frames. To unsubscribe, pass the returned channel to the Unsubscribe method.

func (*Camera) Unsubscribe

func (cam *Camera) Unsubscribe(unsub <-chan Frame) bool

Unsubscribe removes a channel returned from a Subscribe call from the list of cam listeners. Unsubscribe returns a boolean value of whether the channel was found and removed from the listeners.

type Frame

type Frame struct {
	CameraName string    // the source of frame
	Number     uint64    // a monotomically incremented frame count
	Timestamp  time.Time // time the frame was received
	Bytes      []byte    // jpeg data
}

A Frame is a container for jpeg data from a Camera

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL