Files
go-mxl-player/internal/playback/video.go
T
2026-09-01 23:45:10 +03:00

55 lines
1.5 KiB
Go

package playback
import "context"
type videoSourceContextKey struct{}
func withVideoSource(ctx context.Context, source FeedConfig) context.Context {
return context.WithValue(ctx, videoSourceContextKey{}, source)
}
func videoSourceFromContext(ctx context.Context) FeedConfig {
source, _ := ctx.Value(videoSourceContextKey{}).(FeedConfig)
return source
}
// VideoFrame contains metadata and borrowed source payload.
//
// Payload is valid only until the next VideoReader.ReadVideo call or until the
// reader is closed. Consumers must finish reading Payload before returning
// control to the worker
type VideoFrame struct {
Index uint64
Width uint32
Height uint32
Stride uint32
Size uint32
Invalid bool
Label string
FrameRateNumerator int64
FrameRateDenominator int64
Payload []byte
}
// VideoReader reads frames from a video source.
//
// ReadVideo must not be called again until the previous frame's payload has
// been consumed.
type VideoReader interface {
ReadVideo(context.Context) (VideoFrame, error)
Close() error
}
// VideoReaderFactory opens a reader for the configured video feed.
type VideoReaderFactory interface {
OpenVideo(context.Context, FeedConfig) (VideoReader, error)
}
// VideoSink consumes a borrowed video frame.
//
// ConsumeVideo must finish using frame.Payload before returning and must never
// retain it for asynchronous use.
type VideoSink interface {
ConsumeVideo(context.Context, VideoFrame) error
}