diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml index 6f489f5..a5ed9c0 100644 --- a/.github/workflows/pull-request.yaml +++ b/.github/workflows/pull-request.yaml @@ -6,7 +6,7 @@ jobs: test: strategy: matrix: - go-version: [1.14.x, 1.15.x, 1.16.x] + go-version: [1.14.x, 1.15.x, 1.16.x, 1.17.x, 1.18.x, 1.19.x] os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: diff --git a/go.mod b/go.mod index 2dcaf36..5946c96 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/Comcast/gots -go 1.16 +go 1.18 diff --git a/v2/ebp/cablelabsebp.go b/v2/ebp/cablelabsebp.go index a2a043e..b3ca48c 100644 --- a/v2/ebp/cablelabsebp.go +++ b/v2/ebp/cablelabsebp.go @@ -29,7 +29,7 @@ import ( "encoding/binary" "time" - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" ) // cableLabsEbp is an encoder boundary point diff --git a/v2/ebp/comcastebp.go b/v2/ebp/comcastebp.go index ae67364..f063375 100644 --- a/v2/ebp/comcastebp.go +++ b/v2/ebp/comcastebp.go @@ -29,7 +29,7 @@ import ( "encoding/binary" "time" - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" ) // cableLabsEbp is an encoder boundary point diff --git a/v2/ebp/ebp.go b/v2/ebp/ebp.go index 39dc897..22dd27e 100644 --- a/v2/ebp/ebp.go +++ b/v2/ebp/ebp.go @@ -28,7 +28,7 @@ import ( "encoding/binary" "time" - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" ) // EBP tags diff --git a/v2/ebp/ebp_test.go b/v2/ebp/ebp_test.go index 79735d9..bb44a1a 100644 --- a/v2/ebp/ebp_test.go +++ b/v2/ebp/ebp_test.go @@ -27,7 +27,7 @@ import ( "testing" "time" - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" ) var CableLabsEBPBytes = []byte{ diff --git a/v2/go.mod b/v2/go.mod index 0e7613b..1b733fe 100644 --- a/v2/go.mod +++ b/v2/go.mod @@ -1,14 +1,3 @@ module github.com/Comcast/gots/v2 -go 1.16 - -require ( - github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect - github.com/ksubedi/gomove v0.0.0-20200106182546-e1fa47256217 // indirect - github.com/mattn/go-colorable v0.1.10 // indirect - github.com/mattn/go-isatty v0.0.14 // indirect - github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect - github.com/urfave/cli v1.22.5 // indirect - golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 // indirect - golang.org/x/tools v0.1.6 // indirect -) +go 1.18 diff --git a/v2/go.sum b/v2/go.sum index 67de742..e69de29 100644 --- a/v2/go.sum +++ b/v2/go.sum @@ -1,58 +0,0 @@ -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU= -github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/ksubedi/gomove v0.0.0-20200106182546-e1fa47256217 h1:CYk3GRunz2nSWbGNXpDxlr5uU/YTkBf1p9zorauMvvc= -github.com/ksubedi/gomove v0.0.0-20200106182546-e1fa47256217/go.mod h1:yq7Mn2Ip7t9irYr+JskEuBYdF3tKnikTKG49Qn5aDuY= -github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-colorable v0.1.10 h1:KWqbp83oZ6YOEgIbNW3BM1Jbe2tz4jgmWA9FOuAF8bw= -github.com/mattn/go-colorable v0.1.10/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= -github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= -github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI= -github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= -github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= -github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= -github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= -github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU= -github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= -github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 h1:foEbQz/B0Oz6YIqu/69kfXPYeFQAuuMYFkjaqXzl5Wo= -golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191204214957-d79e56da46fe/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.6 h1:SIasE1FVIQOWz2GEAHFOmoW7xchJcqlucjSULTL0Ag4= -golang.org/x/tools v0.1.6/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/v2/packet/accumulator.go b/v2/packet/accumulator.go index 26e2698..27a324e 100644 --- a/v2/packet/accumulator.go +++ b/v2/packet/accumulator.go @@ -27,7 +27,7 @@ package packet import ( "bytes" - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" ) // Iotas to track the state of the accumulator @@ -61,9 +61,10 @@ type accumulator struct { // the provided function returns done as true. func NewAccumulator(f func(data []byte) (done bool, err error)) Accumulator { return &accumulator{ - f: f, - buf: &bytes.Buffer{}, - state: stateStarting} + f: f, + buf: &bytes.Buffer{}, + packets: []*Packet{}, + state: stateStarting} } // Add a packet to the accumulator. If the added packet completes @@ -77,7 +78,8 @@ func (a *accumulator) WritePacket(pkt *Packet) (int, error) { return PacketSize, gots.ErrNoPayloadUnitStartIndicator } - a.packets = []*Packet{} + a.buf.Reset() + a.packets = a.packets[:0] a.state = stateAccumulating case stateAccumulating: @@ -114,17 +116,24 @@ func (a *accumulator) WritePacket(pkt *Packet) (int, error) { // Bytes returns the payload bytes from the underlying buffer func (a *accumulator) Bytes() []byte { - return a.buf.Bytes() + b := make([]byte, a.buf.Len()) + copy(b, a.buf.Bytes()) + + return b } // Packets returns the packets used to fill the payload buffer // NOTE: Not thread safe func (a *accumulator) Packets() []*Packet { - return a.packets + b := make([]*Packet, len(a.packets)) + copy(b, a.packets) + + return b } // Reset resets the accumulator state func (a *accumulator) Reset() { a.state = stateStarting a.buf.Reset() + a.packets = a.packets[:0] } diff --git a/v2/packet/accumulator_test.go b/v2/packet/accumulator_test.go index 7ff73b9..6b9c816 100644 --- a/v2/packet/accumulator_test.go +++ b/v2/packet/accumulator_test.go @@ -28,7 +28,7 @@ import ( "encoding/hex" "testing" - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" ) // PacketAccumulator is not thread safe diff --git a/v2/packet/adaptationfield.go b/v2/packet/adaptationfield.go index f0f921b..18f8c07 100644 --- a/v2/packet/adaptationfield.go +++ b/v2/packet/adaptationfield.go @@ -25,7 +25,7 @@ SOFTWARE. package packet import ( - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" ) const ( diff --git a/v2/packet/adaptationfield/adaptationfield.go b/v2/packet/adaptationfield/adaptationfield.go index 3174027..bb4b31d 100644 --- a/v2/packet/adaptationfield/adaptationfield.go +++ b/v2/packet/adaptationfield/adaptationfield.go @@ -1,7 +1,7 @@ package adaptationfield import ( - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" "github.com/Comcast/gots/v2/packet" ) diff --git a/v2/packet/create.go b/v2/packet/create.go index 815b7a9..6ce6478 100644 --- a/v2/packet/create.go +++ b/v2/packet/create.go @@ -25,7 +25,7 @@ SOFTWARE. package packet import ( - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" ) var ( diff --git a/v2/packet/io.go b/v2/packet/io.go index cb6d8a0..f1b964e 100644 --- a/v2/packet/io.go +++ b/v2/packet/io.go @@ -28,7 +28,7 @@ import ( "encoding/binary" "io" - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" ) // Peeker wraps the Peek method. diff --git a/v2/packet/modify.go b/v2/packet/modify.go index 60bea2f..49ebb35 100644 --- a/v2/packet/modify.go +++ b/v2/packet/modify.go @@ -25,7 +25,7 @@ SOFTWARE. package packet import ( - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" ) // flags that are reserved and should not be used. diff --git a/v2/packet/packet.go b/v2/packet/packet.go index 92d6610..9cc012f 100644 --- a/v2/packet/packet.go +++ b/v2/packet/packet.go @@ -25,7 +25,7 @@ SOFTWARE. package packet import ( - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" ) const ( diff --git a/v2/packet/packetwriter.go b/v2/packet/packetwriter.go index b9c2ada..bc6e100 100644 --- a/v2/packet/packetwriter.go +++ b/v2/packet/packetwriter.go @@ -27,7 +27,7 @@ package packet import ( "io" - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" ) // PacketWriter is subject to all rules governing implementations of io.Writer diff --git a/v2/pes/pesheader.go b/v2/pes/pesheader.go index d3c39a7..c7f561c 100644 --- a/v2/pes/pesheader.go +++ b/v2/pes/pesheader.go @@ -28,7 +28,7 @@ import ( "errors" "fmt" - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" ) // stream_id possibilities @@ -170,7 +170,7 @@ func NewPESHeader(pesBytes []byte) (PESHeader, error) { pes := new(pESHeader) var err error - if CheckLength(pesBytes, "PES", 6) { + if CheckLength(pesBytes, "PES", 7) { pes.packetStartCodePrefix = uint32(pesBytes[0])<<16 | uint32(pesBytes[1])<<8 | uint32(pesBytes[2]) diff --git a/v2/psi/pat.go b/v2/psi/pat.go index 734ab1a..2a3e14b 100644 --- a/v2/psi/pat.go +++ b/v2/psi/pat.go @@ -28,7 +28,7 @@ import ( "errors" "io" - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" "github.com/Comcast/gots/v2/packet" ) diff --git a/v2/psi/pmt.go b/v2/psi/pmt.go index 514d49d..7f3847c 100644 --- a/v2/psi/pmt.go +++ b/v2/psi/pmt.go @@ -30,7 +30,7 @@ import ( "fmt" "io" - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" "github.com/Comcast/gots/v2/packet" ) diff --git a/v2/psi/pmt_test.go b/v2/psi/pmt_test.go index 0fb2837..4f5061f 100644 --- a/v2/psi/pmt_test.go +++ b/v2/psi/pmt_test.go @@ -30,7 +30,7 @@ import ( "fmt" "testing" - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" "github.com/Comcast/gots/v2/packet" ) diff --git a/v2/psi/psi.go b/v2/psi/psi.go index be7ae5d..1fb23fb 100644 --- a/v2/psi/psi.go +++ b/v2/psi/psi.go @@ -25,7 +25,7 @@ SOFTWARE. package psi import ( - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" ) // TableHeader struct represents operations available on all PSI diff --git a/v2/scte35/descriptormodify.go b/v2/scte35/descriptormodify.go index daaca18..7dc0233 100644 --- a/v2/scte35/descriptormodify.go +++ b/v2/scte35/descriptormodify.go @@ -25,7 +25,7 @@ SOFTWARE. package scte35 import ( - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" ) // SetUPIDType will set the type of the UPID diff --git a/v2/scte35/doc.go b/v2/scte35/doc.go index f41de45..830cb50 100644 --- a/v2/scte35/doc.go +++ b/v2/scte35/doc.go @@ -26,7 +26,7 @@ SOFTWARE. package scte35 import ( - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" "github.com/Comcast/gots/v2/psi" ) @@ -79,65 +79,85 @@ var DeviceRestrictionsNames = map[DeviceRestrictions]string{ type SegDescType uint8 const ( - SegDescNotIndicated SegDescType = 0x00 - SegDescContentIdentification = 0x01 - SegDescProgramStart = 0x10 - SegDescProgramEnd = 0x11 - SegDescProgramEarlyTermination = 0x12 - SegDescProgramBreakaway = 0x13 - SegDescProgramResumption = 0x14 - SegDescProgramRunoverPlanned = 0x15 - SegDescProgramRunoverUnplanned = 0x16 - SegDescProgramOverlapStart = 0x17 - SegDescProgramBlackoutOverride = 0x18 - SegDescProgramStartInProgress = 0x19 - SegDescChapterStart = 0x20 - SegDescChapterEnd = 0x21 - SegDescBreakStart = 0x22 - SegDescBreakEnd = 0x23 - SegDescProviderAdvertisementStart = 0x30 - SegDescProviderAdvertisementEnd = 0x31 - SegDescDistributorAdvertisementStart = 0x32 - SegDescDistributorAdvertisementEnd = 0x33 - SegDescProviderPOStart = 0x34 - SegDescProviderPOEnd = 0x35 - SegDescDistributorPOStart = 0x36 - SegDescDistributorPOEnd = 0x37 - SegDescUnscheduledEventStart = 0x40 - SegDescUnscheduledEventEnd = 0x41 - SegDescNetworkStart = 0x50 - SegDescNetworkEnd = 0x51 + SegDescNotIndicated SegDescType = 0x00 + SegDescContentIdentification = 0x01 + SegDescProgramStart = 0x10 + SegDescProgramEnd = 0x11 + SegDescProgramEarlyTermination = 0x12 + SegDescProgramBreakaway = 0x13 + SegDescProgramResumption = 0x14 + SegDescProgramRunoverPlanned = 0x15 + SegDescProgramRunoverUnplanned = 0x16 + SegDescProgramOverlapStart = 0x17 + SegDescProgramBlackoutOverride = 0x18 + SegDescProgramStartInProgress = 0x19 + SegDescChapterStart = 0x20 + SegDescChapterEnd = 0x21 + SegDescBreakStart = 0x22 + SegDescBreakEnd = 0x23 + SegDescOpeningCreditStart = 0x24 + SegDescOpeningCreditEnd = 0x25 + SegDescClosingCreditStart = 0x26 + SegDescClosingCreditEnd = 0x27 + SegDescProviderAdvertisementStart = 0x30 + SegDescProviderAdvertisementEnd = 0x31 + SegDescDistributorAdvertisementStart = 0x32 + SegDescDistributorAdvertisementEnd = 0x33 + SegDescProviderPOStart = 0x34 + SegDescProviderPOEnd = 0x35 + SegDescDistributorPOStart = 0x36 + SegDescDistributorPOEnd = 0x37 + SegDescProviderPromoStart = 0x3C + SegDescProviderPromoEnd = 0x3D + SegDescUnscheduledEventStart = 0x40 + SegDescUnscheduledEventEnd = 0x41 + SegDescAlternateContentOpportunityStart = 0x42 + SegDescAlternateContentOpportunityEnd = 0x43 + SegDescProviderAdBlockStart = 0x44 + SegDescProviderAdBlockEnd = 0x45 + SegDescNetworkStart = 0x50 + SegDescNetworkEnd = 0x51 ) var SegDescTypeNames = map[SegDescType]string{ - SegDescNotIndicated: "SegDescNotIndicated", - SegDescContentIdentification: "SegDescContentIdentification", - SegDescProgramStart: "SegDescProgramStart", - SegDescProgramEnd: "SegDescProgramEnd", - SegDescProgramEarlyTermination: "SegDescProgramEarlyTermination", - SegDescProgramBreakaway: "SegDescProgramBreakaway", - SegDescProgramResumption: "SegDescProgramResumption", - SegDescProgramRunoverPlanned: "SegDescProgramRunoverPlanned", - SegDescProgramRunoverUnplanned: "SegDescProgramRunoverUnplanned", - SegDescProgramOverlapStart: "SegDescProgramOverlapStart", - SegDescProgramBlackoutOverride: "SegDescProgramBlackoutOverride", - SegDescProgramStartInProgress: "SegDescProgramStartInProgress", - SegDescChapterStart: "SegDescChapterStart", - SegDescChapterEnd: "SegDescChapterEnd", - SegDescBreakStart: "SegDescBreakStart", - SegDescBreakEnd: "SegDescBreakEnd", - SegDescProviderAdvertisementStart: "SegDescProviderAdvertisementStar", - SegDescProviderAdvertisementEnd: "SegDescProviderAdvertisementEn", - SegDescDistributorAdvertisementStart: "SegDescDistributorAdvertisementStar", - SegDescDistributorAdvertisementEnd: "SegDescDistributorAdvertisementEn", - SegDescProviderPOStart: "SegDescProviderPOStart", - SegDescProviderPOEnd: "SegDescProviderPOEnd", - SegDescDistributorPOStart: "SegDescDistributorPOStart", - SegDescDistributorPOEnd: "SegDescDistributorPOEnd", - SegDescUnscheduledEventStart: "SegDescUnscheduledEventStart", - SegDescUnscheduledEventEnd: "SegDescUnscheduledEventEnd", - SegDescNetworkStart: "SegDescNetworkStart", - SegDescNetworkEnd: "SegDescNetworkEnd", + SegDescNotIndicated: "SegDescNotIndicated", + SegDescContentIdentification: "SegDescContentIdentification", + SegDescProgramStart: "SegDescProgramStart", + SegDescProgramEnd: "SegDescProgramEnd", + SegDescProgramEarlyTermination: "SegDescProgramEarlyTermination", + SegDescProgramBreakaway: "SegDescProgramBreakaway", + SegDescProgramResumption: "SegDescProgramResumption", + SegDescProgramRunoverPlanned: "SegDescProgramRunoverPlanned", + SegDescProgramRunoverUnplanned: "SegDescProgramRunoverUnplanned", + SegDescProgramOverlapStart: "SegDescProgramOverlapStart", + SegDescProgramBlackoutOverride: "SegDescProgramBlackoutOverride", + SegDescProgramStartInProgress: "SegDescProgramStartInProgress", + SegDescChapterStart: "SegDescChapterStart", + SegDescChapterEnd: "SegDescChapterEnd", + SegDescBreakStart: "SegDescBreakStart", + SegDescBreakEnd: "SegDescBreakEnd", + SegDescProviderAdvertisementStart: "SegDescProviderAdvertisementStart", + SegDescProviderAdvertisementEnd: "SegDescProviderAdvertisementEnd", + SegDescOpeningCreditStart: "SegDescOpeningCreditStart", + SegDescOpeningCreditEnd: "SegDescOpeningCreditEnd", + SegDescClosingCreditStart: "SegDescClosingCreditStart", + SegDescClosingCreditEnd: "SegDescClosingCreditEnd", + SegDescDistributorAdvertisementStart: "SegDescDistributorAdvertisementStart", + SegDescDistributorAdvertisementEnd: "SegDescDistributorAdvertisementEnd", + SegDescProviderPOStart: "SegDescProviderPOStart", + SegDescProviderPOEnd: "SegDescProviderPOEnd", + SegDescDistributorPOStart: "SegDescDistributorPOStart", + SegDescDistributorPOEnd: "SegDescDistributorPOEnd", + SegDescProviderPromoStart: "SegDescProviderPromoStart", + SegDescProviderPromoEnd: "SegDescProviderPromoEnd", + SegDescUnscheduledEventStart: "SegDescUnscheduledEventStart", + SegDescUnscheduledEventEnd: "SegDescUnscheduledEventEnd", + SegDescAlternateContentOpportunityStart: "SegDescAlternateContentOpportunityStart", + SegDescAlternateContentOpportunityEnd: "SegDescAlternateContentOpportunityEnd", + SegDescProviderAdBlockStart: "SegDescProviderAdBlockStart", + SegDescProviderAdBlockEnd: "SegDescProviderAdBlockEnd", + SegDescNetworkStart: "SegDescNetworkStart", + SegDescNetworkEnd: "SegDescNetworkEnd", } // SegUPIDType is the Segmentation UPID Types - Only type that really needs to be checked is diff --git a/v2/scte35/modify.go b/v2/scte35/modify.go index 7a22192..46927d7 100644 --- a/v2/scte35/modify.go +++ b/v2/scte35/modify.go @@ -25,7 +25,7 @@ SOFTWARE. package scte35 import ( - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" "github.com/Comcast/gots/v2/psi" ) diff --git a/v2/scte35/modify_test.go b/v2/scte35/modify_test.go index b4ebdc6..a0cff4a 100644 --- a/v2/scte35/modify_test.go +++ b/v2/scte35/modify_test.go @@ -26,7 +26,7 @@ package scte35 import ( "bytes" - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" "github.com/Comcast/gots/v2/psi" "testing" ) diff --git a/v2/scte35/scte35.go b/v2/scte35/scte35.go index b620430..4c42e0a 100644 --- a/v2/scte35/scte35.go +++ b/v2/scte35/scte35.go @@ -29,7 +29,7 @@ import ( "encoding/binary" "fmt" - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" "github.com/Comcast/gots/v2/psi" ) diff --git a/v2/scte35/scte35_test.go b/v2/scte35/scte35_test.go index a50aa32..6b51abf 100644 --- a/v2/scte35/scte35_test.go +++ b/v2/scte35/scte35_test.go @@ -30,7 +30,7 @@ import ( "strings" "testing" - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" ) var testScte = []byte{ diff --git a/v2/scte35/segmentationdescriptor.go b/v2/scte35/segmentationdescriptor.go index 8732e81..fc56995 100644 --- a/v2/scte35/segmentationdescriptor.go +++ b/v2/scte35/segmentationdescriptor.go @@ -29,7 +29,7 @@ import ( "encoding/binary" "strings" - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" ) // upidSt is the struct used for creating a Multiple UPID (MID) @@ -147,26 +147,36 @@ var segCloseRules map[SegDescType]map[SegDescType]segCloseType // initialize the SegCloseRules map func init() { segCloseRules = map[SegDescType]map[SegDescType]segCloseType{ - 0x10: {0x10: segCloseNoBreakaway, 0x14: segCloseNormal, 0x17: segCloseNoBreakaway, 0x19: segCloseNoBreakaway, 0x20: segCloseNormal, 0x30: segCloseNormal, 0x32: segCloseNormal, 0x34: segCloseNormal, 0x36: segCloseNormal}, - 0x11: {0x10: segCloseEventID, 0x14: segCloseEventID, 0x17: segCloseEventID, 0x19: segCloseEventID, 0x20: segCloseNormal, 0x30: segCloseNormal, 0x32: segCloseNormal, 0x34: segCloseNormal, 0x36: segCloseNormal}, + 0x10: {0x10: segCloseNoBreakaway, 0x14: segCloseNormal, 0x17: segCloseNoBreakaway, 0x19: segCloseNoBreakaway, 0x20: segCloseNormal, 0x22: segCloseNormal, 0x24: segCloseNormal, 0x26: segCloseNormal, 0x30: segCloseNormal, 0x34: segCloseNormal, 0x36: segCloseNormal, 0x3C: segCloseNormal, 0x40: segCloseNormal, 0x42: segCloseNormal, 0x44: segCloseNormal}, + 0x11: {0x10: segCloseEventID, 0x14: segCloseEventID, 0x17: segCloseEventID, 0x19: segCloseEventID, 0x20: segCloseNormal, 0x22: segCloseNormal, 0x24: segCloseNormal, 0x26: segCloseNormal, 0x30: segCloseNormal, 0x34: segCloseNormal, 0x36: segCloseNormal, 0x3C: segCloseNormal, 0x40: segCloseNormal, 0x42: segCloseNormal, 0x44: segCloseNormal}, 0x12: {0x10: segCloseEventID, 0x14: segCloseEventID, 0x17: segCloseEventID, 0x19: segCloseEventID, 0x20: segCloseNormal, 0x30: segCloseNormal, 0x32: segCloseNormal, 0x34: segCloseNormal, 0x36: segCloseNormal}, 0x13: {0x20: segCloseNormal, 0x30: segCloseNormal, 0x32: segCloseNormal, 0x34: segCloseNormal, 0x36: segCloseNormal}, 0x14: {0x10: segCloseBreakaway, 0x17: segCloseBreakaway, 0x19: segCloseBreakaway, 0x20: segCloseNormal, 0x30: segCloseNormal, 0x32: segCloseNormal, 0x34: segCloseNormal, 0x36: segCloseNormal}, 0x19: {0x10: segCloseNoBreakaway, 0x14: segCloseNormal, 0x17: segCloseNoBreakaway, 0x19: segCloseNoBreakaway, 0x20: segCloseNormal, 0x30: segCloseNormal, 0x32: segCloseNormal, 0x34: segCloseNormal, 0x36: segCloseNormal}, 0x20: {0x20: segCloseNormal, 0x30: segCloseNormal, 0x32: segCloseNormal, 0x34: segCloseNormal, 0x36: segCloseNormal}, 0x21: {0x20: segCloseEventID, 0x30: segCloseNormal, 0x32: segCloseNormal, 0x34: segCloseNormal, 0x36: segCloseNormal}, - 0x22: {0x22: segCloseNormal}, - 0x23: {0x22: segCloseEventID}, + 0x22: {0x20: segCloseNormal, 0x22: segCloseNormal, 0x24: segCloseNormal, 0x26: segCloseNormal, 0x30: segCloseNormal, 0x34: segCloseNormal, 0x36: segCloseNormal, 0x3C: segCloseNormal, 0x44: segCloseNormal}, + 0x23: {0x22: segCloseEventID, 0x30: segCloseNormal, 0x34: segCloseNormal, 0x36: segCloseNormal, 0x3C: segCloseNormal, 0x44: segCloseNormal}, + 0x24: {0x20: segCloseNormal, 0x22: segCloseNormal, 0x24: segCloseNormal, 0x26: segCloseNormal, 0x30: segCloseNormal, 0x34: segCloseNormal, 0x36: segCloseNormal, 0x3C: segCloseNormal, 0x44: segCloseNormal}, + 0x25: {0x24: segCloseEventID, 0x30: segCloseNormal, 0x34: segCloseNormal, 0x36: segCloseNormal, 0x3C: segCloseNormal, 0x44: segCloseNormal}, + 0x26: {0x20: segCloseNormal, 0x22: segCloseNormal, 0x24: segCloseNormal, 0x26: segCloseNormal, 0x30: segCloseNormal, 0x34: segCloseNormal, 0x36: segCloseNormal, 0x3C: segCloseNormal, 0x44: segCloseNormal}, + 0x27: {0x26: segCloseEventID, 0x30: segCloseNormal, 0x34: segCloseNormal, 0x36: segCloseNormal, 0x3C: segCloseNormal, 0x44: segCloseNormal}, 0x30: {0x30: segCloseNormal, 0x32: segCloseNormal}, 0x31: {0x30: segCloseEventID}, 0x32: {0x30: segCloseNormal, 0x32: segCloseNormal}, 0x33: {0x32: segCloseEventID}, - 0x34: {0x30: segCloseDiffPTS, 0x32: segCloseDiffPTS, 0x34: segCloseNotNested, 0x36: segCloseNormal}, - 0x35: {0x30: segCloseNormal, 0x32: segCloseNormal, 0x34: segCloseEventIDNotNested, 0x36: segCloseNormal}, - 0x36: {0x30: segCloseDiffPTS, 0x32: segCloseDiffPTS, 0x36: segCloseNotNested}, - 0x37: {0x30: segCloseNormal, 0x32: segCloseNormal, 0x36: segCloseEventIDNotNested}, + 0x34: {0x30: segCloseDiffPTS, 0x3C: segCloseDiffPTS, 0x44: segCloseDiffPTS}, + 0x35: {0x30: segCloseNormal, 0x34: segCloseEventIDNotNested, 0x3C: segCloseNormal, 0x44: segCloseNormal}, + 0x36: {0x30: segCloseDiffPTS, 0x3C: segCloseDiffPTS, 0x44: segCloseDiffPTS}, + 0x37: {0x30: segCloseNormal, 0x36: segCloseEventIDNotNested, 0x3C: segCloseNormal, 0x44: segCloseNormal}, + 0x3C: {0x30: segCloseNormal, 0x3C: segCloseNormal}, + 0x3D: {0x3C: segCloseEventID}, 0x40: {0x40: segCloseNormal}, 0x41: {0x40: segCloseEventID}, + 0x42: {0x20: segCloseNormal, 0x22: segCloseNormal, 0x24: segCloseNormal, 0x26: segCloseNormal, 0x30: segCloseNormal, 0x34: segCloseNormal, 0x36: segCloseNormal, 0x3C: segCloseNormal, 0x42: segCloseNormal, 0x44: segCloseNormal}, + 0x43: {0x20: segCloseNormal, 0x22: segCloseNormal, 0x24: segCloseNormal, 0x26: segCloseNormal, 0x30: segCloseNormal, 0x34: segCloseNormal, 0x36: segCloseNormal, 0x3C: segCloseNormal, 0x42: segCloseEventID, 0x44: segCloseNormal}, + 0x44: {0x30: segCloseDiffPTS, 0x3C: segCloseDiffPTS, 0x44: segCloseNormal}, + 0x45: {0x30: segCloseNormal, 0x3C: segCloseNormal, 0x44: segCloseEventID}, 0x50: {0x10: segCloseNormal, 0x14: segCloseNormal, 0x17: segCloseNormal, 0x19: segCloseNormal, 0x20: segCloseNormal, 0x30: segCloseNormal, 0x32: segCloseNormal, 0x34: segCloseNormal, 0x36: segCloseNormal, 0x40: segCloseUnconditional, 0x50: segCloseNormal}, 0x51: {0x10: segCloseNormal, 0x14: segCloseNormal, 0x17: segCloseNormal, 0x19: segCloseNormal, 0x20: segCloseNormal, 0x30: segCloseNormal, 0x32: segCloseNormal, 0x34: segCloseNormal, 0x36: segCloseNormal, 0x40: segCloseUnconditional, 0x50: segCloseEventID}, } diff --git a/v2/scte35/splicecommand.go b/v2/scte35/splicecommand.go index 9e8494f..0f8b809 100644 --- a/v2/scte35/splicecommand.go +++ b/v2/scte35/splicecommand.go @@ -28,7 +28,7 @@ import ( "bytes" "encoding/binary" - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" ) // timeSignal is a struct that represents a time signal splice command in SCTE35 diff --git a/v2/scte35/splicecommandmodify.go b/v2/scte35/splicecommandmodify.go index f66f8e2..8f7ea0b 100644 --- a/v2/scte35/splicecommandmodify.go +++ b/v2/scte35/splicecommandmodify.go @@ -25,7 +25,7 @@ SOFTWARE. package scte35 import ( - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" ) // CreateSpliceInsertCommand will create a default SpliceInsertCommand. diff --git a/v2/scte35/state.go b/v2/scte35/state.go index 3e01cf1..07392bd 100644 --- a/v2/scte35/state.go +++ b/v2/scte35/state.go @@ -25,7 +25,7 @@ SOFTWARE. package scte35 import ( - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" "strings" ) @@ -144,31 +144,23 @@ func (s *state) ProcessDescriptor(desc SegmentationDescriptor) ([]SegmentationDe // out signals case SegDescProgramStart, SegDescChapterStart, + SegDescBreakStart, SegDescProviderAdvertisementStart, SegDescDistributorAdvertisementStart, SegDescProviderPOStart, SegDescDistributorPOStart, + SegDescProviderAdBlockStart, SegDescUnscheduledEventStart, SegDescNetworkStart, SegDescProgramOverlapStart, SegDescProgramStartInProgress: s.open = append(s.open, desc) - // in signals - // SegDescProgramEnd treated individually since it is expected to normally - // close program resumption AND program start case SegDescProgramEnd: if len(closed) == 0 { err = gots.ErrSCTE35MissingOut break } - for _, d := range closed { - if d.TypeID() != SegDescProgramStart && - d.TypeID() != SegDescProgramResumption { - err = gots.ErrSCTE35MissingOut - break - } - } case SegDescChapterEnd, SegDescProviderAdvertisementEnd, SegDescProviderPOEnd, diff --git a/v2/scte35/state_test.go b/v2/scte35/state_test.go index 9c1956a..04e91c3 100644 --- a/v2/scte35/state_test.go +++ b/v2/scte35/state_test.go @@ -28,7 +28,7 @@ import ( "fmt" "testing" - "github.com/Comcast/gots/v2/" + "github.com/Comcast/gots/v2" ) // All signal data generated with scte_creator: https://github.comcast.com/mniebu200/scte_creator @@ -44,25 +44,6 @@ var poClose1 = []byte{ 0x7f, 0xbf, 0x09, 0x0a, 0x54, 0x65, 0x73, 0x74, 0x31, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x35, 0x01, 0x01, 0x00, 0x00, 0xfc, 0x53, 0xaf, 0x44, } -var poOpen12 = []byte{ - 0x00, 0xfc, 0x30, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x06, 0xfe, - 0x00, 0x02, 0xbf, 0xd4, 0x00, 0x1d, 0x02, 0x1b, 0x43, 0x55, 0x45, 0x49, 0x00, 0x00, 0x00, 0x01, - 0x7f, 0xff, 0x00, 0x00, 0x0d, 0xbb, 0xa0, 0x09, 0x05, 0x54, 0x65, 0x73, 0x74, 0x32, 0x34, 0x01, - 0x02, 0x00, 0x00, 0xf9, 0x48, 0xd2, 0x4b, -} -var poOpen22 = []byte{ - 0x00, 0xfc, 0x30, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x06, 0xfe, - 0x00, 0x05, 0x7f, 0xa8, 0x00, 0x1d, 0x02, 0x1b, 0x43, 0x55, 0x45, 0x49, 0x00, 0x00, 0x00, 0x02, - 0x7f, 0xff, 0x00, 0x00, 0x05, 0x7f, 0xa8, 0x09, 0x05, 0x54, 0x65, 0x73, 0x74, 0x32, 0x34, 0x02, - 0x02, 0x00, 0x00, 0xfd, 0x82, 0x54, 0x6b, -} -var poClose1and2 = []byte{ - 0x00, 0xfc, 0x30, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x06, 0xfe, - 0x00, 0x0d, 0xbf, 0x24, 0x00, 0x36, 0x02, 0x19, 0x43, 0x55, 0x45, 0x49, 0x00, 0x00, 0x00, 0x02, - 0x7f, 0xbf, 0x09, 0x0a, 0x54, 0x65, 0x73, 0x74, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x32, 0x35, 0x01, - 0x01, 0x02, 0x19, 0x43, 0x55, 0x45, 0x49, 0x00, 0x00, 0x00, 0x01, 0x7f, 0xbf, 0x09, 0x0a, 0x54, - 0x65, 0x73, 0x74, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x31, 0x35, 0x01, 0x01, 0xfb, 0x7e, 0xde, 0xce, -} var poClose12 = []byte{ 0x00, 0xfc, 0x30, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x06, 0xfe, @@ -138,12 +119,48 @@ var ppoEndSubsegments = []byte{ 0x72, 0x50, 0x4f, 0x53, 0x74, 0x61, 0x72, 0x74, 0x35, 0x00, 0x00, 0xfa, 0x0b, 0x30, 0xf0, } +// 0x10 ProgramStart +var scteDesc10Signal = "/DBFAAAAABeOAP/wBQb+WxdHNQAvAi1DVUVJACSqm3/9ABNP17wMGURJU0MyMjA1NjVfMDAyXzAxXzU3MUEtMDEQAQEeP8NH" +// 0x11 ProgramEnd +var scteDesc11Signal = "/DBAAAAAABeOAP/wBQb+bmg4eQAqAihDVUVJACSqm3+9DBlESVNDMjIwNTY1XzAwMl8wMV81NzFBLTA2EQEB/G8f5w==" +// 0x20 ChapterStart +var scteDesc20Signal = "/DBAAAAAAtaWAAAABQb/d5cVcgAqAihDVUVJ/////3//AALEr24BFGJyYXZvX0VQMDExMzQ0MTkwMTIyIAEA4BXDFw==" +var scteDesc20Signal1= "/DA/AAB6tBn0AP/wBQb/+aPMhwApAh1DVUVJYh5C/n+fAQ5FUDAxMjMxOTU3MDk1MCABZAAIQ1VFSQAAAABYSAjC" +// 0x21 ChapterEnd +var scteDesc21Signal = "/DBAAAAAAtaWAAAABQb/elu5JQAqAihDVUVJ/////3//AALEr24BFGJyYXZvX0VQMDExMzQ0MTkwMTIyIQEA1Kv4MQ==" +// 0x22 BreakStart +var scteDesc22Signal = "/DBAAAAAAtaWAAAABQb/elu5JQAqAihDVUVJ/////3//AAEgZ5IBFGJyYXZvX0VQMDExMzQ0MTkwMTIyIgIERTkzgA==" +var scteDesc22Signal1 ="/DAsAAAAAAAAAP/wBQb+Uq7jaQAWAhRDVUVJAAABAH//AAGhbPAAACIAAL5jGRA=" +// 0x23 BreakEnd +var scteDesc23Signal = "/DBAAAAAAtaWAAAABQb/e3rvuQAqAihDVUVJ/////3//AAEgZ5IBFGJyYXZvX0VQMDExMzQ0MTkwMTIyIwIEzcrAYA==" +// 0x30 ProviderAdStart +var scteDesc30Signal = "/DBPAAAAAAAAAP/wBQb/xHJKjwA5AAVTQVBTCwIwQ1VFSf////9//wAAKSd/Dxx1cm46bmJjdW5pLmNvbTpicmM6NTM5NjM4MjY2MAYCNMFiCw==" +var scteDesc30Signal1 = "/DA2AAB6tBn0AP/wBQb//bDBCQAgAhRDVUVJYh5C/n+fAQVDMjQ3MDABAQAIQ1VFSQAAAACc3JW8" +// 0x31 ProviderAdEnd +var scteDesc31Signal = "/DBPAAAAAAAAAP/wBQb/xJt8QAA5AAVTQVBTCwIwQ1VFSf////9//wAAKSd/Dxx1cm46bmJjdW5pLmNvbTpicmM6NTM5NjM4MjY2MQYCW++KKQ==" +// 0x34 ProviderPlacementOpportunityStart +var scteDesc34Signal = "/DBfAAAAAAAA///wBQb/iRp43QBJAhxDVUVJ6tzJ0n//AAEhrJQICAAFH4Lq3MnSNAIDAilDVUVJAAAAAH+/DBpWTU5VAWCXNGVv9BHsmxsOQM8vwoUB+olIUQEAAKn6Lds=" +// 0x35 ProviderPlacementOpportunityEnd +var scteDesc35Signal = "/DBaAAAAAAAA///wBQb/ijwo4wBEAhdDVUVJ6tzJ0n+/CAgABR+C6tzJ0jUAAAIpQ1VFSQAAAAB/vwwaVk1OVQFglzRlb/QR7JsbDkDPL8KFAPqJSFEBAABl+tWe" +// 0x36 DistributorPlacementOpportunityStart +var scteDesc36Signal ="/DBLAAEs/S0UAP/wBQb+AAAAAAA1AjNDVUVJT///9X//AACky4AJH1NJR05BTDoyWURWeCtSKzlWc0FBQUFBQUFBQkFRPT02AAD9DXQ/" +//0x40 UnscheduledEventStart +var scteDesc40Signal = "/DB7AAFfzZzVAP/wBQb+AAAAAABlAlJDVUVJAABeUX+XDUMJIUJMQUNLT1VUOjI1dU5ZeEl3UXVXclI5WUxDR2I0Y2c9PQ4eY29tY2FzdDpsaW5lYXI6bGljZW5zZXJvdGF0aW9uQAAAAg9DVUVJAABeUX+XAABBAAB1H+6A" +// 0x44 ProviderAdBlockStart +var scteDesc44Signal = "/DCJAAGqtdGtAP/wBQb/AAAAAQBzAnFDVUVJQAFfVH//AAApMuANXQ8edXJuOmNvbWNhc3Q6YWx0Y29uOmFkZHJlc3NhYmxlDyx1cm46bWVybGluOmxpbmVhcjpzdHJlYW06Mzg0OTU3MzQ4MjgzNzU2NTE2MwkNUE86MTA3MzgzMTc2NEQAAAAA5o/+Nw==" +var scteDesc44Signal1 ="/DCfAAGab0HiAP/wBQb/AAAAAQCJAodDVUVJQAFfVH//AAApMuANcw8edXJuOmNvbWNhc3Q6YWx0Y29uOmFkZHJlc3NhYmxlDyx1cm46bWVybGluOmxpbmVhcjpzdHJlYW06Mzg0OTU3MzQ4MjgzNzU2NTE2MwkNUE86MTA3MzgzMTc2NAkKQlJFQUs6MTIzNAgIAAAAADeUEfJEAQMAAAu+e9A=" +// 0x45 ProviderAdBlockEnd +var scteDesc45Signal = "/DCEAAGq3wk7AP/wBQb/AAAAAQBuAmxDVUVJQAFfVH+/DV0PHnVybjpjb21jYXN0OmFsdGNvbjphZGRyZXNzYWJsZQ8sdXJuOm1lcmxpbjpsaW5lYXI6c3RyZWFtOjM4NDk1NzM0ODI4Mzc1NjUxNjMJDVBPOjEwNzM4MzE3NjRFAAAAAHbwDu4=" +// 0x50 NetworkStart +var scteDesc50Signal = "/DBQAAAAAAAAAABwBQb/LrIZ4QA6AhtDVUVJQAAAAH+fCgwUd4vl4/YAAAAAAABQAAACG0NVRUlAAAABf48KDBR3vd4u/wAAAAAAAFEAAF4PZmg=" +// 0x51 NetworkEnd +var scteDesc51Signal = "DBQAAAAAAAAAABwBQb/LrIZ4QA6AhtDVUVJQAAAAH+fCgwUd4vl4/YAAAAAAABQAAACG0NVRUlAAAABf48KDBR3vd4u/wAAAAAAAFEAAF4PZmg=" + func TestOutIn(t *testing.T) { st := NewState() open, e := NewSCTE35(poOpen1) if e != nil { - t.Error("NewSCTE35(poOpen1) returned err:", e) - t.FailNow() + t.Fatal("NewSCTE35(poOpen1) returned err:", e) } c, e := st.ProcessDescriptor(open.Descriptors()[0]) if e != nil { @@ -159,8 +176,7 @@ func TestOutIn(t *testing.T) { } close, e := NewSCTE35(poClose1) if e != nil { - t.Error("NewSCTE35(poClose1) returned err:", e) - t.FailNow() + t.Fatal("NewSCTE35(poClose1) returned err:", e) } c, e = st.ProcessDescriptor(close.Descriptors()[0]) if e != nil { @@ -180,8 +196,7 @@ func TestOutInIn(t *testing.T) { st := NewState() open, e := NewSCTE35(poOpen1) if e != nil { - t.Error("NewSCTE35(poOpen1) returned err:", e) - t.FailNow() + t.Fatal("NewSCTE35(poOpen1) returned err:", e) } c, e := st.ProcessDescriptor(open.Descriptors()[0]) if e != nil { @@ -197,15 +212,14 @@ func TestOutInIn(t *testing.T) { } close1, e := NewSCTE35(poClose12) if e != nil { - t.Error("NewSCTE35(poClose12) returned unexpected err:", e) + t.Fatal("NewSCTE35(poClose12) returned unexpected err:", e) } c, e = st.ProcessDescriptor(close1.Descriptors()[0]) if e != nil { t.Error("ProcessDescriptor of in 1 returned unexpected err:", e) } if len(c) != 0 { - t.Error("Close 1/2 closed open, which is not correct behavior") - t.FailNow() + t.Fatal("Close 1/2 closed open, which is not correct behavior") } if len(st.Open()) != 1 { t.Error("Open() returned unexpected number of descriptors") @@ -214,7 +228,7 @@ func TestOutInIn(t *testing.T) { } close2, e := NewSCTE35(poClose22) if e != nil { - t.Error("NewSCTE35(poClose22) returned unexpected err:", e) + t.Fatal("NewSCTE35(poClose22) returned unexpected err:", e) } c, e = st.ProcessDescriptor(close2.Descriptors()[0]) if e != nil { @@ -234,8 +248,7 @@ func TestDuplicateOut(t *testing.T) { st := NewState() open, e := NewSCTE35(poOpen1) if e != nil { - t.Error("NewSCTE35(poOpen1) returned err:", e) - t.FailNow() + t.Fatal("NewSCTE35(poOpen1) returned err:", e) } _, e = st.ProcessDescriptor(open.Descriptors()[0]) if e != nil { @@ -246,105 +259,92 @@ func TestDuplicateOut(t *testing.T) { t.Error("ProcessDescriptor of out returned unexpected err:", e) } if len(st.Open()) != 1 { - t.Error("Unexpected number of open signals") + t.Error("There should have been 1 open signal, instead num(open):", len(st.Open())) } } func TestOutOutIn(t *testing.T) { st := NewState() - // 0x34 - 1 - (1/2) - open12, e := NewSCTE35(poOpen12) - if e != nil { - t.Error("NewSCTE35(poOpen12) returned err:", e) - t.FailNow() + // 0x30 + padOpenSignalBytes, _ := base64.StdEncoding.DecodeString("/DBsAAH/7m1eAAKQBQb+sX6o+wBWAlRDVUVJAAAAJ3//AAApMuANQAwOQU1DTiBMMDAxMjM0NTYJCFBPOjEyMzQ1DiRiY2IxZGQ4ZS1kMzIzLTQ1ODktOWQ3OC1hM2QxMzYyYWJiYjYwAQGtc8xr") + padOpenSignal, err := NewSCTE35(append([]byte{0x0}, padOpenSignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) } - _, e = st.ProcessDescriptor(open12.Descriptors()[0]) - if e != nil { - t.Error("ProcessDescriptor of out returned unexpected err:", e) + _, err = st.ProcessDescriptor(padOpenSignal.Descriptors()[0]) + if err != nil { + t.Error("ProcessDescriptor of out returned unexpected err:", err) } if len(st.Open()) != 1 { - t.Error("Unexpected number of open signals after open12 processed.") + t.Error("There should have been 1 open signal, instead num(open):", len(st.Open())) } - // 0x34 - 2 - (2/2) - open22, e := NewSCTE35(poOpen22) - if e != nil { - t.Error("NewSCTE35(poOpen22) return err:", e) - t.FailNow() + // 0x34 + ppoStartSignalBytes, _ := base64.StdEncoding.DecodeString("/DA0AAG3wyKO///wBQb/yRLo+gAeAhxDVUVJQAAAZH/PAAEOFNwICAAAAAArJkYdNAAAMcFkEw==") + ppoStartSignal, err := NewSCTE35(append([]byte{0x0}, ppoStartSignalBytes...)) + if err != nil { + t.Fatal("NewSCTE35(ppoStartSignal) return err:", err) } - c, e := st.ProcessDescriptor(open22.Descriptors()[0]) - if e != nil { - t.Error("ProcessDescriptor of out 2 returned unexpected err:", e) + c, err := st.ProcessDescriptor(ppoStartSignal.Descriptors()[0]) + if err != nil { + t.Error("ProcessDescriptor of out 2 returned unexpected err:", err) } if len(c) != 1 { - t.Error("poOpen22 unexpectedly did not close the first signal") + t.Error("ppoStartSignal unexpectedly did not close the first signal") } if len(st.Open()) != 1 { - t.Error("state has unexpected number of signals open") + t.Error("There should have been 1 open signal, instead num(open):", len(st.Open())) } - // now pass through the close signals and check - // 0x35 - 2 - (1/1) && 0x35 - 1 - (1/1) - close, e := NewSCTE35(poClose1and2) - if e != nil { - t.Error("NewSCTE35(poClose1and2) return unexpected err:", e) + // now pass through the close signal and check + // 0x35 - close the 0x34 + closeSignalBytes, _ := base64.StdEncoding.DecodeString("/DAvAAG2uS3c///wBQb/yiD8XAAZAhdDVUVJQAAAZH+fCAgAAAAAKyZGHTUAAMzqBnE=") + close, err := NewSCTE35(append([]byte{0x0},closeSignalBytes...)) + if err != nil { + t.Fatal("NewSCTE35(closeSignalBytes) return unexpected err:", err) } - c, e = st.ProcessDescriptor(close.Descriptors()[0]) - if e != nil { - t.Error("Processing first desc of close returned unexpected err:", e) + c, err = st.ProcessDescriptor(close.Descriptors()[0]) + if err != nil { + t.Error("Processing first desc of close returned unexpected err:", err) } if len(c) != 1 { t.Error("First desc unexpectedly did not close inner out") } if len(st.Open()) != 0 { - t.Error("Unexpected number of open decriptors found") - } - - c, e = st.ProcessDescriptor(close.Descriptors()[1]) - if e != gots.ErrSCTE35MissingOut { - t.Error("Processing second desc of close return unexpected err:", e) - } - if len(c) != 0 { - t.Error("Processing second desc of close did not close outer signal") - } - if len(st.Open()) != 0 { - t.Error("Open signals remain after processing close signal") + t.Error("There should have been 0 open signals, instead num(open):", len(st.Open())) } } func TestOutOut(t *testing.T) { state := NewState() - - // 0x36 - event_id:0 - seg_num: 0 - seg_expected: 0 - outSignalBytes, _ := base64.StdEncoding.DecodeString("/DBLAAFztMbuAP/wBQb+AAAAAAA1AjNDVUVJAAAAAH//AACky4AJH1NJR05BTDozR1NOajNnb01sb0FBQUFBQUFBQkFRPT02AADO/OgI") - outSignal, err := NewSCTE35(append([]byte{0x0}, outSignalBytes...)) + // 0x30 - Out signal 1 + padOpenSignalBytes, _ := base64.StdEncoding.DecodeString("/DBsAAH/7m1eAAKQBQb+sX6o+wBWAlRDVUVJAAAAJ3//AAApMuANQAwOQU1DTiBMMDAxMjM0NTYJCFBPOjEyMzQ1DiRiY2IxZGQ4ZS1kMzIzLTQ1ODktOWQ3OC1hM2QxMzYyYWJiYjYwAQGtc8xr") + padOpenSignal, err := NewSCTE35(append([]byte{0x0}, padOpenSignalBytes...)) if err != nil { - t.Errorf("Error creating SCTE-35 signal: %s", err.Error()) + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) } - closed, err := state.ProcessDescriptor(outSignal.Descriptors()[0]) + _, err = state.ProcessDescriptor(padOpenSignal.Descriptors()[0]) if err != nil { - t.Errorf("ProcessDescriptor returned an error: %s", err.Error()) - } - if len(closed) != 0 { - t.Errorf("No events should have been closed (%d were)", len(closed)) + t.Error("ProcessDescriptor of out returned unexpected err:", err) } if len(state.Open()) != 1 { - t.Errorf("There should be one open signal (%d)", len(state.Open())) + t.Error("There should have been 1 open signal, instead num(open):", len(state.Open())) } // 0x36 - event_id: 1342177266 - seg_num: 0 - seg_expected: 0 + // Should close the earlier Out secondOutSignalBytes, _ := base64.StdEncoding.DecodeString("/DBLAAF0QXOWAP/wBQb+AAAAAAA1AjNDVUVJT///8n//AACky4AJH1NJR05BTDozR1NOanl3cE1sb0FBQUFBQUFBQkFRPT02AAA9gIK2") secondOutSignal, err := NewSCTE35(append([]byte{0x0}, secondOutSignalBytes...)) if err != nil { - t.Errorf("Error creating SCTE-35 signal: %s", err.Error()) + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) } - closed, err = state.ProcessDescriptor(secondOutSignal.Descriptors()[0]) + closed, err := state.ProcessDescriptor(secondOutSignal.Descriptors()[0]) if err != nil { t.Errorf("ProcessDescriptor returned an error: %s", err.Error()) } @@ -352,7 +352,7 @@ func TestOutOut(t *testing.T) { t.Errorf("One event should have been closed (%d were)", len(closed)) } if len(state.Open()) != 1 { - t.Errorf("There should be one open signals (%d)", len(state.Open())) + t.Errorf("There should be one open signal (%d)", len(state.Open())) } } @@ -363,8 +363,7 @@ func TestSubsegments(t *testing.T) { // 0x34 ppoStart, err := NewSCTE35(ppoStartSubsegments) if err != nil { - t.Error("NewSCTE35(poOpen22) return err:", err.Error()) - t.FailNow() + t.Fatal("NewSCTE35(ppoStartSubsegments) return err:", err.Error()) } closed, err := state.ProcessDescriptor(ppoStart.Descriptors()[0]) @@ -381,8 +380,7 @@ func TestSubsegments(t *testing.T) { // 0x36 dpoStart, err := NewSCTE35(dpoStartSubsegments) if err != nil { - t.Error("NewSCTE35(dpoStartSubsegments) return err:", err.Error()) - t.FailNow() + t.Fatal("NewSCTE35(dpoStartSubsegments) return err:", err.Error()) } closed, err = state.ProcessDescriptor(dpoStart.Descriptors()[0]) @@ -399,8 +397,7 @@ func TestSubsegments(t *testing.T) { // 0x37 dpoFirstEnd, err := NewSCTE35(dpoFirstEndSubsegments) if err != nil { - t.Error("NewSCTE35(dpoFirstEndSubsegments) return err:", err.Error()) - t.FailNow() + t.Fatal("NewSCTE35(dpoFirstEndSubsegments) return err:", err.Error()) } closed, err = state.ProcessDescriptor(dpoFirstEnd.Descriptors()[0]) @@ -417,8 +414,7 @@ func TestSubsegments(t *testing.T) { // 0x37 dpoSecondEnd, err := NewSCTE35(dpoSecondEndSubsegments) if err != nil { - t.Error("NewSCTE35(dpoSecondEndSubsegments) return err:", err.Error()) - t.FailNow() + t.Fatal("NewSCTE35(dpoSecondEndSubsegments) return err:", err.Error()) } closed, err = state.ProcessDescriptor(dpoSecondEnd.Descriptors()[0]) @@ -435,8 +431,7 @@ func TestSubsegments(t *testing.T) { // 0x35 ppoEnd, err := NewSCTE35(ppoEndSubsegments) if err != nil { - t.Error("NewSCTE35(ppoEndSubsegments) return err:", err.Error()) - t.FailNow() + t.Fatal("NewSCTE35(ppoEndSubsegments) return err:", err.Error()) } closed, err = state.ProcessDescriptor(ppoEnd.Descriptors()[0]) if err != nil { @@ -451,8 +446,8 @@ func TestSubsegments(t *testing.T) { } // Test the logic for when a closing IN signal occurs after another OUT signal. -// 0x36 -> 0x37 (1/3) -> 0x37 (2/3) -> 0x36 -> 0x37 (3/3) -// End state should be just the second 0x36. +// 0x36 -> 0x37 (1/3) -> 0x37 (2/3) -> 0x30 -> 0x37 (3/3) +// End state should be just 0x30. func TestOutInInOutIn(t *testing.T) { state := NewState() @@ -460,7 +455,7 @@ func TestOutInInOutIn(t *testing.T) { outSignalBytes, _ := base64.StdEncoding.DecodeString("/DBLAAFztMbuAP/wBQb+AAAAAAA1AjNDVUVJAAAAAH//AACky4AJH1NJR05BTDozR1NOajNnb01sb0FBQUFBQUFBQkFRPT02AADO/OgI") outSignal, err := NewSCTE35(append([]byte{0x0}, outSignalBytes...)) if err != nil { - t.Errorf("Error creating SCTE-35 signal: %s", err.Error()) + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) } closed, err := state.ProcessDescriptor(outSignal.Descriptors()[0]) @@ -478,7 +473,7 @@ func TestOutInInOutIn(t *testing.T) { firstInSignalBytes, _ := base64.StdEncoding.DecodeString("/DBGAAF0ByyuAP/wBQb+AAAAAAAwAi5DVUVJAAAAAH+/CR9TSUdOQUw6M0dTTmozZ29NbG9BQUFBQUFBQUJBZz09NwEDfTeSVQ==") firstInSignal, err := NewSCTE35(append([]byte{0x0}, firstInSignalBytes...)) if err != nil { - t.Errorf("Error creating SCTE-35 signal: %s", err.Error()) + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) } closed, err = state.ProcessDescriptor(firstInSignal.Descriptors()[0]) @@ -496,7 +491,7 @@ func TestOutInInOutIn(t *testing.T) { secondInSignalBytes, _ := base64.StdEncoding.DecodeString("/DBGAAF0MF+OAP/wBQb+AAAAAAAwAi5DVUVJAAAAAH+/CR9TSUdOQUw6M0dTTmozZ29NbG9BQUFBQUFBQUJBdz09NwIDvefEqg==") secondInSignal, err := NewSCTE35(append([]byte{0x0}, secondInSignalBytes...)) if err != nil { - t.Errorf("Error creating SCTE-35 signal: %s", err.Error()) + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) } closed, err = state.ProcessDescriptor(secondInSignal.Descriptors()[0]) @@ -510,48 +505,41 @@ func TestOutInInOutIn(t *testing.T) { t.Errorf("There should be one open signal (%d)", len(state.Open())) } - // 0x36 - event_id: 1342177266 - seg_num: 0 - seg_expected: 0 - // This signal will close the previous 0x36. - secondOutSignalBytes, _ := base64.StdEncoding.DecodeString("/DBLAAF0QXOWAP/wBQb+AAAAAAA1AjNDVUVJT///8n//AACky4AJH1NJR05BTDozR1NOanl3cE1sb0FBQUFBQUFBQkFRPT02AAA9gIK2") - secondOutSignal, err := NewSCTE35(append([]byte{0x0}, secondOutSignalBytes...)) + // 0x30 Another Out + padOpenSignalBytes, _ := base64.StdEncoding.DecodeString("/DBsAAH/7m1eAAKQBQb+sX6o+wBWAlRDVUVJAAAAJ3//AAApMuANQAwOQU1DTiBMMDAxMjM0NTYJCFBPOjEyMzQ1DiRiY2IxZGQ4ZS1kMzIzLTQ1ODktOWQ3OC1hM2QxMzYyYWJiYjYwAQGtc8xr") + padOpenSignal, err := NewSCTE35(append([]byte{0x0}, padOpenSignalBytes...)) if err != nil { - t.Errorf("Error creating SCTE-35 signal: %s", err.Error()) + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) } - closed, err = state.ProcessDescriptor(secondOutSignal.Descriptors()[0]) + closed, err = state.ProcessDescriptor(padOpenSignal.Descriptors()[0]) if err != nil { t.Errorf("ProcessDescriptor returned an error: %s", err.Error()) } - if len(closed) != 1 { - t.Errorf("One event should have been closed (%d were)", len(closed)) + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) } - if len(state.Open()) != 1 { - t.Errorf("There should be one open signals (%d)", len(state.Open())) + if len(state.Open()) != 2 { + t.Errorf("There should be two open signals (%d)", len(state.Open())) } // 0x37 = event_id: 0 - seg_num: 3 - seg_expected: 3 - // This will return ErrMissingOut when processed since the previous 0x36 closed the 0x36 this 0x37 belongs to. + // This closed the 0x30 and the 0x36 thirdInSignalBytes, _ := base64.StdEncoding.DecodeString("/DBGAAF0WZJuAP/wBQb+AAAAAAAwAi5DVUVJAAAAAH+/CR9TSUdOQUw6M0dTTmozZ29NbG9BQUFBQUFBQUJCQT09NwMDFkn/Gw==") thirdInSignal, err := NewSCTE35(append([]byte{0x0}, thirdInSignalBytes...)) if err != nil { - t.Errorf("Error creating SCTE-35 signal: %s", err.Error()) + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) } closed, err = state.ProcessDescriptor(thirdInSignal.Descriptors()[0]) - if err != gots.ErrSCTE35MissingOut { + if err != nil { t.Error("ProcessDescriptor of out returned unexpected err:", err) } - if len(closed) != 0 { - t.Errorf("No events should have been closed (%d were)", len(closed)) - } - if len(state.Open()) != 1 { - t.Errorf("There should be one open signal (%d)", len(state.Open())) + if len(closed) != 2 { + t.Errorf("Two events should have been closed (%d were)", len(closed)) } - if state.Open()[0].TypeID() != SegDescDistributorPOStart { - t.Errorf("Expected segmentation_type_id 0x36 but got %x", state.Open()[0].TypeID()) - } - if state.Open()[0].EventID() != 1342177266 { - t.Errorf("Expected event_id 1342177266 but got %d", state.Open()[0].EventID()) + if len(state.Open()) != 0 { + t.Errorf("There should be no open signal (%d)", len(state.Open())) } } @@ -562,7 +550,7 @@ func TestVSS(t *testing.T) { outSignalBytes, _ := base64.StdEncoding.DecodeString("/DB7AAFe1ms7AP/wBQb+AAAAAABlAlJDVUVJAABeT3+XDUMJIUJMQUNLT1VUOlEza2dMYmx4UzlhTmh4S24wY1N0MlE9PQ4eY29tY2FzdDpsaW5lYXI6bGljZW5zZXJvdGF0aW9uQAAAAg9DVUVJAABeT3+XAABBAAC9uy+v") outSignal, err := NewSCTE35(append([]byte{0x0}, outSignalBytes...)) if err != nil { - t.Errorf("Error creating SCTE-35 signal: %s", err.Error()) + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) } // 0x40 @@ -608,7 +596,7 @@ func TestVSSSameSignalIdBackToBack(t *testing.T) { outSignalBytes1, _ := base64.StdEncoding.DecodeString(vss_1) outSignal1, err := NewSCTE35(append([]byte{0x0}, outSignalBytes1...)) if err != nil { - t.Errorf("Error creating SCTE-35 signal: %s", err.Error()) + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) } // 0x40 @@ -646,7 +634,7 @@ func TestVSSSameSignalIdBackToBack(t *testing.T) { outSignalBytes2, _ := base64.StdEncoding.DecodeString(vss_2) outSignal2, err := NewSCTE35(append([]byte{0x0}, outSignalBytes2...)) if err != nil { - t.Errorf("Error creating SCTE-35 signal: %s", err.Error()) + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) } // 0x40 @@ -678,14 +666,14 @@ func printState(s State, header string) { println() } -func TestOutInInOutIn36_37_35_37_37(t *testing.T) { +func TestOutInInOutIn36_37_10_37_37(t *testing.T) { state := NewState() // 0x36 - event_id:0 - seg_num: 0 - seg_expected: 0 outSignalBytes, _ := base64.StdEncoding.DecodeString("/DBLAAEs/S0UAP/wBQb+AAAAAAA1AjNDVUVJT///9X//AACky4AJH1NJR05BTDoyWURWeCtSKzlWc0FBQUFBQUFBQkFRPT02AAD9DXQ/") outSignal, err := NewSCTE35(append([]byte{0x0}, outSignalBytes...)) if err != nil { - t.Errorf("Error creating SCTE-35 signal: %s", err.Error()) + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) } closed, err := state.ProcessDescriptor(outSignal.Descriptors()[0]) @@ -703,7 +691,7 @@ func TestOutInInOutIn36_37_35_37_37(t *testing.T) { firstInSignalBytes, _ := base64.StdEncoding.DecodeString("/DBGAAEtT5LUAP/wBQb+AAAAAAAwAi5DVUVJT///9X+/CR9TSUdOQUw6MllEVngrUis5VnNBQUFBQUFBQUJBZz09NwEDU/ktPg==") firstInSignal, err := NewSCTE35(append([]byte{0x0}, firstInSignalBytes...)) if err != nil { - t.Errorf("Error creating SCTE-35 signal: %s", err.Error()) + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) } closed, err = state.ProcessDescriptor(firstInSignal.Descriptors()[0]) @@ -717,11 +705,11 @@ func TestOutInInOutIn36_37_35_37_37(t *testing.T) { t.Errorf("There should be one open signal (%d)", len(state.Open())) } - // 0x35 closes 36 - In35SignalBytes, _ := base64.StdEncoding.DecodeString("/DAvAAD5dbEbAP/wBQb+M+6KUwAZAhdDVUVJQAAAPn+fCAgAAAAALecjUzUAALuiqds=") + // 0x10 closes 0x36 as per the SCTE-35 2020 spec + In35SignalBytes, _ := base64.StdEncoding.DecodeString("/DBFAAAAABeOAP/wBQb+WxdHNQAvAi1DVUVJACSqm3/9ABNP17wMGURJU0MyMjA1NjVfMDAyXzAxXzU3MUEtMDEQAQEeP8NH") In35Signal, err := NewSCTE35(append([]byte{0x0}, In35SignalBytes...)) if err != nil { - t.Errorf("Error creating SCTE-35 signal: %s", err.Error()) + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) } closed, err = state.ProcessDescriptor(In35Signal.Descriptors()[0]) @@ -731,46 +719,890 @@ func TestOutInInOutIn36_37_35_37_37(t *testing.T) { if len(closed) != 1 { t.Errorf("1 event should have been closed (%d were)", len(closed)) } - if len(state.Open()) != 0 { - t.Errorf("There should be 0 open signal (%d)", len(state.Open())) + if len(state.Open()) != 1 { + t.Errorf("There should be 1 signal (%d)", len(state.Open())) } // 0x37 - event_id: 0 - seg_num: 2 - seg_expected: 3 secondInSignalBytes, _ := base64.StdEncoding.DecodeString("/DBGAAEteMW0AP/wBQb+AAAAAAAwAi5DVUVJT///9X+/CR9TSUdOQUw6MllEVngrUis5VnNBQUFBQUFBQUJBdz09NwID1nPQRg==") secondInSignal, err := NewSCTE35(append([]byte{0x0}, secondInSignalBytes...)) if err != nil { - t.Errorf("Error creating SCTE-35 signal: %s", err.Error()) + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) } closed, err = state.ProcessDescriptor(secondInSignal.Descriptors()[0]) - // ErrSCTE35MissingOut expected as 0x35 closed 0x36 - if err != gots.ErrSCTE35MissingOut { + // ErrSCTE35MissingOut expected as 0x30 closed the 0x36, the 0x37 has nothing to close. + if err != nil && err != gots.ErrSCTE35MissingOut { t.Errorf("ProcessDescriptor returned an error: %s", err.Error()) } if len(closed) != 0 { t.Errorf("No events should have been closed (%d were)", len(closed)) } + if len(state.Open()) != 1 { + t.Errorf("There should have been 1 open signal, but we saw (%d) open signals instead.", len(state.Open())) + } +} + +// Tests closing logic of 0x11 with 0x10, 0x20 ,0x30 +func Test11ClosingLogic(t *testing.T) { + state := NewState() + + // 0x10 + scteDesc10SignalBytes, _ := base64.StdEncoding.DecodeString(scteDesc10Signal) + outSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc10SignalBytes ...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err := state.ProcessDescriptor(outSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be one open signal (have %d)", len(state.Open())) + } + + // 0x20 + scteDesc20SignalBytes, _ := base64.StdEncoding.DecodeString(scteDesc20Signal) + outSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc20SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + closed, err = state.ProcessDescriptor(outSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 2 { + t.Errorf("There should be two open signals (have %d)", len(state.Open())) + } + + // 0x30 + scteDesc30SignalBytes, _ := base64.StdEncoding.DecodeString(scteDesc30Signal) + inSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc30SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 3 { + t.Errorf("There should be three open signals (have %d)", len(state.Open())) + } + + // 0x11, it should close the open 0x10, 0x20 ,0x30 + scteDesc11SignalBytes, _ := base64.StdEncoding.DecodeString(scteDesc11Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc11SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 3 { + t.Errorf("Three events should have been closed (%d were)", len(closed)) + } if len(state.Open()) != 0 { - t.Errorf("There should be 0 open signal (%d)", len(state.Open())) + t.Errorf("There should be no open signal (have %d)", len(state.Open())) } +} - // 0x37 = event_id: 0 - seg_num: 3 - seg_expected: 3 - // This will return ErrMissingOut when processed since the previous 0x36 closed the 0x36 this 0x37 belongs to. - thirdInSignalBytes, _ := base64.StdEncoding.DecodeString("/DBGAAEtofiUAP/wBQb+AAAAAAAwAi5DVUVJT///9X+/CR9TSUdOQUw6MllEVngrUis5VnNBQUFBQUFBQUJCQT09NwMDJVJ1Mg==") - thirdInSignal, err := NewSCTE35(append([]byte{0x0}, thirdInSignalBytes...)) +func Test11Closing22(t *testing.T) { + state := NewState() + + // 0x22 + scteDesc22SignalBytes, _ := base64.StdEncoding.DecodeString(scteDesc22Signal) + outSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc22SignalBytes...)) if err != nil { - t.Errorf("Error creating SCTE-35 signal: %s", err.Error()) + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) } - closed, err = state.ProcessDescriptor(thirdInSignal.Descriptors()[0]) - // ErrSCTE35MissingOut expected as 0x35 closed 0x36 - if err != gots.ErrSCTE35MissingOut { - t.Error("ProcessDescriptor of out returned unexpected err:", err) + closed, err := state.ProcessDescriptor(outSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // 0x11, it should close the open 0x22 + scteDesc11SignalBytes, _ := base64.StdEncoding.DecodeString(scteDesc11Signal) + inSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc11SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 1 { + t.Errorf("One event should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 0 { + t.Errorf("There should be no open signal (have %d)", len(state.Open())) + } +} + +func Test11Closing34_36_40_44(t *testing.T) { + state := NewState() + + //0x34 + scteDesc34SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc34Signal) + inSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc34SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err := state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // 0x36 + scteDesc36SignalBytes, _ := base64.StdEncoding.DecodeString(scteDesc36Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc36SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 2 { + t.Errorf("There should be 2 open signals (have %d)", len(state.Open())) + } + + // 0x40 + scteDesc40SignalBytes, _ := base64.StdEncoding.DecodeString(scteDesc40Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc40SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 3 { + t.Errorf("There should be 3 open signals (have %d)", len(state.Open())) + } + + // 0x44 + scteDesc44SignalBytes, _ := base64.StdEncoding.DecodeString(scteDesc44Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc44SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 4 { + t.Errorf("There should be 4 open signals (have %d)", len(state.Open())) + } + + // 0x11 - it should close the open 0x34, 0x36, 0x40, 0x44 + scteDesc11SignalBytes, _ := base64.StdEncoding.DecodeString(scteDesc11Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc11SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 4 { + t.Errorf("4 events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 0 { + t.Errorf("There should be no open signal (have %d)", len(state.Open())) + } +} + +// Tests closing logic of 0x45 +func Test45ClosingLogic(t *testing.T) { + state := NewState() + + //0x44 + scteDesc44SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc44Signal) + inSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc44SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err := state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // 0x30 + scteDesc30SignalBytes, _ := base64.StdEncoding.DecodeString(scteDesc30Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc30SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) } if len(closed) != 0 { t.Errorf("No events should have been closed (%d were)", len(closed)) } + if len(state.Open()) != 2 { + t.Errorf("There should be 2 open signals (have %d)", len(state.Open())) + } + + // 0x45 - closes 0x44 and 0x30 + scteDesc45SignalBytes, _ := base64.StdEncoding.DecodeString(scteDesc45Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc45SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 2 { + t.Errorf("2 events should have been closed (%d were)", len(closed)) + } if len(state.Open()) != 0 { - t.Errorf("There should be 0 open signal (%d)", len(state.Open())) + t.Errorf("There should be no open signals (have %d)", len(state.Open())) + } +} +// Tests closing logic of 0x44 +func Test44ClosingLogic(t *testing.T) { + state := NewState() + + // 0x44 + scteDesc44SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc44Signal) + inSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc44SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err := state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // 0x30 + scteDesc30SignalBytes, _ := base64.StdEncoding.DecodeString(scteDesc30Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc30SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 2 { + t.Errorf("There should be 2 open signals (have %d)", len(state.Open())) + } + + // Different 0x44 - closes the earlier 0x44 and 0x30 + scteDesc44SignalBytes1, _ := base64.StdEncoding.DecodeString(scteDesc44Signal1) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc44SignalBytes1...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 2 { + t.Errorf("2 events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { // the last 0x44 sent should still be open + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) } } + +// Tests closing logic of 0x23 +func Test23ClosingLogic_30_34_36_44(t *testing.T) { + state := NewState() + + // 0x34 + scteDesc34SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc34Signal) + inSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc34SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err := state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // 0x36 + scteDesc36SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc36Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc36SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 2 { + t.Errorf("There should be 2 open signals (have %d)", len(state.Open())) + } + + // 0x44 + scteDesc44SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc44Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc44SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 3 { + t.Errorf("There should be 3 open signals (have %d)", len(state.Open())) + } + + // 0x30 + scteDesc30SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc30Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc30SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 4 { + t.Errorf("There should be 4 open signals (have %d)", len(state.Open())) + } + + // 0x23 - This should close 0x30, 0x34, 0x36, 0x44 + scteDesc23SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc23Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc23SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 4 { + t.Errorf("4 events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 0 { + t.Errorf("There should be 0 open signals (have %d)", len(state.Open())) + } +} + +func Test23Closing22Logic(t *testing.T){ + state := NewState() + + // 0x22 + scteDesc22SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc22Signal) + inSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc22SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err := state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // 0x23 - This should close 0x22 + scteDesc23SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc23Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc23SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 1 { + t.Errorf("1 event should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 0 { + t.Errorf("There should be 0 open signals (have %d)", len(state.Open())) + } +} + +func Test22ClosingLogic_30_34_36_44_22(t *testing.T){ + state := NewState() + + // 0x36 + scteDesc36SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc36Signal) + inSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc36SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err := state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // 0x34 + scteDesc34SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc34Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc34SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 2 { + t.Errorf("There should be 2 open signals (have %d)", len(state.Open())) + } + + // 0x44 + scteDesc44SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc44Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc44SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 3 { + t.Errorf("There should be 3 open signals (have %d)", len(state.Open())) + } + + // 0x30 + scteDesc30SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc30Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc30SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 4 { + t.Errorf("There should be 4 open signals (have %d)", len(state.Open())) + } + + // 0x22 - should close 0x30, 0x34, 0x36, 0x44 + scteDesc22SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc22Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc22SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 4 { + t.Errorf("4 events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // New 0x22 - should close the last 0x22 + scteDesc22SignalBytes1 , _ := base64.StdEncoding.DecodeString(scteDesc22Signal1) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc22SignalBytes1...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 1 { + t.Errorf("1 event should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } +} + +func Test31ClosingLogic(t *testing.T){ + state := NewState() + + // 0x30 + scteDesc30SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc30Signal) + inSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc30SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err := state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // 0x31 + scteDesc31SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc31Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc31SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 1 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 0 { + t.Errorf("There should be 0 open signals (have %d)", len(state.Open())) + } +} + +func Test30Closing30Logic(t *testing.T){ + state := NewState() + + // 0x30 + scteDesc30SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc30Signal) + inSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc30SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err := state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // 0x30 - new one, will close the old 0x30 + scteDesc30SignalBytes1 , _ := base64.StdEncoding.DecodeString(scteDesc30Signal1) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc30SignalBytes1...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 1 { + t.Errorf("1 event should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } +} + +func Test21ClosingLogic_30_34_36(t *testing.T){ + state := NewState() + + // 0x34 + scteDesc34SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc34Signal) + inSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc34SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err := state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // 0x36 + scteDesc36SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc36Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc36SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 2 { + t.Errorf("There should be 2 open signals (have %d)", len(state.Open())) + } + + // 0x30 + scteDesc30SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc30Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc30SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 3 { + t.Errorf("There should be 3 open signals (have %d)", len(state.Open())) + } + + // 0x21 - This should close 0x30, 0x34, 0x36 + scteDesc21SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc21Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc21SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 3 { + t.Errorf("3 events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 0 { + t.Errorf("There should be 0 open signals (have %d)", len(state.Open())) + } +} + +func Test21Closing20Logic(t *testing.T){ + state := NewState() + + // 0x20 + scteDesc20SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc20Signal) + inSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc20SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err := state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // 0x21 - This should close 0x20 + scteDesc21SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc21Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc21SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 1 { + t.Errorf("1 event should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 0 { + t.Errorf("There should be 0 open signals (have %d)", len(state.Open())) + } +} + +func Test20ClosingLogic_20_30_34_36(t *testing.T){ + state := NewState() + + // 0x36 + scteDesc36SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc36Signal) + inSignal, err := NewSCTE35(append([]byte{0x0}, scteDesc36SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err := state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // 0x34 + scteDesc34SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc34Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc34SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 2 { + t.Errorf("There should be 2 open signals (have %d)", len(state.Open())) + } + + // 0x30 + scteDesc30SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc30Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc30SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 0 { + t.Errorf("No events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 3 { + t.Errorf("There should be 3 open signals (have %d)", len(state.Open())) + } + + // 0x20 - should close 0x30, 0x34, 0x36 + scteDesc20SignalBytes , _ := base64.StdEncoding.DecodeString(scteDesc20Signal) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc20SignalBytes...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 3 { + t.Errorf("3 events should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } + + // New 0x20 - should close the last 0x20 + scteDesc20SignalBytes1 , _ := base64.StdEncoding.DecodeString(scteDesc20Signal1) + inSignal, err = NewSCTE35(append([]byte{0x0}, scteDesc20SignalBytes1...)) + if err != nil { + t.Fatal("Error creating SCTE-35 signal, return err:", err.Error()) + } + + closed, err = state.ProcessDescriptor(inSignal.Descriptors()[0]) + if err != nil { + t.Errorf("ProcessDescriptor returned an error unexpectedly: %s", err.Error()) + } + if len(closed) != 1 { + t.Errorf("1 event should have been closed (%d were)", len(closed)) + } + if len(state.Open()) != 1 { + t.Errorf("There should be 1 open signal (have %d)", len(state.Open())) + } +} \ No newline at end of file