pub struct AsyncVideoToken<'a, 'buf> { /* private fields */ }Expand description
A token that tracks an async video send operation.
The token holds exclusive access to the sender and a borrow of the frame buffer, ensuring memory safety at compile time. Only one async send can be in-flight at a time in the non-advanced SDK build.
When the token is dropped, a flush is automatically performed to ensure the NDI SDK releases the buffer before the token’s borrows expire.
Implementations§
Source§impl<'a, 'buf> AsyncVideoToken<'a, 'buf>
impl<'a, 'buf> AsyncVideoToken<'a, 'buf>
Sourcepub fn wait(self) -> Result<()>
pub fn wait(self) -> Result<()>
Explicitly wait for the async video operation to complete.
This method provides an explicit way to wait for completion instead of relying on Drop.
It consumes the token, ensuring the buffer is safe to reuse after this call returns.
§Behavior by SDK Version
- Standard SDK: Sends a NULL frame to flush the pipeline, blocking until all pending async video operations complete. This is the same behavior as dropping the token.
- Advanced SDK (with
advanced_sdkandhas_async_completion_callback): Waits for the SDK completion callback to signal that the buffer has been released, with a 5-second timeout. Falls back to null-frame flush if the timeout elapses.
§Errors
Currently always returns Ok(()). The Result return type is preserved for forward
compatibility.
§Examples
let ndi = NDI::new()?;
let options = SenderOptions::builder("Test Sender").build();
let mut sender = grafton_ndi::Sender::new(&ndi, &options)?;
let mut buffer = vec![0u8; 1920 * 1080 * 4];
let borrowed_frame = BorrowedVideoFrame::try_from_uncompressed(&buffer, 1920, 1080, PixelFormat::BGRA, 30, 1)?;
let token = sender.send_video_async(&borrowed_frame);
// Explicitly wait for completion instead of relying on Drop
token.wait()?;
// Now safe to reuse or drop the buffer
buffer.clear();Trait Implementations§
Auto Trait Implementations§
impl<'a, 'buf> Freeze for AsyncVideoToken<'a, 'buf>
impl<'a, 'buf> !RefUnwindSafe for AsyncVideoToken<'a, 'buf>
impl<'a, 'buf> Send for AsyncVideoToken<'a, 'buf>
impl<'a, 'buf> Sync for AsyncVideoToken<'a, 'buf>
impl<'a, 'buf> Unpin for AsyncVideoToken<'a, 'buf>
impl<'a, 'buf> UnsafeUnpin for AsyncVideoToken<'a, 'buf>
impl<'a, 'buf> !UnwindSafe for AsyncVideoToken<'a, 'buf>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more