Documentation
¶
Index ¶
- Constants
- func V4L2DiscoverDevices() (map[string]V4L2Capability, error)
- type CameraCoordinator
- type CameraDetector
- type CameraEvent
- type CameraEventType
- type DBusNotifier
- type DBusNotifierSignalBody
- type EBPFVb2IoctlStreamDetector
- type Notifier
- type PrintNotifier
- type ScriptNotifier
- type ScriptNotifierConfig
- type V4L2Capability
- type V4L2CapabilityCapabilities
Constants ¶
const ( // DBusObjectPath is the object path used when emitting signals. DBusObjectPath = dbus.ObjectPath("/io/github/shuhaowu/CameraCoordinator") // DBusInterface is the DBus interface name for signals emitted by the // notifier. DBusInterface = "io.github.shuhaowu.CameraCoordinator" // DBusMemberName is the member name for signals emitted by the notifier. DBusMemberName = "CameraEvent" // DBusSignalName is the fully-qualified signal name (interface.Signal). DBusSignalName = DBusInterface + "." + DBusMemberName )
const VIDIOC_QUERYCAP = 0x80685600
https://github.com/torvalds/linux/blob/d79526b89571ae447c1a5cfd3d627efa07098348/include/uapi/linux/videodev2.h#L2730 Number is derived from _IOR('V', 0, struct v4l2_capability) in the kernel headers. This is AI generated and it seems to work. Linux should also be ABI stable.
Variables ¶
This section is empty.
Functions ¶
func V4L2DiscoverDevices ¶
func V4L2DiscoverDevices() (map[string]V4L2Capability, error)
Types ¶
type CameraCoordinator ¶
type CameraCoordinator struct {
// contains filtered or unexported fields
}
CameraCoordinator aggregates one or more detector event streams into a single logical view of camera state. It deduplicates events across detectors (emits one RecordingOn when the first detector goes active for a device, one RecordingOff when the last one goes inactive) and fans out the resulting events to a set of output channels provided at construction time.
func NewCameraCoordinator ¶
func NewCameraCoordinator(outputs []chan CameraEvent) *CameraCoordinator
NewCameraCoordinator creates a CameraCoordinator that fans out deduplicated camera events to the supplied output channels.
func (*CameraCoordinator) Run ¶
func (c *CameraCoordinator) Run(ctx context.Context, events <-chan CameraEvent) error
Run monitors the supplied events channel for camera on/off events and statefully emits coordinator-level on/off events to the output channels provided at construction time.
The caller is responsible for starting the detectors and providing their combined events channel. Run returns when ctx is cancelled or events is closed (i.e. all detectors have finished).
A camera on event is generated on the first event from the detectors for that device. A camera off event is generated on the last event from the detectors for that device.
The events in the buffer are not guaranteed to be processed on context cancellation.
Run can only be called once.
type CameraDetector ¶
type CameraDetector interface {
Run(context.Context, chan<- CameraEvent) error
Name() string
}
type CameraEvent ¶
type CameraEvent struct {
// The string identifying the detector that emitted this event. This is useful for debugging.
Detector string
// The type of the event.
Type CameraEventType
// The video device file associated with this event, e.g. "video0".
VideoDevice string
// The card name from the V4L2 capability. Populated by the coordinator;
// may be empty when the event originates directly from a detector or in tests.
Card string
// The bus info from the V4L2 capability. Populated by the coordinator;
// may be empty when the event originates directly from a detector or in tests.
BusInfo string
}
type CameraEventType ¶
type CameraEventType uint32
const ( // Synchronize this with camera_event_type in bpf/camera_detector_vb2_ioctl.bpf.c CameraEventRecordingOn CameraEventType = 1 CameraEventRecordingOff CameraEventType = 2 )
func (CameraEventType) String ¶
func (t CameraEventType) String() string
type DBusNotifier ¶
type DBusNotifier struct{}
DBusNotifier is a Notifier that emits a CameraEvent signal on the system DBus bus whenever a camera recording starts or stops.
func (*DBusNotifier) Run ¶
func (d *DBusNotifier) Run(ctx context.Context, events <-chan CameraEvent) error
Run connects to the system bus, claims the well-known name, and listens for CameraEvents, emitting a DBus signal for each one until ctx is cancelled or the events channel is closed.
type DBusNotifierSignalBody ¶
type DBusNotifierSignalBody struct {
Detector string
Type uint32
VideoDevice string
Card string
BusInfo string
}
DBusNotifierSignalBody is the structured payload carried by every CameraEvent DBus signal.
type EBPFVb2IoctlStreamDetector ¶
type EBPFVb2IoctlStreamDetector struct {
// contains filtered or unexported fields
}
func NewEBPFVb2IoctlStreamDetector ¶
func NewEBPFVb2IoctlStreamDetector() *EBPFVb2IoctlStreamDetector
func (*EBPFVb2IoctlStreamDetector) Name ¶
func (d *EBPFVb2IoctlStreamDetector) Name() string
func (*EBPFVb2IoctlStreamDetector) Run ¶
func (d *EBPFVb2IoctlStreamDetector) Run(ctx context.Context, ch chan<- CameraEvent) error
type Notifier ¶
type Notifier interface {
// Run reads from events and processes them until ctx is cancelled or the
// channel is closed. It is designed to be called in a goroutine.
Run(ctx context.Context, events <-chan CameraEvent) error
}
Notifier processes camera events from a CameraCoordinator. Implementations are intended to be started in a background goroutine via Run.
type PrintNotifier ¶
type PrintNotifier struct{}
PrintNotifier is a Notifier that logs camera recording on/off events using slog.
func NewPrintNotifier ¶
func NewPrintNotifier() *PrintNotifier
func (*PrintNotifier) Run ¶
func (p *PrintNotifier) Run(ctx context.Context, events <-chan CameraEvent) error
Run logs each CameraEvent until ctx is cancelled or events is closed.
type ScriptNotifier ¶
type ScriptNotifier struct {
// contains filtered or unexported fields
}
ScriptNotifier is a Notifier that executes shell scripts on camera recording on/off events.
func NewScriptNotifier ¶
func NewScriptNotifier(cfg ScriptNotifierConfig) *ScriptNotifier
NewScriptNotifier creates a ScriptNotifier with the given configuration.
func (*ScriptNotifier) Run ¶
func (s *ScriptNotifier) Run(ctx context.Context, events <-chan CameraEvent) error
Run listens for CameraEvents and executes the configured scripts until ctx is cancelled or the events channel is closed.
type ScriptNotifierConfig ¶
type ScriptNotifierConfig struct {
// OnScript is the path to the script to run when recording starts.
// If empty, no script is run.
OnScript string
// OffScript is the path to the script to run when recording stops.
// If empty, no script is run.
OffScript string
// BaseDir is the directory where the JSON config file was located. If
// a script path starts with "./" it will be resolved relative to this
// directory.
BaseDir string
}
ScriptNotifierConfig holds the paths to scripts to run on camera events.
type V4L2Capability ¶
type V4L2Capability struct {
Driver [16]uint8
Card [32]uint8
BusInfo [32]uint8
Version uint32
Capabilities uint32
DeviceCaps uint32
Reserved [3]uint32
// contains filtered or unexported fields
}
https://docs.kernel.org/userspace-api/media/v4l/vidioc-querycap.html#c.V4L.V4L2Capability
func V4L2DeviceCapability ¶
func V4L2DeviceCapability(filename string) (V4L2Capability, error)
QueryDevice returns V4L2 capability information for the given device path.
func (V4L2Capability) BusInfoString ¶
func (c V4L2Capability) BusInfoString() string
func (V4L2Capability) CardString ¶
func (c V4L2Capability) CardString() string
func (V4L2Capability) DriverString ¶
func (c V4L2Capability) DriverString() string
func (V4L2Capability) HasCapabilities ¶
func (c V4L2Capability) HasCapabilities(caps ...V4L2CapabilityCapabilities) bool
func (V4L2Capability) VersionString ¶
func (c V4L2Capability) VersionString() string
type V4L2CapabilityCapabilities ¶
type V4L2CapabilityCapabilities uint32
const ( V4L2CapVideoCapture V4L2CapabilityCapabilities = 0x00000001 V4L2CapVideoCaptureMplane V4L2CapabilityCapabilities = 0x00001000 V4L2CapVideoOutput V4L2CapabilityCapabilities = 0x00000002 V4L2CapVideoOutputMplane V4L2CapabilityCapabilities = 0x00002000 V4L2CapVideoM2M V4L2CapabilityCapabilities = 0x00008000 V4L2CapVideoM2MMplane V4L2CapabilityCapabilities = 0x00004000 V4L2CapVideoOverlay V4L2CapabilityCapabilities = 0x00000004 V4L2CapVbiCapture V4L2CapabilityCapabilities = 0x00000010 V4L2CapVbiOutput V4L2CapabilityCapabilities = 0x00000020 V4L2CapSlicedVbiCapture V4L2CapabilityCapabilities = 0x00000040 V4L2CapSlicedVbiOutput V4L2CapabilityCapabilities = 0x00000080 V4L2CapRdsCapture V4L2CapabilityCapabilities = 0x00000100 V4L2CapVideoOutputOverlay V4L2CapabilityCapabilities = 0x00000200 V4L2CapHwFreqSeek V4L2CapabilityCapabilities = 0x00000400 V4L2CapRdsOutput V4L2CapabilityCapabilities = 0x00000800 V4L2CapTuner V4L2CapabilityCapabilities = 0x00010000 V4L2CapAudio V4L2CapabilityCapabilities = 0x00020000 V4L2CapRadio V4L2CapabilityCapabilities = 0x00040000 V4L2CapModulator V4L2CapabilityCapabilities = 0x00080000 V4L2CapSdrCapture V4L2CapabilityCapabilities = 0x00100000 V4L2CapExtPixFormat V4L2CapabilityCapabilities = 0x00200000 V4L2CapSdrOutput V4L2CapabilityCapabilities = 0x00400000 V4L2CapMetaCapture V4L2CapabilityCapabilities = 0x00800000 V4L2CapReadwrite V4L2CapabilityCapabilities = 0x01000000 V4L2CapEdid V4L2CapabilityCapabilities = 0x02000000 V4L2CapStreaming V4L2CapabilityCapabilities = 0x04000000 V4L2CapMetaOutput V4L2CapabilityCapabilities = 0x08000000 V4L2CapTouch V4L2CapabilityCapabilities = 0x10000000 V4L2CapIoMc V4L2CapabilityCapabilities = 0x20000000 V4L2CapDeviceCaps V4L2CapabilityCapabilities = 0x80000000 )
