asf

package
v0.0.0-...-192e0e1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package asf demuxes the Advanced Systems Format container, the .wma/.asf file Windows Media Audio ships in: a flat tree of GUID-tagged objects (header, data, index) whose Data Object holds a run of fixed-size packets, each carrying one or more payload fragments that reassemble into media objects. One media object is one codec packet, which for WMA is one super-frame.

ASF names positions in milliseconds, not samples, so unlike the formats whose frames can be counted this container cannot state an exact sample position for anything: Track.Samples comes from the File Properties Object's play duration and SamplesExact stays false, and a packet's PTS is its millisecond presentation time converted at the track rate. That is also why seeking lands on a packet boundary at or before the target and backs up far enough to cover a whole media object: WMA's bit reservoir carries state across super-frames, so the landing owes the decoder run-up, and format.Media's pre-roll takes it from there.

The package is named asf rather than wma because ASF is the container and WMA the codec inside it (the flacn and wv precedent). The public container name and error prefix are "wma" either way, since that is the driver name the registry advertises.

Hostile-input invariants (ADR-0005): the object tree is walked, never recursed on attacker-chosen depth -- the Header Object's children are dispatched to named parsers and every unrecognized object, the Header Extension included, is treated as a leaf and skipped by its own declared size. Every size is validated against the bytes remaining before any slice or allocation, the header is read once into a bounded buffer, table and tag growth is capped, and each parse loop consumes input so none can spin.

Index

Constants

View Source
const MatchNeed = 16

MatchNeed is how many leading bytes Match inspects.

Variables

This section is empty.

Functions

func Match

func Match(head []byte) bool

Match reports whether head begins with the ASF Header Object GUID. It is the format sniff-table entry.

Types

type Demuxer

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

Demuxer reads one audio stream from an ASF source, emitting one packet per media object.

func NewDemuxer

func NewDemuxer(src container.Source, opts *DemuxerOptions) (*Demuxer, error)

NewDemuxer parses an ASF header and positions on the first data packet. The returned Demuxer implements container.Seeker, container.Warner, and container.Tagger.

func (*Demuxer) ReadPacket

func (d *Demuxer) ReadPacket(pkt *container.Packet) error

ReadPacket delivers the next media object. Data is borrowed until the next call, the container.Demuxer contract's own bound: the following call shifts the lookahead down and reads into the buffer handed out here.

func (*Demuxer) SeekSample

func (d *Demuxer) SeekSample(track int, sample int64) (int64, error)

SeekSample repositions to a packet boundary at or before the target and returns the position reads resume at.

func (*Demuxer) Tags

func (d *Demuxer) Tags() map[string][]string

Tags returns the canonical tags parsed from the header's two tag objects.

func (*Demuxer) Tracks

func (d *Demuxer) Tracks() []container.Track

Tracks returns the selected audio track.

func (*Demuxer) Warnings

func (d *Demuxer) Warnings() []container.Warning

Warnings returns the tolerated oddities seen so far.

type DemuxerOptions

type DemuxerOptions struct {
	// Strict turns tolerated damage (the Warnings list) into errors.
	Strict bool
}

DemuxerOptions configures parsing.

Jump to

Keyboard shortcuts

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