Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include segmentationUpidFormat when encoding to json/xml #61

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 8 additions & 21 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,16 @@ jobs:
- name: Check out code
uses: actions/checkout@v3

- name: Install Go
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: "1.20"
check-latest: true

- name: Go Format
run: gofmt -s -w . && git diff --exit-code

- name: Go Tidy
run: go mod tidy && git diff --exit-code

- name: Go Mod
run: go mod download

- name: Go Mod Verify
run: go mod verify

- name: Go Vet
run: go vet ./...

- name: Go Build
run: go build -o /dev/null ./...
- name: Run linters
uses: golangci/golangci-lint-action@v6
with:
version: latest
args: -v --timeout=5m

- name: Go Test
run: go test -v -count=1 -race -shuffle=on ./...
- name: Run Test
run: go test --race ./...
46 changes: 46 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
run:
tests: false
timeout: 5m

linters-settings:
errcheck:
check-type-assertions: true

linters:
enable:
- bodyclose
- containedctx
- contextcheck
- copyloopvar
- decorder
- errname
- errorlint
- exhaustive
- exportloopref
- gci
- gochecknoinits
- gocritic
- godox
- gofmt
- goimports
- goprintffuncname
- gosec
- intrange
- misspell
- noctx
- nosprintfhostport
- revive
- sqlclosecheck
- stylecheck
- testpackage
- unparam
- wastedassign
- whitespace

issues:
include:
- EXC0012
- EXC0013
- EXC0014
- EXC0015
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,13 @@ avail_descriptor() {
}

XML:
<SpliceInfoSection xmlns="http://www.scte.org/schemas/35" sapType="3" ptsAdjustment="0" protocolVersion="0" tier="4095">
<SpliceInfoSection xmlns="http://www.scte.org/schemas/35" sapType="3" tier="4095">
<EncryptedPacket xmlns="http://www.scte.org/schemas/35" encryptionAlgorithm="0" cwIndex="0"></EncryptedPacket>
<TimeSignal xmlns="http://www.scte.org/schemas/35">
<SpliceTime xmlns="http://www.scte.org/schemas/35" ptsTime="3550479013"></SpliceTime>
</TimeSignal>
<SegmentationDescriptor xmlns="http://www.scte.org/schemas/35" segmentationEventId="39965" segmentationEventCancelIndicator="false" segmentationDuration="10800000" segmentationTypeId="49" segmentNum="1" segmentsExpected="1">
<SegmentationUpid xmlns="http://www.scte.org/schemas/35" segmentationUpidType="12" formatIdentifier="1145656131" format="base-64">WU1XRjA0NTIwMDBI</SegmentationUpid>
<SegmentationDescriptor xmlns="http://www.scte.org/schemas/35" segmentationEventId="39965" segmentationDuration="10800000" segmentationTypeId="49" segmentNum="1" segmentsExpected="1">
<SegmentationUpid xmlns="http://www.scte.org/schemas/35" segmentationUpidType="12" segmentationUpidFormat="base-64" formatIdentifier="1145656131">WU1XRjA0NTIwMDBI</SegmentationUpid>
</SegmentationDescriptor>
</SpliceInfoSection>

Expand Down
4 changes: 2 additions & 2 deletions cmd/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ func decodeCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "decode",
Short: "Decode a splice_info_section from binary",
Args: func(cmd *cobra.Command, args []string) error {
Args: func(_ *cobra.Command, args []string) error {
if len(args) != 1 {
return fmt.Errorf("requires a binary signal")
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
bin := args[0]
var sis *scte35.SpliceInfoSection
var err error
Expand Down
4 changes: 2 additions & 2 deletions cmd/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ func encodeCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "encode < filename or encode {\"protocolVersion\"... ",
Short: "Encode a splice_info_section to binary being provided from stdin or as a parameter",
Args: func(cmd *cobra.Command, args []string) error {
Args: func(_ *cobra.Command, args []string) error {
if len(args) > 1 {
return fmt.Errorf("invalid number of parameter provided")
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
var err error
var input string
var sis *scte35.SpliceInfoSection
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/Comcast/scte35-go

go 1.18
go 1.22.0

toolchain go1.22.5

require (
github.com/bamiaux/iobit v0.0.0-20170418073505-498159a04883
Expand Down
2 changes: 1 addition & 1 deletion pkg/scte35/audio_descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (sd *AudioDescriptor) decode(b []byte) error {
audioCount := int(r.Uint32(4))
r.Skip(4) // reserved
sd.AudioChannels = make([]AudioChannel, audioCount)
for i := 0; i < audioCount; i++ {
for i := range audioCount {
ac := AudioChannel{}
ac.ComponentTag = r.Uint32(8)
ac.ISOCode = r.String(3)
Expand Down
1 change: 1 addition & 0 deletions pkg/scte35/delivery_restrictions.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (dr *DeliveryRestrictions) deviceRestrictionsName() string {
case DeviceRestrictionsNone:
return "None"
default:
// nolint:goconst
return "Unknown"
}
}
4 changes: 2 additions & 2 deletions pkg/scte35/encrypted_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const (
// EncryptedPacket contains the encryption details if this payload has been
// encrypted.
type EncryptedPacket struct {
EncryptionAlgorithm uint32 `xml:"encryptionAlgorithm,attr,omitempty" json:"encryptionAlgorithm,omitempty"`
CWIndex uint32 `xml:"cwIndex,attr,omitempty" json:"cwIndex,omitempty"`
EncryptionAlgorithm uint32 `xml:"encryptionAlgorithm,attr" json:"encryptionAlgorithm"`
CWIndex uint32 `xml:"cwIndex,attr" json:"cwIndex"`
}

// encryptionAlgorithmName returns the user-friendly encryption algorithm name
Expand Down
53 changes: 30 additions & 23 deletions pkg/scte35/scte35_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,9 @@ func TestDecodeBase64(t *testing.T) {
},
SegmentationUPIDs: []scte35.SegmentationUPID{
{
Type: 8,
Value: "791755781",
Type: 8,
Format: scte35.SegmentationUPIDFormatText,
Value: "791755781",
},
},
SegmentationTypeID: 53,
Expand All @@ -378,8 +379,9 @@ func TestDecodeBase64(t *testing.T) {
},
SegmentationUPIDs: []scte35.SegmentationUPID{
{
Type: 8,
Value: "791755998",
Type: 8,
Format: scte35.SegmentationUPIDFormatText,
Value: "791755998",
},
},
SegmentationTypeID: 35,
Expand Down Expand Up @@ -423,16 +425,19 @@ func TestDecodeBase64(t *testing.T) {
&scte35.SegmentationDescriptor{
SegmentationUPIDs: []scte35.SegmentationUPID{
{
Type: scte35.SegmentationUPIDTypeEIDR,
Value: "10.5239/8BE5-E3F6-0000-0000-0000",
Type: scte35.SegmentationUPIDTypeEIDR,
Format: scte35.SegmentationUPIDFormatText,
Value: "10.5239/8BE5-E3F6-0000-0000-0000",
},
{
Type: scte35.SegmentationUPIDTypeEIDR,
Value: "10.5239/8BE5-E3F6-0000-0000-0000",
Type: scte35.SegmentationUPIDTypeEIDR,
Format: scte35.SegmentationUPIDFormatText,
Value: "10.5239/8BE5-E3F6-0000-0000-0000",
},
{
Type: scte35.SegmentationUPIDTypeADI,
Value: "SIGNAL:Ly9EMGxKR0hFZUtpMHdCUVZnRUFnZz1",
Type: scte35.SegmentationUPIDTypeADI,
Format: scte35.SegmentationUPIDFormatText,
Value: "SIGNAL:Ly9EMGxKR0hFZUtpMHdCUVZnRUFnZz1",
},
},
SegmentationEventID: 2,
Expand All @@ -454,6 +459,7 @@ func TestDecodeBase64(t *testing.T) {
SegmentationUPIDs: []scte35.SegmentationUPID{
{
Type: scte35.SegmentationUPIDTypeMPU,
Format: scte35.SegmentationUPIDFormatBase64,
FormatIdentifier: uint32ptr(1145656131),
Value: "WU1XRjA0NTIwMDBI",
},
Expand Down Expand Up @@ -486,8 +492,9 @@ func TestDecodeBase64(t *testing.T) {
&scte35.SegmentationDescriptor{
SegmentationUPIDs: []scte35.SegmentationUPID{
{
Type: scte35.SegmentationUPIDTypeURI,
Value: "urn:nbcuni.com:brc:499866434",
Type: scte35.SegmentationUPIDTypeURI,
Format: scte35.SegmentationUPIDFormatText,
Value: "urn:nbcuni.com:brc:499866434",
},
},
SegmentationDuration: uint64ptr(1347087),
Expand Down Expand Up @@ -546,7 +553,7 @@ func TestDecodeBase64(t *testing.T) {
DeviceRestrictions: 3,
},
SegmentationUPIDs: []scte35.SegmentationUPID{
{Type: scte35.SegmentationUPIDTypeTI, Value: "1044285552"},
{Type: scte35.SegmentationUPIDTypeTI, Format: scte35.SegmentationUPIDFormatText, Value: "1044285552"},
},
},
&scte35.SegmentationDescriptor{
Expand All @@ -559,7 +566,7 @@ func TestDecodeBase64(t *testing.T) {
DeviceRestrictions: 3,
},
SegmentationUPIDs: []scte35.SegmentationUPID{
{Type: scte35.SegmentationUPIDTypeTI, Value: "1044285552"},
{Type: scte35.SegmentationUPIDTypeTI, Format: scte35.SegmentationUPIDFormatText, Value: "1044285552"},
},
},
&scte35.SegmentationDescriptor{
Expand All @@ -572,7 +579,7 @@ func TestDecodeBase64(t *testing.T) {
DeviceRestrictions: 3,
},
SegmentationUPIDs: []scte35.SegmentationUPID{
{Type: scte35.SegmentationUPIDTypeTI, Value: "1044285622"},
{Type: scte35.SegmentationUPIDTypeTI, Format: scte35.SegmentationUPIDFormatText, Value: "1044285622"},
},
},
&scte35.SegmentationDescriptor{
Expand All @@ -586,7 +593,7 @@ func TestDecodeBase64(t *testing.T) {
DeviceRestrictions: 3,
},
SegmentationUPIDs: []scte35.SegmentationUPID{
{Type: scte35.SegmentationUPIDTypeTI, Value: "1044285622"},
{Type: scte35.SegmentationUPIDTypeTI, Format: scte35.SegmentationUPIDFormatText, Value: "1044285622"},
},
},
&scte35.SegmentationDescriptor{
Expand All @@ -602,13 +609,13 @@ func TestDecodeBase64(t *testing.T) {
DeviceRestrictions: 3,
},
SegmentationUPIDs: []scte35.SegmentationUPID{
{Type: scte35.SegmentationUPIDTypeEIDR, Value: "10.5239/F9B9-7B34-0000-0000-0000"},
{Type: scte35.SegmentationUPIDTypeADS, Value: "type=LA&dur=60000&tierü0"},
{Type: uint32(199)},
{Type: uint32(0)},
{Type: uint32(0)},
{Type: uint32(0)},
{Type: uint32(255)},
{Type: scte35.SegmentationUPIDTypeEIDR, Format: scte35.SegmentationUPIDFormatText, Value: "10.5239/F9B9-7B34-0000-0000-0000"},
{Type: scte35.SegmentationUPIDTypeADS, Format: scte35.SegmentationUPIDFormatText, Value: "type=LA&dur=60000&tierü0"},
{Type: uint32(199), Format: scte35.SegmentationUPIDFormatText},
{Type: uint32(0), Format: scte35.SegmentationUPIDFormatText},
{Type: uint32(0), Format: scte35.SegmentationUPIDFormatText},
{Type: uint32(0), Format: scte35.SegmentationUPIDFormatText},
{Type: uint32(255), Format: scte35.SegmentationUPIDFormatText},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/scte35/segmentation_descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func (sd *SegmentationDescriptor) decode(b []byte) error {
if !programSegmentationFlag {
componentCount := int(r.Uint32(8))
sd.Components = make([]SegmentationDescriptorComponent, componentCount)
for i := 0; i < componentCount; i++ {
for i := range componentCount {
c := SegmentationDescriptorComponent{}
c.Tag = r.Uint32(8)
r.Skip(7) // reserved
Expand Down
34 changes: 24 additions & 10 deletions pkg/scte35/segmentation_upid.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ const (
SegmentationUPIDTypeUUID = 0x10
// SegmentationUPIDTypeSCR is the segmentation_upid_type for SCR.
SegmentationUPIDTypeSCR = 0x11

// SegmentationUPIDFormatText is the text segmentation upid value format.
SegmentationUPIDFormatText = "text"
// SegmentationUPIDFormatHex is the hex segmentation upid value format.
SegmentationUPIDFormatHex = "hex"
// SegmentationUPIDFormatBase64 is the hex segmentation upid value format.
SegmentationUPIDFormatBase64 = "base-64"
// SegmentationUPIDFormatPrivatePrefix is the private segmentation upid value
// format.
SegmentationUPIDFormatPrivatePrefix = "private:"
)

// NewSegmentationUPID construct a new SegmentationUPID
Expand All @@ -79,47 +89,51 @@ func NewSegmentationUPID(upidType uint32, buf []byte) SegmentationUPID {
// EIDR - custom
case SegmentationUPIDTypeEIDR:
return SegmentationUPID{
Type: upidType,
Value: canonicalEIDR(r.LeftBytes()),
Type: upidType,
Format: SegmentationUPIDFormatText,
Value: canonicalEIDR(r.LeftBytes()),
}
// ISAN - base64
case SegmentationUPIDTypeISAN, SegmentationUPIDTypeISANDeprecated:
return SegmentationUPID{
Type: upidType,
Value: base64.StdEncoding.EncodeToString(r.LeftBytes()),
Type: upidType,
Format: SegmentationUPIDFormatBase64,
Value: base64.StdEncoding.EncodeToString(r.LeftBytes()),
}
// MPU - custom
case SegmentationUPIDTypeMPU:
fi := r.Uint32(32)
return SegmentationUPID{
Type: upidType,
Format: SegmentationUPIDFormatBase64,
FormatIdentifier: &fi,
Value: base64.StdEncoding.EncodeToString(r.LeftBytes()),
}
// TI - unsigned int
case SegmentationUPIDTypeTI:
return SegmentationUPID{
Type: upidType,
Value: strconv.FormatUint(r.Uint64(r.LeftBits()), 10),
Format: SegmentationUPIDFormatText,
Type: upidType,
Value: strconv.FormatUint(r.Uint64(r.LeftBits()), 10),
}
// everything else - plain text
default:
// decode troublesome Latin1 characters to their UTF8 equivalents
b, _ := charmap.ISO8859_1.NewDecoder().Bytes(r.LeftBytes())
return SegmentationUPID{
Type: upidType,
Value: string(b),
Type: upidType,
Format: SegmentationUPIDFormatText,
Value: string(b),
}
}
}

// SegmentationUPID is used to express a UPID in an XML document.
type SegmentationUPID struct {
Type uint32 `xml:"segmentationUpidType,attr" json:"segmentationUpidType"`
Format string `xml:"segmentationUpidFormat,attr,omitempty" json:"segmentationUpidFormat,omitempty"`
FormatIdentifier *uint32 `xml:"formatIdentifier,attr,omitempty" json:"formatIdentifier,omitempty"`
Value string `xml:",chardata" json:"value"`
// Deprecated: no longer used and will be removed in a future release
Format string `xml:"-" json:"-"`
}

// Name returns the name for the segmentation_upid_type.
Expand Down
1 change: 0 additions & 1 deletion pkg/scte35/splice_descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func NewSpliceDescriptor(identifier uint32, tag uint32) SpliceDescriptor {
// as a last resort, fall back to private_descriptor. This is not strictly
// compliant but allows us to deal with a wider array of quirky signals.
return &PrivateDescriptor{Identifier: identifier}

}

// SpliceDescriptor is a prototype for adding new fields to the
Expand Down
Loading
Loading