mirror of https://bitbucket.org/ausocean/av.git
Added GetPTS.
This commit is contained in:
parent
aa67134969
commit
9e5bc3806f
|
@ -424,9 +424,9 @@ var errNoPesPTS = errors.New("no PES PTS")
|
||||||
var errInvalidPesHeader = errors.New("invalid PES header")
|
var errInvalidPesHeader = errors.New("invalid PES header")
|
||||||
var errInvalidPesPayload = errors.New("invalid PES payload")
|
var errInvalidPesPayload = errors.New("invalid PES payload")
|
||||||
|
|
||||||
// GetPTS returns a PTS from an MTS packet that has PES payload, or an error otherwise.
|
// GetPTS returns a PTS from a packet that has PES payload, or an error otherwise.
|
||||||
func GetPTS(pkt []byte) (pts int64, err error) {
|
func GetPTS(pkt []byte) (pts int64, err error) {
|
||||||
// Bail if packet does not contain a PES.
|
// Check the Payload Unit Start Indicator.
|
||||||
if pkt[1]&0x040 == 0 {
|
if pkt[1]&0x040 == 0 {
|
||||||
err = errNoPesPayload
|
err = errNoPesPayload
|
||||||
return
|
return
|
||||||
|
@ -435,27 +435,22 @@ func GetPTS(pkt []byte) (pts int64, err error) {
|
||||||
// Compute start of PES payload and check its length.
|
// Compute start of PES payload and check its length.
|
||||||
start := HeadSize
|
start := HeadSize
|
||||||
if pkt[3]&0x20 != 0 {
|
if pkt[3]&0x20 != 0 {
|
||||||
// Take into account length of the adaptation field.
|
// Adaptation field is present, so adjust start of payload accordingly.
|
||||||
start += 1 + int(pkt[4])
|
start += 1 + int(pkt[4])
|
||||||
}
|
}
|
||||||
pes := pkt[start:]
|
pes := pkt[start:]
|
||||||
|
|
||||||
if len(pes) < 9 {
|
if len(pes) < 14 {
|
||||||
err = errInvalidPesHeader
|
err = errInvalidPesHeader
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that PES has a PTS.
|
// Check the PTS DTS indicator.
|
||||||
if pes[7]&0xc0 == 0 {
|
if pes[7]&0xc0 == 0 {
|
||||||
err = errNoPesPTS
|
err = errNoPesPTS
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract the PTS.
|
|
||||||
if len(pes) < 14 {
|
|
||||||
err = errInvalidPesHeader
|
|
||||||
return
|
|
||||||
}
|
|
||||||
pts = extractPTS(pes[9:14])
|
pts = extractPTS(pes[9:14])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue