ipc

package
v1.4.21 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Code generated by godddx, DO AVOID EDIT.

Code generated by godddx, DO AVOID EDIT.

Code generated by godddx, DO AVOID EDIT.

Code generated by godddx, DO AVOID EDIT.

Code generated by godddx, DO AVOID EDIT.

Code generated by godddx, DO AVOID EDIT.

Code generated by godddx, DO AVOID EDIT.

Code generated by godddx, DO AVOID EDIT.

Index

Constants

View Source
const (
	TypeGB28181 = "GB28181"
	TypeOnvif   = "ONVIF"
	TypeRTSP    = "RTSP"
	TypeRTMP    = "RTMP"
)

Variables

This section is empty.

Functions

func ChannelDisplayName added in v1.3.34

func ChannelDisplayName(ch *Channel) string

ChannelDisplayName 返回通道展示名。

func ChannelReachable added in v1.3.34

func ChannelReachable(ch *Channel, deviceOnline bool) bool

ChannelReachable 判断通道是否可用:通道与所属设备均在线才算在线(与设备列表里对子通道的处理一致)。

func GenerateChannelID

func GenerateChannelID(c *Channel, uni uniqueid.Core) string

GenerateChannelID 根据通道类型生成唯一 ID

func GenerateDID

func GenerateDID(d *Device, uni uniqueid.Core) string

func GetType

func GetType(stream string) string

func ONVIFProfileName added in v1.3.34

func ONVIFProfileName(ch *Channel, deviceName string, deviceOnline bool) string

ONVIFProfileName 返回 ONVIF/HA 上展示的 Profile 名。 RTSP 拉流通道用 BUSY/IDLE 语义,不在名称标离线;其余类型需通道与设备同时在线,否则加「(离线)」。

func ProfileDisplayName added in v1.3.34

func ProfileDisplayName(ch *Channel, deviceName string) string

ProfileDisplayName 返回 ONVIF Profile 展示名:通道名-设备名。

Types

type Adapter

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

为协议适配,提供协议会用到的功能

func NewAdapter

func NewAdapter(store Storer, uni uniqueid.Core) Adapter

func (Adapter) GetChannel

func (g Adapter) GetChannel(ctx context.Context, id string) (*Channel, error)

func (Adapter) GetDevice

func (g Adapter) GetDevice(ctx context.Context, id string) (*Device, error)

func (Adapter) GetDeviceByDeviceID

func (g Adapter) GetDeviceByDeviceID(gbDeviceID string) (*Device, error)

func (Adapter) ListDevices added in v1.4.21

func (g Adapter) ListDevices(ctx context.Context) ([]*Device, error)

ListDevices 获取所有设备

func (Adapter) Logout

func (g Adapter) Logout(deviceID string, changeFn func(*Device)) error

func (Adapter) SaveChannels

func (g Adapter) SaveChannels(channels []*Channel) error

SaveChannels 保存通道列表(增量更新 + 删除多余通道)

策略说明: 1. 批量查询现有通道(减少数据库查询) 2. 对比更新:存在则更新,不存在则新增 3. 删除多余:不在上报列表中的通道标记为离线或删除 4. 使用事务保证数据一致性

func (Adapter) Store

func (g Adapter) Store() Storer

func (Adapter) Update added in v1.4.21

func (g Adapter) Update(deviceID string, changeFn func(*Device)) error

func (Adapter) UpdatePlaying added in v1.4.21

func (g Adapter) UpdatePlaying(ctx context.Context, deviceID, channelID string, playing bool) error

func (Adapter) UpdatePlayingByID added in v1.4.21

func (g Adapter) UpdatePlayingByID(ctx context.Context, id string, playing bool) error

type AddChannelInput

type AddChannelInput struct {
	Type       string `json:"type"`        // 通道类型 (RTMP/RTSP)
	Name       string `json:"name"`        // 通道名称
	DeviceID   string `json:"device_id"`   // 可选,关联的父设备 ID
	DeviceName string `json:"device_name"` // 可选,device_id 不存在时用于创建新设备

	// RTMP/RTSP 配置
	App    string       `json:"app"`    // 应用名
	Stream string       `json:"stream"` // 流 ID
	Config StreamConfig `json:"config"` // 流配置
}

AddChannelInput 添加通道请求参数,支持 RTMP/RTSP 类型

type AddDeviceInput

type AddDeviceInput struct {
	DeviceID string `json:"device_id"` // 20 位国标编号
	// onvif
	Username string `json:"username"` // 用户名
	IP       string `json:"ip"`       // ip
	Port     int    `json:"port"`     // port
	// 通用
	Name     string `json:"name"`     // 设备名称
	Password string `json:"password"` // 注册密码

	Type string `json:"type"` // 设备类型(ONVIF/GB28181)

}

目前仅应用于 onvif 添加

type AddZoneInput

type AddZoneInput struct {
	Name        string    `json:"name"`        // 区域名称
	Coordinates []float32 `json:"coordinates"` // 坐标
	Color       string    `json:"color"`       // 颜色,支持 hex 颜色值,如 #FF0000
	Labels      []string  `json:"labels"`      // 标签
	ChannelID   string    `json:"-"`           // 通道 id
}

type Channel

type Channel struct {
	ID        string    `gorm:"primaryKey" json:"id"`
	DID       string    `gorm:"column:did;index;notNull;default:'';comment:父级 ID" json:"did"`
	DeviceID  string    `gorm:"column:device_id;index;notNull;default:'';comment:国标编码" json:"device_id"`   // 国标编码
	ChannelID string    `gorm:"column:channel_id;index;notNull;default:'';comment:国标编码" json:"channel_id"` // 国标编码
	Name      string    `gorm:"column:name;notNull;default:'';comment:通道名称" json:"name"`                   // 通道名称
	PTZ       int       `gorm:"column:ptz;notNull;default:0;comment:云台类型" json:"ptz"`                      // 云台类型
	IsOnline  bool      `gorm:"column:is_online;notNull;default:FALSE;comment:是否在线" json:"is_online"`      // 是否在线
	IsPlaying bool      `gorm:"column:is_playing;notNull;default:FALSE;comment:是否播放中" json:"is_playing"`   // 是否播放中
	Ext       DeviceExt `gorm:"column:ext;notNull;default:'{}';type:jsonb" json:"ext"`
	CreatedAt orm.Time  `gorm:"column:created_at;notNull;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间
	UpdatedAt orm.Time  `gorm:"column:updated_at;notNull;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间
	Type      string    `gorm:"column:type;notNull;default:'';comment:通道类型" json:"type"`                            // 通道类型,继承父级设备类型

	// RTMP/RTSP 流配置字段
	App    string       `gorm:"column:app;index;notNull;default:'';comment:应用名" json:"app"`        // 应用名 (RTMP/RTSP)
	Stream string       `gorm:"column:stream;index;notNull;default:'';comment:流 ID" json:"stream"` // 流 ID (RTMP/RTSP)
	Config StreamConfig `gorm:"column:config;notNull;default:'{}';type:jsonb" json:"config"`       // 流配置 (RTMP/RTSP)

	// 非持久化字段,用于 API 响应
	HasRecording bool `gorm:"-" json:"has_recording"` // 是否存在录像(查询时动态填充)
}

Channel domain model

func (*Channel) GetApp added in v1.3.34

func (c *Channel) GetApp() string

func (*Channel) GetChannelID

func (c *Channel) GetChannelID() string

func (*Channel) GetGB28181DeviceID

func (c *Channel) GetGB28181DeviceID() string

func (*Channel) GetID

func (c *Channel) GetID() string

实现 port.Channel 接口

func (*Channel) GetStream added in v1.3.34

func (c *Channel) GetStream() string

func (*Channel) GetType added in v1.3.34

func (c *Channel) GetType() string

func (*Channel) IsGB28181

func (c *Channel) IsGB28181() bool

func (*Channel) IsOnvif

func (c *Channel) IsOnvif() bool

func (*Channel) IsRTMP added in v1.3.0

func (c *Channel) IsRTMP() bool

func (*Channel) IsRTSP added in v1.3.0

func (c *Channel) IsRTSP() bool

func (*Channel) TableName

func (*Channel) TableName() string

TableName database table name

type ChannelStorer

