pub struct Runtime { /* private fields */ }Expand description
The NDI implementation selected for this process.
A Runtime is a small Copy handle. Obtaining one loads and pins the NDI
runtime library but does not start NDI, so it can be inspected first:
info for its path, edition and version,
capabilities for what it supports and
is_supported_cpu for whether it can run here.
initialize then starts NDI.
A process has one selected implementation. Once select
succeeds, every handle refers to it, and what the accessors return stays
valid until the process exits.
§Examples
use grafton_ndi::{Finder, FinderOptions, Runtime, RuntimeFeature, RuntimeOptions};
let runtime = Runtime::select(&RuntimeOptions::default())?;
let info = runtime.info();
println!("{:?} {} from {:?}", info.edition(), info.raw_version(), info.library_path());
if !runtime.capabilities().supports(RuntimeFeature::Planar444Video) {
println!("this runtime predates the planar 4:4:4 formats");
}
let ndi = runtime.initialize()?;
let finder = Finder::new(&ndi, &FinderOptions::default())?;Implementations§
Source§impl Runtime
impl Runtime
Sourcepub fn select(options: &RuntimeOptions) -> Result<Self>
pub fn select(options: &RuntimeOptions) -> Result<Self>
Select the NDI implementation options describe, without starting NDI.
The first successful call loads the runtime library, checks that it exports every entry point this crate requires, and pins it for the rest of the process. Later calls return the same implementation, provided their options are met by it. A statically linked target selects the archive linked at build time.
Loading a native library runs its initialization code: select only trusted SDK files.
§Errors
Error::RuntimeLoadFailedwhen no usable library is found. Nothing is selected and the call can be repeated, with other options if wanted. Thecrate::LoadFailurerecords each attempted location, its origin, typed refusal and whether native code loaded.Error::RuntimeConflictwhen an implementation is already selected and does not meetoptions: they name a different library file, or ask for the Advanced SDK when the selected implementation is not one. Also returned for an explicit path on a linked target, or when native loading re-enters selection on the same thread before selection finishes. On dynamically loaded, non-Apple ELF targets, an explicit file is also refused before opening when another runtime is in the global symbol scope.crate::SelectionConflictidentifies the cause.Error::InvalidInputwhenoptionsname a relative library path.
§Examples
use grafton_ndi::{Error, Runtime, RuntimeOptions};
match Runtime::select(&RuntimeOptions::default()) {
Ok(runtime) => println!("selected {:?}", runtime.info().library_path()),
Err(Error::RuntimeLoadFailed(failure)) if !failure.loaded_any() => {
eprintln!("no runtime could be opened: {failure}");
}
Err(error) => eprintln!("{error}"),
}Sourcepub fn info(&self) -> &'static RuntimeInfo
pub fn info(&self) -> &'static RuntimeInfo
The selected implementation’s identity: the file it was loaded from, its edition, how it is linked and the version it reports.
§Examples
let runtime = Runtime::select(&RuntimeOptions::default())?;
println!("NDI version: {}", runtime.info().raw_version());Sourcepub fn capabilities(&self) -> &'static Capabilities
pub fn capabilities(&self) -> &'static Capabilities
What the selected implementation supports, by optional capability.
This is evidence about the library and this build, not about hardware or licenses.
§Examples
let runtime = Runtime::select(&RuntimeOptions::default())?;
let status = runtime.capabilities().status(RuntimeFeature::ReceiveDelay);
println!("receive delay: {status:?}");Sourcepub fn require_feature(&self, feature: RuntimeFeature) -> Result<()>
pub fn require_feature(&self, feature: RuntimeFeature) -> Result<()>
Check that the selected implementation provides feature.
§Errors
Returns Error::UnsupportedCapability naming the capability and why
the selected implementation or this build cannot provide it.
§Examples
let runtime = Runtime::select(&RuntimeOptions::default())?;
runtime.require_feature(RuntimeFeature::Routing)?;Sourcepub fn is_supported_cpu(&self) -> bool
pub fn is_supported_cpu(&self) -> bool
Whether the selected implementation can run on this CPU.
The implementation itself answers, because the instructions it needs
depend on the SDK version and the platform. A runtime that does not
start for this reason makes Runtime::initialize report
Error::UnsupportedCpu.
§Examples
let runtime = Runtime::select(&RuntimeOptions::default())?;
if !runtime.is_supported_cpu() {
eprintln!("this CPU lacks instructions the NDI runtime needs");
}Sourcepub fn initialize(&self) -> Result<Ndi>
pub fn initialize(&self) -> Result<Ndi>
Start NDI and return a handle to it.
NDI is started by the first handle and stays started while any handle
exists; each further call, like Ndi::clone, only adds a handle.
Dropping the last one stops NDI, after which this can be called again.
The call is thread-safe.
§Errors
Error::UnsupportedCpuwhen the implementation does not start and reports that this CPU cannot run it.Error::InitializationFailedwhen it does not start for any other reason, or the count of handles is exhausted.
A failed start can be retried.
§Examples
let runtime = Runtime::select(&RuntimeOptions::default())?;
match runtime.initialize() {
Ok(ndi) => println!("NDI is running: {ndi:?}"),
Err(Error::UnsupportedCpu) => eprintln!("NDI cannot run on this CPU"),
Err(error) => return Err(error),
}