oggreader

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 5 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 oggreader implements the Ogg media container reader

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewWith

func NewWith(in io.Reader) (*OggReader, *OggHeader, error)

NewWith returns a new Ogg reader and Ogg header with an io.Reader input.

Warning: NewWith only parses the first OpusHead (a single logical bitstream/track) and returns a single OggHeader. If you need to handle Ogg containers with multiple Opus headers/tracks, use NewWithOptions and scan pages (e.g. via ParseNextPage) to find and parse each OpusHead.

Types

type HeaderType

type HeaderType string
const (
	HeaderOpusID   HeaderType = "OpusHead"
	HeaderOpusTags HeaderType = "OpusTags"
)

type OggHeader

type OggHeader struct {
	ChannelMap   uint8
	Channels     uint8
	OutputGain   uint16
	PreSkip      uint16
	SampleRate   uint32
	Version      uint8
	StreamCount  uint8
	CoupledCount uint8
	// ChannelMapping we store it as a string to be comparable (maps/struct equality)
	// while still holding raw bytes.
	ChannelMapping string
}

OggHeader contains Opus codec metadata parsed from an Opus ID page. This header is extracted from an Ogg page payload that starts with the OpusHead signature (the first page of an Opus stream in an Ogg container).

Use OggPageHeader.OpusPacketType() to classify a page payload as OpusHead, and OggPageHeader.ParseOpusHeader() to parse the OpusHead payload.

https://tools.ietf.org/html/rfc7845.html#section-3

func ParseOpusHead

func ParseOpusHead(payload []byte) (*OggHeader, error)

ParseOpusHead parses an Opus head from the page payload.

type OggPageHeader

type OggPageHeader struct {
	GranulePosition uint64

	Serial uint32
	// contains filtered or unexported fields
}

OggPageHeader is the metadata for a Page Pages are the fundamental unit of multiplexing in an Ogg stream

https://tools.ietf.org/html/rfc7845.html#section-1

func (*OggPageHeader) HeaderType

func (p *OggPageHeader) HeaderType(payload []byte) (HeaderType, bool)

HeaderType classifies the page.

type OggReader

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

OggReader is used to read Ogg files and return page payloads.

func NewWithOptions

func NewWithOptions(in io.Reader, options ...Option) (*OggReader, error)

NewWithOptions returns a new Ogg reader.

func (*OggReader) ParseNextPage

func (o *OggReader) ParseNextPage() ([]byte, *OggPageHeader, error)

ParseNextPage reads from stream and returns Ogg page payload, header, and an error if there is incomplete page data.

func (*OggReader) ResetReader

func (o *OggReader) ResetReader(reset func(bytesRead int64) io.Reader)

ResetReader resets the internal stream of OggReader. This is useful for live streams, where the end of the file might be read without the data being finished.

type Option

type Option func(*OggReader) error

func WithDoChecksum

func WithDoChecksum(doChecksum bool) Option

WithDoChecksum is an option to set the doChecksum flag Default is true.

type OpusTags

type OpusTags struct {
	Vendor       string
	UserComments []UserComment
}

OpusTags is the metadata for an OpusTags page. https://www.xiph.org/vorbis/doc/v-comment.html

func ParseOpusTags

func ParseOpusTags(payload []byte) (*OpusTags, error)

ParseOpusTags parses an OpusTags from the page payload. https://datatracker.ietf.org/doc/html/rfc7845#section-5.2

type UserComment

type UserComment struct {
	Comment string
	Value   string
}

UserComment is a key-value pair of a vorbis comment.

Jump to

Keyboard shortcuts

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