psi

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: BSD-3-Clause Imports: 8 Imported by: 2

Documentation

Overview

Package psi provides functionality for read program specific information from MPEG transport stream.

Index

Constants

View Source
const (
	ZeroServiceType          = ServiceType(0x00)
	DigitalTelevisionService = ServiceType(0x01)
	DigitalRadioSoundService = ServiceType(0x02)
	TeletextService          = ServiceType(0x03)
	NVODReferenceService     = ServiceType(0x04)
	NVODTimeShiftedService   = ServiceType(0x05)
	MosaicService            = ServiceType(0x06)
	FMRadioService           = ServiceType(0x07)
	DVBSRMService            = ServiceType(0x08)

	AdvancedCodecDigitalRadioSoundService = ServiceType(0x0a)
	AdvancedCodecMosaicService            = ServiceType(0x0b)
	DataBroadcastService                  = ServiceType(0x0c)

	RCSMapService                   = ServiceType(0x0e)
	RCSFLSService                   = ServiceType(0x0f)
	DVBMHPService                   = ServiceType(0x10)
	MPEG2HDDigitalTelevisionService = ServiceType(0x11)

	H264SDDigitalTelevisionService             = ServiceType(0x16)
	H264SDNVODTimeShiftedService               = ServiceType(0x17)
	H264SDNVODReferenceService                 = ServiceType(0x18)
	H264HDDigitalTelevisionService             = ServiceType(0x19)
	H264HDNVODTimeShiftedService               = ServiceType(0x1a)
	H264HDNVODReferenceService                 = ServiceType(0x1b)
	H264StereoscopicHDDigitalTelevisionService = ServiceType(0x1c)
	H264StereoscopicHDNVODTimeShiftedService   = ServiceType(0x1d)
	H264StereoscopicHDNVODReferenceService     = ServiceType(0x1e)
	H265DigitalTelevisionService               = ServiceType(0x1f)
)
View Source
const (
	SectionMaxLen    = 4096
	ISOSectionMaxLen = 1024
)
View Source
const TDTSectionLen = 3 + 5

Variables

View Source
var (
	ErrPMTSectionSyntax = dvb.TemporaryError("incorrect PMT section syntax")
	ErrPMTProgInfoLen   = dvb.TemporaryError("incorrect PMT program info length")
)
View Source
var (
	ErrSectionLength   = dvb.TemporaryError("incorrect value of section_length field")
	ErrSectionPointer  = dvb.TemporaryError("incorrect pointer_field")
	ErrSectionSpace    = dvb.TemporaryError("no free space for section decoding")
	ErrSectionSyntax   = dvb.TemporaryError("section syntax indicator not set")
	ErrSectionCRC      = dvb.TemporaryError("section has incorrect CRC")
	ErrSectionReserved = dvb.TemporaryError("section has wrong value of header reserved bits")
	ErrSectionData     = dvb.TemporaryError("too few data to decode section")
)
View Source
var (
	ErrTableSectionNumber = dvb.TemporaryError("Table: incorrect section number")
	ErrTableSyntax        = dvb.TemporaryError("Table: incorrect section syntax")
)
View Source
var ErrBadMJDUTC = errors.New("bad MJD UTC time")
View Source
var ErrNITSectionLen = dvb.TemporaryError("incorrect NIT section length")
View Source
var ErrSDTSectionLen = dvb.TemporaryError("incorrect SDT section length")
View Source
var ErrTDTSectionSyntax = dvb.TemporaryError("incorrect TDT section syntax")
View Source
var ErrTOTSectionSyntax = dvb.TemporaryError("incorrect TOT section syntax")

Functions

func DecodeText

func DecodeText(s []byte) string

Decode treats s as text encoded according to EN 300 468 Annex A. It uses appropriate conversion according to selection byte

func EncodeText

func EncodeText(s string) []byte

func ParsePrivateDataSpecifier

func ParsePrivateDataSpecifier(d Descriptor) (pds uint32, ok bool)

func ParseTDT

func ParseTDT(s Section) (time.Time, error)

Types

type AudioType

type AudioType byte
const (
	UndefinedAudio AudioType = iota
	CleanEffectsAudio
	HearingImpairedAudio
	VisualImpairedCommentaryAudio
)

func (AudioType) String

func (t AudioType) String() string

type CADescriptor

type CADescriptor struct {
	Sys CAS
	Pid int16
}

func ParseCADescriptor

func ParseCADescriptor(d Descriptor) (cad CADescriptor, ok bool)

type CAS

type CAS uint16

func (CAS) String

func (cas CAS) String() string

type Descriptor

type Descriptor []byte

func MakeDescriptor

func MakeDescriptor(tag DescriptorTag, datalen int) Descriptor

func MakeNetworkNameDescriptor

func MakeNetworkNameDescriptor(netname string) Descriptor

func MakePrivateDataSpecifierDescriptor

func MakePrivateDataSpecifierDescriptor(pds uint32) Descriptor

func MakeServiceDescriptor

func MakeServiceDescriptor(typ ServiceType, provider, service string) Descriptor

