avfoundation

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: MIT Imports: 9 Imported by: 1

Documentation

Rendered for darwin/amd64

Overview

Package avfoundation provides AVFoundation binding for Go

Index

Constants

Variables

This section is empty.

Functions

func DestroyObserver added in v0.9.0

func DestroyObserver() error

DestroyObserver destroys the device observer and releases all C/Objective-C resources. The observer is single-use and cannot be restarted after being destroyed. Safe to call concurrently and idempotently.

func IsObserverRunning added in v0.9.0

func IsObserverRunning() bool

IsObserverRunning reports whether the device observer has successfully started and populated the in-memory cache.

func SetOnDeviceChange added in v0.9.0

func SetOnDeviceChange(f func(Device, DeviceEventType))

func SetupObserver added in v0.9.0

func SetupObserver() error

SetupObserver initializes the device observer and starts a goroutine locked to a thread for NSRunLoop, but does not begin pumping the run loop yet. The goroutine waits idle until StartObserver is called, avoiding CPU overhead. Safe to call concurrently and idempotently.

func StartObserver added in v0.9.0

func StartObserver() error

StartObserver signals the observer goroutine to begin pumping the run loop. If SetupObserver has not been called, StartObserver will call it first. Safe to call concurrently and idempotently.

Types

type Device

type Device struct {
	// UID is a unique identifier for a device
	UID string

	Name string
	// contains filtered or unexported fields
}

Device represents a metadata that later can be used to retrieve back the underlying device given by AVFoundation

func Devices

func Devices(mediaType MediaType) ([]Device, error)

Devices uses AVFoundation to query a list of devices based on the media type

func LookupCachedDevice added in v0.9.0

func LookupCachedDevice(uid string) (Device, bool)

LookupCachedDevice returns the cached device that matches the provided UID. The returned boolean indicates whether the device was present in the cache. Callers should verify IsObserverRunning before relying on the result.

type DeviceEventType added in v0.9.0

type DeviceEventType int
const (
	DeviceEventConnected    DeviceEventType = C.DeviceEventConnected
	DeviceEventDisconnected DeviceEventType = C.DeviceEventDisconnected
)

type MediaType

type MediaType C.AVBindMediaType

type ReadCloser

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

ReadCloser is a wrapper around the data callback from AVFoundation. The data received from the the underlying callback can be retrieved by calling Read.

func (*ReadCloser) Close

func (rc *ReadCloser) Close()

Close closes the capturing session, and no data will flow anymore

func (*ReadCloser) Read

func (rc *ReadCloser) Read() ([]byte, func(), error)

Read reads raw data, the format is determined by the media type and property:

  • For video, each call will return a frame.
  • For audio, each call will return a chunk which its size configured by Latency

func (*ReadCloser) ReadContext added in v0.8.0

func (rc *ReadCloser) ReadContext(ctx context.Context) ([]byte, func(), error)

ReadContext is Read but with a context for better error handling e.g. timeout, cancellation, etc.

type Session

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

Session represents a capturing session.

func NewSession

func NewSession(device Device) (*Session, error)

NewSession creates a new capturing session

func (*Session) Close

func (session *Session) Close() error

Close stops capturing session and frees up resources

func (*Session) Open

func (session *Session) Open(property prop.Media) (*ReadCloser, error)

Open start capturing session. As soon as it returns successfully, the data will start flowing. The raw data can be retrieved by using ReadCloser's Read method.

func (*Session) Properties

func (session *Session) Properties() []prop.Media

Properties queries a list of properties that device supports

Jump to

Keyboard shortcuts

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