dvr

package
v0.0.33 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package dvr implements the DVR (Digital Video Recorder).

Storage layout per stream:

./dvr/{streamCode}/
  index.json      — lightweight metadata: stream info, segment count, gaps
  playlist.m3u8   — HLS EVENT/VOD playlist with EXT-X-PROGRAM-DATE-TIME
  000000.ts
  000001.ts
  ...

index.json is intentionally lean — no per-segment details. Per-segment timeline (wall time, duration, discontinuity) lives in playlist.m3u8.

On server restart: index.json + playlist.m3u8 are read to resume state. The first new segment after resume is tagged #EXT-X-DISCONTINUITY.

On signal loss (gap > 2× segment duration): partial segment is flushed, TS muxer is reset, gap is recorded in index.json, next segment tagged #EXT-X-DISCONTINUITY with updated #EXT-X-PROGRAM-DATE-TIME.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SegmentMeta

type SegmentMeta struct {
	Index         int
	WallTime      time.Time
	Duration      time.Duration
	Discontinuity bool
}

SegmentMeta is the exported view of a parsed playlist segment.

type Service

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

Service manages DVR recording sessions.

func New

func New(i do.Injector) (*Service, error)

New creates a Service and registers it with the DI injector.

func NewForTesting added in v0.0.23

func NewForTesting(buf *buffer.Service, bus events.Bus, m *metrics.Metrics, recRepo store.RecordingRepository) *Service

NewForTesting builds a Service from pre-constructed deps. Used by unit tests that wire fakes / minimal real implementations and skip the DI plumbing.

func (*Service) IsRecording

func (s *Service) IsRecording(streamID domain.StreamCode) bool

IsRecording reports whether there is an active recording session for streamID.

func (*Service) LoadIndex

func (s *Service) LoadIndex(segDir string) (*domain.DVRIndex, error)

LoadIndex reads index.json for a stream's recording directory. Exported for the API info handler.

func (*Service) ParsePlaylist

func (s *Service) ParsePlaylist(segDir string) ([]SegmentMeta, error)

ParsePlaylist reads playlist.m3u8 and returns the ordered segment metadata. Exported for the timeshift handler.

func (*Service) StartRecording

func (s *Service) StartRecording(ctx context.Context, streamID domain.StreamCode, mediaBufferID domain.StreamCode, dvrCfg *domain.StreamDVRConfig) (*domain.Recording, error)

StartRecording begins (or resumes) recording for the given stream.

func (*Service) StopRecording

func (s *Service) StopRecording(ctx context.Context, streamID domain.StreamCode) error

StopRecording stops the active recording and writes a final VOD playlist.

Jump to

Keyboard shortcuts

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