helpers

package
v0.0.0-...-70b8bd4 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultChunkBytes         = 16000
	DefaultMaxBytes           = 1440000
	DefaultTrimBytes          = 1120000
	DefaultProcessingInterval = 2000
	DefaultMediaType          = "audio"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseMediaProcessor

type BaseMediaProcessor struct {
	Lock          sync.Mutex
	ChunkBytes    int
	MaxBytes      int
	TrimBytes     int
	ChunkBuf      []byte
	NewBytes      int
	OutputChannel chan *Event
	StopChannel   chan struct{}
	// contains filtered or unexported fields
}

BaseMediaProcessor is the abstract base for all media processors It provides common fields and functionality for accumulating and emitting data

func NewBaseMediaProcessor

func NewBaseMediaProcessor(chunkBytes, maxBytes, trimBytes int) *BaseMediaProcessor

NewBaseMediaProcessor creates a new base media processor with default channels

func (*BaseMediaProcessor) BaseStart

func (bmp *BaseMediaProcessor) BaseStart(interval time.Duration, loopFunc func(time.Duration))

BaseStart starts the processor's event loop Subclasses should override the loop method for specific behavior

func (*BaseMediaProcessor) CommonEventLoop

func (bmp *BaseMediaProcessor) CommonEventLoop(interval time.Duration, emitter func() *Event)

CommonEventLoop provides the standard event loop behavior Used by both audio and video processors

func (*BaseMediaProcessor) GetPipeline

func (bmp *BaseMediaProcessor) GetPipeline() any

GetPipeline returns the underlying media pipeline processor

func (*BaseMediaProcessor) Output

func (bmp *BaseMediaProcessor) Output() <-chan *Event

Output returns the output channel for processed events

func (*BaseMediaProcessor) SetPipeline

func (bmp *BaseMediaProcessor) SetPipeline(p any)

SetPipeline sets the underlying media pipeline processor

func (*BaseMediaProcessor) Stop

func (bmp *BaseMediaProcessor) Stop()

Stop signals the processor to stop processing

type Configuration

type Configuration struct {
	trigger.Configuration

	RTSPURL            string        `mapstructure:"rtsp_url"`
	ChunkBytes         int           `mapstructure:"chunk_bytes"`
	MaxBytes           int           `mapstructure:"max_bytes"`
	TrimBytes          int           `mapstructure:"trim_bytes"`
	ProcessingInterval time.Duration `mapstructure:"processing_interval"`
	MediaType          string        `mapstructure:"media_type"` // "audio" or "video"
	// Output             map[string]any     `mapstructure:"output"`
	Sink *SinkConfiguration `mapstructure:"sink"`
}

func NewConfiguration

func NewConfiguration(id string,
	triggerConfiguration *functionconfig.Trigger,
	runtimeConfiguration *runtime.Configuration) (*Configuration, error)

type Event

type Event struct {
	nuclio.AbstractEvent
	Body       []byte
	Attributes map[string]any
	Timestamp  time.Time
}

Event wraps audio packet data from RTSP stream

func (*Event) GetBody

func (e *Event) GetBody() []byte

GetBody returns the audio packet data

func (*Event) GetContentType

func (e *Event) GetContentType() string

GetContentType returns the content type of the audio packet

func (*Event) GetField

func (e *Event) GetField(key string) any

GetField returns an attribute by key

func (*Event) GetFieldByteSlice

func (e *Event) GetFieldByteSlice(key string) []byte

GetFieldByteSlice returns an attribute value as a byte slice

func (*Event) GetFieldInt

func (e *Event) GetFieldInt(key string) (int, error)

GetFieldInt returns an attribute value as an int

func (*Event) GetFieldString

func (e *Event) GetFieldString(key string) string

GetFieldString returns an attribute value as a string

func (*Event) GetFields

func (e *Event) GetFields() map[string]any

GetFields returns all attributes

func (*Event) GetHeader

func (e *Event) GetHeader(key string) any

GetHeader returns a header value as an any

func (*Event) GetHeaderByteSlice

func (e *Event) GetHeaderByteSlice(key string) []byte

GetHeaderByteSlice returns a header value as a byte slice

func (*Event) GetHeaderInt

func (e *Event) GetHeaderInt(key string) (int, error)

GetHeaderInt returns a header value as an int

func (*Event) GetHeaderString

func (e *Event) GetHeaderString(key string) string

GetHeaderString returns a header value as a string

func (*Event) GetHeaders

func (e *Event) GetHeaders() map[string]any

GetHeaders returns all attributes as headers

func (*Event) GetMethod

func (e *Event) GetMethod() string

GetMethod returns "rtsp" as the method

func (*Event) GetPath

func (e *Event) GetPath() string

GetPath returns empty path (not applicable for RTSP)

func (*Event) GetTimestamp

func (e *Event) GetTimestamp() time.Time

GetTimestamp returns the packet timestamp

type MediaPipeline

type MediaPipeline struct {
	Depacketizers map[uint8]any
}

MediaPipeline handles RTP depacketization and format-specific processing

func NewMediaPipeline

func NewMediaPipeline(medias []*description.Media) (*MediaPipeline, error)

NewMediaPipeline creates a media pipeline for processing RTP streams

func (*MediaPipeline) ProcessRTP

func (mp *MediaPipeline) ProcessRTP(pkt *rtp.Packet, forma format.Format) (any, error)

ProcessRTP handles generic RTP packet processing (audio, H265, etc.)

type MediaProcessor

type MediaProcessor interface {
	// Start begins processing with specified interval
	Start(interval time.Duration)
	// Stop signals the processor to stop
	Stop()
	// ProcessRTP decodes an RTP packet based on format type
	ProcessRTP(pkt *rtp.Packet, forma format.Format) (any, error)
	// Push adds data to be processed
	Push(data any)
	// Output returns the channel for processed events
	Output() <-chan *Event
	// SetPipeline sets the underlying media pipeline processor
	SetPipeline(p any)
}

MediaProcessor defines the interface for processing media data (audio or video) It handles both RTP packet depacketization and buffered event emission

type SinkConfiguration

type SinkConfiguration struct {
	Kind       string         `mapstructure:"kind"`
	Attributes map[string]any `mapstructure:"attributes"`
}

SinkConfiguration holds the sink config for the trigger (optional)

Jump to

Keyboard shortcuts

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