Documentation
¶
Index ¶
- Constants
- Variables
- type AssembleFn
- type Desc_48
- type Desc_7A
- func (d *Desc_7A) AsvcFlag() bool
- func (d *Desc_7A) BsidFlag() bool
- func (d *Desc_7A) ComponentTypeFlag() bool
- func (d *Desc_7A) Decode(desc Descriptors) error
- func (d *Desc_7A) Encode() (desc Descriptors)
- func (d *Desc_7A) MainidFlag() bool
- func (d *Desc_7A) Mixinfoexists() bool
- func (d *Desc_7A) String() string
- func (d *Desc_7A) Substream1Flag() bool
- func (d *Desc_7A) Substream2Flag() bool
- func (d *Desc_7A) Substream3Flag() bool
- type Descriptors
- type PAT
- type PCR
- type PES
- func (p PES) CheckPrefix() bool
- func (p PES) DTS() Timestamp
- func (p PES) HasDTS() bool
- func (p PES) HasPTS() bool
- func (p PES) IsES() bool
- func (p PES) PTS() Timestamp
- func (p PES) SetDTS(value Timestamp)
- func (p PES) SetLength(value int)
- func (p PES) SetPTS(value Timestamp)
- func (p PES) SetPrefix()
- func (p PES) SetStreamID(streamID uint8)
- func (p PES) StreamID() uint8
- type PID
- type PMT
- func (p *PMT) AppendDescriptors(desc Descriptors)
- func (p *PMT) Descriptors() Descriptors
- func (p *PMT) Finalize()
- func (p *PMT) PCR() PID
- func (p *PMT) PNR() uint16
- func (p *PMT) Packetizer() *PsiPacketizer
- func (p *PMT) ParsePmtSection(b []byte) error
- func (p *PMT) SetPCR(pcr PID)
- func (p *PMT) SetPNR(pnr uint16)
- func (p *PMT) SetVersion(version uint8)
- func (p *PMT) Version() uint8
- type PSI
- type PatItem
- type PmtItem
- func (p *PmtItem) AppendDescriptors(desc Descriptors)
- func (p *PmtItem) Clone() *PmtItem
- func (p *PmtItem) Descriptors() Descriptors
- func (p *PmtItem) PID() PID
- func (p *PmtItem) SetPID(pid PID)
- func (p *PmtItem) SetType(ty uint8)
- func (p *PmtItem) StreamType() StreamType
- func (p *PmtItem) Type() uint8
- type PsiPacketizer
- type SDT
- func (s *SDT) Actual() bool
- func (s *SDT) Finalize()
- func (s *SDT) ONID() uint16
- func (s *SDT) Packetizer() *PsiPacketizer
- func (s *SDT) ParseSdtSection(b []byte) error
- func (s *SDT) SetONID(onid uint16)
- func (s *SDT) SetTSID(tsid uint16)
- func (s *SDT) SetVersion(version uint8)
- func (s *SDT) TSID() uint16
- func (s *SDT) Version() uint8
- type ScramblingControl
- type SdtItem
- func (s *SdtItem) AppendDescriptors(desc Descriptors)
- func (s *SdtItem) Descriptors() Descriptors
- func (s *SdtItem) IsPresentFollowing() bool
- func (s *SdtItem) IsSchedule() bool
- func (s *SdtItem) IsScrambled() bool
- func (s *SdtItem) RunningStatus() uint8
- func (s *SdtItem) ServiceID() uint16
- func (s *SdtItem) SetPresentFollowing(flag bool)
- func (s *SdtItem) SetRunningStatus(status uint8)
- func (s *SdtItem) SetSchedule(flag bool)
- func (s *SdtItem) SetScrambled(flag bool)
- func (s *SdtItem) SetServiceID(id uint16)
- type Slicer
- type StreamType
- type TS
- func (p TS) CC() uint8
- func (p TS) CheckCC(previous uint8) (uint8, bool)
- func (p TS) ClearAF()
- func (p TS) ClearPUSI()
- func (p TS) Fill(size int)
- func (p TS) HasAF() bool
- func (p TS) HasPCR() bool
- func (p TS) HasPUSI() bool
- func (p TS) HasPayload() bool
- func (p TS) HasTEI() bool
- func (p TS) HeaderSize() int
- func (p TS) IncrementCC()
- func (p TS) PCR() PCR
- func (p TS) PID() PID
- func (p TS) Payload() []byte
- func (p TS) SetAF()
- func (p TS) SetCC(cc uint8)
- func (p TS) SetPCR(value PCR)
- func (p TS) SetPID(pid PID)
- func (p TS) SetPUSI()
- func (p TS) SetPayload()
- func (p TS) TSC() ScramblingControl
- type Timestamp
Examples ¶
Constants ¶
const ( PatHeaderSize = 8 PatMaximumSize = 1024 PatItemSize = 4 )
const ( PmtHeaderSize = 12 PmtMaximumSize = 1024 PmtItemSize = 5 )
const ( // First 3 bytes of the PSI packet. Contains Table ID and Section Length PsiHeaderSize = 3 // The maximum number of bytes in a section of // a ITU-T Rec. H.222.0 | ISO/IEC 13818-1 defined PSI table is 1024 bytes. // The maximum number of bytes in a private_section is 4096 bytes. // Includes PsiHeaderSize PsiMaximumSize = 4096 )
const ( SdtHeaderSize = 11 SdtMaximumSize = 1024 SdtItemSize = 5 )
const ( SyncByte uint8 = 0x47 PacketSize int = 188 )
const (
ProgramClock = 27e6 // 27MHz
)
const (
SystemClock = 90000 // 90kHz
)
Variables ¶
var ( ErrCC = errors.New("psi: discontinuity received") ErrPUSI = errors.New("psi: pointer field out of range") ErrAssemblePSI = errors.New("psi: assemble failed") ErrCRC = errors.New("psi: checksum not match") ErrPsiFormat = errors.New("psi: invalid format") )
var ( ErrSyncTS = errors.New("ts slicer: sync error") ErrNotComplete = errors.New("ts slicer: not complete") )
var (
ErrDescriptorFormat = errors.New("descriptor: invalid format")
)
var (
ErrPatFormat = errors.New("pat: invalid format")
)
var (
ErrPmtFormat = errors.New("pmt: invalid format")
)
var (
ErrSdtFormat = errors.New("sdt: invalid format")
)
var NullTS = TS{}/* 188 elements not displayed */
Functions ¶
This section is empty.
Types ¶
type Desc_48 ¶
func (*Desc_48) Decode ¶
func (d *Desc_48) Decode(desc Descriptors) error
func (*Desc_48) Encode ¶
func (d *Desc_48) Encode() (desc Descriptors)
type Desc_7A ¶
type Desc_7A struct {
// contains filtered or unexported fields
}
func (*Desc_7A) ComponentTypeFlag ¶
func (*Desc_7A) Decode ¶
func (d *Desc_7A) Decode(desc Descriptors) error
func (*Desc_7A) Encode ¶
func (d *Desc_7A) Encode() (desc Descriptors)
func (*Desc_7A) MainidFlag ¶
func (*Desc_7A) Mixinfoexists ¶
func (*Desc_7A) Substream1Flag ¶
func (*Desc_7A) Substream2Flag ¶
func (*Desc_7A) Substream3Flag ¶
type Descriptors ¶
type Descriptors []byte
func (Descriptors) Check ¶
func (d Descriptors) Check() error
func (Descriptors) Next ¶
func (d Descriptors) Next() Descriptors
type PAT ¶
type PAT struct { Items []*PatItem // contains filtered or unexported fields }
PAT is Program Association Table
func (*PAT) Packetizer ¶
func (p *PAT) Packetizer() *PsiPacketizer
Packetizer returns a new PsiPacketizer to get TS packets from PAT
Example ¶
pat := NewPat() pat.SetVersion(1) pat.SetTSID(1) item := NewPatItem() item.SetPNR(1) item.SetPID(1031) pat.Items = append(pat.Items, item) pat.Finalize() ts := NewTS(0) for pack := pat.Packetizer(); pack.Next(ts); ts.IncrementCC() { // TS Header with Payload start offset fmt.Printf("%X...\n", ts[:25]) }
Output: 474000100000B00D0001C300000001E407FF2D3E2FFFFFFFFF...
func (*PAT) ParsePatSection ¶
Example ¶
data := []byte{ 0x00, 0xB0, 0x0D, 0x70, 0xE9, 0xDD, 0x00, 0x00, 0x00, 0x01, 0xE0, 0x42, 0xAE, 0xF4, 0xD8, 0x1C, } pat := new(PAT) if err := pat.ParsePatSection(data); err != nil { panic(err) } fmt.Println("TSID", pat.TSID()) for _, item := range pat.Items { fmt.Printf("Program Number %d PID %d\n", item.PNR(), item.PID()) }
Output: TSID 28905 Program Number 1 PID 66
func (*PAT) SetVersion ¶
type PCR ¶
type PCR uint64
PCR is Program Clock Reference
func (PCR) EstimatedPCR ¶
EstimatedPCR returns estimated PCR value
| time --> | X---------X---------X | \ \ \ | \ \ estimated PCR | \ current PCR | previous PCR
- lastBlock - bytes between PCR(previous) and PCR(current) - currentBlock - bytes between PCR(current) and PCR(estimated)
type PES ¶
type PES []byte
func (PES) CheckPrefix ¶
CheckPrefix checks is PES prefix equal to 0x000001.
func (PES) HasDTS ¶
HasDTS checks a Decoding TimeStamp (DTS) is defined in the PES header. DTS field presents only in pair with PTS field. If DTS field is not presented than DTS value equal to PTS.
func (PES) HasPTS ¶
HasPTS checks is a Presentation Time Stamp (PTS) defined in the PES header. PTS field presents only for elementary streams.
func (PES) SetLength ¶
SetLength sets PES_packet_length field. Value specifying the number of bytes in the PES packet following the last byte of the field. 0 allowed only for video elementary stream.
type PMT ¶
type PMT struct { Items []*PmtItem // contains filtered or unexported fields }
PMT is Program Map Table
func (*PMT) AppendDescriptors ¶
func (p *PMT) AppendDescriptors(desc Descriptors)
func (*PMT) Descriptors ¶
func (p *PMT) Descriptors() Descriptors
func (*PMT) Packetizer ¶
func (p *PMT) Packetizer() *PsiPacketizer
Packetizer returns a new PsiPacketizer to get TS packets from PMT
func (*PMT) ParsePmtSection ¶
func (*PMT) SetVersion ¶
type PSI ¶
type PSI struct { TableID uint8 Version uint8 SectionNumber uint8 LastSectionNumber uint8 CRC uint32 // contains filtered or unexported fields }
Program Specific Information (ISO 13818-1 / 2.4.4)
func (*PSI) Assemble ¶
func (p *PSI) Assemble(packet TS, fn AssembleFn)
Assembles TS packets into single PSI. Calls fn when PSI is ready or error occurs
type PatItem ¶
type PatItem struct {
// contains filtered or unexported fields
}
func NewPatItem ¶
func NewPatItem() *PatItem
type PmtItem ¶
type PmtItem struct {
// contains filtered or unexported fields
}
PMT Item contains information about elementary stream
func NewPmtItem ¶
func NewPmtItem() *PmtItem
func (*PmtItem) AppendDescriptors ¶
func (p *PmtItem) AppendDescriptors(desc Descriptors)
func (*PmtItem) Descriptors ¶
func (p *PmtItem) Descriptors() Descriptors
func (*PmtItem) StreamType ¶
func (p *PmtItem) StreamType() StreamType
StreamType returns stream type by element ID and related descriptors
type PsiPacketizer ¶
type PsiPacketizer struct {
// contains filtered or unexported fields
}
PsiPacketizer is a helper to splits PSI section into multiple TS packets. If data more than fits into one section, it will be split into multiple sections.
func (*PsiPacketizer) Next ¶
func (p *PsiPacketizer) Next(ts TS) bool
type SDT ¶
type SDT struct { Items []*SdtItem // contains filtered or unexported fields }
SDT is Service Description Table
func (*SDT) Packetizer ¶
func (s *SDT) Packetizer() *PsiPacketizer
Packetizer returns a new PsiPacketizer to get TS packets from SDT
func (*SDT) ParseSdtSection ¶
func (*SDT) SetVersion ¶
type ScramblingControl ¶
type ScramblingControl byte
const ( NotScrambled ScramblingControl = 0 ScrambledEvenKey ScramblingControl = 2 // 10 ScrambledOddKey ScramblingControl = 3 // 11 )
type SdtItem ¶
type SdtItem struct {
// contains filtered or unexported fields
}
func NewSdtItem ¶
func NewSdtItem() *SdtItem
func (*SdtItem) AppendDescriptors ¶
func (s *SdtItem) AppendDescriptors(desc Descriptors)
Appends descriptors to the last added item
func (*SdtItem) Descriptors ¶
func (s *SdtItem) Descriptors() Descriptors
func (*SdtItem) IsPresentFollowing ¶
Returns true if present-following information is present in the stream EIT_present_following_flag
func (*SdtItem) IsSchedule ¶
Returns true if schedule information is present in the stream EIT_schedule_flag
func (*SdtItem) IsScrambled ¶
Returns false if stream is not scrambled Returns true if one or more streams may be controlled by a CA system free_CA_mode
func (*SdtItem) RunningStatus ¶
func (*SdtItem) SetPresentFollowing ¶
func (*SdtItem) SetRunningStatus ¶
func (*SdtItem) SetSchedule ¶
func (*SdtItem) SetScrambled ¶
func (*SdtItem) SetServiceID ¶
type Slicer ¶
type Slicer struct {
// contains filtered or unexported fields
}
Slicer is a tool for split TS buffer to TS packets. If buffer length is not multiple to TS packet size it store remain data in the internal buffer and will be used on the next iteration.
Example ¶
slicer := Slicer{} buffer := NullTS for packet := slicer.Begin(buffer); packet != nil; packet = slicer.Next() { fmt.Println("PID", packet.PID()) }
Output: PID 8191
type StreamType ¶
type StreamType int
StreamType is an elementary stream type
const ( StreamData StreamType = iota StreamVideoH261 StreamVideoH262 StreamVideoH263 StreamVideoH264 StreamVideoH265 StreamAudioMP2 StreamAudioMP3 StreamAudioAAC StreamAudioLATM StreamAudioAC3 StreamAudioEAC3 StreamDataSCTE35 StreamDataSubtitles StreamDataTeletext StreamDataAIT )
func (StreamType) String ¶
func (t StreamType) String() string
type TS ¶
type TS []byte
ISO/IEC 13818-1 : 2.4.3 Specification of the Transport Stream syntax and semantics
Example ¶
packet := TS([]byte{0x47, 0x40, 0x11, 0x15}) fmt.Println("PID", packet.PID(), "CC", packet.CC())
Output: PID 17 CC 5
func (TS) CC ¶
CC returns continuity counter value. Continuity Counter is a 4-bit field incrementing by 1 for each packet with payload on the same PID.
func (TS) CheckCC ¶
CheckCC checks continuity counter Returns current CC and true if CC is equal to expected value
func (TS) HasPCR ¶
HasPCR returns true if PCR flag is set in the Adaptation Field. Make sure that Adaptation Field is not empty: packet HeaderSize() more or equal than 6 bytes.
func (TS) IncrementCC ¶
func (p TS) IncrementCC()
IncrementCC increments continuity counter in packet
func (TS) PCR ¶
PCR returns PCR value from the Adaptation Field. Packet should be with Adaptation Field
func (TS) PID ¶
PID returns packet identifier value. PID is a 13-bit field that identifies the payload carried in the packet.
func (TS) TSC ¶
func (p TS) TSC() ScramblingControl
TSC returns 2-bit Transport Scrambling Control field
type Timestamp ¶
type Timestamp uint64
Timestamp is a 33-bit MPEG-2 timestamp for PTS/DTS
const ( NonTimestamp Timestamp = 1 << 33 MaxTimestamp Timestamp = NonTimestamp - 1 )