gbs

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2026 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NotifyMethodUserActive 设备活跃状态通知
	NotifyMethodDevicesActive = "devices.active"
	// NotifyMethodUserRegister 设备注册通知
	NotifyMethodDevicesRegister = "devices.regiester"
	// NotifyMethodDeviceActive 通道活跃通知
	NotifyMethodChannelsActive = "channels.active"
	// NotifyMethodRecordStop 视频录制结束
	NotifyMethodRecordStop = "records.stop"
)
View Source
const CMDTypeConfigDownload = "ConfigDownload"

Variables

View Source
var (
	ErrXMLDecode = errors.New("xml decode error")
	ErrDatabase  = errors.New("database error")
)
View Source
var (
	ErrDeviceNotExist  = errors.New("device not exist")
	ErrChannelNotExist = errors.New("channel not exist")

	ErrDeviceOffline  = errors.New("device offline")
	ErrChannelOffline = errors.New("channel offline")
)
View Source
var MODDEBUG = "DEBUG"

MODDEBUG MODDEBUG

View Source
var RecordList apiRecordList

key:ssrc value=channel 记录流录制

View Source
var StreamList streamsList

Functions

func CheckStreams

func CheckStreams()

定时检查未关闭的流 检查规则: 1. 数据库查询当前status=0在推流状态的所有流信息 2. 比对当前streamlist中存在的流,如果不在streamlist或者ssrc与channelid不匹配则关闭

func ClearFiles

func ClearFiles()

func GetIP

func GetIP(input string) (string, error)

GetIP 判断输入字符串并返回对应的IP地址 输入可能是IPv4地址、域名、空值或其他非法值

func LoadSYSInfo

func LoadSYSInfo()

func NewBasicParamRequest

func NewBasicParamRequest(sn int32, deviceID string) []byte

func SipStopPlay

func SipStopPlay(ssrc string)

sip 停止播放

func SyncDevicesCodec

func SyncDevicesCodec(ssrc, deviceid string)

同步摄像头编码格式

Types

type ActiveDevices

type ActiveDevices struct {
	sync.Map
}

ActiveDevices 记录当前活跃设备,请求播放时设备必须处于活跃状态

func (*ActiveDevices) Get

func (a *ActiveDevices) Get(key string) (Devices, bool)

Get Get

type BasicParam

type BasicParam struct {
	Name              string `xml:"Name"`              // 设备名称
	Expiration        int    `xml:"Expiration"`        // 注册过期时间
	HeartBeatInterval int    `xml:"HeartBeatInterval"` // 心跳间隔时间
	HeartBeatCount    int    `xml:"HeartBeatCount"`    // 心跳超时次数
}

BasicParam 设备基本参数配置

type Channel

type Channel struct {
	ChannelID string
	// contains filtered or unexported fields
}

func (*Channel) Conn

func (c *Channel) Conn() sip.Connection

Conn implements Targeter.

func (*Channel) Source

func (c *Channel) Source() net.Addr

Source implements Targeter.

func (*Channel) To

func (c *Channel) To() *sip.Address

To implements Targeter.

type Channels

