sonycrapi

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

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

Go to latest
Published: Aug 24, 2018 License: MIT Imports: 11 Imported by: 5

README

sonycrapi

Sony Camera Remote API

Based off of documentaiton proived by Sony and using the Sony Camera Reomote API.

More information about the API from Sony can be found here.

This has only been tested on my Sony NEX-6, and I cannot make any guarantees about other devices.

Disclaimer: This was developed for so I could build a photbooth to use at my wedding (see examples/photobooth). It worked well, didn't crash, and I got married (yay!), however it does not implment the complete Sony Camera Remote API. I'll hopefully find time to complete the API implementation one day.

Install

go get -u github.com/JamesMcMinn/sonycrapi

Usage

See /examples/ folder for API useage examples.

Features

  • Device Discovery using uPnP
  • Ability to control:
    • Shoot mode (Still, Movie, Audio, InvervalStill, Loop Recording)
    • Still quality (RAW+JPEG, Fine, Standard)
    • PostView size (2MP or Original)
  • Still picture shooting
  • Continious shooting
  • Liveview via websocket (see examples folder for client) or raw JPEG bytestream
  • Event polling

Todo

  • Movie & Audio Recording
  • Loop recording
  • Set camera exposue/WB/Zoom/AF/Timer/Flsh/Program/Scene

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ContinuousShootingModes = struct {
	Single      continuousShootingMode
	Continuous  continuousShootingMode
	SpdPriority continuousShootingMode
	Burst       continuousShootingMode
	MotionShot  continuousShootingMode
}{"Single", "Continuous", "Spd Priority Cont.", "Burst", "MotionShot"}
View Source
var ContinuousShootingSpeeds = struct {
	Hi         continuousShootingSpeed
	Low        continuousShootingSpeed
	TenFPSx1   continuousShootingSpeed
	EightFPSx1 continuousShootingSpeed
	FiveFPSx2  continuousShootingSpeed
	TwoFPSx5   continuousShootingSpeed
}{"Hi", "Low", "10fps 1sec", "8fps 1sec", "5fps 2sec", "2fps 5sec"}
View Source
var LiveviewSizes = struct {
	L LiveviewSize
	M LiveviewSize
}{"L", "M"}

LiveviewSizes is defined as above.

View Source
var PostViewSizes = struct {
	Original PostViewSize // The origianl image size
	TwoM     PostViewSize // A device spcific size, smaller than the original. Often 2 megapixels.
}{"Original", "2M"}

PostViewSizes defined the possible size options for postview images returned by the camera.

View Source
var ShootModes = struct {
	Still         ShootMode // Still image shoot mode
	Movie         ShootMode // Movie shoot mode
	Audio         ShootMode // Audio shoot mode
	IntervalStill ShootMode // Interval still shoot mode
	LoopRec       ShootMode // Loop recording shoot mode
}{"still", "movie", "audio", "intervalstill", "looprec"}

ShootModes defines, at the time of writing, all possible shoot modes supported by the camera API.

View Source
var StillQualities = struct {
	RAWJPG   stillQuality
	Fine     stillQuality
	Standard stillQuality
}{"RAW+JPEG", "Fine", "Standard"}

StillQualities defines the possible qualities that can be passed to the camera.

Functions

This section is empty.

Types

type Camera

