server

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServiceGetServiceCapabilities = "GetServiceCapabilities"

	DeviceGetCapabilities          = "GetCapabilities"
	DeviceGetDeviceInformation     = "GetDeviceInformation"
	DeviceGetDiscoveryMode         = "GetDiscoveryMode"
	DeviceGetDNS                   = "GetDNS"
	DeviceGetHostname              = "GetHostname"
	DeviceGetNetworkDefaultGateway = "GetNetworkDefaultGateway"
	DeviceGetNetworkInterfaces     = "GetNetworkInterfaces"
	DeviceGetNetworkProtocols      = "GetNetworkProtocols"
	DeviceGetNTP                   = "GetNTP"
	DeviceGetScopes                = "GetScopes"
	DeviceGetServices              = "GetServices"
	DeviceGetSystemDateAndTime     = "GetSystemDateAndTime"
	DeviceSetSystemDateAndTime     = "SetSystemDateAndTime"
	DeviceSystemReboot             = "SystemReboot"

	MediaGetAudioEncoderConfigurations       = "GetAudioEncoderConfigurations"
	MediaGetAudioSources                     = "GetAudioSources"
	MediaGetAudioSourceConfigurations        = "GetAudioSourceConfigurations"
	MediaGetProfile                          = "GetProfile"
	MediaGetProfiles                         = "GetProfiles"
	MediaGetSnapshotUri                      = "GetSnapshotUri"
	MediaGetStreamUri                        = "GetStreamUri"
	MediaGetVideoEncoderConfiguration        = "GetVideoEncoderConfiguration"
	MediaGetVideoEncoderConfigurations       = "GetVideoEncoderConfigurations"
	MediaGetVideoEncoderConfigurationOptions = "GetVideoEncoderConfigurationOptions"
	MediaGetVideoSources                     = "GetVideoSources"
	MediaGetVideoSourceConfiguration         = "GetVideoSourceConfiguration"
	MediaGetVideoSourceConfigurations        = "GetVideoSourceConfigurations"
)

ONVIF SOAP 操作名常量,与 go2rtc 对齐以便兼容 HA 等客户端。

Variables

This section is empty.

Functions

func FindTagValue

func FindTagValue(b []byte, tag string) string

FindTagValue 从 XML 中提取首个匹配标签的文本内容。

func GetCapabilitiesResponse

func GetCapabilitiesResponse(host string) []byte

GetCapabilitiesResponse 返回 Device/Media 服务地址,HA 依赖 Media 段。

func GetDeviceInformationResponse

func GetDeviceInformationResponse(manuf, model, firmware, serial string) []byte

GetDeviceInformationResponse 返回设备信息,SerialNumber 供 HA 作为唯一 ID。

func GetPosixTZ

func GetPosixTZ(current time.Time) string

GetPosixTZ 生成 ONVIF 要求的 POSIX 时区字符串。

func GetProfileResponse

func GetProfileResponse(token, name string) []byte

GetProfileResponse 返回单个 Profile。

func GetProfilesResponse

func GetProfilesResponse(profiles []StreamProfile) []byte

GetProfilesResponse 将全部流映射为 ONVIF Profile 列表。

func GetRequestAction

func GetRequestAction(b []byte) string

GetRequestAction 从 SOAP 请求体解析操作名(如 GetCapabilities)。

func GetScopesResponse

func GetScopesResponse(scopeName string) []byte

GetScopesResponse 返回设备 Scope 列表。

func GetServicesResponse

func GetServicesResponse(host string) []byte

GetServicesResponse 列出设备与媒体服务端点。

func GetSnapshotUriResponse

func GetSnapshotUriResponse(uri string) []byte

GetSnapshotUriResponse 返回截图 HTTP 地址。

func GetStreamUriResponse

func GetStreamUriResponse(uri string) []byte

GetStreamUriResponse 返回 RTSP 播放地址。

func GetSystemDateAndTimeResponse

func GetSystemDateAndTimeResponse() []byte

GetSystemDateAndTimeResponse 返回当前系统时间,HA 接入必需。

func GetVideoEncoderConfigurationResponse

func GetVideoEncoderConfigurationResponse() []byte

GetVideoEncoderConfigurationResponse 返回单个编码器配置。

