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 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) {
|
||||
// Bail if packet does not contain a PES.
|
||||
// Check the Payload Unit Start Indicator.
|
||||
if pkt[1]&0x040 == 0 {
|
||||
err = errNoPesPayload
|
||||
return
|
||||
|
@ -435,27 +435,22 @@ func GetPTS(pkt []byte) (pts int64, err error) {
|
|||
// Compute start of PES payload and check its length.
|
||||
start := HeadSize
|
||||
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])
|
||||
}
|
||||
pes := pkt[start:]
|
||||
|
||||
if len(pes) < 9 {
|
||||
if len(pes) < 14 {
|
||||
err = errInvalidPesHeader
|
||||
return
|
||||
}
|
||||
|
||||
// Check that PES has a PTS.
|
||||
// Check the PTS DTS indicator.
|
||||
if pes[7]&0xc0 == 0 {
|
||||
err = errNoPesPTS
|
||||
return
|
||||
}
|
||||
|
||||
// Extract the PTS.
|
||||
if len(pes) < 14 {
|
||||
err = errInvalidPesHeader
|
||||
return
|
||||
}
|
||||
pts = extractPTS(pes[9:14])
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue