From 8a53313d733bb5600a5ab856d4d4ac76052a8128 Mon Sep 17 00:00:00 2001 From: Jeff Date: Thu, 8 Jul 2021 08:16:39 -0700 Subject: [PATCH] Fix nil pointer with SpliceInsert.TimeSpecifiedFlag * Export additional flags methods --- CHANGELOG.md | 10 ++++++++++ pkg/scte35/splice_insert.go | 10 +++++----- pkg/scte35/splice_schedule.go | 28 ++++++++++++++-------------- pkg/scte35/splice_time.go | 5 +++++ 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17a1b0f1d..d146603ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +## [1.2.0] - 2021-07-07 + +### Fixed + +* Fixed nil pointer in `SpliceInsert.TimeSpecifiedFlag` + +### Added + +* Added additional methods for computing `_flag` values. + ## [1.1.0] - 2021-07-07 ### Added diff --git a/pkg/scte35/splice_insert.go b/pkg/scte35/splice_insert.go index 3e35b1657..1d990554b 100644 --- a/pkg/scte35/splice_insert.go +++ b/pkg/scte35/splice_insert.go @@ -58,7 +58,7 @@ func (cmd *SpliceInsert) ProgramSpliceFlag() bool { // TimeSpecifiedFlag returns the time_specified_flag func (cmd *SpliceInsert) TimeSpecifiedFlag() bool { - return cmd.Program == nil && cmd.Program.SpliceTime.PTSTime != nil + return cmd != nil && cmd.Program != nil && cmd.Program.SpliceTime.TimeSpecifiedFlag() } // Type returns the splice_command_type. @@ -188,7 +188,7 @@ func (cmd *SpliceInsert) encode() ([]byte, error) { iow.PutBit(cmd.SpliceImmediateFlag) iow.PutUint32(4, Reserved) if cmd.ProgramSpliceFlag() && !cmd.SpliceImmediateFlag { - if cmd.Program.timeSpecifiedFlag() { + if cmd.Program.TimeSpecifiedFlag() { iow.PutBit(true) iow.PutUint32(6, Reserved) iow.PutUint64(33, *cmd.Program.SpliceTime.PTSTime) @@ -246,7 +246,7 @@ func (cmd SpliceInsert) length() int { length++ // time_specified_flag // if time_specified_flag == 1 - if cmd.Program.timeSpecifiedFlag() { + if cmd.Program.TimeSpecifiedFlag() { length += 6 // reserved length += 33 // pts_time } else { @@ -317,7 +317,7 @@ type SpliceInsertProgram struct { SpliceTime SpliceTime `xml:"http://www.scte.org/schemas/35 SpliceTime" json:"spliceTime"` } -// timeSpecifiedFlag returns the time_specified_flag. -func (p *SpliceInsertProgram) timeSpecifiedFlag() bool { +// TimeSpecifiedFlag returns the time_specified_flag. +func (p *SpliceInsertProgram) TimeSpecifiedFlag() bool { return p != nil && p.SpliceTime.PTSTime != nil } diff --git a/pkg/scte35/splice_schedule.go b/pkg/scte35/splice_schedule.go index 1222900df..f15057c2e 100644 --- a/pkg/scte35/splice_schedule.go +++ b/pkg/scte35/splice_schedule.go @@ -105,10 +105,10 @@ func (cmd *SpliceSchedule) encode() ([]byte, error) { iow.PutUint32(7, Reserved) // reserved if !e.SpliceEventCancelIndicator { iow.PutBit(e.OutOfNetworkIndicator) - iow.PutBit(e.programSpliceFlag()) - iow.PutBit(e.durationFlag()) + iow.PutBit(e.ProgramSpliceFlag()) + iow.PutBit(e.DurationFlag()) iow.PutUint32(5, Reserved) // reserved - if e.programSpliceFlag() { + if e.ProgramSpliceFlag() { iow.PutUint32(32, e.Program.UTCSpliceTime.GPSSeconds()) } else { iow.PutUint32(8, uint32(len(e.Components))) @@ -117,7 +117,7 @@ func (cmd *SpliceSchedule) encode() ([]byte, error) { iow.PutUint32(32, c.UTCSpliceTime.GPSSeconds()) } } - if e.durationFlag() { + if e.DurationFlag() { iow.PutBit(e.BreakDuration.AutoReturn) iow.PutUint32(6, Reserved) iow.PutUint64(33, e.BreakDuration.Duration) @@ -150,7 +150,7 @@ func (cmd SpliceSchedule) length() int { length++ // duration_flag length += 5 // reserved - if e.programSpliceFlag() { + if e.ProgramSpliceFlag() { // program_splice_flag == 1 length += 32 // utc_splice_time } else { @@ -163,7 +163,7 @@ func (cmd SpliceSchedule) length() int { } // if duration_flag == 1 - if e.durationFlag() { + if e.DurationFlag() { length++ // auto_return length += 6 // reserved length += 33 // duration @@ -189,9 +189,9 @@ func (cmd *SpliceSchedule) table(prefix, indent string) string { _, _ = fmt.Fprintln(&b, prefix+indent+indent+"splice_event_cancel_indicator: %v\n", e.SpliceEventCancelIndicator) if !e.SpliceEventCancelIndicator { _, _ = fmt.Fprintln(&b, prefix+indent+indent+"out_of_network_indicator: %v\n", e.OutOfNetworkIndicator) - _, _ = fmt.Fprintln(&b, prefix+indent+indent+"program_splice_flag: %v\n", e.programSpliceFlag()) - _, _ = fmt.Fprintln(&b, prefix+indent+indent+"duration_flag: %v", e.durationFlag()) - if e.programSpliceFlag() { + _, _ = fmt.Fprintln(&b, prefix+indent+indent+"program_splice_flag: %v\n", e.ProgramSpliceFlag()) + _, _ = fmt.Fprintln(&b, prefix+indent+indent+"duration_flag: %v", e.DurationFlag()) + if e.ProgramSpliceFlag() { _, _ = fmt.Fprintln(&b, prefix+indent+indent+"utc_splice_time: %s\n", e.Program.UTCSpliceTime.Format(time.RFC3339)) } else { _, _ = fmt.Fprintln(&b, prefix+indent+indent+"component_count: %d\n", len(e.Components)) @@ -202,7 +202,7 @@ func (cmd *SpliceSchedule) table(prefix, indent string) string { _, _ = fmt.Fprintln(&b, prefix+indent+indent+"}\n") } } - if e.durationFlag() { + if e.DurationFlag() { _, _ = fmt.Fprintln(&b, prefix+indent+indent+"auto_return: %v\n", e.BreakDuration.AutoReturn) _, _ = fmt.Fprintln(&b, prefix+indent+indent+"duration: %d ticks (%s)\n", e.BreakDuration.Duration, TicksToDuration(e.BreakDuration.Duration)) } @@ -229,13 +229,13 @@ type Event struct { AvailsExpected uint32 `xml:"availsExpected,attr" json:"availsExpected,omitempty"` } -// durationFlag returns the duration_flag. -func (e *Event) durationFlag() bool { +// DurationFlag returns the duration_flag. +func (e *Event) DurationFlag() bool { return e != nil && e.BreakDuration != nil } -// programSpliceFlag returns the program_splice_flag. -func (e *Event) programSpliceFlag() bool { +// ProgramSpliceFlag returns the program_splice_flag. +func (e *Event) ProgramSpliceFlag() bool { return e != nil && e.Program != nil } diff --git a/pkg/scte35/splice_time.go b/pkg/scte35/splice_time.go index ecdd99fd6..cbb748275 100644 --- a/pkg/scte35/splice_time.go +++ b/pkg/scte35/splice_time.go @@ -20,3 +20,8 @@ package scte35 type SpliceTime struct { PTSTime *uint64 `xml:"ptsTime,attr" json:"ptsTime,omitempty"` } + +// TimeSpecifiedFlag returns true if PTSTime is not nil. +func (t *SpliceTime) TimeSpecifiedFlag() bool { + return t != nil && t.PTSTime != nil +}