tstream

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

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

Go to latest
Published: May 11, 2023 License: ISC Imports: 7 Imported by: 0

Documentation

Overview

Package tstream implements encoding and decoding of MPEG transport streams as specified in ISO/IEC 13818-1.

Index

Constants

View Source
const (
	ScrambleNone = 0 + iota
	ScrambeReserved
	ScrambleEvenKey
	ScrambleOddKey
)
View Source
const PacketSize int = 188

PacketSize is the number of bytes in a single MPEG-TS packet.

Variables

View Source
var ErrBadPacket error = errors.New("malformed packet")
View Source
var ErrNoData error = errors.New("no data in packet")

Functions

func Marshal

func Marshal(p *Packet) ([]byte, error)

Marshal returns the packed wire-format encoding of p.

func Unmarshal

func Unmarshal(buf []byte, p *Packet) error

Unmarshal reads an encoded packet from buf and stores it in the packet pointed to by p. The provided slice must have a length of PacketSize.

Types

type AdaptationField

type AdaptationField struct {
	Header AdaptationHeader
	PCR    *ClockRef
	OPCR   *ClockRef
	// contains filtered or unexported fields
}

type AdaptationHeader

type AdaptationHeader struct {
	Length        uint8
	Discontinuity bool
	RandomAccess  bool
	Priority      bool
	// Reports whether a program clock reference is set in the
	HasPCR               bool
	HasOPCR              bool
	SplicingPoint        bool
	TransportPrivateData bool
	Extensions           bool
}

type ClockRef

type ClockRef [6]byte

A ClockRef holds a duration as the number of ticks of a 27MHz clock, most commonly used as the value of a Program Clock Reference (PCR).

func ToPCR

func ToPCR(dur time.Duration) ClockRef

func (ClockRef) Duration

func (c ClockRef) Duration() time.Duration

func (ClockRef) Ticks

func (c ClockRef) Ticks() uint64

Returns the clock reference as the number of ticks of a 27MHz clock.

type Decoder

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

A Decoder reads and decodes MPEG-TS packets from an input stream using its own internal buffering.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new decoder that reads from r.

func (*Decoder) Decode

func (dec *Decoder) Decode(p *Packet) error

Decode reads and parses the next packet from its input and stores it in the packet pointed to by p. EOF is returned when there is no more input.

type Header struct {

	// Indicates whether the packet's payload is erroneous.
	// If true, the payload is likely to be discarded by players.
	Error bool
	// Indicates if a PES packet is present in the payload.
	PayloadStart bool
	Priority     bool
	PacketID     uint16
	Scramble     uint8
	// Also known as the payload unit start indicator (PUSI).
	HasPayload         bool
	HasAdaptationField bool
	ContinuityCounter  uint8
	// contains filtered or unexported fields
}

A Header contains metadata of a Packet.

type PESFlags

type PESFlags struct {

	// Scrambling holds a 2-bit field representing...
	Scrambling uint8
	Priority   bool
	Aligned    bool
	Copyright  bool
	Original   bool
	HasPTS     bool
	HasDTS     bool
	// Indicates presence of Element stream clock reference
	HasClockRef bool
	// Indicates presence of Element stream rate
	HasStreamRate bool
	HasTrickMode  bool
	HasCopyInfo   bool
	HasCRC        bool
	HasExtensions bool

	HeaderLength uint8
	// contains filtered or unexported fields
}

PESFlags indicates what data is present in PES header fields.

type PESHeader

type PESHeader struct {
	StreamID uint8
	// Holds the number of bytes in the PES packet.
	// TODO(otl): does this include or exclude bytes in Fields?
	PacketLength uint16

	// Optional fields; may be nil.
	Flags  *PESFlags
	Fields *PESHeaderFields
	// contains filtered or unexported fields
}

PESHeader contains metadata on the contents of a PES packet.

type PESHeaderFields

type PESHeaderFields struct {
	// Holds the presentation timestamp; the number of ticks of a 90KHz clock.
	PTS Timestamp
	// Holds the decoder timestamp. This is usually not required.
	// Even if it is set, it usually holds the same value as PTS.
	DTS Timestamp
	// Holds the Digital Storage Media trick mode configuration.
	TrickMode uint8
	// CopyInfo     *CopyInfo
	Extensions uint8
	Stuffing   []byte
	// contains filtered or unexported fields
}

PESHeaderFields represents the parsed values of header fields set in a PES header.

type PESPacket

type PESPacket struct {
	Header *PESHeader
	Data   []byte
}

PESPacket represents a packetized elementary stream (PES) packet. PES packets are encapsulated in the payloads of MPEG-TS packets.

type Packet

type Packet struct {
	// Header contains this Packet's metadata.
	Header Header
	// Holds the optional adaptation field in its native binary-encoded format.
	// If nil, the packet has no adapation field.
	AdaptationField *AdaptationField
	// Contains the raw payload, excluding the adapation field if present.
	Payload []byte
	// PES holds a decoded packet elementary stream (PES) packet if one is
	// encapsulated in Payload.
	PES *PESPacket
}

A Packet represents a fixed-length MPEG Transport Stream packet.

type Scanner

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

A Scanner provides a way to incrementally read through a stream of Packets. A Scanner must be created with NewScanner.

func NewScanner

func NewScanner(r io.Reader) *Scanner

func (*Scanner) Err

func (sc *Scanner) Err() error

Err returns the most recent error the scanner encountered while reading from its input.

func (*Scanner) Packet

func (sc *Scanner) Packet() (*Packet, error)

Packet returns the Packet in the scanner's buffer.

func (*Scanner) Scan

func (sc *Scanner) Scan() bool

Scan advances the scanner to the next packet from its input. It returns false when there is no more input, or on error. To access the error, use Err().

type Timestamp

type Timestamp [5]byte

Timestamp holds a presentation or decode timestamp (PTS/DTS) in wire format. It is a binary encoding of 32-bit unsigned integers using 5 bytes, with some padding. Using "." as the bits of a PTS/DTS, a timestamp is encoded like so:

0b0010...1...............1...............1

func ToDTS

func ToDTS(dur time.Duration) Timestamp

func ToPTS

func ToPTS(dur time.Duration, withDTS bool) Timestamp

ToPTS returns the given duration as a packed Timestamp ready for transport in a PES packet. If a DTS is expected to also be present in the same packet, withDTS should be true.

func (Timestamp) Duration

func (ts Timestamp) Duration() time.Duration

func (Timestamp) Ticks

func (ts Timestamp) Ticks() int

Ticks returns the timestamp as the number of ticks of a 90KHz clock.

Jump to

Keyboard shortcuts

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