func (Descriptor) Data

func (d Descriptor) Data() []byte

func (Descriptor) SetTag

func (d Descriptor) SetTag(tag DescriptorTag)

func (Descriptor) Tag

func (d Descriptor) Tag() DescriptorTag

type DescriptorList

type DescriptorList []byte

func (*DescriptorList) Alloc

func (dl *DescriptorList) Alloc(datalen int) Descriptor

Alloc allocates descriptor for datalen bytes of data + 2 bytes for tag and data length.

func (DescriptorList) Pop

func (dl DescriptorList) Pop() (d Descriptor, rdl DescriptorList)

Pop returns first descriptor in d and remaining descriptors in rdl. If there is no more descriptors len(rdl) == 0. If an error occurs d == nil.

type DescriptorTag

type DescriptorTag byte
const (
	VideoStreamTag                DescriptorTag = 0x02
	AudioStreamTag                DescriptorTag = 0x03 //PMT
	HierarchyTag                  DescriptorTag = 0x04
	RegistrationTag               DescriptorTag = 0x05 //PMT
	DataStreamAlignmentTag        DescriptorTag = 0x06
	TargetBackgroundGridTag       DescriptorTag = 0x07
	VideoWindowTag                DescriptorTag = 0x08
	CATag                         DescriptorTag = 0x09
	ISO639LangTag                 DescriptorTag = 0x0A //PMT
	SystemClockTag                DescriptorTag = 0x0B
	MultiplexBufferUtilizationTag DescriptorTag = 0x0C
	CopyrightTag                  DescriptorTag = 0x0D
	MaximumBitrateTag             DescriptorTag = 0x0E //PMT
	PrivateDataIndicatorTag       DescriptorTag = 0x0F
	SmoothingBufferTag            DescriptorTag = 0x10
	STDTag                        DescriptorTag = 0x11
	IBPTag                        DescriptorTag = 0x12

	MPEG4VideoTag      DescriptorTag = 0x1b
	MPEG4AudioTag      DescriptorTag = 0x1c
	IODTag             DescriptorTag = 0x1d
	SLTag              DescriptorTag = 0x1f
	FMCTag             DescriptorTag = 0x20
	ExternalESIDTag    DescriptorTag = 0x21
	MuxCodeTag         DescriptorTag = 0x22
	FmxBufferSizeTag   DescriptorTag = 0x23
	MultiplexBufferTag DescriptorTag = 0x24

	NetworkNameTag               DescriptorTag = 0x40 //NIT
	ServiceListTag               DescriptorTag = 0x41 //NIT
	StuffingTag                  DescriptorTag = 0x42
	SatelliteDeliverySystemTag   DescriptorTag = 0x43
	CableDeliverySystemTag       DescriptorTag = 0x44
	BouquetNameTag               DescriptorTag = 0x47
	ServiceTag                   DescriptorTag = 0x48
	CountryAvailabilityTag       DescriptorTag = 0x49
	LinkageTag                   DescriptorTag = 0x4A
	NVODReferenceTag             DescriptorTag = 0x4B
	TimeShiftedServiceTag        DescriptorTag = 0x4C
	ShortEventTag                DescriptorTag = 0x4D
	ExtendedEventTag             DescriptorTag = 0x4E
	TimeShiftedEventTag          DescriptorTag = 0x4F
	ComponentTag                 DescriptorTag = 0x50
	MosaicTag                    DescriptorTag = 0x51
	StreamIdentifierTag          DescriptorTag = 0x52 //PMT
	CAIdentifierTag              DescriptorTag = 0x53
	ContentTag                   DescriptorTag = 0x54
	ParentalRatingTag            DescriptorTag = 0x55
	TeletextTag                  DescriptorTag = 0x56
	TelephoneTag                 DescriptorTag = 0x57
	LocalTimeOffsetTag           DescriptorTag = 0x58
	SubtitlingTag                DescriptorTag = 0x59 //PMT
	TerrestrialDeliverySystemTag DescriptorTag = 0x5A //NIT
	MultilingualNetworkNameTag   DescriptorTag = 0x5B
	MultilingualBouquetNameTag   DescriptorTag = 0x5C
	MultilingualServiceNameTag   DescriptorTag = 0x5D
	MultilingualComponentTag     DescriptorTag = 0x5E
	PrivateDataSpecifierTag      DescriptorTag = 0x5F //NIT
	ServiceMoveTag               DescriptorTag = 0x60
	ShortSmoothingBufferTag      DescriptorTag = 0x61
	FrequencyListTag             DescriptorTag = 0x62 //NIT
	PartialTransportStreamTag    DescriptorTag = 0x63
	DataBroadcastTag             DescriptorTag = 0x64
	CASystemTag                  DescriptorTag = 0x65
	DataBroadcastIdTag           DescriptorTag = 0x66
	TransportStreamTag           DescriptorTag = 0x67
	DSNGTag                      DescriptorTag = 0x68
	PDCTag                       DescriptorTag = 0x69
	AC3Tag                       DescriptorTag = 0x6a //PMT
	AncillaryDataTag             DescriptorTag = 0x6b
	CellListTag                  DescriptorTag = 0x6c
	CellFrequencyLinkTag         DescriptorTag = 0x6d
	AnnouncementSupportTag       DescriptorTag = 0x6e
	ApplicationSignallingTag     DescriptorTag = 0x6f //PMT

	EnhancedAC3Tag DescriptorTag = 0x7a //PMT
	DTSTag         DescriptorTag = 0x7b
	AACTag         DescriptorTag = 0x7c

	LogicalChannelTag DescriptorTag = 0x83 //NIT
)

