Files
engine/common/index.go
2022-02-02 10:39:39 +08:00

39 lines
632 B
Go

package common
import "time"
type Track interface {
Get(size int) (result []byte)
Put(b []byte)
}
type AVTrack interface {
Track
WriteAVCC(ts uint32, frame AVCCFrame) //写入AVCC格式的数据
Flush()
}
type BPS struct {
ts time.Time
bytes int
BPS int
}
func (bps *BPS) ComputeBPS(bytes int) {
bps.bytes += bytes
if elapse := time.Since(bps.ts).Seconds(); elapse > 1 {
bps.BPS = bps.bytes / int(elapse)
bps.ts = time.Now()
}
}
type HZ uint32
func (hz HZ) ToMini(nts uint32) uint32 {
return nts / (uint32(hz) / 1000)
}
func (hz HZ) ToNTS(mini uint32) uint32 {
return mini * (uint32(hz) / 1000)
}