pub struct AllocatedReceiver<M: ReceiverMode = RawCapture> { /* private fields */ }Expand description
A receiver whose frames can be received into application memory.
The default RawCapture mode retains ordinary receiver capture.
AllocatorService::attach_packets returns the PacketAttached mode,
which captures through capture_any and
capture_any_ref.
receiver lends the receiver in its existing mode;
controls permits exclusive stream controls and KVM
without allowing that receiver to be replaced.
Dropping this owner, or taking the receiver back, returns it to the SDK’s
own memory first. The receiver may live on in a
RecvAdvertiser registration;
allocations it still holds are freed through the process-wide token registry.
The registration retains the exact receiver core, so resetting always
reaches the original native instance.
Setting an allocator replaces the previous one for frames allocated from then on. Frames allocated earlier stay in the memory the earlier policy supplied, and that policy is kept until the SDK has freed the last of them. Only a call of the earlier policy still running when the replacement is installed is declined.
§Threading
Both returned modes are Send and Sync: capturing, changing allocators
and dropping the owner can happen on any thread. Captures borrow it shared;
changing allocators requires an exclusive borrow. The SDK calls policies
on its own threads, possibly concurrently, and frees each allocation through
the callback that created it. Registry access is synchronized.
§Examples
use std::time::Duration;
use grafton_ndi::{
advanced::{AllocationBuffer, AllocationRequest, AllocatorLimits, AllocatorService},
Receiver, ReceiverOptions, Ndi,
};
let ndi = Ndi::new()?;
let receiver = Receiver::new(&ndi, &ReceiverOptions::disconnected())?;
let service = AllocatorService::new(ndi.process_lifetime(), &AllocatorLimits::default())?;
let mut receiver = service.attach(receiver)?;
// Pad every video line to a multiple of 256 bytes.
receiver.set_video_allocator(|request: AllocationRequest| {
let stride = request.stride_bytes().next_multiple_of(256);
AllocationBuffer::zeroed(request.with_stride_bytes(stride)?)
})?;
if let Some(frame) = receiver.receiver().capture_video(Duration::from_secs(1))? {
println!("line stride: {} bytes", frame.line_stride_bytes());
}Application allocator code follows the
ReceiveAllocator callback contract.
Implementations§
Source§impl<M: ReceiverMode> AllocatedReceiver<M>
impl<M: ReceiverMode> AllocatedReceiver<M>
Sourcepub fn receiver(&self) -> &Receiver<M>
pub fn receiver(&self) -> &Receiver<M>
The receiver, for capture permitted by its mode and shared controls.
Sourcepub fn controls(&mut self) -> ReceiverControls<'_, M>
pub fn controls(&mut self) -> ReceiverControls<'_, M>
Borrow exclusive stream controls or start KVM without permitting receiver replacement. This allocates nothing and makes no SDK call. Capture through the KVM session while inputs are held.
Sourcepub fn set_video_allocator<P: ReceiveAllocator>(
&mut self,
policy: P,
) -> Result<(), Rejected<P>>
pub fn set_video_allocator<P: ReceiveAllocator>( &mut self, policy: P, ) -> Result<(), Rejected<P>>
Receive video into memory from policy.
§Errors
Returns the policy with Error::InvalidInput
when the process already has AllocatorLimits::max_generations
policies. The current allocator then stays in place.
Sourcepub fn set_audio_allocator<P: ReceiveAllocator>(
&mut self,
policy: P,
) -> Result<(), Rejected<P>>
pub fn set_audio_allocator<P: ReceiveAllocator>( &mut self, policy: P, ) -> Result<(), Rejected<P>>
Sourcepub fn reset_video_allocator(&mut self)
pub fn reset_video_allocator(&mut self)
Return to the SDK’s own video memory.
Sourcepub fn reset_audio_allocator(&mut self)
pub fn reset_audio_allocator(&mut self)
Return to the SDK’s own audio memory.
Source§impl AllocatedReceiver<RawCapture>
impl AllocatedReceiver<RawCapture>
Sourcepub fn into_receiver(self) -> Receiver
pub fn into_receiver(self) -> Receiver
Return to the SDK’s own memory and give the receiver back.
Source§impl AllocatedReceiver<PacketAttached>
impl AllocatedReceiver<PacketAttached>
Sourcepub fn capture_any(&self, timeout: Duration) -> Result<Option<PacketItem>>
pub fn capture_any(&self, timeout: Duration) -> Result<Option<PacketItem>>
Wait up to timeout for the next frame or event; see
PacketReceiver::capture_any.
§Errors
As for PacketReceiver::capture_any, including crate::Error::UnexpectedSdkResult
once per failed status publication, whose event remains pending.
Sourcepub fn capture_any_ref(
&self,
timeout: Duration,
) -> Result<Option<PacketItemRef<'_>>>
pub fn capture_any_ref( &self, timeout: Duration, ) -> Result<Option<PacketItemRef<'_>>>
Borrow a packet directly from SDK or application-provided storage.
A held item keeps its custom allocation charged until the SDK releases
it after the item is dropped. See PacketReceiver::capture_any_ref.
§Errors
As for PacketReceiver::capture_any_ref, including crate::Error::UnexpectedSdkResult
once per failed status publication, whose event remains pending.
Sourcepub fn into_packet_receiver(self) -> PacketReceiver
pub fn into_packet_receiver(self) -> PacketReceiver
Return to the SDK’s own memory and give the packet receiver back.