-
Notifications
You must be signed in to change notification settings - Fork 199
/
base.go
88 lines (75 loc) · 1.71 KB
/
base.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package track
import (
"time"
"go.uber.org/zap"
"m7s.live/engine/v4/common"
"m7s.live/engine/v4/log"
"m7s.live/engine/v4/util"
)
// Base 基础Track类
type Base[T any, F util.IDataFrame[T]] struct {
util.RingWriter[T, F]
Name string
log.Zap `json:"-" yaml:"-"`
Publisher common.IPuber `json:"-" yaml:"-"` //所属发布者
State common.TrackState
ts time.Time
bytes int
frames int
DropCount int `json:"-" yaml:"-"` //丢帧数
BPS int
FPS int
Drops int // 丢帧率
RawSize int // 裸数据长度
RawPart []int // 裸数据片段用于UI上显示
}
func (bt *Base[T, F]) ComputeBPS(bytes int) {
bt.bytes += bytes
bt.frames++
if elapse := time.Since(bt.ts).Seconds(); elapse > 1 {
bt.BPS = int(float64(bt.bytes) / elapse)
bt.FPS = int(float64(bt.frames) / elapse)
bt.Drops = int(float64(bt.DropCount) / elapse)
bt.bytes = 0
bt.frames = 0
bt.DropCount = 0
bt.ts = time.Now()
}
}
func (bt *Base[T, F]) GetName() string {
return bt.Name
}
func (bt *Base[T, F]) GetBPS() int {
return bt.BPS
}
func (bt *Base[T, F]) GetFPS() int {
return bt.FPS
}
func (bt *Base[T, F]) GetDrops() int {
return bt.Drops
}
// GetRBSize 获取缓冲区大小
func (bt *Base[T, F]) GetRBSize() int {
return bt.RingWriter.Size
}
func (bt *Base[T, F]) SnapForJson() {
}
func (bt *Base[T, F]) SetStuff(stuff ...any) {
for _, s := range stuff {
switch v := s.(type) {
case common.IPuber:
bt.Publisher = v
bt.Zap = v.With(zap.String("track", bt.Name))
case common.TrackState:
bt.State = v
case string:
bt.Name = v
}
}
}
func (bt *Base[T, F]) GetPublisher() common.IPuber {
return bt.Publisher
}
func (bt *Base[T, F]) Dispose() {
bt.Value.Broadcast()
}