gb28181

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChannelOnStatus  = "ON"
	ChannelOffStatus = "OFF"
)
View Source
const (
	DeviceRegisterStatus = "REGISTER"
	DeviceRecoverStatus  = "RECOVER"
	DeviceOnlineStatus   = "ONLINE"
	DeviceOfflineStatus  = "OFFLINE"
	DeviceAlarmedStatus  = "ALARMED"
)
View Source
const (
	PresetSet  = 0x81
	PresetCall = 0x82
	PresetDel  = 0x83
)
View Source
const (
	CruiseAdd      = 0x84
	CruiseDel      = 0x85
	CruiseSetSpeed = 0x86
	CruiseStopTime = 0x87
	CruiseStart    = 0x88
)
View Source
const (
	ScanningStart = 0x89
	ScanningSpeed = 0x8A
)
View Source
const (
	SpeedParamError = "speed 范围(0,8]"
	PointParamError = "point 范围(0,50]"
)
View Source
const DeviceControl = "DeviceControl"
View Source
const MaxRegisterCount = 3
View Source
const PTZFirstByte = 0xA5
View Source
const TIME_LAYOUT = "2006-01-02T15:04:05"

Variables

View Source
var (
	Devices             sync.Map
	DeviceNonce         sync.Map //保存nonce防止设备伪造
	DeviceRegisterCount sync.Map //设备注册次数
)
View Source
var (
	// CatalogXML 获取设备列表xml样式
	CatalogXML = `<?xml version="1.0"?><Query>
<CmdType>Catalog</CmdType>
<SN>%d</SN>
<DeviceID>%s</DeviceID>
</Query>
`
	// RecordInfoXML 获取录像文件列表xml样式
	RecordInfoXML = `` /* 191-byte string literal not displayed */

	// DeviceInfoXML 查询设备详情xml样式
	DeviceInfoXML = `<?xml version="1.0"?>
<Query>
<CmdType>DeviceInfo</CmdType>
<SN>%d</SN>
<DeviceID>%s</DeviceID>
</Query>
`
	// DevicePositionXML 订阅设备位置
	DevicePositionXML = `` /* 132-byte string literal not displayed */

)
View Source
var (
	AlarmResponseXML = `<?xml version="1.0"?>
<Response>
<CmdType>Alarm</CmdType>
<SN>17430</SN>
<DeviceID>%s</DeviceID>
</Response>
`
)

AlarmResponseXML alarm response xml样式

View Source
var ErrNazaNet = errors.New("gb28181: fxxk")

Functions

func BuildAlarmResponseXML

func BuildAlarmResponseXML(id string) string

BuildRecordInfoXML 获取录像文件列表指令

func BuildCatalogXML

func BuildCatalogXML(sn int, id string) string

func BuildDeviceInfoXML

func BuildDeviceInfoXML(sn int, id string) string

func DecodeGbk

func DecodeGbk(v interface{}, body []byte) error

func GbkToUtf8

func GbkToUtf8(s []byte) ([]byte, error)

func RandNumString

func RandNumString(n int) string

func RandString

func RandString(n int) string

func ResponseErrorWithMsg

func ResponseErrorWithMsg(c *gin.Context, code ResCode, msg interface{})

func ResponseSuccess

func ResponseSuccess(c *gin.Context, data interface{})

func XmlEncode

func XmlEncode(v interface{}) (string, error)

Types

type Authorization

type Authorization struct {
	*sip.Authorization
}

func (*Authorization) Verify

func (a *Authorization) Verify(username, passwd, realm, nonce string) bool

type AvailConnPool

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

从指定的端口范围内,寻找可绑定监听的端口,绑定监听并返回

func NewAvailConnPool

func NewAvailConnPool(minPort uint16, maxPort uint16) *AvailConnPool

func (*AvailConnPool) Acquire

func (a *AvailConnPool) Acquire() (net.Listener, uint16, error)

func (*AvailConnPool) ListenWithPort

