Overview
FunctionFilter is a flexible processor that uses a custom async function to determine which frames to pass through. This allows for complex, dynamic filtering logic beyond simple type checking.
Constructor Parameters
Callable[[Frame], Awaitable[bool]]
required
Async function that examines each frame and returns True to allow it or False
to filter it out
FrameDirection | None
default:"FrameDirection.DOWNSTREAM"
Which direction of frames to filter (DOWNSTREAM or UPSTREAM).
None filters
frames in both directions.bool
default:"False"
Whether system frames go through the filter function. Lifecycle frames
(
StartFrame, EndFrame, CancelFrame) always pass through.Functionality
When a frame passes through the processor:- Lifecycle frames are always passed through, and so are other system frames unless
filter_system_framesisTrue - Frames moving in a different direction than specified are always passed through
- Other frames are passed to the filter function
- If the filter function returns True, the frame is passed through
Output Frames
The processor conditionally passes through frames based on:- Frame type (lifecycle frames always pass, and system frames pass unless
filter_system_framesisTrue) - Frame direction (only filters in the specified direction)
- Result of the custom filter function
Usage Example
Frame Flow
Notes
- Provides maximum flexibility for complex filtering logic
- Can incorporate dynamic conditions that change at runtime
- Only filters frames moving in the specified direction
- Always passes through system frames for proper pipeline operation
- Can be used to create sophisticated content-based filters
- Supports async filter functions for complex processing