astits

package module
Version: v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2021 License: MIT Imports: 10 Imported by: 24

README

GoReportCard GoDoc Travis Coveralls

This is a Golang library to natively demux and mux MPEG Transport Streams (ts) in GO.

WARNING: this library is not yet production ready. Use at your own risks!

Installation

To install the library use the following:

go get -u github.com/asticode/go-astits/...

Before looking at the code...

The transport stream is made of packets.
Each packet has a header, an optional adaptation field and a payload.
Several payloads can be appended and parsed as a data.

                                           TRANSPORT STREAM
 +--------------------------------------------------------------------------------------------------+
 |                                                                                                  |
 
                       PACKET                                         PACKET
 +----------------------------------------------+----------------------------------------------+----
 |                                              |                                              |
 
 +--------+---------------------------+---------+--------+---------------------------+---------+
 | HEADER | OPTIONAL ADAPTATION FIELD | PAYLOAD | HEADER | OPTIONAL ADAPTATION FIELD | PAYLOAD | ...
 +--------+---------------------------+---------+--------+---------------------------+---------+
 
                                      |         |                                    |         |
                                      +---------+                                    +---------+
                                           |                                              |
                                           +----------------------------------------------+
                                                                DATA

Using the library in your code

WARNING: the code below doesn't handle errors for readability purposes. However you SHOULD!

Demux

// Create a cancellable context in case you want to stop reading packets/data any time you want
ctx, cancel := context.WithCancel(context.Background())

// Handle SIGTERM signal
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGTERM)
go func() {
    <-ch
    cancel()
}()

// Open your file or initialize any kind of io.Reader
// Buffering using bufio.Reader is recommended for performance
f, _ := os.Open("/path/to/file.ts")
defer f.Close()

// Create the demuxer
dmx := astits.NewDemuxer(ctx, f)
for {
    // Get the next data
    d, _ := dmx.NextData()
    
    // Data is a PMT data
    if d.PMT != nil {
        // Loop through elementary streams
        for _, es := range d.PMT.ElementaryStreams {
                fmt.Printf("Stream detected: %d\n", es.ElementaryPID)
        }
        return
    }
}

Mux

// Create a cancellable context in case you want to stop writing packets/data any time you want
ctx, cancel := context.WithCancel(context.Background())

// Handle SIGTERM signal
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGTERM)
go func() {
    <-ch
    cancel()
}()

// Create your file or initialize any kind of io.Writer
// Buffering using bufio.Writer is recommended for performance
f, _ := os.Create("/path/to/file.ts")
defer f.Close()

// Create the muxer
mx := astits.NewMuxer(ctx, f)

// Add an elementary stream
mx.AddElementaryStream(astits.PMTElementaryStream{
    ElementaryPID: 1,
    StreamType:    astits.StreamTypeMetadata,
})

// Write tables
// Using that function is not mandatory, WriteData will retransmit tables from time to time 
mx.WriteTables()

// Write data
mx.WriteData(&astits.MuxerData{
    PES: &astits.PESData{
        Data: []byte("test"),
    },
    PID: 1,
})

Options

In order to pass options to the demuxer or the muxer, look for the methods prefixed with DemuxerOpt or MuxerOpt and add them upon calling NewDemuxer or NewMuxer :

// This is your custom packets parser
p := func(ps []*astits.Packet) (ds []*astits.Data, skip bool, err error) {
        // This is your logic
        skip = true
        return
}

// Now you can create a demuxer with the proper options
dmx := NewDemuxer(ctx, f, DemuxerOptPacketSize(192), DemuxerOptPacketsParser(p))

CLI

This library provides 2 CLIs that will automatically get installed in GOPATH/bin on go get execution.

astits-probe

List streams
$ astits-probe -i <path to your file> -f <format: text|json (default: text)>
List packets
$ astits-probe packets -i <path to your file>
List data
$ astits-probe data -i <path to your file> -d <data type: eit|nit|... (repeatable argument | if empty, all data types are shown)>

astits-es-split

Split streams into separate .ts files
$ astits-es-split <path to your file> -o <path to output dir>

