Documentation ¶
Index ¶
- Variables
- func LocalIP() (net.IP, error)
- func StreamNamedSource(ctx context.Context, is ImageSource, name string, view View)
- func StreamSource(ctx context.Context, is ImageSource, view View)
- type AutoTiler
- type ClientResponder
- type FrameReleasePair
- type ImageSource
- type ImageSourceFunc
- type ResizeImageSource
- type RotateImageSource
- type Stream
- type View
- type ViewConfig
- type ViewHTML
- type ViewHandler
- type ViewServer
Constants ¶
This section is empty.
Variables ¶
var Debug = false
Debug is helpful to turn on when the library isn't working quite right.
var ( // DefaultICEServers is the default set of ICE servers to use for WebRTC session negotiation. DefaultICEServers = []webrtc.ICEServer{ { URLs: []string{"stun:stun.trevor.jp:3478", "turn:turn.trevor.jp:3478?transport=udp"}, Username: "trevor", Credential: getenvs.GetEnvString("TURN_PASSWORD", "redacted"), CredentialType: webrtc.ICECredentialTypePassword, }, } )
var ErrServerAlreadyStarted = errors.New("already started")
ErrServerAlreadyStarted happens when the server has already been started.
var Logger = golog.Global
Logger is used various parts of the package for informational/debugging purposes.
var PartialDefaultViewConfig = ViewConfig{ StreamNumber: 0, WebRTCConfig: webrtc.Configuration{ ICEServers: DefaultICEServers, }, }
PartialDefaultViewConfig is invalid by default; it requires an EncoderFactory to be set.
Functions ¶
func StreamNamedSource ¶
func StreamNamedSource(ctx context.Context, is ImageSource, name string, view View)
StreamNamedSource streams the given image source to the view forever until context signals cancelation. The given name is used to identify the stream.
func StreamSource ¶
func StreamSource(ctx context.Context, is ImageSource, view View)
StreamSource streams the given image source to the view forever until context signals cancelation.
Types ¶
type AutoTiler ¶
type AutoTiler struct {
// contains filtered or unexported fields
}
An AutoTiler automatically tiles a series of images from sources. It rudimentarily swaps between veritcal and horizontal splits and makes all images the same size within a grid. This can produce aesthetically unappealing results but it gets the job done in a pinch where you don't want multiple streams. AutoTiler supports adding image sources over time (but not removing them yet).
func NewAutoTiler ¶
func NewAutoTiler(maxWidth, maxHeight int, sources ...ImageSource) *AutoTiler
NewAutoTiler returns an AutoTiler that adapts its image sources to the given width and height.
func NewAutoTilerVertical ¶
func NewAutoTilerVertical(maxWidth, maxHeight int, sources ...ImageSource) *AutoTiler
NewAutoTilerVertical returns an AutoTiler that adapts its image sources to the given width and height. This AutoTiler starts its splits vertically, instead of horizontally.
func (*AutoTiler) AddSource ¶
func (at *AutoTiler) AddSource(src ImageSource)
AddSource adds another image source to the tiler. It will appear down and to the right of the main image.
type ClientResponder ¶
A ClientResponder is able to respond directly to a client. This is used in the onData/Click handlers.
type FrameReleasePair ¶
FrameReleasePair associates a frame with a corresponding function to release its resources once the receiver of a pair is finished with the frame.
type ImageSource ¶
type ImageSource interface { // Next returns an image along with a function to release // the image once it is no longer used. Not calling the function // will not leak memory but may cause the implementer to be // as efficient with memory. Next(ctx context.Context) (image.Image, func(), error) Close() error }
An ImageSource is responsible for producing images when requested. A source should produce the image as quickly as possible and introduce no rate limiting of its own as that is handled internally.
type ImageSourceFunc ¶
An ImageSourceFunc is a helper to turn a function into an ImageSource
type ResizeImageSource ¶
type ResizeImageSource struct { Src ImageSource Width, Height int }
ResizeImageSource resizes images to the set dimensions.
func (ResizeImageSource) Close ¶
func (ris ResizeImageSource) Close() error
Close closes the underlying source.
type RotateImageSource ¶
type RotateImageSource struct { Src ImageSource RotateByDeg float64 }
RotateImageSource rotates images by a set amount of degrees.
func (*RotateImageSource) Close ¶
func (rms *RotateImageSource) Close() error
Close closes the underlying source.
type Stream ¶
type Stream interface {
InputFrames() chan<- FrameReleasePair
}
A Stream is sink that accepts any image frames for the purpose of displaying in a view.
type View ¶
type View interface { // Stop stops further processing of streams and will not accept new // connections. Stop() // Ready signals that there is at least one client connected and that // streams are ready for input. StreamingReady() <-chan struct{} // SetOnSizeHandler sets a handler for clicks on the view. This is typically // used to alter the view or send information back with SendDataToAll or SendTextToAll. SetOnSizeHandler(func(ctx context.Context, factor float32, responder ClientResponder)) // SetOnDataHandler sets a handler for data sent to the view. This is typically // used to alter the view or send information back with the responder. SetOnDataHandler(func(ctx context.Context, data []byte, responder ClientResponder)) // SendDataToAll allows sending arbitrary data to all clients. SendDataToAll(data []byte) // SendCursorToAll ... SendCursorToAll(img image.Image, width int, height int, hotx int, hoty int) // SendTextToAll allows sending arbitrary messages to all clients. SendTextToAll(msg string) // HTML returns the HTML needed to interact with the view in a browser. HTML() ViewHTML // SinglePageHTML returns a complete HTML document that can interact with the view in a browser. SinglePageHTML() string // Handler returns a named http.Handler that handles new WebRTC connections. Handler() ViewHandler // ReserveStream allocates a Stream of the given name to be able to stream images to. Reserving // streams after the Ready signal is fired is currently not allowed but the method will not fail. // This is a lower level method and typically StreamSource is used instead. ReserveStream(name string) Stream }
A View represents a view of streams that can be communicated with from a client.
func NewView ¶
func NewView(config ViewConfig) (View, error)
NewView returns a newly configured view that can begin to handle new connections.
type ViewConfig ¶
type ViewConfig struct { StreamNumber int StreamName string WebRTCConfig webrtc.Configuration EncoderFactory codec.EncoderFactory // TargetFrameRate will hint to the View to try to maintain this frame rate. TargetFrameRate int Logger golog.Logger }
A ViewConfig describes how a View should be managed.
type ViewHandler ¶
type ViewHandler struct { Name string Func http.HandlerFunc }
A ViewHandler names a view and its http.Handler for processing new WebRTC connections.
type ViewServer ¶
type ViewServer interface { // Start starts the server and waits for new connections. Start() error // Stop stops the server and stops the underlying views. Stop(ctx context.Context) error }
A ViewServer is a convenience helper for solely streaming a series Views. Views can be added over time for future new connections.
func NewViewServer ¶
func NewViewServer(port int, view View, logger golog.Logger) ViewServer
NewViewServer returns a server that will run on the given port and initially starts with the given view.