Documentation
¶
Overview ¶
Package recording 视频录制管理领域
负责管理流媒体录像文件的生命周期,包括: - 接收 ZLM on_record_mp4 回调,将录像信息持久化到数据库 - 控制录制的启动和停止(流注册时自动录制) - 提供录像列表查询和时间轴数据接口 - 基于磁盘空间阈值和保留天数自动清理过期录像
Code generated by godddx, DO AVOID EDIT.
Index ¶
- type AddRecordingInput
- type Core
- func (c Core) AddRecording(ctx context.Context, in *AddRecordingInput) (*Recording, error)
- func (c Core) DelRecording(ctx context.Context, id int64) (*Recording, error)
- func (c Core) EditRecording(ctx context.Context, in *EditRecordingInput, id int64) (*Recording, error)
- func (c Core) FindRecordings(ctx context.Context, in *FindRecordingInput) ([]*Recording, int64, 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) StartCleanupWorker()
- func (c Core) StartRecording(ctx context.Context, channelType, app, stream string) error
- func (c Core) StopRecording(ctx context.Context, app, stream string) error
- type EditRecordingInput
- type FindRecordingInput
- type MonthlyStatsInput
- type MonthlyStatsOutput
- type Option
- 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 Core ¶
type Core struct {
// contains filtered or unexported fields
}
Core business domain
func (Core) AddRecording ¶
AddRecording Insert into database
func (Core) DelRecording ¶
DelRecording Delete object
func (Core) EditRecording ¶
func (c Core) EditRecording(ctx context.Context, in *EditRecordingInput, id int64) (*Recording, error)
EditRecording Update object information
func (Core) FindRecordings ¶
func (c Core) FindRecordings(ctx context.Context, in *FindRecordingInput) ([]*Recording, int64, error)
FindRecordings 分页查询录像列表,支持通道ID和时间范围筛选
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) StartCleanupWorker ¶
func (c Core) StartCleanupWorker()
StartCleanupWorker 启动定时清理协程 常规每 10 分钟检查一次,磁盘超标时缩短到 2 分钟加速清理
func (Core) StartRecording ¶
StartRecording 启动录制,在流注册时调用 根据配置决定是否录制该流,并通知 ZLM 开始 MP4 录制
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 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 WithSMSProvider ¶
func WithSMSProvider(provider SMSProvider) Option
WithSMSProvider 注入流媒体服务提供者,用于控制录制
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 {
Find(context.Context, *[]*Recording, orm.Pager, ...orm.QueryOption) (int64, error)
Get(context.Context, *Recording, ...orm.QueryOption) error
Add(context.Context, *Recording) error
Edit(context.Context, *Recording, func(*Recording), ...orm.QueryOption) error
Del(context.Context, *Recording, ...orm.QueryOption) error
Count(context.Context, ...orm.QueryOption) (int64, error)
Session(context.Context, ...func(*gorm.DB) error) error
EditWithSession(*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
}
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. |