Skip to main content

Genlock

Struct Genlock 

Source
pub struct Genlock { /* private fields */ }
Expand description

Clocks locked to the timing of a reference NDI source.

A genlock paces a sender so that its frames leave in step with another source instead of the local clock: take the two clocks with clocks, wait on the matching one before submitting each frame, and create the sender with its own clocking disabled. While no reference signal arrives, the waits fall back to the system clock and say so.

The waits block their thread and cannot be cancelled or given a deadline. A completed paced wait does not prove live reference media; inspect the returned ClockSource for reference versus system-clock fallback.

§Threading

A genlock is Send but not Sync: it can be created on one thread and connected, waited on and dropped on others. Each of its two clocks can be moved to a thread of its own while they borrow it, because the SDK lets the video and the audio wait run on separate threads at once. The SDK gives no such assurance for is_active, so a shared reference to the genlock stays on one thread.

§Examples

use grafton_ndi::{advanced::{Genlock, GenlockOptions}, FrameRate, Ndi, ScanType, Source};

let ndi = Ndi::new()?;
let mut genlock = Genlock::new(&ndi, &GenlockOptions::new().source(reference))?;
let (mut video, _audio) = genlock.clocks();
let paced_by = video.wait(FrameRate::new(60_000, 1001)?, ScanType::Progressive);
println!("frame paced by {paced_by:?}");

Implementations§

Source§

impl Genlock

Source

pub fn new(ndi: &Ndi, options: &GenlockOptions) -> Result<Self>

Create a genlock with a reference source and native configuration from options. With no source it follows the system clock until connect_to names one.

§Errors

Error::UnsupportedCapability without an Advanced runtime or the corresponding Advanced SDK declarations, and Error::NativeOperationFailed when the SDK creates no genlock.

Source

pub fn connect_to(&mut self, source: &Source)

Follow the timing of source.

No clock from clocks can be in use while this exclusive borrow changes the reference. A Source is already validated.

Source

pub fn disconnect(&mut self)

Stop following a reference source and use the system clock.

Source

pub fn is_active(&self) -> bool

Whether a reference signal is being received.

Source

pub fn clocks(&mut self) -> (VideoClock<'_>, AudioClock<'_>)

The video clock and the audio clock.

Each can be moved to its own thread; both borrow the genlock, so it can be neither reconnected nor dropped while they exist.

Trait Implementations§

Source§

impl Debug for Genlock

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> 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, 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.