moq

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package moq implements the wire-protocol codec for MoQ Transport (draft-ietf-moq-transport-15), including control message parsing and serialization, media format conversion (Annex B → AVC1, ADTS stripping, decoder configuration records), and typed error definitions.

This package contains no session or relay logic; those higher-level concerns live in github.com/zsiec/prism/distribution.

Index

Constants

View Source
const (
	MsgSubscribe      uint64 = 0x03
	MsgSubscribeOK    uint64 = 0x04
	MsgSubscribeError uint64 = 0x05
	MsgUnsubscribe    uint64 = 0x0a
	MsgGoAway         uint64 = 0x10
	MsgMaxRequestID   uint64 = 0x15
	MsgClientSetup    uint64 = 0x20
	MsgServerSetup    uint64 = 0x21
)

MoQ Transport draft-15 message type IDs.

View Source
const (
	ParamPath         uint64 = 0x01 // odd → length-prefixed byte string
	ParamMaxRequestID uint64 = 0x02 // even → varint value
)

Setup parameter keys (draft-15 §6.2).

View Source
const (
	FilterNextGroupStart uint64 = 0x01
	FilterLatestObject   uint64 = 0x02
	FilterAbsoluteStart  uint64 = 0x03
	FilterAbsoluteRange  uint64 = 0x04
)

Subscribe filter types (draft-15 §6.6).

View Source
const (
	GroupOrderDefault    byte = 0x00
	GroupOrderAscending  byte = 0x01
	GroupOrderDescending byte = 0x02
)

Group order values (draft-15 §6.6).

View Source
const Version uint64 = 0xff00000f

Version is the MoQ Transport version: draft-15 uses 0xff000000 + draft number.

Variables

View Source
var (
	ErrVersionMismatch   = errors.New("moq: no compatible version")
	ErrUnknownTrack      = errors.New("moq: unknown track")
	ErrUnsupportedFilter = errors.New("moq: unsupported filter type")
	ErrUnknownNamespace  = errors.New("moq: unknown namespace")
)

Sentinel errors for MoQ session handling. These enable callers to programmatically distinguish failure modes using errors.Is.

Functions

func AnnexBToAVC1

func AnnexBToAVC1(nalus [][]byte) []byte

AnnexBToAVC1 converts Annex B NALUs (4-byte start code prefixed) to AVC1 format (4-byte big-endian length prefixed). Each NALU in the input slice is expected to start with a 4-byte start code (0x00 0x00 0x00 0x01).

func AppendNamespaceTuple

func AppendNamespaceTuple(buf []byte, parts []string) []byte

AppendNamespaceTuple appends a namespace tuple to buf.

func BuildAVCDecoderConfig

func BuildAVCDecoderConfig(sps, pps []byte) []byte

BuildAVCDecoderConfig builds an AVCDecoderConfigurationRecord (ISO 14496-15 §5.2.4.1.1) from raw SPS and PPS NAL data (without start codes). The SPS must include the NAL header byte (0x67).

func BuildHEVCDecoderConfig

func BuildHEVCDecoderConfig(vps, sps, pps []byte) []byte

BuildHEVCDecoderConfig builds an HEVCDecoderConfigurationRecord (ISO 14496-15 §8.3.3.1.2) from raw VPS, SPS, and PPS NAL data (without start codes). The SPS must include the 2-byte NAL header.

func ReadControlMsg

func ReadControlMsg(r io.Reader) (uint64, []byte, error)

ReadControlMsg reads a MoQ control message from the control stream. Wire format: [message_type (varint)] [message_length (uint16 big-endian)] [payload].

func SerializeGoAway

func SerializeGoAway(ga GoAway) []byte

SerializeGoAway serializes a GOAWAY payload.

func SerializeMaxRequestID

func SerializeMaxRequestID(reqID uint64) []byte

SerializeMaxRequestID serializes a MAX_REQUEST_ID payload.

func SerializeServerSetup

func SerializeServerSetup(ss ServerSetup) []byte

SerializeServerSetup serializes a SERVER_SETUP payload.

func SerializeSubscribeError

func SerializeSubscribeError(se SubscribeError) []byte

SerializeSubscribeError serializes a SUBSCRIBE_ERROR payload.

func SerializeSubscribeOK

func SerializeSubscribeOK(sok SubscribeOK) []byte

SerializeSubscribeOK serializes a SUBSCRIBE_OK payload.

func StripADTS

func StripADTS(data []byte) []byte

StripADTS removes the ADTS header from a complete ADTS frame, returning the raw AAC payload. Returns the input unchanged if it is not a valid ADTS frame.

func WriteControlMsg

func WriteControlMsg(w io.Writer, msgType uint64, payload []byte) error

WriteControlMsg writes a MoQ control message to the control stream as a single Write call to ensure atomicity even without external synchronization.

Types

type ClientSetup

type ClientSetup struct {
	Versions     []uint64
	Path         string
	MaxRequestID uint64
	HasPath      bool
}

ClientSetup is the first message sent by a MoQ client.

func ParseClientSetup

func ParseClientSetup(data []byte) (ClientSetup, error)

ParseClientSetup parses a CLIENT_SETUP payload.

type GoAway

type GoAway struct {
	NewSessionURI string
}

GoAway signals a graceful session shutdown.

type MaxRequestIDMsg

type MaxRequestIDMsg struct {
	RequestID uint64
}

MaxRequestIDMsg updates the peer's request ID quota.

type ParseError

type ParseError struct {
	Field string
	Err   error
}

ParseError indicates a failure to parse a MoQ control message field. It wraps the underlying I/O or format error and records which field was being parsed when the error occurred.

func (*ParseError) Error

func (e *ParseError) Error() string

func (*ParseError) Unwrap

func (e *ParseError) Unwrap() error

type ServerSetup

type ServerSetup struct {
	SelectedVersion uint64
	MaxRequestID    uint64
}

ServerSetup is the response to a ClientSetup.

type Subscribe

type Subscribe struct {
	RequestID  uint64
	Namespace  []string
	TrackName  string
	Priority   byte
	GroupOrder byte
	Forward    byte
	FilterType uint64
	StartGroup uint64 // only for AbsoluteStart / AbsoluteRange
	StartObj   uint64 // only for AbsoluteStart / AbsoluteRange
	EndGroup   uint64 // only for AbsoluteRange
}

Subscribe requests delivery of a track.

func ParseSubscribe

func ParseSubscribe(data []byte) (Subscribe, error)

ParseSubscribe parses a SUBSCRIBE payload.

type SubscribeError

type SubscribeError struct {
	RequestID    uint64
	ErrorCode    uint64
	ReasonPhrase string
}

SubscribeError rejects a subscription.

type SubscribeOK

type SubscribeOK struct {
	RequestID     uint64
	TrackAlias    uint64
	Expires       uint64
	GroupOrder    byte
	ContentExists bool
	LargestGroup  uint64 // only when ContentExists
	LargestObj    uint64 // only when ContentExists
}

SubscribeOK confirms a subscription.

type Unsubscribe

type Unsubscribe struct {
	RequestID uint64
}

Unsubscribe cancels a subscription.

func ParseUnsubscribe

func ParseUnsubscribe(data []byte) (Unsubscribe, error)

ParseUnsubscribe parses an UNSUBSCRIBE payload.

Jump to

Keyboard shortcuts

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