frames

package
v0.2.15 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0 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 frames serves a camera stream's access units over HTTP, one length-prefixed record per frame, for a client that owns its own decoder.

It exists for the cam wall. Every general-purpose player on the wall boxes sits one to three seconds behind the camera: RTSP jitter buffers, the container demux and the player's own render clock all add their share. A client that feeds access units straight into the hardware decoder and renders each picture as it comes out has none of those stages, and this is the simplest possible feed for it: no container, no RTP, no SDP, just the frames as the camera sent them, Annex B parameter sets inline.

Record layout, big-endian, 20 bytes then payload:

0   "RF"      magic
2   u8        version, 1
3   u8        kind: 1 keyframe, 2 inter frame, 3 AAC
4   u8        codec: 1 H264, 2 H265, 3 AAC
5   u8        reserved
6   u16       width, 0 if not yet known
8   u16       height, 0 if not yet known
10  u32       camera microseconds (wraps every 71.6 minutes)
14  u32       payload length
18  u16       server send time, milliseconds since the epoch mod 65536

The send time lets a client with a synchronized clock measure the server-to-screen leg on its own, without a round trip and without trusting the camera's clock. It wraps every 65.5 seconds, which is far longer than any latency worth measuring.

A subscriber's first record is a keyframe, and a subscriber that falls behind is resumed at the next keyframe rather than handed a frame whose references it never saw. Nothing here blocks the camera goroutine.

Index

Constants

View Source
const (
	HeaderLen = 20
	Version   = 1

	KindKey   = 1
	KindInter = 2
	KindAAC   = 3

	CodecH264 = 1
	CodecH265 = 2
	CodecAAC  = 3
)

Variables

This section is empty.

Functions

func Handles

func Handles(r *http.Request) bool

Handles reports whether the request path is one this server serves.

Types

type Record

type Record struct {
	Kind, Codec   uint8
	Width, Height uint16
	Micros        uint32
	Payload       []byte
}

Record is one decoded frame record.

func ReadRecord

func ReadRecord(r io.Reader) (Record, error)

ReadRecord reads one record from r. It is what a Go client, or a test, uses; the wall's client is not written in Go.

func (Record) Marshal

func (r Record) Marshal() []byte

Marshal encodes the record, header and payload, into one new slice.

type Server

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

Server holds the feeds and serves them at "/<path>.frames".

func New

func New() *Server

func (*Server) Add

func (s *Server) Add(path string) *Stream

Add registers a path and returns the stream that feeds it.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP streams records until the client goes away. Each record is flushed on its own: the whole point of this feed is that nothing waits for the next frame before the current one leaves.

func (*Server) Subscribe added in v0.2.14

func (s *Server) Subscribe(path string) (records <-chan []byte, cancel func(), ok bool)

Subscribe gives an in-process reader the feed at path: marshaled records, the first a keyframe, until cancel. ok is false for a path no stream feeds.

type Stream

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

Stream is one camera stream's feed. It implements stream.FrameSink and stream.ConnectionSink.

func (*Stream) Connected

func (s *Stream) Connected()

Connected implements stream.ConnectionSink. A new camera connection may carry new parameter sets, and every client decodes those from the keyframe itself, so nothing is needed here beyond forgetting the size until the camera restates it.

func (*Stream) Frame

func (s *Stream) Frame(f baichuan.Frame)

Frame implements stream.FrameSink. It runs on the camera goroutine and never blocks: a subscriber that cannot take a record loses it, and the frames after it until the next keyframe.

Jump to

Keyboard shortcuts

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