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 ¶
const ( // Continuation of packet COP byte = 1 + iota // Beginning of stream BOS = 1 << iota // End of stream EOS = 1 << iota )
const HeaderSize = 27
const MIMEType = "application/ogg"
The MIME type as defined in RFC 3534.
const MaxPacketSize = MaxSegmentSize * 255
max packet size
const MaxSegmentSize = 255
max segment size
Variables ¶
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 (*Decoder) Decode ¶
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 ¶
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 ¶
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.
type ErrBadCrc ¶
ErrBadCrc is the error used when an ogg page's CRC field does not match the CRC calculated by the Decoder.
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.