media

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package media provides bounded, transport-free media primitives shared by local system capture and playback implementations.

Index

Constants

View Source
const (
	// DefaultRecordingDuration bounds one caller-started recording.
	DefaultRecordingDuration = time.Minute
	// MaxRecordingDuration is the library ceiling for a recording.
	MaxRecordingDuration = time.Hour
	// DefaultRecordingBytes bounds a retained recording.
	DefaultRecordingBytes int64 = 128 << 20
	// MaxRecordingBytes is the library ceiling for a recording.
	MaxRecordingBytes int64 = 1 << 30
)

Variables

View Source
var ErrRecordingLimit = errors.New("recording limit exceeded")

ErrRecordingLimit reports that a recording hit its duration or byte bound.

Functions

func Annotate

func Annotate(frame Frame, boxes []Annotation, maxBytes, maxPixels int) ([]byte, error)

Annotate draws bounded element boxes without mutating the source frame.

func ContactSheet

func ContactSheet(frames []Frame, options ContactSheetOptions) ([]byte, error)

ContactSheet creates a deterministic finite PNG. Labels and other presentation choices remain consumer concerns.

func WAV

func WAV(p PCM16, maxBytes int) ([]byte, error)

WAV wraps samples in a PCM16 RIFF/WAVE container without resampling or changing their amplitude.

Types

type Annotation

type Annotation struct {
	ID     string     `json:"id"`
	Region Region     `json:"region"`
	Color  color.RGBA `json:"color"`
}

type ContactSheetOptions

type ContactSheetOptions struct {
	Columns       int
	TileWidth     int
	TileHeight    int
	MaxFrameBytes int
	MaxTotalBytes int64
	MaxPixels     int
}

type Frame

type Frame struct {
	Data            []byte
	ObservedAt      time.Time
	Target          string
	CoordinateSpace string
}

Frame is one caller-owned encoded image with its local target identity and coordinate system. Capture implementations return bytes directly; network envelopes, storage IDs, and retention policy belong to consumers.

func Around

func Around(ctx context.Context, source FrameSource, operation func(context.Context) error) (before, after Frame, err error)

Around captures before and after one caller-supplied local operation. It still returns post-operation evidence after an operation error when the context permits it; callers decide how to interpret dispatch uncertainty.

func Crop

func Crop(frame Frame, region Region, maxBytes, maxPixels int) (Frame, error)

Crop produces a new PNG using image-local coordinates. The returned frame uses crop-local coordinates and does not rewrite the source bytes.

type FrameConsumer

type FrameConsumer func(context.Context, Frame, FrameMetadata) error

FrameConsumer processes one retained frame. Persistence, references, and transport remain entirely outside this package.

type FrameMetadata

type FrameMetadata struct {
	Sequence        int       `json:"sequence"`
	ObservedAt      time.Time `json:"observed_at"`
	Target          string    `json:"target"`
	CoordinateSpace string    `json:"coordinate_space"`
	Width           int       `json:"width"`
	Height          int       `json:"height"`
	Bytes           int       `json:"bytes"`
	SHA256          string    `json:"sha256"`
	ChangedFraction float64   `json:"changed_fraction"`
	ChangedBounds   *Region   `json:"changed_bounds,omitempty"`
}

type FrameSource

type FrameSource interface {
	Capture(context.Context) (Frame, error)
}

FrameSource captures from a target already selected by its caller.

type FrameSourceFunc

type FrameSourceFunc func(context.Context) (Frame, error)

func (FrameSourceFunc) Capture

func (f FrameSourceFunc) Capture(ctx context.Context) (Frame, error)

type PCM16

type PCM16 struct {
	SampleRate int
	Channels   int
	Data       []byte
}

PCM16 contains signed little-endian interleaved samples. Data is finite and caller-owned; PCM16 opens no capture device, player, file, or connection.

func ReadWAV

func ReadWAV(data []byte, maxBytes int) (PCM16, error)

ReadWAV accepts bounded PCM16 RIFF/WAVE containers. Compressed, floating-point, extensible, duplicated, and truncated data fails explicitly; the function never guesses a codec.

func (PCM16) Validate

func (p PCM16) Validate(maxBytes int) error

Validate checks format, frame alignment, and a caller-selected byte ceiling.

type Recorder

type Recorder interface {
	Record(context.Context, RecordingOptions) (Recording, error)
}

Recorder starts a recording from the desktop or surface its implementation owns. The caller supplies the bounds, output format, and lifetime.

type Recording

type Recording interface {
	io.ReadCloser
	Stop(context.Context) error
}

Recording is a bounded, caller-owned stream of encoded output. Reading is transport-free; persistence, publishing, and retention belong to the caller. Stop ends the native recording and must be safe to call after an error.

type RecordingOptions

type RecordingOptions struct {
	Format      string
	FrameRate   int
	MaxDuration time.Duration
	MaxBytes    int64
}

RecordingOptions selects a caller-owned recording. Format names a container; the backend rejects a format it cannot produce rather than substituting one.

func (RecordingOptions) Normalize

func (o RecordingOptions) Normalize() (RecordingOptions, error)

Normalize supplies defaults and rejects unsupported values.

type Region

type Region struct {
	X      int `json:"x"`
	Y      int `json:"y"`
	Width  int `json:"width"`
	Height int `json:"height"`
}

func Difference

func Difference(previous, current image.Image) (float64, *Region)

Difference measures exact pixel changes between equal-sized images. A resize reports a completely changed image; bounds use image-local pixels.

type SampleManifest

type SampleManifest struct {
	StartedAt    time.Time       `json:"started_at"`
	FinishedAt   time.Time       `json:"finished_at"`
	Sampled      int             `json:"sampled"`
	Retained     int             `json:"retained"`
	SampledBytes int64           `json:"sampled_bytes"`
	Frames       []FrameMetadata `json:"frames"`
	Complete     bool            `json:"complete"`
	StopReason   string          `json:"stop_reason"`
}

func Sample

func Sample(ctx context.Context, source FrameSource, options SampleOptions, consume FrameConsumer) (manifest SampleManifest, err error)

Sample performs captures under explicit time, frame, pixel, and byte limits. Manifest metrics include samples discarded by change filtering.

type SampleOptions

type SampleOptions struct {
	MaxFrames     int
	MaxDuration   time.Duration
	Interval      time.Duration
	Heartbeat     time.Duration
	MaxFrameBytes int
	MaxTotalBytes int64
	MaxPixels     int
	MinChange     float64
}

func (SampleOptions) Validate

func (o SampleOptions) Validate() error

type VideoDecoder

type VideoDecoder interface {
	FrameAt(context.Context, time.Duration) (Frame, error)
}

VideoDecoder borrows a caller-selected decoder and media resource. It does not open a path, fetch a URL, or launch a codec. FrameAt must apply its own decoding limits before returning a PNG frame.

type VideoFrame

type VideoFrame struct {
	OffsetMS int64         `json:"offset_ms"`
	Metadata FrameMetadata `json:"metadata"`
}

type VideoManifest

type VideoManifest struct {
	Frames   []VideoFrame `json:"frames"`
	Bytes    int64        `json:"bytes"`
	Complete bool         `json:"complete"`
}

func SampleVideo

func SampleVideo(ctx context.Context, decoder VideoDecoder, options VideoOptions, consume FrameConsumer) (VideoManifest, error)

SampleVideo extracts caller-selected increasing timestamps exactly once.

type VideoOptions

type VideoOptions struct {
	Offsets       []time.Duration
	MaxDuration   time.Duration
	MaxFrameBytes int
	MaxTotalBytes int64
	MaxPixels     int
}

Jump to

Keyboard shortcuts

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