astits

package module
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 13 Imported by: 0

README

go-astits — opinionated fork

An opinionated fork of asticode/go-astits focused on hot-path performance of MPEG-TS demuxing and remuxing (live video and archives) — at the cost of upstream compatibility. The API and semantics have diverged from the original for good; this module is not and will never be a drop-in replacement.

Pros

Measurements: one-hour SD stream (2.1 Mbit/s, 952 MB), single CPU thread (Apple M-series); upstream — v1.15.0.

Path This fork Upstream Delta
Packet walk (NextPacketTo) 5.4 GB/s, 15 allocs/hour 1.85 GB/s, 10.5M allocs ×2.9 / ×700,000
Same, view mode + skipper 9.0 GB/s — —
PES assembly (NextData) 3.3 GB/s, 147k allocs, 75 MB garbage 0.28 GB/s, 32.9M, 4.1 GB ×11.8 / ×224 / ×54

How:

  • Direct parsing and serialization: no BytesIterator/BitsWriter on hot paths — slice cursors for reads, packet assembly in a scratch buffer with a single Write per packet for writes.
  • Circular memory lifecycle: packet pool + demuxer-local freelist (chain-linked returns, drained back to the global pool on EOF), payload and list pools, embedded structs instead of pointer fields (AF inside Packet, PES and an owned AF copy inside DemuxerData, optional header inside PESHeader), compact generic pidMap tables instead of maps keyed by PID.
  • Zero-copy view mode (DemuxerOptZeroCopyPackets): batched reads, packets are views into the batch buffer.
  • PacketSkipper — header-level filtering before any payload work.
  • Packet.Offset — a byte map of the stream, correct even with a skipper installed.
  • PSI dedup: byte-identical repeats of PAT/PMT/… are neither parsed nor emitted.
  • Data ownership: AdaptationField/TransportPrivateData inside DemuxerData are owned copies; retaining data on the consumer side is safe from pool reuse.
  • Demuxer.Close() — deterministic resource return for demuxers abandoned before EOF; Rewind() cleans up after itself.
  • Muxer: raw packet passthrough (WritePacket with UpdateHeader), SetCC, table retransmission from cache.
  • Byte-for-byte output identity across optimizations is guarded by golden tests on real streams (demux differential against an independent parser + remux references).

Problems and deliberate trade-offs

  • Incompatible with upstream in both API and semantics. Compatibility is a non-goal.
  • The demuxer is single-goroutine by contract — no internal locking.
  • Close discipline is mandatory: DemuxerData.Close() after use; a demuxer abandoned before EOF must be released via Demuxer.Close() — otherwise held resources go to the GC instead of the pools.
  • View mode: packet memory is valid only until the next batch refill; NextData is forbidden in this mode (ErrZeroCopyNextData).
  • PSI dedup changes emission semantics: a repeated section with identical bytes is not delivered to the consumer. The first occurrence and any change are.
  • The PSI path retains its payload buffer forever (descriptors are views into it): a deliberate leak of one buffer per section change.
  • DemuxerData is large (~1 KB due to embedded structs): cheap to allocate, expensive to retain by the thousands.
  • Upstream cmd/ tools are unsupported and do not build.
  • Requires Go ≥ 1.26.
  • Part of the test suite runs against real assets (env GOLDEN_TS_DIR); without it only unit tests run.

Roadmap

  • Split into packages (ts / pes / psi / demux / mux) with a move to /v2.
  • Fuzz and roundtrip tests for parsers/serializers.
  • Per-PID byte accumulator: view-compatible NextData, one copy less.
  • Full DemuxerData pooling and PSI ownership (descriptor copying).

Documentation

Overview

Code generated by astits using internal/cmd/crc32_table. DO NOT EDIT

Index

Constants

View Source
const (
	PIDPAT  uint16 = 0x0    // Program Association Table (PAT) contains a directory listing of all Program Map Tables.
	PIDCAT  uint16 = 0x1    // Conditional Access Table (CAT) contains a directory listing of all ITU-T Rec. H.222 entitlement management message streams used by Program Map Tables.
	PIDTSDT uint16 = 0x2    // Transport Stream Description Table (TSDT) contains descriptors related to the overall transport stream
	PIDNull uint16 = 0x1fff // Null Packet (used for fixed bandwidth padding)
)

PIDs

View Source
const (
	PSTDBufferScale128Bytes  = 0
	PSTDBufferScale1024Bytes = 1
)

P-STD buffer scales

View Source
const (
	PTSDTSIndicatorBothPresent = 3
	PTSDTSIndicatorIsForbidden = 1
	PTSDTSIndicatorNoPTSOrDTS  = 0
	PTSDTSIndicatorOnlyPTS     = 2
)

PTS DTS indicator

View Source
const (
	StreamIDPrivateStream1 = 189
	StreamIDPaddingStream  = 190
	StreamIDPrivateStream2 = 191
)

Stream IDs

View Source
const (
	TrickModeControlFastForward = 0
	TrickModeControlFastReverse = 3
	TrickModeControlFreezeFrame = 2
	TrickModeControlSlowMotion  = 1
	TrickModeControlSlowReverse = 4
)

Trick mode controls

View Source
const (
	PSITableTypeBAT     = "BAT"
	PSITableTypeDIT     = "DIT"
	PSITableTypeEIT     = "EIT"
	PSITableTypeNIT     = "NIT"
	PSITableTypeNull    = "Null"
	PSITableTypePAT     = "PAT"
	PSITableTypePMT     = "PMT"
	PSITableTypeRST     = "RST"
	PSITableTypeSDT     = "SDT"
	PSITableTypeSIT     = "SIT"
	PSITableTypeST      = "ST"
	PSITableTypeTDT     = "TDT"
	PSITableTypeTOT     = "TOT"
	PSITableTypeUnknown = "Unknown"
)

