Documentation
¶
Overview ¶
Package recording 视频录制管理领域
负责管理流媒体录像文件的生命周期,包括: - 接收 ZLM on_record_mp4 回调,将录像信息持久化到数据库 - 控制录制的启动和停止(流注册时自动录制) - 提供录像列表查询和时间轴数据接口 - 基于磁盘空间阈值和保留天数自动清理过期录像
Code generated by godddx, DO AVOID EDIT.
Index ¶
- type AddRecordingInput
- type ChannelInfo
- type Core
- func (c Core) CreateRecording(ctx context.Context, in *AddRecordingInput) (*Recording, error)
- func (c Core) DeleteRecording(ctx context.Context, id int64) (*Recording, error)
- func (c Core) GetFullPath(relativePath string) string
- func (c Core) GetMonthlyStats(ctx context.Context, in *MonthlyStatsInput) (*MonthlyStatsOutput, error)
- func (c Core) GetRecording(ctx context.Context, id int64) (*Recording, error)
- func (c Core) GetTimeline(ctx context.Context, in *TimelineInput) ([]TimeRange, error)
- func (c Core) HasRecordings(ctx context.Context, cids []string) (map[string]bool, error)
- func (c Core) IsEnabled() bool
- func (c Core) ListRecordings(ctx context.Context, in *FindRecordingInput) ([]*Recording, int64, error)
- func (c Core) StartCleanupWorker()
- func (c Core) StartRecording(ctx context.Context, channelType, app, stream string) error
- func (c Core) StartRecordingSyncLoop(ctx context.Context)
- func (c Core) StopRecording(ctx context.Context, app, stream string) error
- func (c Core) UpdateRecording(ctx context.Context, in *EditRecordingInput, id int64) (*Recording, error)
- type EditRecordingInput
- type FindRecordingInput
- type IPCProvider
- type MonthlyStatsInput
- type MonthlyStatsOutput
- type Option
- type PlayProvider
- type Recording
- type RecordingStorer
- type SMSProvider
- type Storer
- type TimeRange
- type TimelineInput
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddRecordingInput ¶
type AddRecordingInput struct {
CID string `json:"-"` // 通道 ID(由 API 层填充)
App string `json:"app"` // ZLM 应用名
Stream string `json:"stream"` // ZLM 流 ID
StartedAt orm.Time `json:"started_at"` // 录像开始时间
EndedAt orm.Time `json:"ended_at"` // 录像结束时间
Duration float64 `json:"duration"` // 持续时长(秒)
Path string `json:"path"` // 文件相对路径
Size int64 `json:"size"` // 文件大小(字节)
}
type ChannelInfo ¶ added in v1.4.21
type ChannelInfo struct {
ID string // 通道唯一 ID
App string // 应用名(如 rtp / live)
Stream string // 流 ID
Type string // 通道类型(gb28181 / onvif / rtmp / rtsp)
RecordMode string // 录像模式(always / ai / none / 空串=always)
}
ChannelInfo 同步任务使用的通道信息摘要
type Core ¶
type Core struct {
// contains filtered or unexported fields
}
Core business domain
func (Core) CreateRecording ¶ added in v1.4.21
CreateRecording Insert into database
func (Core) DeleteRecording ¶ added in v1.4.21
DeleteRecording Delete object
func (Core) GetFullPath ¶
GetFullPath 获取录像文件的完整路径 relativePath 可能是相对于 StorageDir 的路径,也可能是完整路径
func (Core) GetMonthlyStats ¶
func (c Core) GetMonthlyStats(ctx context.Context, in *MonthlyStatsInput) (*MonthlyStatsOutput, error)
GetMonthlyStats 获取月度录像统计 返回指定月份每天是否有录像的位图字符串
func (Core) GetRecording ¶
GetRecording Query a single object
func (Core) GetTimeline ¶
GetTimeline 获取时间轴数据,返回指定时间范围内的录像时段列表
func (Core) HasRecordings ¶
HasRecordings 批量检查通道是否有录像 使用 WHERE IN + GROUP BY 一次性查询所有通道是否有录像
func (Core) ListRecordings ¶ added in v1.4.21
func (c Core) ListRecordings(ctx context.Context, in *FindRecordingInput) ([]*Recording, int64, error)
ListRecordings 分页查询录像列表,支持通道ID和时间范围筛选
func (Core) StartCleanupWorker ¶
func (c Core) StartCleanupWorker()
StartCleanupWorker 启动定时清理协程 常规每 10 分钟检查一次,磁盘超标时缩短到 2 分钟加速清理
func (Core) StartRecording ¶
StartRecording 启动录制,在流注册时调用 根据配置决定是否录制该流,并通知 ZLM 开始 MP4 录制
func (Core) StartRecordingSyncLoop ¶ added in v1.4.21
StartRecordingSyncLoop 启动录制同步协程 延迟 syncInitialDelay 后首次执行,之后每 syncInterval 同步一次 确保录制状态与通道配置一致,覆盖平台重启、ZLM 重启、流中断等异常场景
func (Core) StopRecording ¶
StopRecording 停止录制,在流注销时调用 流不存在时视为已停止(幂等),打 debug 而非 error
func (Core) UpdateRecording ¶ added in v1.4.21
func (c Core) UpdateRecording(ctx context.Context, in *EditRecordingInput, id int64) (*Recording, error)
UpdateRecording Update object information
type EditRecordingInput ¶
type EditRecordingInput struct {
ObjectCount int `json:"object_count"` // AI检测对象数量(从event表统计)
}
type FindRecordingInput ¶
type FindRecordingInput struct {
web.PagerFilter
web.DateFilter
CID string `form:"cid"` // 通道 ID (channel.ID)
App string `form:"app"` // ZLM 应用名
Stream string `form:"stream"` // ZLM 流 ID
}
type IPCProvider ¶ added in v1.4.21
type IPCProvider interface {
ListOnlineChannels(ctx context.Context) ([]ChannelInfo, error)
}
IPCProvider 通道信息提供者,解耦录制域与 ipc 域 用于定时同步时查询所有在线通道
type MonthlyStatsInput ¶
type MonthlyStatsInput struct {
CID string `form:"cid"` // 通道 ID(可选,不传则查所有通道)
Year int `form:"year"` // 年份,如 2024
Month int `form:"month"` // 月份,1-12
}
MonthlyStatsInput 月度统计查询参数
type MonthlyStatsOutput ¶
type MonthlyStatsOutput struct {
Year int `json:"year"` // 年份
Month int `json:"month"` // 月份
Days int `json:"days"` // 该月总天数
HasVideo string `json:"has_video"` // 位图字符串,如 "10101010..." 第 1 天有录像则第 1 位为 1
}
MonthlyStatsOutput 月度统计输出
type Option ¶
type Option func(*Core)
func WithIPCProvider ¶ added in v1.4.21
func WithIPCProvider(provider IPCProvider) Option
WithIPCProvider 注入通道信息提供者,用于定时同步时查询应录制的通道
func WithPlayProvider ¶ added in v1.4.21
func WithPlayProvider(provider PlayProvider) Option
WithPlayProvider 注入拉流能力,用于流不存在时主动触发拉流
func WithSMSProvider ¶
func WithSMSProvider(provider SMSProvider) Option
WithSMSProvider 注入流媒体服务提供者,用于控制录制
func WithSyncInterval ¶ added in v1.4.21
WithSyncInterval 设置同步周期,用于测试时缩短等待时间
type PlayProvider ¶ added in v1.4.21
type PlayProvider interface {
TriggerStream(ctx context.Context, info ChannelInfo) error
}
PlayProvider 主动拉流能力,解耦录制域与播放域 仅用于"应录制但流不存在"时触发拉流
type Recording ¶
type Recording struct {
ID int64 `gorm:"primaryKey" json:"id"`
CID string `gorm:"column:cid;notNull;index;default:'';comment:通道 ID (channel.ID)" json:"cid"` // 通道 ID (channel.ID)
App string `gorm:"column:app;notNull;default:'';comment:ZLM 应用名" json:"app"` // ZLM 应用名
Stream string `gorm:"column:stream;notNull;default:'';comment:ZLM 流 ID" json:"stream"` // ZLM 流 ID
StartedAt orm.Time `gorm:"column:started_at;notNull;index;default:CURRENT_TIMESTAMP;comment:录像开始时间" json:"started_at"` // 录像开始时间
EndedAt orm.Time `gorm:"column:ended_at;notNull;default:CURRENT_TIMESTAMP;comment:录像结束时间" json:"ended_at"` // 录像结束时间
Duration float64 `gorm:"column:duration;notNull;default:0;comment:持续时长(秒)" json:"duration"` // 持续时长(秒)
Path string `gorm:"column:path;notNull;default:'';comment:文件相对路径" json:"path"` // 文件相对路径
Size int64 `gorm:"column:size;notNull;default:0;index;comment:文件大小(字节)" json:"size"` // 文件大小(字节)
ObjectCount int `gorm:"column:object_count;notNull;default:0;comment:AI检测对象数量(从event表统计)" json:"object_count"` // AI检测对象数量(从event表统计)
DeleteFlag bool `gorm:"column:delete_flag;notNull;default:false;comment:待删除标记" json:"delete_flag"` // 待删除标记(即将被清理)
CreatedAt orm.Time `gorm:"column:created_at;notNull;default:CURRENT_TIMESTAMP" json:"created_at"`
UpdatedAt orm.Time `gorm:"column:updated_at;notNull;default:CURRENT_TIMESTAMP" json:"updated_at"`
}
Recording domain model
type RecordingStorer ¶
type RecordingStorer interface {
List(context.Context, *[]*Recording, orm.Pager, ...orm.QueryOption) (int64, error)
Get(context.Context, *Recording, ...orm.QueryOption) error
Create(context.Context, *Recording) error
Update(context.Context, *Recording, func(*Recording), ...orm.QueryOption) error
Delete(context.Context, *Recording, ...orm.QueryOption) error
Count(context.Context, ...orm.QueryOption) (int64, error)
Session(context.Context, ...func(*gorm.DB) error) error
UpdateWithSession(*gorm.DB, *Recording, func(b *Recording) error, ...orm.QueryOption) error
}
RecordingStorer Instantiation interface
type SMSProvider ¶
type SMSProvider interface {
StartRecord(app, stream, customPath string, maxSecond int) error
StopRecord(app, stream string) error
// ListRecordingStreams 批量获取所有在线流的录制状态
// 返回 map[app/stream]bool,true 表示正在录制 MP4
ListRecordingStreams() (map[string]bool, error)
}
SMSProvider 流媒体服务提供者接口,解耦录制领域与 sms 领域
type TimeRange ¶
type TimeRange struct {
ID int64 `json:"id"` // 录像记录 ID
StartMs int64 `json:"start_ms"` // 开始时间(毫秒时间戳)
EndMs int64 `json:"end_ms"` // 结束时间(毫秒时间戳)
Duration float64 `json:"duration"` // 时长(秒)
ObjectCount int `json:"object_count"` // AI检测对象数量
DeleteFlag bool `json:"delete_flag"` // 待删除标记(已被标记即将清理)
}
TimeRange 时间轴数据项,表示一段录像的时间范围
type TimelineInput ¶
type TimelineInput struct {
web.DateFilter
CID string `form:"cid"` // 通道 ID
}
TimelineInput 时间轴查询参数
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
store
|
|
|
recordingcache
Code generated by godddx, DO AVOID EDIT.
|
Code generated by godddx, DO AVOID EDIT. |
|
recordingdb
Code generated by godddx, DO AVOID EDIT.
|
Code generated by godddx, DO AVOID EDIT. |