func (DescriptorTag) String

func (tag DescriptorTag) String() string

type ESInfo

type ESInfo []byte

func (ESInfo) Descriptors

func (i ESInfo) Descriptors() DescriptorList

func (ESInfo) Pid

func (i ESInfo) Pid() int16

func (ESInfo) SetPid

func (i ESInfo) SetPid(pid int16)

func (ESInfo) SetType added in v0.1.4

func (i ESInfo) SetType(typ StreamType)

func (ESInfo) Type

func (i ESInfo) Type() StreamType

type ESInfoList

type ESInfoList []byte

func (ESInfoList) Append

func (il ESInfoList) Append(i ESInfo) ESInfoList

Append adds i to the end of the il. It works like Go append function so need to be used in this way:

il = il.Append(i)

func (ESInfoList) Pop

func (il ESInfoList) Pop() (i ESInfo, ril ESInfoList)

Pop returns first elementary stream information element in i and remaining elements in ril. If there is no more elements then len(ril) == 0. If an error occurs i == nil.

type ISO639LangCode

type ISO639LangCode uint32

type ISO639LangDescriptor

type ISO639LangDescriptor []byte

func ParseISO639LangDescriptor

func ParseISO639LangDescriptor(d Descriptor) (ld ISO639LangDescriptor, ok bool)

func (ISO639LangDescriptor) Pop

Pop returns first (lc, at) pair from d. Remaining pairs are returned in rd. If there is no more pairs to read len(rd) == 0. If an error occurs rd = nil

type LocalTimeOffset

type LocalTimeOffset struct {
	Country      [3]byte   // ISO 3166 country identifier.
	Region       byte      // Region number in the country (6-bit).
	Offset       int       // Seconds east of UTC.
	TimeOfChange time.Time // Date and time (UTC) when the next time change.
	NextOffset   int       // Next offset (seconds east of UTC).
}

type LocalTimeOffsetDescriptor

type LocalTimeOffsetDescriptor []byte

func MakeLocalTimeOffsetDescriptor

func MakeLocalTimeOffsetDescriptor(n int) LocalTimeOffsetDescriptor

MakeLocalTimeOffsetDescriptor makes descriptor suitable for n time offsets.

func ParseLocalTimeOffsetDescriptor

func ParseLocalTimeOffsetDescriptor(d Descriptor) (tod LocalTimeOffsetDescriptor, ok bool)

func ParseTOT

func ParseTOT(s Section) (utc time.Time, tod LocalTimeOffsetDescriptor, err error)

func (LocalTimeOffsetDescriptor) MakeDescriptor

func (lto LocalTimeOffsetDescriptor) MakeDescriptor() Descriptor

func (LocalTimeOffsetDescriptor) Pop

Pop returns first LocalTimeOffset from d. Remaining offsets are returned in rd. If there is no more data to read len(rd) == 0. If an error occurs rd = nil.

func (LocalTimeOffsetDescriptor) Set

Update updates n-th time ofset in d.

type LogicalChannelDescriptor

type LogicalChannelDescriptor []byte

func ParseLogicalChannelDescriptor

func ParseLogicalChannelDescriptor(d Descriptor) (lcd LogicalChannelDescriptor, ok bool)

func (*LogicalChannelDescriptor) Append

func (LogicalChannelDescriptor) MakeDescriptor

func (lcd LogicalChannelDescriptor) MakeDescriptor() Descriptor

func (LogicalChannelDescriptor) Pop

Pop returns first LogicalChannelInfo from d. Remaining infos are returned in rd. If there is no more infos to read len(rd) == 0. If an error occurs rd = nil.

type LogicalChannelInfo

type LogicalChannelInfo struct {
	Sid     uint16 // Program Id
	LCN     int16  // Logical Channel Number
	Visible bool   // Should be visible on program list?
}

type MuxInfo

type MuxInfo []byte

func MakeMuxInfo

func MakeMuxInfo() MuxInfo

func (*MuxInfo) AppendDescriptor

func (mi *MuxInfo) AppendDescriptor(ds ...Descriptor)

func (MuxInfo) ClearDescriptors

func (mi MuxInfo) ClearDescriptors()

func (MuxInfo) Descriptors

func (mi MuxInfo) Descriptors() DescriptorList

func (MuxInfo) MuxId

func (mi MuxInfo) MuxId() uint16

func (MuxInfo) OrgNetId

func (mi MuxInfo) OrgNetId() uint16

func (MuxInfo) SetMuxId