type Camera struct {
	ActionListURL string

	// API Versions 1.0
	// 0
	AvailableAPIList []string `json:"names"`

	// 1
	Status string `json:"cameraStatus"`

	// 2
	Zoom struct {
		Position           int `json:"zoomPosition"`
		NumberBox          int `json:"zoomNumberBox"`
		CurrentBox         int `json:"zoomIndexCurrentBox"`
		PositionCurrentBox int `json:"zoomPositionCurrentBox"`
	}

	// 3
	LiveviewStatus bool `json:"liveviewStatus,string"`

	// 4
	LiveviewOrientation string `json:"liveviewOrientation"`

	// 5
	TakePictureURLs []struct {
		URL []string `json:"takePictureUrl"`
	}

	// 10
	Storage []struct {
		ID                       string `json:"storageID"`
		RecordTarget             bool   `json:"recordTarget"`
		NumberOfRecordableImages int    `json:"numberOfRecordableImages"`
		RecordableTime           int    `json:"recordableTime"` // minutes
		Description              string `json:"storageDescription"`
	}

	// 11
	BeepMode struct {
		Current    string   `json:"currentBeepMode"`
		Candidates []string `json:"beepModeCandidates"`
	}

	// 12
	Function struct {
		Current    string   `json:"currentCameraFunction"`
		Candidates []string `json:"cameraFunctionCandidates"`
	}

	// 13
	MovieQuality struct {
		Current    string   `json:"currentMovieQuality"`
		Candidates []string `json:"movieQualityCandidates"`
	}

	// 14
	StillSize struct {
		CheckAvailability bool   `json:"checkAvailability"`
		CurrentAspect     string `json:"currentAspect"`
		CurrentSize       string `json:"currentSize"`
	}

	// 15
	FunctionResult string `json:"cameraFunctionResult"`

	// 16
	SteadyMode struct {
		Current    string   `json:"currentSteadyMode"`
		Candidates []string `json:"steadyModeCandidates"`
	}

	// 17
	ViewAngle struct {
		Current    string   `json:"currentViewAngle"`
		Candidates []string `json:"viewAngleCandidates"`
	}

	// 18
	ExposureMode struct {
		Current    string   `json:"currentExposureMode"`
		Candidates []string `json:"exposureModeCandidates"`
	}

	// 19
	PostviewImageSize struct {
		Current    string   `json:"currentPostviewImageSize"`
		Candidates []string `json:"postviewImageSizeCandidates"`
	}

	// 20
	SelfTimer struct {
		Current    int   `json:"currentSelfTimer"`
		Candidates []int `json:"selfTimerCandidates"`
	}

	// 21
	ShootMode struct {
		Current    string   `json:"currentShootMode"`
		Candidates []string `json:"shootModeCandidates"`
	}

	// 25
	ExposureCompensation struct {
		Current   int `json:"currentExposureCompensation"`
		Max       int `json:"maxExposureCompensation"`
		Min       int `json:"minExposureCompensation"`
		StepIndex int `json:"stepIndexOfExposureCompensation"`
	}

	// 26
	FlashMode struct {
		Current    string   `json:"currentFlashMode"`
		Candidates []string `json:"flashModeCandidates"`
	}

	// 27
	FNumber struct {
		Current    string   `json:"currentFNumber"`
		Candidates []string `json:"fNumberCandidates"`
	}

	// 28
	FocusMode struct {
		Current    string   `json:"currentFocusMode"`
		Candidates []string `json:"focusModeCandidates"`
	}

	// 29
	ISO struct {
		Current    string   `json:"currentIsoSpeedRate"`
		Candidates []string `json:"isoSpeedRateCandidates"`
	}

	// 31
	IsShifted bool `json:"isShifted,string"`

	// 32
	ShutterSpeed struct {
		Current    string   `json:"currentShutterSpeed"`
		Candidates []string `json:"shutterSpeedCandidates"`
	}

	// 33
	WhiteBalance struct {
		CheckAvailability bool   `json:"checkAvailability"`
		Current           string `json:"currentWhiteBalanceMode"`
		ColorTemperature  int    `json:"currentColorTemperature"`
	}

	// 34
	TouchAFPosition struct {
		Set                bool      `json:"currentSet"`
		CurrentCoordinates []float64 `json:"currentTouchCoordinates"`
	}

	// 35
	FocusState string `json:"focusStatus"`

	// 36
	ZoomMode struct {
		Current    string   `json:"zoom"`
		Candidates []string `json:"candidate"`
	}

	// 37
	StillQuality struct {
		Current    string   `json:"stillQuality"`
		Candidates []string `json:"candidate"`
	}

	// 38
	ContinuousShootingMode struct {
		Current    string   `json:"contShootingMode"`
		Candidates []string `json:"candidate"`
	}

	// 39
	ContinuousShootingSpeed struct {
		Current    string   `json:"contShootingSpeed"`
		Candidates []string `json:"candidate"`
	}

	// 40
	ContinuousShootingURL []struct {
		PostviewURL  string `json:"postviewUrl"`
		ThumbnailURL string `json:"thumbnailUrl"`
	}

	// 41
	FlipSetting struct {
		Current    string   `json:"flip"`
		Candidates []string `json:"candidate"`
	}

	// 42
	SceneSelection struct {
		Current    string   `json:"scene"`
		Candidates []string `json:"candidate"`
	}

	// 43
	InvtervalTime struct {
		Current    string   `json:"intervalTimeSec"`
		Candidates []string `json:"candidate"`
	}

	// 44
	Color struct {
		Current    string   `json:"colorSetting"`
		Candidates []string `json:"candidate"`
	}

	// 45
	MovieFileFormat struct {
		Current    string   `json:"movieFileFormat"`
		Candidates []string `json:"candidate"`
	}

	// 52
	IRRemoteSetting struct {
		Current    string   `json:"infraredRemoteControl"`
		Candidates []string `json:"candidate"`
	}

	// 53
	TVColorSystem struct {
		Current    string   `json:"tvColorSystem"`
		Candidates []string `json:"candidate"`
	}

	// 54
	TrackingFocusStauts string `json:"trackingFocusStatus"`

	// 55
	TrackingFocusSetting struct {
		Current    string   `json:"trackingFocus"`
		Candidates []string `json:"candidate"`
	}

	// 56
	BatteryInfo []struct {
		ID               string `json:"batteryID"`
		Status           string `json:"status"`
		AdditionalStatus string `json:"additionalStatus"`
		LevelNumber      int    `json:"levelNumer"`
		LevelDenom       int    `json:"levelDenom"`
		Description      string `json:"description"`
	}

	// 57
	RecordingTime int `json:"recordingTime"`

	// 58
	NumberOfshots int `json:"numberOfShots"`

	// 59
	AutoPowerOffTime struct {
		Current    int   `json:"autoPowerOff"`
		Candidates []int `json:"candidate"`
	}

	// 60
	LoopRecordingTime struct {
		Current    string   `json:"loopRecTime"`
		Candidates []string `json:"candidate"`
	}

	// 61
	AudioRecording struct {
		Current    string   `json:"audioRecording"`
		Candidates []string `json:"candidate"`
	}

	// 62
	WindNoiseReduction struct {
		Current    string   `json:"windNoiseReduction"`
		Candidates []string `json:"candidate"`
	}
	// contains filtered or unexported fields
}

