From 9e5bc3806f8913bbb715fcc84d0c3040f8565c83 Mon Sep 17 00:00:00 2001 From: scruzin Date: Fri, 12 Jul 2019 14:24:30 +0930 Subject: [PATCH] Added GetPTS. --- container/mts/mpegts.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/container/mts/mpegts.go b/container/mts/mpegts.go index ee898177..484254fe 100644 --- a/container/mts/mpegts.go +++ b/container/mts/mpegts.go @@ -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 }