diff --git a/scte35/scte35.go b/scte35/scte35.go index 4c42e0a..fd8c590 100644 --- a/scte35/scte35.go +++ b/scte35/scte35.go @@ -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. diff --git a/scte35/segmentationdescriptor_test.go b/scte35/segmentationdescriptor_test.go index 69bff3f..28c2f33 100644 --- a/scte35/segmentationdescriptor_test.go +++ b/scte35/segmentationdescriptor_test.go @@ -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, } @@ -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) + } +}