psi

package
v0.0.0-...-1989dba Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package psi provides mechanisms for collecting and querying program specific information in an MPEG transport stream.

Index

Constants

View Source
const (
	// Pointerfield(1) + table id(1) + flags(.5) + section length (2.5)
	PSIHeaderLen uint16 = 4
	CrcLen       uint16 = 4
)

Unaccounted bytes before the end of the SectionLength field

View Source
const (
	VIDEO_STREAM       uint8 = 2   // 0000 0010 (0x02)
	AUDIO_STREAM       uint8 = 3   // 0000 0011 (0x03)
	REGISTRATION       uint8 = 5   // 0000 1000 (0x05)
	CONDITIONAL_ACCESS uint8 = 9   // 0000 1001 (0x09)
	LANGUAGE           uint8 = 10  // 0000 1010 (0x0A)
	SYSTEM_CLOCK       uint8 = 11  // 0000 1011 (0x0B)
	DOLBY_DIGITAL      uint8 = 12  // 0000 1100 (0x0C)
	COPYRIGHT          uint8 = 13  // 0000 1101 (0x0D)
	MAXIMUM_BITRATE    uint8 = 14  // 0000 1110 (0x0E)
	METADATA           uint8 = 38  // 0010 0110 (0x26)
	AVC_VIDEO          uint8 = 40  // 0010 1000 (0x28)
	STREAM_IDENTIFIER  uint8 = 82  // 0101 0010 (0x52)
	TTML_SUBTITLING    uint8 = 127 // 0111 1111 (0x7F)
	SCTE_ADAPTATION    uint8 = 151 // 1001 0111 (0x97)
	DOLBY_VISION       uint8 = 176 // 1011 0000 (0xB0)
	EBP                uint8 = 233 // 1110 1001 (0xE9)
	EC3                uint8 = 204 // 1100 1100 (0xCC)
)

Program Element Stream Descriptor Type.

View Source
const (
	AUDIO_UNDEFINED   int = 0   // 0000 0000 (0x00)
	AUDIO_DESCRIPTION int = 3   // 0000	0011 (0x03)
	AUDIO_PRIMARY     int = 128 // 1000 0000 (0x80)
)

ISO_639 Audio service type

View Source
const (
	// BitsPerByte is the number of bits in a byte
	BitsPerByte = 8
	// MaxBitRateBytesPerSecond is the maximum bit rate per second in a profile
	MaxBitRateBytesPerSecond = 50
)
View Source
const (
	PmtStreamTypeMpeg2VideoH262 uint8 = 2  // H262
	PmtStreamTypeMpeg4Video     uint8 = 27 // H264
	PmtStreamTypeMpeg4VideoH264 uint8 = 27 // H264
	PmtStreamTypeMpeg4VideoH265 uint8 = 36 // H265

	PmtStreamTypeAac uint8 = 15  // AAC
	PmtStreamTypeAc3 uint8 = 129 // DD
	PmtStreamTypeEc3 uint8 = 135 // DD+

	PmtStreamTypeScte35 uint8 = 134 // SCTE-35

	PmtStreamTypeID3 uint8 = 21 // Nielsen ID3

	PmtStreamTypePrivateContent uint8 = 6  // Private Content
	PmtStreamTypeMetadata       uint8 = 21 // Metadata in PES packets
)

Stream type constants

View Source
const (
	// PatPid is the PID of a PAT. By definition this value is zero.
	PatPid = uint16(0)
)

Variables

This section is empty.

Functions

func FilterPMTPacketsToPids

func FilterPMTPacketsToPids(packets []*packet.Packet, pids []uint16) ([]*packet.Packet, error)

FilterPMTPacketsToPids filters the PMT contents of the provided packet to the PIDs provided and returns a new packet(s). For example: if the provided PMT has PIDs 101, 102, and 103 and the provided PIDs are 101 and 102,

the new PMT will have only descriptors for PID 101 and 102. The descriptor for PID 103 will be stripped from the new PMT packet.

Returns packets and nil error if all pids are present in the PMT. Returns packets and non-nil error if some pids are present in the PMT. Returns nil packets and non-nil error if none of the pids are present in the PMT.

func IsPMT

func IsPMT(pkt *packet.Packet, pat PAT) (bool, error)

IsPMT returns true if the provided packet is a PMT defined by the PAT provided. Returns ErrNilPAT if pat is nil, or any error encountered in parsing the PID of pkt.

func NewPointerField

func NewPointerField(size int) []byte

NewPointerField will return a new pointer field with stuffing as raw bytes. The pointer field specifies where the TableHeader should start. Everything in between the pointer field and table header should be bytes with the value 0xFF.

func PmtAccumulatorDoneFunc

func PmtAccumulatorDoneFunc(b []byte) (bool, error)

PmtAccumulatorDoneFunc is a doneFunc that can be used for packet accumulation to create a PMT

func PointerField

func PointerField(psi []byte) uint8

func PrivateIndicator