type ChannelStorer interface {
	List(context.Context, *[]*Channel, orm.Pager, ...orm.QueryOption) (int64, error)
	Get(context.Context, *Channel, ...orm.QueryOption) error
	Create(context.Context, *Channel) error
	Update(context.Context, *Channel, func(*Channel) error, ...orm.QueryOption) error
	Delete(context.Context, *Channel, ...orm.QueryOption) error

	BatchEdit(context.Context, string, any, ...orm.QueryOption) error // 批量更新一个字段
	EditGB28181Config(context.Context, *Channel) error                // 直接更新 GB28181 上报的四个字段,跳过查询
	Session(ctx context.Context, changeFns ...func(*gorm.DB) error) error
}

ChannelStorer Instantiation interface

type Core

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

Core business domain

func NewCore

func NewCore(store Storer, uni uniqueid.Core, protocols map[string]Protocoler) Core

NewCore create business domain

func (Core) AddZone

func (c Core) AddZone(ctx context.Context, in *AddZoneInput, channelID string) (*Zone, error)

func (Core) BatchOfflineRTMP added in v1.3.0

func (c Core) BatchOfflineRTMP(ctx context.Context) error

func (Core) CreateChannel added in v1.4.21

func (c Core) CreateChannel(ctx context.Context, in *AddChannelInput) (*Channel, error)

CreateChannel 添加 RTMP/RTSP 通道,支持自动创建虚拟设备 RTMP/RTSP: 支持自定义 app 和 stream,但禁止使用 app=rtp(rtp 专用于 GB28181)

func (Core) CreateDevice added in v1.4.21

func (c Core) CreateDevice(ctx context.Context, in *AddDeviceInput) (*Device, error)

CreateDevice Insert into database

func (Core) DeleteChannel added in v1.4.21

func (c Core) DeleteChannel(ctx context.Context, id string) (*Channel, error)

DeleteChannel Delete object 删除通道后会自动扣减所属设备的通道计数

func (Core) DeleteDevice added in v1.4.21

func (c Core) DeleteDevice(ctx context.Context, id string) (*Device, error)

DeleteDevice Delete object

func (Core) DeleteZone added in v1.3.34

func (c Core) DeleteZone(ctx context.Context, channelID, zoneName string) ([]Zone, error)

DeleteZone 按名称删除指定区域,返回删除后的区域列表

func (Core) GetChannel

func (c Core) GetChannel(ctx context.Context, id string) (*Channel, error)

GetChannel Query a single object

func (Core) GetChannelByAppStream added in v1.3.0

func (c Core) GetChannelByAppStream(ctx context.Context, app, stream string) (*Channel, error)

GetChannelByAppStream 通过 app 和 stream 获取通道

func (Core) GetChannelByAppStreamOrID added in v1.3.34

func (c Core) GetChannelByAppStreamOrID(ctx context.Context, app, stream string) (*Channel, error)

GetChannelByAppStreamOrID 通过 app+stream 或 id=stream 获取通道 用于 ZLM 回调时识别通道:先按 app+stream 查找,查不到再按 id=stream 查找 支持自定义 app/stream 的 RTMP/RTSP 通道以及使用默认 ID 作为 stream 的旧通道

func (Core) GetChannelByStream added in v1.3.34

func (c Core) GetChannelByStream(ctx context.Context, stream string) (*Channel, error)

GetChannelByStream 通过 stream ID 获取通道 先按 stream 字段查找,找不到再按 ID 查找

func (Core) GetDevice

func (c Core) GetDevice(ctx context.Context, id string) (*Device, error)

GetDevice Query a single object

func (Core) GetDeviceByDeviceID

func (c Core) GetDeviceByDeviceID(ctx context.Context, deviceID string) (*Device, error)

func (Core) GetProtocol

func (c Core) GetProtocol(atype string) Protocoler

func (Core) GetZones

func (c Core) GetZones(ctx context.Context, channelID string) ([]Zone, error)

func (Core) ListChannels added in v1.4.21

func (c Core) ListChannels(ctx context.Context, in *FindChannelInput) ([]*Channel, int64, error)

ListChannels Paginated search

func (Core) ListChannelsForDevice added in v1.4.21

func (c Core) ListChannelsForDevice(ctx context.Context, in *FindDeviceInput) ([]*Device, int64, error)

func (Core) ListDevices added in v1.4.21