type Channels struct {
	// db.DBModel
	// ChannelID 通道编码
	ChannelID string `xml:"DeviceID" json:"channelid" gorm:"column:channelid"`
	// DeviceID 设备编号
	DeviceID string `xml:"-" json:"deviceid"  gorm:"column:deviceid"`
	// Memo 备注(用来标示通道信息)
	MeMo string `json:"memo"  gorm:"column:memo"`
	// Name 通道名称(设备端设置名称)
	Name         string `xml:"Name" json:"name"  gorm:"column:name"`
	Manufacturer string `xml:"Manufacturer" json:"manufacturer"  gorm:"column:manufacturer"`
	Model        string `xml:"Model" json:"model"  gorm:"column:model"`
	Owner        string `xml:"Owner"  json:"owner"  gorm:"column:owner"`
	CivilCode    string `xml:"CivilCode" json:"civilcode"  gorm:"column:civilcode"`
	// Address ip地址
	Address     string `xml:"Address"  json:"address"  gorm:"column:address"`
	Parental    int    `xml:"Parental"  json:"parental"  gorm:"column:parental"`
	SafetyWay   int    `xml:"SafetyWay"  json:"safetyway"  gorm:"column:safetyway"`
	RegisterWay int    `xml:"RegisterWay"  json:"registerway"  gorm:"column:registerway"`
	Secrecy     int    `xml:"Secrecy" json:"secrecy"  gorm:"column:secrecy"`
	// Status 状态  on 在线
	Status string `xml:"Status"  json:"status"  gorm:"column:status"`
	// Active 最后活跃时间
	Active int64  `json:"active"  gorm:"column:active"`
	URIStr string ` json:"uri"  gorm:"column:uri"`

	// 视频编码格式
	VF string ` json:"vf"  gorm:"column:vf"`
	// 视频高
	Height int `json:"height"  gorm:"column:height"`
	// 视频宽
	Width int `json:"width"  gorm:"column:width"`
	// 视频FPS
	FPS int `json:"fps"  gorm:"column:fps"`
	//  pull 媒体服务器主动拉流,push 监控设备主动推流
	StreamType string `json:"streamtype"  gorm:"column:streamtype"`
	// streamtype=pull时,拉流地址
	URL string `json:"url"  gorm:"column:url"`
	// contains filtered or unexported fields
}

Channels 摄像头通道信息

type ConfigDownloadRequest

type ConfigDownloadRequest struct {
	XMLName        xml.Name  `xml:"Query"`
	CmdType        string    `xml:"CmdType"`    // 命令类型:设备配置查询(必选)
	SN             int32     `xml:"SN"`         // 命令序列号(必选)
	DeviceID       string    `xml:"DeviceID"`   // 目标设备编码(必选)
	ConfigType     string    `xml:"ConfigType"` // 查询配置参数类型(必选)
	SnapShotConfig *SnapShot `xml:"SnapShotConfig"`
}

type ConfigDownloadResponse

type ConfigDownloadResponse struct {
	XMLName    xml.Name    `xml:"Response"`
	CmdType    string      `xml:"CmdType"`
	SN         int         `xml:"SN"`
	DeviceID   string      `xml:"DeviceID"`
	Result     string      `xml:"Result"`
	BasicParam *BasicParam `xml:"BasicParam"`
	// VideoParamOpt       *VideoParamOpt       `xml:"VideoParamOpt"`
	// SVACEncodeConfig    *SVACEncodeConfig    `xml:"SVACEncodeConfig"`
	// SVACDecodeConfig    *SVACDecodeConfig    `xml:"SVACDecodeConfig"`
	// VideoParamAttribute *VideoParamAttribute `xml:"VideoParamAttribute"`
	// VideoRecordPlan     *VideoRecordPlan     `xml:"VideoRecordPlan"`
	// VideoAlarmRecord    *VideoAlarmRecord    `xml:"VideoAlarmRecord"`
	// PictureMask         *PictureMask         `xml:"PictureMask"`
	// FrameMirror         *FrameMirror         `xml:"FrameMirror"`
	// AlarmReport         *AlarmReport         `xml:"AlarmReport"`
	// OSDConfig           *OSDConfig           `xml:"OSDConfig"`
	SnapShot *SnapShot `xml:"SnapShot"`
}

type Device

type Device struct {
	Channels conc.Map[string, *Channel]

	IsOnline bool
	Address  string
	Password string

	LastKeepaliveAt time.Time
	LastRegisterAt  time.Time
	Expires         int
	// contains filtered or unexported fields
}

func NewDevice

func NewDevice(conn sip.Connection, d *ipc.Device) *Device

func (*Device) CheckConnection

func (d *Device) CheckConnection() error

CheckConnection 检查 udp 设备能否通信

func (*Device) Conn

func (d *Device) Conn() sip.Connection

Conn implements Targeter.

func (*Device) GetChannel

func (c *Device) GetChannel(channelID string) (*Channel, bool)

func (*Device) LoadChannels

func (d *Device) LoadChannels(channels ...*ipc.Channel)

func (*Device) Source

func (d *Device) Source() net.Addr

Source implements Targeter.

func (*Device) To

