-
Notifications
You must be signed in to change notification settings - Fork 3
/
ui.go
180 lines (147 loc) · 3.98 KB
/
ui.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package main
import (
"fmt"
"time"
ui "gopkg.in/gizak/termui.v2"
)
const (
uiDataListSize = 120
)
var (
videoFrameRateList = make([]float64, uiDataListSize)
videoKeyFrameRateList = make([]float64, uiDataListSize)
videoKeyFrameTagList = make([]string, uiDataListSize)
audioFrameRateList = make([]float64, uiDataListSize)
streamBandwidth = make([]float64, uiDataListSize)
processInfoPar *ui.Par
streamInfoPar *ui.Par
processLogPar *ui.Par
)
func initStreamInfoBox() (*ui.Par, *ui.Par) {
parProcess := ui.NewPar("")
parProcess.Height = 6
parProcess.BorderLabel = "Process Info"
parStream := ui.NewPar("")
parStream.Height = 6
parStream.BorderLabel = "Stream Info"
ui.Body.AddRows(
ui.NewRow(
ui.NewCol(9, 0, parStream),
ui.NewCol(3, 0, parProcess),
),
)
return parProcess, parStream
}
func initStreamLogBox() *ui.Par {
parProcess := ui.NewPar("")
parProcess.Height = 8
parProcess.BorderLabel = "Process Log"
ui.Body.AddRows(
ui.NewRow(
ui.NewCol(12, 0, parProcess),
),
)
return parProcess
}
func initAudioInfoBox() {
lcFrames := ui.NewLineChart()
lcFrames.BorderLabel = "Audio: frames"
lcFrames.Data = audioFrameRateList
lcFrames.Mode = "dot"
lcFrames.Height = 11
lcFrames.AxesColor = ui.ColorWhite
lcFrames.LineColor = ui.ColorYellow | ui.AttrBold
lcKeyFrames := ui.NewLineChart()
lcKeyFrames.BorderLabel = "Bandwidth: Mbps"
lcKeyFrames.Data = streamBandwidth
lcKeyFrames.Mode = "dot"
lcKeyFrames.Height = 11
lcKeyFrames.AxesColor = ui.ColorWhite
lcKeyFrames.LineColor = ui.ColorYellow | ui.AttrBold
ui.Body.AddRows(
ui.NewRow(
ui.NewCol(6, 0, lcFrames),
ui.NewCol(6, 0, lcKeyFrames),
),
)
}
func initVideoInfoBox() {
lcFrames := ui.NewLineChart()
lcFrames.BorderLabel = "Video: frames"
lcFrames.Data = videoFrameRateList
lcFrames.Mode = "dot"
lcFrames.Height = 11
lcFrames.AxesColor = ui.ColorWhite
lcFrames.LineColor = ui.ColorYellow | ui.AttrBold
lcKeyFrames := ui.NewLineChart()
lcKeyFrames.BorderLabel = "Video: key frames"
lcKeyFrames.Data = videoKeyFrameRateList
lcKeyFrames.Height = 11
lcKeyFrames.AxesColor = ui.ColorWhite
lcKeyFrames.LineColor = ui.ColorYellow
ui.Body.AddRows(
ui.NewRow(
ui.NewCol(6, 0, lcFrames),
ui.NewCol(6, 0, lcKeyFrames),
),
)
}
func updateUI(curInfo, lastInfo *streamInfo) {
// process info
if !curInfo.ProcessStartTime.IsZero() {
processInfoPar.Text = fmt.Sprintf("%s\n\nStart on: %s\nDuration: %s",
time.Now().Format(time.Stamp),
curInfo.ProcessStartTime.Format(time.Stamp),
time.Now().Sub(curInfo.ProcessStartTime))
}
streamInfoPar.Text = curInfo.StreamInfo
processLogPar.Text = curInfo.AnalyzingLog
vFPS := float64(curInfo.VideoFrames - lastInfo.VideoFrames)
vKFPS := float64(curInfo.VideoKeyFrames - lastInfo.VideoKeyFrames)
aFPS := float64(curInfo.AudioFrames - lastInfo.AudioFrames)
streamBW := float64(curInfo.ReceivedSize-lastInfo.ReceivedSize) / 1024 / 1024 * 8
for i := uiDataListSize - 1; i >= 2; i-- {
videoFrameRateList[i] = videoFrameRateList[i-1]
videoKeyFrameRateList[i] = videoKeyFrameRateList[i-1]
audioFrameRateList[i] = audioFrameRateList[i-1]
streamBandwidth[i] = streamBandwidth[i-1]
}
videoFrameRateList[1] = vFPS
videoKeyFrameRateList[1] = vKFPS
audioFrameRateList[1] = aFPS
streamBandwidth[1] = streamBW
ui.Render(ui.Body)
}
func streamInfoRecv(streamInfoChan chan *streamInfo) {
lastInfo := streamInfo{}
curInfo := streamInfo{}
ticker := time.NewTicker(time.Second)
for {
select {
case sInfo := <-streamInfoChan:
curInfo = *sInfo
case <-ticker.C:
updateUI(&curInfo, &lastInfo)
lastInfo = curInfo
}
}
}
func drawUI(streamInfoChan chan *streamInfo) {
go streamInfoRecv(streamInfoChan)
err := ui.Init()
if err != nil {
panic(err)
}
defer ui.Close()
ui.Handle("/sys/kbd/q", func(ui.Event) {
// press q to quit
ui.StopLoop()
})
processInfoPar, streamInfoPar = initStreamInfoBox()
initVideoInfoBox()
initAudioInfoBox()
processLogPar = initStreamLogBox()
ui.Body.Align()
ui.Render(ui.Body)
ui.Loop()
}