Skip to content

Commit

Permalink
Fix nil pointer with SpliceInsert.TimeSpecifiedFlag
Browse files Browse the repository at this point in the history
* Export additional flags methods
  • Loading branch information
blahspam committed Jul 8, 2021
1 parent 6bdbb29 commit 8a53313
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 19 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions pkg/scte35/splice_insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
28 changes: 14 additions & 14 deletions pkg/scte35/splice_schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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))
Expand All @@ -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))
}
Expand All @@ -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
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/scte35/splice_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 8a53313

Please sign in to comment.