func (a *AvailConnPool) ListenWithPort(port uint16) (net.Listener, error)

func (*AvailConnPool) Peek

func (a *AvailConnPool) Peek() (uint16, error)

通过Acquire获取到可用net.UDPConn对象后,将对象关闭,只返回可用的端口

func (*AvailConnPool) WithListenWithPort

func (a *AvailConnPool) WithListenWithPort(listenWithPort OnListenWithPort)

type Channel

type Channel struct {

	//status  atomic.Int32 // 通道状态,0:空闲,1:正在invite,2:正在播放
	GpsTime time.Time // gps时间

	ChannelInfo
	// contains filtered or unexported fields
}

func (*Channel) Bye

func (channel *Channel) Bye(streamName string) (err error)

func (*Channel) CanInvite

func (channel *Channel) CanInvite(streamName string) bool

func (*Channel) CreateRequst

func (channel *Channel) CreateRequst(Method sip.RequestMethod, conf config.GB28181Config) (req sip.Request)

func (*Channel) GetCallId

func (channel *Channel) GetCallId() string

func (*Channel) Invite

func (channel *Channel) Invite(opt *InviteOptions, streamName string, playInfo *PlayInfo) (code int, err error)

func (*Channel) PtzDirection

func (channel *Channel) PtzDirection(direction *PtzDirection) error

func (*Channel) PtzFi

func (channel *Channel) PtzFi(fi *PtzFi) error

func (*Channel) PtzPreset

func (channel *Channel) PtzPreset(ptzPreset *PtzPreset) error

func (*Channel) PtzStop

func (channel *Channel) PtzStop(stop *PtzStop) error

func (*Channel) PtzZoom

func (channel *Channel) PtzZoom(zoom *PtzZoom) error

func (*Channel) TryAutoInvite

func (channel *Channel) TryAutoInvite(opt *InviteOptions, streamName string, playInfo *PlayInfo)

func (*Channel) WithMediaServer

func (channel *Channel) WithMediaServer(observer IMediaOpObserver)

type ChannelInfo

type ChannelInfo struct {
	ChannelId    string        `xml:"DeviceID"`     // 设备id
	ParentId     string        `xml:"ParentID"`     //父目录Id
	Name         string        `xml:"Name"`         //设备名称
	Manufacturer string        `xml:"Manufacturer"` //制造厂商
	Model        string        `xml:"Model"`        //型号
	Owner        string        `xml:"Owner"`        //设备归属
	CivilCode    string        `xml:"CivilCode"`    //行政区划编码
	Address      string        `xml:"Address"`      //地址
	Port         int           `xml:"Port"`         //端口
	Parental     int           `xml:"Parental"`     //存在子设备,这里表明有子目录存在 1代表有子目录,0表示没有
	SafetyWay    int           `xml:"SafetyWay"`    //信令安全模式(可选)缺省为 0;0:不采用;2:S/MIME 签名方式;3:S/MIME	加密签名同时采用方式;4:数字摘要方式
	RegisterWay  int           `xml:"RegisterWay"`  //标准的认证注册模式
	Secrecy      int           `xml:"Secrecy"`      //0 表示不涉密
	Status       ChannelStatus `xml:"Status"`       // 状态  on 在线 off离线
	Longitude    string        `xml:"Longitude"`    // 经度
	Latitude     string        `xml:"Latitude"`     // 纬度
	StreamName   string        `xml:"-"`

	mediaserver.MediaInfo
	// contains filtered or unexported fields
}

Channel 通道

type ChannelItem

type ChannelItem struct {
	ChannelId    string        `json:"channel_id"`   // channel id
	Name         string        `json:"name"`         // 设备名称
	Manufacturer string        `json:"manufacturer"` // 制造厂商
	Owner        string        `json:"owner"`        // 设备归属
	CivilCode    string        `json:"civilCode"`    // 行政区划编码
	Address      string        `json:"address"`      // 地址
	Status       ChannelStatus `json:"status"`       // 状态  on 在线 off离线
	Longitude    string        `json:"longitude"`    // 经度
	Latitude     string        `json:"latitude"`     // 纬度
	StreamName   string        `json:"-"`
}

type ChannelStatus

type ChannelStatus string

type Cruise

type Cruise struct {
	CMD      byte
	GroupNum byte
	Value    uint16
}

注1 : 字节5 表示巡航组号, 字节6 表示预置位号。 注2: 序号2 中, 字节6 为00H 时, 删除对应的整条巡航; 序号3、4 中字节6 表示数据的低8 位, 字节7 的高4 位 表示数据的高4 位。 注3: 巡航停留时间的单位是秒(s) 。 注4: 停止巡航用 PTZ 指令中的字节4 的各 Bit 位均为0 的停止指令。

func (*Cruise) Pack

func (c *Cruise) Pack() string

type Device

type Device struct {
	ID              string
	Name            string
	Manufacturer    string
	Model           string
	Owner           string
	RegisterTime    time.Time
	UpdateTime      time.Time
	LastKeepaliveAt time.Time
	Status          DeviceStatus

	NetAddr string

	GpsTime   time.Time //gps时间
	Longitude string    //经度
	Latitude  string    //纬度
	// contains filtered or unexported fields
}

func (*Device) Catalog

func (d *Device) Catalog(conf config.GB28181Config) int

func (*Device) CreateRequest

func (d *Device) CreateRequest(Method sip.RequestMethod, conf config.GB28181Config) (req sip.Request)

func (*Device) QueryDeviceInfo

func (d *Device) QueryDeviceInfo(conf config.GB28181Config)

func (*Device) SipRequestForResponse

func (d *Device) SipRequestForResponse(request sip.Request) (sip.Response, error)

func (*Device) Subscribe

func (d *Device) Subscribe(conf config.GB28181Config) int

func (*Device) UpdateChannelPosition

func (d *Device) UpdateChannelPosition(channelId string, gpsTime string, lng string, lat string)

UpdateChannelPosition 更新通道GPS坐标

func (*Device) UpdateChannelStatus

func (d *Device) UpdateChannelStatus(deviceList []*notifyMessage, conf config.GB28181Config)

UpdateChannelStatus 目录订阅消息处理:新增/移除/更新通道或者更改通道状态

func (*Device) UpdateChannels

func (d *Device) UpdateChannels(list ...ChannelInfo)

func (*Device) WithMediaServer

func (d *Device) WithMediaServer(observer IMediaOpObserver)

type DeviceInfos

type DeviceInfos struct {
	DeviceItems []*DeviceItem `json:"device_items"`
}

type DeviceItem

type DeviceItem struct {
	DeviceId string         `json:"device_id"` // 设备ID
	Channels []*ChannelItem `json:"channels"`
}

type DeviceStatus

type DeviceStatus string

type Fi

type Fi struct {
	IrisIn    bool
	IrisOut   bool
	FocusNear bool
	FocusFar  bool
	Speed     byte //0-8
}

注1 : 字节4 中的 Bit3 为1 时, 光圈缩小;Bit2 为1 时, 光圈放大。 Bit1 为1 时, 聚焦近;Bit0 为1 时, 聚焦远。 Bit3~ Bit0 的相应位清0, 则相应控制操作停止动作。 注2: 字节5 表示聚焦速度, 速度范围由慢到快为00H~FFH。 注3: 字节6 表示光圈速度, 速度范围由慢到快为00H~FFH

func (*Fi) Pack

func (f *Fi) Pack() string

type GB28181Server

type GB28181Server struct {
	RegisterValidity  time.Duration // 注册有效期,单位秒,默认 3600
	HeartbeatInterval time.Duration // 心跳间隔,单位秒,默认 60
	RemoveBanInterval time.Duration // 移除禁止设备间隔,默认600s

	MediaServerMap sync.Map
	// contains filtered or unexported fields
}

func NewGB28181Server

func NewGB28181Server(conf config.GB28181Config, lal logic.ILalServer) *GB28181Server

func (*GB28181Server) CheckSsrc

func (s *GB28181Server) CheckSsrc(ssrc uint32) (*mediaserver.MediaInfo, bool)

func (*GB28181Server) Dispose

func (s *GB28181Server) Dispose()

func (*GB28181Server) FindChannel

func (s *GB28181Server) FindChannel(deviceId string, channelId string) (channel *Channel)

func (*GB28181Server) GetAllSyncChannels

func (s *GB28181Server) GetAllSyncChannels()

func (*GB28181Server) GetMediaInfoByKey

func (s *GB28181Server) GetMediaInfoByKey(key string) (*mediaserver.MediaInfo, bool)

func (*GB28181Server) GetSyncChannels

func (s *GB28181Server) GetSyncChannels(deviceId string) bool

func (*GB28181Server) NotifyClose

func (s *GB28181Server) NotifyClose(streamName string)

func (*GB28181Server) OnBye

func (s *GB28181Server) OnBye(req sip.Request, tx sip.ServerTransaction)

func (*GB28181Server) OnMessage

func (s *GB28181Server) OnMessage(req sip.Request, tx sip.ServerTransaction)

func (*GB28181Server) OnNotify

func (s *GB28181Server) OnNotify(req sip.Request, tx sip.ServerTransaction)

func (*GB28181Server) OnRegister

func (s *GB28181Server) OnRegister(req sip.Request, tx sip.ServerTransaction)

func (*GB28181Server) OnStartMediaServer

func (s *GB28181Server) OnStartMediaServer(netWork string, singlePort bool, deviceId string, channelId string) *mediaserver.GB28181MediaServer

func (*GB28181Server) OnStopMediaServer

func (s *GB28181Server) OnStopMediaServer(netWork string, singlePort bool, deviceId string, channelId string) error

func (*GB28181Server) RecoverDevice

func (s *GB28181Server) RecoverDevice(d *Device, req sip.Request)

func (*GB28181Server) Start

func (s *GB28181Server) Start()

func (*GB28181Server) StoreDevice

func (s *GB28181Server) StoreDevice(id string, req sip.Request) (d *Device)

type GbLogic

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

func NewGbLogic

func NewGbLogic(s *GB28181Server) *GbLogic

func (*GbLogic) GetDeviceInfos

func (g *GbLogic) GetDeviceInfos(c *gin.Context)

func (*GbLogic) PtzDirection

func (g *GbLogic) PtzDirection(c *gin.Context)

func (*GbLogic) PtzFi

func (g *GbLogic) PtzFi(c *gin.Context)

func (*GbLogic) PtzPreset

func (g *GbLogic) PtzPreset(c *gin.Context)

func (*GbLogic) PtzStop

func (g *GbLogic) PtzStop(c *gin.Context)

func (*GbLogic) PtzZoom

func (g *GbLogic) PtzZoom(c *gin.Context)

func (*GbLogic) StartPlay

func (g *GbLogic) StartPlay(c *gin.Context)

func (*GbLogic) StopPlay

func (g *GbLogic) StopPlay(c *gin.Context)

func (*GbLogic) UpdateAllNotify

func (g *GbLogic) UpdateAllNotify(c *gin.Context)

func (*GbLogic) UpdateNotify

func (g *GbLogic) UpdateNotify(c *gin.Context)

type IMediaOpObserver

type IMediaOpObserver interface {
	OnStartMediaServer(netWork string, singlePort bool, deviceId string, channelId string) *mediaserver.GB28181MediaServer
	OnStopMediaServer(netWork string, singlePort bool, deviceId string, channelId string) error
}

type InviteOptions

type InviteOptions struct {
	Start int
	End   int

	SSRC      uint32
	MediaPort uint16
	// contains filtered or unexported fields
}

func (*InviteOptions) CreateSSRC

func (o *InviteOptions) CreateSSRC(serial string, number uint16)

func (InviteOptions) IsLive

func (o InviteOptions) IsLive() bool

func (InviteOptions) String

func (o InviteOptions) String() string

type MessagePtz

type MessagePtz struct {
	XMLName  xml.Name `xml:"Control"`
	CmdType  string   `xml:"CmdType"`
	SN       int      `xml:"SN"`
	DeviceID string   `xml:"DeviceID"`
	PTZCmd   string   `xml:"PTZCmd"`
}

type OnListenWithPort

type OnListenWithPort func(port uint16) (net.Listener, error)

type PlayInfo

type PlayInfo struct {
	NetWork      string `json:"network" form:"network" url:"network"`                      // 媒体传输类型,tcp/udp,默认udp
	DeviceId     string `json:"device_id" form:"device_id" url:"device_id"`                // 设备 Id
	ChannelId    string `json:"channel_id" form:"channel_id" url:"channel_id"`             // channel id
	StreamName   string `json:"stream_name" form:"stream_name" url:"stream_name"`          // 对应的流名
	SinglePort   bool   `json:"single_port" form:"single_port" url:"single_port"`          // 是否单端口
	DumpFileName string `json:"dump_file_name" form:"dump_file_name" url:"dump_file_name"` // dump文件路径
}

type Preset

type Preset struct {
	CMD   byte
	Point byte
}

func (*Preset) Pack

func (p *Preset) Pack() string

type PresetCmd

type PresetCmd byte
const (
	PresetEditPoint PresetCmd = iota
	PresetDelPoint
	PresetCallPoint
)

type Ptz

type Ptz struct {
	ZoomOut bool
	ZoomIn  bool
	Up      bool
	Down    bool
	Left    bool
	Right   bool
	Speed   byte //0-8
}

注1 : 字节4 中的 Bit5、Bit4 分别控制镜头变倍的缩小和放大, 字节4 中的 Bit3、Bit2、Bit1、Bit0 位分别控制云台 上、 下、 左、 右方向的转动, 相应 Bit 位置1 时, 启动云台向相应方向转动, 相应 Bit 位清0 时, 停止云台相应 方向的转动。 云台的转动方向以监视器显示图像的移动方向为准。 注2: 字节5 控制水平方向速度, 速度范围由慢到快为00H~FFH; 字节6 控制垂直方向速度, 速度范围由慢到快 为00H-FFH。 注3: 字节7 的高4 位为变焦速度, 速度范围由慢到快为0H~FH; 低4 位为地址的高4 位。

func (*Ptz) Pack

func (p *Ptz) Pack() string

func (*Ptz) Stop

func (p *Ptz) Stop() string

type PtzDirection

type PtzDirection struct {
	DeviceId  string `json:"device_id" form:"device_id" url:"device_id"`    // 设备 Id
	ChannelId string `json:"channel_id" form:"channel_id" url:"channel_id"` // channel id
	Up        bool   `json:"up" form:"up" url:"up"`
	Down      bool   `json:"down" form:"down" url:"down"`
	Left      bool   `json:"left" form:"left" url:"left"`
	Right     bool   `json:"right" form:"right" url:"right"`
	Speed     byte   `json:"speed" form:"speed" url:"speed"` //0-8
}

type PtzFi

type PtzFi struct {
	DeviceId  string `json:"device_id" form:"device_id" url:"device_id"`    // 设备 Id
	ChannelId string `json:"channel_id" form:"channel_id" url:"channel_id"` // channel id
	IrisIn    bool   `json:"iris_in" form:"iris_in" url:"iris_in"`
	IrisOut   bool   `json:"iris_out" form:"iris_out" url:"iris_out"`
	FocusNear bool   `json:"focus_near" form:"focus_near" url:"focus_near"`
	FocusFar  bool   `json:"focus_far" form:"focus_far" url:"focus_far"`
	Speed     byte   `json:"speed" form:"speed" url:"speed"` //0-8
}

type PtzHead

type PtzHead struct {
	FirstByte    uint8
	AssembleByte uint8
	Addr         uint8 //低地址码0-ff
}

