upnptype

package
v0.0.0-...-366e4d7 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2016 License: GPL-2.0 Imports: 3 Imported by: 1

Documentation

Overview

Package upnptype defines common types for the upnp package.

Index

Constants

View Source
const (
	BrowseObjectIDRoot = "0"

	BrowseFlagBrowseMetadata       = "BrowseMetadata"
	BrowseFlagBrowseDirectChildren = "BrowseDirectChildren"

	BrowseFilterAll = "*"

	BrowseSortCriteriaNone = ""
)

Browse common options.

View Source
const (
	ChannelMaster = "Master"
	ChannelRF     = "RF"
	ChannelLF     = "LF"
)

Channels names.

View Source
const (
	SeekModeTrackNR = "TRACK_NR" // Seek to the beginning of the specified track
	SeekModeAbsTime = "ABS_TIME" // Seek to the given absolute offset in the current track
	SeekModeRelTime = "REL_TIME" // Seek to the given relative offset in the current track
	SeekModeSection = "SECTION"  // Seek to the specified section (not tested)
)

Legal values for @unit in calls to Seek.

View Source
const (
	PlayModeNormal          = "NORMAL"           // Play sequentially from the beginning of the queue to the end
	PlayModeRepeatAll       = "REPEAT_ALL"       // Begin again at the first track of the queue after reaching the last
	PlayModeShuffleNoRepeat = "SHUFFLE_NOREPEAT" // Play tracks out of order, with repeat
	PlayModeShuffle         = "SHUFFLE"          // Play through tracks out of order once
)

Valid values for PlayMode in SetPlayMode and TransportSettings.

View Source
const (
	StateTransitioning  = "TRANSITIONING"
	StateStopped        = "STOPPED"
	StatePausedPlayback = "PAUSED_PLAYBACK"
	StatePlaying        = "PLAYING"
)

Legal values for TransportInfo.CurrentTransportState

View Source
const (
	MaxBrowse = 64
)

Common settings.

View Source
const PlaySpeedNormal = "1"

Playback speed.

Variables

This section is empty.

Functions

func Clock

func Clock(rend Renderer, tick *time.Ticker, state PlaybackState) *time.Ticker

Clock ticks to refresh a renderer track position.

func TimeToSecond

func TimeToSecond(str string) int

TimeToSecond converts a time string to a duration in sceonds.

input as "15:04:05" format as used by renderers.

func TimeToString

func TimeToString(sec int) string

TimeToString formats time input in seconds to HH:MM:SS string used by renderers.

output as "15:04:05" format for seek requests.

Types

type Action

type Action int

Action defines an UPnP simple renderer action.

const (
	ActionNone Action = iota
	ActionToggleMute
	ActionVolumeDown
	ActionVolumeUp
	ActionPlayPause
	ActionStop
	ActionSeekBackward
	ActionSeekForward
)

Actions defined by the media controler.

type AddMultipleURIsToQueueIn

type AddMultipleURIsToQueueIn struct {
	// UpdateID (in), can be 0
	UpdateID uint32
	// The number of URIs to be added in this request
	NumberOfURIs uint32
	// A list of @NumberOfURIs URIs, separated by a space
	EnqueuedURIs string
	// A list of @NumberOfURIs DIDL-Lite documents, separated by a space
	EnqueuedURIsMetaData string
	// URI of a container in the ContentDirectory containing the
	// URIs to be added.  If adding tracks this should be the URI for
	// the A:TRACK entry in the directory.
	ContainerURI string
	// A DIDL-Lite document describing the resource given by @ContainerURI
	ContainerMetaData string
	// This field should be 0 to insert the new item at the end
	// of the queue.  If non-zero the new track will be inserted at
	// this location, and later tracks will see their track numbers
	// incremented.
	DesiredFirstTrackNumberEnqueued uint32
	// ???? (possibly unsupported)
	EnqueueAsNext bool
}

AddMultipleURIsToQueueIn defines input parameters for AddMultipleURIsToQueue.

type AddMultipleURIsToQueueOut

type AddMultipleURIsToQueueOut struct {
	FirstTrackNumberEnqueued uint32 // The starting position int the queue (Q:0) of the newly added tracks
	NumTracksAdded           uint32 // The number of tracks added by the request
	NewQueueLength           uint32 // The length of the queue after the request was complete
	NewUpdateID              uint32 // The new UpdateID
}

AddMultipleURIsToQueueOut defines output value for AddMultipleURIsToQueue.

type AddURIToQueueIn

type AddURIToQueueIn struct {
	// The URI of the track to be added to the queue, corresponding
	// the to <res> tag in a DIDL-Lite description (@see dldl,
	// @ContentDirectory, etc) e.g.:
	//     "x-file-cifs://servername/path/to/track.mp3"
	EnqueuedURI string
	// A DIDL-Lite document describing the the resource given by @EnqueuedURI
	EnqueuedURIMetaData string
	// This field should be 0 to insert the new item at the end
	// of the queue.  If non-zero the new track will be inserted at
	// this location, and later tracks will see their track numbers
	// incremented.
	DesiredFirstTrackNumberEnqueued uint32
	// ???? (possibly unsupported)
	EnqueueAsNext bool
}

AddURIToQueueIn defines input parameters for AddURIToQueue.

type AddURIToQueueOut

type AddURIToQueueOut struct {
	// The track number of the newly added track.
	FirstTrackNumberEnqueued uint32
	// The number of tracks added by this request (always 1).
	NumTracksAdded uint32
	// The length of the queue now that this track has been added
	NewQueueLength uint32
}

AddURIToQueueOut defines output value for AddURIToQueue

type BrowseRequest

type BrowseRequest struct {
	ObjectID      string
	BrowseFlag    string
	Filter        string
	StartingIndex uint32
	RequestCount  uint32
	SortCriteria  string
}

BrowseRequest defines input parameters for Browse.

type BrowseResult

type BrowseResult struct {
	NumberReturned int32
	TotalMatches   int32
	UpdateID       int32
	// Doc            *didl.Lite
	Container []Container
	Item      []Object
}

BrowseResult defines output value for Browse.

type Container

type Container struct {
	Object
	XMLName    xml.Name `xml:"container"`
	ChildCount int      `xml:"childCount,attr"`
}

Container defines a server file container.

type ControlPointEvents

type ControlPointEvents struct {
	OnRendererFound func(Renderer)
	OnRendererLost  func(Renderer)
	OnServerFound   func(Server)
	OnServerLost    func(Server)
}

ControlPointEvents defines events of a control point.

type DeviceBase

type DeviceBase struct {
	// contains filtered or unexported fields
}

DeviceBase provides a common device base to extend for backends.

func (*DeviceBase) CompareProxy

func (db *DeviceBase) CompareProxy(devtest UDNer) bool

CompareProxy compares two devices to see if they points to the same object.

func (*DeviceBase) GetIconFile

func (db *DeviceBase) GetIconFile(filename string) string

GetIconFile gets the device icon location.

func (*DeviceBase) Icon

func (db *DeviceBase) Icon() string

Icon returns the icon file location.

func (*DeviceBase) Name

func (db *DeviceBase) Name() string

Name returns the friendly name of the device (if found).

func (*DeviceBase) SetIcon

func (db *DeviceBase) SetIcon(icon string)

SetIcon sets the icon file location.

func (*DeviceBase) SetName

func (db *DeviceBase) SetName(name string)

SetName sets the friendly name of the device.

func (*DeviceBase) SetUDN

func (db *DeviceBase) SetUDN(udn string)

SetUDN sets the UDN (UPnP ID) of the device.

func (*DeviceBase) UDN

func (db *DeviceBase) UDN() string

UDN returns the UDN (UPnP ID) of the device.

type Item

type Item struct {
	Object
	XMLName xml.Name   `xml:"item"`
	Res     []Resource `xml:"res"`
}

Item defines a server file object with resources.

type Logger

type Logger interface {
	Infof(string, ...interface{})
	Warningf(string, ...interface{})
}

Logger defines logging forwarding for the API.

type MediaControl