func (d *Device) To() *sip.Address

To implements Targeter.

type DeviceConfigRequest

type DeviceConfigRequest struct {
	XMLName        xml.Name  `xml:"Control"`
	CmdType        string    `xml:"CmdType"`  // 命令类型:设备配置查询(必选)
	SN             int32     `xml:"SN"`       // 命令序列号(必选)
	DeviceID       string    `xml:"DeviceID"` // 目标设备编码(必选)
	SnapShotConfig *SnapShot `xml:"SnapShotConfig"`
}

设备配置 A.2.3.2.1

func NewDeviceConfig

func NewDeviceConfig(deviceID string) *DeviceConfigRequest

func (*DeviceConfigRequest) Marshal

func (d *DeviceConfigRequest) Marshal() []byte

func (*DeviceConfigRequest) SetSN

func (*DeviceConfigRequest) SetSnapShotConfig

func (d *DeviceConfigRequest) SetSnapShotConfig(snapShot *SnapShot) *DeviceConfigRequest

type Devices

type Devices struct {
	// db.DBModel
	// Name 设备名称
	Name string `json:"name" gorm:"column:name" `
	// DeviceID 设备id
	DeviceID string `json:"deviceid" gorm:"column:deviceid"`
	// Region 设备域
	Region string `json:"region" gorm:"column:region"`
	// Host Via 地址
	Host string `json:"host" gorm:"column:host"`
	// Port via 端口
	Port string `json:"port" gorm:"column:port"`
	// TransPort via transport
	TransPort string `json:"transport" gorm:"column:transport"`
	// Proto 协议
	Proto string `json:"proto" gorm:"column:proto"`
	// Rport via rport
	Rport string `json:"report" gorm:"column:report"`
	// RAddr via recevied
	RAddr string `json:"raddr"  gorm:"column:raddr"`
	// Manufacturer 制造厂商
	Manufacturer string `xml:"Manufacturer"  json:"manufacturer"  gorm:"column:manufacturer"`
	// 设备类型DVR,NVR
	DeviceType string `xml:"DeviceType"  json:"devicetype"  gorm:"column:devicetype"`
	// Firmware 固件版本
	Firmware string ` json:"firmware"  gorm:"column:firmware"`
	// Model 型号
	Model  string `json:"model"  gorm:"column:model"`
	URIStr string `json:"uri"  gorm:"column:uri"`
	// ActiveAt 最后心跳检测时间
	ActiveAt int64 `json:"active" gorm:"column:active"`
	// Regist 是否注册
	Regist bool `json:"regist"  gorm:"column:regist"`
	// PWD 密码
	PWD string `json:"pwd" gorm:"column:pwd"`
	// Source
	Source string `json:"source"  gorm:"column:source"`

	Sys m.SysInfo `json:"sysinfo" gorm:"-"`

	Expire string `json:"-"`
	// contains filtered or unexported fields
}

Devices NVR 设备信息

type Files

type Files struct {
	// db.DBModel
	Start  int64  `json:"start" bson:"start"`
	End    int64  `json:"end" bson:"end"`
	Stream string `json:"stream" bson:"stream"`
	FID    string `json:"fid" bson:"fid"`
	Status int    `json:"status" bson:"status"`
	File   string `json:"file" bson:"file"`
	Clear  bool   `json:"clear" bson:"clear"`
	// contains filtered or unexported fields
}

Files Files

type GB28181API

type GB28181API struct {
	// contains filtered or unexported fields
}

func NewGB28181API

func NewGB28181API(cfg *conf.Bootstrap, store ipc.Adapter, sms *sms.NodeManager) *GB28181API

func (*GB28181API) Play

func (g *GB28181API) Play(in *PlayInput) error

func (*GB28181API) QueryCatalog

func (g *GB28181API) QueryCatalog(deviceID string) error

QueryCatalog 设备目录查询或订阅请求 GB/T28181 81 页 A.2.4.3

func (*GB28181API) QueryConfigDownloadBasic

func (g *GB28181API) QueryConfigDownloadBasic(deviceID string) error

func (GB28181API) QueryDeviceInfo

