Skip to content

api/buffer_backend_registry.h

Namespaces

Name
cvedia
cvedia::rt
API for controlling the server and lifecycle management of runtime instances.
cvedia::rt::api
cvedia::rt::api::buffer
cvedia::rt::api::buffer::backend

Classes

Name
struct cvedia::rt::api::buffer::backend::InferenceFanoutReservation
struct cvedia::rt::api::buffer::backend::BackendFactories
Structure containing all static factory functions for a backend.

Types

Name
using std::function< expected< std::unique_ptr< iface::BufferBackend > >(int width, int height, BufferDataType type, std::string const &transportUri, void *nativeContext)> AllocateFactoryFn
Static factory functions for creating fully initialized buffer backends These return raw BufferBackend* and are used by UnifiedBuffer and backend plugins. Public API (cbuffer) should use cvedia::rt::api::buffer functions that return shared_ptr wrappers. Note: transportUri is always the LAST parameter for consistency.
using std::function< expected< std::unique_ptr< iface::BufferBackend > >(std::string const &filename, BufferDataType type, std::string const &transportUri, void *nativeContext)> LoadImageFactoryFn
using std::function< expected< std::unique_ptr< iface::BufferBackend > >(void *data, int dataSize, BufferDataType type, std::string const &transportUri, void *nativeContext)> DecodeImageFactoryFn
using std::function< expected< std::unique_ptr< iface::BufferBackend > >(int width, int height, BufferDataType type, void *data, size_t step, std::string const &transportUri, BufferOwnership ownership, void *nativeContext)> FromDataFactoryFn
using std::function< expected< std::unique_ptr< iface::BufferBackend > >(iface::BufferBackend const *b, iface::BufferBackend const *g, iface::BufferBackend const *r, std::string const &transportUri, void *nativeContext)> MergeChannelsFactoryFn
using std::function< expected< std::unique_ptr< iface::BufferBackend > >(iface::BufferBackend const *source1, Rect const &region1, iface::BufferBackend const *source2, Rect const &region2, Size outputSize, std::string const &transportUri, void *nativeContext)> CreateMotionBufferFactoryFn
using std::function< expected< std::unique_ptr< iface::BufferBackend > >(void *nativeHandle, std::string const &sourceUri, std::string const &targetScheme, std::optional<:🇨🇻:Rect2i > crop, void *keepAlive, void *sourceContext)> FromInteropFactoryFn
using std::function< expected< std::shared_ptr< void > >(cbuffer const &, uint32_t)> InferenceFanoutPrepareFn
using std::function< expected< void >(cbuffer const &, std::shared_ptr< void > const &)> InferenceFanoutAbortFn

Functions

Name
bool isBackendRegistered(std::string const & scheme)
Check if a backend is registered for the specified scheme.
expected< void > registerBackendFactories(std::string const & scheme, BackendFactories factories)
Register static factory functions for a backend Called by each backend plugin during registerHandler()
expected< void > registerBackendFactories(std::string const & scheme, BackendFactories factories, bool supportsImageOperations)
Register backend factories and generic image-operation support atomically.
bool supportsImageOperations(std::string const & transportUri)
Check whether a buffer URI supports generic image operations.
expected< void > registerInferenceFanoutPreparer(std::string const & scheme, InferenceFanoutPrepareFn preparer)
expected< void > registerInferenceFanoutAborter(std::string const & scheme, InferenceFanoutAbortFn aborter)
expected< InferenceFanoutReservation > prepareInferenceFanout(cbuffer const & source, uint32_t totalConsumers)
expected< void > abortInferenceFanout(InferenceFanoutReservation const & reservation)
expected< iface::BufferBackend * > allocate(int width, int height, BufferDataType type, std::string const & transportUri ="cpu://", void * nativeContext =nullptr)
Backend factory API - create fully initialized backends Used by UnifiedBuffer and backend plugins to create backend instances. Note: transportUri is always the LAST parameter for consistency. The scheme is extracted from transportUri to select the appropriate backend.
expected< iface::BufferBackend * > loadImage(std::string const & filename, BufferDataType type, std::string const & transportUri ="cpu://", void * nativeContext =nullptr)
expected< iface::BufferBackend * > decodeImage(void * data, int dataSize, BufferDataType type, std::string const & transportUri ="cpu://", void * nativeContext =nullptr)
expected< iface::BufferBackend * > fromData(int width, int height, BufferDataType type, void * data, size_t step, std::string const & transportUri ="cpu://", BufferOwnership ownership =BufferOwnership::COPY, void * nativeContext =nullptr)
expected< iface::BufferBackend * > mergeChannels(iface::BufferBackend const * b, iface::BufferBackend const * g, iface::BufferBackend const * r, std::string const & transportUri ="cpu://", void * nativeContext =nullptr)
expected< iface::BufferBackend * > createMotionBuffer(iface::BufferBackend const * source1, Rect const & region1, iface::BufferBackend const * source2, Rect const & region2, Size outputSize, std::string const & transportUri ="", void * nativeContext =nullptr)
Create motion buffer from two grayscale/NV12 sources (fused operation)
expected< iface::BufferBackend * > fromInterop(void * nativeHandle, std::string const & sourceUri, std::string const & targetScheme, std::optional<:🇨🇻:Rect2i > crop =std::nullopt, void * keepAlive =nullptr, void * sourceContext =nullptr)
Create buffer from hardware decoder interop (D3D11/VAAPI → OpenCL)

Types Documentation

using AllocateFactoryFn

using AllocateFactoryFn =  std::function<expected<std::unique_ptr<iface::BufferBackend> >(int width, int height, BufferDataType type, std::string const& transportUri, void* nativeContext)>;

Static factory functions for creating fully initialized buffer backends These return raw BufferBackend* and are used by UnifiedBuffer and backend plugins. Public API (cbuffer) should use cvedia::rt::api::buffer functions that return shared_ptr wrappers. Note: transportUri is always the LAST parameter for consistency.

using LoadImageFactoryFn

using LoadImageFactoryFn =  std::function<expected<std::unique_ptr<iface::BufferBackend> >(std::string const& filename, BufferDataType type, std::string const& transportUri, void* nativeContext)>;

using DecodeImageFactoryFn

using DecodeImageFactoryFn =  std::function<expected<std::unique_ptr<iface::BufferBackend> >(void* data, int dataSize, BufferDataType type, std::string const& transportUri, void* nativeContext)>;

using FromDataFactoryFn

using FromDataFactoryFn =  std::function<expected<std::unique_ptr<iface::BufferBackend> >(int width, int height, BufferDataType type, void* data, size_t step, std::string const& transportUri, BufferOwnership ownership, void* nativeContext)>;

using MergeChannelsFactoryFn

using MergeChannelsFactoryFn =  std::function<expected<std::unique_ptr<iface::BufferBackend> >(iface::BufferBackend const* b, iface::BufferBackend const* g, iface::BufferBackend const* r, std::string const& transportUri, void* nativeContext)>;

using CreateMotionBufferFactoryFn

using CreateMotionBufferFactoryFn =  std::function<expected<std::unique_ptr<iface::BufferBackend> >(iface::BufferBackend const* source1, Rect const& region1, iface::BufferBackend const* source2, Rect const& region2, Size outputSize, std::string const& transportUri, void* nativeContext)>;

using FromInteropFactoryFn

using FromInteropFactoryFn =  std::function<expected<std::unique_ptr<iface::BufferBackend> >(void* nativeHandle, std::string const& sourceUri, std::string const& targetScheme, std::optional<::cv::Rect2i> crop, void* keepAlive, void* sourceContext)>;

using InferenceFanoutPrepareFn

using InferenceFanoutPrepareFn =  std::function<expected<std::shared_ptr<void> >(cbuffer const&, uint32_t)>;

using InferenceFanoutAbortFn

using InferenceFanoutAbortFn =  std::function<expected<void>(cbuffer const&, std::shared_ptr<void> const&)>;

Functions Documentation

function isBackendRegistered

bool isBackendRegistered(
    std::string const & scheme
)

Check if a backend is registered for the specified scheme.

Parameters:

  • scheme The transport URI scheme to check (e.g., "cpu", "cuda", "opencl")

Return: true if backend is registered, false otherwise

function registerBackendFactories

expected< void > registerBackendFactories(
    std::string const & scheme,
    BackendFactories factories
)

Register static factory functions for a backend Called by each backend plugin during registerHandler()

Parameters:

  • scheme The transport URI scheme this backend handles (e.g., "cpu", "cuda", "opencl")

function registerBackendFactories

expected< void > registerBackendFactories(
    std::string const & scheme,
    BackendFactories factories,
    bool supportsImageOperations
)

Register backend factories and generic image-operation support atomically.

Relay-only backends pass false so callers can avoid image operations that require image-addressable storage. The legacy overload keeps its existing behavior and registers support as true.

function supportsImageOperations

bool supportsImageOperations(
    std::string const & transportUri
)