type MediaControl interface {

	// DefineEvents returns pointers to control events callbacks.
	//
	DefineEvents() ControlPointEvents

	// Action sends an action message to the selected renderer.
	//
	Action(Action) error

	// Renderer return the current renderer if any.
	//
	Renderer() Renderer

	// RendererExists return true if a renderer is selected.
	//
	RendererExists() bool

	// SetRenderer sets the current renderer by its udn reference.
	//
	SetRenderer(udn string)

	// Renderers return the list of all known renderers.
	//
	Renderers() Renderers

	// Server return the current server if any.
	//
	Server() Server

	// ServerExists return true if a server is selected.
	//
	ServerExists() bool

	// SetServer sets the current server by its udn reference.
	//
	SetServer(udn string)

	// Servers return the list of all known servers.
	//
	Servers() map[string]Server

	// SetVolumeDelta configures the default volume delta for user actions.
	//
	SetVolumeDelta(delta int)

	// SetSeekDelta configures the default volume delta for user actions.
	//
	SetSeekDelta(delta int)

	// SetPreferredRenderer sets the renderer that will be selected if found (unless anoter is selected).
	//
	SetPreferredRenderer(name string)

	// SetPreferredServer sets the server that will be selected if found (unless anoter is selected)..
	//
	SetPreferredServer(name string)

	// SetSeek seeks to new time in track.
	//
	Seek(unit, target string) error

	// SetSeekPercent seeks to new time in track. Input is the percent position in track. Range 0 to 100.
	//
	SeekPercent(value float64) error

	// GetCurrentTime returns the current track position on selected renderer in seconds.
	//
	GetCurrentTime() int

	// Browse lists files on a server.
	//
	Browse(container string, startingIndex uint32) ([]Container, []Object, uint, uint)

	// BrowseMetadata starts the playback of the given file on the selected renderer.
	//
	BrowseMetadata(container string, startingIndex uint) error

	// SetNextAVTransportURI sets the next playback URI,
	//
	SetNextAVTransportURI(nextURI, nextURIMetaData string) error

	// SubscribeHook register a new hook client and returns the MediaHook to connect to.
	//
	SubscribeHook(id string) *MediaHook

	// UnsubscribeHook removes a client hook.
	//
	UnsubscribeHook(id string)
}

MediaControl defines actions provided by the selected server and renderer.

type MediaHook

type MediaHook struct {
	ControlPointEvents
	RendererEvents

	// Local events.
	OnSetVolumeDelta   func(int)
	OnSetSeekDelta     func(int)
	OnRendererSelected func(Renderer)
	OnServerSelected   func(Server)
}

MediaHook provides a registration method to media events for multiple clients.

type MediaInfo

type MediaInfo struct {
	NrTracks           uint32 // The number of tracks in the queue (Q:0)
	MediaDuration      string // ???? (possibly not supported)
	CurrentURI         string // The URI of the queue
	CurrentURIMetaData string // ????
	NextURI            string // ???? (possibly not supported)
	NextURIMetaData    string // ???? (possibly not supported)
	PlayMedium         string // ????
	RecordMedium       string // ???? (possibly not supported)
	WriteStatus        string // ???? (possibly not supported)
}

MediaInfo defines information about the currently selected media.

type Object

type Object struct {
	ID         string `xml:"id,attr"`
	ParentID   string `xml:"parentID,attr"`
	Restricted int    `xml:"restricted,attr"`  // indicates whether the object is modifiable
	Class      string `xml:"class"`            // upnp:
	Icon       string `xml:"icon,omitempty"`   // upnp:
	Title      string `xml:"title"`            // dc:
	Artist     string `xml:"artist,omitempty"` // upnp:
	Album      string `xml:"album,omitempty"`  // upnp:
	Genre      string `xml:"genre,omitempty"`  // upnp:
}

Object defines a server file object description.

type PlaybackState

type PlaybackState int

PlaybackState defines the playback state of a renderer.

const (
	PlaybackStateUnknown PlaybackState = iota
	PlaybackStateTransitioning
	PlaybackStateStopped
	PlaybackStatePaused
	PlaybackStatePlaying
)

Renderer playback states.

func PlaybackStateFromName

func PlaybackStateFromName(name string) PlaybackState

PlaybackStateFromName returns the PlaybackState for the given state string.

type PositionInfo

type PositionInfo struct {
	// Track number relative to the beginning of the queue (not the containing album).
	Track uint32
	// Total length of the track in HH:MM:SS format
	TrackDuration string
	// The DIDL-Lite document describing this item in the ContentDirectory
	TrackMetaData string
	// The URI of the track, corresponding // the to <res> tag in
	// a DIDL-Lite description (@see dldl, @ContentDirectory, etc) e.g.:
	//     "x-file-cifs://servername/path/to/track.mp3"
	TrackURI string
	// The number of elapsed seconds into the track in HH:MM:SS format
	RelTime string
	// ???? (possibly unsupported)
	AbsTime string
	// ???? (possibly unsupported)
	RelCount uint32
	// ???? (possibly unsupported)
	AbsCount uint32
}

PositionInfo defines information about the track.

type Renderer