func PrivateIndicator(psi []byte) bool

PrivateIndicator returns true if the psi contains private data

func SectionLength

func SectionLength(psi []byte) uint16

SectionLength returns the psi section length

func SectionSyntaxIndicator

func SectionSyntaxIndicator(psi []byte) bool

SectionSyntaxIndicator returns true if the psi contains section syntax

func TableID

func TableID(psi []byte) uint8

TableID returns the psi table header table id

Types

type PAT

type PAT interface {
	NumPrograms() int
	ProgramMap() map[uint16]uint16
	SPTSpmtPID() (uint16, error)
}

PAT interface represents operations on a Program Association Table. Currently only single program transport streams (SPTS)are supported

func NewPAT

func NewPAT(patBytes []byte) (PAT, error)

NewPAT constructs a new PAT from the provided bytes. patBytes should be concatenated packet payload contents. If a 188 byte slice is passed in, NewPAT tries to help and treats it as TS packet and builds a PAT from the packet payload.

func ReadPAT

func ReadPAT(r io.Reader) (PAT, error)

ReadPAT extracts a PAT from a reader of a TS stream. It will read until a PAT packet is found or EOF is reached. It returns a new PAT object parsed from the packet, if found, and otherwise returns an error.

type PMT

type PMT interface {
	Pids() []uint16
	IsPidForStreamWherePresentationLagsEbp(pid uint16) bool
	ElementaryStreams() []PmtElementaryStream
	RemoveElementaryStreams(pids []uint16)
	String() string
	PIDExists(pid uint16) bool
	VideoPid() uint16
	KlvPid() uint16
}

PMT is a Program Map Table.

func NewPMT

func NewPMT(pmtBytes []byte) (PMT, error)

NewPMT Creates a new PMT from the given bytes. pmtBytes should be concatenated packet payload contents.

func ReadPMT

func ReadPMT(r io.Reader, pid uint16) (PMT, error)

ReadPMT extracts a PMT from a reader of a TS stream. It will read until PMT packet(s) are found or EOF is reached. It returns a new PMT object parsed from the packet(s), if found, and otherwise returns an error.

type PmtDescriptor

type PmtDescriptor interface {
	Tag() uint8
	Format() string
	IsIso639LanguageDescriptor() bool
	IsMaximumBitrateDescriptor() bool
	IsIFrameProfile() bool
	IsEBPDescriptor() bool
	DecodeMaximumBitRate() uint32
	DecodeIso639LanguageCode() string
	DecodeIso639AudioType() byte
	IsDolbyATMOS() bool
	IsDolbyVision() bool
	DecodeDolbyVisionCodec(string) string
	IsTTMLSubtitlingDescriptor() bool
	DecodeTTMLIso639LanguageCode() string
	DecodeTTMLSubtitlePurpose() uint
}

PmtDescriptor represents operations currently necessary on descriptors found in the PMT

func NewPmtDescriptor

func NewPmtDescriptor(tag uint8, data []byte) PmtDescriptor

NewPmtDescriptor creates a new PMTDescriptor with the provided tag and byte contents.

type PmtElementaryStream

type PmtElementaryStream interface {
	PmtStreamType
	ElementaryPid() uint16
	Descriptors() []PmtDescriptor
	MaxBitRate() uint64
}

PmtElementaryStream represents an elementary stream inside a PMT

func NewPmtElementaryStream

func NewPmtElementaryStream(streamType uint8, elementaryPid uint16, descriptors []PmtDescriptor) PmtElementaryStream

NewPmtElementaryStream creates a new PmtElementaryStream.

type PmtStreamType

type PmtStreamType interface {
	StreamType() uint8
	StreamTypeDescription() string
	IsStreamWherePresentationLagsEbp() bool
	IsAudioContent() bool
	IsVideoContent() bool
	// IsKlvContent() bool
	IsSCTE35Content() bool
	IsID3Content() bool
	IsPrivateContent() bool
	IsSyncKlvContent() bool
	IsAsyncKlvContent() bool
}

PmtStreamType is used to represent elementary steam type inside a PMT

func LookupPmtStreamType

func LookupPmtStreamType(code uint8) PmtStreamType

LookupPmtStreamType returns the associated PmtStreamType of the provided code. If the code is not recognized, a PmtSteamType of "unknown" is returned.

type TableHeader

type TableHeader struct {
	TableID                uint8
	SectionSyntaxIndicator bool
	PrivateIndicator       bool
	SectionLength          uint16
}

TableHeader struct represents operations available on all PSI

func NewTableHeader

func NewTableHeader() TableHeader

NewPSI will create a PSI with default values of zero and false for everything

func TableHeaderFromBytes

func TableHeaderFromBytes(data []byte) TableHeader

PSIFromBytes returns the PSI struct from a byte slice

func (TableHeader) Data

func (th TableHeader) Data() []byte

Data returns the byte representation of the PSI struct.

Jump to

Keyboard shortcuts

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