func (mi MuxInfo) SetMuxId(tsid uint16)

func (MuxInfo) SetOrgNetId

func (mi MuxInfo) SetOrgNetId(onid uint16)

type MuxInfoList

type MuxInfoList struct {
	TableCursor
}

func (MuxInfoList) Pop

func (il MuxInfoList) Pop() (MuxInfo, MuxInfoList)

Pop returns first MuxInfo element from il. If there is no more data to read Pop returns empty ServiceInfoList. If an error occurs it returns nil MuxInfo and non-empty MuxInfoList.

type NIT

type NIT Table

func (*NIT) AppendMuxInfo

func (nit *NIT) AppendMuxInfo(mis ...MuxInfo)

AppendMuxInfos appends information about transport stream to nit.

func (*NIT) AppendNetDescriptor

func (nit *NIT) AppendNetDescriptor(ds ...Descriptor)

AppendNetDescriptors appends network descriptors ds to nit. It can be called only before first AppendMuxInfo call.

func (NIT) Close

func (nit NIT) Close(netid uint16, actualMux, current bool, version int8)

func (NIT) Current

func (nit NIT) Current() bool

func (NIT) Descriptors

func (nit NIT) Descriptors() TableDescriptors

Descriptors returns network descriptors list

func (NIT) MuxInfo

func (nit NIT) MuxInfo() MuxInfoList

func (NIT) NetId

func (nit NIT) NetId() uint16

func (*NIT) Update

func (nit *NIT) Update(r SectionReader, actualMux bool, current bool) error

Update reads next NIT from r

func (NIT) Version

func (nit NIT) Version() int8

type NetworkNameDescriptor

type NetworkNameDescriptor []byte

func ParseNetworkNameDescriptor

func ParseNetworkNameDescriptor(d Descriptor) (nnd NetworkNameDescriptor, ok bool)

type PAT

type PAT Table

func (*PAT) Append

func (pat *PAT) Append(progId uint16, pmtpid int16)

Append appends next program to PAT. After Append pat is in invalid state. Use Close to recalculate all section numbers and CRCs.

func (PAT) Close

func (pat PAT) Close(tsid uint16, current bool, version int8)

func (PAT) Current

func (pat PAT) Current() bool

func (PAT) FindPMT

func (pat PAT) FindPMT(progid uint16) (pmtpid int16)

FindPMT returns PMT PID for given progid. If there is no such progId it returns pid == ts.NullPid. If an error occurs FindPMT retuns -1

func (PAT) FindProgId

func (pat PAT) FindProgId(pmtpid int16) (progid uint16, ok bool)

FindProgId returns first found program number that corresponds to pmtpid. Returns ok == false if not found or error.

func (PAT) MuxId

func (pat PAT) MuxId() uint16

func (PAT) ProgramList

func (pat PAT) ProgramList() ProgramList

ProgramList returns list of programs

func (*PAT) SetEmpty

func (pat *PAT) SetEmpty()

func (*PAT) Update

func (pat *PAT) Update(r SectionReader, current bool) error

Update reads next PAT from r.

func (PAT) Version

func (pat PAT) Version() int8

type PMT

type PMT Section

func AsPMT

func AsPMT(s Section) (PMT, error)

AsPMT returns s as PMT or error if s isn't PMT section. This works because PMT should fit in one section (other tables occupy multiple sections.

func (PMT) Current

func (p PMT) Current() bool

func (PMT) ESInfo

func (p PMT) ESInfo() ESInfoList

func (PMT) Len

func (p PMT) Len() int

func (PMT) MakeCRC

func (p PMT) MakeCRC()

func (PMT) PidPCR

func (p PMT) PidPCR() int16

func (PMT) ProgId

func (p PMT) ProgId() uint16

func (PMT) ProgramDescriptors

func (p PMT) ProgramDescriptors() DescriptorList

func (PMT) Section

func (p PMT) Section() Section

func (PMT) SetPidPCR

func (p PMT) SetPidPCR(pid int16)

func (PMT) SetProgId

func (p PMT) SetProgId(sid uint16)

func (PMT) SetVersion

func (p PMT) SetVersion(v int8)

func (PMT) Update

func (p PMT) Update(r SectionReader) error

Update reads one section into p and runs AsPMT to check its syntax.

func (PMT) Version

func (p PMT) Version() int8

type ProgramList

type ProgramList struct {
	TableCursor
}

func (ProgramList) Pop

func (pl ProgramList) Pop() (progId uint16, pmtpid int16, rpl ProgramList)

Pop returns first (progId, pid) pair from pl. Remaining pairs are returned in rpl. If there is no more programs to read rpl is empty. If an error occurs pmtpid == -1

type SDT

type SDT Table

func (*SDT) Append

func (sdt *SDT) Append(onid uint16, si ServiceInfo)

func (SDT) Close

func (sdt SDT) Close(tsid uint16, actualMux, current bool, version int8)

func (SDT) Current

func (sdt SDT) Current() bool

func (SDT) MuxId

func (sdt SDT) MuxId() uint16