PSI table IDs

View Source
const (
	RunningStatusNotRunning          = 1
	RunningStatusPausing             = 3
	RunningStatusRunning             = 4
	RunningStatusServiceOffAir       = 5
	RunningStatusStartsInAFewSeconds = 2
	RunningStatusUndefined           = 0
)

Running statuses

View Source
const (
	AudioTypeCleanEffects             = 0x1
	AudioTypeHearingImpaired          = 0x2
	AudioTypeVisualImpairedCommentary = 0x3
)

Audio types Page: 683 | https://books.google.fr/books?id=6dgWB3-rChYC&printsec=frontcover&hl=fr

View Source
const (
	DataStreamAligmentAudioSyncWord          = 0x1
	DataStreamAligmentVideoSliceOrAccessUnit = 0x1
	DataStreamAligmentVideoAccessUnit        = 0x2
	DataStreamAligmentVideoGOPOrSEQ          = 0x3
	DataStreamAligmentVideoSEQ               = 0x4
)

Data stream alignments Page: 85 | Chapter:2.6.11 | Link: http://ecee.colorado.edu/~ecen5653/ecen5653/papers/iso13818-1.pdf

View Source
const (
	TeletextTypeAdditionalInformationPage                    = 0x3
	TeletextTypeInitialTeletextPage                          = 0x1
	TeletextTypeProgramSchedulePage                          = 0x4
	TeletextTypeTeletextSubtitlePage                         = 0x2
	TeletextTypeTeletextSubtitlePageForHearingImpairedPeople = 0x5
)

Teletext types Chapter: 6.2.43 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

View Source
const (
	VBIDataServiceIDEBUTeletext          = 0x1
	VBIDataServiceIDInvertedTeletext     = 0x2
	VBIDataServiceIDVPS                  = 0x4
	VBIDataServiceIDWSS                  = 0x5
	VBIDataServiceIDClosedCaptioning     = 0x6
	VBIDataServiceIDMonochrome442Samples = 0x7
)

VBI data service id Chapter: 6.2.47 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

View Source
const (
	ScramblingControlNotScrambled         = 0
	ScramblingControlReservedForFutureUse = 1
	ScramblingControlScrambledWithEvenKey = 2
	ScramblingControlScrambledWithOddKey  = 3
)

Scrambling Controls

View Source
const (
	MpegTsPacketSize = 188
	M2TsPacketSize   = 192
)
View Source
const (
	DescriptorTagExtensionSupplementaryAudio = 0x6
)

Descriptor extension tags Chapter: 6.3 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

View Source
const (
	ServiceTypeDigitalTelevisionService = 0x1
)

Service types Chapter: 6.2.33 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

Variables

View Source
var (
	ErrNoMorePackets                = errors.New("astits: no more packets")
	ErrPacketMustStartWithASyncByte = errors.New("astits: packet must start with a sync byte")
	ErrZeroCopyNextData             = errors.New("astits: NextData is unavailable with zero-copy packets")
	ErrShortPacket                  = errors.New("astits: packet too short")
)

Errors

View Source
var (
	ErrPIDNotFound      = errors.New("astits: PID not found")
	ErrPIDAlreadyExists = errors.New("astits: PID already exists")
	ErrPCRPIDInvalid    = errors.New("astits: PCR PID invalid")
)
View Source
var EmptySkipper = func(_ *Packet) (skip bool) { return }
View Source
var ErrCounterOverflow = errors.New("counter overflow")

Functions

func DemuxerOptPacketSize

func DemuxerOptPacketSize(packetSize int) func(*Demuxer)

DemuxerOptPacketSize returns the option to set the packet size

func DemuxerOptPacketSkipper

func DemuxerOptPacketSkipper(s PacketSkipper) func(*Demuxer)

DemuxerOptPacketSkipper returns the option to set the packet skipper

func DemuxerOptPacketsParser

func DemuxerOptPacketsParser(p PacketsParser) func(*Demuxer)

DemuxerOptPacketsParser returns the option to set the packets parser

func DemuxerOptSkipErrLimit

func DemuxerOptSkipErrLimit(count int) func(*Demuxer)

DemuxerOptSkipErrLimit returns the option to set the packet skipper

func DemuxerOptZeroCopyPackets

func DemuxerOptZeroCopyPackets(batchPackets uint) func(*Demuxer)

DemuxerOptZeroCopyPackets makes NextPacket/NextPacketTo read the stream in batches of batchPackets and return packets as views into the internal buffer: no per-packet read call and no copy. A packet's memory (Payload, adaptation private data) is only valid until the NextPacket/NextPacketTo call that triggers the next batch refill — consume it immediately. NextData is unavailable in this mode (it accumulates packets across refills) and returns ErrZeroCopyNextData.

func MuxerOptTablesRetransmitPeriod

func MuxerOptTablesRetransmitPeriod(newPeriod int) func(*Muxer)

Types

type ClockReference

type ClockReference uint64

ClockReference represents a clock reference Base is based on a 90 kHz clock and extension is based on a 27 MHz clock

func (*ClockReference) Base

func (cr *ClockReference) Base() uint64

func (*ClockReference) Duration

func (cr *ClockReference) Duration() time.Duration

Duration converts the clock reference into duration

func (*ClockReference) Extension

