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
default:"FrameDirection.DOWNSTREAM"
Which direction of frames to filter (DOWNSTREAM or UPSTREAM)
Functionality
When a frame passes through the processor:- System frames and end frames are always passed through
- 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 (system frames and end frames always pass)
- 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