Documentation ¶
Overview ¶
Package ts contains MPEG-TS realated functions
Index ¶
- Constants
- Variables
- type AF
- type AFFlags
- type ArrayPkt
- func (p *ArrayPkt) AF() AF
- func (p *ArrayPkt) Bytes() []byte
- func (p *ArrayPkt) CC() int8
- func (p *ArrayPkt) ContainsAF() bool
- func (p *ArrayPkt) ContainsError() bool
- func (p *ArrayPkt) ContainsPayload() bool
- func (p *ArrayPkt) Copy(pkt Pkt)
- func (p *ArrayPkt) Flags() PktFlags
- func (p *ArrayPkt) IncCC()
- func (p *ArrayPkt) Payload() []byte
- func (p *ArrayPkt) PayloadUnitStart() bool
- func (p *ArrayPkt) Pid() int16
- func (p *ArrayPkt) Prio() bool
- func (p *ArrayPkt) ScramblingCtrl() PktScramblingCtrl
- func (p *ArrayPkt) SetCC(b int8)
- func (p *ArrayPkt) SetContainsAF(b bool)
- func (p *ArrayPkt) SetContainsError(b bool)
- func (p *ArrayPkt) SetContainsPayload(b bool)
- func (p *ArrayPkt) SetFlags(f PktFlags)
- func (p *ArrayPkt) SetPayloadUnitStart(b bool)
- func (p *ArrayPkt) SetPid(pid int16)
- func (p *ArrayPkt) SetPrio(b bool)
- func (p *ArrayPkt) SetScramblingCtrl(sc PktScramblingCtrl)
- func (p *ArrayPkt) SetSync()
- func (p *ArrayPkt) Slice() SlicePkt
- func (p *ArrayPkt) SyncOK() bool
- type PCR
- type Pkt
- type PktFlags
- func (f PktFlags) ContainsAF() bool
- func (f PktFlags) ContainsError() bool
- func (f PktFlags) ContainsPayload() bool
- func (f PktFlags) PayloadUnitStart() bool
- func (f PktFlags) Prio() bool
- func (f PktFlags) ScramblingCtrl() PktScramblingCtrl
- func (f *PktFlags) SetContainsAF(b bool)
- func (f *PktFlags) SetContainsError(b bool)
- func (f *PktFlags) SetContainsPayload(b bool)
- func (f *PktFlags) SetPayloadUnitStart(b bool)
- func (f *PktFlags) SetPrio(b bool)
- func (f *PktFlags) SetScramblingCtrl(sc PktScramblingCtrl)
- type PktPktReader
- type PktQueue
- type PktReadQueue
- type PktReader
- type PktReaderAsReplacer
- type PktReplacer
- type PktScramblingCtrl
- type PktStreamReader
- type PktStreamWriter
- type PktWriteQueue
- type PktWriter
- type PktWriterAsReplacer
- type Reader
- type SlicePkt
- func (p SlicePkt) AF() AF
- func (p SlicePkt) Bytes() []byte
- func (p SlicePkt) CC() int8
- func (p SlicePkt) ContainsAF() bool
- func (p SlicePkt) ContainsError() bool
- func (p SlicePkt) ContainsPayload() bool
- func (p SlicePkt) Copy(pkt Pkt)
- func (p SlicePkt) Flags() PktFlags
- func (p SlicePkt) IncCC()
- func (p SlicePkt) Payload() []byte
- func (p SlicePkt) PayloadUnitStart() bool
- func (p SlicePkt) Pid() int16
- func (p SlicePkt) Prio() bool
- func (p SlicePkt) ScramblingCtrl() PktScramblingCtrl
- func (p SlicePkt) SetCC(b int8)
- func (p SlicePkt) SetContainsAF(b bool)
- func (p SlicePkt) SetContainsError(b bool)
- func (p SlicePkt) SetContainsPayload(b bool)
- func (p SlicePkt) SetFlags(f PktFlags)
- func (p SlicePkt) SetPayloadUnitStart(b bool)
- func (p SlicePkt) SetPid(pid int16)
- func (p SlicePkt) SetPrio(b bool)
- func (p SlicePkt) SetScramblingCtrl(sc PktScramblingCtrl)
- func (p SlicePkt) SetSync()
- func (p SlicePkt) SyncOK() bool
Constants ¶
const ( PCRModulo = (1 << 33) * 300 PCRFreq = 27e6 // Hz )
const ( PktLen = 188 NullPid = 8191 )
Variables ¶
var ( ErrAFTooShort = errors.New("adaptation field is too short") ErrBadPCR = errors.New("PCR decoding error") ErrNotInAF = errors.New("no such entry in adaptation field") )
var ( // ErrSync means a lost of MPEG-TS synchronization. ErrSync = dvb.TemporaryError("MPEG-TS synchronization error") )
Functions ¶
This section is empty.
Types ¶
type AF ¶
type AF []byte
AF represents content of adaptation field
func (AF) Flags ¶
Flags returns adaptation field flags. If len(af) == 0 returns zero flags (all AFFlags methods returns false).
func (AF) OPCR ¶
OPCR returns value of OPCR in a. It returns OPCR == -1 and not nil error if there is no OPCR in AF or it can't decode OPCR.
func (AF) PCR ¶
PCR returns value of PCR in a. It returns PCR == -1 and not nil error if there is no PCR in AF or it can't decode PCR.
func (AF) SpliceCountdown ¶
type AFFlags ¶
type AFFlags byte
const ( Discontinuity AFFlags = 0x80 // discontinuity_indicator RandomAccess AFFlags = 0x40 // random_access_indicator ESPrio AFFlags = 0x20 // elementary_stream_priority_indicator ContainsPCR AFFlags = 0x10 // PCR_flag ContainsOPCR AFFlags = 0x08 // OPCR_flag SplicingPoint AFFlags = 0x04 // splicing_point_flag ContainsPrivateData AFFlags = 0x02 // transport_private_data_flag HasExtension AFFlags = 0x01 // adaptation_field_extension_flag )
type ArrayPkt ¶
ArrayPkt implements Pkt interface and represents array of bytes that contains one MPEG-TS packet.
func (*ArrayPkt) ContainsAF ¶
func (*ArrayPkt) ContainsError ¶
func (*ArrayPkt) ContainsPayload ¶
func (*ArrayPkt) PayloadUnitStart ¶
func (*ArrayPkt) ScramblingCtrl ¶
func (p *ArrayPkt) ScramblingCtrl() PktScramblingCtrl
func (*ArrayPkt) SetContainsAF ¶
func (*ArrayPkt) SetContainsError ¶
func (*ArrayPkt) SetContainsPayload ¶
func (*ArrayPkt) SetPayloadUnitStart ¶
func (*ArrayPkt) SetScramblingCtrl ¶
func (p *ArrayPkt) SetScramblingCtrl(sc PktScramblingCtrl)
type PCR ¶
type PCR int64
PCR contains the number of ticks of 27MHz generator. PCR generator counts modulo PCRModulo.
type Pkt ¶
type Pkt interface { // Bytes returns content of the packet as byte slice. It guarantees that // len of slice is equal to PktLen. Bytes() []byte // Copy copies conntent of Pkt. Copy(Pkt) // SyncOK checks does sync byte is OK. SyncOK() bool // SetSync() sets right sync byte SetSync() // Pid return value of packet identifier Pid() int16 // SetPid sets packet identifier SetPid(int16) // CC returns value of continuity counter CC() int8 // SetCC sets the value of continuity counter to byte&0x0f SetCC(int8) // IncCC increments continuity counter IncCC() // Flags returns packet flags Flags() PktFlags // SetFlags sets packet flags SetFlags(PktFlags) // AF returns adaptation field bytes. If p doesn't contain AF it returns // AF{}. If adaptation_field_length byte has wrong value it returns nil. AF() AF // Payload returns payload bytes. It returns nil if packet dosn't contain // payload or adaptation_field_length byte has incorrect value. Payload() []byte // Direct access to options/flags ContainsError() bool SetContainsError(b bool) PayloadUnitStart() bool SetPayloadUnitStart(b bool) Prio() bool SetPrio(bool) ScramblingCtrl() PktScramblingCtrl SetScramblingCtrl(PktScramblingCtrl) ContainsAF() bool SetContainsAF(bool) ContainsPayload() bool SetContainsPayload(bool) }
Pkt is common interface to any MPEG-TS packet implementation
type PktFlags ¶
type PktFlags byte
func (PktFlags) ContainsAF ¶
ContainsAF returns true if adaptation_field_control & 2 == 1
func (PktFlags) ContainsError ¶
ContainsError returns true if transport_error_indicator == 1
func (PktFlags) ContainsPayload ¶
ContainsPayload returns true if adaptation_field_control & 1 == 1
func (PktFlags) PayloadUnitStart ¶
PayloadUnitStart returns true if payload_unit_start_indicator == 1
func (PktFlags) ScramblingCtrl ¶
func (f PktFlags) ScramblingCtrl() PktScramblingCtrl
func (*PktFlags) SetContainsAF ¶
SetContainsAF sets first bit of adaptation_field_control
func (*PktFlags) SetContainsError ¶
SetContainsError sets transport_error_indicator
func (*PktFlags) SetContainsPayload ¶
SetContainsPayload sets second bit of daptation_field_control
func (*PktFlags) SetPayloadUnitStart ¶
SetPayloadUnitStart sets payload_unit_start_indicator
func (*PktFlags) SetScramblingCtrl ¶
func (f *PktFlags) SetScramblingCtrl(sc PktScramblingCtrl)
type PktPktReader ¶
type PktPktReader struct {
// contains filtered or unexported fields
}
PktPktReader wraps any io.Reader interface and returns PktReader and PktReplacer implementation for read MPEG-TS packets from stream of packets. Internally it doesn't allocate any memory so is friendly for real-time applications (it doesn't cause GC to run).
PktPktReader assumes that every call of io.Reader's Read method returns one transport packet that fits in provided buffer and contains integer number of MPEG-TS packets that are properly aligned to the begining of transport packet.
func NewPktPktReader ¶
func NewPktPktReader(r io.Reader, buf []byte) *PktPktReader
NewPktPktReader is equivalent to:
p := new(PktPktReader); p.SetReader(r); p.SetBuffer(buf)
func (*PktPktReader) ReadPkt ¶
func (p *PktPktReader) ReadPkt(pkt Pkt) error
ReadPkt reads one MPEG-TS packet
func (*PktPktReader) SetBuffer ¶
func (p *PktPktReader) SetBuffer(buf []byte)
SetReader sets new io.Reader as stream source. Forces resynchronization.
func (*PktPktReader) SetReader ¶
func (p *PktPktReader) SetReader(r io.Reader)
SetReader sets new io.Reader as stream source. Forces resynchronization.
type PktQueue ¶
type PktQueue struct {
// contains filtered or unexported fields
}
PktQueue represents queue of TS packets.
func NewPktQueue ¶
NewPktQueue creates new queue with internall buffer of size n packets.
func (*PktQueue) ReadPart ¶
func (q *PktQueue) ReadPart() *PktReadQueue
ReadPart returns read part of q that can be used only to read packets from q.
func (*PktQueue) WritePart ¶
func (q *PktQueue) WritePart() *PktWriteQueue
WritePart returns write part of q that can be used to write packets to q and to close q.
type PktReadQueue ¶
type PktReadQueue PktQueue
PktReadQueue represenst read part of PktQueue and implements PktReplacer interface. If reader uses raw channels insteed of ReplacePkt method it should first read filled packet from the Filled channel and next write empty packet to the Empty channel.
func (*PktReadQueue) Empty ¶
func (q *PktReadQueue) Empty() chan<- *ArrayPkt
Empty returns a channel that can be used to pass empty packets to q.
func (*PktReadQueue) Filled ¶
func (q *PktReadQueue) Filled() <-chan *ArrayPkt
Filled returns a channel that can be used to obtain filled packets from q.
func (*PktReadQueue) Len ¶
func (q *PktReadQueue) Len() int
Len returns number of packets queued in q.
func (*PktReadQueue) ReplacePkt ¶
func (q *PktReadQueue) ReplacePkt(pkt *ArrayPkt) (*ArrayPkt, error)
ReplacePkt obtains filled packet from q and next pass empty pkt to q. It returns io.EOF error when queue was closed and there is no more packets to read.
type PktReader ¶
type PktReader interface { // ReadPkt reads one MPEG-TS packet. // If it returns ErrSync or dvb.ErrOverflow you can try to read next // packet. ReadPkt(Pkt) error }
PktReader is an interface that wraps the ReadPkt method.
type PktReaderAsReplacer ¶
type PktReaderAsReplacer struct {
R PktReader
}
PktReaderAsReplacer converts any PktReader to PktReplacer
func (PktReaderAsReplacer) ReplacePkt ¶
func (r PktReaderAsReplacer) ReplacePkt(p *ArrayPkt) (*ArrayPkt, error)
type PktReplacer ¶
type PktReplacer interface { // ReplacePkt consumes packet reffered by p an returns other packet reffered // by r. // If you use ReplacePkt for reading ErrSync or dvb.ErrOverflow are not // fatal errors. You can still call ReplacePkt after obtaining such errors. // If you use ReplacePkt for writing, any error is probably a problem. ReplacePkt(p *ArrayPkt) (r *ArrayPkt, e error) }
PktReplacer is an interface that wraps the ReplacePkt method. After ReplacePkt call caller should not reffer to p content any more. If ReplacePkt returns an error it is guaranteed that r == p (but content reffered by p can be modified). Generally ReplacePkt should be used in this way:
p, err = q.ReplacePkt(p) if err != nil { ... }
type PktScramblingCtrl ¶
type PktScramblingCtrl byte
const ( PktNotScrambled PktScramblingCtrl = iota PktScrambled1 PktScrambled2 PktScrambled3 )
type PktStreamReader ¶
type PktStreamReader struct {
// contains filtered or unexported fields
}
PktStreamReader wraps any io.Reader interface and returns PktReader and PktReplacer implementation for read MPEG-TS packets from stream of bytes. Internally it doesn't allocate any memory so is friendly for real-time applications (it doesn't cause GC to run).
Using PktStreamReader you can start read at any point in stream. If the start point doesn't match a beginning of a packet, PktReader returns ErrSync and tries to synchronize during next read.
func NewPktStreamReader ¶
func NewPktStreamReader(r io.Reader) *PktStreamReader
NewPktStreamReader is equivalent to:
s := new(PktStreamReader); s.SetReader(r)
func (*PktStreamReader) ReadPkt ¶
func (s *PktStreamReader) ReadPkt(pkt Pkt) error
ReadPkt reads one MPEG-TS packet directly to provided buffer with exception for out of sync state when it reads more than one packet to internal buffer and tries to synchronize. ReadPkt check len(pkt) and panics if it isn't PktLen (usefull if bound checking is disabled at compile time). ReadPkt converts os.PathError{Err: syscall.EOVERFLOW} to dvb.ErrOverflow.
func (*PktStreamReader) ReplacePkt ¶
func (s *PktStreamReader) ReplacePkt(pkt *ArrayPkt) (*ArrayPkt, error)
ReplacePkt works like ReadPkt but implements PktReplacer interface.
func (*PktStreamReader) SetReader ¶
func (s *PktStreamReader) SetReader(r io.Reader)
SetReader sets new io.Reader as stream source. Forces resynchronization.
type PktStreamWriter ¶
PktStreamReader wraps any io.Writer interface and returns PktWriter and PktReplacer implementation for write MPEG-TS packets as stream of bytes.
func (PktStreamWriter) ReplacePkt ¶
func (s PktStreamWriter) ReplacePkt(pkt *ArrayPkt) (*ArrayPkt, error)
ReplacePkt works like WritePkt but implements PktReplacer interface.
func (PktStreamWriter) WritePkt ¶
func (s PktStreamWriter) WritePkt(pkt Pkt) error
WritePkt wraps s.W.Write method
type PktWriteQueue ¶
type PktWriteQueue PktQueue
PktWriteQueue represenst write part of PktQueue and implements PktReplacer interface. If writer uses raw channels insteed of ReplacePkt method it should read empty packet from Empty channel and next write filled packet to Filled channel.
func (*PktWriteQueue) Close ¶
func (q *PktWriteQueue) Close()
Close closes write part of queue. After close on write part, ReplacePkt method on read part returns io.EOF error if there is no more packets to read.
func (*PktWriteQueue) Empty ¶
func (q *PktWriteQueue) Empty() <-chan *ArrayPkt
Empty returns a channel that can be used to obtain empty packets from q.
func (*PktWriteQueue) Filled ¶
func (q *PktWriteQueue) Filled() chan<- *ArrayPkt
Filled returns a channel that can be used to pass filled packets to q.
func (*PktWriteQueue) Len ¶
func (q *PktWriteQueue) Len() int
Len returns number of packet queued in q.
func (*PktWriteQueue) ReplacePkt ¶
func (q *PktWriteQueue) ReplacePkt(pkt *ArrayPkt) (*ArrayPkt, error)
ReplacePkt obtains empty packet from q and next pass pkt to q. It always returns nil error.
type PktWriterAsReplacer ¶
type PktWriterAsReplacer struct {
W PktWriter
}
PktWriterAsReplacer converts any PktWriter to PktReplacer
func (PktWriterAsReplacer) ReplacePkt ¶
func (r PktWriterAsReplacer) ReplacePkt(p *ArrayPkt) (*ArrayPkt, error)
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader wraps PktReplacer or PktReader to implement a standard io.Reader interface. Internally it doesn't allocate any memory so it is friendly for real-time applications (it doesn't cause GC to run).
func (*Reader) Read ¶
Read allow to read from MPEG-TS packet stream as from ordinary byte stream. It reads no more than 2*PktLen-1 bytes. If len(buf) >= 2*PktLen-1, buf always contains one packet at the end of data, plus (possibly) some data from previously not fully read packet. If you always use len(buf) >= PktLen it always read one MPEG-TS packet without internal buffering. If you need to fill big buffer for multiple packets, use io.ReadFull helper function.
func (*Reader) SetPktReader ¶
SetPktReader sets new PktReader as packets source. If internal buffer contains some data from previous source they will be returned before any new read from new source.
type SlicePkt ¶
type SlicePkt []byte
SlicePkt implements Pkt interface and represents MPEG-TS packet that can be a slice of some more data (eg. slice of buffer that contains more packets). Use it only when you can't use ArrayPkt. Assigning variable of type SlicePkt to variable of type Pkt causes memory allocation (you can use *SlicePkt to avoid this).
func (SlicePkt) ContainsAF ¶
func (SlicePkt) ContainsError ¶
func (SlicePkt) ContainsPayload ¶
func (SlicePkt) PayloadUnitStart ¶
func (SlicePkt) ScramblingCtrl ¶
func (p SlicePkt) ScramblingCtrl() PktScramblingCtrl
func (SlicePkt) SetContainsAF ¶
func (SlicePkt) SetContainsError ¶
func (SlicePkt) SetContainsPayload ¶
func (SlicePkt) SetPayloadUnitStart ¶
func (SlicePkt) SetScramblingCtrl ¶
func (p SlicePkt) SetScramblingCtrl(sc PktScramblingCtrl)