1 Star 0 Fork 0

Bin/media-server-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
refresher.go 978 Bytes
一键复制 编辑 原始数据 按行查看 历史
notedit 提交于 2019-12-31 15:30 . remove callback
package mediaserver
import (
"sync"
"time"
)
type Refresher struct {
period int
tracks map[string]*IncomingStreamTrack
ticker *time.Ticker
sync.Mutex
}
func NewRefresher(period int) *Refresher {
refresher := &Refresher{}
refresher.tracks = map[string]*IncomingStreamTrack{}
refresher.period = period
return refresher
}
func (r *Refresher) Add(incom *IncomingStreamTrack) {
if incom.GetMedia() == "video" {
r.Lock()
r.tracks[incom.GetID()] = incom
r.Unlock()
}
if r.ticker == nil {
r.ticker = time.NewTicker(time.Duration(r.period) * time.Millisecond)
go func() {
for _ = range r.ticker.C {
for _, track := range r.tracks {
track.Refresh()
}
}
}()
}
}
func (r *Refresher) AddStream(incoming *IncomingStream) {
for _, track := range incoming.GetTracks() {
if track.GetMedia() == "video" {
r.Add(track)
}
}
}
func (r *Refresher) Stop() {
if r.ticker != nil {
r.ticker.Stop()
r.ticker = nil
}
r.tracks = nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/huzbin/media-server-go.git
git@gitee.com:huzbin/media-server-go.git
huzbin
media-server-go
media-server-go
master

搜索帮助