mirror of
https://github.com/Monibuca/engine.git
synced 2025-10-18 22:44:42 +08:00
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package engine
|
||
|
||
import "github.com/pion/rtp"
|
||
|
||
type Track interface {
|
||
PushRTP(rtp.Packet)
|
||
GetBPS(int)
|
||
Dispose()
|
||
}
|
||
|
||
// 一定要在写入Track的协程中调用该函数,这个函数的作用是防止订阅者无限等待
|
||
func DisposeTracks(tracks ...Track) {
|
||
for _, track := range tracks {
|
||
if track != nil {
|
||
track.Dispose()
|
||
}
|
||
}
|
||
}
|
||
|
||
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
|
||
}
|
||
func (t *Track_Audio) Dispose() {
|
||
t.Buffer.Dispose()
|
||
}
|
||
|
||
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
|
||
}
|
||
func (t *Track_Video) Dispose() {
|
||
t.Buffer.Dispose()
|
||
}
|