stream/mts: adding some constants

This commit is contained in:
saxon 2019-01-25 16:25:01 +10:30
parent 90a85fbfbb
commit a6d02a2e02
2 changed files with 61 additions and 27 deletions

View File

@ -171,14 +171,6 @@ var (
pmtTable = standardPmtTimeLocation.Bytes()
)
const (
sdtPid = 17
patPid = 0
pmtPid = 4096
videoPid = 256
streamID = 0xe0 // First video stream ID.
)
// Time related constants.
const (
// ptsOffset is the offset added to the clock to determine
@ -213,18 +205,13 @@ func NewEncoder(dst io.Writer, fps float64) *Encoder {
ptsOffset: ptsOffset,
continuity: map[int]byte{
patPid: 0,
pmtPid: 0,
videoPid: 0,
PatPid: 0,
PmtPid: 0,
VideoPid: 0,
},
}
}
const (
hasPayload = 0x1
hasAdaptationField = 0x2
)
const (
hasDTS = 0x1
hasPTS = 0x2
@ -244,7 +231,7 @@ func (e *Encoder) Encode(nalu []byte) error {
// Prepare PES data.
pesPkt := pes.Packet{
StreamID: streamID,
StreamID: StreamID,
PDI: hasPTS,
PTS: e.pts(),
Data: nalu,
@ -256,10 +243,10 @@ func (e *Encoder) Encode(nalu []byte) error {
for len(buf) != 0 {
pkt := Packet{
PUSI: pusi,
PID: videoPid,
PID: VideoPid,
RAI: pusi,
CC: e.ccFor(videoPid),
AFC: hasAdaptationField | hasPayload,
CC: e.ccFor(VideoPid),
AFC: HasAdaptationField | HasPayload,
PCRF: pusi,
}
n := pkt.FillPayload(buf)
@ -288,9 +275,9 @@ func (e *Encoder) writePSI() error {
// Write PAT.
patPkt := Packet{
PUSI: true,
PID: patPid,
CC: e.ccFor(patPid),
AFC: hasPayload,
PID: PatPid,
CC: e.ccFor(PatPid),
AFC: HasPayload,
Payload: patTable,
}
_, err := e.dst.Write(patPkt.Bytes(e.tsSpace[:PacketSize]))
@ -311,9 +298,9 @@ func (e *Encoder) writePSI() error {
// Create mts packet from pmt table.
pmtPkt := Packet{
PUSI: true,
PID: pmtPid,
CC: e.ccFor(pmtPid),
AFC: hasPayload,
PID: PmtPid,
CC: e.ccFor(PmtPid),
AFC: HasPayload,
Payload: pmtTable,
}
_, err = e.dst.Write(pmtPkt.Bytes(e.tsSpace[:PacketSize]))

View File

@ -37,6 +37,53 @@ const (
PayloadSize = 176
)
const (
SdtPid = 17
PatPid = 0
PmtPid = 4096
VideoPid = 256
StreamID = 0xe0 // First video stream ID.
HeadSize = 4
DefaultAdaptationSize = 2
)
const (
AdaptationIdx = 4
AdaptationControlIdx = 3
AdaptationBodyIdx = AdaptationIdx + 1
AdaptationControlMask = 0x30
DefaultAdaptationBodySize = 1
)
const (
HasPayload = 0x1
HasAdaptationField = 0x2
)
// Adaptation field body masks.
const (
DiscontinuityIndicatorMask = 0x80
RandomAccessIndicatorMask = 0x40
ElementaryStreamPriorityIndicatorMask = 0x20
ProgramClockReferenceFlagMask = 0x10
OriginalProgramClockReferenceFlagMask = 0x08
SplicingPointFlagMask = 0x04
TransportPrivateDataFlagMask = 0x02
AdaptationFieldExtensionMask = 0x01
)
// Adaptation field body indexes.
const (
DiscontinuityIndicatorIdx = AdaptationIdx + 1
RandomAccessIndicatorIdx = AdaptationIdx + 1
ElementaryStreamPriorityIndicatorIdx = AdaptationIdx + 1
ProgramClockReferenceFlagIdx = AdaptationIdx + 1
OriginalProgramClockReferenceFlagIdx = AdaptationIdx + 1
SplicingPointFlagIdx = AdaptationIdx + 1
TransportPrivateDataFlagIdx = AdaptationIdx + 1
AdaptationFieldExtensionFlagIdx = AdaptationIdx + 1
)
/*
The below data struct encapsulates the fields of an MPEG-TS packet. Below is
the formatting of an MPEG-TS packet for reference!
@ -135,7 +182,7 @@ func FindPMT(d []byte) (p []byte, i int, err error) {
}
for i = 0; i < len(d); i += PacketSize {
pid := (uint16(d[i+1]&0x1f) << 8) | uint16(d[i+2])
if pid == pmtPid {
if pid == PmtPid {
p = d[i+4 : i+PacketSize]
return
}