type Renderer interface {

	// Events returns the renderer events callbacks.
	//
	Events() *RendererEvents

	// CompareProxy compares two devices to see if they points to the same object.
	//
	CompareProxy(devtest UDNer) bool

	// GetIconFile gets the device icon location.
	//
	GetIconFile(filename string) string

	ServiceRenderingControl
	ServiceAVTransport

	// PlayPause toggles the play / pause action on the renderer.
	//
	PlayPause(instanceID uint32, speed string) error

	// GetCurrentTime returns the current track position on selected renderer in seconds.
	//
	GetCurrentTime() int

	// DisplayCurrentTime forwards the current track position with OnCurrentTime event.
	//
	DisplayCurrentTime()
	// contains filtered or unexported methods
}

Renderer defines actions provided by an UPnP renderer.

type RendererBase

type RendererBase struct {
	DeviceBase
	// contains filtered or unexported fields
}

RendererBase provides a common renderer base to extend for backends.

func (*RendererBase) Events

func (rend *RendererBase) Events() *RendererEvents

Events returns the renderer events callbacks.

type RendererEvents

type RendererEvents struct {
	OnTransportState       func(Renderer, PlaybackState)
	OnCurrentTrackDuration func(Renderer, int)
	OnCurrentTrackMetaData func(Renderer, *Item)

	OnMute   func(Renderer, bool)
	OnVolume func(Renderer, uint)

	OnCurrentTime func(r Renderer, secs int, percent float64)
}

RendererEvents defines events of a renderer.

type Renderers

type Renderers map[string]Renderer

Renderers defines a list of renderer indexed by udn.

type Resource

type Resource struct {
	// XMLName      xml.Name `xml:"res"`
	ProtocolInfo string `xml:"protocolInfo,attr"`
	URL          string `xml:",chardata"`
	Size         uint64 `xml:"size,attr,omitempty"`
	Bitrate      uint   `xml:"bitrate,attr,omitempty"`
	Duration     string `xml:"duration,attr,omitempty"`
	Resolution   string `xml:"resolution,attr,omitempty"`
}

Resource defines a server file resource.

type Server

type Server interface {
	ServiceContentDirectory

	// CompareProxy compares two devices to see if they points to the same object.
	//
	CompareProxy(devtest UDNer) bool

	// GetIconFile gets the device icon location.
	//
	GetIconFile(filename string) string
	// contains filtered or unexported methods
}

Server defines actions provided by an UPnP file server.

type ServerBase

type ServerBase struct {
	DeviceBase
}

ServerBase provides a common server base to extend for backends.

type ServiceAVTransport

