streaming

Media streaming and broadcast systems in Go
Log | Files | Refs | README | LICENSE

break_duration.go (781B)


      1 package scte35
      2 
      3 import (
      4 	"encoding/binary"
      5 )
      6 
      7 type BreakDuration struct {
      8 	AutoReturn bool
      9 	// Holds a number of ticks of a 90KHz clock.
     10 	Duration uint64
     11 }
     12 
     13 func packBreakDuration(b *BreakDuration) [5]byte {
     14 	var p [5]byte
     15 	if b.AutoReturn {
     16 		p[0] |= (1 << 7)
     17 	}
     18 	// toggle 6 reserved bits
     19 	p[0] |= 0b01111110
     20 	pts := toPTS(b.Duration)
     21 	// 1 bit remaining in the first byte, so pack 1 bit from the timestamp
     22 	p[0] |= pts[0]
     23 	copy(p[1:], pts[1:])
     24 	return p
     25 }
     26 
     27 func readBreakDuration(a [5]byte) *BreakDuration {
     28 	var bd BreakDuration
     29 	bd.AutoReturn = a[0]&(1<<7) > 0
     30 	a[0] &= 0x01
     31 	// first, allocate 3 empty bytes, then add the remaining 5;
     32 	// enough for the uint64 (8 bytes).
     33 	b := []byte{0, 0, 0}
     34 	b = append(b, a[:]...)
     35 	bd.Duration = binary.BigEndian.Uint64(b)
     36 	return &bd
     37 }