Skip to main content

Runtime

Struct Runtime 

Source
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

Source

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::RuntimeLoadFailed when no usable library is found. Nothing is selected and the call can be repeated, with other options if wanted. The crate::LoadFailure records each attempted location, its origin, typed refusal and whether native code loaded.
  • Error::RuntimeConflict when an implementation is already selected and does not meet options: 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::SelectionConflict identifies the cause.
  • Error::InvalidInput when options name 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}"),
}
Source

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());
Source

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:?}");
Source

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)?;
Source

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");
}
Source

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

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),
}

Trait Implementations§

Source§

impl Clone for Runtime

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Runtime

Source§

impl Debug for Runtime

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.