func GetVideoEncoderConfigurationsResponse

func GetVideoEncoderConfigurationsResponse() []byte

GetVideoEncoderConfigurationsResponse 返回编码器配置列表。

func GetVideoSourceConfigurationResponse

func GetVideoSourceConfigurationResponse(name string) []byte

GetVideoSourceConfigurationResponse 返回单个视频源配置。

func GetVideoSourceConfigurationsResponse

func GetVideoSourceConfigurationsResponse(names []string) []byte

GetVideoSourceConfigurationsResponse 返回视频源配置列表。

func GetVideoSourcesResponse

func GetVideoSourcesResponse(names []string) []byte

GetVideoSourcesResponse 返回视频源列表。

func StaticResponse

func StaticResponse(operation, scopeName string) []byte

StaticResponse 返回预置或动态生成的静态 SOAP 响应。

Types

type Config

type Config struct {
	Manufacturer  string // 制造商
	Model         string // 型号
	Version       string // 固件版本
	SerialNumber  string // 序列号,HA 用作设备唯一标识
	ScopeName     string // GetScopes 中的 onvif name 段,默认 owl
	Username      string // WS-Security 用户名,与 Password 同时配置时启用鉴权
	Password      string // WS-Security 密码
	AdvertiseHost string // SOAP XAddr 对外 IP,请求 Host 为回环时替换
}

Config ONVIF 虚拟设备元数据。

func (Config) AuthEnabled

func (c Config) AuthEnabled() bool

AuthEnabled 是否在配置了用户名或密码时启用鉴权。

type Discovery

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

Discovery 在 UDP 3702 应答 Probe,供 HA 等客户端自动发现。

func NewDiscovery

func NewDiscovery(cfg DiscoveryConfig) (*Discovery, error)

NewDiscovery 创建 WS-Discovery 服务;HTTPPort 必须大于 0。

func (*Discovery) Start

func (d *Discovery) Start(ctx context.Context) error

Start 开始监听组播 Probe;ctx 取消时停止。

func (*Discovery) Stop

func (d *Discovery) Stop()

Stop 关闭组播监听。

type DiscoveryConfig

type DiscoveryConfig struct {
	HTTPPort   int    // SOAP 与 Web 共用端口,写入 XAddrs
	Host       string // 对外宣告 IP/主机名,空则按 Probe 来源网卡自动探测
	Name       string // onvif://www.onvif.org/name/ 段
	EndpointID string // wsa:Address,空则启动时生成 uuid
}

DiscoveryConfig WS-Discovery 服务端(对外广播本机 ONVIF 设备)配置。

type Envelope

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

Envelope 用于拼接 SOAP 响应体,避免 encoding/xml 的命名空间问题。

func NewEnvelope

func NewEnvelope() *Envelope

NewEnvelope 创建带标准 ONVIF 命名空间前缀的 SOAP 信封。

func (*Envelope) Append

func (e *Envelope) Append(args ...string)

func (*Envelope) Appendf

func (e *Envelope) Appendf(format string, args ...any)

func (*Envelope) Bytes

func (e *Envelope) Bytes() []byte

type Server

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

Server 可嵌入的 ONVIF Device/Media SOAP 服务端。

func New

func New(cfg Config, provider StreamProvider) *Server

New 创建 ONVIF 服务端;provider 不可为 nil。

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler 返回可挂到 /onvif/ 前缀的 HTTP 处理器。

type StreamProfile

type StreamProfile struct {
	Token string
	Name  string
}

StreamProfile 一条 ONVIF Profile:Token 必须唯一,Name 供客户端展示。

type StreamProvider

type StreamProvider interface {
	// ListStreamProfiles 返回全部通道对应的 Profile(含离线通道)。
	ListStreamProfiles() []StreamProfile
	// GetStreamURI 根据 Profile Token 与 HTTP Host 生成 RTSP 地址。
	GetStreamURI(profileToken, requestHost string) string
	// GetSnapshotURI 根据 Profile Token 与 HTTP Host 生成截图地址,无截图可返回空串。
	GetSnapshotURI(profileToken, requestHost string) string
}

StreamProvider 由宿主应用实现,向 ONVIF 服务端提供可暴露的流列表与地址。

Jump to

Keyboard shortcuts

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