1 Star 0 Fork 0

irishcoffeeguo/RTSPtoWeb

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
storageClient.go 1.53 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"time"
"github.com/deepch/vdk/av"
)
//ClientAdd Add New Client to Translations
func (obj *StorageST) ClientAdd(streamID string, channelID string, mode int) (string, chan *av.Packet, chan *[]byte, error) {
obj.mutex.Lock()
defer obj.mutex.Unlock()
streamTmp, ok := obj.Streams[streamID]
if !ok {
return "", nil, nil, ErrorStreamNotFound
}
//Generate UUID client
cid, err := generateUUID()
if err != nil {
return "", nil, nil, err
}
chAV := make(chan *av.Packet, 2000)
chRTP := make(chan *[]byte, 2000)
channelTmp, ok := streamTmp.Channels[channelID]
if !ok {
return "", nil, nil, ErrorStreamNotFound
}
channelTmp.clients[cid] = ClientST{mode: mode, outgoingAVPacket: chAV, outgoingRTPPacket: chRTP, signals: make(chan int, 100)}
channelTmp.ack = time.Now()
streamTmp.Channels[channelID] = channelTmp
obj.Streams[streamID] = streamTmp
return cid, chAV, chRTP, nil
}
//ClientDelete Delete Client
func (obj *StorageST) ClientDelete(streamID string, cid string, channelID string) {
obj.mutex.Lock()
defer obj.mutex.Unlock()
if _, ok := obj.Streams[streamID]; ok {
delete(obj.Streams[streamID].Channels[channelID].clients, cid)
}
}
//ClientHas check is client ext
func (obj *StorageST) ClientHas(streamID string, channelID string) bool {
obj.mutex.Lock()
defer obj.mutex.Unlock()
streamTmp, ok := obj.Streams[streamID]
if !ok {
return false
}
channelTmp, ok := streamTmp.Channels[channelID]
if !ok {
return false
}
if time.Now().Sub(channelTmp.ack).Seconds() > 30 {
return false
}
return true
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/irishcoffeeguo/RTSPtoWeb.git
git@gitee.com:irishcoffeeguo/RTSPtoWeb.git
irishcoffeeguo
RTSPtoWeb
RTSPtoWeb
master

搜索帮助