func (c Core) ListDevices(ctx context.Context, in *FindDeviceInput) ([]*Device, int64, error)

ListDevices Paginated search

func (Core) PTZControl added in v1.3.34

func (c Core) PTZControl(ctx context.Context, channelID string, cmd PTZCommand) error

PTZControl 云台控制

func (Core) QueryCatalog

func (c Core) QueryCatalog(ctx context.Context, deviceID string) error

func (Core) SetAIEnabled

func (c Core) SetAIEnabled(ctx context.Context, channelID string, enabled bool) (*Channel, error)

SetAIEnabled 设置通道的 AI 检测开关状态,同时返回更新后的完整通道信息供调用方使用

func (Core) SetRecordMode added in v1.3.34

func (c Core) SetRecordMode(ctx context.Context, channelID string, mode string) (*Channel, error)

SetRecordMode 设置通道的录像模式,支持 always/ai/none 三种模式

func (Core) UpdateChannel added in v1.4.21

func (c Core) UpdateChannel(ctx context.Context, in *EditChannelInput, id string) (*Channel, error)

UpdateChannel 部分更新通道信息 仅覆盖前端实际传入的非零值字段,避免 copier 零值覆盖导致数据丢失

func (Core) UpdateChannelConfig added in v1.4.21

func (c Core) UpdateChannelConfig(ctx context.Context, id string, fn func(*StreamConfig)) (*Channel, error)

UpdateChannelConfig 更新通道的流配置(用于 Hook 回调更新状态)

func (Core) UpdateChannelConfigAndOnline added in v1.4.21

func (c Core) UpdateChannelConfigAndOnline(ctx context.Context, id string, isOnline bool, fn func(*StreamConfig)) (*Channel, error)

UpdateChannelConfigAndOnline 更新通道的流配置和在线状态

func (Core) UpdateChannelConfigAndOnlineByAppStream added in v1.4.21

func (c Core) UpdateChannelConfigAndOnlineByAppStream(ctx context.Context, app, stream string, isOnline bool, fn func(*StreamConfig)) (*Channel, error)

UpdateChannelConfigAndOnlineByAppStream 通过 app+stream 更新通道配置和在线状态

func (Core) UpdateChannelConfigByAppStream added in v1.4.21

func (c Core) UpdateChannelConfigByAppStream(ctx context.Context, app, stream string, fn func(*StreamConfig)) (*Channel, error)

UpdateChannelConfigByAppStream 通过 app+stream 更新通道配置

func (Core) UpdateChannelOnlineAndPlaying added in v1.4.21

func (c Core) UpdateChannelOnlineAndPlaying(ctx context.Context, stream string, isOnline, isPlaying bool) (*Channel, error)

UpdateChannelOnlineAndPlaying 更新通道在线状态和播放状态 流注销时需要同时更新 IsOnline 和 IsPlaying

func (Core) UpdateChannelPlaying added in v1.4.21

func (c Core) UpdateChannelPlaying(ctx context.Context, stream string, isPlaying bool) (*Channel, error)

UpdateChannelPlaying 更新通道播放状态 任何协议的流被播放或停止播放时都需要更新此状态

func (Core) UpdateDevice added in v1.4.21

func (c Core) UpdateDevice(ctx context.Context, in *EditDeviceInput, id string) (*Device, error)

UpdateDevice Update object information

type Device