Check whether a buffer URI supports generic image operations.

Return: false for malformed URIs or schemes that explicitly opt out; true for legacy registrations and syntactically valid unknown schemes.

function registerInferenceFanoutPreparer

expected< void > registerInferenceFanoutPreparer(
    std::string const & scheme,
    InferenceFanoutPrepareFn preparer
)

Register optional explicit-reference preparation for a transport.

function registerInferenceFanoutAborter

expected< void > registerInferenceFanoutAborter(
    std::string const & scheme,
    InferenceFanoutAbortFn aborter
)

function prepareInferenceFanout

expected< InferenceFanoutReservation > prepareInferenceFanout(
    cbuffer const & source,
    uint32_t totalConsumers
)

Prepare a source for all consumers before any fan-out worker submits it. The opaque token identifies exactly the references this preflight added.

function abortInferenceFanout

expected< void > abortInferenceFanout(
    InferenceFanoutReservation const & reservation
)

Undo only the reservation represented by this successful preflight.

function allocate

expected< iface::BufferBackend * > allocate(
    int width,
    int height,
    BufferDataType type,
    std::string const & transportUri ="cpu://",
    void * nativeContext =nullptr
)

Backend factory API - create fully initialized backends Used by UnifiedBuffer and backend plugins to create backend instances. Note: transportUri is always the LAST parameter for consistency. The scheme is extracted from transportUri to select the appropriate backend.

function loadImage

expected< iface::BufferBackend * > loadImage(
    std::string const & filename,
    BufferDataType type,
    std::string const & transportUri ="cpu://",
    void * nativeContext =nullptr
)

function decodeImage

expected< iface::BufferBackend * > decodeImage(
    void * data,
    int dataSize,
    BufferDataType type,
    std::string const & transportUri ="cpu://",
    void * nativeContext =nullptr
)

function fromData

expected< iface::BufferBackend * > fromData(
    int width,
    int height,
    BufferDataType type,
    void * data,
    size_t step,
    std::string const & transportUri ="cpu://",
    BufferOwnership ownership =BufferOwnership::COPY,
    void * nativeContext =nullptr
)

function mergeChannels

expected< iface::BufferBackend * > mergeChannels(
    iface::BufferBackend const * b,
    iface::BufferBackend const * g,
    iface::BufferBackend const * r,
    std::string const & transportUri ="cpu://",
    void * nativeContext =nullptr
)

function createMotionBuffer

expected< iface::BufferBackend * > createMotionBuffer(
    iface::BufferBackend const * source1,
    Rect const & region1,
    iface::BufferBackend const * source2,
    Rect const & region2,
    Size outputSize,
    std::string const & transportUri ="",
    void * nativeContext =nullptr
)

Create motion buffer from two grayscale/NV12 sources (fused operation)

Parameters:

  • source1 First source buffer (GRAY or NV12)
  • region1 Absolute pixel region in source1
  • source2 Second source buffer (GRAY or NV12)
  • region2 Absolute pixel region in source2
  • outputSize Target dimensions for output buffer
  • transportUri Transport URI (empty = auto-select from sources, prefer GPU)
  • nativeContext Optional native context

Return: New BGR buffer with fused operation result

Extracts Y-plane from GRAY or NV12 sources, resizes regions to outputSize, and merges into BGR buffer where B=source1, G=source2, R=black.

function fromInterop

expected< iface::BufferBackend * > fromInterop(
    void * nativeHandle,
    std::string const & sourceUri,
    std::string const & targetScheme,
    std::optional<::cv::Rect2i > crop =std::nullopt,
    void * keepAlive =nullptr,
    void * sourceContext =nullptr
)

Create buffer from hardware decoder interop (D3D11/VAAPI → OpenCL)

Parameters:

  • nativeHandle ID3D11Texture2D* (Windows) or VASurfaceID (Linux)
  • sourceUri Fully qualified source URI (e.g., "d3d11://0", "vaapi://0")
  • targetScheme Target backend scheme ("opencl")
  • crop Optional logical crop rectangle
  • keepAlive Optional token to keep native resource alive
  • sourceContext Optional native display handle (VADisplay on Linux, ID3D11Device on Windows) that overrides the default lookup from sourceUri. Pass the decoder's actual display handle when it differs from the transport registry.

Return: Backend in interop mode, or error

Creates an OpenCL buffer in interop mode with cl_image2d storage for zero-copy access to hardware-decoded NV12 frames. First operation that processes the buffer will convert to UMat using hardware-accelerated kernels.