Skip to content

Commit

Permalink
Support unencrypted signals use of alignment_stuffing
Browse files Browse the repository at this point in the history
  • Loading branch information
blahspam committed Sep 9, 2021
1 parent bb00af4 commit 4003cca
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [1.2.1] - 2021-09-09

### Fixed

* Fixed case where unencrypted signals with `alignment_stuffing` returned `ErrBufferUnderflow`.

## [1.2.0] - 2021-07-07

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Get the module:

```shell
$ go get github.com/Comcast/scte35-go
go get: added github.com/Comcast/scte35-go v1.0.0
go get: added github.com/Comcast/scte35-go v1.2.1
```

## Code Examples
Expand Down
18 changes: 16 additions & 2 deletions pkg/scte35/scte35_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func TestDecodeBase64(t *testing.T) {
{
name: "Empty String",
binary: "",
err: fmt.Errorf("splice_info_section: %w", scte35.ErrBufferOverflow),
err: scte35.ErrBufferOverflow,
},
{
name: "Invalid Base64 Encoding",
Expand Down Expand Up @@ -536,9 +536,23 @@ func TestDecodeBase64(t *testing.T) {
binary: "/DA4AAAAAAAAAP/wFAUABDEAf+//mWEhzP4Azf5gAQAAAAATAhFDVUVJAAAAAX+/AQIwNAEAAKeYO3Q=",
err: fmt.Errorf("splice_info_section: %w", scte35.ErrCRC32Invalid),
},
{
name: "Alignment Stuffing without Encryption",
binary: "/DAeAAAAAAAAAP///wViAA/nf18ACQAAAAAskJv+YPtE",
expected: scte35.SpliceInfoSection{
SpliceCommand: &scte35.SpliceInsert{
SpliceEventID: 1644171239,
Program: &scte35.SpliceInsertProgram{},
SpliceImmediateFlag: true,
UniqueProgramID: 9,
},
Tier: 4095,
SAPType: 3,
},
legacy: true, // binary wont match because of stuffing
},
}


for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
// decode the binary
Expand Down
8 changes: 7 additions & 1 deletion pkg/scte35/splice_info_section.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ func (sis *SpliceInfoSection) Decode(b []byte) (err error) {
if encryptedPacket {
sis.alignmentStuffing = int(r.LeftBits()) - 64
sis.ecrc32 = r.Bytes(4)
} else {
sis.alignmentStuffing = int(r.LeftBits()-32) / 8
if sis.alignmentStuffing < 0 {
return ErrBufferOverflow
}
r.Skip(uint(sis.alignmentStuffing * 8))
}
sis.crc32 = r.Bytes(4)

Expand Down Expand Up @@ -201,8 +207,8 @@ func (sis *SpliceInfoSection) Encode() ([]byte, error) {
}

// Encoding encrypted signals is untested.
iow.PutUint64(uint(sis.alignmentStuffing), 0) // alignment_stuffing
if sis.EncryptedPacket.EncryptionAlgorithm != EncryptionAlgorithmNone {
iow.PutUint64(uint(sis.alignmentStuffing), 0) // alignment_stuffing
iow.PutUint32(32, calculateCRC32(buf[:iow.Index()/8])) // E_CRC_32
}

Expand Down

0 comments on commit 4003cca

Please sign in to comment.