func (SDT) OrgNetId

func (sdt SDT) OrgNetId() uint16

OrgNetId returns original_network_id

func (SDT) ServiceInfo

func (sdt SDT) ServiceInfo() ServiceInfoList

Info returns list of ifnormation about services (programs)

func (*SDT) SetEmpty

func (sdt *SDT) SetEmpty()

func (*SDT) Update

func (sdt *SDT) Update(r SectionReader, actualMux bool, current bool) error

Update reads next SDT from r

func (SDT) Version

func (sdt SDT) Version() int8

type Section

type Section []byte

func MakeEmptySection

func MakeEmptySection(maxLen int, genericSyntax bool) Section

MakeEmptySection creates new empty, reseted section.

func (Section) Alloc

func (s Section) Alloc(n, m int) []byte

Alloc allocates n bytes in section. It returns nil if there is no room for n+m bytes. Alloc invalidates CRC sum if used. Use MakeCRC to recalculate it.

func (Section) CRC

func (s Section) CRC() uint32

func (Section) Cap

func (s Section) Cap() int

func (Section) CheckCRC

func (s Section) CheckCRC() bool

CheckCRC returns true if s.Len() is valid and CRC32 of whole section is correct

func (Section) Copy

func (s Section) Copy(sec Section)

Copy copies content of sec to s (sec.Len() bytes are copied from sec to s). It panics if len(s) < sec.Len().

func (Section) Current

func (s Section) Current() bool

Current returns the value of current_next_indicator field

func (Section) Data

func (s Section) Data() []byte

Data rturns data part of section.

func (Section) GenericSyntax

func (s Section) GenericSyntax() bool

GenericSyntax returns the value of section_syntax_indicator field

func (Section) LastNumber

func (s Section) LastNumber() byte

LastNumber returns the value of last_section_number field

func (Section) Len

func (s Section) Len() int

Len returns length of the whole section (section_length + 3) or -1 if section_length filed contains incorrect value

func (Section) MakeCRC

func (s Section) MakeCRC()

MakeCRC calculates CRC32 for whole section and uses it to set CRC_32 field

func (Section) Number

func (s Section) Number() byte

Number returns the value of section_number field

func (Section) PrivateSyntax

func (s Section) PrivateSyntax() bool

PrivateIndicator returns the value of private_syntax_indicator field

func (Section) Reserved

func (s Section) Reserved() int

func (Section) Reset

func (s Section) Reset()

Reset resets section s to contain all bits set to 1.

func (Section) SetCurrent

func (s Section) SetCurrent(c bool)

SetCurrent sets the value of current_next_indicator field

func (Section) SetEmpty

func (s Section) SetEmpty()

SetEmpty initializes section lenght, so s becomes empty. SetEmpty invalidates CRC sum. Use MakeCRC to recalculate it.

func (Section) SetGenericSyntax

func (s Section) SetGenericSyntax(si bool)

SetGenericSyntax sets the value of section_syntax_indicator field

func (Section) SetLastNumber

func (s Section) SetLastNumber(n byte)

SetLastNumber sets the value of last_section_number field

func (Section) SetNumber

func (s Section) SetNumber(n byte)

SetNumber sets the value of section_number field

func (Section) SetPrivateSyntax

func (s Section) SetPrivateSyntax(pi bool)

SetPrivateSyntax sets the value of private_syntax_indicator field

func (Section) SetTableId

func (s Section) SetTableId(id byte)

SetTableId sets the value of table_id field

func (Section) SetTableIdExt

func (s Section) SetTableIdExt(id uint16)

Set TableIdExt sets the value of table_id_extension

func (Section) SetVersion

func (s Section) SetVersion(v int8)

SetVersion sets the value of version_number field. It panic if v > 31

func (Section) String

func (s Section) String() string

func (Section) TableId

func (s Section) TableId() byte

TableId returns the value of table_id field

func (Section) TableIdExt

func (s Section) TableIdExt() uint16

TableIdExt returns the value of table_id_extension

func (Section) Version

func (s Section) Version() int8

Version returns the value of version_number field.

type SectionDecoder

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

SectionDecoder can decode section from stream of packets

func NewSectionDecoder

func NewSectionDecoder(r ts.PktReplacer, check bool) *SectionDecoder

NewSectionDecoder creates section decoder. You can use r == nil and set source of packets lather using SetPktReplacer or SetPktReader method. If check is true decoder checks value of reserved header bits and CRC.

func (*SectionDecoder) ReadSection

func (d *SectionDecoder) ReadSection(s Section) error

ReadSection decodes one section.

func (*SectionDecoder) Reset

func (d *SectionDecoder) Reset()

Reset resets internal state of decoder (discards possible buffered data for next section decoding)

func (*SectionDecoder) SetPktReader

func (d *SectionDecoder) SetPktReader(r ts.PktReader)

SetPktReader sets ts.PktReader that will be usea as data source

func (*SectionDecoder) SetPktReplacer

func (d *SectionDecoder) SetPktReplacer(r ts.PktReplacer)

SetPktReplacer sets ts.PktReplacer that will be used as data source

type SectionEncoder

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

SectionEncoder can encode sections into stream of MPEG-TS packets. It has one TS packet internal buffer and writes it down only when it need more space or Flush method is called.

func NewSectionEncoder

func NewSectionEncoder(r ts.PktReplacer, pid int16) *SectionEncoder

NewSectionEncoder creates section encoder. You can use r == nil and set it lather using SetPktReplacer or SetPktWriter method.

func (*SectionEncoder) Flush

func (e *SectionEncoder) Flush() error

Flush writes internally buffered packet adding stuffing bytes at end if need.

func (*SectionEncoder) SetPktReplacer

func (e *SectionEncoder) SetPktReplacer(r ts.PktReplacer)

SetPktReplacer sets ts.PktReplacer that will be used to write packets.

func (*SectionEncoder) SetPktWriter

func (e *SectionEncoder) SetPktWriter(r ts.PktWriter)

SetPktWriter sets ts.PktWriter that will be used to write packets.

func (*SectionEncoder) WriteSection

func (e *SectionEncoder) WriteSection(s Section) error

WriteSection encodes one section into one or more MPEG-TS packets.

type SectionQueue

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

SectionQueue represents queue of Sections.

func NewSectionQueue

func NewSectionQueue(n, seclen int) *SectionQueue

NewSectionQueue creates new queue with internall buffer of size n sections. Every section in buffer has secap capacity. Sections in buffer are not inintialized.

func (*SectionQueue) Cap

func (q *SectionQueue) Cap() int

Cap returns capacity of q.

func (*SectionQueue) Len

func (q *SectionQueue) Len() int

Len returns number of sections queued in q.

func (*SectionQueue) ReadPart

func (q *SectionQueue) ReadPart() *SectionReadQueue

ReadPart returns read part of q that can be used only to read sections from q.

func (*SectionQueue) WritePart

func (q *SectionQueue) WritePart() *SectionWriteQueue

WritePart returns write part of q that can be used to write sections to q and to close q.

type SectionReadQueue

type SectionReadQueue SectionQueue

SectionReadQueue represenst read part of SectionQueue and implements SectionReplacer interface. If reader uses raw channels insteed of ReplaceSection method it should first read filled sections from the Filled channel and next write empty sections to the Empty channel.

func (*SectionReadQueue) Cap

func (q *SectionReadQueue) Cap() int

Cap returns capacity of q.

func (*SectionReadQueue) Empty

func (q *SectionReadQueue) Empty() chan<- Section

Empty returns a channel that can be used to pass empty sections to q.

func (*SectionReadQueue) Filled

func (q *SectionReadQueue) Filled() <-chan Section

Filled returns a channel that can be used to obtain filled sections from q.

func (*SectionReadQueue) Len

func (q *SectionReadQueue) Len() int

Len returns number of sections queued in q.

func (*SectionReadQueue) ReplaceSection

func (q *SectionReadQueue) ReplaceSection(s Section) (Section, error)

ReplaceSection obtains filled section from q and next pass empty section to q. It returns io.EOF error when queue was closed and there is no more sections to read.

type SectionReader

type SectionReader interface {
	// ReadSection reads one section into s. len(s) should be equal to
	// MaxSectionLen or MaxISOSectionLen if you read standard PSI tables. You
	// can use shorter s (but not shorter that 8 bytes) if you are sure that
	// read section should fit in it. If ReadSection returned error of
	// dvb.TemporaryError type you can try read next section.
	ReadSection(Section) error
}

SectionReader is an interface that wraps the ReadSection method.

type SectionReplacer

type SectionReplacer interface {
	// ReplaceSection consumes secion reffered by s an returns other section
	// reffered by r.
	ReplaceSection(s Section) (r Section, e error)
}

SectionReplacer is an interface that wraps the ReplaceSection method. After ReplaceSection call caller should not reffer to s content any more. If ReplaceSection returns an error it is guaranteed that r == s (but content reffered by s can be modified). Generally ReplaceSection should be used in this way:

s, err = q.ReplaceSection(s)
if err != nil {
    ...
}

type SectionStreamReader

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

SectionStreamReader wraps any io.Reader interface and returns SectionReader implementation for read MPEG-TS sections from stream of bytes.

func NewSectionStreamReader

func NewSectionStreamReader(r io.Reader, checkCRC bool) *SectionStreamReader

func (*SectionStreamReader) ReadSection

func (sr *SectionStreamReader) ReadSection(s Section) error

type SectionWriteQueue

type SectionWriteQueue SectionQueue

SectionWriteQueue represenst write part of SectionQueue and implements SectionReplacer interface. If writer uses raw channels insteed of ReplaceSection method it should read empty section from Empty channel and next write filled section to Filled channel.

func (*SectionWriteQueue) Cap

func (q *SectionWriteQueue) Cap() int

Cap returns capacity of q.

func (*SectionWriteQueue) Close

func (q *SectionWriteQueue) Close()

Close closes write part of queue. After close on write part, ReplaceSection method on read part returns io.EOF error if there is no more sections to read from q.

func (*SectionWriteQueue) Empty

func (q *SectionWriteQueue) Empty() <-chan Section

Empty returns a channel that can be used to obtain empty sections from q.

func (*SectionWriteQueue) Filled

func (q *SectionWriteQueue) Filled() chan<- Section

Filled returns a channel that can be used to pass filled sections to q.

func (*SectionWriteQueue) Len

func (q *SectionWriteQueue) Len() int

Len returns number of sections queued in q.

func (*SectionWriteQueue) ReplaceSection

func (q *SectionWriteQueue) ReplaceSection(s Section) (Section, error)

ReplaceSection obtains empty section from q and next pass pkt to q. It always returns nil error.

type SectionWriter

type SectionWriter interface {
	WriteSection(s Section) error
}

SectionWriter is an interface wraps the WriteSection method.

type ServiceDescriptor

type ServiceDescriptor struct {
	Type         ServiceType
	ProviderName []byte
	ServiceName  []byte
}

func ParseServiceDescriptor

func ParseServiceDescriptor(d Descriptor) (sd ServiceDescriptor, ok bool)

type ServiceInfo

type ServiceInfo []byte

func MakeServiceInfo

func MakeServiceInfo() ServiceInfo

func (*ServiceInfo) AppendDescriptors

func (si *ServiceInfo) AppendDescriptors(ds ...Descriptor)

func (ServiceInfo) ClearDescriptors

func (si ServiceInfo) ClearDescriptors()

ClearDescriptors clears descriptors_loop_length field.

func (ServiceInfo) Descriptors

func (si ServiceInfo) Descriptors() DescriptorList

func (ServiceInfo) EITPresentFollowing

func (si ServiceInfo) EITPresentFollowing() bool

EITPresentFollowing returns the value of EIT_present_following_flag field.

func (ServiceInfo) EITSchedule

func (si ServiceInfo) EITSchedule() bool

EITSchedule returns the value of EIT_schedule_flag field.

func (ServiceInfo) Scrambled

func (si ServiceInfo) Scrambled() bool

Scrambled returns the value of free_CA_mode field.

func (ServiceInfo) ServiceId

func (si ServiceInfo) ServiceId() uint16

ServiceId return id of service (program) that this information applies to.

func (ServiceInfo) SetEITPresentFollowing

func (si ServiceInfo) SetEITPresentFollowing(b bool)

func (ServiceInfo) SetEITSchedule

func (si ServiceInfo) SetEITSchedule(b bool)

func (ServiceInfo) SetServiceId

func (si ServiceInfo) SetServiceId(sid uint16)

func (ServiceInfo) SetStatus

func (si ServiceInfo) SetStatus(s ServiceStatus)

SetStatus sets running_status field.

func (ServiceInfo) Status

func (si ServiceInfo) Status() ServiceStatus

Status returns the value of running_status field.

type ServiceInfoList

type ServiceInfoList struct {
	TableCursor
}

func (ServiceInfoList) Pop

Pop returns first ServiceInfo element from sl. If there is no more data to read Pop returns empty ServiceInfoList. If an error occurs it returns nil ServiceInfo.

type ServiceListDescriptor

type ServiceListDescriptor []byte

func ParseServiceListDescriptor

func ParseServiceListDescriptor(d Descriptor) (sld ServiceListDescriptor, ok bool)

func (*ServiceListDescriptor) Append

func (sld *ServiceListDescriptor) Append(sid uint16, typ ServiceType)

func (ServiceListDescriptor) MakeDescriptor

func (sld ServiceListDescriptor) MakeDescriptor() Descriptor

func (ServiceListDescriptor) Pop

Pop returns first (sid, typ) pair from d. Remaining pairs are returned in rd. If there is no more pairs to read len(rd) == 0. If an error occurs rd = nil

type ServiceStatus

type ServiceStatus byte
const (
	StatusUndefined ServiceStatus = iota
	NotRunnind
	StartsInFewSeconds
	Pausing
	Running
)

func (ServiceStatus) String

func (ss ServiceStatus) String() string

type ServiceType

type ServiceType byte

func (ServiceType) String

func (t ServiceType) String() string

type StreamIdentifierDescriptor

type StreamIdentifierDescriptor byte

func ParseStreamIdentifierDescriptor

func ParseStreamIdentifierDescriptor(d Descriptor) (sid StreamIdentifierDescriptor, ok bool)

type StreamType

type StreamType byte
const (
	ZeroStreamType StreamType = 0x00
	MPEG1Video     StreamType = 0x01
	MPEG2Video     StreamType = 0x02
	MPEG1Audio     StreamType = 0x03
	MPEG2Audio     StreamType = 0x04
	PrivSect       StreamType = 0x05
	PrivPES        StreamType = 0x06
	MHEG           StreamType = 0x07
	DSMCC          StreamType = 0x08
	H222_1         StreamType = 0x09
	DSMCC_A        StreamType = 0x0A
	DSMCC_B        StreamType = 0x0B
	DSMCC_C        StreamType = 0x0C
	DSMCC_D        StreamType = 0x0D
	MPEG2Aux       StreamType = 0x0E
	AAC            StreamType = 0x0F
	MPEG4Video     StreamType = 0x10
	MPEG4Audio     StreamType = 0x11
	DSMCC_SDP      StreamType = 0x12
	SPSPES         StreamType = 0x13
	SPSSect        StreamType = 0x14
	MetaDataPES    StreamType = 0x15
	MetaDataSect   StreamType = 0x16
	MetaDataDC     StreamType = 0x17
	MetaDataOC     StreamType = 0x18
	MetaDataDL     StreamType = 0x19
	MPEG2IPMP      StreamType = 0x1A
	H264Video      StreamType = 0x1B
	MPEG4RawAudio  StreamType = 0x1C
	MPEG4Text      StreamType = 0x1D
	MPEG4Aux       StreamType = 0x1E
	MPEG4SVC       StreamType = 0x1E
	MPEG4MVC       StreamType = 0x20
	JPEG2000Video  StreamType = 0x21

	H265Video StreamType = 0x24
)

func ParseStreamType

func ParseStreamType(s string) StreamType

func (StreamType) String

func (t StreamType) String() string

type TDT

type TDT Section

func MakeTDT

func MakeTDT() TDT

func (TDT) SetTime

func (tdt TDT) SetTime(t time.Time)

SetTime converts UTC time t to MJD and stores it in tdt. TDT has no CRC sum so modified TDT is valid.

type TOT

type TOT Section

func MakeTOT

func MakeTOT(n int) TOT

MakeTOT creates TOT that can hold n time offests.

func (TOT) MakeCRC

func (tot TOT) MakeCRC()

func (TOT) SetLTO

func (tot TOT) SetLTO(n int, lto LocalTimeOffset)

func (TOT) SetTime

func (tot TOT) SetTime(t time.Time)

SetTime converts UTC time t to MJD and stores it in tot. TOT has CRC sum so modified TOT is invalid. Use MakeCRC method to recalculate CRC.

type Table

type Table []Section

func (*Table) Alloc

func (t *Table) Alloc(n int, cfg *TableConfig, uself int, sectionHeader []byte) []byte

func (Table) Close

func (t Table) Close(cfg *TableConfig, tableIdExt uint16, current bool, version int8)

Close recalculates section numbers and makes CRC sums for all sections.

func (Table) Current

func (t Table) Current() bool

func (Table) Cursor

func (t Table) Cursor() TableCursor

Cursor returns TableCursor that can be used to obtain data from table.

func (Table) Descriptors

func (t Table) Descriptors(offset int) TableDescriptors

Descriptors handles table global descriptors (if exists). offset is an offest from begining of section data part to descriptor length word.

func (*Table) Reset

func (t *Table) Reset()

func (*Table) SetEmpty

func (t *Table) SetEmpty()

func (Table) SetTableId

func (t Table) SetTableId(id byte)

func (Table) TableId

func (t Table) TableId() byte

func (Table) TableIdExt

func (t Table) TableIdExt() uint16

func (*Table) Update

func (t *Table) Update(r SectionReader, tableId byte, private, current bool, sectionMaxLen int) error

Update reads next table from r.

func (Table) Version

func (t Table) Version() int8

type TableConfig

type TableConfig struct {
	TableId        byte
	GenericSyntax  bool
	PrivateSyntax  bool
	SectionMaxLen  int
	SectionHeadLen int
	NumLenFields   int // Number of length fields in section.
}

type TableCursor

type TableCursor struct {
	Tab  Table
	Data []byte
}

func (TableCursor) IsEmpty

func (tc TableCursor) IsEmpty() bool

func (TableCursor) NextSection

func (tc TableCursor) NextSection() TableCursor

type TableDescriptors

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

func (TableDescriptors) IsEmpty

func (td TableDescriptors) IsEmpty() bool

func (TableDescriptors) Pop

func (td TableDescriptors) Pop() (d Descriptor, rtd TableDescriptors)

type TerrestrialDeliverySystemDescriptor

type TerrestrialDeliverySystemDescriptor struct {
	Freq          int64 // center frequency [Hz]
	Bandwidth     int   // bandwidth [Hz]
	HighPrio      bool
	TimeSlicing   bool
	MPEFEC        bool
	Constellation dvb.Modulation
	Hierarchy     dvb.Hierarchy
	CodeRateHP    dvb.CodeRate
	CodeRateLP    dvb.CodeRate
	Guard         dvb.Guard
	TxMode        dvb.TxMode
	OtherFreq     bool
}

func ParseTerrestrialDeliverySystemDescriptor

func ParseTerrestrialDeliverySystemDescriptor(d Descriptor) (tds TerrestrialDeliverySystemDescriptor, ok bool)

func (TerrestrialDeliverySystemDescriptor) Bitrate

func (TerrestrialDeliverySystemDescriptor) MakeDescriptor

func (tds TerrestrialDeliverySystemDescriptor) MakeDescriptor() Descriptor

Jump to

Keyboard shortcuts

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