func (cr *ClockReference) Extension() uint64

func (*ClockReference) Time

func (cr *ClockReference) Time() time.Time

Time converts the clock reference into time

type Demuxer

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

Demuxer represents a demuxer https://en.wikipedia.org/wiki/MPEG_transport_stream http://seidl.cs.vsb.cz/download/dvb/DVB_Poster.pdf http://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.13.01_40/en_300468v011301o.pdf

func NewDemuxer

func NewDemuxer(ctx context.Context, r io.Reader, opts ...func(*Demuxer)) (d *Demuxer)

NewDemuxer creates a new transport stream based on a reader

func (*Demuxer) Close

func (dmx *Demuxer) Close()

Close returns everything the demuxer holds to the pools (buffered data, unfinished lists, the freelist). The demuxer must not be used after Close. Mandatory for demuxers abandoned before the end of the stream.

func (*Demuxer) GetStats

func (dmx *Demuxer) GetStats() (ret map[uint64]uint)

func (*Demuxer) NextData

func (dmx *Demuxer) NextData() (d *DemuxerData, err error)

NextData retrieves the next data

func (*Demuxer) NextPacket

func (dmx *Demuxer) NextPacket() (p *Packet, err error)

NextPacket retrieves the next packet. You must Close() the packet after use.

func (*Demuxer) NextPacketTo

func (dmx *Demuxer) NextPacketTo(p *Packet) (err error)

NextPacketTo unpack packet to provided p.

func (*Demuxer) Rewind

func (dmx *Demuxer) Rewind() (n int64, err error)

Rewind rewinds the demuxer reader

type DemuxerData

type DemuxerData struct {
	PAT *PATData
	PMT *PMTData
	PES *PESData
	EIT *EITData
	NIT *NITData
	SDT *SDTData
	TOT *TOTData

	AdaptationField *PacketAdaptationField

	ContinuityCounter uint8
	PID               uint16
	// contains filtered or unexported fields
}

DemuxerData represents a data parsed by Demuxer

func (*DemuxerData) Close

func (d *DemuxerData) Close()

type Descriptor

type Descriptor interface {
	// contains filtered or unexported methods
}

type DescriptorAC3

type DescriptorAC3 struct {
	Header           DescriptorHeader
	AdditionalInfo   []byte
	ASVC             uint8
	BSID             uint8
	ComponentType    uint8
	HasASVC          bool
	HasBSID          bool
	HasComponentType bool
	HasMainID        bool
	MainID           uint8
}

DescriptorAC3 represents an AC3 descriptor Chapter: Annex D | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

type DescriptorAVCVideo

type DescriptorAVCVideo struct {
	Header               DescriptorHeader
	AVC24HourPictureFlag bool
	AVCStillPresent      bool
	CompatibleFlags      uint8
	ConstraintSet0Flag   bool
	ConstraintSet1Flag   bool
	ConstraintSet2Flag   bool
	LevelIDC             uint8
	ProfileIDC           uint8
}

DescriptorAVCVideo represents an AVC video descriptor No doc found unfortunately, basing the implementation on https://github.com/gfto/bitstream/blob/master/mpeg/psi/desc_28.h

type DescriptorComponent

type DescriptorComponent struct {
	Header             DescriptorHeader
	ISO639LanguageCode [3]byte
	Text               []byte
	ComponentTag       uint8
	ComponentType      uint8
	StreamContent      uint8
	StreamContentExt   uint8
}

DescriptorComponent represents a component descriptor Chapter: 6.2.8 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

type DescriptorContent

type DescriptorContent struct {
	Header DescriptorHeader
	Items  []DescriptorContentItem
}

DescriptorContent represents a content descriptor Chapter: 6.2.9 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

type DescriptorContentItem

type DescriptorContentItem struct {
	ContentNibbleLevel1 uint8
	ContentNibbleLevel2 uint8
	UserByte            uint8
}

DescriptorContentItem represents a content item descriptor Chapter: 6.2.9 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

type DescriptorDataStreamAlignment

type DescriptorDataStreamAlignment struct {
	Header DescriptorHeader
	Type   uint8
}

DescriptorDataStreamAlignment represents a data stream alignment descriptor

type DescriptorEnhancedAC3

type DescriptorEnhancedAC3 struct {
	Header           DescriptorHeader
	AdditionalInfo   []byte
	ASVC             uint8
	BSID             uint8
	ComponentType    uint8
	HasASVC          bool
	HasBSID          bool
	HasComponentType bool
	HasMainID        bool
	HasSubStream1    bool
	HasSubStream2    bool
	HasSubStream3    bool
	MainID           uint8
	MixInfoExists    bool
	SubStream1       uint8
	SubStream2       uint8
	SubStream3       uint8
}

DescriptorEnhancedAC3 represents an enhanced AC3 descriptor Chapter: Annex D | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

type DescriptorExtendedEvent

type DescriptorExtendedEvent struct {
	Text                 []byte
	Items                []DescriptorExtendedEventItem
	Header               DescriptorHeader
	ISO639LanguageCode   [3]byte
	LastDescriptorNumber uint8
	Number               uint8
}

DescriptorExtendedEvent represents an extended event descriptor Chapter: 6.2.15 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

type DescriptorExtendedEventItem

type DescriptorExtendedEventItem struct {
	Content     []byte
	Description []byte
}

DescriptorExtendedEventItem represents an extended event item descriptor Chapter: 6.2.15 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

type DescriptorExtension

