pub struct FrameStream { /* private fields */ }Expand description
Frames from one GVSP stream, assembled by a receive thread of its own.
The thread starts when the stream is created and stops, joined within a
few milliseconds, when it is dropped. It reads every datagram as it
arrives, whether or not anything is waiting for a frame, and keeps up to
sixteen finished frames for next_block or
next_block_blocking; when the application
falls behind, the oldest is dropped and counted in
StreamStats::frames_backpressure.
Only complete frames are delivered unless
set_deliver_incomplete asks otherwise;
every block is counted either way.
§Example
let raw_stream = StreamBuilder::new(&mut device)
.iface(iface)
.build()
.await?;
let mut frame_stream = FrameStream::new(raw_stream, None);
while let Some(frame) = frame_stream.next_frame().await? {
println!("Frame {}: {}x{}", frame.block_id, frame.width, frame.height);
}Implementations§
Source§impl FrameStream
impl FrameStream
Sourcepub fn from_socket(
socket: UdpSocket,
packet_size: u32,
) -> Result<Self, GenicamError>
pub fn from_socket( socket: UdpSocket, packet_size: u32, ) -> Result<Self, GenicamError>
Receive GVSP on a socket the caller bound, from a camera configured some other way: another application holds control, or the stream was set up by hand.
packet_size is the camera’s GevSCPSPacketSize, which fixes where
each packet’s bytes belong. config is None for such
a stream.
Such a stream accepts datagrams from any address until
set_source_filter names the camera, and
never asks for lost packets unless
enable_resend is called. A host that only
monitors a stream must not ask: it does not control the camera, and its
requests would add traffic to a stream another application configured.
Sourcepub fn set_block_timeout(&mut self, timeout: Duration)
pub fn set_block_timeout(&mut self, timeout: Duration)
How long a block may go without a packet before it is closed as incomplete (default 100 ms).
Counted from the block’s last packet, not its first: a large frame on a slow or paced link takes as long as it takes, and only silence ends it.
Sourcepub fn set_payload_size(&mut self, payload_size: Option<usize>)
pub fn set_payload_size(&mut self, payload_size: Option<usize>)
The camera’s PayloadSize: the exact size of every frame buffer.
Without it each buffer is sized from the leader’s geometry, which cannot know about chunk data or vendor padding. Set it before acquisition starts; blocks already in flight keep their buffers.
Sourcepub fn set_deliver_incomplete(&mut self, deliver: bool)
pub fn set_deliver_incomplete(&mut self, deliver: bool)
Also deliver frames that did not complete, with their
FrameStatus saying how (default: off).
Lost packets’ bytes are zero in the payload. Every incomplete frame is
counted in StreamStats::frames_incomplete either way.
Sourcepub fn set_source_filter(&mut self, camera: Option<Ipv4Addr>)
pub fn set_source_filter(&mut self, camera: Option<Ipv4Addr>)
Accept GVSP only from camera; None accepts any source.
A stream from StreamBuilder or
Camera::open_stream accepts only the
camera’s own address. Datagrams from anywhere else are ignored and
counted in StreamStats::packets_ignored_foreign; a camera that
sends its stream from another address than the one it answers GVCP on
needs None.
Sourcepub fn source_filter(&self) -> Option<Ipv4Addr>
pub fn source_filter(&self) -> Option<Ipv4Addr>
The only address GVSP is accepted from, if any.
Sourcepub fn enable_resend(&mut self, camera: SocketAddrV4, channel: u16)
pub fn enable_resend(&mut self, camera: SocketAddrV4, channel: u16)
Ask the camera at camera (its GVCP address, normally port 3956) to
send lost packets of stream channel channel again.
Camera::open_stream does this when the
camera’s capability register says it supports packet resend. Call it
yourself only for a stream this application controls, on a camera
that supports resend.
Sourcepub fn disable_resend(&mut self)
pub fn disable_resend(&mut self)
Stop asking for lost packets.
Sourcepub fn resend_enabled(&self) -> bool
pub fn resend_enabled(&self) -> bool
Whether the stream asks the camera for lost packets.
Sourcepub fn set_resend_delay(&mut self, delay: Duration)
pub fn set_resend_delay(&mut self, delay: Duration)
How old a gap in a block’s packets must be before it is asked for (default 2 ms), so a packet that was only overtaken is not.
Sourcepub fn set_resend_retry_interval(&mut self, interval: Duration)
pub fn set_resend_retry_interval(&mut self, interval: Duration)
How long to wait for a resent packet before asking again (default 20 ms).
Sourcepub fn set_resend_max_requests(&mut self, requests: u32)
pub fn set_resend_max_requests(&mut self, requests: u32)
How many times one range of packets is asked for, the first request included (default 3).
Sourcepub fn set_resend_budget(&mut self, share: f64)
pub fn set_resend_budget(&mut self, share: f64)
The share of a block’s packets its requests may ask for, retries included (default 0.25, rounded up). A block that lost more is not worth flooding the camera for; it closes incomplete.
Sourcepub fn set_time_sync(&mut self, time_sync: TimeSync)
pub fn set_time_sync(&mut self, time_sync: TimeSync)
Update or set the time synchronization model for timestamp mapping.
Sourcepub fn stats_handle(&self) -> StreamStatsAccumulator
pub fn stats_handle(&self) -> StreamStatsAccumulator
Obtain a clone of the statistics accumulator handle.
Sourcepub fn stats(&self) -> StreamStats
pub fn stats(&self) -> StreamStats
Snapshot the collected statistics.
Sourcepub fn params(&self) -> StreamParams
pub fn params(&self) -> StreamParams
Access the negotiated stream parameters.
Sourcepub fn config(&self) -> Option<&StreamConfig>
pub fn config(&self) -> Option<&StreamConfig>
The stream configuration, or None for a stream made with
from_socket.
Sourcepub async fn next_frame(&mut self) -> Result<Option<Frame>, GenicamError>
pub async fn next_frame(&mut self) -> Result<Option<Frame>, GenicamError>
Receive the next image frame.
This backwards-compatible image API also returns an EVS block as a
Frame carrying the raw bytes and its EVT PFNC code. New callers that
need to distinguish event data should use next_block.
Sourcepub async fn next_block(
&mut self,
) -> Result<Option<GenericStreamBlock>, GenicamError>
pub async fn next_block( &mut self, ) -> Result<Option<GenericStreamBlock>, GenicamError>
Receive and classify the next GVSP block.
Ok(None) means the stream has ended. Cancel-safe: dropping the
future, as tokio::select! does, loses no block.
Sourcepub fn next_block_blocking(
&mut self,
timeout: Duration,
) -> Result<Option<GenericStreamBlock>, GenicamError>
pub fn next_block_blocking( &mut self, timeout: Duration, ) -> Result<Option<GenericStreamBlock>, GenicamError>
Wait up to timeout for the next block on the calling thread.
For callers without an async runtime. Ok(None) means the stream has
ended; nothing within timeout is GenicamError::Timeout.
Sourcepub fn next_frame_blocking(
&mut self,
timeout: Duration,
) -> Result<Option<Frame>, GenicamError>
pub fn next_frame_blocking( &mut self, timeout: Duration, ) -> Result<Option<Frame>, GenicamError>
next_frame on the calling thread, waiting up to
timeout: Ok(None) when the stream has ended,
GenicamError::Timeout when nothing arrived.