func DiscoverDevice

func DiscoverDevice() (camera *Camera, err error)

func NewCamera

func NewCamera(actionListURL string) *Camera

func (*Camera) AwaitTakePicture

func (c *Camera) AwaitTakePicture() (urls []string, err error)

AwaitTakePicture waits while the camera is taking the picture and returns the picture URL

func (*Camera) GetApplicationInfo

func (c *Camera) GetApplicationInfo() (server string, version string, err error)

GetApplicationInfo obtains the name and version of the application server on the camera.

func (*Camera) GetAvailableAPIList

func (c *Camera) GetAvailableAPIList() (available []string, err error)

GetAvailableAPIList obtains a list of available API features from the camera

func (*Camera) GetAvailableContinuousShootingMode

func (c *Camera) GetAvailableContinuousShootingMode() (current continuousShootingMode, available []continuousShootingMode, err error)

func (*Camera) GetAvailablePostviewImageSize

func (c *Camera) GetAvailablePostviewImageSize() (current string, available []string, err error)

GetAvailablePostviewImageSize obtains the current and available Post View Image sizes from the camera

func (*Camera) GetAvailableShootMode

func (c *Camera) GetAvailableShootMode() (current string, available []string, err error)

GetAvailableShootMode obtains the current and available shoot mode for the camera

func (*Camera) GetContinuousShootingMode

func (c *Camera) GetContinuousShootingMode() (mode continuousShootingMode, err error)

func (*Camera) GetMethodTypes

func (c *Camera) GetMethodTypes(ep endpoint, version string) (types [][]string, err error)

GetMethodTypes obtains the types for each of the given API functions for a given endpoint. An ampty string for version will return types for all versions

func (*Camera) GetPostviewImageSize

func (c *Camera) GetPostviewImageSize() (size string, err error)

GetPostviewImageSize obtains the current Post View Image size from the camera:

The possible options are: "2M" - a smaller preview, usually 2Megpixels in size, sometimes not - camera dependant "Original" - the size of the image taken

func (*Camera) GetShootMode

func (c *Camera) GetShootMode() (mode string, err error)

GetShootMode returns the current shoot mode of the camera.

func (*Camera) GetSupportedContinuousShootingMode

func (c *Camera) GetSupportedContinuousShootingMode() (modes []continuousShootingMode, err error)

func (*Camera) GetSupportedLiveviewSize

func (c *Camera) GetSupportedLiveviewSize() (sizes []string, err error)

GetSupportedLiveviewSize obtains the supported Live View sizes from the camera

func (*Camera) GetSupportedPostviewImageSize

func (c *Camera) GetSupportedPostviewImageSize() (sizes []string, err error)

GetSupportedPostviewImageSize obtains the supported Post View Image sizes from the camera