type Device struct {
	ID   string `gorm:"primaryKey" json:"id"`
	Type string `gorm:"column:type;notNull;default:'GB28181';comment:设备类型(onvif)" json:"type"` // 设备类型(onvif/gb28181)

	// 自定义 id 可以简写为 did,国标 device_id 应简写成 gbid,而不是 device_id
	// 起这个名义会难以区分,但为了兼容已经部署的旧数据库...保留
	DeviceID string `gorm:"column:device_id;notNull;uniqueIndex;default:'';comment:20 位国标编号" json:"device_id"` // 20 位国标编号

	// 自定义名称
	Name         string    `gorm:"column:name;notNull;default:'';comment:设备名称" json:"name"`                                                    // 设备名称
	Transport    string    `gorm:"column:transport;notNull;default:'';comment:传输协议(tcp/udp)" json:"transport"`                                 // 传输协议(TCP/UDP)
	StreamMode   int8      `gorm:"column:stream_mode;notNull;default:1;comment:数据传输模式(0:UDP; 1:TCP_PASSIVE; 2:TCP_ACTIVE)" json:"stream_mode"` // 数据传输模式
	IP           string    `gorm:"column:ip;notNull;default:''" json:"ip"`
	Port         int       `gorm:"column:port;notNull;default:0" json:"port"`
	IsOnline     bool      `gorm:"column:is_online;notNull;default:FALSE" json:"is_online"`
	RegisteredAt orm.Time  `gorm:"column:registered_at;notNull;default:CURRENT_TIMESTAMP;comment:注册时间" json:"registered_at"` // 注册时间
	KeepaliveAt  orm.Time  `gorm:"column:keepalive_at;notNull;default:CURRENT_TIMESTAMP;comment:心跳时间" json:"keepalive_at"`   // 心跳时间
	Keepalives   int       `gorm:"column:keepalives;notNull;default:0;comment:心跳间隔" json:"keepalives"`                       // 心跳间隔
	Expires      int       `gorm:"column:expires;notNull;default:0;comment:注册有效期" json:"expires"`                            // 注册有效期
	Channels     int       `gorm:"column:channels;notNull;default:0;comment:通道数量" json:"channels"`                           // 通道数量
	CreatedAt    orm.Time  `gorm:"column:created_at;notNull;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"`       // 创建时间
	UpdatedAt    orm.Time  `gorm:"column:updated_at;notNull;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"`       // 更新时间
	Password     string    `gorm:"column:password;notNull;default:'';comment:注册密码" json:"password"`
	Address      string    `gorm:"column:address;notNull;default:'';comment:设备网络地址" json:"address"`
	Ext          DeviceExt `gorm:"column:ext;notNull;default:'{}';type:jsonb;comment:设备属性" json:"ext"` // 设备属性
	Username     string    `gorm:"column:username;notNull;default:'';comment:用户名" json:"username"`

	Children []*Channel `gorm:"-" json:"children,omitzero"`
}

Device domain model

func (Device) Check

func (d Device) Check() error

func (*Device) GetGB28181DeviceID

func (d *Device) GetGB28181DeviceID() string

func (*Device) GetID

func (d *Device) GetID() string

实现 port.Device 接口

func (*Device) GetIP

func (d *Device) GetIP() string

func (*Device) GetName added in v1.3.34

func (d *Device) GetName() string

func (*Device) GetPassword

func (d *Device) GetPassword() string

func (*Device) GetPort

func (d *Device) GetPort() int

func (*Device) GetType

func (d *Device) GetType() string

func (*Device) GetUsername

func (d *Device) GetUsername() string

func (*Device) IsGB28181

func (d *Device) IsGB28181() bool

func (*Device) IsOnvif

func (d *Device) IsOnvif() bool

func (*Device) NetworkAddress

func (d *Device) NetworkAddress() string

func (*Device) TableName

func (*Device) TableName() string

TableName database table name

type DeviceExt

type DeviceExt struct {
	Manufacturer     string  `json:"manufacturer"`      // 生产厂商
	Model            string  `json:"model"`             // 型号
	Firmware         string  `json:"firmware"`          // 固件版本
	Name             string  `json:"name"`              // 设备名
	GBVersion        string  `json:"gb_version"`        // GB版本
	Zones            []Zone  `json:"zones"`             // 区域
	EnabledAI        bool    `json:"enabled_ai"`        // 是否启用 AI
	AnalysisInterval float32 `json:"analysis_interval"` // AI 分析间隔(秒),0 表示使用默认值

	// 空串表示 always
	RecordMode string `json:"record_mode"` // 录像模式, 一直录制:always, 按AI触发:ai, 不录制:none
}

DeviceExt domain model

func (*DeviceExt) GetRecordMode added in v1.3.34

func (e *DeviceExt) GetRecordMode() string

func (*DeviceExt) IsAIRecord added in v1.3.34

func (e *DeviceExt) IsAIRecord() bool

func (*DeviceExt) IsAlwaysRecord added in v1.3.34

func (e *DeviceExt) IsAlwaysRecord() bool

func (*DeviceExt) IsNoneRecord added in v1.3.34

func (e *DeviceExt) IsNoneRecord() bool