Features and roadmap

  • Add demuxer
  • Add muxer
  • Demux PES packets
  • Mux PES packets
  • Demux PAT packets
  • Mux PAT packets
  • Demux PMT packets
  • Mux PMT packets
  • Demux EIT packets
  • Mux EIT packets
  • Demux NIT packets
  • Mux NIT packets
  • Demux SDT packets
  • Mux SDT packets
  • Demux TOT packets
  • Mux TOT packets
  • Demux BAT packets
  • Mux BAT packets
  • Demux DIT packets
  • Mux DIT packets
  • Demux RST packets
  • Mux RST packets
  • Demux SIT packets
  • Mux SIT packets
  • Mux ST packets
  • Demux TDT packets
  • Mux TDT packets
  • Demux TSDT packets
  • Mux TSDT packets

Documentation

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

Descriptor tags Chapter: 6.1 | Link: https://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.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 (
	VBIDataServiceIDClosedCaptioning     = 0x6
	VBIDataServiceIDEBUTeletext          = 0x1
	VBIDataServiceIDInvertedTeletext     = 0x2
	VBIDataServiceIDMonochrome442Samples = 0x7
	VBIDataServiceIDVPS                  = 0x4
	VBIDataServiceIDWSS                  = 0x5
)

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 (
	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 (
	MpegTsPacketSize = 188
)
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")
)

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")
)

Functions

func DemuxerOptPacketSize added in v1.7.0

func DemuxerOptPacketSize(packetSize int) func(*Demuxer)

DemuxerOptPacketSize returns the option to set the packet size

func DemuxerOptPacketsParser added in v1.7.0

func DemuxerOptPacketsParser(p PacketsParser) func(*Demuxer)

DemuxerOptPacketsParser returns the option to set the packets parser

func MuxerOptTablesRetransmitPeriod added in v1.7.0

func MuxerOptTablesRetransmitPeriod(newPeriod int) func(*Muxer)

Types

type ClockReference

type ClockReference struct {
	Base, Extension int64
}

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

func (ClockReference) Duration

func (p ClockReference) Duration() time.Duration

Duration converts the clock reference into duration

func (ClockReference) Time

func (p 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 added in v1.7.0

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) 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

func (*Demuxer) Rewind

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

Rewind rewinds the demuxer reader

type DemuxerData added in v1.7.0

type DemuxerData struct {
	EIT         *EITData
	FirstPacket *Packet
	NIT         *NITData
	PAT         *PATData
	PES         *PESData
	PID         uint16
	PMT         *PMTData
	SDT         *SDTData
	TOT         *TOTData
}

DemuxerData represents a data parsed by Demuxer

type Descriptor

type Descriptor struct {
	AC3                        *DescriptorAC3
	AVCVideo                   *DescriptorAVCVideo
	Component                  *DescriptorComponent
	Content                    *DescriptorContent
	DataStreamAlignment        *DescriptorDataStreamAlignment
	EnhancedAC3                *DescriptorEnhancedAC3
	ExtendedEvent              *DescriptorExtendedEvent
	Extension                  *DescriptorExtension
	ISO639LanguageAndAudioType *DescriptorISO639LanguageAndAudioType
	Length                     uint8
	LocalTimeOffset            *DescriptorLocalTimeOffset
	MaximumBitrate             *DescriptorMaximumBitrate
	NetworkName                *DescriptorNetworkName
	ParentalRating             *DescriptorParentalRating
	PrivateDataIndicator       *DescriptorPrivateDataIndicator
	PrivateDataSpecifier       *DescriptorPrivateDataSpecifier
	Registration               *DescriptorRegistration
	Service                    *DescriptorService
	ShortEvent                 *DescriptorShortEvent
	StreamIdentifier           *DescriptorStreamIdentifier
	Subtitling                 *DescriptorSubtitling
	Tag                        uint8 // the tag defines the structure of the contained data following the descriptor length.
	Teletext                   *DescriptorTeletext
	Unknown                    *DescriptorUnknown
	UserDefined                []byte
	VBIData                    *DescriptorVBIData
	VBITeletext                *DescriptorTeletext
}

Descriptor represents a descriptor TODO Handle UTF8

type DescriptorAC3

type DescriptorAC3 struct {
	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 {
	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 {
	ComponentTag       uint8
	ComponentType      uint8
	ISO639LanguageCode []byte
	StreamContent      uint8
	StreamContentExt   uint8
	Text               []byte
}

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 {
	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 {
	Type uint8
}

DescriptorDataStreamAlignment represents a data stream alignment descriptor

type DescriptorEnhancedAC3

type DescriptorEnhancedAC3 struct {
	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 {
	ISO639LanguageCode   []byte
	Items                []*DescriptorExtendedEventItem
	LastDescriptorNumber uint8
	Number               uint8
	Text                 []byte
}

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 {
	SupplementaryAudio *DescriptorExtensionSupplementaryAudio
	Tag                uint8
	Unknown            *[]byte
}

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 {
	EditorialClassification uint8
	HasLanguageCode         bool
	LanguageCode            []byte
	MixType                 bool
	PrivateData             []byte
}

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 DescriptorISO639LanguageAndAudioType

type DescriptorISO639LanguageAndAudioType struct {
	Language []byte
	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 {
	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 {
	CountryCode             []byte
	CountryRegionID         uint8
	LocalTimeOffset         time.Duration
	LocalTimeOffsetPolarity bool
	NextTimeOffset          time.Duration
	TimeOfChange            time.Time
}

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
}

DescriptorMaximumBitrate represents a maximum bitrate descriptor

type DescriptorNetworkName

type DescriptorNetworkName struct {
	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 {
	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 []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 DescriptorPrivateDataIndicator

type DescriptorPrivateDataIndicator struct {
	Indicator uint32
}

DescriptorPrivateDataIndicator represents a private data Indicator descriptor

type DescriptorPrivateDataSpecifier

type DescriptorPrivateDataSpecifier struct {
	Specifier uint32
}

DescriptorPrivateDataSpecifier represents a private data specifier descriptor

type DescriptorRegistration

type DescriptorRegistration struct {
	AdditionalIdentificationInfo []byte
	FormatIdentifier             uint32
}

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
	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 {
	EventName []byte
	Language  []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 {
	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 {
	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 {
	AncillaryPageID   uint16
	CompositionPageID uint16
	Language          []byte
	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 DescriptorTeletext

type DescriptorTeletext struct {
	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 []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 added in v1.6.0

type DescriptorUnknown struct {
	Content []byte
	Tag     uint8
}

type DescriptorVBIData

type DescriptorVBIData struct {
	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
	LastTableID              uint8
	OriginalNetworkID        uint16
	SegmentLastSectionNumber uint8
	ServiceID                uint16
	TransportStreamID        uint16
}

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
	EventID        uint16
	HasFreeCSAMode bool // When true indicates that access to one or more streams may be controlled by a CA system.
	RunningStatus  uint8
	StartTime      time.Time
}

EITDataEvent represents an EIT data event

type Muxer added in v1.7.0

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

func NewMuxer added in v1.7.0

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

func (*Muxer) AddElementaryStream added in v1.7.0

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

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

func (*Muxer) RemoveElementaryStream added in v1.7.0

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

func (*Muxer) SetPCRPID added in v1.7.0

func (m *Muxer) SetPCRPID(pid uint16)

SetPCRPID marks pid as one to look PCRs in

func (*Muxer) WriteData added in v1.7.0

func (m *Muxer) WriteData(d *MuxerData) (int, 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 added in v1.7.0

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 added in v1.7.0

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

type MuxerData added in v1.7.0

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
	NetworkID          uint16
	TransportStreams   []*NITDataTransportStream
}

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 {
	OriginalNetworkID    uint16
	TransportDescriptors []*Descriptor
	TransportStreamID    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)
}

PESHeader represents a packet PES header

func (*PESHeader) IsVideoStream added in v1.7.0

func (h *PESHeader) IsVideoStream() bool

type PESOptionalHeader

type PESOptionalHeader struct {
	AdditionalCopyInfo              uint8
	CRC                             uint16
	DataAlignmentIndicator          bool // True indicates that the PES packet header is immediately followed by the video start code or audio syncword
	DSMTrickMode                    *DSMTrickMode
	DTS                             *ClockReference
	ESCR                            *ClockReference
	ESRate                          uint32
	Extension2Data                  []byte
	Extension2Length                uint8
	HasAdditionalCopyInfo           bool
	HasCRC                          bool
	HasDSMTrickMode                 bool
	HasESCR                         bool
	HasESRate                       bool
	HasExtension                    bool
	HasExtension2                   bool
	HasOptionalFields               bool
	HasPackHeaderField              bool
	HasPrivateData                  bool
	HasProgramPacketSequenceCounter bool
	HasPSTDBuffer                   bool
	HeaderLength                    uint8
	IsCopyrighted                   bool
	IsOriginal                      bool
	MarkerBits                      uint8
	MPEG1OrMPEG2ID                  uint8
	OriginalStuffingLength          uint8
	PacketSequenceCounter           uint8
	PackField                       uint8
	Priority                        bool
	PrivateData                     []byte
	PSTDBufferScale                 uint8
	PSTDBufferSize                  uint16
	PTS                             *ClockReference
	PTSDTSIndicator                 uint8
	ScramblingControl               uint8
}

PESOptionalHeader represents a PES optional header

type PMTData

type PMTData struct {
	ElementaryStreams  []*PMTElementaryStream
	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).
	ProgramDescriptors []*Descriptor // Program descriptors
	ProgramNumber      uint16
}

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

type PMTElementaryStream

type PMTElementaryStream struct {
	ElementaryPID               uint16        // The packet identifier that contains the stream type data.
	ElementaryStreamDescriptors []*Descriptor // Elementary stream descriptors
	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 {
	CRC32  uint32 // A checksum of the entire table excluding the pointer field, pointer filler bytes and the trailing CRC32.
	Header *PSISectionHeader
	Syntax *PSISectionSyntax
}

PSISection represents a PSI section

type PSISectionHeader

type PSISectionHeader struct {
	PrivateBit             bool       // The PAT, PMT, and CAT all set this to 0. Other tables set this to 1.
	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.
	SectionSyntaxIndicator bool       // A flag that indicates if the syntax section follows the section length. The PAT, PMT, and CAT all set this to 1.
	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.
	TableType              string
}

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 struct {
	EIT *EITData
	NIT *NITData
	PAT *PATData
	PMT *PMTData
	SDT *SDTData
	TOT *TOTData
}

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.
	TableIDExtension     uint16 // Informational only identifier. The PAT uses this for the transport stream identifier and the PMT uses this for the Program number.
	VersionNumber        uint8  // Syntax version number. Incremented when data is changed and wrapped around on overflow for values greater than 32.
}

PSISectionSyntaxHeader represents a PSI section syntax header

type PSITableID added in v1.7.0

type PSITableID uint16
const (
	PSITableIDPAT  PSITableID = 0x00
	PSITableIDPMT  PSITableID = 0x02
	PSITableIDBAT  PSITableID = 0x4a
	PSITableIDDIT  PSITableID = 0x7e
	PSITableIDRST  PSITableID = 0x71
	PSITableIDSIT  PSITableID = 0x7f
	PSITableIDST   PSITableID = 0x72
	PSITableIDTDT  PSITableID = 0x70
	PSITableIDTOT  PSITableID = 0x73
	PSITableIDNull PSITableID = 0xff

	PSITableIDEITStart    PSITableID = 0x4e
	PSITableIDEITEnd      PSITableID = 0x6f
	PSITableIDSDTVariant1 PSITableID = 0x42
	PSITableIDSDTVariant2 PSITableID = 0x46
	PSITableIDNITVariant1 PSITableID = 0x40
	PSITableIDNITVariant2 PSITableID = 0x41
)

func (PSITableID) Type added in v1.7.0

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 {
	AdaptationField *PacketAdaptationField
	Header          *PacketHeader
	Payload         []byte // This is only the payload content
}

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

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.
	HasLegalTimeWindow     bool
	HasPiecewiseRate       bool
	HasSeamlessSplice      bool
	LegalTimeWindowIsValid bool
	LegalTimeWindowOffset  uint16 // Extra information for rebroadcasters to determine the state of buffers when packets may be missing.
	Length                 int
	PiecewiseRate          uint32 // The rate of the stream, measured in 188-byte packets, to define the end-time of the LTW.
	SpliceType             uint8  // Indicates the parameters of the H.262 splice.
}

PacketAdaptationExtensionField represents a packet adaptation extension field

type PacketAdaptationField

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

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 PacketsParser

type PacketsParser func(ps []*Packet) (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 {
	OriginalNetworkID uint16
	Services          []*SDTDataService
	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
	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
	ServiceID              uint16
}

SDTDataService represents an SDT data service

type StreamType added in v1.7.0

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
	StreamTypeEAC3Audio                  StreamType = 0x87
)

Stream types

func (StreamType) IsAudio added in v1.7.0

func (t StreamType) IsAudio() bool

func (StreamType) IsVideo added in v1.7.0

func (t StreamType) IsVideo() bool

func (StreamType) String added in v1.7.0

func (t StreamType) String() string

func (StreamType) ToPESStreamID added in v1.7.0

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

Jump to

Keyboard shortcuts

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