github.com/puellanivis/breton@v0.2.16/lib/mpeg/ts/pcr/source.go (about)

     1  package pcr
     2  
     3  import (
     4  	"time"
     5  )
     6  
     7  // Source represents a source of PCR values.
     8  type Source struct {
     9  	t time.Time
    10  }
    11  
    12  // NewSource establishes a new PCR source that counts from the current time as of the this call.
    13  func NewSource() *Source {
    14  	return &Source{
    15  		t: time.Now(),
    16  	}
    17  }
    18  
    19  // Read sets the given PCR from this Source.
    20  func (s *Source) Read(pcr *PCR) {
    21  	// There is a possible discontinuity due to math overflow at (time.Duration(1 << 64) / 27)
    22  	// However, math says that should be at about ~21.65 years on average.
    23  	// If a stream is running for that long, this code could go haywire.
    24  	pcr.Set(time.Since(s.t))
    25  }