func (*DeviceExt) Scan

func (i *DeviceExt) Scan(input any) error

Scan implements orm.Scaner.

func (DeviceExt) Value

func (i DeviceExt) Value() (driver.Value, error)

type DeviceStorer

type DeviceStorer interface {
	List(context.Context, *[]*Device, orm.Pager, ...orm.QueryOption) (int64, error)
	Get(context.Context, *Device, ...orm.QueryOption) error
	Create(context.Context, *Device) error
	Update(context.Context, *Device, func(*Device) error, ...orm.QueryOption) error
	Delete(context.Context, *Device, ...orm.QueryOption) error

	Session(ctx context.Context, changeFns ...func(*gorm.DB) error) error
}

DeviceStorer Instantiation interface

type EditChannelInput

type EditChannelInput struct {
	DeviceID string    `json:"device_id"` // 国标编码
	Name     string    `json:"name"`      // 通道名称
	PTZType  int       `json:"ptztype"`   // 云台类型
	IsOnline bool      `json:"is_online"` // 是否在线
	Ext      DeviceExt `json:"ext"`

	// RTMP/RTSP 配置
	App    string       `json:"app"`    // 应用名(RTMP/RTSP 可自定义,但不能为 rtp)
	Stream string       `json:"stream"` // 流 ID(RTMP/RTSP 可自定义)
	Config StreamConfig `json:"config"` // 流配置
}

type EditDeviceInput

type EditDeviceInput struct {
	DeviceID   string `json:"device_id"`   // 20 位国标编号
	Name       string `json:"name"`        // 设备名称
	Password   string `json:"password"`    // 注册密码
	StreamMode int    `json:"stream_mode"` // 数据传输模式

	Username string `json:"username"` // 用户名
	IP       string `json:"ip"`       // ip
	Port     int    `json:"port"`     // port

}

type FindChannelInput

type FindChannelInput struct {
	web.PagerFilter
	DID      string `form:"did"`       // 设备 id
	DeviceID string `form:"device_id"` // 国标编码
	Key      string `form:"key"`       // 名称/国标编码 模糊搜索,id 精确搜索
	IsOnline string `form:"is_online"` // 是否在线
	Type     string `form:"type"`      // 通道类型 (GB28181/ONVIF/RTMP/RTSP)
	App      string `form:"app"`       // 应用名
	Stream   string `form:"stream"`    // 流 ID
}

type FindDeviceInput

type FindDeviceInput struct {
	web.PagerFilter
	Key string `form:"key"`
}

type Hooker

type Hooker interface {
	OnStreamNotFound(ctx context.Context, app, stream string) error
	// OnStreamChanged 流注销时调用,用于更新通道状态
	// app/stream 用于支持自定义 app/stream 的 RTMP/RTSP 通道
	OnStreamChanged(ctx context.Context, app, stream string) error
}

type OnPublisher added in v1.3.34

type OnPublisher interface {
	// OnPublish 处理推流鉴权
	// 返回 true 表示鉴权通过,false 表示鉴权失败
	// app/stream 用于支持自定义 app/stream 的 RTMP/RTSP 通道
	OnPublish(ctx context.Context, app, stream string, params map[string]string) (bool, error)
}

OnPublisher 推流鉴权接口(可选实现) 只有 RTMP 需要实现此接口

type PTZCommand added in v1.3.34

type PTZCommand struct {
	Action    string  `json:"action"`    // 动作类型: continuous(连续移动), absolute(绝对移动), relative(相对移动), stop(停止), preset(预置位)
	Direction string  `json:"direction"` // 方向: up, down, left, right, upleft, upright, downleft, downright, zoomin, zoomout
	Speed     float64 `json:"speed"`     // 速度 (0-1), 默认 0.5
	X         float64 `json:"x"`         // X 轴位置 (绝对/相对移动时使用, -1 到 1)
	Y         float64 `json:"y"`         // Y 轴位置 (绝对/相对移动时使用, -1 到 1)
	Zoom      float64 `json:"zoom"`      // 缩放值 (绝对/相对移动时使用, 0 到 1)
	PresetID  string  `json:"preset_id"` // 预置位 ID
	PresetOp  string  `json:"preset_op"` // 预置位操作: goto(转到), set(设置), remove(删除)
}

PTZCommand 云台控制命令

type PlayResponse

type PlayResponse struct {
	SSRC   string // GB28181 SSRC
	Stream string // 流 ID
	RTSP   string // RTSP 地址 (ONVIF)
}

PlayResponse 播放响应

type Protocoler

type Protocoler interface {
	// ValidateDevice 验证设备连接(添加设备前调用)
	// 可以修改设备信息(如从 ONVIF 获取的固件版本等)
	ValidateDevice(ctx context.Context, device *Device) error

	// InitDevice 初始化设备连接(添加设备后调用)
	// 例如: GB28181 不需要主动初始化,ONVIF 需要查询 Profiles 作为通道
	InitDevice(ctx context.Context, device *Device) error

	// QueryCatalog 查询设备目录/通道
	QueryCatalog(ctx context.Context, device *Device) error

	// StartPlay 开始播放
	StartPlay(ctx context.Context, device *Device, channel *Channel) (*PlayResponse, error)

	// StopPlay 停止播放
	StopPlay(ctx context.Context, device *Device, channel *Channel) error

	DeleteDevice(ctx context.Context, device *Device) error

	// PTZControl 云台控制
	PTZControl(ctx context.Context, device *Device, channel *Channel, cmd PTZCommand) error

	Hooker
}

Protocoler 协议抽象接口(端口)

设计原则: 1. 接口在 ipc 包内定义,避免循环依赖 2. 接口方法直接使用领域模型 (*Device, *Channel) 3. 适配器实现此接口,可以直接依赖和修改领域模型 4. 符合依赖倒置原则 (DIP):

  • ipc (高层) 依赖 Protocoler 接口
  • adapter (低层) 实现 Protocoler 接口
  • adapter (低层) 依赖 ipc.Device (高层) ✅ 合理

这就是依赖反转!

type Storer

type Storer interface {
	Device() DeviceStorer
	Channel() ChannelStorer
}

Storer data persistence

type StreamConfig added in v1.3.0

type StreamConfig struct {
	// RTMP 推流配置
	IsAuthDisabled bool      `json:"is_auth_disabled"`    // 是否禁用推流鉴权
	Session        string    `json:"session,omitempty"`   // 推流鉴权参数(由推流客户端携带)
	PushedAt       *orm.Time `json:"pushed_at"`           // 最后推流时间
	StoppedAt      *orm.Time `json:"stopped_at"`          // 最后停止时间
	MediaServerID  string    `json:"media_server_id"`     // 媒体服务器 ID
	PushAddr       string    `json:"push_addr,omitempty"` // 推流地址(动态生成,不持久化)

	// RTSP 拉流配置
	SourceURL                 string `json:"source_url"`                   // 原始 URL
	Transport                 int    `json:"transport"`                    // 拉流方式 (0:tcp, 1:udp)
	TimeoutS                  int    `json:"timeout_s"`                    // 超时时间
	EnabledAudio              bool   `json:"enabled_audio"`                // 是否启用音频
	EnabledRemoveNoneReader   bool   `json:"enabled_remove_none_reader"`   // 无人观看时删除
	EnabledDisabledNoneReader bool   `json:"enabled_disabled_none_reader"` // 无人观看时禁用
	StreamKey                 string `json:"stream_key"`                   // ZLM 返回的 key
	Enabled                   bool   `json:"enabled"`                      // 是否启用
}

StreamConfig 流配置,用于 RTMP 推流和 RTSP 拉流代理

func (*StreamConfig) Scan added in v1.3.0

func (s *StreamConfig) Scan(input any) error

Scan implements orm.Scanner

func (StreamConfig) Value added in v1.3.0

func (s StreamConfig) Value() (driver.Value, error)

Value implements driver.Valuer

type Zone

type Zone struct {
	Name        string    `json:"name"`        // 区域名称
	Coordinates []float32 `json:"coordinates"` // 坐标
	Color       string    `json:"color"`       // 颜色,支持 hex 颜色值,如 #FF0000
	Labels      []string  `json:"labels"`      // 标签
}

Directories

Path Synopsis
store
ipcdb
Code generated by godddx, DO AVOID EDIT.
Code generated by godddx, DO AVOID EDIT.

Jump to

Keyboard shortcuts

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