func (g GB28181API) QueryDeviceInfo(ctx *sip.Context)

QueryDeviceInfo 设备信息查询请求 GB/T28181 81 页 A.2.4.4

func (*GB28181API) QuerySnapshot

func (g *GB28181API) QuerySnapshot(deviceID, channelID string) error

func (*GB28181API) StopPlay

func (g *GB28181API) StopPlay(ctx context.Context, in *StopPlayInput) error

StopPlay 加锁的停止播放

type MemoryStorer

type MemoryStorer interface {
	LoadOrStore(deviceID string, value *Device)
	LoadDeviceToMemory(conn sip.Connection)               // 加载设备到内存
	RangeDevices(fn func(key string, value *Device) bool) // 遍历设备

	Change(deviceID string, changeFn func(*ipc.Device) error, changeFn2 func(*Device)) error // 登出设备

	Load(deviceID string) (*Device, bool)
	Store(deviceID string, value *Device)
	GetChannel(deviceID, channelID string) (*Channel, bool)
}

type MessageDeviceInfoResponse

type MessageDeviceInfoResponse struct {
	CmdType      string `xml:"CmdType"`
	SN           int    `xml:"SN"`
	DeviceID     string `xml:"DeviceID"`     // 目标设备的编码(必选)
	DeviceName   string `xml:"DeviceName"`   // 目标设备的名称(可选
	Manufacturer string `xml:"Manufacturer"` // 设备生产商(可选)
	Model        string `xml:"Model"`        // 设备型号(可选)
	Firmware     string `xml:"Firmware"`     // 设备固件版本(可选)
	Result       string `xml:"Result"`       // 査询结果(必选)
}

MessageDeviceInfoResponse 设备信息查询应答结构

type MessageDeviceListResponse

type MessageDeviceListResponse struct {
	XMLName  xml.Name   `xml:"Response"`
	CmdType  string     `xml:"CmdType"`
	SN       int        `xml:"SN"`
	DeviceID string     `xml:"DeviceID"`
	SumNum   int        `xml:"SumNum"`
	Item     []Channels `xml:"DeviceList>Item"`
}

MessageDeviceListResponse 设备明细列表返回结构

type MessageNotify

type MessageNotify struct {
	CmdType  string `xml:"CmdType"`
	SN       int    `xml:"SN"`
	DeviceID string `xml:"DeviceID"`
	Status   string `xml:"Status"`
	Info     string `xml:"Info"`
}

MessageNotify 心跳包xml结构

type MessageRecordInfoResponse

type MessageRecordInfoResponse struct {
	CmdType  string       `xml:"CmdType"`
	SN       int          `xml:"SN"`
	DeviceID string       `xml:"DeviceID"`
	SumNum   int          `xml:"SumNum"`
	Item     []RecordItem `xml:"RecordList>Item"`
}

MessageRecordInfoResponse 目录列表

type Notify

type Notify struct {
	Method string `json:"method"`
	Data   any    `json:"data"`
}

Notify 消息通知结构

type PlayInput

type PlayInput struct {
	Channel    *ipc.Channel
	SMS        *sms.MediaServer
	StreamMode int8
}

type RecordDate

type RecordDate struct {
	// 日期
	Date string `json:"date"`
	// 时间段
	Items []RecordInfo `json:"items"`
}

type RecordInfo

type RecordInfo struct {
	Start int64 `json:"start" bson:"start"`
	End   int64 `json:"end" bson:"end"`
}

type RecordItem

type RecordItem struct {
	// DeviceID 设备编号
	DeviceID string `xml:"DeviceID" bson:"DeviceID" json:"DeviceID"`
	// Name 设备名称
	Name      string `xml:"Name" bson:"Name" json:"Name"`
	FilePath  string `xml:"FilePath" bson:"FilePath" json:"FilePath"`
	Address   string `xml:"Address" bson:"Address" json:"Address"`
	StartTime string `xml:"StartTime" bson:"StartTime" json:"StartTime"`
	EndTime   string `xml:"EndTime" bson:"EndTime" json:"EndTime"`
	Secrecy   int    `xml:"Secrecy" bson:"Secrecy" json:"Secrecy"`
	Type      string `xml:"Type" bson:"Type" json:"Type"`
}

