Skip to main content

ReceiveAllocator

Trait ReceiveAllocator 

Source
pub trait ReceiveAllocator:
    Send
    + Sync
    + 'static {
    // Required method
    fn allocate(&self, request: AllocationRequest) -> Result<AllocationBuffer>;
}
Expand description

A policy that supplies the memory received frames are written into.

Any closure Fn(AllocationRequest) -> Result<AllocationBuffer> that is Send + Sync is a policy.

The SDK calls the policy on its own threads, possibly several at once, and stalls video or audio while a call blocks. An error or a panic makes that one allocation fail; the SDK then drops the frame. Inspect AllocatorService::usage for process-wide AllocationDecline counts, including distinct policy-error and contained-panic counts. Invalid media layouts are declined before calling the policy, including planar audio requests above capture’s 64 MiB frame limit.

§Callback contract

Allocator code, including policy calls, allocation destructors and pool releases, can run on SDK decoder/free threads or on the thread inside Receiver::connect_to, Receiver::disconnect or Receiver::reconnect. Connection changes and allocator replacement wait for running policies. Allocator code may capture and use shared controls on its own receiver. It must not change that receiver’s connection or release the last AllocatedReceiver owner: either operation can wait for the callback itself and deadlock.

A replaced policy is destroyed only after its replacement is installed. With no outstanding allocations or policy calls, the replacing call drops it. Otherwise the last call or allocation to release it does, possibly on an SDK thread inside a free callback. Its destructor must not wait for frames from that receiver.

Required Methods§

Source

fn allocate(&self, request: AllocationRequest) -> Result<AllocationBuffer>

Supply memory for one frame.

§Errors

Any error declines the allocation.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§