From 6efed19b7fd772904639a36ea2234d8604b8c234 Mon Sep 17 00:00:00 2001 From: scruzin Date: Mon, 15 Jul 2019 08:50:45 +0930 Subject: [PATCH 1/9] Use ausocean/iot v1.2.5. --- go.mod | 9 ++------- go.sum | 11 +++++++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index c3d766c5..37a7a31f 100644 --- a/go.mod +++ b/go.mod @@ -3,17 +3,12 @@ module bitbucket.org/ausocean/av go 1.12 require ( - bitbucket.org/ausocean/iot v1.2.4 + bitbucket.org/ausocean/iot v1.2.5 bitbucket.org/ausocean/utils v1.2.6 - github.com/BurntSushi/toml v0.3.1 // indirect github.com/Comcast/gots v0.0.0-20190305015453-8d56e473f0f7 - github.com/Shopify/toxiproxy v2.1.4+incompatible // indirect - github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 // indirect github.com/go-audio/audio v0.0.0-20181013203223-7b2a6ca21480 github.com/go-audio/wav v0.0.0-20181013172942-de841e69b884 github.com/mewkiz/flac v1.0.5 - github.com/sergi/go-diff v1.0.0 // indirect + github.com/pkg/errors v0.8.1 github.com/yobert/alsa v0.0.0-20180630182551-d38d89fa843e - gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect - gopkg.in/yaml.v2 v2.2.2 // indirect ) diff --git a/go.sum b/go.sum index cd09945f..5ee9f294 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,8 @@ bitbucket.org/ausocean/iot v1.2.4 h1:M/473iQ0d4q+76heerjAQuqXzQyc5dZ3F7Bfuq6X7q4= bitbucket.org/ausocean/iot v1.2.4/go.mod h1:5HVLgPHccW2PxS7WDUQO6sKWMgk3Vfze/7d5bHs8EWU= +bitbucket.org/ausocean/iot v1.2.5 h1:udD5X4oXUuKwdjO7bcq4StcDdjP8fJa2L0FnJJwF+6Q= +bitbucket.org/ausocean/iot v1.2.5/go.mod h1:dOclxXkdxAQGWO7Y5KcP1wpNfxg9oKUA2VqjJ3Le4RA= +bitbucket.org/ausocean/utils v1.2.4/go.mod h1:5JIXFTAMMNl5Ob79tpZfDCJ+gOO8rj7v4ORj56tHZpw= bitbucket.org/ausocean/utils v1.2.6 h1:JN66APCV+hu6GebIHSu2KSywhLym4vigjSz5+fB0zXc= bitbucket.org/ausocean/utils v1.2.6/go.mod h1:uXzX9z3PLemyURTMWRhVI8uLhPX4uuvaaO85v2hcob8= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= @@ -8,16 +11,21 @@ github.com/Comcast/gots v0.0.0-20190305015453-8d56e473f0f7 h1:LdOc9B9Bj6LEsKiXSh github.com/Comcast/gots v0.0.0-20190305015453-8d56e473f0f7/go.mod h1:O5HA0jgDXkBp+jw0770QNBT8fsRJCbH7JXmM7wxLUBU= github.com/Shopify/toxiproxy v2.1.4+incompatible h1:TKdv8HiTLgE5wdJuEML90aBgNWsokNbMijUGhmcoBJc= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= +github.com/adrianmo/go-nmea v1.1.1-0.20190109062325-c448653979f7/go.mod h1:HHPxPAm2kmev+61qmkZh7xgZF/7qHtSpsWppip2Ipv8= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-audio/aiff v0.0.0-20180403003018-6c3a8a6aff12/go.mod h1:AMSAp6W1zd0koOdX6QDgGIuBDTUvLa2SLQtm7d9eM3c= github.com/go-audio/audio v0.0.0-20180206231410-b697a35b5608/go.mod h1:6uAu0+H2lHkwdGsAY+j2wHPNPpPoeg5AaEFh9FlA+Zs= github.com/go-audio/audio v0.0.0-20181013203223-7b2a6ca21480 h1:4sGU+UABMMsRJyD+Y2yzMYxq0GJFUsRRESI0P1gZ2ig= github.com/go-audio/audio v0.0.0-20181013203223-7b2a6ca21480/go.mod h1:6uAu0+H2lHkwdGsAY+j2wHPNPpPoeg5AaEFh9FlA+Zs= github.com/go-audio/wav v0.0.0-20181013172942-de841e69b884 h1:2TaXIaVA4ff/MHHezOj83tCypALTFAcXOImcFWNa3jw= github.com/go-audio/wav v0.0.0-20181013172942-de841e69b884/go.mod h1:UiqzUyfX0zs3pJ/DPyvS5v8sN6s5bXPUDDIVA5v8dks= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/jacobsa/go-serial v0.0.0-20180131005756-15cf729a72d4/go.mod h1:2RvX5ZjVtsznNZPEt4xwJXNJrM3VTZoQf7V6gk0ysvs= +github.com/kidoman/embd v0.0.0-20170508013040-d3d8c0c5c68d/go.mod h1:ACKj9jnzOzj1lw2ETilpFGK7L9dtJhAzT7T1OhAGtRQ= github.com/mattetti/audio v0.0.0-20180912171649-01576cde1f21 h1:Hc1iKlyxNHp3CV59G2E/qabUkHvEwOIJxDK0CJ7CRjA= github.com/mattetti/audio v0.0.0-20180912171649-01576cde1f21/go.mod h1:LlQmBGkOuV/SKzEDXBPKauvN2UqCgzXO2XjecTGj40s= github.com/mewkiz/flac v1.0.5 h1:dHGW/2kf+/KZ2GGqSVayNEhL9pluKn/rr/h/QqD9Ogc= @@ -29,16 +37,19 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/yobert/alsa v0.0.0-20180630182551-d38d89fa843e h1:3NIzz7weXhh3NToPgbtlQtKiVgerEaG4/nY2skGoGG0= github.com/yobert/alsa v0.0.0-20180630182551-d38d89fa843e/go.mod h1:CaowXBWOiSGWEpBBV8LoVnQTVPV4ycyviC9IBLj8dRw= +github.com/yryz/ds18b20 v0.0.0-20180211073435-3cf383a40624/go.mod h1:MqFju5qeLDFh+S9PqxYT7TEla8xeW7bgGr/69q3oki0= go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/zap v1.9.1 h1:XCJQEf3W6eZaVwhRBof6ImoYGJSITeKWsyeh3HFu/5o= go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +golang.org/x/sys v0.0.0-20190305064518-30e92a19ae4a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= From bdc3b4cfc5c7e402a1c8148f2e4a27a9bbcdd264 Mon Sep 17 00:00:00 2001 From: Saxon Date: Wed, 24 Jul 2019 00:04:10 +0930 Subject: [PATCH 2/9] container/mts/mpegts.go: added Programs, Streams and MediaStreams functions --- container/mts/mpegts.go | 85 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 3 deletions(-) diff --git a/container/mts/mpegts.go b/container/mts/mpegts.go index 0b356770..f2a9ae0b 100644 --- a/container/mts/mpegts.go +++ b/container/mts/mpegts.go @@ -33,6 +33,7 @@ import ( "fmt" "github.com/Comcast/gots/packet" + gotspsi "github.com/Comcast/gots/psi" "github.com/pkg/errors" "bitbucket.org/ausocean/av/container/mts/meta" @@ -420,9 +421,9 @@ func GetPTSRange(clip []byte, pid uint16) (pts [2]uint64, err error) { } var ( - errNoPesPayload = errors.New("no PES payload") - errNoPesPTS = errors.New("no PES PTS") - errInvalidPesHeader = errors.New("invalid PES header") + errNoPesPayload = errors.New("no PES payload") + errNoPesPTS = errors.New("no PES PTS") + errInvalidPesHeader = errors.New("invalid PES header") errInvalidPesPayload = errors.New("invalid PES payload") ) @@ -592,3 +593,81 @@ func SegmentForMeta(d []byte, key, val string) ([][]byte, error) { return res, nil } + +// pid returns the packet identifier for the given packet. +func pid(p []byte) uint16 { + return uint16(p[1]&0x1f)<<8 | uint16(p[2]) +} + +// Programs returns a map of program numbers and corresponding PMT PIDs for a +// given MPEG-TS PAT packet. +func Programs(p []byte) (map[uint16]uint16, error) { + pat, err := gotspsi.NewPAT(p) + if err != nil { + return nil, err + } + return pat.ProgramMap(), nil +} + +// Streams returns elementary streams defined in a given MPEG-TS PMT packet. +// A gotspsi.PmtElementaryStream will give stream type from +// gotspsi.PmtElementaryStream.StreamType() and PID from +// gotspsi.PmtElementaryStream.ElementaryPid(). +// +// PmtStreamTypes from gots/psi are defined as follows: +// PmtStreamTypeMpeg2VideoH262 uint8 = 2 // H262 +// PmtStreamTypeMpeg4Video uint8 = 27 // H264 +// PmtStreamTypeMpeg4VideoH264 uint8 = 27 // H264 +// PmtStreamTypeMpeg4VideoH265 uint8 = 36 // H265 +// PmtStreamTypeAac uint8 = 15 // AAC +// PmtStreamTypeAc3 uint8 = 129 // DD +// PmtStreamTypeEc3 uint8 = 135 // DD+ +// PmtStreamTypeScte35 uint8 = 134 // SCTE-35 +func Streams(p []byte) ([]gotspsi.PmtElementaryStream, error) { + pmt, err := gotspsi.NewPMT(p) + if err != nil { + return nil, err + } + return pmt.ElementaryStreams(), nil +} + +// MediaStreams retrieves the PmtElementaryStreams from the given PSI. This +// function currently assumes that PSI contain a PAT followed by a PMT directly +// after. We also assume that this MPEG-TS stream contains just one program, +// but this program may contain different streams, i.e. a video stream + audio +// stream. +func MediaStreams(p []byte) ([]gotspsi.PmtElementaryStream, error) { + pat := p[:PacketSize] + pmt := p[PacketSize : 2*PacketSize] + + if pid(pat) != PatPid { + return nil, errors.New("first packet is not a PAT") + } + + m, err := Programs(pat) + if err != nil { + return nil, errors.Wrap(err, "could not get programs from PAT") + } + + if len(m) == 0 { + return nil, errors.New("no programs contained in PAT") + } + + if len(m) > 1 { + return nil, errors.New("more than one program not yet supported") + } + + var v uint16 + for _, v = range m { + } + + if pid(pmt) != v { + return nil, errors.New("second packet is not desired PMT") + } + + s, err := Streams(pmt) + if err != nil { + return nil, errors.Wrap(err, "could not get streams from PMT") + } + return s, nil +} From 3c1965d93826b8ba77c4715cbd96ed6dc5e86877 Mon Sep 17 00:00:00 2001 From: scruzin Date: Fri, 26 Jul 2019 18:55:56 +0930 Subject: [PATCH 3/9] Propagate netsender client error. --- cmd/revid-cli/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index 46f39905..cf2ee174 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -262,7 +262,7 @@ func run(cfg revid.Config) { ns, err := netsender.New(log, nil, readPin, nil) if err != nil { - log.Log(logger.Fatal, pkg+"could not initialise netsender client") + log.Log(logger.Fatal, pkg+"could not initialise netsender client: "+err.Error()) } var vs int From 23c53d78f5900f0f8d44148dc7bb6d546f2b0d3e Mon Sep 17 00:00:00 2001 From: scruzin Date: Mon, 15 Jul 2019 08:50:45 +0930 Subject: [PATCH 4/9] Use ausocean/iot v1.2.5. --- go.mod | 9 ++------- go.sum | 11 +++++++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index c3d766c5..37a7a31f 100644 --- a/go.mod +++ b/go.mod @@ -3,17 +3,12 @@ module bitbucket.org/ausocean/av go 1.12 require ( - bitbucket.org/ausocean/iot v1.2.4 + bitbucket.org/ausocean/iot v1.2.5 bitbucket.org/ausocean/utils v1.2.6 - github.com/BurntSushi/toml v0.3.1 // indirect github.com/Comcast/gots v0.0.0-20190305015453-8d56e473f0f7 - github.com/Shopify/toxiproxy v2.1.4+incompatible // indirect - github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 // indirect github.com/go-audio/audio v0.0.0-20181013203223-7b2a6ca21480 github.com/go-audio/wav v0.0.0-20181013172942-de841e69b884 github.com/mewkiz/flac v1.0.5 - github.com/sergi/go-diff v1.0.0 // indirect + github.com/pkg/errors v0.8.1 github.com/yobert/alsa v0.0.0-20180630182551-d38d89fa843e - gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect - gopkg.in/yaml.v2 v2.2.2 // indirect ) diff --git a/go.sum b/go.sum index cd09945f..5ee9f294 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,8 @@ bitbucket.org/ausocean/iot v1.2.4 h1:M/473iQ0d4q+76heerjAQuqXzQyc5dZ3F7Bfuq6X7q4= bitbucket.org/ausocean/iot v1.2.4/go.mod h1:5HVLgPHccW2PxS7WDUQO6sKWMgk3Vfze/7d5bHs8EWU= +bitbucket.org/ausocean/iot v1.2.5 h1:udD5X4oXUuKwdjO7bcq4StcDdjP8fJa2L0FnJJwF+6Q= +bitbucket.org/ausocean/iot v1.2.5/go.mod h1:dOclxXkdxAQGWO7Y5KcP1wpNfxg9oKUA2VqjJ3Le4RA= +bitbucket.org/ausocean/utils v1.2.4/go.mod h1:5JIXFTAMMNl5Ob79tpZfDCJ+gOO8rj7v4ORj56tHZpw= bitbucket.org/ausocean/utils v1.2.6 h1:JN66APCV+hu6GebIHSu2KSywhLym4vigjSz5+fB0zXc= bitbucket.org/ausocean/utils v1.2.6/go.mod h1:uXzX9z3PLemyURTMWRhVI8uLhPX4uuvaaO85v2hcob8= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= @@ -8,16 +11,21 @@ github.com/Comcast/gots v0.0.0-20190305015453-8d56e473f0f7 h1:LdOc9B9Bj6LEsKiXSh github.com/Comcast/gots v0.0.0-20190305015453-8d56e473f0f7/go.mod h1:O5HA0jgDXkBp+jw0770QNBT8fsRJCbH7JXmM7wxLUBU= github.com/Shopify/toxiproxy v2.1.4+incompatible h1:TKdv8HiTLgE5wdJuEML90aBgNWsokNbMijUGhmcoBJc= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= +github.com/adrianmo/go-nmea v1.1.1-0.20190109062325-c448653979f7/go.mod h1:HHPxPAm2kmev+61qmkZh7xgZF/7qHtSpsWppip2Ipv8= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-audio/aiff v0.0.0-20180403003018-6c3a8a6aff12/go.mod h1:AMSAp6W1zd0koOdX6QDgGIuBDTUvLa2SLQtm7d9eM3c= github.com/go-audio/audio v0.0.0-20180206231410-b697a35b5608/go.mod h1:6uAu0+H2lHkwdGsAY+j2wHPNPpPoeg5AaEFh9FlA+Zs= github.com/go-audio/audio v0.0.0-20181013203223-7b2a6ca21480 h1:4sGU+UABMMsRJyD+Y2yzMYxq0GJFUsRRESI0P1gZ2ig= github.com/go-audio/audio v0.0.0-20181013203223-7b2a6ca21480/go.mod h1:6uAu0+H2lHkwdGsAY+j2wHPNPpPoeg5AaEFh9FlA+Zs= github.com/go-audio/wav v0.0.0-20181013172942-de841e69b884 h1:2TaXIaVA4ff/MHHezOj83tCypALTFAcXOImcFWNa3jw= github.com/go-audio/wav v0.0.0-20181013172942-de841e69b884/go.mod h1:UiqzUyfX0zs3pJ/DPyvS5v8sN6s5bXPUDDIVA5v8dks= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/jacobsa/go-serial v0.0.0-20180131005756-15cf729a72d4/go.mod h1:2RvX5ZjVtsznNZPEt4xwJXNJrM3VTZoQf7V6gk0ysvs= +github.com/kidoman/embd v0.0.0-20170508013040-d3d8c0c5c68d/go.mod h1:ACKj9jnzOzj1lw2ETilpFGK7L9dtJhAzT7T1OhAGtRQ= github.com/mattetti/audio v0.0.0-20180912171649-01576cde1f21 h1:Hc1iKlyxNHp3CV59G2E/qabUkHvEwOIJxDK0CJ7CRjA= github.com/mattetti/audio v0.0.0-20180912171649-01576cde1f21/go.mod h1:LlQmBGkOuV/SKzEDXBPKauvN2UqCgzXO2XjecTGj40s= github.com/mewkiz/flac v1.0.5 h1:dHGW/2kf+/KZ2GGqSVayNEhL9pluKn/rr/h/QqD9Ogc= @@ -29,16 +37,19 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/yobert/alsa v0.0.0-20180630182551-d38d89fa843e h1:3NIzz7weXhh3NToPgbtlQtKiVgerEaG4/nY2skGoGG0= github.com/yobert/alsa v0.0.0-20180630182551-d38d89fa843e/go.mod h1:CaowXBWOiSGWEpBBV8LoVnQTVPV4ycyviC9IBLj8dRw= +github.com/yryz/ds18b20 v0.0.0-20180211073435-3cf383a40624/go.mod h1:MqFju5qeLDFh+S9PqxYT7TEla8xeW7bgGr/69q3oki0= go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/zap v1.9.1 h1:XCJQEf3W6eZaVwhRBof6ImoYGJSITeKWsyeh3HFu/5o= go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +golang.org/x/sys v0.0.0-20190305064518-30e92a19ae4a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= From 46c709404f7213499eb1672d55bc900f94d28e14 Mon Sep 17 00:00:00 2001 From: scruzin Date: Fri, 26 Jul 2019 18:55:56 +0930 Subject: [PATCH 5/9] Propagate netsender client error. --- cmd/revid-cli/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index 46f39905..cf2ee174 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -262,7 +262,7 @@ func run(cfg revid.Config) { ns, err := netsender.New(log, nil, readPin, nil) if err != nil { - log.Log(logger.Fatal, pkg+"could not initialise netsender client") + log.Log(logger.Fatal, pkg+"could not initialise netsender client: "+err.Error()) } var vs int From 404e6493b609d533e3583c8b300563b65554074f Mon Sep 17 00:00:00 2001 From: Saxon Date: Sat, 27 Jul 2019 13:35:05 +0930 Subject: [PATCH 6/9] codec/h264/h26dec/read.go: added fieldReader type to provide sticky error and specific methods for bool and int reading --- codec/h264/h264dec/read.go | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/codec/h264/h264dec/read.go b/codec/h264/h264dec/read.go index 92a12ed9..f0a65500 100644 --- a/codec/h264/h264dec/read.go +++ b/codec/h264/h264dec/read.go @@ -228,3 +228,43 @@ func readFlags(br *bits.BitReader, flags []flag) error { } return nil } + +// fieldReader provides methods for reading bool and int fields from a +// bits.BitReader with a sticky error that may be checked after a series of +// parsing read calls. +type fieldReader struct { + e error + br *bits.BitReader +} + +// newFieldReader returns a new fieldReader. +func newFieldReader(br *bits.BitReader) fieldReader { + return fieldReader{br: br} +} + +// readBool returns a bool from reading one bit from br. If we have an error +// already, we do not continue with the read. +func (r fieldReader) readBool() bool { + if r.e != nil { + return false + } + var b uint64 + b, r.e = r.br.ReadBits(1) + return b == 1 +} + +// readBitsInt returns an int from reading n bits from br. If we have an error +// already, we do not continue with the read. +func (r fieldReader) readBitsInt(n int) int { + if r.e != nil { + return 0 + } + var b uint64 + b, r.e = r.br.ReadBits(n) + return int(b) +} + +// err returns the fieldReader's error e. +func (r fieldReader) err() error { + return r.e +} From 9f47b22a84b82dc09579852238d45a14f5815b81 Mon Sep 17 00:00:00 2001 From: Saxon Date: Sat, 27 Jul 2019 13:59:12 +0930 Subject: [PATCH 7/9] codec/h264/h264dec: moved fieldReader to parse.go and wrote methods for reading other descriptor types like ue and te. --- codec/h264/h264dec/parse.go | 92 +++++++++++++++++++++++++++++++++++++ codec/h264/h264dec/read.go | 40 ---------------- 2 files changed, 92 insertions(+), 40 deletions(-) diff --git a/codec/h264/h264dec/parse.go b/codec/h264/h264dec/parse.go index 86baaece..e6fba287 100644 --- a/codec/h264/h264dec/parse.go +++ b/codec/h264/h264dec/parse.go @@ -36,6 +36,98 @@ const ( naMbPartPredMode ) +// fieldReader provides methods for reading bool and int fields from a +// bits.BitReader with a sticky error that may be checked after a series of +// parsing read calls. +type fieldReader struct { + e error + br *bits.BitReader +} + +// newFieldReader returns a new fieldReader. +func newFieldReader(br *bits.BitReader) fieldReader { + return fieldReader{br: br} +} + +// readBool returns a bool from reading one bit from br. If we have an error +// already, we do not continue with the read. +func (r fieldReader) readBool() bool { + if r.e != nil { + return false + } + var b uint64 + b, r.e = r.br.ReadBits(1) + return b == 1 +} + +// readBitsInt returns an int from reading n bits from br. If we have an error +// already, we do not continue with the read. +func (r fieldReader) readBitsInt(n int) int { + if r.e != nil { + return 0 + } + var b uint64 + b, r.e = r.br.ReadBits(n) + return int(b) +} + +// readUe parses a syntax element of ue(v) descriptor, i.e. an unsigned integer +// Exp-Golomb-coded element using method as specified in section 9.1 of ITU-T +// H.264 and return as an int. The read does not happen if the fieldReader +// has a non-nil error. +func (r fieldReader) readUe() int { + if r.e != nil { + return 0 + } + var i int + i, r.e = readUe(r.br) + return i +} + +// readTe parses a syntax element of te(v) descriptor i.e, truncated +// Exp-Golomb-coded syntax element using method as specified in section 9.1 +// and returns as an int. The read does not happen if the fieldReader +// has a non-nil error. +func (r fieldReader) readTe(x uint) int { + if r.e != nil { + return 0 + } + var i int + i, r.e = readTe(r.br, x) + return i +} + +// readSe parses a syntax element with descriptor se(v), i.e. a signed integer +// Exp-Golomb-coded syntax element, using the method described in sections +// 9.1 and 9.1.1 and returns as int. The read does not happen if the fieldReader +// has a non-nil error. +func (r fieldReader) readSe() int { + if r.e != nil { + return 0 + } + var i int + i, r.e = readSe(r.br) + return i +} + +// readMe parses a syntax element of me(v) descriptor, i.e. mapped +// Exp-Golomb-coded element, using methods described in sections 9.1 and 9.1.2 +// and returns as int. The read does not happen if the fieldReader has a +// non-nil error. +func (r fieldReader) readMe(chromaArrayType uint, mpm mbPartPredMode) int { + if r.e != nil { + return 0 + } + var i uint + i, r.e = readMe(r.br, chromaArrayType, mpm) + return int(i) +} + +// err returns the fieldReader's error e. +func (r fieldReader) err() error { + return r.e +} + // readUe parses a syntax element of ue(v) descriptor, i.e. an unsigned integer // Exp-Golomb-coded element using method as specified in section 9.1 of ITU-T H.264. // diff --git a/codec/h264/h264dec/read.go b/codec/h264/h264dec/read.go index f0a65500..92a12ed9 100644 --- a/codec/h264/h264dec/read.go +++ b/codec/h264/h264dec/read.go @@ -228,43 +228,3 @@ func readFlags(br *bits.BitReader, flags []flag) error { } return nil } - -// fieldReader provides methods for reading bool and int fields from a -// bits.BitReader with a sticky error that may be checked after a series of -// parsing read calls. -type fieldReader struct { - e error - br *bits.BitReader -} - -// newFieldReader returns a new fieldReader. -func newFieldReader(br *bits.BitReader) fieldReader { - return fieldReader{br: br} -} - -// readBool returns a bool from reading one bit from br. If we have an error -// already, we do not continue with the read. -func (r fieldReader) readBool() bool { - if r.e != nil { - return false - } - var b uint64 - b, r.e = r.br.ReadBits(1) - return b == 1 -} - -// readBitsInt returns an int from reading n bits from br. If we have an error -// already, we do not continue with the read. -func (r fieldReader) readBitsInt(n int) int { - if r.e != nil { - return 0 - } - var b uint64 - b, r.e = r.br.ReadBits(n) - return int(b) -} - -// err returns the fieldReader's error e. -func (r fieldReader) err() error { - return r.e -} From 75a6df5da5a15426c7a9c3d9e0ae3b477e920560 Mon Sep 17 00:00:00 2001 From: Saxon Date: Mon, 29 Jul 2019 12:33:14 +0930 Subject: [PATCH 8/9] codec/h264/h264dec: removed readBitsInt and readBool --- codec/h264/h264dec/parse.go | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/codec/h264/h264dec/parse.go b/codec/h264/h264dec/parse.go index e6fba287..68abe8c6 100644 --- a/codec/h264/h264dec/parse.go +++ b/codec/h264/h264dec/parse.go @@ -49,20 +49,9 @@ func newFieldReader(br *bits.BitReader) fieldReader { return fieldReader{br: br} } -// readBool returns a bool from reading one bit from br. If we have an error -// already, we do not continue with the read. -func (r fieldReader) readBool() bool { - if r.e != nil { - return false - } - var b uint64 - b, r.e = r.br.ReadBits(1) - return b == 1 -} - // readBitsInt returns an int from reading n bits from br. If we have an error // already, we do not continue with the read. -func (r fieldReader) readBitsInt(n int) int { +func (r fieldReader) readBits(n int) int { if r.e != nil { return 0 } From 430e56e22bd477be5954223d1092a48bf721e870 Mon Sep 17 00:00:00 2001 From: Saxon Date: Mon, 29 Jul 2019 12:35:01 +0930 Subject: [PATCH 9/9] codec/h264/h264dec: fixed readBits return type --- codec/h264/h264dec/parse.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codec/h264/h264dec/parse.go b/codec/h264/h264dec/parse.go index 68abe8c6..0763be27 100644 --- a/codec/h264/h264dec/parse.go +++ b/codec/h264/h264dec/parse.go @@ -51,13 +51,13 @@ func newFieldReader(br *bits.BitReader) fieldReader { // readBitsInt returns an int from reading n bits from br. If we have an error // already, we do not continue with the read. -func (r fieldReader) readBits(n int) int { +func (r fieldReader) readBits(n int) uint64 { if r.e != nil { return 0 } var b uint64 b, r.e = r.br.ReadBits(n) - return int(b) + return b } // readUe parses a syntax element of ue(v) descriptor, i.e. an unsigned integer