mirror of https://bitbucket.org/ausocean/av.git
stream/mts: adding some constants
This commit is contained in:
parent
c4d68f1562
commit
aea41fb710
|
@ -171,14 +171,6 @@ var (
|
||||||
pmtTable = standardPmtTimeLocation.Bytes()
|
pmtTable = standardPmtTimeLocation.Bytes()
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
sdtPid = 17
|
|
||||||
patPid = 0
|
|
||||||
pmtPid = 4096
|
|
||||||
videoPid = 256
|
|
||||||
streamID = 0xe0 // First video stream ID.
|
|
||||||
)
|
|
||||||
|
|
||||||
// Time related constants.
|
// Time related constants.
|
||||||
const (
|
const (
|
||||||
// ptsOffset is the offset added to the clock to determine
|
// ptsOffset is the offset added to the clock to determine
|
||||||
|
@ -213,18 +205,13 @@ func NewEncoder(dst io.Writer, fps float64) *Encoder {
|
||||||
ptsOffset: ptsOffset,
|
ptsOffset: ptsOffset,
|
||||||
|
|
||||||
continuity: map[int]byte{
|
continuity: map[int]byte{
|
||||||
patPid: 0,
|
PatPid: 0,
|
||||||
pmtPid: 0,
|
PmtPid: 0,
|
||||||
videoPid: 0,
|
VideoPid: 0,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
hasPayload = 0x1
|
|
||||||
hasAdaptationField = 0x2
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
hasDTS = 0x1
|
hasDTS = 0x1
|
||||||
hasPTS = 0x2
|
hasPTS = 0x2
|
||||||
|
@ -241,7 +228,7 @@ func (e *Encoder) Encode(nalu []byte) error {
|
||||||
}
|
}
|
||||||
// Prepare PES data.
|
// Prepare PES data.
|
||||||
pesPkt := pes.Packet{
|
pesPkt := pes.Packet{
|
||||||
StreamID: streamID,
|
StreamID: StreamID,
|
||||||
PDI: hasPTS,
|
PDI: hasPTS,
|
||||||
PTS: e.pts(),
|
PTS: e.pts(),
|
||||||
Data: nalu,
|
Data: nalu,
|
||||||
|
@ -253,10 +240,10 @@ func (e *Encoder) Encode(nalu []byte) error {
|
||||||
for len(buf) != 0 {
|
for len(buf) != 0 {
|
||||||
pkt := Packet{
|
pkt := Packet{
|
||||||
PUSI: pusi,
|
PUSI: pusi,
|
||||||
PID: videoPid,
|
PID: VideoPid,
|
||||||
RAI: pusi,
|
RAI: pusi,
|
||||||
CC: e.ccFor(videoPid),
|
CC: e.ccFor(VideoPid),
|
||||||
AFC: hasAdaptationField | hasPayload,
|
AFC: HasAdaptationField | HasPayload,
|
||||||
PCRF: pusi,
|
PCRF: pusi,
|
||||||
}
|
}
|
||||||
n := pkt.FillPayload(buf)
|
n := pkt.FillPayload(buf)
|
||||||
|
@ -286,9 +273,9 @@ func (e *Encoder) writePSI() error {
|
||||||
// Write PAT.
|
// Write PAT.
|
||||||
patPkt := Packet{
|
patPkt := Packet{
|
||||||
PUSI: true,
|
PUSI: true,
|
||||||
PID: patPid,
|
PID: PatPid,
|
||||||
CC: e.ccFor(patPid),
|
CC: e.ccFor(PatPid),
|
||||||
AFC: hasPayload,
|
AFC: HasPayload,
|
||||||
Payload: patTable,
|
Payload: patTable,
|
||||||
}
|
}
|
||||||
_, err := e.dst.Write(patPkt.Bytes(e.tsSpace[:PacketSize]))
|
_, err := e.dst.Write(patPkt.Bytes(e.tsSpace[:PacketSize]))
|
||||||
|
@ -309,9 +296,9 @@ func (e *Encoder) writePSI() error {
|
||||||
// Create mts packet from pmt table.
|
// Create mts packet from pmt table.
|
||||||
pmtPkt := Packet{
|
pmtPkt := Packet{
|
||||||
PUSI: true,
|
PUSI: true,
|
||||||
PID: pmtPid,
|
PID: PmtPid,
|
||||||
CC: e.ccFor(pmtPid),
|
CC: e.ccFor(PmtPid),
|
||||||
AFC: hasPayload,
|
AFC: HasPayload,
|
||||||
Payload: pmtTable,
|
Payload: pmtTable,
|
||||||
}
|
}
|
||||||
_, err = e.dst.Write(pmtPkt.Bytes(e.tsSpace[:PacketSize]))
|
_, err = e.dst.Write(pmtPkt.Bytes(e.tsSpace[:PacketSize]))
|
||||||
|
|
|
@ -37,6 +37,53 @@ const (
|
||||||
PayloadSize = 176
|
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 below data struct encapsulates the fields of an MPEG-TS packet. Below is
|
||||||
the formatting of an MPEG-TS packet for reference!
|
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 {
|
for i = 0; i < len(d); i += PacketSize {
|
||||||
pid := (uint16(d[i+1]&0x1f) << 8) | uint16(d[i+2])
|
pid := (uint16(d[i+1]&0x1f) << 8) | uint16(d[i+2])
|
||||||
if pid == pmtPid {
|
if pid == PmtPid {
|
||||||
p = d[i+4 : i+PacketSize]
|
p = d[i+4 : i+PacketSize]
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue