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

Correct parsing segmentation duration with 40 bits. #178

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion scte35/scte35.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ func (s *scte35) Data() []byte {
}

func uint40(buf []byte) gots.PTS {
return (gots.PTS(buf[0]&0x1) << 32) | (gots.PTS(buf[1]) << 24) | (gots.PTS(buf[2]) << 16) | (gots.PTS(buf[3]) << 8) | (gots.PTS(buf[4]))
data := append([]byte{0, 0, 0}, buf[:5]...)
return gots.PTS(binary.BigEndian.Uint64(data))
}

// String returns a string representation of the SCTE35 message.
Expand Down
19 changes: 18 additions & 1 deletion scte35/segmentationdescriptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var network_end = []byte{
var program_start = []byte{
0x00, 0xfc, 0x30, 0x35, 0x00, 0x00, 0x00, 0x02, 0xdd, 0x20, 0x00, 0x00, 0x00, 0x05, 0x06, 0xfe,
0x00, 0x02, 0xbf, 0xd4, 0x00, 0x1f, 0x02, 0x1d, 0x43, 0x55, 0x45, 0x49, 0x00, 0x00, 0x00, 0x02,
0x7f, 0xff, 0x00, 0x09, 0xa7, 0xec, 0x80, 0x09, 0x09, 0x50, 0x72, 0x6f, 0x67, 0x53, 0x74, 0x61,
0x7f, 0xff, 0xff, 0x09, 0xa7, 0xec, 0x80, 0x09, 0x09, 0x50, 0x72, 0x6f, 0x67, 0x53, 0x74, 0x61,
0x72, 0x74, 0x10, 0x01, 0x01, 0xfd, 0xbe, 0x65, 0x8c,
}

Expand Down Expand Up @@ -270,3 +270,20 @@ func TestVSSSignalId(t *testing.T) {
t.FailNow()
}
}

func TestSegmentationDuration(t *testing.T) {
// Create a 0x10 (program start)
programStart, err := NewSCTE35(program_start)
if err != nil {
t.Error("NewSCTE35(program_start) returned err:", err.Error())
t.FailNow()
}

seg := programStart.Descriptors()[0].(*segmentationDescriptor)
seg.SetHasDuration(true)

// segmentation duration supports up to 40 bits
if expected, actual := uint64(0xff09a7ec80), uint64(seg.Duration()); expected != actual {
t.Errorf("Expected segmentation duraiont to be %v, but %v is found", expected, actual)
}
}