frames

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 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 stream's access units over HTTP as length-prefixed records, for low-latency clients that feed a hardware decoder directly. No container or RTP; payloads are Annex B with 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

New subscribers start at a keyframe. A subscriber that falls behind skips to the next keyframe. 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.

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, flushing each one.

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. Forget the size until the camera sends it again.

func (*Stream) Frame

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

Frame implements stream.FrameSink. Never blocks; a full subscriber drops frames until the next keyframe.

Jump to

Keyboard shortcuts

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