表 A.3 指令格式 字节 字节1 字节2 字节3 字节4 字节5 字节6 字节7 字节8 含义 A5H 组合码1 地址 指令 数据1 数据2 组合码2 校验码 各字节定义如下: 字节1: 指令的首字节为 A5H。 字节2: 组合码1, 高4 位是版本信息, 低4 位是校验位。 本标准的版本号是1.0, 版本信息为0H。 校验位= (字节1 的高4 位+ 字节1 的低4 位+ 字节2 的高4 位) %16。 字节3: 地址的低8 位。 字节4: 指令码。 字节5、6: 数据1 和数据2。 字节7: 组合码2, 高4 位是数据3, 低4 位是地址的高4 位; 在后续叙述中, 没有特别指明的高4 位, 表示该4 位与所指定的功能无关。 字节8: 校验码, 为前面的第1~7 字节的算术和的低8 位, 即算术和对256 取模后的结果。 字节8= (字节1+ 字节2+ 字节3+ 字节4+ 字节5+ 字节6+ 字节7) %256。 地址范围000H~FFFH(即0~4095) , 其中000H 地址作为广播地址。 注: 前端设备控制中, 不使用字节3 和字节7 的低4 位地址码, 使用前端设备控制消息体中的<DeviceID> 统一编码 标识控制的前端设备

type PtzPreset

type PtzPreset struct {
	DeviceId  string    `json:"device_id" form:"device_id" url:"device_id"`    // 设备 Id
	ChannelId string    `json:"channel_id" form:"channel_id" url:"channel_id"` // channel id
	Cmd       PresetCmd `json:"cmd" form:"cmd" url:"cmd"`
	Point     byte      `json:"point" form:"point" url:"point"`
}

type PtzStop

type PtzStop struct {
	DeviceId  string `json:"device_id" form:"device_id" url:"device_id"`    // 设备 Id
	ChannelId string `json:"channel_id" form:"channel_id" url:"channel_id"` // channel id
}

type PtzZoom

type PtzZoom struct {
	DeviceId  string `json:"device_id" form:"device_id" url:"device_id"`    // 设备 Id
	ChannelId string `json:"channel_id" form:"channel_id" url:"channel_id"` // channel id
	ZoomOut   bool   `json:"zoom_out" form:"zoom_out" url:"zoom_out"`
	ZoomIn    bool   `json:"zoom_in" form:"zoom_in" url:"zoom_in"`
	Speed     byte   `json:"speed" form:"speed" url:"speed"` //0-8
}

type ReqPlay

type ReqPlay struct {
	PlayInfo
}

type ReqStop

type ReqStop struct {
	PlayInfo
}

type ReqUpdateNotify

type ReqUpdateNotify struct {
	DeviceId string `json:"device_id" form:"device_id" url:"device_id"` //设备 Id
}

type ResCode

type ResCode int64
const (
	CodeSuccess ResCode = 1000 + iota
	CodeInvalidParam
	CodeServerBusy
	CodeDeviceNotRegister
	CodeDeviceStopError
)

func (ResCode) Msg

func (c ResCode) Msg() string

type RespPlay

type RespPlay struct {
	StreamName string `json:"stream_name" form:"stream_name" url:"stream_name"`
}

type ResponseData

type ResponseData struct {
	Code ResCode     `json:"code"`
	Msg  interface{} `json:"msg"`
	Data interface{} `json:"data,omitempty"`
}

type Scanning

type Scanning struct {
	CMD      byte
	No       byte
	Value    byte
	HighAddr byte // 0-f 后4位高地址码 0-f
}

注1 : 字节5 表示扫描组号。 注2: 序号4 中, 字节6 表示数据的低8 位, 字节7 的高4 位表示数据的高4 位。 注3: 停止自动扫描用 PTZ 指令中的字节4 的各 Bit 位均为0 的停止指令。 注4: 自动扫描开始时, 整体画面从右向左移动。

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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