type DescriptorExtension struct {
	Header             DescriptorHeader
	SupplementaryAudio *DescriptorExtensionSupplementaryAudio
	Unknown            []byte
	Tag                uint8
}

DescriptorExtension represents an extension descriptor Chapter: 6.2.16 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

type DescriptorExtensionSupplementaryAudio

type DescriptorExtensionSupplementaryAudio struct {
	LanguageCode            [3]byte
	PrivateData             []byte
	EditorialClassification uint8
	HasLanguageCode         bool
	MixType                 bool
}

DescriptorExtensionSupplementaryAudio represents a supplementary audio extension descriptor Chapter: 6.4.10 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

type DescriptorHeader

type DescriptorHeader struct {
	Tag    DescriptorTag // the tag defines the structure of the contained data following the descriptor length.
	Length uint8
}

type DescriptorISO639LanguageAndAudioType

type DescriptorISO639LanguageAndAudioType struct {
	Language [3]byte
	Header   DescriptorHeader
	Type     uint8
}

DescriptorISO639LanguageAndAudioType represents an ISO639 language descriptor https://github.com/gfto/bitstream/blob/master/mpeg/psi/desc_0a.h FIXME (barbashov) according to Chapter 2.6.18 ISO/IEC 13818-1:2015 there could be not one, but multiple such descriptors

type DescriptorLocalTimeOffset

type DescriptorLocalTimeOffset struct {
	Header DescriptorHeader
	Items  []DescriptorLocalTimeOffsetItem
}

DescriptorLocalTimeOffset represents a local time offset descriptor Chapter: 6.2.20 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

type DescriptorLocalTimeOffsetItem

type DescriptorLocalTimeOffsetItem struct {
	LocalTimeOffset         time.Duration
	NextTimeOffset          time.Duration
	TimeOfChange            time.Time
	CountryCode             [3]byte
	CountryRegionID         uint8
	LocalTimeOffsetPolarity bool
}

DescriptorLocalTimeOffsetItem represents a local time offset item descriptor Chapter: 6.2.20 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

type DescriptorMaximumBitrate

type DescriptorMaximumBitrate struct {
	Bitrate uint32 // In bytes/second
	Header  DescriptorHeader
}

DescriptorMaximumBitrate represents a maximum bitrate descriptor

type DescriptorNetworkName

type DescriptorNetworkName struct {
	Header DescriptorHeader
	Name   []byte
}

DescriptorNetworkName represents a network name descriptor Chapter: 6.2.27 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

type DescriptorParentalRating

type DescriptorParentalRating struct {
	Header DescriptorHeader
	Items  []DescriptorParentalRatingItem
}

DescriptorParentalRating represents a parental rating descriptor Chapter: 6.2.28 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

type DescriptorParentalRatingItem

type DescriptorParentalRatingItem struct {
	CountryCode [3]byte
	Rating      uint8
}

DescriptorParentalRatingItem represents a parental rating item descriptor Chapter: 6.2.28 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

func (DescriptorParentalRatingItem) MinimumAge

func (d DescriptorParentalRatingItem) MinimumAge() int

MinimumAge returns the minimum age for the parental rating

type DescriptorParser

type DescriptorParser func(i *astikit.BytesIterator, h DescriptorHeader, offsetEnd int) (d Descriptor, err error)

type DescriptorPrivateDataIndicator

type DescriptorPrivateDataIndicator struct {
	Header    DescriptorHeader
	Indicator uint32
}

DescriptorPrivateDataIndicator represents a private data Indicator descriptor

type DescriptorPrivateDataSpecifier

type DescriptorPrivateDataSpecifier struct {
	Header    DescriptorHeader
	Specifier uint32
}

DescriptorPrivateDataSpecifier represents a private data specifier descriptor

type DescriptorRegistration

type DescriptorRegistration struct {
	AdditionalIdentificationInfo []byte
	FormatIdentifier             uint32
	Header                       DescriptorHeader
}

DescriptorRegistration represents a registration descriptor Page: 84 | http://ecee.colorado.edu/~ecen5653/ecen5653/papers/iso13818-1.pdf

type DescriptorService

type DescriptorService struct {
	Name     []byte
	Provider []byte
	Header   DescriptorHeader
	Type     uint8
}

DescriptorService represents a service descriptor Chapter: 6.2.33 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

type DescriptorShortEvent

type DescriptorShortEvent struct {
	Header    DescriptorHeader
	EventName []byte
	Language  [3]byte
	Text      []byte
}

DescriptorShortEvent represents a short event descriptor Chapter: 6.2.37 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

type DescriptorStreamIdentifier

type DescriptorStreamIdentifier struct {
	Header       DescriptorHeader
	ComponentTag uint8
}

DescriptorStreamIdentifier represents a stream identifier descriptor Chapter: 6.2.39 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

type DescriptorSubtitling

type DescriptorSubtitling struct {
	Header DescriptorHeader
	Items  []DescriptorSubtitlingItem
}

DescriptorSubtitling represents a subtitling descriptor Chapter: 6.2.41 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

type DescriptorSubtitlingItem

type DescriptorSubtitlingItem struct {
	Language          [3]byte
	AncillaryPageID   uint16
	CompositionPageID uint16
	Type              uint8
}

DescriptorSubtitlingItem represents subtitling descriptor item Chapter: 6.2.41 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

type DescriptorTag

type DescriptorTag uint8
const (
	DescriptorTagAC3                        DescriptorTag = 0x6a
	DescriptorTagAVCVideo                   DescriptorTag = 0x28
	DescriptorTagComponent                  DescriptorTag = 0x50
	DescriptorTagContent                    DescriptorTag = 0x54
	DescriptorTagDataStreamAlignment        DescriptorTag = 0x6
	DescriptorTagEnhancedAC3                DescriptorTag = 0x7a
	DescriptorTagExtendedEvent              DescriptorTag = 0x4e
	DescriptorTagExtension                  DescriptorTag = 0x7f
	DescriptorTagISO639LanguageAndAudioType DescriptorTag = 0xa
	DescriptorTagLocalTimeOffset            DescriptorTag = 0x58
	DescriptorTagMaximumBitrate             DescriptorTag = 0xe
	DescriptorTagNetworkName                DescriptorTag = 0x40
	DescriptorTagParentalRating             DescriptorTag = 0x55
	DescriptorTagPrivateDataIndicator       DescriptorTag = 0xf
	DescriptorTagPrivateDataSpecifier       DescriptorTag = 0x5f
	DescriptorTagRegistration               DescriptorTag = 0x5
	DescriptorTagService                    DescriptorTag = 0x48
	DescriptorTagShortEvent                 DescriptorTag = 0x4d
	DescriptorTagStreamIdentifier           DescriptorTag = 0x52
	DescriptorTagSubtitling                 DescriptorTag = 0x59
	DescriptorTagTeletext                   DescriptorTag = 0x56
	DescriptorTagVBIData                    DescriptorTag = 0x45
	DescriptorTagVBITeletext                DescriptorTag = 0x46
)

Descriptor tags Chapter: 6.1 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

type DescriptorTeletext

type DescriptorTeletext struct {
	Header DescriptorHeader
	Items  []DescriptorTeletextItem
}

DescriptorTeletext represents a teletext descriptor Chapter: 6.2.43 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

type DescriptorTeletextItem

type DescriptorTeletextItem struct {
	Language [3]byte
	Magazine uint8
	Page     uint8
	Type     uint8
}

DescriptorTeletextItem represents a teletext descriptor item Chapter: 6.2.43 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

type DescriptorUnknown

type DescriptorUnknown struct {
	Header  DescriptorHeader
	Content []byte
}

type DescriptorUserDefined

type DescriptorUserDefined struct {
	Header DescriptorHeader
	Data   []byte
}

type DescriptorVBIData

type DescriptorVBIData struct {
	Header   DescriptorHeader
	Services []DescriptorVBIDataService
}

DescriptorVBIData represents a VBI data descriptor Chapter: 6.2.47 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

type DescriptorVBIDataDescriptor

type DescriptorVBIDataDescriptor struct {
	FieldParity bool
	LineOffset  uint8
}

DescriptorVBIDataItem represents a vbi data descriptor item Chapter: 6.2.47 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

type DescriptorVBIDataService

type DescriptorVBIDataService struct {
	DataServiceID uint8
	Descriptors   []DescriptorVBIDataDescriptor
}

DescriptorVBIDataService represents a vbi data service descriptor Chapter: 6.2.47 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf

type EITData

type EITData struct {
	Events                   []EITDataEvent
	OriginalNetworkID        uint16
	ServiceID                uint16
	TransportStreamID        uint16
	LastTableID              uint8
	SegmentLastSectionNumber uint8
}

EITData represents an EIT data Page: 36 | Chapter: 5.2.4 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf (barbashov) the link above can be broken, alternative: https://dvb.org/wp-content/uploads/2019/12/a038_tm1217r37_en300468v1_17_1_-_rev-134_-_si_specification.pdf

type EITDataEvent

type EITDataEvent struct {
	Descriptors    []Descriptor
	Duration       time.Duration
	StartTime      time.Time
	EventID        uint16
	HasFreeCSAMode bool // When true indicates that access to one or more streams may be controlled by a CA system.
	RunningStatus  uint8
}

EITDataEvent represents an EIT data event

type Muxer

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

func NewMuxer

func NewMuxer(ctx context.Context, w io.Writer, opts ...func(*Muxer)) (m *Muxer)

func (*Muxer) AddElementaryStream

func (m *Muxer) AddElementaryStream(es PMTElementaryStream) error

if es.ElementaryPID is zero, it will be generated automatically

func (*Muxer) RemoveElementaryStream

func (m *Muxer) RemoveElementaryStream(pid uint16) error

func (*Muxer) SetCC

func (m *Muxer) SetCC(pid uint16, cc uint8) error

func (*Muxer) SetPCRPID

func (m *Muxer) SetPCRPID(pid uint16)

SetPCRPID marks pid as one to look PCRs in

func (*Muxer) WriteData

func (m *Muxer) WriteData(d *MuxerData) (bytesWritten int, err error)

WriteData writes MuxerData to TS stream Currently only PES packets are supported Be aware that after successful call WriteData will set d.AdaptationField.StuffingLength value to zero

func (*Muxer) WritePacket

func (m *Muxer) WritePacket(p *Packet) (int, error)

Writes given packet to MPEG-TS stream Stuffs with 0xffs if packet turns out to be shorter than target packet length

func (*Muxer) WriteTables

func (m *Muxer) WriteTables() (bytesWritten int, err error)

type MuxerData

type MuxerData struct {
	PID             uint16
	AdaptationField *PacketAdaptationField
	PES             *PESData
}

MuxerData represents a data to be written by Muxer

type NITData

type NITData struct {
	NetworkDescriptors []Descriptor
	TransportStreams   []NITDataTransportStream
	NetworkID          uint16
}

NITData represents a NIT data Page: 29 | Chapter: 5.2.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf (barbashov) the link above can be broken, alternative: https://dvb.org/wp-content/uploads/2019/12/a038_tm1217r37_en300468v1_17_1_-_rev-134_-_si_specification.pdf

type NITDataTransportStream

type NITDataTransportStream struct {
	TransportDescriptors []Descriptor
	TransportStreamID    uint16
	OriginalNetworkID    uint16
}

NITDataTransportStream represents a NIT data transport stream

type PATData

type PATData struct {
	Programs          []PATProgram
	TransportStreamID uint16
}

PATData represents a PAT data https://en.wikipedia.org/wiki/Program-specific_information

type PATProgram

type PATProgram struct {
	ProgramMapID  uint16 // The packet identifier that contains the associated PMT
	ProgramNumber uint16 // Relates to the Table ID extension in the associated PMT. A value of 0 is reserved for a NIT packet identifier.
}

PATProgram represents a PAT program

type PESHeader

type PESHeader struct {
	OptionalHeader *PESOptionalHeader

	PacketLength uint16 // Specifies the number of bytes remaining in the packet after this field. Can be zero. If the PES packet length is set to zero, the PES packet can be of any length. A value of zero for the PES packet length can be used only when the PES packet payload is a video elementary stream.
	StreamID     uint8  // Examples: Audio streams (0xC0-0xDF), Video streams (0xE0-0xEF)
	// contains filtered or unexported fields
}

PESHeader represents a packet PES header

func (*PESHeader) IsVideoStream

func (h *PESHeader) IsVideoStream() bool

type PESOptionalHeader

type PESOptionalHeader struct {
	DSMTrickMode           *DSMTrickMode
	Extension              *PESOptionalHeaderExtension
	DTS                    ClockReference
	PTS                    ClockReference
	ESCR                   ClockReference
	ESRate                 uint32
	CRC                    uint16
	AdditionalCopyInfo     uint8
	DataAlignmentIndicator bool // True indicates that the PES packet header is immediately followed by the video start code or audio syncword
	HasAdditionalCopyInfo  bool
	HasCRC                 bool
	HasDSMTrickMode        bool
	HasESCR                bool
	HasESRate              bool
	HasExtension           bool
	HasOptionalFields      bool
	HeaderLength           uint8
	IsCopyrighted          bool
	IsOriginal             bool
	MarkerBits             uint8
	Priority               bool
	PTSDTSIndicator        uint8
	ScramblingControl      uint8
}

PESOptionalHeader represents a PES optional header

type PESOptionalHeaderExtension

type PESOptionalHeaderExtension struct {
	PrivateData                     []byte
	Extension2Data                  []byte
	HasPrivateData                  bool
	HasPackHeaderField              bool
	HasProgramPacketSequenceCounter bool
	HasPSTDBuffer                   bool
	HasExtension2                   bool
	PackField                       uint8
	PacketSequenceCounter           uint8
	MPEG1OrMPEG2ID                  uint8
	OriginalStuffingLength          uint8
	PSTDBufferScale                 uint8
	PSTDBufferSize                  uint16
	Extension2Length                uint8
}

type PMTData

type PMTData struct {
	ElementaryStreams  []PMTElementaryStream
	ProgramDescriptors []Descriptor // Program descriptors
	ProgramNumber      uint16
	PCRPID             uint16 // The packet identifier that contains the program clock reference used to improve the random access accuracy of the stream's timing that is derived from the program timestamp. If this is unused. then it is set to 0x1FFF (all bits on).
}

PMTData represents a PMT data https://en.wikipedia.org/wiki/Program-specific_information

type PMTElementaryStream

type PMTElementaryStream struct {
	ElementaryStreamDescriptors []Descriptor // Elementary stream descriptors
	ElementaryPID               uint16       // The packet identifier that contains the stream type data.
	StreamType                  StreamType   // This defines the structure of the data contained within the elementary packet identifier.
}

PMTElementaryStream represents a PMT elementary stream

type PSIData

type PSIData struct {
	PointerField int // Present at the start of the TS packet payload signaled by the payload_unit_start_indicator bit in the TS header. Used to set packet alignment bytes or content before the start of tabled payload data.
	Sections     []PSISection
}

PSIData represents a PSI data https://en.wikipedia.org/wiki/Program-specific_information

type PSISection

type PSISection struct {
	Syntax *PSISectionSyntax
	CRC32  uint32 // A checksum of the entire table excluding the pointer field, pointer filler bytes and the trailing CRC32.
	Header PSISectionHeader
}

PSISection represents a PSI section

type PSISectionHeader

type PSISectionHeader struct {
	SectionLength          uint16     // The number of bytes that follow for the syntax section (with CRC value) and/or table data. These bytes must not exceed a value of 1021.
	TableID                PSITableID // Table Identifier, that defines the structure of the syntax section and other contained data. As an exception, if this is the byte that immediately follow previous table section and is set to 0xFF, then it indicates that the repeat of table section end here and the rest of TS data payload shall be stuffed with 0xFF. Consequently the value 0xFF shall not be used for the Table Identifier.
	SectionSyntaxIndicator bool       // A flag that indicates if the syntax section follows the section length. The PAT, PMT, and CAT all set this to 1.
	PrivateBit             bool       // The PAT, PMT, and CAT all set this to 0. Other tables set this to 1.
}

PSISectionHeader represents a PSI section header

type PSISectionSyntax

type PSISectionSyntax struct {
	Data   PSISectionSyntaxData
	Header PSISectionSyntaxHeader
}

PSISectionSyntax represents a PSI section syntax

type PSISectionSyntaxData

type PSISectionSyntaxData interface{}

PSISectionSyntaxData represents a PSI section syntax data

type PSISectionSyntaxHeader

type PSISectionSyntaxHeader struct {
	CurrentNextIndicator bool   // Indicates if data is current in effect or is for future use. If the bit is flagged on, then the data is to be used at the present moment.
	LastSectionNumber    uint8  // This indicates which table is the last table in the sequence of tables.
	SectionNumber        uint8  // This is an index indicating which table this is in a related sequence of tables. The first table starts from 0.
	VersionNumber        uint8  // Syntax version number. Incremented when data is changed and wrapped around on overflow for values greater than 32.
	TableIDExtension     uint16 // Informational only identifier. The PAT uses this for the transport stream identifier and the PMT uses this for the Program number.
}

PSISectionSyntaxHeader represents a PSI section syntax header

type PSITableID

type PSITableID uint8
const (
	PSITableIDPAT PSITableID = 0x00
	PSITableIDPMT PSITableID = 0x02

	PSITableIDNITVariant1 PSITableID = 0x40
	PSITableIDNITVariant2 PSITableID = 0x41
	PSITableIDSDTVariant1 PSITableID = 0x42
	PSITableIDSDTVariant2 PSITableID = 0x46

	PSITableIDBAT PSITableID = 0x4a

	PSITableIDEITStart PSITableID = 0x4e
	PSITableIDEITEnd   PSITableID = 0x6f

	PSITableIDTDT PSITableID = 0x70
	PSITableIDRST PSITableID = 0x71
	PSITableIDST  PSITableID = 0x72
	PSITableIDTOT PSITableID = 0x73

	PSITableIDDIT PSITableID = 0x7e
	PSITableIDSIT PSITableID = 0x7f

	PSITableIDNull PSITableID = 0xff
)

func (PSITableID) Type

func (t PSITableID) Type() string

PSITableID.Type() returns the psi table type based on the table id Page: 28 | https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf (barbashov) the link above can be broken, alternative: https://dvb.org/wp-content/uploads/2019/12/a038_tm1217r37_en300468v1_17_1_-_rev-134_-_si_specification.pdf

type Packet

type Packet struct {
	Header          PacketHeader
	AdaptationField *PacketAdaptationField
	Payload         []byte // This is only the payload content

	// Offset is the byte offset of the raw packet start (including any M2TS prefix)
	// within the demuxed stream, counted from the Demuxer's first packet. Packets
	// dropped by a PacketSkipper advance it too, so it stays a valid byte map.
	Offset int64
	// contains filtered or unexported fields
}

Packet represents a packet https://en.wikipedia.org/wiki/MPEG_transport_stream

func NewPacket

func NewPacket() (p *Packet)

func (*Packet) Close

func (p *Packet) Close()

func (*Packet) Next

func (p *Packet) Next() *Packet

func (*Packet) Reset

func (p *Packet) Reset()

Reset deliberately keeps bs: it is fully overwritten by the next read before any parse, and zeroing it per packet doubles the per-packet memory traffic.

func (*Packet) UpdateHeader

func (p *Packet) UpdateHeader()

type PacketAdaptationExtensionField

type PacketAdaptationExtensionField struct {
	DTSNextAccessUnit      ClockReference // The PES DTS of the splice point. Split up as 3 bits, 1 marker bit (0x1), 15 bits, 1 marker bit, 15 bits, and 1 marker bit, for 33 data bits total.
	PiecewiseRate          uint32         // The rate of the stream, measured in 188-byte packets, to define the end-time of the LTW.
	LegalTimeWindowOffset  uint16         // Extra information for rebroadcasters to determine the state of buffers when packets may be missing.
	LegalTimeWindowIsValid bool
	HasLegalTimeWindow     bool
	HasPiecewiseRate       bool
	HasSeamlessSplice      bool
	Length                 uint8
	SpliceType             uint8 // Indicates the parameters of the H.262 splice.
}

PacketAdaptationExtensionField represents a packet adaptation extension field

type PacketAdaptationField

type PacketAdaptationField struct {
	AdaptationExtensionField          *PacketAdaptationExtensionField
	OPCR                              ClockReference // Original Program clock reference. Helps when one TS is copied into another
	PCR                               ClockReference // Program clock reference
	TransportPrivateData              []byte         // points into privBuf after parse — owned by this struct, survives value copies via repoint
	TransportPrivateDataLength        uint8
	Length                            uint8
	StuffingLength                    uint8 // Only used in writePacketAdaptationField to request stuffing
	SpliceCountdown                   uint8 // Indicates how many TS packets from this one a splicing point occurs (Two's complement signed; may be negative)
	IsOneByteStuffing                 bool  // Only used for one byte stuffing - if true, adaptation field will be written as one uint8(0). Not part of TS format
	DiscontinuityIndicator            bool  // Set if current TS packet is in a discontinuity state with respect to either the continuity counter or the program clock reference
	RandomAccessIndicator             bool  // Set when the stream may be decoded without errors from this point
	ElementaryStreamPriorityIndicator bool  // Set when this stream should be considered "high priority"
	HasPCR                            bool
	HasOPCR                           bool
	HasSplicingCountdown              bool
	HasTransportPrivateData           bool
	HasAdaptationExtensionField       bool
	// contains filtered or unexported fields
}

PacketAdaptationField represents a packet adaptation field

type PacketHeader

type PacketHeader struct {
	ContinuityCounter          uint8 // Sequence number of payload packets (0x00 to 0x0F) within each stream (except PID 8191)
	HasAdaptationField         bool
	HasPayload                 bool
	PayloadUnitStartIndicator  bool   // Set when a PES, PSI, or DVB-MIP packet begins immediately following the header.
	PID                        uint16 // Packet Identifier, describing the payload data.
	TransportErrorIndicator    bool   // Set when a demodulator can't correct errors from FEC data; indicating the packet is corrupt.
	TransportPriority          bool   // Set when the current packet has a higher priority than other packets with the same PID.
	TransportScramblingControl uint8
}

PacketHeader represents a packet header

type PacketList

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

func NewPacketList

func NewPacketList() *PacketList

func (*PacketList) Clear

func (pl *PacketList) Clear()

func (*PacketList) Close

func (pl *PacketList) Close()

Close clears the list and returns it to the pool: only when no references remain

func (*PacketList) Head

func (pl *PacketList) Head() *Packet

func (*PacketList) IsEmpty

func (pl *PacketList) IsEmpty() bool

func (*PacketList) Length

func (pl *PacketList) Length() int

func (*PacketList) PushBack

func (pl *PacketList) PushBack(p *Packet)

func (*PacketList) Size

func (pl *PacketList) Size() int

func (*PacketList) Tail

func (pl *PacketList) Tail() *Packet

type PacketSkipper

type PacketSkipper func(p *Packet) (skip bool)

PacketSkipper represents an object capable of skipping a packet before parsing its payload. Its header and adaptation field is parsed and provided to the object. Use this option if you need to filter out unwanted packets from your pipeline. NextPacket() will return the next unskipped packet if any.

type PacketsParser

type PacketsParser func(pl *PacketList) (ds []*DemuxerData, skip bool, err error)

PacketsParser represents an object capable of parsing a set of packets containing a unique payload spanning over those packets Use the skip returned argument to indicate whether the default process should still be executed on the set of packets

type SDTData

type SDTData struct {
	Services          []SDTDataService
	OriginalNetworkID uint16
	TransportStreamID uint16
}

SDTData represents an SDT data Page: 33 | Chapter: 5.2.3 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf (barbashov) the link above can be broken, alternative: https://dvb.org/wp-content/uploads/2019/12/a038_tm1217r37_en300468v1_17_1_-_rev-134_-_si_specification.pdf

type SDTDataService

type SDTDataService struct {
	Descriptors            []Descriptor
	ServiceID              uint16
	HasEITPresentFollowing bool // When true indicates that EIT present/following information for the service is present in the current TS
	HasEITSchedule         bool // When true indicates that EIT schedule information for the service is present in the current TS
	HasFreeCSAMode         bool // When true indicates that access to one or more streams may be controlled by a CA system.
	RunningStatus          uint8
}

SDTDataService represents an SDT data service

type StreamType

type StreamType uint8
const (
	StreamTypeMPEG1Video                 StreamType = 0x01
	StreamTypeMPEG2Video                 StreamType = 0x02
	StreamTypeMPEG1Audio                 StreamType = 0x03 // ISO/IEC 11172-3
	StreamTypeMPEG2HalvedSampleRateAudio StreamType = 0x04 // ISO/IEC 13818-3
	StreamTypeMPEG2Audio                 StreamType = 0x04
	StreamTypePrivateSection             StreamType = 0x05
	StreamTypePrivateData                StreamType = 0x06
	StreamTypeMPEG2PacketizedData        StreamType = 0x06 // Rec. ITU-T H.222 | ISO/IEC 13818-1 i.e., DVB subtitles/VBI and AC-3
	StreamTypeADTS                       StreamType = 0x0F // ISO/IEC 13818-7 Audio with ADTS transport syntax
	StreamTypeAACAudio                   StreamType = 0x0f
	StreamTypeMPEG4Video                 StreamType = 0x10
	StreamTypeAACLATMAudio               StreamType = 0x11
	StreamTypeMetadata                   StreamType = 0x15
	StreamTypeH264Video                  StreamType = 0x1B // Rec. ITU-T H.264 | ISO/IEC 14496-10
	StreamTypeH265Video                  StreamType = 0x24 // Rec. ITU-T H.265 | ISO/IEC 23008-2
	StreamTypeHEVCVideo                  StreamType = 0x24
	StreamTypeCAVSVideo                  StreamType = 0x42
	StreamTypeVC1Video                   StreamType = 0xea
	StreamTypeDIRACVideo                 StreamType = 0xd1
	StreamTypeAC3Audio                   StreamType = 0x81
	StreamTypeDTSAudio                   StreamType = 0x82
	StreamTypeTRUEHDAudio                StreamType = 0x83
	StreamTypeSCTE35                     StreamType = 0x86
	StreamTypeEAC3Audio                  StreamType = 0x87
)

Stream types

func (StreamType) IsAudio

func (t StreamType) IsAudio() bool

func (StreamType) IsVideo

func (t StreamType) IsVideo() bool

func (StreamType) String

func (t StreamType) String() string

func (StreamType) ToPESStreamID

func (t StreamType) ToPESStreamID() uint8

type TOTData

type TOTData struct {
	Descriptors []Descriptor
	UTCTime     time.Time
}

TOTData represents a TOT data Page: 39 | Chapter: 5.2.6 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf (barbashov) the link above can be broken, alternative: https://dvb.org/wp-content/uploads/2019/12/a038_tm1217r37_en300468v1_17_1_-_rev-134_-_si_specification.pdf

Directories

Path Synopsis
cmd
astits-es-split command
astits-probe command
internal
cmd/crc32_table command

Jump to

Keyboard shortcuts

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