psi

package
Version: v0.0.0-...-c0b8c9c Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2021 License: MIT Imports: 9 Imported by: 8

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)
	AVC_VIDEO          uint8 = 40  // 0010 1000 (0x28)
	STREAM_IDENTIFIER  uint8 = 82  // 0101 0010 (0x52)
	EXTENSION          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 (
	TTML_PURPOSE_SAME_LANG_DIALOGUE                       uint8 = 0  // 0000 0000 (0x00)
	TTML_PURPOSE_OTHER_LANG_DIALOGUE                      uint8 = 1  // 0000 0001 (0x01)
	TTML_PURPOSE_ALL_DIALOGUE                             uint8 = 2  // 0000 0010 (0x02)
	TTML_PURPOSE_HARD_OF_HEARING                          uint8 = 16 // 0001 0000 (0x10)
	TTML_PURPOSE_OTHER_LANG_DIALOGUE_WITH_HARD_OF_HEARING uint8 = 17 // 0001 0001 (0x11)
	TTML_PURPOSE_ALL_DIALOGUE_WITH_HARD_OF_HEARING        uint8 = 18 // 0001 0010 (0x12)
	TTML_PURPOSE_AUDIO_DESCRIPTION                        uint8 = 48 // 0011 0000 (0x30)
	TTML_PURPOSE_CONTENT_RELATED_COMMENTARY               uint8 = 49 // 0011 0001 (0x31)
)
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
)

Stream type constants

View Source
const (
	// PatPid is the PID of a PAT. By definition this value is zero.
	PatPid = 0
)
View Source
const PidNotFound int = 1<<16 - 1
View Source
const (
	TTML_DESC_TAG_EXTENSION uint8 = 32 // 0010 0000 (0x20)
)

Descriptor tag extension

Variables

This section is empty.

Functions

func CanBuildPMT

func CanBuildPMT(payload []byte, sectionLength uint16) bool

func ExtractCRC

func ExtractCRC(payload []byte) (uint32, error)

func FilterPMTPacketsToPids

func FilterPMTPacketsToPids(packets []*packet.Packet, pids []int) ([]*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[int]int
	SPTSpmtPID() (int, 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() []int
	VersionNumber() uint8
	CurrentNextIndicator() bool
	ElementaryStreams() []PmtElementaryStream
	RemoveElementaryStreams(pids []int)
	IsPidForStreamWherePresentationLagsEbp(pid int) bool
	String() string
	PIDExists(pid int) bool
}

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 int) (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() uint8
	IsTTMLDescTagExtension() bool
}

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() int
	Descriptors() []PmtDescriptor
	MaxBitRate() uint64
	IsTTMLSubtitling() bool
}

PmtElementaryStream represents an elementary stream inside a PMT

func NewPmtElementaryStream

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

NewPmtElementaryStream creates a new PmtElementaryStream.

type PmtStreamType

type PmtStreamType interface {
	StreamType() uint8
	StreamTypeDescription() string
	IsStreamWherePresentationLagsEbp() bool
	IsAudioContent() bool
	IsVideoContent() bool
	IsSCTE35Content() bool
	IsID3Content() bool
	IsPrivateContent() 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, error)

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
t or T : Toggle theme light dark auto
y or Y : Canonical URL