From ed40392bb503cea0edd7b5a93bbf147fbbeb0003 Mon Sep 17 00:00:00 2001 From: Trek H Date: Wed, 31 Mar 2021 20:31:16 +1030 Subject: [PATCH 1/4] mts: add function for converting byte slice to packet.Packet --- container/mts/mpegts.go | 10 ++++++++++ container/mts/mpegts_test.go | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/container/mts/mpegts.go b/container/mts/mpegts.go index b89a7882..a10cd804 100644 --- a/container/mts/mpegts.go +++ b/container/mts/mpegts.go @@ -31,6 +31,7 @@ package mts import ( "fmt" + "unsafe" "github.com/Comcast/gots/packet" gotspsi "github.com/Comcast/gots/psi" @@ -374,6 +375,15 @@ func asByte(b bool) byte { return 0 } +// GotsPacket takes a byte slice and returns a Packet as defined in github.com/comcast/gots/packet. +// TODO: replace this with a type conversion as described here: https://github.com/golang/go/issues/395 +func GotsPacket(b []byte) *packet.Packet { + if len(b) != packet.PacketSize { + panic("invalid packet size") + } + return *(**packet.Packet)(unsafe.Pointer(&b)) +} + type Option func(p *packet.Packet) // addAdaptationField adds an adaptation field to p, and applys the passed options to this field. diff --git a/container/mts/mpegts_test.go b/container/mts/mpegts_test.go index d9591fd2..901e4336 100644 --- a/container/mts/mpegts_test.go +++ b/container/mts/mpegts_test.go @@ -768,3 +768,12 @@ func TestFindPSI(t *testing.T) { } } } + +func TestGotsPacket(t *testing.T) { + b := make([]byte, 188) + p := GotsPacket(b) + p.SetPID(PIDAudio) + if p.PID() != PIDAudio { + t.Error("failed to set PID in gots Packet") + } +} From 5dac5f952c8715985035f483a4945cd9df12d42a Mon Sep 17 00:00:00 2001 From: Trek H Date: Wed, 31 Mar 2021 20:33:51 +1030 Subject: [PATCH 2/4] mts: small style/syntax changes --- container/mts/mpegts.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/container/mts/mpegts.go b/container/mts/mpegts.go index a10cd804..e47f720b 100644 --- a/container/mts/mpegts.go +++ b/container/mts/mpegts.go @@ -420,7 +420,7 @@ func resetAdaptation(p *packet.Packet) error { return nil } -// DiscontinuityIndicator returns and Option that will set p's discontinuity +// DiscontinuityIndicator returns an Option that will set p's discontinuity // indicator according to f. func DiscontinuityIndicator(f bool) Option { return func(p *packet.Packet) { @@ -648,13 +648,13 @@ func SegmentForMeta(d []byte, key, val string) ([][]byte, error) { // We've reached the end of the entire MTS clip so if we're segmenting we need // to append current segment to res. if segmenting { - res = append(res, d[start:len(d)]) + res = append(res, d[start:]) } return res, nil } -// pid returns the packet identifier for the given packet. +// PID returns the packet identifier for the given packet. func PID(p []byte) (uint16, error) { if len(p) < PacketSize { return 0, errors.New("packet length less than 188") From a8e65bfa7b395fef2f67d4579d72720ec7ecf582 Mon Sep 17 00:00:00 2001 From: Trek H Date: Wed, 31 Mar 2021 20:40:40 +1030 Subject: [PATCH 3/4] mts: updated authors --- container/mts/mpegts.go | 5 +++-- container/mts/mpegts_test.go | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/container/mts/mpegts.go b/container/mts/mpegts.go index e47f720b..2be1841b 100644 --- a/container/mts/mpegts.go +++ b/container/mts/mpegts.go @@ -6,11 +6,12 @@ NAME DESCRIPTION See Readme.md -AUTHOR +AUTHORS Saxon A. Nelson-Milton + Trek Hopton LICENSE - mpegts.go is Copyright (C) 2017 the Australian Ocean Lab (AusOcean) + mpegts.go is Copyright (C) 2017-2021 the Australian Ocean Lab (AusOcean) It is free software: you can redistribute it and/or modify them under the terms of the GNU General Public License as published by the diff --git a/container/mts/mpegts_test.go b/container/mts/mpegts_test.go index 901e4336..3370ff11 100644 --- a/container/mts/mpegts_test.go +++ b/container/mts/mpegts_test.go @@ -7,9 +7,10 @@ DESCRIPTION AUTHORS Saxon A. Nelson-Milton + Trek Hopton LICENSE - Copyright (C) 2019 the Australian Ocean Lab (AusOcean) + Copyright (C) 2019-2021 the Australian Ocean Lab (AusOcean) It is free software: you can redistribute it and/or modify them under the terms of the GNU General Public License as published by the From 624bf79a6ec66462c868ce386e7924617fbb3b0e Mon Sep 17 00:00:00 2001 From: Trek H Date: Wed, 31 Mar 2021 21:00:00 +1030 Subject: [PATCH 4/4] mts: expand on comment --- container/mts/mpegts.go | 1 + 1 file changed, 1 insertion(+) diff --git a/container/mts/mpegts.go b/container/mts/mpegts.go index 2be1841b..68565078 100644 --- a/container/mts/mpegts.go +++ b/container/mts/mpegts.go @@ -378,6 +378,7 @@ func asByte(b bool) byte { // GotsPacket takes a byte slice and returns a Packet as defined in github.com/comcast/gots/packet. // TODO: replace this with a type conversion as described here: https://github.com/golang/go/issues/395 +// when it becomes available in Go 1.17. func GotsPacket(b []byte) *packet.Packet { if len(b) != packet.PacketSize { panic("invalid packet size")