cvedia::rt::JpegEncoderRegistry¶
Registry for JPEG encoders. More...
#include <jpeg_encoder_registry.h>
Public Types¶
| Name | |
|---|---|
| using std::function< std::shared_ptr< iface::JpegEncoder >(std::string const &)> | EncoderFactory Factory function type for creating encoder instances. |
Public Functions¶
| Name | |
|---|---|
| void | registerEncoder(std::string const & transportUri, EncoderFactory factory, int priority =100) Register a JPEG encoder for a transport URI. |
| std::shared_ptr< iface::JpegEncoder > | getEncoder(std::string const & transportUri) Get encoder for a transport URI. |
| std::vector< std::string > | getSupportedTransports() Get list of transport URIs with registered encoders. |
| bool | hasZeroCopyEncoder(std::string const & transportUri) Check if an encoder supports a transport URI with zero-copy. |
| void | clear() Unregister all encoders (for testing/cleanup) |
Detailed Description¶
class cvedia::rt::JpegEncoderRegistry;
Registry for JPEG encoders.
Manages encoder registration against transport URIs and provides automatic fallback to CPU when no zero-copy encoder is available. Encoders are selected based on buffer transport URI for optimal zero-copy path.
Registration (in plugin's registerHandler):
JpegEncoderRegistry::registerEncoder("opencl://0-0", factory, 100);
JpegEncoderRegistry::registerEncoder("vaapi://0", factory, 100);
JpegEncoderRegistry::registerEncoder("cpu://", softwareFactory, 0); // Fallback
Lookup (automatically falls back to cpu:// if no match):
auto encoder = JpegEncoderRegistry::getEncoder(buffer->getTransportUri());
auto jpeg = encoder->encode(buffer, quality); // Blocks until worker available
Thread-safe: All methods are safe to call from multiple threads.
Public Types Documentation¶
using EncoderFactory¶
using EncoderFactory = std::function<std::shared_ptr<iface::JpegEncoder>(std::string const&)>;
Factory function type for creating encoder instances.
The factory receives the transport URI and should return a shared_ptr to an encoder instance. The encoder maintains its own worker pool.
Public Functions Documentation¶
function registerEncoder¶
static void registerEncoder(
std::string const & transportUri,
EncoderFactory factory,
int priority =100
)
Register a JPEG encoder for a transport URI.
Parameters:
- transportUri Transport URI the encoder supports (e.g., "opencl://0-0", "cpu://")
- factory Factory function to create encoder instances
- priority Selection priority (higher wins); use 100 for hardware, 0 for software fallback
Called by encoder plugins during registerHandler(). Multiple encoders can be registered for the same URI; the highest priority one is selected.
Example:
// In VPL JPEG encoder plugin
JpegEncoderRegistry::registerEncoder("d3d11://0", vplFactory, 100);
JpegEncoderRegistry::registerEncoder("vaapi://0", vplFactory, 100);
// In software encoder plugin
JpegEncoderRegistry::registerEncoder("cpu://", softwareFactory, 0);
function getEncoder¶
static std::shared_ptr< iface::JpegEncoder > getEncoder(
std::string const & transportUri
)
Get encoder for a transport URI.
Parameters:
- transportUri Transport URI to find encoder for
Return: Shared pointer to encoder, or nullptr if none available
Returns the highest-priority encoder registered for the given URI. If no exact match is found, automatically falls back to "cpu://" encoder. If no encoder is available at all, returns nullptr.
Note: The returned encoder is shared; encode() handles worker pool locking internally. Calling getEncoder() does NOT block.
function getSupportedTransports¶
static std::vector< std::string > getSupportedTransports()
Get list of transport URIs with registered encoders.
Return: Vector of transport URIs that have registered encoders
Used by rtcmd transport to display encoder availability.
function hasZeroCopyEncoder¶
static bool hasZeroCopyEncoder(
std::string const & transportUri
)
Check if an encoder supports a transport URI with zero-copy.
Parameters:
- transportUri Transport URI to check
Return: true if a zero-copy encoder is available for this URI
function clear¶
static void clear()
Unregister all encoders (for testing/cleanup)