RecordItem 目录详情

type Records

type Records struct {
	// 存在录像的天数
	DayTotal int          `json:"daynum"`
	TimeNum  int          `json:"timenum"`
	Data     []RecordDate `json:"list"`
}

Records Records

func SipRecordList

func SipRecordList(to *Channels, start, end int64) (*Records, error)

获取录像文件列表

type RequestOption

type RequestOption func(*sip.Request)

type Server

type Server struct {
	*sip.Server
	// contains filtered or unexported fields
}

func NewServer

func NewServer(cfg *conf.Bootstrap, store ipc.Adapter, sc sms.Core) (*Server, func())

func (*Server) Play

func (s *Server) Play(in *PlayInput) error

func (*Server) QueryCatalog

func (s *Server) QueryCatalog(deviceID string) error

QueryCatalog 查询 catalog

func (*Server) QuerySnapshot

func (s *Server) QuerySnapshot(deviceID, channelID string) error

QuerySnapshot 厂商实现抓图的少,sip 层已实现,先搁置

func (*Server) SetConfig added in v1.3.0

func (s *Server) SetConfig()

SetConfig 热更新 SIP 配置,用于配置变更时更新 from 地址而无需重启服务

func (*Server) StopPlay

func (s *Server) StopPlay(ctx context.Context, in *StopPlayInput) error

type SnapShot

type SnapShot struct {
	SnapNum   int    `xml:"SnapNum"`   // 连拍张数(必选),最多10张,当手动抓拍时,取值为1
	Interval  int    `xml:"Interval"`  // 单张抓拍间隔时间,单位:秒(必选),取值范围:最短1秒
	UploadURL string `xml:"UploadURL"` // 抓拍图像上传路径(必选)
	SessionID string `xml:"SessionID"` // 会话ID,由平台生成,用于关联抓拍的图像与平台请求(必选)
}

type StopPlayInput

type StopPlayInput struct {
	Channel *ipc.Channel
}

type Streams

type Streams struct {
	// 0  直播 1 历史
	T int `json:"t" gorm:"column:t"`
	// 设备ID
	DeviceID string `json:"deviceid" gorm:"column:deviceid"`
	// 通道ID
	ChannelID string `json:"channelid" gorm:"column:channelid"`
	//  pull 媒体服务器主动拉流,push 监控设备主动推流
	StreamType string `json:"streamtype" gorm:"column:streamtype"`
	// 0正常 1关闭 -1 尚未开始
	Status int `json:"status" gorm:"column:status"`
	// header from params
	// Ftag db.M `gorm:"column:ftag" sql:"type:json" json:"-"`
	// header to params
	// Ttag db.M `gorm:"column:ttag" sql:"type:json" json:"-"`
	// header callid
	CallID string `json:"callid" gorm:"column:callid"`
	// 是否停止
	Stop   bool   `json:"stop" gorm:"column:stop"`
	Msg    string `json:"msg" gorm:"column:msg"`
	CseqNo uint32 `json:"cseqno" gorm:"column:cseqno"`
	// 视频流ID gb28181的ssrc
	StreamID string `json:"streamid"  gorm:"column:streamid"`
	// m3u8播放地址
	HTTP string `json:"http" gorm:"column:http"`
	// rtmp 播放地址
	RTMP string `json:"rtmp" gorm:"column:rtmp"`
	// rtsp 播放地址
	RTSP string `json:"rtsp" gorm:"column:rtsp"`
	// flv 播放地址
	WSFLV string `json:"wsflv" gorm:"column:wsflv"`
	// zlm是否收到流
	Stream bool `json:"stream" gorm:"column:stream"`

	// ---
	S, E time.Time `json:"-" gorm:"-"`

	Ext  int64         `json:"-" gorm:"-"` // 流等待过期时间
	Resp *sip.Response `json:"-" gorm:"-"`
	// contains filtered or unexported fields
}

Streams Streams

type Targeter

type Targeter interface {
	To() *sip.Address
	Conn() sip.Connection
	Source() net.Addr
}

Directories

Path Synopsis
m

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL