port

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: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel any

Channel 通道接口

type Device

type Device any

Device 设备接口 注意: 适配器实现时,参数类型为 *ipc.Device,满足此接口

type PlayResponse

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

PlayResponse 播放响应

type Protocol

type Protocol interface {
	// ValidateDevice 验证设备连接(添加设备前调用)
	// 参数类型: *ipc.Device
	ValidateDevice(ctx context.Context, device Device) error

	// InitDevice 初始化设备连接(添加设备后调用)
	// 参数类型: *ipc.Device
	InitDevice(ctx context.Context, device Device) error

	// QueryCatalog 查询设备目录/通道
	// 参数类型: *ipc.Device
	QueryCatalog(ctx context.Context, device Device) error

	// StartPlay 开始播放
	// 参数类型: *ipc.Device, *ipc.Channel
	StartPlay(ctx context.Context, device Device, channel Channel) (*PlayResponse, error)

	// StopPlay 停止播放
	// 参数类型: *ipc.Device, *ipc.Channel
	StopPlay(ctx context.Context, device Device, channel Channel) error
}

Protocol 协议抽象接口(端口)

设计原则: 1. 接口参数使用 Device/Channel 接口(空接口) 2. 适配器实现时使用具体类型 *ipc.Device, *ipc.Channel 3. 由于是空接口,任何类型都满足,但语义上明确是 Device/Channel 4. 避免循环依赖,同时保持类型语义

使用示例:

// 适配器实现
func (a *Adapter) ValidateDevice(ctx context.Context, device Device) error {
    dev := device.(*ipc.Device)  // 类型断言
    // ...
}

// 或者更好的方式:在包级别声明具体签名
func (a *Adapter) ValidateDevice(ctx context.Context, device *ipc.Device) error

Jump to

Keyboard shortcuts

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