ogg

package module
v0.0.0-...-ca16305 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2020 License: MIT Imports: 5 Imported by: 0

README

Package ogg implements encoding and decoding of OGG streams as defined in http://xiph.org/ogg/doc/rfc3533.txt and http://xiph.org/ogg/doc/framing.html .

GoDoc

Build Status

Test Coverage

Documentation

Overview

Package ogg implements encoding and decoding of OGG streams as defined in http://xiph.org/ogg/doc/rfc3533.txt and http://xiph.org/ogg/doc/framing.html .

Index

Constants

View Source
const (
	// Continuation of packet
	COP byte = 1 + iota
	// Beginning of stream
	BOS = 1 << iota
	// End of stream
	EOS = 1 << iota
)
View Source
const HeaderSize = 27
View Source
const MIMEType = "application/ogg"

The MIME type as defined in RFC 3534.

View Source
const MaxPacketSize = MaxSegmentSize * 255

max packet size

View Source
const MaxSegmentSize = 255

max segment size

Variables

View Source
var ErrBadSegs = errors.New("invalid segment table size")

ErrBadSegs is the error used when trying to decode a page with a segment table size less than 1.

Functions

This section is empty.

Types

type Decoder

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

A Decoder decodes an ogg stream page-by-page with its Decode method.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder creates an ogg Decoder.

func (*Decoder) Decode

func (d *Decoder) Decode() (Page, error)

Decode reads from d's Reader to the next ogg page, then returns the decoded Page or an error. The error may be io.EOF if that's what the Reader returned.

The buffer underlying the returned Page's Packet is owned by the Decoder. It may be overwritten by subsequent calls to Decode.

It is safe to call Decode concurrently on distinct Decoders if their Readers are distinct. Otherwise, the behavior is undefined.

type Encoder

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

An Encoder encodes raw bytes into an ogg stream.

func NewEncoder

func NewEncoder(id uint32, w io.Writer) *Encoder

NewEncoder creates an ogg encoder with the given serial ID. Multiple Encoders can be used to encode multiplexed logical streams by giving them distinct IDs. Users must be sure to encode the streams as specified by the ogg RFC: When Grouping, all BOS pages must come before the data and EOS pages, with the order of BOS pages defined by the encapsulated encoding. When Chaining, the EOS page of the first stream must be immediately followed by the BOS of the second stream, and so on.

For more details, see http://xiph.org/ogg/doc/rfc3533.txt and http://xiph.org/ogg/doc/framing.html

func (*Encoder) Encode

func (w *Encoder) Encode(granule int64, packet []byte) error

Encode writes a data packet to the ogg stream, using the provided granule position. If the packet is larger than can fit in a page, it is split into multiple pages with the continuation-of-packet flag set.

func (*Encoder) EncodeBOS

func (w *Encoder) EncodeBOS(granule int64, packet []byte) error

EncodeBOS writes a beginning-of-stream packet to the ogg stream, using the provided granule position. If the packet is larger than can fit in a page, it is split into multiple pages with the continuation-of-packet flag set.

func (*Encoder) EncodeEOS

func (w *Encoder) EncodeEOS() error

EncodeEOS writes an end-of-stream packet to the ogg stream.

type ErrBadCrc

type ErrBadCrc struct {
	Found    uint32
	Expected uint32
}

ErrBadCrc is the error used when an ogg page's CRC field does not match the CRC calculated by the Decoder.

func (ErrBadCrc) Error

func (bc ErrBadCrc) Error() string

type PacketDecoder

type PacketDecoder struct {
	D *Decoder
	// contains filtered or unexported fields
}

PacketDecoder wraps around a decoder to easily read indiv packets

func NewPacketDecoder

func NewPacketDecoder(d *Decoder) *PacketDecoder

func (*PacketDecoder) Decode

func (p *PacketDecoder) Decode() (packet []byte, newPage Page, err error)

func (*PacketDecoder) DecodeChan

func (p *PacketDecoder) DecodeChan(packetChan chan []byte, errorChan chan error)

type Page

type Page struct {
	// Type is a bitmask of COP, BOS, and/or EOS.
	Type byte
	// Serial is the bitstream serial number.
	Serial uint32
	// Granule is the granule position, whose meaning is dependent on the encapsulated codec.
	Granule int64

	Page  uint32 // 18-21, sequence number of page in packet
	Crc   uint32 // 22-25
	Nsegs byte   // 26

	SegTbl []byte

	// Data is the raw packet data.
	// If Type & COP != 0, this is a continuation of the previous page's packet.
	Data []byte
	// contains filtered or unexported fields
}

A Page represents a logical ogg page.

func (*Page) ReadPacket

func (p *Page) ReadPacket() (packet []byte, complete bool, err error)

ReadPacket reads the next packet or returns io.EOF if no more. Complete is false when the the packet was uncomplete (it was the last one and will continue next page)

Jump to

Keyboard shortcuts

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