Skip to content

Commit

Permalink
A signaling server for GB28181
Browse files Browse the repository at this point in the history
  • Loading branch information
duiniuluantanqin committed Apr 3, 2024
1 parent 3646272 commit 27f5cd2
Show file tree
Hide file tree
Showing 7 changed files with 334 additions and 226 deletions.
34 changes: 34 additions & 0 deletions trunk/3rdparty/gb28181-server/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get

# Main package
MAIN=main.go

# Server package
SERVER_DIR=gbserver
SERVER_SRC=$(wildcard $(SERVER_DIR)/*.go)
SERVER_OBJ=$(patsubst %.go,objs/%.o,$(SERVER_SRC))

# Build targets
all: build

build:
$(GOBUILD) -o objs/main $(MAIN)
@mkdir -p objs/$(SERVER_DIR)
$(GOBUILD) -o objs/$(SERVER_DIR)/server $(SERVER_SRC)

clean:
$(GOCLEAN)
rm -rf objs

run:
$(GOBUILD) -o objs/main $(MAIN)
@mkdir -p objs/$(SERVER_DIR)
$(GOBUILD) -o objs/$(SERVER_DIR)/server $(SERVER_SRC)
./objs/main

.PHONY: all build clean run
56 changes: 0 additions & 56 deletions trunk/3rdparty/gb28181-server/device.go

This file was deleted.

73 changes: 73 additions & 0 deletions trunk/3rdparty/gb28181-server/gbserver/device.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package gbserver

import "sync"

type ChannelInfo struct {
DeviceID string // 通道ID
ParentID string
Name string
Manufacturer string
Model string
Owner string
CivilCode string
Address string
Port int
Parental int
SafetyWay int
RegisterWay int
Secrecy int
Status ChannelStatus
}

type ChannelStatus string

type DeviceInfo struct {
DeviceID string
SourceAddr string
ChannelList []ChannelInfo
}

var Devices sync.Map

func (s *GB28181Server) AddDevice(id string, sourceAddr string) {
Devices.Store(id, DeviceInfo{
DeviceID: id,
SourceAddr: sourceAddr,
})
}

func (s *GB28181Server) RemoveDevice(id string) {
Devices.Delete(id)
}

func (s *GB28181Server) GetDevice(id string) (DeviceInfo, bool) {
v, ok := Devices.Load(id)
if !ok {
return DeviceInfo{}, false
}
return v.(DeviceInfo), true
}

func (s *GB28181Server) UpdateChannels(list ...ChannelInfo) {
for _, channel := range list {
if info, ok := s.GetDevice(channel.ParentID); ok {
info.ChannelList = append(info.ChannelList, channel)
Devices.Store(channel.DeviceID, info)
}
}
}

func (s *GB28181Server) GetDeviceByChannel(channelID string) (DeviceInfo, bool) {
var result DeviceInfo
Devices.Range(func(key, value interface{}) bool {
info := value.(DeviceInfo)
for _, channel := range info.ChannelList {
if channel.DeviceID == channelID {
result = info
return false
}
}
return true
})
return result, result.DeviceID != ""
}
Loading

0 comments on commit 27f5cd2

Please sign in to comment.