mirror of
https://github.com/Monibuca/engine.git
synced 2025-10-05 08:36:56 +08:00
36 lines
937 B
Go
36 lines
937 B
Go
package engine
|
|
|
|
type Track interface {
|
|
Push(uint32, []byte)
|
|
}
|
|
type Track_Audio struct {
|
|
Buffer *Ring_Audio `json:"-"`
|
|
PacketCount int
|
|
CodecID byte
|
|
BPS int
|
|
lastIndex byte
|
|
}
|
|
|
|
func (t *Track_Audio) GetBPS(payloadLen int) {
|
|
t.PacketCount++
|
|
if lastTimestamp := t.Buffer.GetAt(t.lastIndex).Timestamp; lastTimestamp > 0 && lastTimestamp != t.Buffer.Current.Timestamp {
|
|
t.BPS = payloadLen * 1000 / int(t.Buffer.Current.Timestamp-lastTimestamp)
|
|
}
|
|
t.lastIndex = t.Buffer.Index
|
|
}
|
|
|
|
type Track_Video struct {
|
|
Buffer *Ring_Video `json:"-"`
|
|
PacketCount int
|
|
CodecID byte
|
|
BPS int
|
|
lastIndex byte
|
|
}
|
|
|
|
func (t *Track_Video) GetBPS(payloadLen int) {
|
|
t.PacketCount++
|
|
if lastTimestamp := t.Buffer.GetAt(t.lastIndex).Timestamp; lastTimestamp > 0 && lastTimestamp != t.Buffer.Current.Timestamp {
|
|
t.BPS = payloadLen * 1000 / int(t.Buffer.Current.Timestamp-lastTimestamp)
|
|
}
|
|
t.lastIndex = t.Buffer.Index
|
|
} |