container/mts/mpegts.go: GetPTSRange now generalised for any PID

This commit is contained in:
Saxon 2019-05-11 13:04:30 +09:30
parent e2d9853264
commit ebb69ea6aa
2 changed files with 5 additions and 5 deletions

View File

@ -318,9 +318,9 @@ func DiscontinuityIndicator(f bool) Option {
} }
// GetPTSRange retreives the first and last PTS of an MPEGTS clip. // GetPTSRange retreives the first and last PTS of an MPEGTS clip.
func GetPTSRange(clip []byte) (pts [2]uint64, err error) { func GetPTSRange(clip []byte, pidType int) (pts [2]uint64, err error) {
// Find the first video packet. // Find the first packet with PID pidType.
pkt, _, err := FindPid(clip, videoPid) pkt, _, err := FindPid(clip, uint16(pidType))
if err != nil { if err != nil {
return [2]uint64{}, err return [2]uint64{}, err
} }
@ -344,7 +344,7 @@ func GetPTSRange(clip []byte) (pts [2]uint64, err error) {
// Get the final PTS searching from end of clip for access unit start. // Get the final PTS searching from end of clip for access unit start.
for i := len(clip) - PacketSize; i >= 0; i -= PacketSize { for i := len(clip) - PacketSize; i >= 0; i -= PacketSize {
copy(_pkt[:], clip[i:i+PacketSize]) copy(_pkt[:], clip[i:i+PacketSize])
if packet.PayloadUnitStartIndicator(&_pkt) { if packet.PayloadUnitStartIndicator(&_pkt) && _pkt.PID() == pidType {
payload, err = packet.Payload(&_pkt) payload, err = packet.Payload(&_pkt)
if err != nil { if err != nil {
return [2]uint64{}, err return [2]uint64{}, err

View File

@ -51,7 +51,7 @@ func TestGetPTSRange(t *testing.T) {
curTime += interval curTime += interval
} }
got, err := GetPTSRange(clip.Bytes()) got, err := GetPTSRange(clip.Bytes(), videoPid)
if err != nil { if err != nil {
t.Fatalf("did not expect error getting PTS range: %v", err) t.Fatalf("did not expect error getting PTS range: %v", err)
} }