streaming

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

pts.go (505B)


      1 package scte35
      2 
      3 // PTS represents a presentation timestamp - the number of ticks of a
      4 // 90KHz clock - as a 33-bit field.
      5 type PTS [5]byte
      6 
      7 func toPTS(ticks uint64) [5]byte {
      8 	var p [5]byte
      9 	p[0] = byte(ticks >> 32)
     10 	// mask off 7 bits; we only want 33 total, not 40.
     11 	p[0] &= 0b00000001
     12 	p[1] = byte(ticks >> 24)
     13 	p[2] = byte(ticks >> 16)
     14 	p[3] = byte(ticks >> 8)
     15 	p[4] = byte(ticks)
     16 	return p
     17 }
     18 
     19 func putPTS(buf []byte, ticks uint64) {
     20 	pts := toPTS(ticks)
     21 	buf[0] |= pts[0]
     22 	copy(buf[1:5], pts[1:5])
     23 }