type ServiceAVTransport interface {

	// SetAVTransportURI sets the current playback URI,
	//
	//   @currentURI will be a valid URI as given by the Res() attribute of a
	//               ContentDirectory object.
	//   @currentURIMetaData can be empty.
	//
	// Use this method to, for example, resume playback from a queue after
	// playback from a radio station or other source.
	//
	SetAVTransportURI(instanceID uint32, currentURI, currentURIMetaData string) error

	//
	// AddURIToQueue adds a single track to the queue (Q:0).
	// See AddURIToQueueIn for a discussion of the input
	// parameters and AddURIToQueueOut for a discussion of the output
	// parameters.
	//
	AddURIToQueue(instanceID uint32, req *AddURIToQueueIn) (*AddURIToQueueOut, error)

	//
	// Add multiple tracks to the queue (Q:0).  This method does not seem
	// to be a standard part of AVTransport:1, but rather a Sonos extension.
	// As such it is not entirely clear how it should be used.
	//
	// For Sonos @instanceID should always be 0; @UpdateID should be 0;
	// @NumberOfURIs should be the number of tracks to be added by the
	// request; @EnqueuedURIs is a space-separated list of URIs (as given by
	// the Res() method of the model.Object class); @EnqueuedURIMetData is a
	// space-separated list of DIDL-Lite documents describing the resources
	// to be added; @ContainerURI should be the ContentDirectory URI for
	// A:TRACK, when adding tracks; @ContainerMetaData should be a DIDL-Lite
	// document describing A:TRACK. Other arguments have the same meaning as
	// in @AddURIToQueue.
	//
	// Note that the number of DIDL-Lite documents in @EnqueuedURIsMetaData
	// must match the number of URIs in @EnqueuedURIs.  These DIDL-Lite documents
	// can be empty, but must be present.  @ContainerMetaData must be a string
	// of non-zero length, but need not be a valid DIDL-Lite document.
	//
	AddMultipleURIsToQueue(instanceID uint32, req *AddMultipleURIsToQueueIn) (*AddMultipleURIsToQueueOut, error)

	// GetMediaInfo gets information about the currently selected media, its URI,
	// length in tracks, and recording status, if any.
	//
	// Many renderers will have a lot of the fields unsupported.
	//
	GetMediaInfo(instanceID uint32) (*MediaInfo, error)

	// GetTransportInfo returns the current state of the transport (playing,
	// stopped, paused), its status, and playback speed.
	//
	GetTransportInfo(instanceID uint32) (*TransportInfo, error)

	// GetPositionInfo returns information about the track that is currently
	// playing, its URI, position in the queue (Q:0), and elapsed time.
	//
	GetPositionInfo(instanceID uint32) (*PositionInfo, error)

	// Stops playback and return to the beginning of the queue (Q:1).
	//
	Stop(instanceID uint32) error

	// Starts or resumes playback at the given speed.
	//
	//   @speed is a fraction relative to normal speed (e.g. "1" or "1/2").
	//
	Play(instanceID uint32, speed string) error

	// Pause playback, prepared to resume at the current position.  For Sonos
	// @instanceID should always be 0.
	//
	Pause(instanceID uint32) error

	//
	// A general function to seek within the playback queue (Q:0).  For Sonos
	// @instanceID should always be 0; @unit should be one of the values given
	// for seek mode (TRACK_NR, REL_TIME, or SECTION); and @target should
	// give the track, time offset, or section where playback should resume.
	//
	// For TRACK_NR the integer track number relative to the start of the queue
	// is supplied to @target.  For REL_TIME a duration in the format HH:MM:SS
	// is given as @target.  SECTION is not tested.
	//
	Seek(instanceID uint32, unit, target string) error

	//
	// Skip ahead to the next track in the queue (Q:).  For Sonos @instanceID
	// should always be 0.  This method returns an error 711 if the current
	// track is the last track in the queue.
	//
	Next(instanceID uint32) error

	//
	// Move to a previous track in the queue (Q:0).  For Sonos @instanceID
	// should always be 0.  This method returns error 711 if the current track
	// is the first track in the queue.
	//
	Previous(instanceID uint32) error

	//
	// Returns a list of the actions that are valid at this time.  The list
	// consists of human-readable strings, such as "Play", and "Stop".  For Sonos
	// @instanceID will always be 0.
	//
	GetCurrentTransportActions(instanceID uint32) ([]string, error)

	// SetNextAVTransportURI sets the next playback URI,
	//
	SetNextAVTransportURI(instanceID uint32, nextURI, nextURIMetaData string) error
}

ServiceAVTransport defines actions provided by the renderer transport.

type ServiceContentDirectory

type ServiceContentDirectory interface {

	// Browse lists files on a server.
	//
	Browse(req *BrowseRequest) (browseResult *BrowseResult, err error)

	BrowseMetadata(container string, startingIndex, requestedCount uint) ([]Container, []Item, string)
}

ServiceContentDirectory defines actions provided by an UPnP file server.

type ServiceRenderingControl

type ServiceRenderingControl interface {
	GetMute(instanceID uint32, channel string) (currentMute bool, e error)
	SetMute(instanceID uint32, channel string, desiredMute bool) error

	GetVolume(instanceID uint32, channel string) (currentVolume uint16, e error)

	// Set the playback volume.
	// @volume is an integer between 0 and 100, where 100 is the loudest.
	//
	SetVolume(instanceID uint32, channel string, volume uint16) error
	SetRelativeVolume(instanceID uint32, channel string, adjustment int32) (newVolume uint16, e error)
}

ServiceRenderingControl defines actions provided by the renderer control.

@instanceID will always be 0 for most devices.
@channel is one of the constants: ChannelMaster, ChannelRF, ChannelLF.

type TransportInfo

type TransportInfo struct {
	// Indicates whether the device is playing, paused, or stopped
	CurrentTransportState string
	// Indicates if an error condition exists ("OK" otherwise)
	CurrentTransportStatus string
	// Playback speed relative to normal playback speed (e.g. "1" or "1/2")
	CurrentSpeed string
}

TransportInfo defines the current state of the transport.

type TransportSettings

type TransportSettings struct {
	// The current play mode (NORMAL, REPEAT_ALL, SHUFFLE, etc.)
	PlayMode string

	// The record quality (not supported in Sonos)
	RecQualityMode string
}

TransportSettings defines output value for GetTransportSettings

type UDNer

type UDNer interface {
	UDN() string
}

UDNer defines an object that returns its UPnP ID.

Jump to

Keyboard shortcuts

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