func (*Camera) GetSupportedShootMode

func (c *Camera) GetSupportedShootMode() (modes []string, err error)

GetSupportedShootMode obtains the supported shooting modes for the camera

func (*Camera) GetVersions

func (c *Camera) GetVersions(ep endpoint) (versions []string, err error)

GetVersions obtains the supported versions of the API server at the given endpoint

func (*Camera) Initilize

func (c *Camera) Initilize() error

Initlize the camera for recording and start threads ongoing event polling

func (*Camera) SetContinuousShootingMode

func (c *Camera) SetContinuousShootingMode(mode continuousShootingMode) (err error)

func (*Camera) SetContinuousShootingSpeed

func (c *Camera) SetContinuousShootingSpeed(speed continuousShootingSpeed) (err error)

SetContinuousShootingSpeed sets the shotting speed of the camera

func (*Camera) SetPostviewImageSize

func (c *Camera) SetPostviewImageSize(size PostViewSize) (err error)

SetPostviewImageSize sets the Post View image size for the camera:

The possible options are: "2M" - a smaller preview, usually 2Megpixels in size, sometimes not - camera dependant "Original" - the size of the image taken

func (*Camera) SetShootMode

func (c *Camera) SetShootMode(mode ShootMode) (err error)

SetShootMode sets the camera to the specified shoot mood. All possible shoot modes are defined in the ShootMode sturct.

func (*Camera) SetStillQuality

func (c *Camera) SetStillQuality(quality stillQuality) (err error)

SetStillQuality sets the quality for still photos taken by the camera. The possible quality settings are defined in the StillQuality struct.

func (*Camera) StartContinuousShooting

func (c *Camera) StartContinuousShooting() (err error)

StartContinuousShooting informs the camera to begin continuous shooting

func (*Camera) StartLiveview

func (c *Camera) StartLiveview() (lv *Liveview, err error)

func (*Camera) StartLiveviewWithSize

func (c *Camera) StartLiveviewWithSize(size LiveviewSize) (lv *Liveview, err error)

func (*Camera) StopContinuousShooting

func (c *Camera) StopContinuousShooting() (err error)

StopContinuousShooting informs the camera to stop continuous shooting

func (*Camera) StopLiveview

func (c *Camera) StopLiveview() (err error)

func (*Camera) TakePicture

func (c *Camera) TakePicture() (urls []string, err error)

TakePicture asks the camera to take a still picture It may return an error if the camera is not in a ready state, or error 40403 of the camera is taking a long exposue. In this case, the client should call AwaitTakePicutre and await the full exposure.

func (*Camera) UpdateState

func (c *Camera) UpdateState(polling bool) (err error)

type Liveview

type Liveview struct {
	URL          string
	Stream       *bufio.Reader
	HTTPResponse *http.Response
	Camera       *Camera
}

Liveview defines a live view stream for decoding

func (*Liveview) Decode

func (lv *Liveview) Decode(out chan *LiveviewPayload)

func (*Liveview) Stop

func (lv *Liveview) Stop()

Stop ends the current livestream

type LiveviewCommonHeader

type LiveviewCommonHeader struct {
	PayloadType    byte
	SequenceNumber uint16
	Timestamp      uint32
}

type LiveviewImagePayload

type LiveviewImagePayload struct {
	Reserved [120]byte // Who the fuck knows what Sony are using this for
	JPEGData []byte
}

type LiveviewInfoPayload

type LiveviewInfoPayload struct {
	VersionMajor    uint8
	VersionMinor    uint8
	FrameCount      uint16
	SingleFrameSize uint16
	Reserved        [114]byte // Reserved by Sony. No idea.
}

type LiveviewPayload

type LiveviewPayload struct {
	LiveviewCommonHeader

	PayloadSize uint32
	PaddingSize uint8

	*LiveviewInfoPayload
	*LiveviewImagePayload
}

type LiveviewSize

type LiveviewSize string

LiveviewSize represents pre-defined resolution or quality for the live view stream. Instances of LiveviewSize are defined in the LiveviewSizes struct variable.

type PostViewSize

type PostViewSize string

PostViewSize defines a supported Post View Image size, as defined by the Sony SRC 2.40 API reference. Instances of PostViewSize can be found in the PostViewSizes variable.

type ShootMode

type ShootMode string

ShootMode defines a particualr shooting mode for the camera. Instances shootmode can be found in the ShootModes variable for use in SetShootMode()

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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